get_ref_dir(): take the containing directory as argument

Previously, the "dir" argument to get_ref_dir() was a pointer to the top-level ref_dir. Change the function to expect a pointer to the ref_dir corresponding to dirname. This allows entries to be added directly to dir, without having to recurse through the reference trie each time (i.e., we can use add_entry_to_dir() instead of add_ref()). 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 9f2fb4a3737c86e245ce365f6ad8f901ad397d6f
1 file changed +8 -4
refs.c
+8 -4
@@ -765,7 +765,8 @@ void add_packed_ref(const char *refname, const unsigned char *sha1)
765
766 /*
767 * Read the loose references for refs from the namespace dirname.
768 - * dirname must end with '/'.
768 + * dirname must end with '/'. dir must be the directory entry
769 + * corresponding to dirname.
770 */
771 static void get_ref_dir(struct ref_cache *refs, const char *dirname,
772 struct ref_dir *dir)
@@ -806,7 +807,8 @@ static void get_ref_dir(struct ref_cache *refs, const char *dirname,
807 ; /* silently ignore */
808 } else if (S_ISDIR(st.st_mode)) {
809 strbuf_addch(&refname, '/');
809 - get_ref_dir(refs, refname.buf, dir);
810 + get_ref_dir(refs, refname.buf,
811 + &search_for_subdir(dir, refname.buf, 1)->u.subdir);
812 } else {
813 if (*refs->name) {
814 hashclr(sha1);
@@ -819,7 +821,8 @@ static void get_ref_dir(struct ref_cache *refs, const char *dirname,
821 hashclr(sha1);
822 flag |= REF_ISBROKEN;
823 }
822 - add_ref(dir, create_ref_entry(refname.buf, sha1, flag, 1));
824 + add_entry_to_dir(dir,
825 + create_ref_entry(refname.buf, sha1, flag, 1));
826 }
827 strbuf_setlen(&refname, dirnamelen);
828 }
@@ -830,7 +833,8 @@ static void get_ref_dir(struct ref_cache *refs, const char *dirname,
833 static struct ref_dir *get_loose_refs(struct ref_cache *refs)
834 {
835 if (!refs->did_loose) {
833 - get_ref_dir(refs, "refs/", &refs->loose);
836 + get_ref_dir(refs, "refs/",
837 + &search_for_subdir(&refs->loose, "refs/", 1)->u.subdir);
838 refs->did_loose = 1;
839 }
840 return &refs->loose;