aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java45
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java7
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java10
3 files changed, 44 insertions, 18 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 f139b0f7f8..0d5952df24 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
@@ -60,8 +60,8 @@ import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Comparator;
-import org.eclipse.jgit.errors.LockFailedException;
import org.eclipse.jgit.errors.CorruptObjectException;
+import org.eclipse.jgit.errors.LockFailedException;
import org.eclipse.jgit.errors.UnmergedPathException;
import org.eclipse.jgit.events.IndexChangedEvent;
import org.eclipse.jgit.events.IndexChangedListener;
@@ -404,6 +404,10 @@ public class DirCache {
if (entryCnt < 0)
throw new CorruptObjectException(JGitText.get().DIRCHasTooManyEntries);
+ snapshot = FileSnapshot.save(liveFile);
+ int smudge_s = (int) (snapshot.lastModified() / 1000);
+ int smudge_ns = ((int) (snapshot.lastModified() % 1000)) * 1000000;
+
// Load the individual file entries.
//
final int infoLength = DirCacheEntry.getMaximumInfoLength(extended);
@@ -412,8 +416,7 @@ public class DirCache {
final MutableInteger infoAt = new MutableInteger();
for (int i = 0; i < entryCnt; i++)
- sortedEntries[i] = new DirCacheEntry(infos, infoAt, in, md);
- snapshot = FileSnapshot.save(liveFile);
+ sortedEntries[i] = new DirCacheEntry(infos, infoAt, in, md, smudge_s, smudge_ns);
// After the file entries are index extensions, and then a footer.
//
@@ -570,21 +573,29 @@ public class DirCache {
dos.write(tmp, 0, 12);
// Write the individual file entries.
- //
- if (snapshot == null) {
- // Write a new index, as no entries require smudging.
- //
- for (int i = 0; i < entryCnt; i++)
- sortedEntries[i].write(dos);
+
+ final int smudge_s;
+ final int smudge_ns;
+ if (myLock != null) {
+ // For new files we need to smudge the index entry
+ // if they have been modified "now". Ideally we'd
+ // want the timestamp when we're done writing the index,
+ // so we use the current timestamp as a approximation.
+ myLock.createCommitSnapshot();
+ snapshot = myLock.getCommitSnapshot();
+ smudge_s = (int) (snapshot.lastModified() / 1000);
+ smudge_ns = ((int) (snapshot.lastModified() % 1000)) * 1000000;
} else {
- 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))
- e.smudgeRacilyClean();
- e.write(dos);
- }
+ // Used in unit tests only
+ smudge_ns = 0;
+ smudge_s = 0;
+ }
+
+ for (int i = 0; i < entryCnt; i++) {
+ final DirCacheEntry e = sortedEntries[i];
+ if (e.mightBeRacilyClean(smudge_s, smudge_ns))
+ e.smudgeRacilyClean();
+ e.write(dos);
}
if (tree != null) {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java
index 9f5aa8cfa1..aec12e3169 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java
@@ -141,7 +141,8 @@ public class DirCacheEntry {
private byte inCoreFlags;
DirCacheEntry(final byte[] sharedInfo, final MutableInteger infoAt,
- final InputStream in, final MessageDigest md) throws IOException {
+ final InputStream in, final MessageDigest md, final int smudge_s,
+ final int smudge_ns) throws IOException {
info = sharedInfo;
infoOffset = infoAt.value;
@@ -199,6 +200,10 @@ public class DirCacheEntry {
IO.skipFully(in, padLen);
md.update(nullpad, 0, padLen);
}
+
+ if (mightBeRacilyClean(smudge_s, smudge_ns))
+ smudgeRacilyClean();
+
}
/**
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java
index f3b533c133..9218121917 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java
@@ -504,6 +504,16 @@ public class LockFile {
}
/**
+ * Update the commit snapshot {@link #getCommitSnapshot()} before commit.
+ * <p>
+ * This may be necessary if you need time stamp before commit occurs, e.g
+ * while writing the index.
+ */
+ public void createCommitSnapshot() {
+ saveStatInformation();
+ }
+
+ /**
* Unlock this file and abort this change.
* <p>
* The temporary file (if created) is deleted before returning.