From 40d52ff77b093fa48f58a168f4b0c4e65b862e56 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 1 Apr 2010 20:05:23 -0400 Subject: make commit_tree a library function Until now, this has been part of the commit-tree builtin. However, it is already used by other builtins (like commit, merge, and notes), and it would be useful to access it from library code. The check_valid helper has to come along, too, but is given a more library-ish name of "assert_sha1_type". Otherwise, the code is unchanged. There are still a few rough edges for a library function, like printing the utf8 warning to stderr, but we can address those if and when they come up as inappropriate. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- sha1_file.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'sha1_file.c') diff --git a/sha1_file.c b/sha1_file.c index ff65328006..28c056e074 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2516,3 +2516,13 @@ int read_pack_header(int fd, struct pack_header *header) return PH_ERROR_PROTOCOL; return 0; } + +void assert_sha1_type(const unsigned char *sha1, enum object_type expect) +{ + enum object_type type = sha1_object_info(sha1, NULL); + if (type < 0) + die("%s is not a valid object", sha1_to_hex(sha1)); + if (type != expect) + die("%s is not a valid '%s' object", sha1_to_hex(sha1), + typename(expect)); +} -- cgit v1.2.3