aboutsummaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2011-08-13 00:36:27 +0200
committerJunio C Hamano <gitster@pobox.com>2011-08-14 15:18:52 -0700
commite5dbf6056faecbd9a3c5510f5c5cd73de10374b8 (patch)
tree1d13c2d252a3c3365fb8132d5cc57f704b1fee62 /refs.c
parentdb4dd93a4a3553c61b416db924520b55bfee5f7e (diff)
downloadgit-e5dbf6056faecbd9a3c5510f5c5cd73de10374b8.tar.gz
git-e5dbf6056faecbd9a3c5510f5c5cd73de10374b8.tar.xz
Allocate cached_refs objects dynamically
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/refs.c b/refs.c
index 10aebcc68..b325fc71f 100644
--- a/refs.c
+++ b/refs.c
@@ -157,7 +157,7 @@ static struct cached_refs {
char did_packed;
struct ref_list *loose;
struct ref_list *packed;
-} cached_refs, submodule_refs;
+} *cached_refs, *submodule_refs;
static struct ref_list *current_ref;
static struct ref_list *extra_refs;
@@ -181,6 +181,15 @@ static void clear_cached_refs(struct cached_refs *ca)
ca->did_loose = ca->did_packed = 0;
}
+struct cached_refs *create_cached_refs(void)
+{
+ struct cached_refs *refs;
+ refs = xmalloc(sizeof(struct cached_refs));
+ refs->did_loose = refs->did_packed = 0;
+ refs->loose = refs->packed = NULL;
+ return refs;
+}
+
/*
* Return a pointer to a cached_refs for the specified submodule. For
* the main repository, use submodule==NULL. The returned structure
@@ -189,12 +198,17 @@ static void clear_cached_refs(struct cached_refs *ca)
*/
static struct cached_refs *get_cached_refs(const char *submodule)
{
- if (!submodule)
- return &cached_refs;
- else {
- /* For now, don't reuse the refs cache for submodules. */
- clear_cached_refs(&submodule_refs);
- return &submodule_refs;
+ if (!submodule) {
+ if (!cached_refs)
+ cached_refs = create_cached_refs();
+ return cached_refs;
+ } else {
+ if (!submodule_refs)
+ submodule_refs = create_cached_refs();
+ else
+ /* For now, don't reuse the refs cache for submodules. */
+ clear_cached_refs(submodule_refs);
+ return submodule_refs;
}
}