From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 2/6] find_pack_entry(): do not keep packed_git pointer locally
Date: Thu, 10 Nov 2011 14:12:31 +0700 [thread overview]
Message-ID: <1320909155-4575-2-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1320909155-4575-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.
However keeping the pointer may become invalid if free_pack_by_name()
happens to free that particular pack.
Move the pointer out and reset the pointer in free_pack_by_name() if we
free it.
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 3401301..155c808 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -53,6 +53,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;
@@ -719,6 +721,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;
}
@@ -2010,14 +2014,13 @@ static 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) {
@@ -2044,16 +2047,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.4.74.g639db
next prev parent reply other threads:[~2011-11-10 7:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-10 7:12 [PATCH 1/6] Print trace in rev-list machinery Nguyễn Thái Ngọc Duy
2011-11-10 7:12 ` Nguyễn Thái Ngọc Duy [this message]
2011-11-10 7:12 ` [PATCH 3/6] parse-options: add OPT_ULONG Nguyễn Thái Ngọc Duy
2011-11-10 7:12 ` [PATCH 4/6] pack-objects: use parse_options() Nguyễn Thái Ngọc Duy
2011-11-10 7:12 ` [PATCH 5/6] parse-options: allow OPTION_ARGUMENT to take argument Nguyễn Thái Ngọc Duy
2011-11-10 7:12 ` [PATCH 6/6] Build in git-repack Nguyễn Thái Ngọc Duy
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=1320909155-4575-2-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/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.