Permalink
Browse files

Allow project decorations regardless of repository root location

If the repository root is more than one level above the project
directory we use the AdaptableFileTreeIterator to recurse the
repository tree until we find a directory that can be mapped
to a container in the workspace. The iterator is then adapted to
a ContainerTreeIterator and decorations are applied like usual.

Signed-off-by: Tor Arne Vestbø <torarnv@gmail.com>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
  • Loading branch information...
1 parent a7a354e commit 6b5558e9249ba0c11bcbbfe7922fa976c91a4be8 @torarnv torarnv committed with robinrosenberg Feb 17, 2009
@@ -13,15 +13,17 @@
package org.spearce.egit.ui.internal.decorators;
+import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.team.core.Team;
+import org.spearce.egit.core.AdaptableFileTreeIterator;
import org.spearce.egit.core.ContainerTreeIterator;
import org.spearce.egit.core.ContainerTreeIterator.ResourceEntry;
import org.spearce.egit.core.project.RepositoryMapping;
@@ -39,6 +41,7 @@
import org.spearce.jgit.revwalk.RevWalk;
import org.spearce.jgit.treewalk.EmptyTreeIterator;
import org.spearce.jgit.treewalk.TreeWalk;
+import org.spearce.jgit.treewalk.WorkingTreeIterator;
import org.spearce.jgit.treewalk.filter.AndTreeFilter;
import org.spearce.jgit.treewalk.filter.PathFilterGroup;
import org.spearce.jgit.treewalk.filter.TreeFilter;
@@ -210,13 +213,21 @@ public boolean include(TreeWalk treeWalk)
}
private boolean shouldRecurse(TreeWalk treeWalk) {
- final ContainerTreeIterator workspaceIterator = treeWalk.getTree(
- T_WORKSPACE, ContainerTreeIterator.class);
- final ResourceEntry resourceEntry = workspaceIterator != null ? workspaceIterator
- .getResourceEntry()
- : null;
- IResource visitingResource = resourceEntry.getResource();
+ final WorkingTreeIterator workspaceIterator = treeWalk.getTree(
+ T_WORKSPACE, WorkingTreeIterator.class);
+
+ if (workspaceIterator instanceof AdaptableFileTreeIterator)
+ return true;
+
+ ResourceEntry resourceEntry = null;
+ if (workspaceIterator != null)
+ resourceEntry = ((ContainerTreeIterator) workspaceIterator)
+ .getResourceEntry();
+
+ if (resourceEntry == null)
+ return true;
+ IResource visitingResource = resourceEntry.getResource();
if (targetDepth == -1) {
if (visitingResource.equals(resource)
|| visitingResource.getParent().equals(resource))
@@ -319,14 +330,16 @@ private TreeWalk createThreeWayTreeWalk() throws IOException {
// Working directory
IProject project = resource.getProject();
- IWorkspace workspace = resource.getWorkspace();
- if (repository.getWorkDir().equals(project.getLocation().toFile()))
+ IWorkspaceRoot workspaceRoot = resource.getWorkspace().getRoot();
+ File repoRoot = repository.getWorkDir();
+
+ if (repoRoot.equals(project.getLocation().toFile()))
treeWalk.addTree(new ContainerTreeIterator(project));
+ else if (repoRoot.equals(workspaceRoot.getLocation().toFile()))
+ treeWalk.addTree(new ContainerTreeIterator(workspaceRoot));
else
- treeWalk.addTree(new ContainerTreeIterator(workspace.getRoot()));
-
- // TODO: Add fallback for projects with the repository more than
- // one parent up, for example by using a stack of DummyIterators
+ treeWalk.addTree(new AdaptableFileTreeIterator(repoRoot,
+ workspaceRoot));
return treeWalk;
}

0 comments on commit 6b5558e

Please sign in to comment.