git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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
Previous: Shawn O. PearceNext: Robin Rosenberg
Message 12 of 14 in “Repository instance caching”
  1. 00/11 Repository instance cachingShawn O. Pearce, Jul 11, 2009
  2. 01/11 Change Daemon to use concurrent collections for exported repositoriesShawn O. Pearce, Jul 11, 2009
  3. 02/11 Make Daemon's exportAll check not require synchronizationShawn O. Pearce, Jul 11, 2009
  4. 03/11 Don't retry ".git" suffix in daemon if already triedShawn O. Pearce, Jul 11, 2009
  5. 04/11 Refactor ref advertisement code from server implementationsShawn O. Pearce, Jul 11, 2009
  6. 05/11 Don't advertise HEAD from ReceivePackShawn O. Pearce, Jul 11, 2009
  7. 06/11 Add a use reference counter to RepositoryShawn O. Pearce, Jul 11, 2009
  8. 07/11 Introduce RepositoryCache to cache handles of Repository objectsShawn O. Pearce, Jul 11, 2009
  9. 08/11 Change Daemon to use RepositoryCacheShawn O. Pearce, Jul 11, 2009
  10. 09/11 Expose the Repository's ObjectDatabase objectShawn O. Pearce, Jul 11, 2009
  11. 10/11 Use cached Repository instances when resolving alternatesShawn O. Pearce, Jul 11, 2009
  12. 11/11 Send .have lines in ReceivePack for alternate repositoriesShawn O. Pearce, Jul 11, 2009
  13. Robin RosenbergJul 21, 2009
  14. Shawn O. PearceJul 21, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.