Browse Source

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>
stable-5.0
Jonathan Tan 7 years ago committed by Jonathan Nieder
parent
commit
df1f3c0f3c
  1. 42
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
  2. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

42
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java

@ -21,9 +21,11 @@ import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
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 @@ public class UploadPackTest {
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 class UploadPackTest {
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) {

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

@ -956,6 +956,8 @@ public class UploadPack {
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
}

Loading…
Cancel
Save