summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkylezhao <kylezhao@tencent.com>2021-05-20 11:29:59 +0800
committerMatthias Sohn <matthias.sohn@sap.com>2023-02-21 09:11:21 +0100
commitd789fe2f4d8a6ca0c22108bed4e6e7a6e96d04dd (patch)
tree5d4bb07af54fe3d4255e8a71c705fd063a648dae
parent5d5a0d537697480ae5a7d530bad283a972aadf52 (diff)
downloadjgit-d789fe2f4d8a6ca0c22108bed4e6e7a6e96d04dd.tar.gz
jgit-d789fe2f4d8a6ca0c22108bed4e6e7a6e96d04dd.zip
UploadPack: use allow-any-sha1-in-want configuration
C git 2.11 supports setting the equivalent of RequestPolicy.ANY with uploadpack.allowAnySHA1InWant[1]. Parse this into TransportConfig and use it from UploadPack. Add additional tests for [2] and this change. We can execute "git clone --filter=blob:none --no-checkout" successfully with config uploadPack.allowFilter is true. But when we checkout, the git will fetch other missing objects required by the checkout(this is why we need this config). When both uploadPack.allowFilter and uploadPack.allowAnySHA1InWant are true, jgit will support partial clone. If you are using an extremely large monorepo, this feature can help. It allows users to work on an incomplete repo which reduces disk usage. [1] https://github.com/git/git/commit/f8edeaa05d8623a9f6dad408237496c51101aad8 [2] change Id39771a6e42d8082099acde11249306828a053c0 Bug: 573390 Change-Id: I8fe75f03bf1fea7c11e0d67c8637bd05dd1f9b89 Signed-off-by: kylezhao <kylezhao@tencent.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java44
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java15
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java4
3 files changed, 62 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
index 4ad7fa3149..0e97d7b155 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
@@ -2726,6 +2726,50 @@ public class UploadPackTest {
assertEquals(1, stats.getNotAdvertisedWants());
}
+ @Test
+ public void testAllowAnySha1InWantConfig() {
+ server.getConfig().setBoolean("uploadpack", null, "allowanysha1inwant",
+ true);
+
+ try (UploadPack uploadPack = new UploadPack(server)) {
+ assertEquals(RequestPolicy.ANY, uploadPack.getRequestPolicy());
+ }
+ }
+
+ @Test
+ public void testAllowReachableSha1InWantConfig() {
+ server.getConfig().setBoolean("uploadpack", null,
+ "allowreachablesha1inwant", true);
+
+ try (UploadPack uploadPack = new UploadPack(server)) {
+ assertEquals(RequestPolicy.REACHABLE_COMMIT,
+ uploadPack.getRequestPolicy());
+ }
+ }
+
+ @Test
+ public void testAllowTipSha1InWantConfig() {
+ server.getConfig().setBoolean("uploadpack", null, "allowtipsha1inwant",
+ true);
+
+ try (UploadPack uploadPack = new UploadPack(server)) {
+ assertEquals(RequestPolicy.TIP, uploadPack.getRequestPolicy());
+ }
+ }
+
+ @Test
+ public void testAllowReachableTipSha1InWantConfig() {
+ server.getConfig().setBoolean("uploadpack", null,
+ "allowreachablesha1inwant", true);
+ server.getConfig().setBoolean("uploadpack", null, "allowtipsha1inwant",
+ true);
+
+ try (UploadPack uploadPack = new UploadPack(server)) {
+ assertEquals(RequestPolicy.REACHABLE_COMMIT_TIP,
+ uploadPack.getRequestPolicy());
+ }
+ }
+
private class RefCallsCountingRepository extends InMemoryRepository {
private final InMemoryRepository.MemRefDatabase refdb;
private int numRefCalls;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
index 805166a405..064201a629 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008, 2020 Google Inc. and others
+ * Copyright (C) 2008, 2023 Google Inc. and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -118,6 +118,7 @@ public class TransferConfig {
private final boolean allowRefInWant;
private final boolean allowTipSha1InWant;
private final boolean allowReachableSha1InWant;
+ private final boolean allowAnySha1InWant;
private final boolean allowFilter;
private final boolean allowSidebandAll;
@@ -202,6 +203,8 @@ public class TransferConfig {
"uploadpack", "allowtipsha1inwant", false);
allowReachableSha1InWant = rc.getBoolean(
"uploadpack", "allowreachablesha1inwant", false);
+ allowAnySha1InWant = rc.getBoolean("uploadpack", "allowanysha1inwant",
+ false);
allowFilter = rc.getBoolean(
"uploadpack", "allowfilter", false);
protocolVersion = ProtocolVersion.parse(rc
@@ -284,6 +287,16 @@ public class TransferConfig {
}
/**
+ * Whether to allow clients to request any SHA-1s
+ *
+ * @return allow clients to request any SHA-1s?
+ * @since 6.5
+ */
+ public boolean isAllowAnySha1InWant() {
+ return allowAnySha1InWant;
+ }
+
+ /**
* @return true if clients are allowed to specify a "filter" line
* @since 5.0
*/
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
index 38c7cb94bb..b648706475 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
@@ -681,6 +681,10 @@ public class UploadPack implements Closeable {
*/
public void setTransferConfig(@Nullable TransferConfig tc) {
this.transferConfig = tc != null ? tc : new TransferConfig(db);
+ if (transferConfig.isAllowAnySha1InWant()) {
+ setRequestPolicy(RequestPolicy.ANY);
+ return;
+ }
if (transferConfig.isAllowTipSha1InWant()) {
setRequestPolicy(transferConfig.isAllowReachableSha1InWant()
? RequestPolicy.REACHABLE_COMMIT_TIP : RequestPolicy.TIP);