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>
Michael Haggerty committed
Aug 13, 2011 at 00:36 UTC
0e88c130f2f6309932464d4919725e54837978c7
1 file changed
+21
-13
refs.c
+21
-13
@@ -153,13 +153,15 @@ static struct ref_list *sort_ref_list(struct ref_list *list)
153
* when doing a full libification.
154
*/
155
static struct cached_refs {
156
+ struct cached_refs *next;
157
char did_loose;
158
char did_packed;
159
struct ref_list *loose;
160
struct ref_list *packed;
161
/* The submodule name, or "" for the main repo. */
162
char name[FLEX_ARRAY];
162
-} *cached_refs, *submodule_refs;
163
+} *cached_refs;
164
+
165
static struct ref_list *current_ref;
166
167
static struct ref_list *extra_refs;
@@ -191,6 +193,7 @@ struct cached_refs *create_cached_refs(const char *submodule)
193
submodule = "";
194
len = strlen(submodule) + 1;
195
refs = xmalloc(sizeof(struct cached_refs) + len);
196
+ refs->next = NULL;
197
refs->did_loose = refs->did_packed = 0;
198
refs->loose = refs->packed = NULL;
199
memcpy(refs->name, submodule, len);
@@ -205,23 +208,28 @@ struct cached_refs *create_cached_refs(const char *submodule)
208
*/
209
static struct cached_refs *get_cached_refs(const char *submodule)
210
{
208
- if (!submodule) {
209
- if (!cached_refs)
210
- cached_refs = create_cached_refs(submodule);
211
- return cached_refs;
212
- } else {
213
- if (!submodule_refs)
214
- submodule_refs = create_cached_refs(submodule);
215
- else
216
- /* For now, don't reuse the refs cache for submodules. */
217
- clear_cached_refs(submodule_refs);
218
- return submodule_refs;
211
+ struct cached_refs *refs = cached_refs;
212
+ if (!submodule)
213
+ submodule = "";
214
+ while (refs) {
215
+ if (!strcmp(submodule, refs->name))
216
+ return refs;
217
+ refs = refs->next;
218
}
219
+
220
+ refs = create_cached_refs(submodule);
221
+ refs->next = cached_refs;
222
+ cached_refs = refs;
223
+ return refs;
224
}
225
226
static void invalidate_cached_refs(void)
227
{
224
- clear_cached_refs(get_cached_refs(NULL));
228
+ struct cached_refs *refs = cached_refs;
229
+ while (refs) {
230
+ clear_cached_refs(refs);
231
+ refs = refs->next;
232
+ }
233
}
234
235
static struct ref_list *read_packed_refs(FILE *f)