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 <redacted>
---
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(-)
@@ -2010,11 +2010,42 @@ int is_pack_valid(struct packed_git *p)return!open_packed_git(p);}+staticintfind_pack_entry_1(constunsignedchar*sha1,+structpacked_git*p,structpack_entry*e)
This looks all goot but the name. Pretty please, try to find something
that is more descriptive than "1". Suggestions:
"find_pack_entry_lookup", "find_pack_entry_inner", etc.
With that fixed, you can add:
Acked-by: Nicolas Pitre <nico@fluxnic.net>
quoted hunk
+{
+ off_t offset;
+ if (p->num_bad_objects) {
+ unsigned i;
+ for (i = 0; i < p->num_bad_objects; i++)
+ if (!hashcmp(sha1, p->bad_object_sha1 + 20 * i))
+ return 0;
+ }
+
+ offset = find_pack_entry_one(sha1, p);
+ if (!offset)
+ return 0;
+
+ /*
+ * We are about to tell the caller where they can locate the
+ * requested object. We better make sure the packfile is
+ * still here and can be accessed before supplying that
+ * answer, as it may have been deleted since the index was
+ * loaded!
+ */
+ if (!is_pack_valid(p)) {
+ warning("packfile %s cannot be accessed", p->pack_name);
+ return 0;
+ }
+ e->offset = offset;
+ e->p = p;
+ hashcpy(e->sha1, sha1);
+ return 1;
+}
+
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)
@@ -2022,35 +2053,11 @@ static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e) p = (last_found == (void *)1) ? packed_git : last_found; do {- if (p->num_bad_objects) {- unsigned i;- for (i = 0; i < p->num_bad_objects; i++)- if (!hashcmp(sha1, p->bad_object_sha1 + 20 * i))- goto next;- }-- offset = find_pack_entry_one(sha1, p);- if (offset) {- /*- * We are about to tell the caller where they can- * locate the requested object. We better make- * sure the packfile is still here and can be- * accessed before supplying that answer, as- * it may have been deleted since the index- * was loaded!- */- if (!is_pack_valid(p)) {- warning("packfile %s cannot be accessed", p->pack_name);- goto next;- }- e->offset = offset;- e->p = p;- hashcpy(e->sha1, sha1);+ if (find_pack_entry_1(sha1, p, e)) { last_found = p; return 1; }- next: if (p == last_found) p = packed_git; else
From: Nicolas Pitre <nico@fluxnic.net> Date: 2016-06-15 22:52:54
On Wed, 1 Feb 2012, Nguyễn Thái Ngọc Duy wrote:
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 <redacted>
Acked-by: Nicolas Pitre <nico@fluxnic.net>
Since Junio's already done the hard work. It'd be silly of me not to
take advantage and credit for free :)
Maybe a little "Thanks to Junio for code layout suggestions" in the
commit message would give him some credit back.
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.
Thanks to Junio for code layout suggestions.
Acked-by: Nicolas Pitre <nico@fluxnic.net>
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
Credit where credit is due. No code changes from pu.
sha1_file.c | 27 +++++++++++++--------------
1 files changed, 13 insertions(+), 14 deletions(-)