diff options
author | Robin Rosenberg <robin.rosenberg@dewire.com> | 2014-05-17 13:00:26 -0400 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2014-05-17 13:00:26 -0400 |
commit | f7ac527ca7a5ab1d0b1a7027c50483849bf39308 (patch) | |
tree | 8953e76ba9c0321ad41fb6be22bf851f87272934 /org.eclipse.jgit/src | |
parent | 19ac1f75ab6a5100144e52760cb29c6484ed3c96 (diff) | |
parent | 17604c77a87716eff2a51942538361c184cc3912 (diff) | |
download | jgit-f7ac527ca7a5ab1d0b1a7027c50483849bf39308.tar.gz jgit-f7ac527ca7a5ab1d0b1a7027c50483849bf39308.zip |
Merge "Archive: Add the ability to select one or more paths."
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java index 70ab73015f..88bc2aee7d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java @@ -46,6 +46,9 @@ import java.io.Closeable; import java.io.IOException; import java.io.OutputStream; import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -60,6 +63,7 @@ import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.treewalk.TreeWalk; +import org.eclipse.jgit.treewalk.filter.PathFilterGroup; /** * Create an archive of files from a named tree. @@ -324,6 +328,7 @@ public class ArchiveCommand extends GitCommand<OutputStream> { private ObjectId tree; private String prefix; private String format; + private List<String> paths = new ArrayList<String>(); /** Filename suffix, for automatically choosing a format. */ private String suffix; @@ -347,6 +352,9 @@ public class ArchiveCommand extends GitCommand<OutputStream> { final RevWalk rw = new RevWalk(walk.getObjectReader()); walk.reset(rw.parseTree(tree)); + if (!paths.isEmpty()) + walk.setFilter(PathFilterGroup.createFromStrings(paths)); + while (walk.next()) { final String name = pfx + walk.getPathString(); FileMode mode = walk.getFileMode(0); @@ -462,4 +470,21 @@ public class ArchiveCommand extends GitCommand<OutputStream> { this.format = fmt; return this; } + + /** + * Set an optional parameter path. without an optional path parameter, all + * files and subdirectories of the current working directory are included in + * the archive. If one or more paths are specified, only these are included. + * @param paths + * file names (e.g <code>file1.c</code>) or directory names (e.g. + * <code>dir</code> to add <code>dir/file1</code> and + * <code>dir/file2</code>) can also be given to add all files in + * the directory, recursively. Fileglobs (e.g. *.c) are not yet + * supported. + * @return this + */ + public ArchiveCommand setPaths(String... paths) { + this.paths = Arrays.asList(paths); + return this; + } } |