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

[JGIT PATCH] Enable ofs-delta during send-pack/receive-pack protocol

From
Shawn O. Pearce <spearce@spearce.org>
Date
May 1, 2009, 21:56 UTC
Message-ID
<1241214968-28743-1-git-send-email-spearce@spearce.org>

In "allow OFS_DELTA objects during a push" Nicolas Pitre taught C git how to enable OBJ_OFS_DELTA usage in a pack file created on a client, to be processed by receive-pack on the server side.

This creates a smaller pack file during transfer, as the OFS_DELTA format uses less per-delta header space than the classical REF_DELTA. If the receiving peer is going to just store the pack to disk, this would also produce a smaller on-disk pack file.

In his change, Nico tied the server side enablement of the capability to the server's repack.usedeltabaseoffset setting, which can be set to false in a repository that needs to service direct access clients that are old to understand OFS_DELTA. We do the same here in JGit to match semantics.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../jgit/transport/BasePackPushConnection.java     |    6 ++++++
 .../org/spearce/jgit/transport/ReceivePack.java    |    9 +++++++++
 2 files changed, 15 insertions(+), 0 deletions(-)
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 07e8cb9..1117109 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java
@@ -78,12 +78,16 @@
 
 	static final String CAPABILITY_DELETE_REFS = "delete-refs";
 
+	static final String CAPABILITY_OFS_DELTA = "ofs-delta";
+
 	private final boolean thinPack;
 
 	private boolean capableDeleteRefs;
 
 	private boolean capableReport;
 
+	private boolean capableOfsDelta;
+
 	private boolean sentCommand;
 
 	private boolean writePack;
@@ -180,6 +184,7 @@ private String enableCapabilities() {
 		final StringBuilder line = new StringBuilder();
 		capableReport = wantCapability(line, CAPABILITY_REPORT_STATUS);
 		capableDeleteRefs = wantCapability(line, CAPABILITY_DELETE_REFS);
+		capableOfsDelta = wantCapability(line, CAPABILITY_OFS_DELTA);
 		if (line.length() > 0)
 			line.setCharAt(0, '\0');
 		return line.toString();
@@ -202,6 +207,7 @@ private void writePack(final Map<String, RemoteRefUpdate> refUpdates,
 		}
 
 		writer.setThin(thinPack);
+		writer.setDeltaBaseAsOffset(capableOfsDelta);
 		writer.preparePack(newObjects, remoteObjects);
 		writer.writePack(out);
 	}
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 89ddafe..f75a01a 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
@@ -77,6 +77,8 @@
 
 	static final String CAPABILITY_DELETE_REFS = BasePackPushConnection.CAPABILITY_DELETE_REFS;
 
+	static final String CAPABILITY_OFS_DELTA = BasePackPushConnection.CAPABILITY_OFS_DELTA;
+
 	/** Database we write the stored objects into. */
 	private final Repository db;
 
@@ -95,6 +97,8 @@
 	/** Should an incoming transfer permit non-fast-forward requests? */
 	private boolean allowNonFastForwards;
 
+	private boolean allowOfsDelta;
+
 	/** Identity to record action as within the reflog. */
 	private PersonIdent refLogIdent;
 
@@ -145,6 +149,7 @@ public ReceivePack(final Repository into) {
 		allowDeletes = !cfg.getBoolean("receive", "denydeletes", false);
 		allowNonFastForwards = !cfg.getBoolean("receive",
 				"denynonfastforwards", false);
+		allowOfsDelta = cfg.getBoolean("repack", "usedeltabaseoffset", true);
 		preReceive = PreReceiveHook.NULL;
 		postReceive = PostReceiveHook.NULL;
 	}
@@ -455,6 +460,10 @@ private void sendAdvertisedRefs() throws IOException {
 			m.append(CAPABILITY_DELETE_REFS);
 			m.append(' ');
 			m.append(CAPABILITY_REPORT_STATUS);
+			if (allowOfsDelta) {
+				m.append(' ');
+				m.append(CAPABILITY_OFS_DELTA);
+			}
 			m.append(' ');
 			writeAdvertisedRef(m);
 		}
-- 
1.6.3.rc3.212.g8c698
Message 1 of 1 in “Enable ofs-delta during send-pack/receive-pack protocol”
  1. Enable ofs-delta during send-pack/receive-pack protocolShawn O. Pearce, May 1, 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.