Git development
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>,
	Marek Zawirski <marek.zawirski@gmail.com>
Cc: git@vger.kernel.org
Subject: [JGIT PATCH] Use ".have" advertisements during push to reduce what is transferred
Date: Wed, 24 Sep 2008 12:05:53 -0700	[thread overview]
Message-ID: <1222283153-10534-1-git-send-email-spearce@spearce.org> (raw)

If a remote peer has an alternate object database it might show
the refs of the alternate repositories by sending special ".have"
ref lines in the advertisement.  These can be used to compute a
better common base, avoiding uploading objects which the remote
side has physically available (and complete), but which aren't in
the ref space of the remote repository.

As most repositories have more than one ref, there can be more than
one ".have" line, and the same object might appear more than once.
Collecting these into a special "additionalHaves" set avoids them
from showing up in the advertised refs collection.

PackWriter already gracefully skips over remoteObjects that
we don't have locally.  We can simply include the entire set
of additionalHaves when we start creating a pack for the push
transfer and PackWriter will seek the best common base available.
Anything advertised that we lack will be silently skipped.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---

 I'm likely to merge Junio's jc/alternate-push branch in git.git
 from next to master when I start merging over the cooked topics.

 JGit clients need this to prevent crashing when they talk to a
 newer git-receive-pack process that is sending these .have lines.
 Without this patch JGit will throw a "duplicate advertisement"
 error when it receives more than one ref with the name ".have".

 Fortunately the entire implementation of the client side of this
 alternate-push feature is 7 lines of Java.

 See http://thread.gmane.org/gmane.comp.version-control.git/95351

 .../spearce/jgit/transport/BasePackConnection.java |    7 ++++++-
 .../jgit/transport/BasePackPushConnection.java     |    1 +
 2 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackConnection.java b/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackConnection.java
index 2d145a6..e5fc040 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackConnection.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackConnection.java
@@ -93,6 +93,9 @@
 	/** Capability tokens advertised by the remote side. */
 	private final Set<String> remoteCapablities = new HashSet<String>();
 
+	/** Extra objects the remote has, but which aren't offered as refs. */
+	protected final Set<ObjectId> additionalHaves = new HashSet<ObjectId>();
+
 	BasePackConnection(final PackTransport packTransport) {
 		local = packTransport.local;
 		uri = packTransport.uri;
@@ -160,7 +163,9 @@ private void readAdvertisedRefsImpl() throws IOException {
 			}
 
 			final ObjectId id = ObjectId.fromString(line.substring(0, 40));
-			if (name.endsWith("^{}")) {
+			if (name.equals(".have")) {
+				additionalHaves.add(id);
+			} else if (name.endsWith("^{}")) {
 				name = name.substring(0, name.length() - 3);
 				final Ref prior = avail.get(name);
 				if (prior == null)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java b/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java
index 2594623..17f6915 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java
@@ -195,6 +195,7 @@ private void writePack(final Map<String, RemoteRefUpdate> refUpdates,
 
 		for (final Ref r : getRefs())
 			remoteObjects.add(r.getObjectId());
+		remoteObjects.addAll(additionalHaves);
 		for (final RemoteRefUpdate r : refUpdates.values()) {
 			if (!ObjectId.zeroId().equals(r.getNewObjectId()))
 				newObjects.add(r.getNewObjectId());
-- 
1.6.0.2.471.g47a76

                 reply	other threads:[~2008-09-24 19:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1222283153-10534-1-git-send-email-spearce@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=marek.zawirski@gmail.com \
    --cc=robin.rosenberg@dewire.com \
    /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