{"thread":{"id":"19150","subject":"[JGIT PATCH] Enable ofs-delta during send-pack/receive-pack protocol","startedAt":"2009-05-01T21:56:08Z","lastAt":"2009-05-01T21:56:08Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"112842","messageId":"1241214968-28743-1-git-send-email-spearce@spearce.org","threadId":"19150","inReplyTo":null,"subject":"[JGIT PATCH] Enable ofs-delta during send-pack/receive-pack protocol","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-05-01T21:56:08Z","receivedAt":"2009-05-01T21:56:08Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"In \"allow OFS_DELTA objects during a push\" Nicolas Pitre taught C\ngit how to enable OBJ_OFS_DELTA usage in a pack file created on a\nclient, to be processed by receive-pack on the server side.\n\nThis creates a smaller pack file during transfer, as the OFS_DELTA\nformat uses less per-delta header space than the classical REF_DELTA.\nIf the receiving peer is going to just store the pack to disk,\nthis would also produce a smaller on-disk pack file.\n\nIn his change, Nico tied the server side enablement of the capability\nto the server's repack.usedeltabaseoffset setting, which can be\nset to false in a repository that needs to service direct access\nclients that are old to understand OFS_DELTA.  We do the same here\nin JGit to match semantics.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../jgit/transport/BasePackPushConnection.java     |    6 ++++++\n .../org/spearce/jgit/transport/ReceivePack.java    |    9 +++++++++\n 2 files changed, 15 insertions(+), 0 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java b/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java\nindex 07e8cb9..1117109 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java\n@@ -78,12 +78,16 @@\n \n \tstatic final String CAPABILITY_DELETE_REFS = \"delete-refs\";\n \n+\tstatic final String CAPABILITY_OFS_DELTA = \"ofs-delta\";\n+\n \tprivate final boolean thinPack;\n \n \tprivate boolean capableDeleteRefs;\n \n \tprivate boolean capableReport;\n \n+\tprivate boolean capableOfsDelta;\n+\n \tprivate boolean sentCommand;\n \n \tprivate boolean writePack;\n@@ -180,6 +184,7 @@ private String enableCapabilities() {\n \t\tfinal StringBuilder line = new StringBuilder();\n \t\tcapableReport = wantCapability(line, CAPABILITY_REPORT_STATUS);\n \t\tcapableDeleteRefs = wantCapability(line, CAPABILITY_DELETE_REFS);\n+\t\tcapableOfsDelta = wantCapability(line, CAPABILITY_OFS_DELTA);\n \t\tif (line.length() > 0)\n \t\t\tline.setCharAt(0, '\\0');\n \t\treturn line.toString();\n@@ -202,6 +207,7 @@ private void writePack(final Map<String, RemoteRefUpdate> refUpdates,\n \t\t}\n \n \t\twriter.setThin(thinPack);\n+\t\twriter.setDeltaBaseAsOffset(capableOfsDelta);\n \t\twriter.preparePack(newObjects, remoteObjects);\n \t\twriter.writePack(out);\n \t}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java\nindex 89ddafe..f75a01a 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java\n@@ -77,6 +77,8 @@\n \n \tstatic final String CAPABILITY_DELETE_REFS = BasePackPushConnection.CAPABILITY_DELETE_REFS;\n \n+\tstatic final String CAPABILITY_OFS_DELTA = BasePackPushConnection.CAPABILITY_OFS_DELTA;\n+\n \t/** Database we write the stored objects into. */\n \tprivate final Repository db;\n \n@@ -95,6 +97,8 @@\n \t/** Should an incoming transfer permit non-fast-forward requests? */\n \tprivate boolean allowNonFastForwards;\n \n+\tprivate boolean allowOfsDelta;\n+\n \t/** Identity to record action as within the reflog. */\n \tprivate PersonIdent refLogIdent;\n \n@@ -145,6 +149,7 @@ public ReceivePack(final Repository into) {\n \t\tallowDeletes = !cfg.getBoolean(\"receive\", \"denydeletes\", false);\n \t\tallowNonFastForwards = !cfg.getBoolean(\"receive\",\n \t\t\t\t\"denynonfastforwards\", false);\n+\t\tallowOfsDelta = cfg.getBoolean(\"repack\", \"usedeltabaseoffset\", true);\n \t\tpreReceive = PreReceiveHook.NULL;\n \t\tpostReceive = PostReceiveHook.NULL;\n \t}\n@@ -455,6 +460,10 @@ private void sendAdvertisedRefs() throws IOException {\n \t\t\tm.append(CAPABILITY_DELETE_REFS);\n \t\t\tm.append(' ');\n \t\t\tm.append(CAPABILITY_REPORT_STATUS);\n+\t\t\tif (allowOfsDelta) {\n+\t\t\t\tm.append(' ');\n+\t\t\t\tm.append(CAPABILITY_OFS_DELTA);\n+\t\t\t}\n \t\t\tm.append(' ');\n \t\t\twriteAdvertisedRef(m);\n \t\t}\n-- \n1.6.3.rc3.212.g8c698\n"}]}