Retain caches of submodule refs
Instead of keeping track of one cache for refs in the main repo and another single cache shared among submodules, keep a linked list of cached_refs objects, one for each module/submodule. Change invalidate_cached_refs() to invalidate all caches. (Previously, it only invalidated the cache of the main repo because the submodule caches were not reused anyway.) Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
ce40979cf8
commit
0e88c130f2
34
refs.c
34
refs.c
@ -153,13 +153,15 @@ static struct ref_list *sort_ref_list(struct ref_list *list)
|
|||||||
* when doing a full libification.
|
* when doing a full libification.
|
||||||
*/
|
*/
|
||||||
static struct cached_refs {
|
static struct cached_refs {
|
||||||
|
struct cached_refs *next;
|
||||||
char did_loose;
|
char did_loose;
|
||||||
char did_packed;
|
char did_packed;
|
||||||
struct ref_list *loose;
|
struct ref_list *loose;
|
||||||
struct ref_list *packed;
|
struct ref_list *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];
|
||||||
} *cached_refs, *submodule_refs;
|
} *cached_refs;
|
||||||
|
|
||||||
static struct ref_list *current_ref;
|
static struct ref_list *current_ref;
|
||||||
|
|
||||||
static struct ref_list *extra_refs;
|
static struct ref_list *extra_refs;
|
||||||
@ -191,6 +193,7 @@ struct cached_refs *create_cached_refs(const char *submodule)
|
|||||||
submodule = "";
|
submodule = "";
|
||||||
len = strlen(submodule) + 1;
|
len = strlen(submodule) + 1;
|
||||||
refs = xmalloc(sizeof(struct cached_refs) + len);
|
refs = xmalloc(sizeof(struct cached_refs) + len);
|
||||||
|
refs->next = NULL;
|
||||||
refs->did_loose = refs->did_packed = 0;
|
refs->did_loose = refs->did_packed = 0;
|
||||||
refs->loose = refs->packed = NULL;
|
refs->loose = refs->packed = NULL;
|
||||||
memcpy(refs->name, submodule, len);
|
memcpy(refs->name, submodule, len);
|
||||||
@ -205,23 +208,28 @@ struct cached_refs *create_cached_refs(const char *submodule)
|
|||||||
*/
|
*/
|
||||||
static struct cached_refs *get_cached_refs(const char *submodule)
|
static struct cached_refs *get_cached_refs(const char *submodule)
|
||||||
{
|
{
|
||||||
if (!submodule) {
|
struct cached_refs *refs = cached_refs;
|
||||||
if (!cached_refs)
|
if (!submodule)
|
||||||
cached_refs = create_cached_refs(submodule);
|
submodule = "";
|
||||||
return cached_refs;
|
while (refs) {
|
||||||
} else {
|
if (!strcmp(submodule, refs->name))
|
||||||
if (!submodule_refs)
|
return refs;
|
||||||
submodule_refs = create_cached_refs(submodule);
|
refs = refs->next;
|
||||||
else
|
|
||||||
/* For now, don't reuse the refs cache for submodules. */
|
|
||||||
clear_cached_refs(submodule_refs);
|
|
||||||
return submodule_refs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refs = create_cached_refs(submodule);
|
||||||
|
refs->next = cached_refs;
|
||||||
|
cached_refs = refs;
|
||||||
|
return refs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void invalidate_cached_refs(void)
|
static void invalidate_cached_refs(void)
|
||||||
{
|
{
|
||||||
clear_cached_refs(get_cached_refs(NULL));
|
struct cached_refs *refs = cached_refs;
|
||||||
|
while (refs) {
|
||||||
|
clear_cached_refs(refs);
|
||||||
|
refs = refs->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ref_list *read_packed_refs(FILE *f)
|
static struct ref_list *read_packed_refs(FILE *f)
|
||||||
|
Reference in New Issue
Block a user