From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
	Nicolas Pitre <nico@fluxnic.net>
Cc: git@vger.kernel.org, Michael Haggerty <mhagger@alum.mit.edu>
Subject: [PATCH 3/6] find_pack_entry(): document last_found_pack
Date: Fri, 21 Feb 2014 17:32:04 +0100	[thread overview]
Message-ID: <1393000327-11402-4-git-send-email-mhagger@alum.mit.edu> (raw)
In-Reply-To: <1393000327-11402-1-git-send-email-mhagger@alum.mit.edu>
Add a comment at the declaration of last_found_pack and where it is
used in find_pack_entry().  In the latter, separate the cases (1) to
make a place for the new comment and (2) to turn the success case into
affirmative logic.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 sha1_file.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index 6e8c05d..0910939 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -60,6 +60,12 @@ static struct cached_object empty_tree = {
 	0
 };
 
+/*
+ * A pointer to the last packed_git in which an object was found.
+ * When an object is sought, we look in this packfile first, because
+ * objects that are looked up at similar times are often in the same
+ * packfile as one another.
+ */
 static struct packed_git *last_found_pack;
 
 static struct cached_object *find_cached_object(const unsigned char *sha1)
@@ -2460,11 +2466,13 @@ static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
 		return 1;
 
 	for (p = packed_git; p; p = p->next) {
-		if (p == last_found_pack || !fill_pack_entry(sha1, e, p))
-			continue;
+		if (p == last_found_pack)
+			continue; /* we already checked this one */
 
-		last_found_pack = p;
-		return 1;
+		if (fill_pack_entry(sha1, e, p)) {
+			last_found_pack = p;
+			return 1;
+		}
 	}
 	return 0;
 }
-- 
1.8.5.3
next prev parent reply	other threads:[~2014-02-21 16:32 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-21 16:32 [PATCH 0/6] Add a bunch of docstrings and make a few minor cleanups Michael Haggerty
2014-02-21 16:32 ` [PATCH 1/6] Add docstrings for lookup_replace_object() and do_lookup_replace_object() Michael Haggerty
2014-02-21 18:21   ` Junio C Hamano
2014-02-24  8:25     ` Michael Haggerty
2014-02-24  9:24   ` Christian Couder
2014-02-24 10:17     ` Michael Haggerty
2014-02-24 18:06       ` Junio C Hamano
2014-02-21 16:32 ` [PATCH 2/6] replace_object: use struct members instead of an array Michael Haggerty
2014-02-21 18:23   ` Junio C Hamano
2014-02-21 16:32 ` Michael Haggerty [this message]
2014-02-21 17:15   ` [PATCH 3/6] find_pack_entry(): document last_found_pack Nicolas Pitre
2014-02-21 16:32 ` [PATCH 4/6] sha1_file_name(): declare to return a const string Michael Haggerty
2014-02-21 16:32 ` [PATCH 5/6] Document a bunch of functions defined in sha1_file.c Michael Haggerty
2014-02-21 17:17   ` Nicolas Pitre
2014-02-24 18:18   ` Jakub Narębski
2014-02-24 20:01     ` Michael Haggerty
2014-02-24 20:08       ` Jonathan Nieder
2014-02-25 15:23         ` Michael Haggerty
2014-02-21 16:32 ` [PATCH 6/6] Document some functions defined in object.c Michael Haggerty
2014-02-21 17:33   ` Nicolas Pitre
2014-02-24  8:47     ` Michael Haggerty
2014-02-24 17:12       ` Junio C Hamano
2014-02-24 17:58 ` [PATCH 0/6] Add a bunch of docstrings and make a few minor cleanups Junio C Hamano
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=1393000327-11402-4-git-send-email-mhagger@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=nico@fluxnic.net \
    --cc=peff@peff.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 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).