git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
	Drew Northup <drew.northup@maine.edu>,
	Jakub Narebski <jnareb@gmail.com>,
	Michael Haggerty <mhagger@alum.mit.edu>
Subject: [PATCH 2/6] Access reference caches only through new function get_cached_refs().
Date: Sat, 13 Aug 2011 00:36:25 +0200	[thread overview]
Message-ID: <1313188589-2330-3-git-send-email-mhagger@alum.mit.edu> (raw)
In-Reply-To: <1313188589-2330-1-git-send-email-mhagger@alum.mit.edu>


Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 refs.c |   54 +++++++++++++++++++++++++++++++-----------------------
 1 files changed, 31 insertions(+), 23 deletions(-)

diff --git a/refs.c b/refs.c
index b0c8308..89840d7 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,19 +251,14 @@ 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 || submodule) {
+	if (!refs->did_packed) {
+		const char *packed_refs_file;
+		if (submodule)
+			packed_refs_file = git_path_submodule(submodule, "packed-refs");
+		else
+			packed_refs_file = git_path("packed-refs");
 		FILE *f = fopen(packed_refs_file, "r");
 		refs->packed = NULL;
 		if (f) {
@@ -361,17 +373,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 */
-- 
1.7.6.8.gd2879

  parent reply	other threads:[~2011-08-12 22:37 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-12 22:36 [PATCH 0/6] Retain caches of submodule refs Michael Haggerty
2011-08-12 22:36 ` [PATCH 1/6] Extract a function clear_cached_refs() Michael Haggerty
2011-08-12 22:36 ` Michael Haggerty [this message]
2011-08-14 22:12   ` [PATCH 2/6] Access reference caches only through new function get_cached_refs() Junio C Hamano
2011-08-23  4:21     ` Michael Haggerty
2011-08-12 22:36 ` [PATCH 3/6] Change the signature of read_packed_refs() Michael Haggerty
2011-08-12 22:36 ` [PATCH 4/6] Allocate cached_refs objects dynamically Michael Haggerty
2011-08-14 22:21   ` Junio C Hamano
2011-08-12 22:36 ` [PATCH 5/6] Store the submodule name in struct cached_refs Michael Haggerty
2011-08-12 22:36 ` [PATCH 6/6] Retain caches of submodule refs Michael Haggerty
2011-08-13 12:54   ` Heiko Voigt
2011-08-24  8:17     ` Michael Haggerty
2011-08-24 20:05       ` Heiko Voigt
2011-08-16 22:45   ` Junio C Hamano
2011-08-24 11:33     ` Michael Haggerty
2011-10-09 11:12     ` Michael Haggerty
2011-10-09 20:10       ` Junio C Hamano
2011-10-10  5:46         ` [PATCH 0/2] Provide API to invalidate refs cache Michael Haggerty
2011-10-10  5:46           ` [PATCH 1/2] invalidate_cached_refs(): take the submodule as parameter Michael Haggerty
2011-10-10  5:46           ` [PATCH 2/2] invalidate_cached_refs(): expose this function in refs API Michael Haggerty
2011-10-10  8:24           ` [PATCH v2 0/7] Provide API to invalidate refs cache Michael Haggerty
2011-10-10  8:24             ` [PATCH v2 1/7] invalidate_ref_cache(): rename function from invalidate_cached_refs() Michael Haggerty
2011-10-11  0:00               ` Junio C Hamano
2011-10-11  5:53                 ` Michael Haggerty
2011-10-10  8:24             ` [PATCH v2 2/7] invalidate_ref_cache(): take the submodule as parameter Michael Haggerty
2011-10-10  8:24             ` [PATCH v2 3/7] invalidate_ref_cache(): expose this function in refs API Michael Haggerty
2011-10-10  8:24             ` [PATCH v2 4/7] clear_cached_refs(): rename parameter Michael Haggerty
2011-10-10  8:24             ` [PATCH v2 5/7] clear_cached_refs(): extract two new functions Michael Haggerty
2011-10-10  8:24             ` [PATCH v2 6/7] write_ref_sha1(): only invalidate the loose ref cache Michael Haggerty
2011-10-10  8:24             ` [PATCH v2 7/7] clear_cached_refs(): inline function Michael Haggerty
2011-10-11  0:02             ` [PATCH v2 0/7] Provide API to invalidate refs cache Junio C Hamano
2011-10-11  5:50               ` Michael Haggerty
2011-10-11  8:09                 ` Julian Phillips
2011-10-11 17:26                 ` Junio C Hamano
2011-10-12 18:44               ` [PATCH v3 " Michael Haggerty
2011-10-12 18:44                 ` [PATCH v3 1/7] invalidate_ref_cache(): rename function from invalidate_cached_refs() Michael Haggerty
2011-10-12 19:14                   ` Junio C Hamano
2011-10-12 22:12                     ` Michael Haggerty
2011-10-12 18:44                 ` [PATCH v3 2/7] invalidate_ref_cache(): take the submodule as parameter Michael Haggerty
2011-10-12 19:19                   ` Junio C Hamano
2011-10-12 22:07                     ` Michael Haggerty
2011-10-17 18:00                       ` Junio C Hamano
2011-11-03 10:23                         ` Michael Haggerty
2011-11-03 18:57                           ` Junio C Hamano
2011-10-12 18:44                 ` [PATCH v3 3/7] invalidate_ref_cache(): expose this function in refs API Michael Haggerty
2011-10-12 18:44                 ` [PATCH v3 4/7] clear_cached_refs(): rename parameter Michael Haggerty
2011-10-12 18:44                 ` [PATCH v3 5/7] clear_cached_refs(): extract two new functions Michael Haggerty
2011-10-12 18:44                 ` [PATCH v3 6/7] write_ref_sha1(): only invalidate the loose ref cache Michael Haggerty
2011-10-12 18:44                 ` [PATCH v3 7/7] clear_cached_refs(): inline function Michael Haggerty
2011-10-12 19:28                 ` [PATCH v3 0/7] Provide API to invalidate refs cache Junio C Hamano
2011-10-10 19:53       ` Re: [PATCH 6/6] Retain caches of submodule refs Heiko Voigt
2011-10-11  4:12         ` Michael Haggerty
2011-10-11 17:41           ` Heiko Voigt
2011-08-13 12:34 ` [PATCH 0/6] " Heiko Voigt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1313188589-2330-3-git-send-email-mhagger@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=drew.northup@maine.edu \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jnareb@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).