Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDariusz Luksza2011-06-01 10:24:37 +0000
committerMatthias Sohn2011-06-01 10:24:37 +0000
commit0d431cd13fd8699cae5ace94be148a960d0f98af (patch)
tree1a133e958b62c4a91d934876ad05a14d7fcb683a
parentb5939449f8dabad1fae3367de2f40c2812d34c1a (diff)
downloadegit-0d431cd13fd8699cae5ace94be148a960d0f98af.tar.gz
egit-0d431cd13fd8699cae5ace94be148a960d0f98af.tar.xz
egit-0d431cd13fd8699cae5ace94be148a960d0f98af.zip
[sync] Refresh Synchronize view after repository change
Bug: 345286 Change-Id: I7bdd5ba94048f537a7fcb96409ea43fcd8adfb09 Signed-off-by: Dariusz Luksza <dariusz@luksza.org> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java6
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties3
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitSubscriberMergeContext.java61
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/dto/GitSynchronizeData.java44
4 files changed, 97 insertions, 17 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java
index 45b6f5859..9fbe63269 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java
@@ -284,6 +284,12 @@ public class CoreText extends NLS {
/** */
public static String IgnoreOperation_updatingFailed;
+ /** */
+ public static String GitSubscriberMergeContext_FailedUpdateRevs;
+
+ /** */
+ public static String GitSubscriberMergeContext_FailedRefreshSyncView;
+
static {
initializeMessages(BUNDLE_NAME, CoreText.class);
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties b/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties
index 14970188c..3259273eb 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties
@@ -115,3 +115,6 @@ IgnoreOperation_parentOutsideRepo=Can not add to gitignore. The parent of {0} is
IgnoreOperation_creatingFailed=creating {0} failed
IgnoreOperation_taskName=Adding resources to gitignore
IgnoreOperation_updatingFailed=updating {0} failed
+
+GitSubscriberMergeContext_FailedUpdateRevs=Failed to update revisions
+GitSubscriberMergeContext_FailedRefreshSyncView=Failed to refresh synchronize view
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitSubscriberMergeContext.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitSubscriberMergeContext.java
index 248223237..7d63e685f 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitSubscriberMergeContext.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitSubscriberMergeContext.java
@@ -8,12 +8,21 @@
*******************************************************************************/
package org.eclipse.egit.core.synchronize;
+import java.io.IOException;
+
+import org.eclipse.core.resources.mapping.ResourceTraversal;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.egit.core.Activator;
+import org.eclipse.egit.core.CoreText;
+import org.eclipse.egit.core.project.GitProjectData;
+import org.eclipse.egit.core.project.RepositoryChangeListener;
+import org.eclipse.egit.core.project.RepositoryMapping;
+import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData;
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet;
import org.eclipse.team.core.diff.IDiff;
import org.eclipse.team.core.mapping.ISynchronizationScopeManager;
-import org.eclipse.team.core.subscribers.Subscriber;
import org.eclipse.team.core.subscribers.SubscriberMergeContext;
/**
@@ -23,16 +32,26 @@ public class GitSubscriberMergeContext extends SubscriberMergeContext {
private final GitSynchronizeDataSet gsds;
+ private final RepositoryChangeListener repoChangeListener;
+
/**
* @param subscriber
* @param manager
* @param gsds
*/
- public GitSubscriberMergeContext(Subscriber subscriber,
+ public GitSubscriberMergeContext(final GitResourceVariantTreeSubscriber subscriber,
ISynchronizationScopeManager manager, GitSynchronizeDataSet gsds) {
super(subscriber, manager);
this.gsds = gsds;
+
+ repoChangeListener = new RepositoryChangeListener() {
+ public void repositoryChanged(RepositoryMapping which) {
+ update(subscriber, which);
+ }
+ };
+ GitProjectData.addRepositoryChangeListener(repoChangeListener);
+
initialize();
}
@@ -62,4 +81,42 @@ public class GitSubscriberMergeContext extends SubscriberMergeContext {
}
+ @Override
+ public void dispose() {
+ GitProjectData.removeRepositoryChangeListener(repoChangeListener);
+ super.dispose();
+ }
+
+
+ private void update(GitResourceVariantTreeSubscriber subscriber,
+ RepositoryMapping which) {
+ for (GitSynchronizeData gsd : gsds) {
+ if (which.getRepository().equals(gsd.getRepository())) {
+ try {
+ gsd.updateRevs();
+ } catch (IOException e) {
+ Activator.error(
+ CoreText.GitSubscriberMergeContext_FailedUpdateRevs,
+ e);
+
+ return;
+ }
+
+ subscriber.reset(this.gsds);
+
+ ResourceTraversal[] traversals = getScopeManager().getScope()
+ .getTraversals();
+ try {
+ subscriber.refresh(traversals, new NullProgressMonitor());
+ } catch (CoreException e) {
+ Activator
+ .error(CoreText.GitSubscriberMergeContext_FailedRefreshSyncView,
+ e);
+ }
+
+ return;
+ }
+ }
+ }
+
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/dto/GitSynchronizeData.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/dto/GitSynchronizeData.java
index d5c2758f2..811e5c572 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/dto/GitSynchronizeData.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/dto/GitSynchronizeData.java
@@ -49,16 +49,20 @@ public class GitSynchronizeData {
private final String dstRemote;
- private final RevCommit srcRevCommit;
+ private RevCommit srcRevCommit;
- private final RevCommit dstRevCommit;
+ private RevCommit dstRevCommit;
- private final RevCommit ancestorRevCommit;
+ private RevCommit ancestorRevCommit;
private final Set<IProject> projects;
private final String repoParentPath;
+ private final String srcRev;
+
+ private final String dstRev;
+
/**
* Constructs {@link GitSynchronizeData} object
*
@@ -76,10 +80,32 @@ public class GitSynchronizeData {
isNotNull(srcRev);
isNotNull(dstRev);
repo = repository;
+ this.srcRev = srcRev;
+ this.dstRev = dstRev;
+ this.includeLocal = includeLocal;
srcRemote = extractRemoteName(srcRev);
dstRemote = extractRemoteName(dstRev);
+ repoParentPath = repo.getDirectory().getParentFile().getAbsolutePath();
+
+ projects = new HashSet<IProject>();
+ final IProject[] workspaceProjects = ROOT.getProjects();
+ for (IProject project : workspaceProjects) {
+ RepositoryMapping mapping = RepositoryMapping.getMapping(project);
+ if (mapping != null && mapping.getRepository() == repo)
+ projects.add(project);
+ }
+
+ updateRevs();
+ }
+
+ /**
+ * Recalculates source, destination and ancestor Rev commits
+ *
+ * @throws IOException
+ */
+ public void updateRevs() throws IOException {
ObjectWalk ow = new ObjectWalk(repo);
if (srcRev.length() > 0)
this.srcRevCommit = ow.parseCommit(repo.resolve(srcRev));
@@ -96,18 +122,6 @@ public class GitSynchronizeData {
this.dstRevCommit);
else
this.ancestorRevCommit = null;
-
- this.includeLocal = includeLocal;
- repoParentPath = repo.getDirectory().getParentFile().getAbsolutePath();
-
- projects = new HashSet<IProject>();
- final IProject[] workspaceProjects = ROOT.getProjects();
- for (IProject project : workspaceProjects) {
- RepositoryMapping mapping = RepositoryMapping.getMapping(project);
- if (mapping != null && mapping.getRepository() == repo)
- projects.add(project);
- }
-
}
/**

Back to the top