From: "Tor Arne Vestbø" <torarnv@gmail.com>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: git@vger.kernel.org, Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [JGIT PATCH] Teach tree iterators to iterate from the workspace root
Date: Wed, 4 Feb 2009 16:36:22 +0100 [thread overview]
Message-ID: <1233761782-842-1-git-send-email-torarnv@gmail.com> (raw)
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@gmail.com>
---
.../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
reply other threads:[~2009-02-04 15:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1233761782-842-1-git-send-email-torarnv@gmail.com \
--to=torarnv@gmail.com \
--cc=git@vger.kernel.org \
--cc=robin.rosenberg@dewire.com \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).