diff options
author | Chris Aniszczyk <caniszczyk@gmail.com> | 2010-11-22 11:19:51 -0600 |
---|---|---|
committer | Chris Aniszczyk <caniszczyk@gmail.com> | 2010-11-22 11:19:51 -0600 |
commit | a7f6764e01e233f85f9780a5a20e3dd08c65d0db (patch) | |
tree | c3f9256c498ab1ce7b9b168ffe3b29450f50f2d4 /org.eclipse.jgit.pgm/src | |
parent | f7690cceeff61875150cecb489a6aa8665532072 (diff) | |
download | jgit-a7f6764e01e233f85f9780a5a20e3dd08c65d0db.tar.gz jgit-a7f6764e01e233f85f9780a5a20e3dd08c65d0db.zip |
Update Rm in the JGit CLI
Since we have the RmCommand API now, update Rm to use it.
Change-Id: I6e2cb37573cc8a29846f01e09e8c07e0dc279dbe
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.pgm/src')
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java | 50 |
1 files changed, 12 insertions, 38 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java index 9f577ff05e..816b3104c2 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java @@ -1,4 +1,5 @@ /* + * Copyright (C) 2010, Chris Aniszczyk <caniszczyk@gmail.com> * Copyright (C) 2008, Google Inc. * and other copyright owners as documented in the project's IP log. * @@ -43,56 +44,29 @@ package org.eclipse.jgit.pgm; -import java.io.File; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.RmCommand; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; import org.kohsuke.args4j.spi.StopOptionHandler; -import org.eclipse.jgit.dircache.DirCache; -import org.eclipse.jgit.dircache.DirCacheBuildIterator; -import org.eclipse.jgit.dircache.DirCacheBuilder; -import org.eclipse.jgit.lib.Constants; -import org.eclipse.jgit.lib.FileMode; -import org.eclipse.jgit.pgm.opt.PathTreeFilterHandler; -import org.eclipse.jgit.treewalk.TreeWalk; -import org.eclipse.jgit.treewalk.filter.TreeFilter; @Command(usage = "usage_StopTrackingAFile", common = true) class Rm extends TextBuiltin { - @Argument(metaVar = "metaVar_path", usage = "usage_path", multiValued = true, required = true, handler = PathTreeFilterHandler.class) + @Argument(metaVar = "metaVar_path", usage = "usage_path", multiValued = true, required = true) + @Option(name = "--", handler = StopOptionHandler.class) - private TreeFilter paths; + private List<String> paths = new ArrayList<String>(); - private File root; @Override protected void run() throws Exception { - root = db.getWorkTree(); - - final DirCache dirc = db.lockDirCache(); - final DirCacheBuilder edit = dirc.builder(); - - final TreeWalk walk = new TreeWalk(db); - walk.reset(); // drop the first empty tree, which we do not need here - walk.setRecursive(true); - walk.setFilter(paths); - walk.addTree(new DirCacheBuildIterator(edit)); - - while (walk.next()) { - final File path = new File(root, walk.getPathString()); - final FileMode mode = walk.getFileMode(0); - if (mode.getObjectType() == Constants.OBJ_BLOB) { - // Deleting a blob is simply a matter of removing - // the file or symlink named by the tree entry. - delete(path); - } - } - - edit.commit(); + RmCommand command = new Git(db).rm(); + for (String p : paths) + command.addFilepattern(p); + command.call(); } - private void delete(File p) { - while (p != null && !p.equals(root) && p.delete()) - p = p.getParentFile(); - } } |