aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit
diff options
context:
space:
mode:
authorRonald Bhuleskar <funronald@google.com>2023-03-22 15:07:19 -0700
committerRonald Bhuleskar <funronald@google.com>2023-03-28 14:29:54 -0700
commit738dacb7fbdd1bfec0bd4d387b37ac5e89d36c07 (patch)
treed9be06b60cf34c89b86cf69aaf37526d823fc478 /org.eclipse.jgit/src/org/eclipse/jgit
parent5166ded0986df7a99bbc9ae6bc057a27a1e7d974 (diff)
downloadjgit-738dacb7fbdd1bfec0bd4d387b37ac5e89d36c07.tar.gz
jgit-738dacb7fbdd1bfec0bd4d387b37ac5e89d36c07.zip
BasePackFetchConnection: support negotiationTip feature
By default, Git will report, to the server, commits reachable from all local refs to find common commits in an attempt to reduce the size of the to-be-received packfile. If specified with negotiation tip, Git will only report commits reachable from the given tips. This is useful to speed up fetches when the user knows which local ref is likely to have commits in common with the upstream ref being fetched. When negotation-tip is on, use the wanted refs instead of all refs as source of the "have" list to send. This is controlled by the `fetch.usenegotationtip` flag, false by default. This works only for programmatic fetches and there is no support for it yet in the CLI. Change-Id: I19f8fe48889bfe0ece7cdf78019b678ede5c6a32
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java38
1 files changed, 36 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
index be36d2b834..8909380176 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
@@ -37,6 +37,7 @@ import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
import org.eclipse.jgit.errors.PackProtocolException;
import org.eclipse.jgit.errors.RemoteRepositoryException;
@@ -215,6 +216,8 @@ public abstract class BasePackFetchConnection extends BasePackConnection
private boolean allowOfsDelta;
+ private boolean useNegotiationTip;
+
private boolean noDone;
private boolean noProgress;
@@ -259,9 +262,11 @@ public abstract class BasePackFetchConnection extends BasePackConnection
final FetchConfig cfg = getFetchConfig();
allowOfsDelta = cfg.allowOfsDelta;
maxHaves = cfg.maxHaves;
+ useNegotiationTip = cfg.useNegotiationTip;
} else {
allowOfsDelta = true;
maxHaves = Integer.MAX_VALUE;
+ useNegotiationTip = false;
}
includeTags = transport.getTagOpt() != TagOpt.NO_TAGS;
@@ -297,14 +302,35 @@ public abstract class BasePackFetchConnection extends BasePackConnection
final int maxHaves;
+ final boolean useNegotiationTip;
+
FetchConfig(Config c) {
allowOfsDelta = c.getBoolean("repack", "usedeltabaseoffset", true); //$NON-NLS-1$ //$NON-NLS-2$
maxHaves = c.getInt("fetch", "maxhaves", Integer.MAX_VALUE); //$NON-NLS-1$ //$NON-NLS-2$
+ useNegotiationTip = c.getBoolean("fetch", "usenegotiationtip", //$NON-NLS-1$ //$NON-NLS-2$
+ false);
}
FetchConfig(boolean allowOfsDelta, int maxHaves) {
+ this(allowOfsDelta, maxHaves, false);
+ }
+
+ /**
+ * @param allowOfsDelta
+ * when true optimizes the pack size by deltafying base
+ * object
+ * @param maxHaves
+ * max haves to be sent per negotiation
+ * @param useNegotiationTip
+ * if true uses the wanted refs instead of all refs as source
+ * of the "have" list to send.
+ * @since 6.6
+ */
+ FetchConfig(boolean allowOfsDelta, int maxHaves,
+ boolean useNegotiationTip) {
this.allowOfsDelta = allowOfsDelta;
this.maxHaves = maxHaves;
+ this.useNegotiationTip = useNegotiationTip;
}
}
@@ -384,7 +410,7 @@ public abstract class BasePackFetchConnection extends BasePackConnection
noProgress = monitor == NullProgressMonitor.INSTANCE;
markRefsAdvertised();
- markReachable(have, maxTimeWanted(want));
+ markReachable(want, have, maxTimeWanted(want));
if (TransferConfig.ProtocolVersion.V2
.equals(getProtocolVersion())) {
@@ -662,9 +688,17 @@ public abstract class BasePackFetchConnection extends BasePackConnection
return maxTime;
}
- private void markReachable(Set<ObjectId> have, int maxTime)
+ private void markReachable(Collection<Ref> want, Set<ObjectId> have,
+ int maxTime)
throws IOException {
+ Set<String> wantRefs = want.stream().map(Ref::getName)
+ .collect(Collectors.toSet());
+
for (Ref r : local.getRefDatabase().getRefs()) {
+ if (useNegotiationTip && !wantRefs.contains(r.getName())) {
+ continue;
+ }
+
ObjectId id = r.getPeeledObjectId();
if (id == null)
id = r.getObjectId();