Michael Haggerty <mhagger@xxxxxxxxxxxx> writes: > Signed-off-by: Michael Haggerty <mhagger@xxxxxxxxxxxx> > --- > refs.c | 54 +++++++++++++++++++++++++++++++----------------------- > 1 files changed, 31 insertions(+), 23 deletions(-) > > diff --git a/refs.c b/refs.c > index b0c8308..89840d7 100644 > --- a/refs.c > +++ b/refs.c > @@ -181,9 +181,26 @@ static void clear_cached_refs(struct cached_refs *ca) > ca->did_loose = ca->did_packed = 0; > } > > +/* > + * Return a pointer to a cached_refs for the specified submodule. For > + * the main repository, use submodule==NULL. The returned structure > + * will be allocated and initialized but not necessarily populated; it > + * should not be freed. > + */ > +static struct cached_refs *get_cached_refs(const char *submodule) > +{ > + if (! submodule) (style) lose the SP before "submodule". > + return &cached_refs; > + else { > + /* For now, don't reuse the refs cache for submodules. */ > + clear_cached_refs(&submodule_refs); > + return &submodule_refs; > + } > +} > + > static void invalidate_cached_refs(void) > { > - clear_cached_refs(&cached_refs); > + clear_cached_refs(get_cached_refs(NULL)); > } > > static void read_packed_refs(FILE *f, struct cached_refs *cached_refs) > @@ -234,19 +251,14 @@ void clear_extra_refs(void) > > static struct ref_list *get_packed_refs(const char *submodule) > { > - const char *packed_refs_file; > - struct cached_refs *refs; > + struct cached_refs *refs = get_cached_refs(submodule); > > - if (submodule) { > - packed_refs_file = git_path_submodule(submodule, "packed-refs"); > - refs = &submodule_refs; > - free_ref_list(refs->packed); > - } else { > - packed_refs_file = git_path("packed-refs"); > - refs = &cached_refs; > - } > - > - if (!refs->did_packed || submodule) { > + if (!refs->did_packed) { > + const char *packed_refs_file; > + if (submodule) > + packed_refs_file = git_path_submodule(submodule, "packed-refs"); > + else > + packed_refs_file = git_path("packed-refs"); > FILE *f = fopen(packed_refs_file, "r"); decl-after-statement. > refs->packed = NULL; > if (f) { > @@ -361,17 +373,13 @@ void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname) > > static struct ref_list *get_loose_refs(const char *submodule) > { > - if (submodule) { > - free_ref_list(submodule_refs.loose); > - submodule_refs.loose = get_ref_dir(submodule, "refs", NULL); > - return submodule_refs.loose; > - } > + struct cached_refs *refs = get_cached_refs(submodule); > > - if (!cached_refs.did_loose) { > - cached_refs.loose = get_ref_dir(NULL, "refs", NULL); > - cached_refs.did_loose = 1; > + if (!refs->did_loose) { > + refs->loose = get_ref_dir(submodule, "refs", NULL); > + refs->did_loose = 1; > } > - return cached_refs.loose; > + return refs->loose; > } > > /* We allow "recursive" symbolic refs. Only within reason, though */ -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html