[JGIT PATCH] Teach tree iterators to iterate from the workspace root

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is needed to be able to do treewalks of projects that
have their repository in the project's parent directory.

We always filter out '.git' entries when building the entry list,
no matter where we are in the tree, because we assume that the
checks in the ResourceEntry and FileEntry constructors for a
'.git' folder ensure that we never navigate into submodules.

Signed-off-by: Tor Arne Vestbø <torarnv@xxxxxxxxx>
---
 .../spearce/egit/core/ContainerTreeIterator.java   |   26 ++++++++++++++++++-
 .../spearce/jgit/treewalk/WorkingTreeIterator.java |    2 +-
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/org.spearce.egit.core/src/org/spearce/egit/core/ContainerTreeIterator.java b/org.spearce.egit.core/src/org/spearce/egit/core/ContainerTreeIterator.java
index 61717f5..6d6b72e 100644
--- a/org.spearce.egit.core/src/org/spearce/egit/core/ContainerTreeIterator.java
+++ b/org.spearce.egit.core/src/org/spearce/egit/core/ContainerTreeIterator.java
@@ -15,6 +15,7 @@
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
 import org.eclipse.core.runtime.CoreException;
 import org.spearce.egit.core.project.RepositoryMapping;
 import org.spearce.jgit.errors.IncorrectObjectTypeException;
@@ -53,7 +54,7 @@ private static String computePrefix(final IContainer base) {
 	private final IContainer node;
 
 	/**
-	 * Construct a new iterator from the workspace.
+	 * Construct a new iterator from a container in the workspace.
 	 * <p>
 	 * The iterator will support traversal over the named container, but only if
 	 * it is contained within a project which has the Git repository provider
@@ -70,6 +71,23 @@ public ContainerTreeIterator(final IContainer base) {
 		init(entries());
 	}
 
+	/**
+	 * Construct a new iterator from the workspace root.
+	 * <p>
+	 * The iterator will support traversal over workspace projects that have
+	 * a Git repository provider connected and is mapped into a Git repository.
+	 * During the iteration the paths will be automatically generated to match
+	 * the proper repository paths for this container's children.
+	 *
+	 * @param root
+	 *            the workspace root to walk over.
+	 */
+	public ContainerTreeIterator(final IWorkspaceRoot root) {
+		super("");
+		node = root;
+		init(entries());
+	}
+
 	private ContainerTreeIterator(final WorkingTreeIterator p,
 			final IContainer base) {
 		super(p);
@@ -119,6 +137,7 @@ ResourceEntry(final IResource f) {
 				else
 					mode = FileMode.REGULAR_FILE;
 				break;
+			case IResource.PROJECT:
 			case IResource.FOLDER: {
 				final IContainer c = (IContainer) f;
 				if (c.findMember(".git") != null)
@@ -140,7 +159,10 @@ public FileMode getMode() {
 
 		@Override
 		public String getName() {
-			return rsrc.getName();
+			if (rsrc.getType() == IResource.PROJECT)
+				return rsrc.getLocation().lastSegment();
+			else
+				return rsrc.getName();
 		}
 
 		@Override
diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java
index 6fce150..07ce2ed 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java
@@ -324,7 +324,7 @@ protected void init(final Entry[] list) {
 			final String name = e.getName();
 			if (".".equals(name) || "..".equals(name))
 				continue;
-			if (parent == null && ".git".equals(name))
+			if (".git".equals(name))
 				continue;
 			if (i != o)
 				entries[o] = e;
-- 
1.6.1.2.309.g2ea3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux