summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2012-04-27 00:27:05 +0200
committerJunio C Hamano <gitster@pobox.com>2012-05-03 13:15:36 -0700
commitf006c42a11d5e97f5abc07b23f353ca64d5180e2 (patch)
tree7415a53797a24d3747ee52e11e6c613953e6d3cd /refs.c
parent3f3aa1bc6215fad0d31d1eae5f4c599c6847a02f (diff)
downloadgit-f006c42a11d5e97f5abc07b23f353ca64d5180e2.tar.gz
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>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/refs.c b/refs.c
index 4af08809ab..6720b90201 100644
--- a/refs.c
+++ b/refs.c
@@ -106,6 +106,8 @@ struct ref_value {
unsigned char peeled[20];
};
+struct ref_cache;
+
struct ref_dir {
int nr, alloc;
@@ -117,6 +119,9 @@ struct ref_dir {
*/
int sorted;
+ /* A pointer to the ref_cache that contains this ref_dir. */
+ struct ref_cache *ref_cache;
+
struct ref_entry **entries;
};
@@ -234,12 +239,14 @@ 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->u.subdir.ref_cache = ref_cache;
direntry->flag = REF_DIR;
return direntry;
}
@@ -296,7 +303,7 @@ static struct ref_dir *search_for_subdir(struct ref_dir *dir,
if (!entry) {
if (!mkdir)
return NULL;
- entry = create_dir_entry(subdirname);
+ entry = create_dir_entry(dir->ref_cache, subdirname);
add_entry_to_dir(dir, entry);
}
return get_ref_dir(entry);
@@ -753,7 +760,7 @@ static struct ref_dir *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
@@ -843,7 +850,7 @@ static void read_loose_refs(struct ref_cache *refs, const char *dirname,
static struct ref_dir *get_loose_refs(struct ref_cache *refs)
{
if (!refs->loose) {
- refs->loose = create_dir_entry("");
+ refs->loose = create_dir_entry(refs, "");
read_loose_refs(refs, "refs/",
search_for_subdir(get_ref_dir(refs->loose),
"refs/", 1));