[EGIT PATCH 20/26] Allow the new DirCacheIterator in command line arguments

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

 



By assuming files passed where we want an AbtractTreeIterator to
be supplied are actually 'DIRC' files (aka .git/index) we can
automatically load them for the command line tool.

Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx>
---
 .../jgit/pgm/opt/AbstractTreeIteratorHandler.java  |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/AbstractTreeIteratorHandler.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/AbstractTreeIteratorHandler.java
index 8e216c7..e439c87 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/AbstractTreeIteratorHandler.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/AbstractTreeIteratorHandler.java
@@ -46,6 +46,8 @@ import org.kohsuke.args4j.OptionDef;
 import org.kohsuke.args4j.spi.OptionHandler;
 import org.kohsuke.args4j.spi.Parameters;
 import org.kohsuke.args4j.spi.Setter;
+import org.spearce.jgit.dircache.DirCache;
+import org.spearce.jgit.dircache.DirCacheIterator;
 import org.spearce.jgit.errors.IncorrectObjectTypeException;
 import org.spearce.jgit.errors.MissingObjectException;
 import org.spearce.jgit.lib.ObjectId;
@@ -87,6 +89,17 @@ public class AbstractTreeIteratorHandler extends
 			return 1;
 		}
 
+		if (new File(name).isFile()) {
+			final DirCache dirc;
+			try {
+				dirc = DirCache.read(new File(name));
+			} catch (IOException e) {
+				throw new CmdLineException(name + " is not an index file", e);
+			}
+			setter.addValue(new DirCacheIterator(dirc));
+			return 1;
+		}
+
 		final ObjectId id;
 		try {
 			id = clp.getRepository().resolve(name);
-- 
1.6.0.rc2.22.g71b99

--
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