From: Lukas Fleischer <lfleischer@lfos.de>
To: git@vger.kernel.org
Subject: [PATCH] receive-pack: avoid sending duplicate "have" lines
Date: Sat, 7 Nov 2015 00:16:13 +0100 [thread overview]
Message-ID: <1446851773-32390-1-git-send-email-lfleischer@lfos.de> (raw)
Alternates and refs outside the current namespace are advertised as
"have" lines. To this end, the object identifiers of alternates are
collected in an array and repeated hashes are omitted before
transmission. In contrast, refs outside the used namespace are currently
converted into "have" lines and transmitted immediately, without
checking for duplicate lines. This means that exactly the same "have"
line might be transmitted several times.
Optimize this by using a single pool to collect all object identifiers
to be converted into "have" lines (including both alternates and refs
outside the namespace) first and transmit them later, omitting any
duplicates.
Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Lukas Fleischer <lfleischer@lfos.de>
---
This is based on pu. I am not sure whether we should also change the
name of show_one_alternate_sha1() in this patch since it is now used
to transmit refs outside the current namespace as well...
builtin/receive-pack.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index f06f70a..548d4ce 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -217,23 +217,24 @@ static void show_ref(const char *path, const unsigned char *sha1)
}
static int show_ref_cb(const char *path_full, const struct object_id *oid,
- int flag, void *unused)
+ int flag, void *data)
{
const char *path = strip_namespace(path_full);
if (ref_is_hidden(path, path_full))
return 0;
- /*
- * Advertise refs outside our current namespace as ".have"
- * refs, so that the client can use them to minimize data
- * transfer but will otherwise ignore them. This happens to
- * cover ".have" that are thrown in by add_one_alternate_ref()
- * to mark histories that are complete in our alternates as
- * well.
- */
- if (!path)
- path = ".have";
+ if (!path) {
+ /*
+ * Advertise refs outside our current namespace as ".have"
+ * refs, so that the client can use them to minimize data
+ * transfer but will otherwise ignore them.
+ */
+ struct sha1_array *sa = data;
+ sha1_array_append(sa, oid->hash);
+ return 0;
+ }
+
show_ref(path, oid->hash);
return 0;
}
@@ -254,9 +255,9 @@ static void write_head_info(void)
struct sha1_array sa = SHA1_ARRAY_INIT;
for_each_alternate_ref(collect_one_alternate_ref, &sa);
+ for_each_ref(show_ref_cb, &sa);
sha1_array_for_each_unique(&sa, show_one_alternate_sha1, NULL);
sha1_array_clear(&sa);
- for_each_ref(show_ref_cb, NULL);
if (!sent_capabilities)
show_ref("capabilities^{}", null_sha1);
--
2.6.2
next reply other threads:[~2015-11-06 23:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-06 23:16 Lukas Fleischer [this message]
2015-11-06 23:38 ` [PATCH] receive-pack: avoid sending duplicate "have" lines Junio C Hamano
2015-11-07 9:04 ` Lukas Fleischer
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=1446851773-32390-1-git-send-email-lfleischer@lfos.de \
--to=lfleischer@lfos.de \
--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 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).