Browse Source

Put filter spec information in a dedicated object

This increases type-safety and is ground work for support of the
"tree:<depth>" filter.

Change-Id: Id19eacdcdaddb9132064c642f6d554b1060efe9f
Signed-off-by: Matthew DeVore <matvore@gmail.com>
stable-5.4
Matthew DeVore 6 years ago
parent
commit
cc9ca71a16
  1. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java
  2. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java
  3. 18
      org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchRequest.java
  4. 21
      org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV0Request.java
  5. 19
      org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java
  6. 52
      org.eclipse.jgit/src/org/eclipse/jgit/transport/FilterSpec.java
  7. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV0Parser.java
  8. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV2Parser.java
  9. 10
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java

@ -193,7 +193,7 @@ public class ProtocolV0ParserTest {
assertThat(request.getWantIds(),
hasOnlyObjectIds("4624442d68ee402a94364191085b77137618633e",
"f900c8326a43303685c46b279b9f70411bff1a4b"));
assertEquals(13000, request.getFilterBlobLimit());
assertEquals(13000, request.getFilterSpec().getBlobLimit());
}
}

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java

@ -232,7 +232,7 @@ public class ProtocolV2ParserTest {
ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.start().allowFilter().done());
FetchV2Request request = parser.parseFetchRequest(pckIn);
assertEquals(0, request.getFilterBlobLimit());
assertEquals(0, request.getFilterSpec().getBlobLimit());
}
@Test
@ -243,7 +243,7 @@ public class ProtocolV2ParserTest {
ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.start().allowFilter().done());
FetchV2Request request = parser.parseFetchRequest(pckIn);
assertEquals(15, request.getFilterBlobLimit());
assertEquals(15, request.getFilterSpec().getBlobLimit());
}
@Test

18
org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchRequest.java

@ -62,7 +62,7 @@ abstract class FetchRequest {
final Set<ObjectId> clientShallowCommits;
final long filterBlobLimit;
final FilterSpec filterSpec;
final Set<String> clientCapabilities;
@ -82,8 +82,8 @@ abstract class FetchRequest {
* how deep to go in the tree
* @param clientShallowCommits
* commits the client has without history
* @param filterBlobLimit
* to exclude blobs on certain conditions
* @param filterSpec
* the filter spec
* @param clientCapabilities
* capabilities sent in the request
* @param deepenNotRefs
@ -96,13 +96,14 @@ abstract class FetchRequest {
* agent as reported by the client in the request body
*/
FetchRequest(@NonNull Set<ObjectId> wantIds, int depth,
@NonNull Set<ObjectId> clientShallowCommits, long filterBlobLimit,
@NonNull Set<ObjectId> clientShallowCommits,
@NonNull FilterSpec filterSpec,
@NonNull Set<String> clientCapabilities, int deepenSince,
@NonNull List<String> deepenNotRefs, @Nullable String agent) {
this.wantIds = requireNonNull(wantIds);
this.depth = depth;
this.clientShallowCommits = requireNonNull(clientShallowCommits);
this.filterBlobLimit = filterBlobLimit;
this.filterSpec = requireNonNull(filterSpec);
this.clientCapabilities = requireNonNull(clientCapabilities);
this.deepenSince = deepenSince;
this.deepenNotRefs = requireNonNull(deepenNotRefs);
@ -137,10 +138,11 @@ abstract class FetchRequest {
}
/**
* @return the blob limit set in a "filter" line (-1 if not set)
* @return the filter spec given in a "filter" line
*/
long getFilterBlobLimit() {
return filterBlobLimit;
@NonNull
FilterSpec getFilterSpec() {
return filterSpec;
}
/**

21
org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV0Request.java

@ -42,6 +42,8 @@
*/
package org.eclipse.jgit.transport;
import static java.util.Objects.requireNonNull;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@ -57,10 +59,11 @@ import org.eclipse.jgit.lib.ObjectId;
final class FetchV0Request extends FetchRequest {
FetchV0Request(@NonNull Set<ObjectId> wantIds, int depth,
@NonNull Set<ObjectId> clientShallowCommits, long filterBlobLimit,
@NonNull Set<ObjectId> clientShallowCommits,
@NonNull FilterSpec filterSpec,
@NonNull Set<String> clientCapabilities, @Nullable String agent) {
super(wantIds, depth, clientShallowCommits, filterBlobLimit,
clientCapabilities, 0, Collections.emptyList(), agent);
super(wantIds, depth, clientShallowCommits, filterSpec,
clientCapabilities, 0, Collections.emptyList(), agent);
}
static final class Builder {
@ -71,7 +74,7 @@ final class FetchV0Request extends FetchRequest {
final Set<ObjectId> clientShallowCommits = new HashSet<>();
long filterBlobLimit = -1;
FilterSpec filterSpec = FilterSpec.NO_FILTER;
final Set<String> clientCaps = new HashSet<>();
@ -129,18 +132,18 @@ final class FetchV0Request extends FetchRequest {
}
/**
* @param filterBlobLim
* blob limit set in a "filter" line
* @param filter
* the filter set in a filter line
* @return this builder
*/
Builder setFilterBlobLimit(long filterBlobLim) {
filterBlobLimit = filterBlobLim;
Builder setFilterSpec(@NonNull FilterSpec filter) {
filterSpec = requireNonNull(filter);
return this;
}
FetchV0Request build() {
return new FetchV0Request(wantIds, depth, clientShallowCommits,
filterBlobLimit, clientCaps, agent);
filterSpec, clientCaps, agent);
}
}

19
org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java

@ -77,11 +77,12 @@ public final class FetchV2Request extends FetchRequest {
@NonNull Set<ObjectId> wantIds,
@NonNull Set<ObjectId> clientShallowCommits, int deepenSince,
@NonNull List<String> deepenNotRefs, int depth,
long filterBlobLimit,
@NonNull FilterSpec filterSpec,
boolean doneReceived, @NonNull Set<String> clientCapabilities,
@Nullable String agent, @NonNull List<String> serverOptions) {
super(wantIds, depth, clientShallowCommits, filterBlobLimit,
clientCapabilities, deepenSince, deepenNotRefs, agent);
super(wantIds, depth, clientShallowCommits, filterSpec,
clientCapabilities, deepenSince,
deepenNotRefs, agent);
this.peerHas = requireNonNull(peerHas);
this.wantedRefs = requireNonNull(wantedRefs);
this.doneReceived = doneReceived;
@ -149,7 +150,7 @@ public final class FetchV2Request extends FetchRequest {
int deepenSince;
long filterBlobLimit = -1;
FilterSpec filterSpec = FilterSpec.NO_FILTER;
boolean doneReceived;
@ -268,12 +269,12 @@ public final class FetchV2Request extends FetchRequest {
}
/**
* @param filterBlobLim
* set in a "filter" line
* @param filter
* spec set in a "filter" line
* @return this builder
*/
Builder setFilterBlobLimit(long filterBlobLim) {
filterBlobLimit = filterBlobLim;
Builder setFilterSpec(@NonNull FilterSpec filter) {
filterSpec = requireNonNull(filter);
return this;
}
@ -322,7 +323,7 @@ public final class FetchV2Request extends FetchRequest {
FetchV2Request build() {
return new FetchV2Request(peerHas, wantedRefs, wantIds,
clientShallowCommits, deepenSince, deepenNotRefs,
depth, filterBlobLimit, doneReceived, clientCapabilities,
depth, filterSpec, doneReceived, clientCapabilities,
agent, Collections.unmodifiableList(serverOptions));
}
}

52
org.eclipse.jgit/src/org/eclipse/jgit/transport/FilterSpec.java

@ -49,24 +49,31 @@ import org.eclipse.jgit.errors.PackProtocolException;
import org.eclipse.jgit.internal.JGitText;
/**
* Utility code for dealing with filter lines.
* Represents either a filter specified in a protocol "filter" line, or a
* placeholder to indicate no filtering.
*
* @since 5.4
*/
final class FilterSpec {
public final class FilterSpec {
private final long blobLimit;
private FilterSpec() {}
private FilterSpec(long blobLimit) {
this.blobLimit = blobLimit;
}
/*
/**
* Process the content of "filter" line from the protocol. It has a shape
* like "blob:none" or "blob:limit=N", with limit a positive number.
*
* @param filterLine
* the content of the "filter" line in the protocol
* @return N, the limit, defaulting to 0 if "none"
* @return a FilterSpec representing the given filter
* @throws PackProtocolException
* invalid filter because due to unrecognized format or
* negative/non-numeric filter.
*/
static long parseFilterLine(String filterLine)
public static FilterSpec fromFilterLine(String filterLine)
throws PackProtocolException {
long blobLimit = -1;
@ -92,7 +99,40 @@ final class FilterSpec {
JGitText.get().invalidFilter, filterLine));
}
return new FilterSpec(blobLimit);
}
/**
* @param blobLimit
* the blob limit in a "blob:[limit]" or "blob:none" filter line
* @return a filter spec which filters blobs above a certain size
*/
static FilterSpec withBlobLimit(long blobLimit) {
if (blobLimit < 0) {
throw new IllegalArgumentException(
"blobLimit cannot be negative: " + blobLimit); //$NON-NLS-1$
}
return new FilterSpec(blobLimit);
}
/**
* A placeholder that indicates no filtering.
*/
public static final FilterSpec NO_FILTER = new FilterSpec(-1);
/**
* @return -1 if this filter does not filter blobs based on size, or a
* non-negative integer representing the max size of blobs to allow
*/
public long getBlobLimit() {
return blobLimit;
}
/**
* @return true if this filter doesn't filter out anything
*/
public boolean isNoOp() {
return blobLimit == -1;
}
}

2
org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV0Parser.java

@ -130,7 +130,7 @@ final class ProtocolV0Parser {
}
filterReceived = true;
reqBuilder.setFilterBlobLimit(FilterSpec.parseFilterLine(arg));
reqBuilder.setFilterSpec(FilterSpec.fromFilterLine(arg));
continue;
}

2
org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV2Parser.java

@ -207,7 +207,7 @@ final class ProtocolV2Parser {
JGitText.get().tooManyFilters);
}
filterReceived = true;
reqBuilder.setFilterBlobLimit(FilterSpec.parseFilterLine(
reqBuilder.setFilterSpec(FilterSpec.fromFilterLine(
line.substring(OPTION_FILTER.length() + 1)));
} else {
throw new PackProtocolException(MessageFormat

10
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

@ -1536,7 +1536,7 @@ public class UploadPack {
if (currentRequest == null) {
throw new RequestNotYetReadException();
}
return currentRequest.getFilterBlobLimit();
return currentRequest.getFilterSpec().getBlobLimit();
}
/**
@ -2098,11 +2098,11 @@ public class UploadPack {
accumulator);
try {
pw.setIndexDisabled(true);
if (req.getFilterBlobLimit() >= 0) {
pw.setFilterBlobLimit(req.getFilterBlobLimit());
pw.setUseCachedPacks(false);
} else {
if (req.getFilterSpec().isNoOp()) {
pw.setUseCachedPacks(true);
} else {
pw.setFilterBlobLimit(req.getFilterSpec().getBlobLimit());
pw.setUseCachedPacks(false);
}
pw.setUseBitmaps(
req.getDepth() == 0

Loading…
Cancel
Save