These properties are protocol v2 specific, but they have clear default no-op values and having them in the common superclass simplifies client code. Move properties deepenSince and deepenNotRefs up to FetchRequest. In FetchV0Request, they are initialized with their no-op values (0 for deepenSince and empty list for deepenNotRefs) Change-Id: I9d46a6dfbe29ebd794b5a6482033cdc70d411a23 Signed-off-by: Ivan Frade <ifrade@google.com>tags/v5.2.0.201811281532-m3
@@ -44,6 +44,7 @@ package org.eclipse.jgit.transport; | |||
import static java.util.Objects.requireNonNull; | |||
import java.util.List; | |||
import java.util.Set; | |||
import org.eclipse.jgit.annotations.NonNull; | |||
@@ -64,6 +65,10 @@ abstract class FetchRequest { | |||
final Set<String> clientCapabilities; | |||
final int deepenSince; | |||
final List<String> deepenNotRefs; | |||
/** | |||
* Initialize the common fields of a fetch request. | |||
* | |||
@@ -77,15 +82,24 @@ abstract class FetchRequest { | |||
* to exclude blobs on certain conditions | |||
* @param clientCapabilities | |||
* capabilities sent in the request | |||
* @param deepenNotRefs | |||
* Requests that the shallow clone/fetch should be cut at these | |||
* specific revisions instead of a depth. | |||
* @param deepenSince | |||
* Requests that the shallow clone/fetch should be cut at a | |||
* specific time, instead of depth | |||
*/ | |||
FetchRequest(@NonNull Set<ObjectId> wantIds, int depth, | |||
@NonNull Set<ObjectId> clientShallowCommits, long filterBlobLimit, | |||
@NonNull Set<String> clientCapabilities) { | |||
@NonNull Set<String> clientCapabilities, int deepenSince, | |||
@NonNull List<String> deepenNotRefs) { | |||
this.wantIds = requireNonNull(wantIds); | |||
this.depth = depth; | |||
this.clientShallowCommits = requireNonNull(clientShallowCommits); | |||
this.filterBlobLimit = filterBlobLimit; | |||
this.clientCapabilities = requireNonNull(clientCapabilities); | |||
this.deepenSince = deepenSince; | |||
this.deepenNotRefs = requireNonNull(deepenNotRefs); | |||
} | |||
/** | |||
@@ -138,4 +152,23 @@ abstract class FetchRequest { | |||
Set<String> getClientCapabilities() { | |||
return clientCapabilities; | |||
} | |||
/** | |||
* The value in a "deepen-since" line in the request, indicating the | |||
* timestamp where to stop fetching/cloning. | |||
* | |||
* @return timestamp in seconds since the epoch, where to stop the shallow | |||
* fetch/clone. Defaults to 0 if not set in the request. | |||
*/ | |||
int getDeepenSince() { | |||
return deepenSince; | |||
} | |||
/** | |||
* @return refs received in "deepen-not" lines. | |||
*/ | |||
@NonNull | |||
List<String> getDeepenNotRefs() { | |||
return deepenNotRefs; | |||
} | |||
} |
@@ -43,6 +43,7 @@ | |||
package org.eclipse.jgit.transport; | |||
import java.util.Collection; | |||
import java.util.Collections; | |||
import java.util.HashSet; | |||
import java.util.Set; | |||
@@ -58,7 +59,7 @@ final class FetchV0Request extends FetchRequest { | |||
@NonNull Set<ObjectId> clientShallowCommits, long filterBlobLimit, | |||
@NonNull Set<String> clientCapabilities) { | |||
super(wantIds, depth, clientShallowCommits, filterBlobLimit, | |||
clientCapabilities); | |||
clientCapabilities, 0, Collections.emptyList()); | |||
} | |||
static final class Builder { |
@@ -67,10 +67,6 @@ public final class FetchV2Request extends FetchRequest { | |||
private final TreeMap<String, ObjectId> wantedRefs; | |||
private final int deepenSince; | |||
private final List<String> deepenNotRefs; | |||
private final boolean doneReceived; | |||
FetchV2Request(@NonNull List<ObjectId> peerHas, | |||
@@ -80,11 +76,10 @@ public final class FetchV2Request extends FetchRequest { | |||
@NonNull List<String> deepenNotRefs, int depth, | |||
long filterBlobLimit, | |||
boolean doneReceived, @NonNull Set<String> clientCapabilities) { | |||
super(wantIds, depth, clientShallowCommits, filterBlobLimit, clientCapabilities); | |||
super(wantIds, depth, clientShallowCommits, filterBlobLimit, | |||
clientCapabilities, deepenSince, deepenNotRefs); | |||
this.peerHas = requireNonNull(peerHas); | |||
this.wantedRefs = requireNonNull(wantedRefs); | |||
this.deepenSince = deepenSince; | |||
this.deepenNotRefs = requireNonNull(deepenNotRefs); | |||
this.doneReceived = doneReceived; | |||
} | |||
@@ -104,25 +99,6 @@ public final class FetchV2Request extends FetchRequest { | |||
return wantedRefs; | |||
} | |||
/** | |||
* The value in a "deepen-since" line in the request, indicating the | |||
* timestamp where to stop fetching/cloning. | |||
* | |||
* @return timestamp in seconds since the epoch, where to stop the shallow | |||
* fetch/clone. Defaults to 0 if not set in the request. | |||
*/ | |||
int getDeepenSince() { | |||
return deepenSince; | |||
} | |||
/** | |||
* @return refs received in "deepen-not" lines. | |||
*/ | |||
@NonNull | |||
List<String> getDeepenNotRefs() { | |||
return deepenNotRefs; | |||
} | |||
/** | |||
* @return true if the request had a "done" line | |||
*/ | |||
@@ -135,7 +111,6 @@ public final class FetchV2Request extends FetchRequest { | |||
return new Builder(); | |||
} | |||
/** A builder for {@link FetchV2Request}. */ | |||
static final class Builder { | |||
final List<ObjectId> peerHas = new ArrayList<>(); |