import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
-import java.util.HashSet;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.filter.PathSuffixFilter;
import org.eclipse.jgit.util.FS;
/**
TreeWalk tw = new TreeWalk(repository);
tw.reset();
tw.addTree(new FileTreeIterator(repository.getWorkDir(), FS.DETECTED));
+ tw.setFilter(PathSuffixFilter.create("/" + Constants.DOT_GIT_IGNORE));
tw.setRecursive(true);
-
- //Don't waste time trying to add iterators that already exist
- HashSet<FileTreeIterator> toAdd = new HashSet<FileTreeIterator>();
- while (tw.next()) {
- FileTreeIterator t = tw.getTree(0, FileTreeIterator.class);
- if (t.hasGitIgnore()) {
- toAdd.add(t);
- //TODO: Account for and test the removal of .gitignore files
- }
- }
- for (FileTreeIterator t : toAdd)
- addNodeFromTree(t);
+ while (tw.next())
+ addNodeFromTree(tw.getTree(0, FileTreeIterator.class));
//The base is special
//TODO: Test alternate locations for GIT_DIR
}
/**
- * Adds a node located at the FileTreeIterator's root directory.
- * <br>
- * Will check for the presence of a .gitignore using {@link FileTreeIterator#hasGitIgnore()}.
- * If no .gitignore file exists, nothing will be done.
- * <br>
- * Will check the last time of modification using {@link FileTreeIterator#hasGitIgnore()}.
- * If a node already exists and the time stamp has not changed, do nothing.
- * <br>
- * Note: This can be extended later if necessary to AbstractTreeIterator by using
- * byte[] path instead of File directory.
+ * Adds a node located at the FileTreeIterator's current position.
*
* @param t
- * AbstractTreeIterator to check for ignore info. The name of the node
- * should be .gitignore
+ * FileTreeIterator to check for ignore info. The name of the
+ * entry should be ".gitignore".
*/
protected void addNodeFromTree(FileTreeIterator t) {
IgnoreNode n = ignoreMap.get(relativize(t.getDirectory()));
- long time = t.getGitIgnoreLastModified();
+ long time = t.getEntryLastModified();
if (n != null) {
if (n.getLastModified() == time)
//TODO: Test and optimize
*/
protected int pathLen;
- /**
- * Last modified time of the .gitignore file. Greater than 0 if a .gitignore
- * file exists.
- *
- */
- protected long gitIgnoreTimeStamp;
-
/** Create a new iterator with no parent. */
protected AbstractTreeIterator() {
parent = null;
path = new byte[DEFAULT_PATH_SIZE];
pathOffset = 0;
- gitIgnoreTimeStamp = 0l;
}
/**
*/
protected AbstractTreeIterator(final String prefix) {
parent = null;
- gitIgnoreTimeStamp = 0l;
if (prefix != null && prefix.length() > 0) {
final ByteBuffer b;
*/
protected AbstractTreeIterator(final byte[] prefix) {
parent = null;
- gitIgnoreTimeStamp = 0l;
if (prefix != null && prefix.length > 0) {
pathLen = prefix.length;
parent = p;
path = p.path;
pathOffset = p.pathLen + 1;
- gitIgnoreTimeStamp = 0l;
try {
path[pathOffset - 1] = '/';
parent = p;
path = childPath;
pathOffset = childPathOffset;
- gitIgnoreTimeStamp = 0l;
}
/**
public void getName(byte[] buffer, int offset) {
System.arraycopy(path, pathOffset, buffer, offset, pathLen - pathOffset);
}
-
- /**
- * @return
- * True if this iterator encountered a .gitignore file when initializing entries.
- * Checks if the gitIgnoreTimeStamp > 0.
- */
- public boolean hasGitIgnore() {
- return gitIgnoreTimeStamp > 0;
- }
-
- /**
- * @return
- * Last modified time of the .gitignore file, if any. Will be > 0 if a .gitignore
- * exists.
- */
- public long getGitIgnoreLastModified() {
- return gitIgnoreTimeStamp;
- }
}
* the root of the repository.
*/
protected final File directory;
+
/**
* the file system abstraction which will be necessary to
* perform certain file system operations.
}
private Entry[] entries() {
- gitIgnoreTimeStamp = 0l;
final File[] all = directory.listFiles();
if (all == null)
return EOF;
final Entry[] r = new Entry[all.length];
- for (int i = 0; i < r.length; i++) {
+ for (int i = 0; i < r.length; i++)
r[i] = new FileEntry(all[i], fs);
- if (all[i].getName().equals(Constants.DOT_GIT_IGNORE))
- gitIgnoreTimeStamp = r[i].getLastModified();
- }
return r;
}