Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-12-14 16:07:06 +0000
committerThomas Wolf2019-12-15 20:03:40 +0000
commitefc4d4acc01e6ccbee512d065e714e6342fc645e (patch)
treeebd218a9b92896d47f8a4107570cf92d8f621675
parent9244bc84355894bc353ba374978f1f92d49d81de (diff)
downloadegit-efc4d4acc01e6ccbee512d065e714e6342fc645e.tar.gz
egit-efc4d4acc01e6ccbee512d065e714e6342fc645e.tar.xz
egit-efc4d4acc01e6ccbee512d065e714e6342fc645e.zip
[deco cache] Reset BranchStatus cache on ConfigChangedEvent
Otherwise labels are not updated when a branch is (re-)configured. Bug: 558323 Change-Id: Ifa47c0edcaf4bc3b73682ac2f2ac33e976a95155 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java59
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratorRepositoryStateCache.java27
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitDecorator.java21
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java9
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoryTreeNodeDecorator.java7
5 files changed, 101 insertions, 22 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java
index 27c32d70b..7e181a2c0 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java
@@ -86,6 +86,11 @@ public class GitRepositoriesViewBranchHandlingTest extends
setVerboseBranchMode(false);
repositoryFile = createProjectAndCommitToRepository();
remoteRepositoryFile = createRemoteRepository(repositoryFile);
+ // Create one more branch on HEAD^1
+ try (Git git = new Git(lookupRepository(remoteRepositoryFile))) {
+ git.branchCreate().setName("initial").setStartPoint("HEAD^1")
+ .call();
+ }
// now let's clone the remote repository
final URIish uri = new URIish(remoteRepositoryFile.getPath());
final File workdir = new File(getTestDirectory(), "Cloned");
@@ -233,7 +238,9 @@ public class GitRepositoriesViewBranchHandlingTest extends
item = TestUtil.expandAndWait(myRepoViewUtil.getRemoteBranchesItem(tree,
clonedRepositoryFile));
children = item.getNodes();
- assertEquals("Wrong number of children", 2, children.size());
+ assertEquals("Wrong number of children", 3, children.size());
+ assertTrue("Missing remote branch",
+ children.contains("origin/initial"));
assertTrue("Missing remote branch", children.contains("origin/master"));
assertTrue("Missing remote branch", children.contains("origin/stable"));
item.getNode("origin/stable").select();
@@ -270,7 +277,7 @@ public class GitRepositoriesViewBranchHandlingTest extends
item = TestUtil.expandAndWait(myRepoViewUtil.getRemoteBranchesItem(tree,
clonedRepositoryFile));
List<String> children = item.getNodes();
- assertEquals("Wrong number of remote children", 2, children.size());
+ assertEquals("Wrong number of remote children", 3, children.size());
item.getNode("origin/stable").select();
ContextMenuHelper.clickContextMenuSync(tree,
@@ -537,4 +544,52 @@ public class GitRepositoriesViewBranchHandlingTest extends
.getNode(UIText.BranchPropertySource_RebaseDescriptor);
assertEquals("true", rebaseItem.cell(1));
}
+
+ @Test
+ public void testBranchConfigurationDecoration() throws Exception {
+ SWTBotView view = getOrOpenView();
+
+ SWTBotTreeItem repoItem = myRepoViewUtil.getRootItem(view.bot().tree(),
+ clonedRepositoryFile);
+ TestUtil.waitForDecorations();
+ String label = repoItem.getText();
+ assertTrue("Expected branch decoration to be present: " + label,
+ label.contains("[master]"));
+ SWTBotTreeItem localItem = myRepoViewUtil
+ .getLocalBranchesItem(view.bot().tree(), clonedRepositoryFile);
+ TestUtil.expandAndWait(localItem).getNode("master").select();
+ ContextMenuHelper.clickContextMenu(view.bot().tree(),
+ myUtil.getPluginLocalizedValue("ConfigurBranchCommand.label"));
+
+ SWTBotShell configureBranchDialog = bot.shell(
+ UIText.BranchConfigurationDialog_BranchConfigurationTitle);
+ configureBranchDialog.bot()
+ .comboBoxWithLabel(
+ UIText.BranchConfigurationDialog_UpstreamBranchLabel)
+ .setSelection(0);
+ // add a listener to wait for the configuration changed event
+ final AtomicBoolean changed = new AtomicBoolean();
+ ConfigChangedListener listener = new ConfigChangedListener() {
+ @Override
+ public void onConfigChanged(ConfigChangedEvent event) {
+ changed.set(true);
+ }
+ };
+ ListenerHandle handle = lookupRepository(clonedRepositoryFile)
+ .getConfig().addChangeListener(listener);
+ // only now click ok
+ configureBranchDialog.bot()
+ .button(UIText.BranchConfigurationDialog_ButtonOK).click();
+ bot.waitUntil(Conditions.shellCloses(configureBranchDialog));
+ // cleanup behind ourselves
+ handle.remove();
+ assertTrue("Expected a ConfigChangeEvent", changed.get());
+ TestUtil.waitForJobs(100, 5000);
+ TestUtil.waitForDecorations();
+ repoItem = myRepoViewUtil.getRootItem(view.bot().tree(),
+ clonedRepositoryFile);
+ label = repoItem.getText();
+ assertTrue("Expected branch decoration to be updated: " + label,
+ label.contains("[master \u21911]"));
+ }
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratorRepositoryStateCache.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratorRepositoryStateCache.java
index f21ce60c5..1f17e4a23 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratorRepositoryStateCache.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratorRepositoryStateCache.java
@@ -13,6 +13,7 @@ package org.eclipse.egit.ui.internal.decorators;
import java.io.File;
import java.io.IOException;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.egit.core.UnitOfWork;
@@ -41,6 +42,8 @@ public class DecoratorRepositoryStateCache extends RepositoryStateCache {
private final Map<File, String> branchStateLabels = new ConcurrentHashMap<>();
+ private final Set<File> branchStatesToClear = ConcurrentHashMap.newKeySet();
+
private DecoratorRepositoryStateCache() {
// No public instantiation
}
@@ -56,13 +59,26 @@ public class DecoratorRepositoryStateCache extends RepositoryStateCache {
super.clear();
branchLabels.clear();
branchStateLabels.clear();
+ branchStatesToClear.clear();
}
@Override
public void clear(Repository repository) {
super.clear(repository);
- branchLabels.remove(repository.getDirectory());
- branchStateLabels.remove(repository.getDirectory());
+ File gitDir = repository.getDirectory();
+ branchLabels.remove(gitDir);
+ branchStateLabels.remove(gitDir);
+ branchStatesToClear.remove(gitDir);
+ }
+
+ /**
+ * Clears the cache for {@link #getBranchStatus(Repository)}.
+ *
+ * @param repository
+ * to clear the state of
+ */
+ public void resetBranchState(Repository repository) {
+ branchStatesToClear.add(repository.getDirectory());
}
/**
@@ -127,8 +143,13 @@ public class DecoratorRepositoryStateCache extends RepositoryStateCache {
* @return the label, or {@code null} if none
*/
public String getBranchStatus(Repository repository) {
+ File gitDir = repository.getDirectory();
+ // Clear if needed
+ if (branchStatesToClear.remove(gitDir)) {
+ branchStateLabels.remove(gitDir);
+ }
String label = branchStateLabels
- .computeIfAbsent(repository.getDirectory(), dir -> {
+ .computeIfAbsent(gitDir, dir -> {
return UnitOfWork.get(repository, () -> {
String branchName = getFullBranchName(repository);
if (branchName == null) {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitDecorator.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitDecorator.java
index f3619767b..30e0ab618 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitDecorator.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitDecorator.java
@@ -22,6 +22,9 @@ import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.jface.viewers.ILightweightLabelDecorator;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
+import org.eclipse.jgit.events.ConfigChangedEvent;
+import org.eclipse.jgit.events.ConfigChangedListener;
+import org.eclipse.jgit.events.ListenerHandle;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.ui.PlatformUI;
@@ -31,13 +34,16 @@ import org.eclipse.ui.PlatformUI;
* changes.
*/
public abstract class GitDecorator extends LabelProvider
- implements ILightweightLabelDecorator, IndexDiffChangedListener {
+ implements ILightweightLabelDecorator, IndexDiffChangedListener,
+ ConfigChangedListener {
private Object lock = new Object();
/** Protected by lock's monitor. */
private EventJob eventJob;
+ private ListenerHandle configListener;
+
/**
* Creates a new {@link GitDecorator}, registering to receive notifications
* about index changes.
@@ -45,12 +51,17 @@ public abstract class GitDecorator extends LabelProvider
public GitDecorator() {
org.eclipse.egit.core.Activator.getDefault().getIndexDiffCache()
.addIndexDiffChangedListener(this);
+ configListener = org.eclipse.egit.core.Activator.getDefault()
+ .getRepositoryCache().getGlobalListenerList()
+ .addConfigChangedListener(this);
}
@Override
public void dispose() {
org.eclipse.egit.core.Activator.getDefault().getIndexDiffCache()
.removeIndexDiffChangedListener(this);
+ configListener.remove();
+ configListener = null;
Job job;
synchronized (lock) {
job = eventJob;
@@ -82,6 +93,14 @@ public abstract class GitDecorator extends LabelProvider
@Override
public void indexDiffChanged(Repository repository,
IndexDiffData indexDiffData) {
+ DecoratorRepositoryStateCache.INSTANCE.clear(repository);
+ postLabelEvent();
+ }
+
+ @Override
+ public void onConfigChanged(ConfigChangedEvent event) {
+ DecoratorRepositoryStateCache.INSTANCE
+ .resetBranchState(event.getRepository());
postLabelEvent();
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java
index d8425772b..d4665ee84 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java
@@ -54,7 +54,6 @@ import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.IDecoration;
import org.eclipse.jgit.annotations.NonNull;
-import org.eclipse.jgit.lib.Repository;
import org.eclipse.osgi.util.NLS;
import org.eclipse.osgi.util.TextProcessor;
import org.eclipse.swt.SWT;
@@ -687,14 +686,6 @@ public class GitLightweightDecorator extends GitDecorator
}
}
- @Override
- public void indexDiffChanged(Repository repository,
- IndexDiffData indexDiffData) {
- // clear calculated repo data
- DecoratorRepositoryStateCache.INSTANCE.clear(repository);
- super.indexDiffChanged(repository, indexDiffData);
- }
-
// -------- Helper methods --------
private static IResource getResource(Object actElement) {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoryTreeNodeDecorator.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoryTreeNodeDecorator.java
index 32ec25610..fd4cadd6a 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoryTreeNodeDecorator.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoryTreeNodeDecorator.java
@@ -104,13 +104,6 @@ public class RepositoryTreeNodeDecorator extends GitDecorator
}
@Override
- public void indexDiffChanged(Repository repository,
- IndexDiffData indexDiffData) {
- DecoratorRepositoryStateCache.INSTANCE.clear(repository);
- super.indexDiffChanged(repository, indexDiffData);
- }
-
- @Override
public void handleStateChange(State state, Object oldValue) {
try {
boolean newValue = ((Boolean) state.getValue())

Back to the top