Teach UploadPack "no-progress" in "fetch"

Add support for the "no-progress" parameter in the "fetch" command in
the fetch-pack/upload-pack protocol v2.

Change-Id: I6a6d6b1534f44845254b81d0e1f5c4ba2ac3d10b
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
This commit is contained in:
Jonathan Tan 2018-03-01 15:45:19 -08:00 committed by Jonathan Nieder
parent a5dee1c125
commit df1f3c0f3c
2 changed files with 44 additions and 0 deletions

View File

@ -21,9 +21,11 @@
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.Sets;
import org.eclipse.jgit.lib.TextProgressMonitor;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTree;
@ -535,6 +537,13 @@ private void parsePack(ByteArrayInputStream recvStream) throws Exception {
SideBandInputStream sb = new SideBandInputStream(
recvStream, NullProgressMonitor.INSTANCE,
new StringWriter(), NullOutputStream.INSTANCE);
parsePack(recvStream, NullProgressMonitor.INSTANCE);
}
private void parsePack(ByteArrayInputStream recvStream, ProgressMonitor pm)
throws Exception {
SideBandInputStream sb = new SideBandInputStream(
recvStream, pm, new StringWriter(), NullOutputStream.INSTANCE);
client.newObjectInserter().newPackParser(sb).parse(NullProgressMonitor.INSTANCE);
}
@ -781,6 +790,39 @@ public void testV2FetchThinPack() throws Exception {
parsePack(recvStream);
}
@Test
public void testV2FetchNoProgress() throws Exception {
RevCommit commit = remote.commit().message("x").create();
remote.update("branch1", commit);
// Without no-progress, progress is reported.
StringWriter sw = new StringWriter();
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
PacketLineIn.DELIM,
"want " + commit.toObjectId().getName() + "\n",
"done\n",
PacketLineIn.END);
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream, new TextProgressMonitor(sw));
assertFalse(sw.toString().isEmpty());
// With no-progress, progress is not reported.
sw = new StringWriter();
recvStream = uploadPackV2(
"command=fetch\n",
PacketLineIn.DELIM,
"want " + commit.toObjectId().getName() + "\n",
"no-progress\n",
"done\n",
PacketLineIn.END);
pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream, new TextProgressMonitor(sw));
assertTrue(sw.toString().isEmpty());
}
private static class RejectAllRefFilter implements RefFilter {
@Override
public Map<String, Ref> filter(Map<String, Ref> refs) {

View File

@ -956,6 +956,8 @@ private void fetchV2() throws IOException {
doneReceived = true;
} else if (line.equals(OPTION_THIN_PACK)) {
options.add(OPTION_THIN_PACK);
} else if (line.equals(OPTION_NO_PROGRESS)) {
options.add(OPTION_NO_PROGRESS);
}
// else ignore it
}