git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Thaeter <ct@pipapo.org>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Christian Thaeter <ct@pipapo.org>
Subject: [PATCH 3/5] provide a reset_packed_git() function
Date: Mon,  7 Jan 2008 06:47:33 +0100	[thread overview]
Message-ID: <1199684855-14246-3-git-send-email-ct@pipapo.org> (raw)
In-Reply-To: <1199684855-14246-2-git-send-email-ct@pipapo.org>

this frees packs and pack-windows allocated by former operations and
reset some variables to let prepare_packed_git() reinit the packs on the
next call.

find_pack_entry() uses a static pointer to cache the last_found pack
which will be reseted too.

Signed-off-by: Christian Thaeter <ct@pipapo.org>
---
 sha1_file.c |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 6583797..139d5a2 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -418,6 +418,7 @@ static unsigned int pack_open_windows;
 static size_t peak_pack_mapped;
 static size_t pack_mapped;
 struct packed_git *packed_git;
+static struct packed_git *last_found_packed_git = (void *)1;
 
 void pack_report(void)
 {
@@ -969,6 +970,22 @@ void reprepare_packed_git(void)
 	prepare_packed_git();
 }
 
+void reset_packed_git(void)
+{
+	/* certainly not the best way to release all windows, but should work for now */
+	while (unuse_one_window(NULL, -1))
+		; /* nothing */
+
+	while (packed_git) {
+		struct packed_git* p = packed_git;
+		packed_git = packed_git->next;
+		free(p);
+	}
+
+	last_found_packed_git = (void *)1;
+	prepare_packed_git_run_once = 0;
+}
+
 int check_sha1_signature(const unsigned char *sha1, void *map, unsigned long size, const char *type)
 {
 	unsigned char real_sha1[20];
@@ -1705,14 +1722,13 @@ int matches_pack_name(struct packed_git *p, const char *name)
 
 static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, const char **ignore_packed)
 {
-	static struct packed_git *last_found = (void *)1;
 	struct packed_git *p;
 	off_t offset;
 
 	prepare_packed_git();
 	if (!packed_git)
 		return 0;
-	p = (last_found == (void *)1) ? packed_git : last_found;
+	p = (last_found_packed_git == (void *)1) ? packed_git : last_found_packed_git;
 
 	do {
 		if (ignore_packed) {
@@ -1741,16 +1757,16 @@ static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, cons
 			e->offset = offset;
 			e->p = p;
 			hashcpy(e->sha1, sha1);
-			last_found = p;
+			last_found_packed_git = p;
 			return 1;
 		}
 
 		next:
-		if (p == last_found)
+		if (p == last_found_packed_git)
 			p = packed_git;
 		else
 			p = p->next;
-		if (p == last_found)
+		if (p == last_found_packed_git)
 			p = p->next;
 	} while (p);
 	return 0;
-- 
1.5.3.7

  reply	other threads:[~2008-01-07  5:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-07  5:47 [PATCH 1/5] Add streq() to compat-util Christian Thaeter
2008-01-07  5:47 ` [PATCH 2/5] First step, making setup (somewhat) reentrant Christian Thaeter
2008-01-07  5:47   ` Christian Thaeter [this message]
2008-01-07  5:47     ` [PATCH 4/5] Export some more functions to enable resetting the git state Christian Thaeter
2008-01-07  5:47       ` [PATCH 5/5] Make setup_git_directory reentrant Christian Thaeter
2008-01-07  8:50   ` [PATCH 2/5] First step, making setup (somewhat) reentrant Johannes Schindelin
2008-01-07  9:22     ` Junio C Hamano
2008-01-07 11:28       ` Johannes Schindelin

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=1199684855-14246-3-git-send-email-ct@pipapo.org \
    --to=ct@pipapo.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).