get_ref_dir(): require that the dirname argument ends in '/'
This removes some conditional code and makes it consistent with the way that direntry names are stored. Please note that this function is never used on the top-level .git directory; it is always called for directories at level .git/refs or deeper. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Apr 25, 2012 at 00:45 UTC
abc390989f1086aa3a8620a81f87622a78cf393b
1 file changed
+7
-7
refs.c
+7
-7
@@ -749,13 +749,17 @@ void add_packed_ref(const char *refname, const unsigned char *sha1)
749
create_ref_entry(refname, sha1, REF_ISPACKED, 1));
750
}
751
752
+/*
753
+ * Read the loose references for refs from the namespace dirname.
754
+ * dirname must end with '/'.
755
+ */
756
static void get_ref_dir(struct ref_cache *refs, const char *dirname,
757
struct ref_dir *dir)
758
{
759
DIR *d;
760
const char *path;
761
struct dirent *de;
758
- int dirnamelen;
762
+ int dirnamelen = strlen(dirname);
763
struct strbuf refname;
764
765
if (*refs->name)
@@ -767,13 +771,8 @@ static void get_ref_dir(struct ref_cache *refs, const char *dirname,
771
if (!d)
772
return;
773
770
- dirnamelen = strlen(dirname);
774
strbuf_init(&refname, dirnamelen + 257);
775
strbuf_add(&refname, dirname, dirnamelen);
773
- if (dirnamelen && dirname[dirnamelen-1] != '/') {
774
- strbuf_addch(&refname, '/');
775
- dirnamelen++;
776
- }
776
777
while ((de = readdir(d)) != NULL) {
778
unsigned char sha1[20];
@@ -792,6 +791,7 @@ static void get_ref_dir(struct ref_cache *refs, const char *dirname,
791
if (stat(refdir, &st) < 0) {
792
; /* silently ignore */
793
} else if (S_ISDIR(st.st_mode)) {
794
+ strbuf_addch(&refname, '/');
795
get_ref_dir(refs, refname.buf, dir);
796
} else {
797
if (*refs->name) {
@@ -816,7 +816,7 @@ static void get_ref_dir(struct ref_cache *refs, const char *dirname,
816
static struct ref_dir *get_loose_refs(struct ref_cache *refs)
817
{
818
if (!refs->did_loose) {
819
- get_ref_dir(refs, "refs", &refs->loose);
819
+ get_ref_dir(refs, "refs/", &refs->loose);
820
refs->did_loose = 1;
821
}
822
return &refs->loose;