X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=sha1_file.c;h=1747276647c7551fd3fe7b1a20612341c0d00d6f;hb=ce11895d5cc5920e5ef01525aa8355357ee0820e;hp=8f20e2f82182a2ab25d7f07a13ac038faececcbc;hpb=dade09c2269ec2117df085e8a99efcabccf08c53;p=git.git diff --git a/sha1_file.c b/sha1_file.c index 8f20e2f8..17472766 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -102,9 +102,36 @@ char *get_index_file(void) return git_index_file; } +char *git_path(const char *fmt, ...) +{ + static char pathname[PATH_MAX], *ret; + va_list args; + int len; + + if (!git_dir) + setup_git_env(); + len = strlen(git_dir); + if (len > PATH_MAX-100) + return "pad-path"; + memcpy(pathname, git_dir, len); + if (len && git_dir[len-1] != '/') + pathname[len++] = '/'; + va_start(args, fmt); + vsnprintf(pathname + len, sizeof(pathname) - len, fmt, args); + va_end(args); + ret = pathname; + + /* Clean it up */ + if (!memcmp(pathname, "./", 2)) { + ret += 2; + while (*ret == '/') + ret++; + } + return ret; +} + int get_sha1(const char *str, unsigned char *sha1) { - static char pathname[PATH_MAX]; static const char *prefix[] = { "", "refs", @@ -118,11 +145,8 @@ int get_sha1(const char *str, unsigned char *sha1) if (!get_sha1_hex(str, sha1)) return 0; - if (!git_dir) - setup_git_env(); for (p = prefix; *p; p++) { - snprintf(pathname, sizeof(pathname), "%s/%s/%s", - git_dir, *p, str); + char * pathname = git_path("%s/%s", *p, str); if (!get_sha1_file(pathname, sha1)) return 0; } @@ -439,6 +463,7 @@ static void prepare_packed_git_one(char *objdir) p->next = packed_git; packed_git = p; } + closedir(dir); } void prepare_packed_git(void)