diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2011-12-12 06:38:53 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-12-12 09:08:56 -0800 |
commit | 21969924c3835de3af353181ea015a17211b118a (patch) | |
tree | 207ce6afea9339953e2e1e66ad05e54c2c52eb4c | |
parent | dd7c62b468a233d5378860243f18cb86955776de (diff) | |
download | git-21969924c3835de3af353181ea015a17211b118a.tar.gz |
struct ref_dir: store a reference to the enclosing ref_cache
This means that it contains enough information to serve as the sole
argument to get_ref_dir(), which will be changed in the next commit.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | refs.c | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -106,6 +106,8 @@ struct ref_value { unsigned char peeled[20]; }; +struct ref_cache; + struct ref_dir { int nr, alloc; @@ -113,6 +115,12 @@ struct ref_dir { int sorted; struct ref_entry **entries; + + /* + * A pointer to the ref_cache that contains this ref_dir, or + * NULL if this ref_dir is used for extra_refs. + */ + struct ref_cache *ref_cache; }; /* ISSYMREF=0x01, ISPACKED=0x02, and ISBROKEN=0x04 are public interfaces */ @@ -226,13 +234,15 @@ static void clear_ref_dir(struct ref_dir *dir) * dirname is the name of the directory with a trailing slash (e.g., * "refs/heads/") or "" for the top-level directory. */ -static struct ref_entry *create_dir_entry(const char *dirname) +static struct ref_entry *create_dir_entry(struct ref_cache *ref_cache, + const char *dirname) { struct ref_entry *direntry; int len = strlen(dirname); direntry = xcalloc(1, sizeof(struct ref_entry) + len + 1); memcpy(direntry->name, dirname, len + 1); direntry->flag = REF_DIR; + direntry->u.subdir.ref_cache = ref_cache; return direntry; } @@ -312,7 +322,8 @@ static struct ref_entry *find_containing_direntry(struct ref_entry *direntry, direntry = NULL; break; } - entry = create_dir_entry(refname_copy); + entry = create_dir_entry(direntry->u.subdir.ref_cache, + refname_copy); add_entry(direntry, entry); } slash[1] = tmp; @@ -726,7 +737,7 @@ static void read_packed_refs(FILE *f, struct ref_entry *direntry) void add_extra_ref(const char *refname, const unsigned char *sha1, int flag) { if (!extra_refs) - extra_refs = create_dir_entry(""); + extra_refs = create_dir_entry(NULL, ""); add_ref(extra_refs, create_ref_entry(refname, sha1, flag, 0)); } @@ -744,7 +755,7 @@ static struct ref_entry *get_packed_refs(struct ref_cache *refs) const char *packed_refs_file; FILE *f; - refs->packed = create_dir_entry(""); + refs->packed = create_dir_entry(refs, ""); if (*refs->name) packed_refs_file = git_path_submodule(refs->name, "packed-refs"); else @@ -835,7 +846,7 @@ static void get_ref_dir(struct ref_cache *refs, const char *dirname) static struct ref_entry *get_loose_refs(struct ref_cache *refs) { if (!refs->loose) { - refs->loose = create_dir_entry(""); + refs->loose = create_dir_entry(refs, ""); get_ref_dir(refs, "refs/"); } return refs->loose; |