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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux