summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMarkus Duft2012-06-06 07:14:14 (EDT)
committer Markus Duft2012-06-06 07:14:14 (EDT)
commit8672c43ae368a014b1fd7d3c108fd41b2fa7ea9e (patch)
treed17623ba26b10cde489374cd638106883568a76d
parent73cdb08af6e402392bd9bc1af270b220ccc64cb8 (diff)
downloadjgit-8672c43ae368a014b1fd7d3c108fd41b2fa7ea9e.zip
jgit-8672c43ae368a014b1fd7d3c108fd41b2fa7ea9e.tar.gz
jgit-8672c43ae368a014b1fd7d3c108fd41b2fa7ea9e.tar.bz2
Make DirCacheCheckout update timestamps in the index.refs/changes/32/6232/6
This updates the timestamp of files that are not touched during checkout. Otherwise the timestamp will always be zero, causing the IndexDiffFilter to always calculate the checksum of file contents. Change-Id: I18047f5725f22811bb4194ca1d3a3cac56074183
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java90
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java10
2 files changed, 98 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java
new file mode 100644
index 0000000..51c6634
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java
@@ -0,0 +1,90 @@
+package org.eclipse.jgit.lib;
+
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.dircache.DirCache;
+import org.eclipse.jgit.dircache.DirCacheEntry;
+import org.junit.Test;
+
+public class IndexModificationTimesTest extends RepositoryTestCase {
+
+ @Test
+ public void testLastModifiedTimes() throws Exception {
+ Git git = new Git(db);
+ String path = "file";
+ writeTrashFile(path, "content");
+ String path2 = "file2";
+ writeTrashFile(path2, "content2");
+
+ git.add().addFilepattern(path).call();
+ git.add().addFilepattern(path2).call();
+ git.commit().setMessage("commit").call();
+
+ DirCache dc = db.readDirCache();
+ DirCacheEntry entry = dc.getEntry(path);
+ DirCacheEntry entry2 = dc.getEntry(path);
+
+ assertTrue("last modified shall not be zero!",
+ entry.getLastModified() != 0);
+
+ assertTrue("last modified shall not be zero!",
+ entry2.getLastModified() != 0);
+
+ writeTrashFile(path, "new content");
+ git.add().addFilepattern(path).call();
+ git.commit().setMessage("commit2").call();
+
+ dc = db.readDirCache();
+ entry = dc.getEntry(path);
+ entry2 = dc.getEntry(path);
+
+ assertTrue("last modified shall not be zero!",
+ entry.getLastModified() != 0);
+
+ assertTrue("last modified shall not be zero!",
+ entry2.getLastModified() != 0);
+ }
+
+ @Test
+ public void testModify() throws Exception {
+ Git git = new Git(db);
+ String path = "file";
+ writeTrashFile(path, "content");
+
+ git.add().addFilepattern(path).call();
+ git.commit().setMessage("commit").call();
+
+ DirCache dc = db.readDirCache();
+ DirCacheEntry entry = dc.getEntry(path);
+
+ long masterLastMod = entry.getLastModified();
+
+ git.checkout().setCreateBranch(true).setName("side").call();
+
+ Thread.sleep(10);
+ String path2 = "file2";
+ writeTrashFile(path2, "side content");
+ git.add().addFilepattern(path2).call();
+ git.commit().setMessage("commit").call();
+
+ dc = db.readDirCache();
+ entry = dc.getEntry(path);
+
+ long sideLastMode = entry.getLastModified();
+
+ Thread.sleep(2000);
+
+ writeTrashFile(path, "uncommitted content");
+ git.checkout().setName("master").call();
+
+ dc = db.readDirCache();
+ entry = dc.getEntry(path);
+
+ assertTrue("shall have equal mod time!", masterLastMod == sideLastMode);
+ assertTrue("shall not equal master timestamp!",
+ entry.getLastModified() == masterLastMod);
+
+ }
+
+}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
index 22a8558..8b15a27 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
@@ -332,8 +332,14 @@ public class DirCacheCheckout {
// conflict
update(m.getEntryPathString(), m.getEntryObjectId(),
m.getEntryFileMode());
- else
- keep(i.getDirCacheEntry());
+ else {
+ // update the timestamp of the index with the one from the
+ // file if not set, as we are sure to be in sync here.
+ DirCacheEntry entry = i.getDirCacheEntry();
+ if (entry.getLastModified() == 0)
+ entry.setLastModified(f.getEntryLastModified());
+ keep(entry);
+ }
} else
// The index contains a folder
keep(i.getDirCacheEntry());