Browse Source

Remove gitIgnoreTimestamp from abstract iterator API

This never should have been exposed on the top of the
AbstractTreeIterator type hierarchy.  There is no concept of a
timestamp in a canonical tree read from the object database, and
the time in the DirCache isn't what we want here either.

Actually all that we need is to find the files whose names are
".gitignore" and are below the root directory.  We can accomplish
that with a suffix filter, and process them immediately.

Change-Id: Ib09cbf81a9e038452ce491385c65498312e2916b
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
CC: Charley Wang <chwang@redhat.com>
CC: Chris Aniszczyk <caniszczyk@gmail.com>
CC: Stefan Lay <stefan.lay@sap.com>
CC: Matthias Sohn <matthias.sohn@sap.com>
stable-0.9
Shawn O. Pearce 15 years ago
parent
commit
c59db09bc5
  1. 35
      org.eclipse.jgit/src/org/eclipse/jgit/ignore/SimpleIgnoreCache.java
  2. 30
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java
  3. 7
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/FileTreeIterator.java

35
org.eclipse.jgit/src/org/eclipse/jgit/ignore/SimpleIgnoreCache.java

@ -46,11 +46,12 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.treewalk.FileTreeIterator; import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.PathSuffixFilter;
import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FS;
/** /**
@ -112,19 +113,10 @@ public class SimpleIgnoreCache {
TreeWalk tw = new TreeWalk(repository); TreeWalk tw = new TreeWalk(repository);
tw.reset(); tw.reset();
tw.addTree(new FileTreeIterator(repository.getWorkDir(), FS.DETECTED)); tw.addTree(new FileTreeIterator(repository.getWorkDir(), FS.DETECTED));
tw.setFilter(PathSuffixFilter.create("/" + Constants.DOT_GIT_IGNORE));
tw.setRecursive(true); tw.setRecursive(true);
while (tw.next())
//Don't waste time trying to add iterators that already exist addNodeFromTree(tw.getTree(0, FileTreeIterator.class));
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);
//The base is special //The base is special
//TODO: Test alternate locations for GIT_DIR //TODO: Test alternate locations for GIT_DIR
@ -153,24 +145,15 @@ public class SimpleIgnoreCache {
} }
/** /**
* Adds a node located at the FileTreeIterator's root directory. * Adds a node located at the FileTreeIterator's current position.
* <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.
* *
* @param t * @param t
* AbstractTreeIterator to check for ignore info. The name of the node * FileTreeIterator to check for ignore info. The name of the
* should be .gitignore * entry should be ".gitignore".
*/ */
protected void addNodeFromTree(FileTreeIterator t) { protected void addNodeFromTree(FileTreeIterator t) {
IgnoreNode n = ignoreMap.get(relativize(t.getDirectory())); IgnoreNode n = ignoreMap.get(relativize(t.getDirectory()));
long time = t.getGitIgnoreLastModified(); long time = t.getEntryLastModified();
if (n != null) { if (n != null) {
if (n.getLastModified() == time) if (n.getLastModified() == time)
//TODO: Test and optimize //TODO: Test and optimize

30
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java

@ -138,19 +138,11 @@ public abstract class AbstractTreeIterator {
*/ */
protected int pathLen; 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. */ /** Create a new iterator with no parent. */
protected AbstractTreeIterator() { protected AbstractTreeIterator() {
parent = null; parent = null;
path = new byte[DEFAULT_PATH_SIZE]; path = new byte[DEFAULT_PATH_SIZE];
pathOffset = 0; pathOffset = 0;
gitIgnoreTimeStamp = 0l;
} }
/** /**
@ -170,7 +162,6 @@ public abstract class AbstractTreeIterator {
*/ */
protected AbstractTreeIterator(final String prefix) { protected AbstractTreeIterator(final String prefix) {
parent = null; parent = null;
gitIgnoreTimeStamp = 0l;
if (prefix != null && prefix.length() > 0) { if (prefix != null && prefix.length() > 0) {
final ByteBuffer b; final ByteBuffer b;
@ -205,7 +196,6 @@ public abstract class AbstractTreeIterator {
*/ */
protected AbstractTreeIterator(final byte[] prefix) { protected AbstractTreeIterator(final byte[] prefix) {
parent = null; parent = null;
gitIgnoreTimeStamp = 0l;
if (prefix != null && prefix.length > 0) { if (prefix != null && prefix.length > 0) {
pathLen = prefix.length; pathLen = prefix.length;
@ -230,7 +220,6 @@ public abstract class AbstractTreeIterator {
parent = p; parent = p;
path = p.path; path = p.path;
pathOffset = p.pathLen + 1; pathOffset = p.pathLen + 1;
gitIgnoreTimeStamp = 0l;
try { try {
path[pathOffset - 1] = '/'; path[pathOffset - 1] = '/';
@ -261,7 +250,6 @@ public abstract class AbstractTreeIterator {
parent = p; parent = p;
path = childPath; path = childPath;
pathOffset = childPathOffset; pathOffset = childPathOffset;
gitIgnoreTimeStamp = 0l;
} }
/** /**
@ -605,22 +593,4 @@ public abstract class AbstractTreeIterator {
public void getName(byte[] buffer, int offset) { public void getName(byte[] buffer, int offset) {
System.arraycopy(path, pathOffset, buffer, offset, pathLen - pathOffset); 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;
}
} }

7
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/FileTreeIterator.java

@ -69,6 +69,7 @@ public class FileTreeIterator extends WorkingTreeIterator {
* the root of the repository. * the root of the repository.
*/ */
protected final File directory; protected final File directory;
/** /**
* the file system abstraction which will be necessary to * the file system abstraction which will be necessary to
* perform certain file system operations. * perform certain file system operations.
@ -117,16 +118,12 @@ public class FileTreeIterator extends WorkingTreeIterator {
} }
private Entry[] entries() { private Entry[] entries() {
gitIgnoreTimeStamp = 0l;
final File[] all = directory.listFiles(); final File[] all = directory.listFiles();
if (all == null) if (all == null)
return EOF; return EOF;
final Entry[] r = new Entry[all.length]; 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); r[i] = new FileEntry(all[i], fs);
if (all[i].getName().equals(Constants.DOT_GIT_IGNORE))
gitIgnoreTimeStamp = r[i].getLastModified();
}
return r; return r;
} }

Loading…
Cancel
Save