提交 e5dbf605 编写于 作者: M Michael Haggerty 提交者: Junio C Hamano

Allocate cached_refs objects dynamically

Signed-off-by: NMichael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 db4dd93a
...@@ -157,7 +157,7 @@ static struct cached_refs { ...@@ -157,7 +157,7 @@ static struct cached_refs {
char did_packed; char did_packed;
struct ref_list *loose; struct ref_list *loose;
struct ref_list *packed; struct ref_list *packed;
} cached_refs, submodule_refs; } *cached_refs, *submodule_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;
...@@ -181,6 +181,15 @@ static void clear_cached_refs(struct cached_refs *ca) ...@@ -181,6 +181,15 @@ static void clear_cached_refs(struct cached_refs *ca)
ca->did_loose = ca->did_packed = 0; 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 * Return a pointer to a cached_refs for the specified submodule. For
* the main repository, use submodule==NULL. The returned structure * the main repository, use submodule==NULL. The returned structure
...@@ -189,12 +198,17 @@ static void clear_cached_refs(struct cached_refs *ca) ...@@ -189,12 +198,17 @@ static void clear_cached_refs(struct cached_refs *ca)
*/ */
static struct cached_refs *get_cached_refs(const char *submodule) static struct cached_refs *get_cached_refs(const char *submodule)
{ {
if (!submodule) if (!submodule) {
return &cached_refs; if (!cached_refs)
else { cached_refs = create_cached_refs();
/* For now, don't reuse the refs cache for submodules. */ return cached_refs;
clear_cached_refs(&submodule_refs); } else {
return &submodule_refs; 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;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册