return 0;
}
+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);
+}
+
+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;
+
+ 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;
+}
+
char * sha1_to_hex(const unsigned char *sha1)
{
static char buffer[50];