import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
NB.decodeInt32(data, 56));
}
+ @Test
+ public void testProgressMonitor() throws Exception {
+ RevCommit root = commit();
+ RevCommit a = commit(root);
+ RevCommit b = commit(root);
+ RevCommit tip = commit(a, b);
+ Set<ObjectId> wants = Collections.singleton(tip);
+
+ NonNestedTasksProgressMonitor nonNested = new NonNestedTasksProgressMonitor();
+ GraphCommits graphCommits = GraphCommits.fromWalk(nonNested, wants,
+ walk);
+ writer = new CommitGraphWriter(graphCommits, true);
+ writer.write(nonNested, os);
+ }
+
+ private static class NonNestedTasksProgressMonitor
+ implements ProgressMonitor {
+
+ boolean inTask;
+
+ @Override
+ public void start(int totalTasks) {
+ }
+
+ @Override
+ public void beginTask(String title, int totalWork) {
+ assertFalse("Previous monitoring task is not closed", inTask);
+ inTask = true;
+ }
+
+ @Override
+ public void update(int completed) {
+ }
+
+ @Override
+ public void endTask() {
+ assertTrue("Closing task that wasn't started", inTask);
+ inTask = false;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return false;
+ }
+
+ @Override
+ public void showDuration(boolean enabled) {
+ }
+ }
+
static HashSet<String> changedPathStrings(byte[] data) {
int oidf_offset = -1;
int bidx_offset = -1;
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
-import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
chunks = Collections.unmodifiableList(chunks);
long expectedSize = calculateExpectedSize(chunks);
- long writeCount = 256L + 2 * graphCommits.size()
- + graphCommits.getExtraEdgeCnt();
- monitor.beginTask(
- MessageFormat.format(JGitText.get().writingOutCommitGraph,
- Integer.valueOf(chunks.size())),
- (int) writeCount);
-
try (CancellableDigestOutputStream out = new CancellableDigestOutputStream(
monitor, commitGraphStream)) {
writeHeader(out, chunks.size());
} catch (InterruptedIOException e) {
throw new IOException(JGitText.get().commitGraphWritingCancelled,
e);
- } finally {
- monitor.endTask();
}
return Stats.from(bloomFilterChunks);
}
private void writeCommitData(ProgressMonitor monitor,
CancellableDigestOutputStream out) throws IOException {
int[] generations = computeGenerationNumbers(monitor);
+ monitor.beginTask(JGitText.get().writingOutCommitGraph,
+ graphCommits.size());
int num = 0;
byte[] tmp = new byte[hashsz + COMMIT_DATA_WIDTH];
int i = 0;
out.getWriteMonitor().update(1);
i++;
}
+ monitor.endTask();
}
private int[] computeGenerationNumbers(ProgressMonitor monitor)