summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2011-03-04 16:00:25 +0100
committerRobin Rosenberg <robin.rosenberg@dewire.com>2011-03-04 16:00:25 +0100
commit3947bd25d9d63c917c499dcfc45ba860c27839e6 (patch)
treeb7b6471e30d8346e9c620a2dbd04c27cbc4a8e09 /org.eclipse.jgit
parentba77150040ab5cc9f8b02e4b8690d30a3aa41560 (diff)
downloadjgit-3947bd25d9d63c917c499dcfc45ba860c27839e6.tar.gz
jgit-3947bd25d9d63c917c499dcfc45ba860c27839e6.zip
Fix DirCache re-read.
During unit tests and most likely elsewhere, updates come too fast for a simple timestamp comparison (with one seconds resolution) to work. I.e. DirCache thinks it hasn't changed. Use FileSnapshot instead which has more advanced logic. Change-Id: Ib850f84398ef7d4b8a8a6f5a0ae6963e37f2b470 Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java24
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileSnapshot.java5
2 files changed, 17 insertions, 12 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
index c2c57c9840..0d8fb7e266 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
@@ -66,6 +66,7 @@ import org.eclipse.jgit.errors.UnmergedPathException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
+import org.eclipse.jgit.storage.file.FileSnapshot;
import org.eclipse.jgit.storage.file.LockFile;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.IO;
@@ -205,9 +206,6 @@ public class DirCache {
/** Location of the current version of the index file. */
private final File liveFile;
- /** Modification time of the file at the last read/write we did. */
- private long lastModified;
-
/** Individual file index entries, sorted by path name. */
private DirCacheEntry[] sortedEntries;
@@ -223,6 +221,9 @@ public class DirCache {
/** file system abstraction **/
private final FS fs;
+ /** Keep track of whether the index has changed or not */
+ private FileSnapshot snapshot;
+
/**
* Create a new in-core index representation.
* <p>
@@ -290,7 +291,7 @@ public class DirCache {
throw new IOException(JGitText.get().dirCacheDoesNotHaveABackingFile);
if (!liveFile.exists())
clear();
- else if (liveFile.lastModified() != lastModified) {
+ else if (snapshot == null || snapshot.isModified(liveFile)) {
try {
final FileInputStream inStream = new FileInputStream(liveFile);
try {
@@ -309,6 +310,7 @@ public class DirCache {
//
clear();
}
+ snapshot = FileSnapshot.save(liveFile);
}
}
@@ -319,12 +321,12 @@ public class DirCache {
public boolean isOutdated() throws IOException {
if (liveFile == null || !liveFile.exists())
return false;
- return liveFile.lastModified() != lastModified;
+ return snapshot.isModified(liveFile);
}
/** Empty this index, removing all entries. */
public void clear() {
- lastModified = 0;
+ snapshot = null;
sortedEntries = NO_ENTRIES;
entryCnt = 0;
tree = null;
@@ -361,7 +363,7 @@ public class DirCache {
final MutableInteger infoAt = new MutableInteger();
for (int i = 0; i < entryCnt; i++)
sortedEntries[i] = new DirCacheEntry(infos, infoAt, in, md);
- lastModified = liveFile.lastModified();
+ snapshot = FileSnapshot.save(liveFile);
// After the file entries are index extensions, and then a footer.
//
@@ -516,14 +518,14 @@ public class DirCache {
// Write the individual file entries.
//
- if (lastModified <= 0) {
+ if (snapshot == null) {
// Write a new index, as no entries require smudging.
//
for (int i = 0; i < entryCnt; i++)
sortedEntries[i].write(dos);
} else {
- final int smudge_s = (int) (lastModified / 1000);
- final int smudge_ns = ((int) (lastModified % 1000)) * 1000000;
+ final int smudge_s = (int) (snapshot.lastModified() / 1000);
+ final int smudge_ns = ((int) (snapshot.lastModified() % 1000)) * 1000000;
for (int i = 0; i < entryCnt; i++) {
final DirCacheEntry e = sortedEntries[i];
if (e.mightBeRacilyClean(smudge_s, smudge_ns))
@@ -564,7 +566,7 @@ public class DirCache {
myLock = null;
if (!tmp.commit())
return false;
- lastModified = tmp.getCommitLastModified();
+ snapshot = tmp.getCommitSnapshot();
return true;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileSnapshot.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileSnapshot.java
index c844404e13..0e5b3c00be 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileSnapshot.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileSnapshot.java
@@ -102,7 +102,10 @@ public class FileSnapshot {
this.cannotBeRacilyClean = notRacyClean(read);
}
- long lastModified() {
+ /**
+ * @return time of last snapshot update
+ */
+ public long lastModified() {
return lastModified;
}