Store the submodule name in struct cached_refs

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 ce40979cf83c4c92421f9dd56cc4eabb67c85f29
1 file changed +11 -4
refs.c
+11 -4
@@ -157,6 +157,8 @@ static struct cached_refs {
157 char did_packed;
158 struct ref_list *loose;
159 struct ref_list *packed;
160 + /* The submodule name, or "" for the main repo. */
161 + char name[FLEX_ARRAY];
162 } *cached_refs, *submodule_refs;
163 static struct ref_list *current_ref;
164
@@ -181,12 +183,17 @@ static void clear_cached_refs(struct cached_refs *ca)
183 ca->did_loose = ca->did_packed = 0;
184 }
185
184 -struct cached_refs *create_cached_refs(void)
186 +struct cached_refs *create_cached_refs(const char *submodule)
187 {
188 + int len;
189 struct cached_refs *refs;
187 - refs = xmalloc(sizeof(struct cached_refs));
190 + if (!submodule)
191 + submodule = "";
192 + len = strlen(submodule) + 1;
193 + refs = xmalloc(sizeof(struct cached_refs) + len);
194 refs->did_loose = refs->did_packed = 0;
195 refs->loose = refs->packed = NULL;
196 + memcpy(refs->name, submodule, len);
197 return refs;
198 }
199
@@ -200,11 +207,11 @@ static struct cached_refs *get_cached_refs(const char *submodule)
207 {
208 if (!submodule) {
209 if (!cached_refs)
203 - cached_refs = create_cached_refs();
210 + cached_refs = create_cached_refs(submodule);
211 return cached_refs;
212 } else {
213 if (!submodule_refs)
207 - submodule_refs = create_cached_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);