in org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV2Parser.java [107:219]
FetchV2Request parseFetchRequest(PacketLineIn pckIn)
throws PackProtocolException, IOException {
FetchV2Request.Builder reqBuilder = FetchV2Request.builder();
// Packs are always sent multiplexed and using full 64K
// lengths.
reqBuilder.addClientCapability(OPTION_SIDE_BAND_64K);
String line = consumeCapabilities(pckIn,
serverOption -> reqBuilder.addServerOption(serverOption),
agent -> reqBuilder.setAgent(agent),
clientSID -> reqBuilder.setClientSID(clientSID));
if (PacketLineIn.isEnd(line)) {
return reqBuilder.build();
}
if (!PacketLineIn.isDelimiter(line)) {
throw new PackProtocolException(
MessageFormat.format(JGitText.get().unexpectedPacketLine,
line));
}
boolean filterReceived = false;
for (String line2 : pckIn.readStrings()) {
if (line2.startsWith(PACKET_WANT)) {
reqBuilder.addWantId(ObjectId
.fromString(line2.substring(PACKET_WANT.length())));
} else if (transferConfig.isAllowRefInWant()
&& line2.startsWith(PACKET_WANT_REF)) {
reqBuilder.addWantedRef(
line2.substring(PACKET_WANT_REF.length()));
} else if (line2.startsWith(PACKET_HAVE)) {
reqBuilder.addPeerHas(ObjectId
.fromString(line2.substring(PACKET_HAVE.length())));
} else if (line2.equals(PACKET_DONE)) {
reqBuilder.setDoneReceived();
} else if (line2.equals(OPTION_WAIT_FOR_DONE)) {
reqBuilder.setWaitForDone();
} else if (line2.equals(OPTION_THIN_PACK)) {
reqBuilder.addClientCapability(OPTION_THIN_PACK);
} else if (line2.equals(OPTION_NO_PROGRESS)) {
reqBuilder.addClientCapability(OPTION_NO_PROGRESS);
} else if (line2.equals(OPTION_INCLUDE_TAG)) {
reqBuilder.addClientCapability(OPTION_INCLUDE_TAG);
} else if (line2.equals(OPTION_OFS_DELTA)) {
reqBuilder.addClientCapability(OPTION_OFS_DELTA);
} else if (line2.startsWith(PACKET_SHALLOW)) {
reqBuilder.addClientShallowCommit(
ObjectId.fromString(
line2.substring(PACKET_SHALLOW.length())));
} else if (line2.startsWith(PACKET_DEEPEN)) {
int parsedDepth = Integer
.parseInt(line2.substring(PACKET_DEEPEN.length()));
if (parsedDepth <= 0) {
throw new PackProtocolException(
MessageFormat.format(JGitText.get().invalidDepth,
Integer.valueOf(parsedDepth)));
}
if (reqBuilder.getDeepenSince() != 0) {
throw new PackProtocolException(
JGitText.get().deepenSinceWithDeepen);
}
if (reqBuilder.hasDeepenNots()) {
throw new PackProtocolException(
JGitText.get().deepenNotWithDeepen);
}
reqBuilder.setDepth(parsedDepth);
} else if (line2.startsWith(PACKET_DEEPEN_NOT)) {
reqBuilder.addDeepenNot(
line2.substring(PACKET_DEEPEN_NOT.length()));
if (reqBuilder.getDepth() != 0) {
throw new PackProtocolException(
JGitText.get().deepenNotWithDeepen);
}
} else if (line2.equals(OPTION_DEEPEN_RELATIVE)) {
reqBuilder.addClientCapability(OPTION_DEEPEN_RELATIVE);
} else if (line2.startsWith(PACKET_DEEPEN_SINCE)) {
int ts = Integer.parseInt(
line2.substring(PACKET_DEEPEN_SINCE.length()));
if (ts <= 0) {
throw new PackProtocolException(MessageFormat
.format(JGitText.get().invalidTimestamp, line2));
}
if (reqBuilder.getDepth() != 0) {
throw new PackProtocolException(
JGitText.get().deepenSinceWithDeepen);
}
reqBuilder.setDeepenSince(ts);
} else if (transferConfig.isAllowFilter()
&& line2.startsWith(OPTION_FILTER + ' ')) {
if (filterReceived) {
throw new PackProtocolException(
JGitText.get().tooManyFilters);
}
filterReceived = true;
reqBuilder.setFilterSpec(FilterSpec.fromFilterLine(
line2.substring(OPTION_FILTER.length() + 1)));
} else if (transferConfig.isAllowSidebandAll()
&& line2.equals(OPTION_SIDEBAND_ALL)) {
reqBuilder.setSidebandAll(true);
} else if (line2.startsWith("packfile-uris ")) { //$NON-NLS-1$
for (String s : line2.substring(14).split(",")) { //$NON-NLS-1$
reqBuilder.addPackfileUriProtocol(s);
}
} else {
throw new PackProtocolException(MessageFormat
.format(JGitText.get().unexpectedPacketLine, line2));
}
}
return reqBuilder.build();
}