diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java index 188c0e057..e633ca420 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java @@ -71,7 +71,7 @@ public final class FetchV2Request { private final int shallowSince; - private final List shallowExcludeRefs; + private final List deepenNotRefs; private final int depth; @@ -79,19 +79,22 @@ public final class FetchV2Request { private final Set options; + private final boolean doneReceived; + private FetchV2Request(List peerHas, TreeMap wantedRefs, Set wantsIds, Set clientShallowCommits, int shallowSince, - List shallowExcludeRefs, int depth, long filterBlobLimit, - Set options) { + List deependNotRefs, int depth, long filterBlobLimit, + boolean doneReceived, Set options) { this.peerHas = peerHas; this.wantedRefs = wantedRefs; this.wantsIds = wantsIds; this.clientShallowCommits = clientShallowCommits; this.shallowSince = shallowSince; - this.shallowExcludeRefs = shallowExcludeRefs; + this.deepenNotRefs = deependNotRefs; this.depth = depth; this.filterBlobLimit = filterBlobLimit; + this.doneReceived = doneReceived; this.options = options; } @@ -135,8 +138,8 @@ Set getClientShallowCommits() { * The value in a "deepen-since" line in the request, indicating the * timestamp where to stop fetching/cloning. * - * @return timestamp where to stop the shallow fetch/clone. Defaults to 0 if - * not set in the request + * @return timestamp in seconds since the epoch, where to stop the shallow + * fetch/clone. Defaults to 0 if not set in the request. */ int getShallowSince() { return shallowSince; @@ -146,8 +149,8 @@ int getShallowSince() { * @return the refs in "deepen-not" lines in the request. */ @NonNull - List getShallowExcludeRefs() { - return shallowExcludeRefs; + List getDeepenNotRefs() { + return deepenNotRefs; } /** @@ -164,6 +167,13 @@ long getFilterBlobLimit() { return filterBlobLimit; } + /** + * @return true if the request had a "done" line + */ + boolean wasDoneReceived() { + return doneReceived; + } + /** * Options that tune the expected response from the server, like * "thin-pack", "no-progress" or "ofs-delta" @@ -194,7 +204,7 @@ static final class Builder { Set clientShallowCommits = new HashSet<>(); - List shallowExcludeRefs = new ArrayList<>(); + List deepenNotRefs = new ArrayList<>(); Set options = new HashSet<>(); @@ -204,6 +214,8 @@ static final class Builder { long filterBlobLimit = -1; + boolean doneReceived; + private Builder() { } @@ -282,16 +294,16 @@ int getDepth() { /** * @return if there has been any "deepen not" line in the request */ - boolean hasShallowExcludeRefs() { - return shallowExcludeRefs.size() > 0; + boolean hasDeepenNotRefs() { + return !deepenNotRefs.isEmpty(); } /** - * @param shallowExcludeRef reference in a "deepen not" line + * @param deepenNotRef reference in a "deepen not" line * @return the builder */ - Builder addShallowExcludeRefs(String shallowExcludeRef) { - this.shallowExcludeRefs.add(shallowExcludeRef); + Builder addDeepenNotRef(String deepenNotRef) { + this.deepenNotRefs.add(deepenNotRef); return this; } @@ -323,13 +335,22 @@ Builder setFilterBlobLimit(long filterBlobLimit) { return this; } + /** + * Mark that the "done" line has been received. + * + * @return the builder + */ + Builder setDoneReceived() { + this.doneReceived = true; + return this; + } /** * @return Initialized fetch request */ FetchV2Request build() { return new FetchV2Request(peerHas, wantedRefs, wantsIds, - clientShallowCommits, shallowSince, shallowExcludeRefs, - depth, filterBlobLimit, options); + clientShallowCommits, shallowSince, deepenNotRefs, + depth, filterBlobLimit, doneReceived, options); } } } 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 03fc57cba..41883c98a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -311,7 +311,7 @@ public Set getOptions() { * not to send using --shallow-exclude. Cannot be non-empty if depth is * nonzero. */ - private List shallowExcludeRefs = new ArrayList<>(); + private List deepenNotRefs = new ArrayList<>(); /** Commit time of the oldest common commit, in seconds. */ private int oldestTime; @@ -963,7 +963,6 @@ private void fetchV2() throws IOException { } String line; - boolean doneReceived = false; // Currently, we do not support any capabilities, so the next // line is DELIM. @@ -997,7 +996,7 @@ private void fetchV2() throws IOException { } else if (line.startsWith("have ")) { //$NON-NLS-1$ reqBuilder.addPeerHas(ObjectId.fromString(line.substring(5))); } else if (line.equals("done")) { //$NON-NLS-1$ - doneReceived = true; + reqBuilder.setDoneReceived(); } else if (line.equals(OPTION_THIN_PACK)) { reqBuilder.addOption(OPTION_THIN_PACK); } else if (line.equals(OPTION_NO_PROGRESS)) { @@ -1021,13 +1020,13 @@ private void fetchV2() throws IOException { throw new PackProtocolException( JGitText.get().deepenSinceWithDeepen); } - if (reqBuilder.hasShallowExcludeRefs()) { + if (reqBuilder.hasDeepenNotRefs()) { throw new PackProtocolException( JGitText.get().deepenNotWithDeepen); } reqBuilder.setDepth(parsedDepth); } else if (line.startsWith("deepen-not ")) { //$NON-NLS-1$ - reqBuilder.addShallowExcludeRefs(line.substring(11)); + reqBuilder.addDeepenNotRef(line.substring(11)); if (reqBuilder.getDepth() != 0) { throw new PackProtocolException( JGitText.get().deepenNotWithDeepen); @@ -1072,7 +1071,7 @@ private void fetchV2() throws IOException { depth = req.getDepth(); shallowSince = req.getShallowSince(); filterBlobLimit = req.getFilterBlobLimit(); - shallowExcludeRefs = req.getShallowExcludeRefs(); + deepenNotRefs = req.getDeepenNotRefs(); boolean sectionSent = false; @Nullable List shallowCommits = null; @@ -1082,14 +1081,14 @@ private void fetchV2() throws IOException { verifyClientShallow(req.getClientShallowCommits()); } if (req.getDepth() != 0 || req.getShallowSince() != 0 - || !req.getShallowExcludeRefs().isEmpty()) { + || !req.getDeepenNotRefs().isEmpty()) { shallowCommits = new ArrayList<>(); processShallow(shallowCommits, unshallowCommits, false); } if (!req.getClientShallowCommits().isEmpty()) walk.assumeShallow(req.getClientShallowCommits()); - if (doneReceived) { + if (req.wasDoneReceived()) { processHaveLines(req.getPeerHas(), ObjectId.zeroId(), new PacketLineOut(NullOutputStream.INSTANCE)); } else { @@ -1109,7 +1108,7 @@ private void fetchV2() throws IOException { sectionSent = true; } - if (doneReceived || okToGiveUp()) { + if (req.wasDoneReceived() || okToGiveUp()) { if (shallowCommits != null) { if (sectionSent) pckOut.writeDelim(); @@ -1252,7 +1251,7 @@ private void processShallow(@Nullable List shallowCommits, boolean writeToPckOut) throws IOException { if (options.contains(OPTION_DEEPEN_RELATIVE) || shallowSince != 0 || - !shallowExcludeRefs.isEmpty()) { + !deepenNotRefs.isEmpty()) { // TODO(jonathantanmy): Implement deepen-relative, deepen-since, // and deepen-not. throw new UnsupportedOperationException();