[PATCH] Add git-local-pull.
[gitweb.git] / sha1_file.c
index d91e072f3e5480de3605fb3f1e581a938301bdfb..ced079184702fad6f1e79a3b90aa4fc317aa0b88 100644 (file)
@@ -63,14 +63,27 @@ int get_sha1_file(const char *path, unsigned char *result)
 int get_sha1(const char *str, unsigned char *sha1)
 {
        static char pathname[PATH_MAX];
+       static const char *prefix[] = {
+               "",
+               "refs",
+               "refs/tags",
+               "refs/heads",
+               "refs/snap",
+               NULL
+       };
+       const char *gitdir;
+       const char **p;
 
        if (!get_sha1_hex(str, sha1))
                return 0;
-       if (!get_sha1_file(str, sha1))
-               return 0;
-       snprintf(pathname, sizeof(pathname), ".git/%s", str);
-       if (!get_sha1_file(pathname, sha1))
-               return 0;
+
+       gitdir = ".git";
+       for (p = prefix; *p; p++) {
+               snprintf(pathname, sizeof(pathname), "%s/%s/%s", gitdir, *p, str);
+               if (!get_sha1_file(pathname, sha1))
+                       return 0;
+       }
+
        return -1;
 }