[PATCH] Make sq_expand() available as sq_quote().
[git.git] / refs.c
diff --git a/refs.c b/refs.c
index 447080e..09c9f90 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -26,6 +26,11 @@ static int do_for_each_ref(const char *base, int (*fn)(const char *path, const u
                struct dirent *de;
                int baselen = strlen(base);
                char *path = xmalloc(baselen + 257);
+
+               if (!strncmp(base, "./", 2)) {
+                       base += 2;
+                       baselen -= 2;
+               }
                memcpy(path, base, baselen);
                if (baselen && base[baselen-1] != '/')
                        path[baselen++] = '/';
@@ -63,6 +68,15 @@ static int do_for_each_ref(const char *base, int (*fn)(const char *path, const u
        return retval;
 }
 
+int head_ref(int (*fn)(const char *path, const unsigned char *sha1))
+{
+       unsigned char sha1[20];
+       const char *headpath = git_path("HEAD");
+       if (!read_ref(headpath, sha1))
+               return fn(headpath, sha1);
+       return 0;
+}
+
 int for_each_ref(int (*fn)(const char *path, const unsigned char *sha1))
 {
        return do_for_each_ref(get_refs_directory(), fn);