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>
This commit is contained in:
parent
5fa0441844
commit
d12229f532
37
refs.c
37
refs.c
@ -607,26 +607,26 @@ static int is_refname_available(const char *refname, const char *oldrefname,
|
|||||||
*/
|
*/
|
||||||
static struct ref_cache {
|
static struct ref_cache {
|
||||||
struct ref_cache *next;
|
struct ref_cache *next;
|
||||||
char did_loose;
|
struct ref_entry *loose;
|
||||||
char did_packed;
|
struct ref_entry *packed;
|
||||||
struct ref_dir loose;
|
|
||||||
struct ref_dir packed;
|
|
||||||
/* The submodule name, or "" for the main repo. */
|
/* The submodule name, or "" for the main repo. */
|
||||||
char name[FLEX_ARRAY];
|
char name[FLEX_ARRAY];
|
||||||
} *ref_cache;
|
} *ref_cache;
|
||||||
|
|
||||||
static void clear_packed_ref_cache(struct ref_cache *refs)
|
static void clear_packed_ref_cache(struct ref_cache *refs)
|
||||||
{
|
{
|
||||||
if (refs->did_packed)
|
if (refs->packed) {
|
||||||
clear_ref_dir(&refs->packed);
|
free_ref_entry(refs->packed);
|
||||||
refs->did_packed = 0;
|
refs->packed = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clear_loose_ref_cache(struct ref_cache *refs)
|
static void clear_loose_ref_cache(struct ref_cache *refs)
|
||||||
{
|
{
|
||||||
if (refs->did_loose)
|
if (refs->loose) {
|
||||||
clear_ref_dir(&refs->loose);
|
free_ref_entry(refs->loose);
|
||||||
refs->did_loose = 0;
|
refs->loose = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ref_cache *create_ref_cache(const char *submodule)
|
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)
|
|||||||
|
|
||||||
static struct ref_dir *get_packed_refs(struct ref_cache *refs)
|
static struct ref_dir *get_packed_refs(struct ref_cache *refs)
|
||||||
{
|
{
|
||||||
if (!refs->did_packed) {
|
if (!refs->packed) {
|
||||||
const char *packed_refs_file;
|
const char *packed_refs_file;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
|
refs->packed = create_dir_entry("");
|
||||||
if (*refs->name)
|
if (*refs->name)
|
||||||
packed_refs_file = git_path_submodule(refs->name, "packed-refs");
|
packed_refs_file = git_path_submodule(refs->name, "packed-refs");
|
||||||
else
|
else
|
||||||
packed_refs_file = git_path("packed-refs");
|
packed_refs_file = git_path("packed-refs");
|
||||||
f = fopen(packed_refs_file, "r");
|
f = fopen(packed_refs_file, "r");
|
||||||
if (f) {
|
if (f) {
|
||||||
read_packed_refs(f, &refs->packed);
|
read_packed_refs(f, &refs->packed->u.subdir);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
refs->did_packed = 1;
|
|
||||||
}
|
}
|
||||||
return &refs->packed;
|
return &refs->packed->u.subdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_packed_ref(const char *refname, const unsigned char *sha1)
|
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,
|
|||||||
|
|
||||||
static struct ref_dir *get_loose_refs(struct ref_cache *refs)
|
static struct ref_dir *get_loose_refs(struct ref_cache *refs)
|
||||||
{
|
{
|
||||||
if (!refs->did_loose) {
|
if (!refs->loose) {
|
||||||
|
refs->loose = create_dir_entry("");
|
||||||
get_ref_dir(refs, "refs/",
|
get_ref_dir(refs, "refs/",
|
||||||
&search_for_subdir(&refs->loose, "refs/", 1)->u.subdir);
|
&search_for_subdir(&refs->loose->u.subdir,
|
||||||
refs->did_loose = 1;
|
"refs/", 1)->u.subdir);
|
||||||
}
|
}
|
||||||
return &refs->loose;
|
return &refs->loose->u.subdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We allow "recursive" symbolic refs. Only within reason, though */
|
/* We allow "recursive" symbolic refs. Only within reason, though */
|
||||||
|
Loading…
Reference in New Issue
Block a user