Allocate cached_refs objects dynamically
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
e5dbf6056faecbd9a3c5510f5c5cd73de10374b8
1 file changed
+21
-7
refs.c
+21
-7
@@ -157,7 +157,7 @@ static struct cached_refs {
157
char did_packed;
158
struct ref_list *loose;
159
struct ref_list *packed;
160
-} cached_refs, submodule_refs;
160
+} *cached_refs, *submodule_refs;
161
static struct ref_list *current_ref;
162
163
static struct ref_list *extra_refs;
@@ -181,6 +181,15 @@ static void clear_cached_refs(struct cached_refs *ca)
181
ca->did_loose = ca->did_packed = 0;
182
}
183
184
+struct cached_refs *create_cached_refs(void)
185
+{
186
+ struct cached_refs *refs;
187
+ refs = xmalloc(sizeof(struct cached_refs));
188
+ refs->did_loose = refs->did_packed = 0;
189
+ refs->loose = refs->packed = NULL;
190
+ return refs;
191
+}
192
+
193
/*
194
* Return a pointer to a cached_refs for the specified submodule. For
195
* the main repository, use submodule==NULL. The returned structure
@@ -189,12 +198,17 @@ static void clear_cached_refs(struct cached_refs *ca)
198
*/
199
static struct cached_refs *get_cached_refs(const char *submodule)
200
{
192
- if (!submodule)
193
- return &cached_refs;
194
- else {
195
- /* For now, don't reuse the refs cache for submodules. */
196
- clear_cached_refs(&submodule_refs);
197
- return &submodule_refs;
201
+ if (!submodule) {
202
+ if (!cached_refs)
203
+ cached_refs = create_cached_refs();
204
+ return cached_refs;
205
+ } else {
206
+ if (!submodule_refs)
207
+ submodule_refs = create_cached_refs();
208
+ else
209
+ /* For now, don't reuse the refs cache for submodules. */
210
+ clear_cached_refs(submodule_refs);
211
+ return submodule_refs;
212
}
213
}
214