[EGIT PATCH 07/11] Allow WorkingTreeIterator to track last modified time for entries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <spearce@xxxxxxxxxxx>
---
 .../spearce/jgit/treewalk/FileTreeIterator.java    |    9 +++++++++
 .../spearce/jgit/treewalk/WorkingTreeIterator.java |   13 +++++++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)

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 331f153..25425dd 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 afac77b..cb4a089 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.
+		 * <p>
+		 * <b>Note: Efficient implementation required.</b>
+		 * <p>
+		 * 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.
 		 * <p>
 		 * Efficient implementations are not required. The caller will obtain
-- 
1.6.0.rc2.219.g1250ab

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux