]> source.dussan.org Git - jgit.git/commitdiff
Fix BatchRefUpdate progress-monitoring so it doesn't count twice 53/12953/5
authorRoberto Tyley <roberto.tyley@gmail.com>
Sat, 18 May 2013 21:52:55 +0000 (22:52 +0100)
committerRobin Stocker <robin@nibor.org>
Sun, 19 May 2013 11:20:47 +0000 (13:20 +0200)
I was seeing output like this while running The BFG:

Updating references:    200% (374/187)

...issue sneaked in with 5cf53fda I think.

The update call is also moved to the end of the loop, as update() is
only supposed to be called after work has been done ("Denote that some
work units have been completed").

Change-Id: I1620fa75be16dc80df44745d0e123ea512762e31
Signed-off-by: Robin Stocker <robin@nibor.org>
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java

index 9bf3b94c431fa7e45e77e9bbcac5b1130e9af032..a821e948e795e283df59a8f28dbc4d1cf7519a58 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010, Google Inc.
+ * Copyright (C) 2010, 2013 Google Inc.
  * and other copyright owners as documented in the project's IP log.
  *
  * This program and the accompanying materials are made available
@@ -73,6 +73,7 @@ import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
 import org.eclipse.jgit.junit.TestRepository;
 import org.eclipse.jgit.lib.AnyObjectId;
 import org.eclipse.jgit.lib.BatchRefUpdate;
+import org.eclipse.jgit.lib.ProgressMonitor;
 import org.eclipse.jgit.lib.NullProgressMonitor;
 import org.eclipse.jgit.lib.Ref;
 import org.eclipse.jgit.lib.Ref.Storage;
@@ -1191,8 +1192,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
                                                ReceiveCommand.Type.UPDATE_NONFASTFORWARD));
                BatchRefUpdate batchUpdate = refdir.newBatchUpdate();
                batchUpdate.addCommand(commands);
-               batchUpdate
-                               .execute(new RevWalk(diskRepo), NullProgressMonitor.INSTANCE);
+               batchUpdate.execute(new RevWalk(diskRepo), new StrictWorkMonitor());
                Map<String, Ref> refs = refdir.getRefs(RefDatabase.ALL);
                assertEquals(ReceiveCommand.Result.OK, commands.get(0).getResult());
                assertEquals(ReceiveCommand.Result.REJECTED_NONFASTFORWARD, commands
@@ -1215,8 +1215,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
                BatchRefUpdate batchUpdate = refdir.newBatchUpdate();
                batchUpdate.setAllowNonFastForwards(true);
                batchUpdate.addCommand(commands);
-               batchUpdate
-                               .execute(new RevWalk(diskRepo), NullProgressMonitor.INSTANCE);
+               batchUpdate.execute(new RevWalk(diskRepo), new StrictWorkMonitor());
                Map<String, Ref> refs = refdir.getRefs(RefDatabase.ALL);
                assertEquals(ReceiveCommand.Result.OK, commands.get(0).getResult());
                assertEquals(ReceiveCommand.Result.OK, commands.get(1).getResult());
@@ -1267,8 +1266,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
                BatchRefUpdate batchUpdate = refdir.newBatchUpdate();
                batchUpdate.setAllowNonFastForwards(true);
                batchUpdate.addCommand(commands);
-               batchUpdate
-                               .execute(new RevWalk(diskRepo), NullProgressMonitor.INSTANCE);
+               batchUpdate.execute(new RevWalk(diskRepo), new StrictWorkMonitor());
                Map<String, Ref> refs = refdir.getRefs(RefDatabase.ALL);
                assertEquals(ReceiveCommand.Result.OK, commands.get(0).getResult());
                assertEquals(ReceiveCommand.Result.OK, commands.get(1).getResult());
@@ -1311,4 +1309,29 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
                File path = new File(diskRepo.getDirectory(), name);
                assertTrue("deleted " + name, path.delete());
        }
+
+       private static final class StrictWorkMonitor implements ProgressMonitor {
+               private int lastWork, totalWork;
+
+               public void start(int totalTasks) {
+                       // empty
+               }
+
+               public void beginTask(String title, int totalWork) {
+                       this.totalWork = totalWork;
+                       lastWork = 0;
+               }
+
+               public void update(int completed) {
+                       lastWork += completed;
+               }
+
+               public void endTask() {
+                       assertEquals("Units of work recorded", totalWork, lastWork);
+               }
+
+               public boolean isCancelled() {
+                       return false;
+               }
+       }
 }
index b86d6fad8431dbfb0bdf2fbd0aae30b168974407..b369d0d1f581ea06d60021202f818b84dfcf10be 100644 (file)
@@ -294,8 +294,6 @@ public class BatchRefUpdate {
                        // Now to the update that may require more room in the name space
                        for (ReceiveCommand cmd : commands2) {
                                try {
-                                       monitor.update(1);
-
                                        if (cmd.getResult() == NOT_ATTEMPTED) {
                                                cmd.updateType(walk);
                                                RefUpdate ru = newUpdate(cmd);
@@ -305,7 +303,6 @@ public class BatchRefUpdate {
                                                        break;
                                                case UPDATE:
                                                case UPDATE_NONFASTFORWARD:
-                                                       monitor.update(1);
                                                        RefUpdate ruu = newUpdate(cmd);
                                                        cmd.setResult(ruu.update(walk));
                                                        break;
@@ -329,6 +326,8 @@ public class BatchRefUpdate {
                                } catch (IOException err) {
                                        cmd.setResult(REJECTED_OTHER_REASON, MessageFormat.format(
                                                        JGitText.get().lockError, err.getMessage()));
+                               } finally {
+                                       monitor.update(1);
                                }
                        }
                }