git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] find_pack_entry(): do not keep packed_git pointer locally
@ 2012-01-30 11:25 Nguyễn Thái Ngọc Duy
  2012-01-30 23:26 ` Junio C Hamano
       [not found] ` <1328010239-29669-1-git-send-email-pclouds@gmail.com>
  0 siblings, 2 replies; 14+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2012-01-30 11:25 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Commit f7c22cc (always start looking up objects in the last used pack
first - 2007-05-30) introduces a static packed_git* pointer as an
optimization.  The kept pointer however may become invalid if
free_pack_by_name() happens to free that particular pack.

Current code base does not access packs after calling
free_pack_by_name() so it should not be a problem. Anyway, move the
pointer out so that free_pack_by_name() can reset it to avoid running
into troubles in future.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1_file.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 88f2151..4ecc953 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -54,6 +54,8 @@ static struct cached_object empty_tree = {
 	0
 };
 
+static struct packed_git *find_pack_entry_last_found = (void *)1;
+
 static struct cached_object *find_cached_object(const unsigned char *sha1)
 {
 	int i;
@@ -720,6 +722,8 @@ void free_pack_by_name(const char *pack_name)
 			close_pack_index(p);
 			free(p->bad_object_sha1);
 			*pp = p->next;
+			if (find_pack_entry_last_found == p)
+				find_pack_entry_last_found = (void*)1;
 			free(p);
 			return;
 		}
@@ -2012,14 +2016,13 @@ int is_pack_valid(struct packed_git *p)
 
 static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
 {
-	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 = (find_pack_entry_last_found == (void *)1) ? packed_git : find_pack_entry_last_found;
 
 	do {
 		if (p->num_bad_objects) {
@@ -2046,16 +2049,16 @@ static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
 			e->offset = offset;
 			e->p = p;
 			hashcpy(e->sha1, sha1);
-			last_found = p;
+			find_pack_entry_last_found = p;
 			return 1;
 		}
 
 		next:
-		if (p == last_found)
+		if (p == find_pack_entry_last_found)
 			p = packed_git;
 		else
 			p = p->next;
-		if (p == last_found)
+		if (p == find_pack_entry_last_found)
 			p = p->next;
 	} while (p);
 	return 0;
-- 
1.7.8.36.g69ee2

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2012-02-02 13:50 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-30 11:25 [PATCH] find_pack_entry(): do not keep packed_git pointer locally Nguyễn Thái Ngọc Duy
2012-01-30 23:26 ` Junio C Hamano
2012-01-31  2:01   ` Nguyen Thai Ngoc Duy
2012-01-31  4:19     ` Nicolas Pitre
     [not found] ` <1328010239-29669-1-git-send-email-pclouds@gmail.com>
2012-01-31 18:02   ` [PATCH v2] " Junio C Hamano
2012-01-31 19:28     ` Nicolas Pitre
2012-02-01 13:48   ` [PATCH v3 1/2] Factor find_pack_entry()'s core out Nguyễn Thái Ngọc Duy
2012-02-01 13:48     ` [PATCH v3 2/2] find_pack_entry(): do not keep packed_git pointer locally Nguyễn Thái Ngọc Duy
2012-02-01 16:02       ` Nicolas Pitre
2012-02-02 13:53         ` [PATCH v4 " Nguyễn Thái Ngọc Duy
2012-02-01 15:59     ` [PATCH v3 1/2] Factor find_pack_entry()'s core out Nicolas Pitre
2012-02-01 22:03       ` Junio C Hamano
2012-02-01 22:33         ` Junio C Hamano
2012-02-01 23:37           ` Nicolas Pitre

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).