Browse Source

Rename Fetch V2 request wantsIds and options

In FetchV0Request, the fields "wantsIds" and "options" are called
"wantIds" and "clientCapabilities". Those names describe them better.

Rename FetchV2Request fields to follow fetch v0. This will make easier
to extract a superclass later.

Take also the chance to polish the javadoc.

Change-Id: Ia17dbbab8084f39cc529fef9ca5c65e189073767
Signed-off-by: Ivan Frade <ifrade@google.com>
stable-5.2
Ivan Frade 6 years ago
parent
commit
8460ab8e87
  1. 16
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java
  2. 113
      org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java
  3. 16
      org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV2Parser.java
  4. 8
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

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

@ -163,15 +163,15 @@ public class ProtocolV2ParserTest {
ConfigBuilder.getDefault());
FetchV2Request request = parser.parseFetchRequest(pckIn,
testRepo.getRepository().getRefDatabase());
assertTrue(request.getOptions()
assertTrue(request.getClientCapabilities()
.contains(GitProtocolConstants.OPTION_THIN_PACK));
assertTrue(request.getOptions()
assertTrue(request.getClientCapabilities()
.contains(GitProtocolConstants.OPTION_NO_PROGRESS));
assertTrue(request.getOptions()
assertTrue(request.getClientCapabilities()
.contains(GitProtocolConstants.OPTION_INCLUDE_TAG));
assertTrue(request.getOptions()
assertTrue(request.getClientCapabilities()
.contains(GitProtocolConstants.CAPABILITY_OFS_DELTA));
assertThat(objIdsAsStrings(request.getWantsIds()),
assertThat(objIdsAsStrings(request.getWantIds()),
hasItems("4624442d68ee402a94364191085b77137618633e",
"f900c8326a43303685c46b279b9f70411bff1a4b"));
assertThat(objIdsAsStrings(request.getPeerHas()),
@ -199,7 +199,7 @@ public class ProtocolV2ParserTest {
"145e683b229dcab9d0e2ccb01b386f9ecc17d29d"));
assertTrue(request.getDeepenNotRefs().isEmpty());
assertEquals(15, request.getDepth());
assertTrue(request.getOptions()
assertTrue(request.getClientCapabilities()
.contains(GitProtocolConstants.OPTION_DEEPEN_RELATIVE));
}
@ -308,8 +308,8 @@ public class ProtocolV2ParserTest {
assertEquals(1, request.getWantedRefs().size());
assertThat(request.getWantedRefs().keySet(),
hasItems("refs/heads/branchA"));
assertEquals(2, request.getWantsIds().size());
assertThat(objIdsAsStrings(request.getWantsIds()),
assertEquals(2, request.getWantIds().size());
assertThat(objIdsAsStrings(request.getWantIds()),
hasItems("e4980cdc48cfa1301493ca94eb70523f6788b819",
one.getName()));
}

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

@ -53,7 +53,7 @@ import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.lib.ObjectId;
/**
* fetch protocol v2 request.
* Fetch request from git protocol v2.
*
* <p>
* This is used as an input to {@link ProtocolV2Hook}.
@ -65,7 +65,7 @@ public final class FetchV2Request {
private final TreeMap<String, ObjectId> wantedRefs;
private final Set<ObjectId> wantsIds;
private final Set<ObjectId> wantIds;
private final Set<ObjectId> clientShallowCommits;
@ -77,37 +77,37 @@ public final class FetchV2Request {
private final long filterBlobLimit;
private final Set<String> options;
private final Set<String> clientCapabilities;
private final boolean doneReceived;
private FetchV2Request(List<ObjectId> peerHas,
TreeMap<String, ObjectId> wantedRefs, Set<ObjectId> wantsIds,
TreeMap<String, ObjectId> wantedRefs, Set<ObjectId> wantIds,
Set<ObjectId> clientShallowCommits, int deepenSince,
List<String> deepenNotRefs, int depth, long filterBlobLimit,
boolean doneReceived, Set<String> options) {
boolean doneReceived, Set<String> clientCapabilities) {
this.peerHas = peerHas;
this.wantedRefs = wantedRefs;
this.wantsIds = wantsIds;
this.wantIds = wantIds;
this.clientShallowCommits = clientShallowCommits;
this.deepenSince = deepenSince;
this.deepenNotRefs = deepenNotRefs;
this.depth = depth;
this.filterBlobLimit = filterBlobLimit;
this.doneReceived = doneReceived;
this.options = options;
this.clientCapabilities = clientCapabilities;
}
/**
* @return object ids in the "have" lines of the request
* @return object ids received in the "have" lines
*/
@NonNull
List<ObjectId> getPeerHas() {
return this.peerHas;
return peerHas;
}
/**
* @return list of references in the "want-ref" lines of the request
* @return list of references received in "want-ref" lines
*/
@NonNull
Map<String, ObjectId> getWantedRefs() {
@ -115,11 +115,11 @@ public final class FetchV2Request {
}
/**
* @return object ids in the "want" (and "want-ref") lines of the request
* @return object ids received in the "want" and "want-ref" lines
*/
@NonNull
Set<ObjectId> getWantsIds() {
return wantsIds;
Set<ObjectId> getWantIds() {
return wantIds;
}
/**
@ -146,7 +146,7 @@ public final class FetchV2Request {
}
/**
* @return the refs in "deepen-not" lines in the request.
* @return refs received in "deepen-not" lines.
*/
@NonNull
List<String> getDeepenNotRefs() {
@ -184,8 +184,8 @@ public final class FetchV2Request {
* @return options found in the request lines
*/
@NonNull
Set<String> getOptions() {
return options;
Set<String> getClientCapabilities() {
return clientCapabilities;
}
/** @return A builder of {@link FetchV2Request}. */
@ -200,13 +200,13 @@ public final class FetchV2Request {
TreeMap<String, ObjectId> wantedRefs = new TreeMap<>();
Set<ObjectId> wantsIds = new HashSet<>();
Set<ObjectId> wantIds = new HashSet<>();
Set<ObjectId> clientShallowCommits = new HashSet<>();
List<String> deepenNotRefs = new ArrayList<>();
Set<String> options = new HashSet<>();
Set<String> clientCapabilities = new HashSet<>();
int depth;
@ -221,8 +221,8 @@ public final class FetchV2Request {
/**
* @param objectId
* from a "have" line in a fetch request
* @return the builder
* object id received in a "have" line
* @return this builder
*/
Builder addPeerHas(ObjectId objectId) {
peerHas.add(objectId);
@ -230,13 +230,13 @@ public final class FetchV2Request {
}
/**
* From a "want-ref" line in a fetch request
* Ref received in "want-ref" line and the object-id it refers to
*
* @param refName
* reference name
* @param oid
* object id
* @return the builder
* object id the reference is pointing at
* @return this builder
*/
Builder addWantedRef(String refName, ObjectId oid) {
wantedRefs.put(refName, oid);
@ -244,42 +244,42 @@ public final class FetchV2Request {
}
/**
* @param option
* fetch request lines acting as options
* @return the builder
* @param clientCapability
* capability line sent by the client
* @return this builder
*/
Builder addOption(String option) {
options.add(option);
Builder addClientCapability(String clientCapability) {
clientCapabilities.add(clientCapability);
return this;
}
/**
* @param objectId
* from a "want" line in a fetch request
* @return the builder
* @param wantId
* object id received in a "want" line
* @return this builder
*/
Builder addWantsIds(ObjectId objectId) {
wantsIds.add(objectId);
Builder addWantId(ObjectId wantId) {
wantIds.add(wantId);
return this;
}
/**
* @param shallowOid
* from a "shallow" line in the fetch request
* @return the builder
* object id received in a "shallow" line
* @return this builder
*/
Builder addClientShallowCommit(ObjectId shallowOid) {
this.clientShallowCommits.add(shallowOid);
clientShallowCommits.add(shallowOid);
return this;
}
/**
* @param d
* from a "deepen" line in the fetch request
* @return the builder
* Depth received in a "deepen" line
* @return this builder
*/
Builder setDepth(int d) {
this.depth = d;
depth = d;
return this;
}
@ -288,32 +288,34 @@ public final class FetchV2Request {
* 0 if not set.
*/
int getDepth() {
return this.depth;
return depth;
}
/**
* @return if there has been any "deepen not" line in the request
* @return true if there has been at least one "deepen not" line in the
* request so far
*/
boolean hasDeepenNotRefs() {
return !deepenNotRefs.isEmpty();
}
/**
* @param deepenNotRef reference in a "deepen not" line
* @return the builder
* @param deepenNotRef
* reference received in a "deepen not" line
* @return this builder
*/
Builder addDeepenNotRef(String deepenNotRef) {
this.deepenNotRefs.add(deepenNotRef);
deepenNotRefs.add(deepenNotRef);
return this;
}
/**
* @param value
* Unix timestamp received in a "deepen since" line
* @return the builder
* @return this builder
*/
Builder setDeepenSince(int value) {
this.deepenSince = value;
deepenSince = value;
return this;
}
@ -322,35 +324,36 @@ public final class FetchV2Request {
* by default.
*/
int getDeepenSince() {
return this.deepenSince;
return deepenSince;
}
/**
* @param filterBlobLimit
* @param filterBlobLim
* set in a "filter" line
* @return the builder
* @return this builder
*/
Builder setFilterBlobLimit(long filterBlobLimit) {
this.filterBlobLimit = filterBlobLimit;
Builder setFilterBlobLimit(long filterBlobLim) {
filterBlobLimit = filterBlobLim;
return this;
}
/**
* Mark that the "done" line has been received.
*
* @return the builder
* @return this builder
*/
Builder setDoneReceived() {
this.doneReceived = true;
doneReceived = true;
return this;
}
/**
* @return Initialized fetch request
*/
FetchV2Request build() {
return new FetchV2Request(peerHas, wantedRefs, wantsIds,
return new FetchV2Request(peerHas, wantedRefs, wantIds,
clientShallowCommits, deepenSince, deepenNotRefs,
depth, filterBlobLimit, doneReceived, options);
depth, filterBlobLimit, doneReceived, clientCapabilities);
}
}
}

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

@ -104,7 +104,7 @@ final class ProtocolV2Parser {
// Packs are always sent multiplexed and using full 64K
// lengths.
reqBuilder.addOption(OPTION_SIDE_BAND_64K);
reqBuilder.addClientCapability(OPTION_SIDE_BAND_64K);
String line;
@ -118,7 +118,7 @@ final class ProtocolV2Parser {
boolean filterReceived = false;
while ((line = pckIn.readString()) != PacketLineIn.END) {
if (line.startsWith("want ")) { //$NON-NLS-1$
reqBuilder.addWantsIds(ObjectId.fromString(line.substring(5)));
reqBuilder.addWantId(ObjectId.fromString(line.substring(5)));
} else if (transferConfig.isAllowRefInWant()
&& line.startsWith(OPTION_WANT_REF + " ")) { //$NON-NLS-1$
String refName = line.substring(OPTION_WANT_REF.length() + 1);
@ -136,19 +136,19 @@ final class ProtocolV2Parser {
.format(JGitText.get().invalidRefName, refName));
}
reqBuilder.addWantedRef(refName, oid);
reqBuilder.addWantsIds(oid);
reqBuilder.addWantId(oid);
} else if (line.startsWith("have ")) { //$NON-NLS-1$
reqBuilder.addPeerHas(ObjectId.fromString(line.substring(5)));
} else if (line.equals("done")) { //$NON-NLS-1$
reqBuilder.setDoneReceived();
} else if (line.equals(OPTION_THIN_PACK)) {
reqBuilder.addOption(OPTION_THIN_PACK);
reqBuilder.addClientCapability(OPTION_THIN_PACK);
} else if (line.equals(OPTION_NO_PROGRESS)) {
reqBuilder.addOption(OPTION_NO_PROGRESS);
reqBuilder.addClientCapability(OPTION_NO_PROGRESS);
} else if (line.equals(OPTION_INCLUDE_TAG)) {
reqBuilder.addOption(OPTION_INCLUDE_TAG);
reqBuilder.addClientCapability(OPTION_INCLUDE_TAG);
} else if (line.equals(OPTION_OFS_DELTA)) {
reqBuilder.addOption(OPTION_OFS_DELTA);
reqBuilder.addClientCapability(OPTION_OFS_DELTA);
} else if (line.startsWith("shallow ")) { //$NON-NLS-1$
reqBuilder.addClientShallowCommit(
ObjectId.fromString(line.substring(8)));
@ -175,7 +175,7 @@ final class ProtocolV2Parser {
JGitText.get().deepenNotWithDeepen);
}
} else if (line.equals(OPTION_DEEPEN_RELATIVE)) {
reqBuilder.addOption(OPTION_DEEPEN_RELATIVE);
reqBuilder.addClientCapability(OPTION_DEEPEN_RELATIVE);
} else if (line.startsWith("deepen-since ")) { //$NON-NLS-1$
int ts = Integer.parseInt(line.substring(13));
if (ts <= 0) {

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

@ -964,8 +964,8 @@ public class UploadPack {
// TODO(ifrade): Refactor to pass around the Request object, instead of
// copying data back to class fields
options = req.getOptions();
wantIds.addAll(req.getWantsIds());
options = req.getClientCapabilities();
wantIds = req.getWantIds();
clientShallowCommits = req.getClientShallowCommits();
depth = req.getDepth();
shallowSince = req.getDeepenSince();
@ -983,7 +983,7 @@ public class UploadPack {
verifyClientShallow(req.getClientShallowCommits());
}
if (mayHaveShallow) {
computeShallowsAndUnshallows(req.getWantsIds(),
computeShallowsAndUnshallows(req.getWantIds(),
shallowCommit -> shallowCommits.add(shallowCommit),
unshallowCommit -> unshallowCommits.add(unshallowCommit));
}
@ -1041,7 +1041,7 @@ public class UploadPack {
pckOut.writeDelim();
pckOut.writeString("packfile\n"); //$NON-NLS-1$
sendPack(new PackStatistics.Accumulator(),
req.getOptions().contains(OPTION_INCLUDE_TAG)
req.getClientCapabilities().contains(OPTION_INCLUDE_TAG)
? db.getRefDatabase().getRefsByPrefix(R_TAGS)
: null,
unshallowCommits);

Loading…
Cancel
Save