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@xxxxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html