[JGIT PATCH 11/11] Send .have lines in ReceivePack for alternate repositories
- From
Shawn O. Pearce <spearce@spearce.org>
- Date
- Jul 11, 2009, 20:19 UTC
- Message-ID
- <1247343566-19025-12-git-send-email-spearce@spearce.org>
- In-Reply-To
- <1247343566-19025-11-git-send-email-spearce@spearce.org>
If we are borrowing objects from an alternate repository we should send the alternates' refs, but under the magical ".have" name, so that a push client won't transmit objects that our alternate already contains for us. To save bandwidth during the advertisement phase of the connection any duplicates are skipped. This way we don't send a ".have" if we have already sent that same object name under a different ref, or under a prior have line.
In 5d3a6706eef2 we introduced the client side support for this, and now we introduce the corresponding server side support.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org> --- .../org/spearce/jgit/transport/ReceivePack.java | 1 + .../org/spearce/jgit/transport/RefAdvertiser.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java index 1c490af..472e0b5 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java @@ -514,6 +514,7 @@ private void sendAdvertisedRefs() throws IOException { adv.send(refs.values()); if (head != null && head.getName() == head.getOrigName()) adv.advertiseHave(head.getObjectId()); + adv.includeAdditionalHaves(); if (adv.isEmpty()) adv.advertiseId(ObjectId.zeroId(), "capabilities^{}"); pckOut.end(); diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/RefAdvertiser.java b/org.spearce.jgit/src/org/spearce/jgit/transport/RefAdvertiser.java index 91700da..1f6adc5 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/transport/RefAdvertiser.java +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/RefAdvertiser.java @@ -42,10 +42,13 @@ import java.util.LinkedHashSet; import java.util.Set; +import org.spearce.jgit.lib.AlternateRepositoryDatabase; import org.spearce.jgit.lib.AnyObjectId; import org.spearce.jgit.lib.Constants; +import org.spearce.jgit.lib.ObjectDatabase; import org.spearce.jgit.lib.Ref; import org.spearce.jgit.lib.RefComparator; +import org.spearce.jgit.lib.Repository; import org.spearce.jgit.revwalk.RevFlag; import org.spearce.jgit.revwalk.RevObject; import org.spearce.jgit.revwalk.RevTag; @@ -104,6 +107,22 @@ void advertiseHave(AnyObjectId id) throws IOException { } } + void includeAdditionalHaves() throws IOException { + additionalHaves(walk.getRepository().getObjectDatabase()); + } + + private void additionalHaves(final ObjectDatabase db) throws IOException { + if (db instanceof AlternateRepositoryDatabase) + additionalHaves(((AlternateRepositoryDatabase) db).getRepository()); + for (ObjectDatabase alt : db.getAlternates()) + additionalHaves(alt); + } + + private void additionalHaves(final Repository alt) throws IOException { + for (final Ref r : alt.getAllRefs().values()) + advertiseHave(r.getObjectId()); + } + boolean isEmpty() { return first; }
-- 1.6.4.rc0.117.g28cb