aboutsummaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2011-08-13 00:36:25 +0200
committerJunio C Hamano <gitster@pobox.com>2011-08-14 15:18:52 -0700
commit4349a66805129ba11121b8a5eaf3f81cfd30bdd5 (patch)
treeaca3ee50d3af01cf34791e2c99c8d0d76847577c /refs.c
parentf130b1168e95f51dcd6c7f3667b14bd244a9c61e (diff)
downloadgit-4349a66805129ba11121b8a5eaf3f81cfd30bdd5.tar.gz
git-4349a66805129ba11121b8a5eaf3f81cfd30bdd5.tar.xz
Access reference caches only through new function get_cached_refs()
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.c54
1 files changed, 32 insertions, 22 deletions
diff --git a/refs.c b/refs.c
index 9dc25c398..df4ce4228 100644
--- a/refs.c
+++ b/refs.c
@@ -181,9 +181,26 @@ static void clear_cached_refs(struct cached_refs *ca)
ca->did_loose = ca->did_packed = 0;
}
+/*
+ * Return a pointer to a cached_refs for the specified submodule. For
+ * the main repository, use submodule==NULL. The returned structure
+ * will be allocated and initialized but not necessarily populated; it
+ * should not be freed.
+ */
+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;
+ }
+}
+
static void invalidate_cached_refs(void)
{
- clear_cached_refs(&cached_refs);
+ clear_cached_refs(get_cached_refs(NULL));
}
static void read_packed_refs(FILE *f, struct cached_refs *cached_refs)
@@ -234,20 +251,17 @@ void clear_extra_refs(void)
static struct ref_list *get_packed_refs(const char *submodule)
{
- const char *packed_refs_file;
- struct cached_refs *refs;
+ struct cached_refs *refs = get_cached_refs(submodule);
- if (submodule) {
- packed_refs_file = git_path_submodule(submodule, "packed-refs");
- refs = &submodule_refs;
- free_ref_list(refs->packed);
- } else {
- packed_refs_file = git_path("packed-refs");
- refs = &cached_refs;
- }
+ if (!refs->did_packed) {
+ const char *packed_refs_file;
+ FILE *f;
- if (!refs->did_packed || submodule) {
- FILE *f = fopen(packed_refs_file, "r");
+ if (submodule)
+ packed_refs_file = git_path_submodule(submodule, "packed-refs");
+ else
+ packed_refs_file = git_path("packed-refs");
+ f = fopen(packed_refs_file, "r");
refs->packed = NULL;
if (f) {
read_packed_refs(f, refs);
@@ -361,17 +375,13 @@ void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname)
static struct ref_list *get_loose_refs(const char *submodule)
{
- if (submodule) {
- free_ref_list(submodule_refs.loose);
- submodule_refs.loose = get_ref_dir(submodule, "refs", NULL);
- return submodule_refs.loose;
- }
+ struct cached_refs *refs = get_cached_refs(submodule);
- if (!cached_refs.did_loose) {
- cached_refs.loose = get_ref_dir(NULL, "refs", NULL);
- cached_refs.did_loose = 1;
+ if (!refs->did_loose) {
+ refs->loose = get_ref_dir(submodule, "refs", NULL);
+ refs->did_loose = 1;
}
- return cached_refs.loose;
+ return refs->loose;
}
/* We allow "recursive" symbolic refs. Only within reason, though */