Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2018-08-24 14:56:17 +0000
committerThomas Wolf2018-08-24 15:07:43 +0000
commit6e3336f9afd68d46e54a5cfb775ac52c2f349359 (patch)
tree44149495e4da8dc39c05e3dd8dad557e5af0f472
parentb8141d8b8c8309955d6bc023735cc211b03fd56f (diff)
downloadegit-6e3336f9afd68d46e54a5cfb775ac52c2f349359.tar.gz
egit-6e3336f9afd68d46e54a5cfb775ac52c2f349359.tar.xz
egit-6e3336f9afd68d46e54a5cfb775ac52c2f349359.zip
Avoid UI blocks in ReflogView
The view already loads the reflog in the background. But the (short) commit message was obtained through RevWalk.parseCommit inside the label provider. This is a potentially long-running operation, and the label provider runs in the UI thread. Avoid this by getting the commit messages up front in the background, too. Change-Id: If0f33d391659aa774ac5d71f7a85dafa4792a193 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/ReflogItem.java18
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/ReflogView.java19
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/ReflogViewContentProvider.java18
3 files changed, 35 insertions, 20 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/ReflogItem.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/ReflogItem.java
index 1b10190ef2..6229465f93 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/ReflogItem.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/ReflogItem.java
@@ -31,9 +31,12 @@ public class ReflogItem implements ReflogEntry, IAdaptable, IRepositoryObject {
private final ReflogInput input;
- ReflogItem(ReflogInput input, ReflogEntry entry) {
+ private final String commitMessage;
+
+ ReflogItem(ReflogInput input, ReflogEntry entry, String commitMessage) {
this.entry = entry;
this.input = input;
+ this.commitMessage = commitMessage;
}
@SuppressWarnings("unchecked")
@@ -73,6 +76,14 @@ public class ReflogItem implements ReflogEntry, IAdaptable, IRepositoryObject {
return entry.parseCheckout();
}
+ /**
+ * @return the (short) commit message of the commit, if any, or {@code null}
+ * otherwise.
+ */
+ public String getCommitMessage() {
+ return commitMessage;
+ }
+
@Override
public boolean equals(Object obj) {
if (obj == this) {
@@ -83,6 +94,7 @@ public class ReflogItem implements ReflogEntry, IAdaptable, IRepositoryObject {
}
ReflogItem other = (ReflogItem) obj;
return input == other.input
+ && Objects.equals(commitMessage, other.commitMessage)
&& Objects.equals(getNewId(), other.getNewId())
&& Objects.equals(getOldId(), other.getOldId())
&& Objects.equals(getWho(), other.getWho())
@@ -91,8 +103,8 @@ public class ReflogItem implements ReflogEntry, IAdaptable, IRepositoryObject {
@Override
public int hashCode() {
- return Objects.hash(input, getNewId(), getOldId(), getWho(),
- getComment());
+ return Objects.hash(input, commitMessage, getNewId(), getOldId(),
+ getWho(), getComment());
}
@Override
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/ReflogView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/ReflogView.java
index 8ae1d118b5..f123ce5094 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/ReflogView.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/ReflogView.java
@@ -67,7 +67,6 @@ import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.ReflogEntry;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryState;
-import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
@@ -225,25 +224,15 @@ public class ReflogView extends ViewPart implements RefsChangedListener, IShowIn
@Override
public String getText(Object element) {
- if (element instanceof ReflogEntry) {
- final ReflogEntry entry = (ReflogEntry) element;
- RevCommit c = getCommit(entry);
- return c == null ? "" : c.getShortMessage(); //$NON-NLS-1$
+ if (element instanceof ReflogItem) {
+ ReflogItem entry = (ReflogItem) element;
+ String c = entry.getCommitMessage();
+ return c == null ? "" : c; //$NON-NLS-1$
} else if (element instanceof IWorkbenchAdapter) {
return ((IWorkbenchAdapter) element).getLabel(element);
}
return null;
}
-
- private RevCommit getCommit(final ReflogEntry entry) {
- try (RevWalk walk = new RevWalk(getRepository())) {
- walk.setRetainBody(true);
- return walk.parseCommit(entry.getNewId());
- } catch (IOException ignored) {
- // ignore
- return null;
- }
- }
});
TreeViewerColumn dateColumn = createColumn(layout,
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/ReflogViewContentProvider.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/ReflogViewContentProvider.java
index 6bafb1a0db..d0c55bba75 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/ReflogViewContentProvider.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/reflog/ReflogViewContentProvider.java
@@ -15,6 +15,7 @@
package org.eclipse.egit.ui.internal.reflog;
import java.io.File;
+import java.io.IOException;
import java.util.Objects;
import org.eclipse.core.runtime.Assert;
@@ -29,6 +30,7 @@ import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.model.WorkbenchAdapter;
import org.eclipse.ui.progress.DeferredTreeContentManager;
@@ -140,9 +142,21 @@ public class ReflogViewContentProvider implements ITreeContentProvider {
if (refLog != null) {
return; // Already loaded.
}
- try (Git git = new Git(repository)) {
+ try (Git git = new Git(repository);
+ RevWalk walk = new RevWalk(repository)) {
refLog = git.reflog().setRef(ref).call().stream()
- .map(entry -> new ReflogItem(ReflogInput.this, entry))
+ .map(entry -> {
+ String commitMessage = null;
+ try {
+ commitMessage = walk
+ .parseCommit(entry.getNewId())
+ .getShortMessage();
+ } catch (IOException e) {
+ // Ignore here
+ }
+ return new ReflogItem(ReflogInput.this, entry,
+ commitMessage);
+ })
.toArray(ReflogItem[]::new);
collector.add(refLog, monitor);
} catch (Exception e) {

Back to the top