git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/5] provide a reset_packed_git() function

From
CTChristian Thaeter <ct@pipapo.org>
Date
Jan 7, 2008, 05:47 UTC
Message-ID
<1199684855-14246-3-git-send-email-ct@pipapo.org>
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
Previous: Christian ThaeterNext: Christian Thaeter
Message 3 of 8 in “Add streq() to compat-util”
  1. 1/5 Add streq() to compat-utilChristian Thaeter, Jan 7, 2008
  2. 2/5 First step, making setup (somewhat) reentrantChristian Thaeter, Jan 7, 2008
  3. 3/5 provide a reset_packed_git() functionChristian Thaeter, Jan 7, 2008
  4. 4/5 Export some more functions to enable resetting the git stateChristian Thaeter, Jan 7, 2008
  5. 5/5 Make setup_git_directory reentrantChristian Thaeter, Jan 7, 2008
  6. Johannes SchindelinJan 7, 2008
  7. Junio C HamanoJan 7, 2008
  8. Johannes SchindelinJan 7, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.