From 3bbcc9d66b09fadc39ea009a1da6abd0d741b15d Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 10 Aug 2008 01:46:22 -0700 Subject: [PATCH] Allow WorkingTreeIterator to track last modified time for entries We need this last modified time to compare against the index to decide if a file is dirty or not. Its computed on demand only for the items we actually care about, as we don't need the last modified time for a directory. Signed-off-by: Shawn O. Pearce Signed-off-by: Robin Rosenberg --- .../src/org/spearce/jgit/treewalk/FileTreeIterator.java | 9 +++++++++ .../src/org/spearce/jgit/treewalk/WorkingTreeIterator.java | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/FileTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/FileTreeIterator.java index 331f153d..25425dde 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/FileTreeIterator.java +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/FileTreeIterator.java @@ -106,6 +106,8 @@ public class FileTreeIterator extends WorkingTreeIterator { private long length = -1; + private long lastModified; + FileEntry(final File f) { file = f; @@ -138,6 +140,13 @@ public class FileTreeIterator extends WorkingTreeIterator { } @Override + public long getLastModified() { + if (lastModified == 0) + lastModified = file.lastModified(); + return lastModified; + } + + @Override public InputStream openInputStream() throws IOException { return new FileInputStream(file); } diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java index 92aa4b70..b47da975 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java @@ -433,6 +433,19 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { public abstract long getLength(); /** + * Get the last modified time of this entry. + *

+ * Note: Efficient implementation required. + *

+ * The implementation of this method must be efficient. If a subclass + * needs to compute the value they should cache the reference within an + * instance member instead. + * + * @return time since the epoch (in ms) of the last change. + */ + public abstract long getLastModified(); + + /** * Get the name of this entry within its directory. *

* Efficient implementations are not required. The caller will obtain -- 2.11.4.GIT