summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorPhilipp Thun2011-02-25 17:52:53 (EST)
committer Matthias Sohn2011-02-28 07:36:20 (EST)
commit9f11bda9a3fd252e769cd14621a861396d24bb0c (patch)
tree44fe50122a10ca22c11f60cc9eac95dd94945245
parentc65d7e7586e37520db43f3acc88d1c329e7f8e06 (diff)
downloadegit-9f11bda9a3fd252e769cd14621a861396d24bb0c.zip
egit-9f11bda9a3fd252e769cd14621a861396d24bb0c.tar.gz
egit-9f11bda9a3fd252e769cd14621a861396d24bb0c.tar.bz2
Create temporary decorations for project nodesrefs/changes/00/2600/6
The label decoration of project nodes contains important information, i.e. the repository name as well as the current branch. This change introduces a temporary decoration for project nodes that only contains this textual (label) information and is shown immediately. The final decoration is shown as soon as a full recursive walk through the whole project has been performed. Change-Id: I376b9284b35bfc5960102182753ed90498da0829 Signed-off-by: Philipp Thun <philipp.thun@sap.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceAdapter.java29
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceHelper.java55
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java71
3 files changed, 108 insertions, 47 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceAdapter.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceAdapter.java
index 5eddaf7..05c19ed 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceAdapter.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceAdapter.java
@@ -36,9 +36,7 @@ import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.EmptyTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
@@ -75,16 +73,11 @@ class DecoratableResourceAdapter extends DecoratableResource {
mapping = RepositoryMapping.getMapping(resource);
repository = mapping.getRepository();
headId = repository.resolve(Constants.HEAD);
-
store = Activator.getDefault().getPreferenceStore();
- String repoName = Activator.getDefault().getRepositoryUtil().getRepositoryName(repository);
- RepositoryState state = repository.getRepositoryState();
- if (state != RepositoryState.SAFE)
- repositoryName = repoName + '|' + state.getDescription();
- else
- repositoryName = repoName;
- branch = getShortBranch();
+ repositoryName = DecoratableResourceHelper
+ .getRepositoryName(repository);
+ branch = DecoratableResourceHelper.getShortBranch(repository);
TreeWalk treeWalk = createThreeWayTreeWalk();
if (treeWalk == null)
@@ -112,22 +105,6 @@ class DecoratableResourceAdapter extends DecoratableResource {
}
}
- private String getShortBranch() throws IOException {
- Ref head = repository.getRef(Constants.HEAD);
- if (head != null && !head.isSymbolic()) {
- String refString = Activator.getDefault().getRepositoryUtil()
- .mapCommitToRef(repository, repository.getFullBranch(),
- false);
- if (refString != null) {
- return repository.getFullBranch().substring(0, 7)
- + "... (" + refString + ")"; //$NON-NLS-1$ //$NON-NLS-2$
- } else
- return repository.getFullBranch().substring(0, 7) + "..."; //$NON-NLS-1$
- }
-
- return repository.getBranch();
- }
-
private void extractResourceProperties(TreeWalk treeWalk) throws IOException {
DecoratableResourceHelper.decorateResource(this, treeWalk);
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceHelper.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceHelper.java
index 9a72f20..6826a8d 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceHelper.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceHelper.java
@@ -13,11 +13,13 @@ import java.util.ArrayList;
import java.util.Map;
import java.util.WeakHashMap;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.egit.core.ContainerTreeIterator;
import org.eclipse.egit.core.ContainerTreeIterator.ResourceEntry;
import org.eclipse.egit.core.IteratorService;
import org.eclipse.egit.core.project.RepositoryMapping;
+import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.internal.decorators.IDecoratableResource.Staged;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEntry;
@@ -25,7 +27,9 @@ import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.EmptyTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
@@ -128,6 +132,29 @@ public class DecoratableResourceHelper {
return decoratableResources;
}
+ /**
+ * Creates a temporary decoratable resource for the given project
+ *
+ * This temporary decoratable resource only contains the name of the
+ * repository and the current branch.
+ *
+ * @param project
+ * the project to be decorated
+ * @return the decoratable resource
+ * @throws IOException
+ */
+ static IDecoratableResource createTemporaryDecoratableResource(
+ final IProject project) throws IOException {
+ final DecoratableResource decoratableResource = new DecoratableResource(
+ project);
+ final Repository repository = RepositoryMapping.getMapping(project)
+ .getRepository();
+ decoratableResource.repositoryName = getRepositoryName(repository);
+ decoratableResource.branch = getShortBranch(repository);
+ decoratableResource.tracked = true;
+ return decoratableResource;
+ }
+
static DirCache getDirCache(Repository repository) throws IOException {
synchronized(repoToDirCache) {
DirCache dirCache = repoToDirCache.get(repository);
@@ -233,4 +260,32 @@ public class DecoratableResourceHelper {
}
return decoratableResource;
}
+
+ static String getRepositoryName(Repository repository) {
+ String repoName = Activator.getDefault().getRepositoryUtil()
+ .getRepositoryName(repository);
+ RepositoryState state = repository.getRepositoryState();
+ if (state != RepositoryState.SAFE)
+ return repoName + '|' + state.getDescription();
+ else
+ return repoName;
+ }
+
+ static String getShortBranch(Repository repository) throws IOException {
+ Ref head = repository.getRef(Constants.HEAD);
+ if (head != null && !head.isSymbolic()) {
+ String refString = Activator
+ .getDefault()
+ .getRepositoryUtil()
+ .mapCommitToRef(repository, repository.getFullBranch(),
+ false);
+ if (refString != null) {
+ return repository.getFullBranch().substring(0, 7)
+ + "... (" + refString + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+ } else
+ return repository.getFullBranch().substring(0, 7) + "..."; //$NON-NLS-1$
+ }
+
+ return repository.getBranch();
+ }
}
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 38df16a..e2e8f33 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
@@ -205,6 +205,8 @@ public class GitLightweightDecorator extends LabelProvider implements
if (resource == null)
return;
+ // Step 1: Perform cheap tests
+
// Don't decorate if the workbench is not running
if (!PlatformUI.isWorkbenchRunning())
return;
@@ -222,34 +224,36 @@ public class GitLightweightDecorator extends LabelProvider implements
if (!resource.exists() && !resource.isPhantom())
return;
+ IDecoratableResource decoratableResource = null;
+ final DecorationHelper helper = new DecorationHelper(
+ activator.getPreferenceStore());
+
+ // Step 2: Read session properties
+
try {
final Boolean notDecoratable = (Boolean) resource
.getSessionProperty(NOT_DECORATABLE_KEY);
if (notDecoratable != null && notDecoratable.equals(Boolean.TRUE))
- // Resource is not decoratable, do not try again
+ // Step 2a: Return - resource is not decoratable
return;
- final IDecoratableResource decoratableResource = (IDecoratableResource) resource
+ decoratableResource = (IDecoratableResource) resource
.getSessionProperty(DECORATABLE_RESOURCE_KEY);
- boolean decorated = false;
if (decoratableResource != null) {
- // Use stored decoratable resource (even when it is outdated)
- final DecorationHelper helper = new DecorationHelper(
- activator.getPreferenceStore());
- helper.decorate(decoration, decoratableResource);
- decorated = true;
- }
-
- final Long refreshed = (Long) resource
- .getSessionProperty(REFRESHED_KEY);
- if (refreshed != null) {
- final Long refresh = (Long) resource.getWorkspace().getRoot()
- .getSessionProperty(REFRESH_KEY);
- if (refresh == null
- || refresh.longValue() <= refreshed.longValue()) {
- // Stored decoratable resource is up-to-date
- if (decorated)
+ final Long refreshed = (Long) resource
+ .getSessionProperty(REFRESHED_KEY);
+ if (refreshed != null) {
+ final Long refresh = (Long) resource.getWorkspace()
+ .getRoot().getSessionProperty(REFRESH_KEY);
+ if (refresh == null
+ || refresh.longValue() <= refreshed.longValue()) {
+ // Condition: Stored decoratable resource exists and is
+ // up-to-date
+ //
+ // Step 2b: Apply stored decoratable resource and return
+ helper.decorate(decoration, decoratableResource);
return;
+ }
}
}
} catch (CoreException e) {
@@ -257,6 +261,11 @@ public class GitLightweightDecorator extends LabelProvider implements
return;
}
+ // Condition: Stored decoratable resource either not exists or is
+ // out-dated
+ //
+ // Step 3: Perform more expensive tests
+
// Don't decorate ignored resources (e.g. bin folder content)
if (Team.isIgnoredHint(resource))
return;
@@ -271,8 +280,28 @@ public class GitLightweightDecorator extends LabelProvider implements
if (mapping.getRepoRelativePath(resource) == null)
return;
- // No (up-to-date) stored decoratable resource is available, thus
- // decoration request is added to the queue
+ // Step 4: For project nodes only: create temporary decoratable resource
+ if (resource.getType() == IResource.PROJECT) {
+ try {
+ decoratableResource = DecoratableResourceHelper
+ .createTemporaryDecoratableResource(resource
+ .getProject());
+ } catch (IOException e) {
+ handleException(
+ resource,
+ new CoreException(Activator.createErrorStatus(
+ UIText.Decorator_exceptionMessage, e)));
+ return;
+ }
+ }
+
+ // Step 5: Apply out-dated or temporary decoratable resource and
+ // continue
+ if (decoratableResource != null) {
+ helper.decorate(decoration, decoratableResource);
+ }
+
+ // Step 6: Add decoration request to the queue
GitDecoratorJob.getJobForRepository(
mapping.getGitDirAbsolutePath().toString())
.addDecorationRequest(element);