From 2629473063da6d0e18023beb730b39f3a4798c99 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Wed, 13 Jun 2007 01:13:57 +0200 Subject: [PATCH] Do not actually compare content when checking modification status Any sane tool will set modification time to "current", so it is extremely unlikely that two files with the same timestmap and size are different. Signed-off-by: Robin Rosenberg --- .../src/org/spearce/jgit/lib/GitIndex.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/GitIndex.java b/org.spearce.jgit/src/org/spearce/jgit/lib/GitIndex.java index a49bbedf..34d0a0e9 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/GitIndex.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/GitIndex.java @@ -340,7 +340,36 @@ public class GitIndex { return false; } + /** + * Check if an entry's content is different from the cache, + * + * File status information is used and status is same we + * consider the file identical to the state in the working + * directory. Native git uses more stat fields than we + * have accessible in Java. + * + * @param wd working directory to compare content with + * @return true if content is most likely different. + */ public boolean isModified(File wd) { + return isModified(wd, false); + } + + /** + * Check if an entry's content is different from the cache, + * + * File status information is used and status is same we + * consider the file identical to the state in the working + * directory. Native git uses more stat fields than we + * have accessible in Java. + * + * @param wd working directory to compare content with + * @param forceContentCheck True if the actual file content + * should be checked if modification time differs. + * + * @return true if content is most likely different. + */ + public boolean isModified(File wd, boolean forceContentCheck) { File file = getFile(wd); if (!file.exists()) return true; @@ -377,6 +406,9 @@ public class GitIndex { if (file.length() != size) return true; if (lastm != javamtime) { + if (!forceContentCheck) + return true; + try { InputStream is = new FileInputStream(file); ObjectWriter objectWriter = new ObjectWriter(theIndex.db); -- 2.11.4.GIT