Teach UploadPack "ofs-delta" in "fetch"
Add support for the "ofs-delta" parameter in the "fetch" command in the fetch-pack/upload-pack protocol v2. Change-Id: I728cf986082fce4ddeb6a6435897692e15e60cc7 Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
This commit is contained in:
parent
5a87d50408
commit
526f5cf984
|
@ -518,15 +518,18 @@ public void testV2LsRefsRefPrefixNoSlash() throws Exception {
|
||||||
* Parse multiplexed packfile output from upload-pack using protocol V2
|
* Parse multiplexed packfile output from upload-pack using protocol V2
|
||||||
* into the client repository.
|
* into the client repository.
|
||||||
*/
|
*/
|
||||||
private void parsePack(ByteArrayInputStream recvStream) throws Exception {
|
private ReceivedPackStatistics parsePack(ByteArrayInputStream recvStream) throws Exception {
|
||||||
parsePack(recvStream, NullProgressMonitor.INSTANCE);
|
return parsePack(recvStream, NullProgressMonitor.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parsePack(ByteArrayInputStream recvStream, ProgressMonitor pm)
|
private ReceivedPackStatistics parsePack(ByteArrayInputStream recvStream, ProgressMonitor pm)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
SideBandInputStream sb = new SideBandInputStream(
|
SideBandInputStream sb = new SideBandInputStream(
|
||||||
recvStream, pm, new StringWriter(), NullOutputStream.INSTANCE);
|
recvStream, pm,
|
||||||
client.newObjectInserter().newPackParser(sb).parse(NullProgressMonitor.INSTANCE);
|
new StringWriter(), NullOutputStream.INSTANCE);
|
||||||
|
PackParser pp = client.newObjectInserter().newPackParser(sb);
|
||||||
|
pp.parse(NullProgressMonitor.INSTANCE);
|
||||||
|
return pp.getReceivedPackStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -838,6 +841,42 @@ public void testV2FetchIncludeTag() throws Exception {
|
||||||
assertTrue(client.hasObject(tag.toObjectId()));
|
assertTrue(client.hasObject(tag.toObjectId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testV2FetchOfsDelta() throws Exception {
|
||||||
|
String commonInBlob = "abcdefghijklmnopqrstuvwxyz";
|
||||||
|
|
||||||
|
RevBlob parentBlob = remote.blob(commonInBlob + "a");
|
||||||
|
RevCommit parent = remote.commit(remote.tree(remote.file("foo", parentBlob)));
|
||||||
|
RevBlob childBlob = remote.blob(commonInBlob + "b");
|
||||||
|
RevCommit child = remote.commit(remote.tree(remote.file("foo", childBlob)), parent);
|
||||||
|
remote.update("branch1", child);
|
||||||
|
|
||||||
|
// Without ofs-delta.
|
||||||
|
ByteArrayInputStream recvStream = uploadPackV2(
|
||||||
|
"command=fetch\n",
|
||||||
|
PacketLineIn.DELIM,
|
||||||
|
"want " + child.toObjectId().getName() + "\n",
|
||||||
|
"done\n",
|
||||||
|
PacketLineIn.END);
|
||||||
|
PacketLineIn pckIn = new PacketLineIn(recvStream);
|
||||||
|
assertThat(pckIn.readString(), is("packfile"));
|
||||||
|
ReceivedPackStatistics stats = parsePack(recvStream);
|
||||||
|
assertTrue(stats.getNumOfsDelta() == 0);
|
||||||
|
|
||||||
|
// With ofs-delta.
|
||||||
|
recvStream = uploadPackV2(
|
||||||
|
"command=fetch\n",
|
||||||
|
PacketLineIn.DELIM,
|
||||||
|
"want " + child.toObjectId().getName() + "\n",
|
||||||
|
"ofs-delta\n",
|
||||||
|
"done\n",
|
||||||
|
PacketLineIn.END);
|
||||||
|
pckIn = new PacketLineIn(recvStream);
|
||||||
|
assertThat(pckIn.readString(), is("packfile"));
|
||||||
|
stats = parsePack(recvStream);
|
||||||
|
assertTrue(stats.getNumOfsDelta() != 0);
|
||||||
|
}
|
||||||
|
|
||||||
private static class RejectAllRefFilter implements RefFilter {
|
private static class RejectAllRefFilter implements RefFilter {
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Ref> filter(Map<String, Ref> refs) {
|
public Map<String, Ref> filter(Map<String, Ref> refs) {
|
||||||
|
|
|
@ -967,6 +967,8 @@ private void fetchV2() throws IOException {
|
||||||
} else if (line.equals(OPTION_INCLUDE_TAG)) {
|
} else if (line.equals(OPTION_INCLUDE_TAG)) {
|
||||||
options.add(OPTION_INCLUDE_TAG);
|
options.add(OPTION_INCLUDE_TAG);
|
||||||
includeTag = true;
|
includeTag = true;
|
||||||
|
} else if (line.equals(OPTION_OFS_DELTA)) {
|
||||||
|
options.add(OPTION_OFS_DELTA);
|
||||||
}
|
}
|
||||||
// else ignore it
|
// else ignore it
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue