From 9938af6a85dd08436ad373fc07a1ddba8dcfa170 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 3 Aug 2005 22:15:49 -0700 Subject: Update get_sha1() to grok extended format. Everybody envies rev-parse, who is the only one that can grok the extended sha1 format. Move the get_extended_sha1() out of rev-parse, rename it to get_sha1() and make it available to everybody else. The one I posted earlier to the list had one bug where it did not handle a name that ends with a digit correctly (it incorrectly tried the "Nth parent" path). This commit fixes it. Signed-off-by: Junio C Hamano --- sha1_file.c | 39 --------------------------------------- 1 file changed, 39 deletions(-) (limited to 'sha1_file.c') diff --git a/sha1_file.c b/sha1_file.c index df5eb2ac6..a17a6d13b 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -46,21 +46,6 @@ int get_sha1_hex(const char *hex, unsigned char *sha1) return 0; } -static int get_sha1_file(const char *path, unsigned char *result) -{ - char buffer[60]; - int fd = open(path, O_RDONLY); - int len; - - if (fd < 0) - return -1; - len = read(fd, buffer, sizeof(buffer)); - close(fd); - if (len < 40) - return -1; - return get_sha1_hex(buffer, result); -} - static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file; static void setup_git_env(void) @@ -132,30 +117,6 @@ int safe_create_leading_directories(char *path) return 0; } -int get_sha1(const char *str, unsigned char *sha1) -{ - static const char *prefix[] = { - "", - "refs", - "refs/tags", - "refs/heads", - "refs/snap", - NULL - }; - const char **p; - - if (!get_sha1_hex(str, sha1)) - return 0; - - for (p = prefix; *p; p++) { - char * pathname = git_path("%s/%s", *p, str); - if (!get_sha1_file(pathname, sha1)) - return 0; - } - - return -1; -} - char * sha1_to_hex(const unsigned char *sha1) { static char buffer[50]; -- cgit v1.2.1