[history view test] Fix bug in GenerateHistoryJob

The test failed because the job sometimes would not update the UI.

Change-Id: I38d357c6029b551d1e0516bbe9ca2c37e3839fea
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/history/HistoryViewTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/history/HistoryViewTest.java
index 5510c8c..8c035e2 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/history/HistoryViewTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/history/HistoryViewTest.java
@@ -615,7 +615,6 @@
 
 	private void assertCommitsAfterBase(SWTBotTable table, String... commitMsgs)
 			throws Exception {
-		TestUtil.waitForJobs(50, 5000);
 		// There are three expected fixed commits, plus then the ones given in
 		// the parameter.
 		int expectedNumberOfCommits = commitMsgs.length + 3;
@@ -645,7 +644,6 @@
 		assertThat("Expected different commits",
 				getCommitMsgsFromUi(table),
 				is(arrayContainingInAnyOrder(matchers)));
-		table.unselect();
 	}
 
 	@Test
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GenerateHistoryJob.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GenerateHistoryJob.java
index ad95a3f..79ee446 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GenerateHistoryJob.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GenerateHistoryJob.java
@@ -82,9 +82,9 @@
 			final boolean loadIncrementally = !Activator.getDefault()
 					.getPreferenceStore()
 					.getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_FINDTOOLBAR);
+			int initialSize = loadedCommits.size();
 			try {
-				for (;;) {
-					int oldsz = loadedCommits.size();
+				for (int oldsz = initialSize;;) {
 					if (trace)
 						GitTraceLocation.getTrace().trace(
 								GitTraceLocation.HISTORYVIEW.getLocation(),
@@ -116,9 +116,10 @@
 						incomplete = true;
 						break;
 					}
+					oldsz = loadedCommits.size();
 					monitor.setTaskName(MessageFormat.format(
 							UIText.GenerateHistoryJob_taskFoundCommits,
-							Integer.valueOf(loadedCommits.size())));
+							Integer.valueOf(oldsz)));
 				}
 			} catch (IOException e) {
 				status = new Status(IStatus.ERROR, Activator.getPluginId(),
@@ -128,9 +129,14 @@
 				GitTraceLocation.getTrace().trace(
 						GitTraceLocation.HISTORYVIEW.getLocation(),
 						"Loaded " + loadedCommits.size() + " commits"); //$NON-NLS-1$ //$NON-NLS-2$
-			if (commitNotFound) {
-				if (forcedRedrawsAfterListIsCompleted < 1 && !loadIncrementally)
+			if (commitNotFound && !loadedCommits.isEmpty()) {
+				if (forcedRedrawsAfterListIsCompleted < 1
+						&& !loadIncrementally) {
 					page.setWarningTextInUIThread(this);
+				}
+				if (initialSize != loadedCommits.size()) {
+					updateUI(incomplete);
+				}
 			}
 			else
 				updateUI(incomplete);
@@ -149,8 +155,9 @@
 					GitTraceLocation.HISTORYVIEW.getLocation());
 		try {
 			if (forcedRedrawsAfterListIsCompleted != 1 && !incomplete
-					&& loadedCommits.size() == lastUpdateCnt)
+					&& loadedCommits.size() == lastUpdateCnt) {
 				return;
+			}
 			if (forcedRedrawsAfterListIsCompleted == 1)
 				forcedRedrawsAfterListIsCompleted++;
 			final SWTCommit[] asArray = new SWTCommit[loadedCommits.size()];