struct ref_dir: store a reference to the enclosing ref_cache

This means that a directory ref_entry contains all of the information needed by read_loose_refs(). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Apr 27, 2012 at 00:27 UTC f006c42a11d5e97f5abc07b23f353ca64d5180e2
1 file changed +11 -4
refs.c
+11 -4
@@ -106,6 +106,8 @@ struct ref_value {
106 unsigned char peeled[20];
107 };
108
109 +struct ref_cache;
110 +
111 struct ref_dir {
112 int nr, alloc;
113
@@ -117,6 +119,9 @@ struct ref_dir {
119 */
120 int sorted;
121
122 + /* A pointer to the ref_cache that contains this ref_dir. */
123 + struct ref_cache *ref_cache;
124 +
125 struct ref_entry **entries;
126 };
127
@@ -234,12 +239,14 @@ static void clear_ref_dir(struct ref_dir *dir)
239 * dirname is the name of the directory with a trailing slash (e.g.,
240 * "refs/heads/") or "" for the top-level directory.
241 */
237 -static struct ref_entry *create_dir_entry(const char *dirname)
242 +static struct ref_entry *create_dir_entry(struct ref_cache *ref_cache,
243 + const char *dirname)
244 {
245 struct ref_entry *direntry;
246 int len = strlen(dirname);
247 direntry = xcalloc(1, sizeof(struct ref_entry) + len + 1);
248 memcpy(direntry->name, dirname, len + 1);
249 + direntry->u.subdir.ref_cache = ref_cache;
250 direntry->flag = REF_DIR;
251 return direntry;
252 }
@@ -296,7 +303,7 @@ static struct ref_dir *search_for_subdir(struct ref_dir *dir,
303 if (!entry) {
304 if (!mkdir)
305 return NULL;
299 - entry = create_dir_entry(subdirname);
306 + entry = create_dir_entry(dir->ref_cache, subdirname);
307 add_entry_to_dir(dir, entry);
308 }
309 return get_ref_dir(entry);
@@ -753,7 +760,7 @@ static struct ref_dir *get_packed_refs(struct ref_cache *refs)
760 const char *packed_refs_file;
761 FILE *f;
762
756 - refs->packed = create_dir_entry("");
763 + refs->packed = create_dir_entry(refs, "");
764 if (*refs->name)
765 packed_refs_file = git_path_submodule(refs->name, "packed-refs");
766 else
@@ -843,7 +850,7 @@ static void read_loose_refs(struct ref_cache *refs, const char *dirname,
850 static struct ref_dir *get_loose_refs(struct ref_cache *refs)
851 {
852 if (!refs->loose) {
846 - refs->loose = create_dir_entry("");
853 + refs->loose = create_dir_entry(refs, "");
854 read_loose_refs(refs, "refs/",
855 search_for_subdir(get_ref_dir(refs->loose),
856 "refs/", 1));