From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nicolas Pitre" <nico@fluxnic.net>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v3 2/2] find_pack_entry(): do not keep packed_git pointer locally
Date: Wed, 1 Feb 2012 20:48:55 +0700 [thread overview]
Message-ID: <1328104135-475-2-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1328104135-475-1-git-send-email-pclouds@gmail.com>
Commit f7c22cc (always start looking up objects in the last used pack
first - 2007-05-30) introduce 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>
---
Since Junio's already done the hard work. It'd be silly of me not to
take advantage and credit for free :)
The new loop looks much better.
sha1_file.c | 27 +++++++++++++--------------
1 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index ff5bf42..ebe77b3 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -54,6 +54,8 @@ static struct cached_object empty_tree = {
0
};
+static struct packed_git *last_found_pack;
+
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 (last_found_pack == p)
+ last_found_pack = NULL;
free(p);
return;
}
@@ -2044,27 +2048,22 @@ static int find_pack_entry_1(const unsigned char *sha1,
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;
prepare_packed_git();
if (!packed_git)
return 0;
- p = (last_found == (void *)1) ? packed_git : last_found;
- do {
- if (find_pack_entry_1(sha1, p, e)) {
- last_found = p;
- return 1;
- }
+ if (last_found_pack && find_pack_entry_1(sha1, last_found_pack, e))
+ return 1;
- if (p == last_found)
- p = packed_git;
- else
- p = p->next;
- if (p == last_found)
- p = p->next;
- } while (p);
+ for (p = packed_git; p; p = p->next) {
+ if (p == last_found_pack || !find_pack_entry_1(sha1, p, e))
+ continue;
+
+ last_found_pack = p;
+ return 1;
+ }
return 0;
}
--
1.7.8.36.g69ee2
next prev parent reply other threads:[~2012-02-01 13:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Nguyễn Thái Ngọc Duy [this message]
2012-02-01 16:02 ` [PATCH v3 2/2] find_pack_entry(): do not keep packed_git pointer locally 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
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=1328104135-475-2-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=nico@fluxnic.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.