summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2005-07-03 10:01:38 -0700
committerLinus Torvalds <torvalds@g5.osdl.org>2005-07-03 10:01:38 -0700
commit944d858969e4e14adefdd8f21fac5c8ab45f83f7 (patch)
tree26f45f4e5544838e40132f579fb86f9ff006688f /refs.c
parent7ec4e60819764128351d526a77859a403c0d4ff4 (diff)
downloadgit-944d858969e4e14adefdd8f21fac5c8ab45f83f7.tar.gz
Fix up "for_each_ref()" to be more usable, and use it in git-fsck-cache
It needed to take the GIT_DIR information into account, something that the original receive-pack usage just never cared about.
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/refs.c b/refs.c
index 0a99dd1458..447080edde 100644
--- a/refs.c
+++ b/refs.c
@@ -17,7 +17,7 @@ static int read_ref(const char *path, unsigned char *sha1)
return ret;
}
-static int do_for_each_ref(const char *base, int (*fn)(const char *path, unsigned char *sha1))
+static int do_for_each_ref(const char *base, int (*fn)(const char *path, const unsigned char *sha1))
{
int retval = 0;
DIR *dir = opendir(base);
@@ -27,6 +27,8 @@ static int do_for_each_ref(const char *base, int (*fn)(const char *path, unsigne
int baselen = strlen(base);
char *path = xmalloc(baselen + 257);
memcpy(path, base, baselen);
+ if (baselen && base[baselen-1] != '/')
+ path[baselen++] = '/';
while ((de = readdir(dir)) != NULL) {
unsigned char sha1[20];
@@ -42,8 +44,6 @@ static int do_for_each_ref(const char *base, int (*fn)(const char *path, unsigne
if (lstat(path, &st) < 0)
continue;
if (S_ISDIR(st.st_mode)) {
- path[baselen + namelen] = '/';
- path[baselen + namelen + 1] = 0;
retval = do_for_each_ref(path, fn);
if (retval)
break;
@@ -63,9 +63,9 @@ static int do_for_each_ref(const char *base, int (*fn)(const char *path, unsigne
return retval;
}
-int for_each_ref(int (*fn)(const char *path, unsigned char *sha1))
+int for_each_ref(int (*fn)(const char *path, const unsigned char *sha1))
{
- return do_for_each_ref("refs/", fn);
+ return do_for_each_ref(get_refs_directory(), fn);
}
static char *ref_file_name(const char *ref)