refs: wrap top-level ref_dirs in ref_entries
Make it turtles all the way down. This affects the loose and packed fields of ref_cache instances. 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
d12229f532dc88024c249fb3e2ca0ac921cc14a9
1 file changed
+19
-18
refs.c
+19
-18
@@ -607,26 +607,26 @@ static int is_refname_available(const char *refname, const char *oldrefname,
607
*/
608
static struct ref_cache {
609
struct ref_cache *next;
610
- char did_loose;
611
- char did_packed;
612
- struct ref_dir loose;
613
- struct ref_dir packed;
610
+ struct ref_entry *loose;
611
+ struct ref_entry *packed;
612
/* The submodule name, or "" for the main repo. */
613
char name[FLEX_ARRAY];
614
} *ref_cache;
615
616
static void clear_packed_ref_cache(struct ref_cache *refs)
617
{
620
- if (refs->did_packed)
621
- clear_ref_dir(&refs->packed);
622
- refs->did_packed = 0;
618
+ if (refs->packed) {
619
+ free_ref_entry(refs->packed);
620
+ refs->packed = NULL;
621
+ }
622
}
623
624
static void clear_loose_ref_cache(struct ref_cache *refs)
625
{
627
- if (refs->did_loose)
628
- clear_ref_dir(&refs->loose);
629
- refs->did_loose = 0;
626
+ if (refs->loose) {
627
+ free_ref_entry(refs->loose);
628
+ refs->loose = NULL;
629
+ }
630
}
631
632
static struct ref_cache *create_ref_cache(const char *submodule)
@@ -740,22 +740,22 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
740
741
static struct ref_dir *get_packed_refs(struct ref_cache *refs)
742
{
743
- if (!refs->did_packed) {
743
+ if (!refs->packed) {
744
const char *packed_refs_file;
745
FILE *f;
746
747
+ refs->packed = create_dir_entry("");
748
if (*refs->name)
749
packed_refs_file = git_path_submodule(refs->name, "packed-refs");
750
else
751
packed_refs_file = git_path("packed-refs");
752
f = fopen(packed_refs_file, "r");
753
if (f) {
753
- read_packed_refs(f, &refs->packed);
754
+ read_packed_refs(f, &refs->packed->u.subdir);
755
fclose(f);
756
}
756
- refs->did_packed = 1;
757
}
758
- return &refs->packed;
758
+ return &refs->packed->u.subdir;
759
}
760
761
void add_packed_ref(const char *refname, const unsigned char *sha1)
@@ -833,12 +833,13 @@ static void get_ref_dir(struct ref_cache *refs, const char *dirname,
833
834
static struct ref_dir *get_loose_refs(struct ref_cache *refs)
835
{
836
- if (!refs->did_loose) {
836
+ if (!refs->loose) {
837
+ refs->loose = create_dir_entry("");
838
get_ref_dir(refs, "refs/",
838
- &search_for_subdir(&refs->loose, "refs/", 1)->u.subdir);
839
- refs->did_loose = 1;
839
+ &search_for_subdir(&refs->loose->u.subdir,
840
+ "refs/", 1)->u.subdir);
841
}
841
- return &refs->loose;
842
+ return &refs->loose->u.subdir;
843
}
844
845
/* We allow "recursive" symbolic refs. Only within reason, though */