From 6cb21049d7a48dbc4384fe98a3d3093eb457e381 Mon Sep 17 00:00:00 2001 From: Michael Keppler Date: Tue, 20 Aug 2019 16:09:12 +0200 Subject: Fix deprecation in DirCache caused by Instant based DirCacheEntry Replace the two int variables smudge_s and smudge_ns by an Instant and use the new method DirCacheEntry.mightBeRacilyClean(Instant). Change-Id: Id70adbb0856a64909617acf65da1bae8e2ae934a Signed-off-by: Michael Keppler Signed-off-by: Matthias Sohn --- org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'org.eclipse.jgit/src') 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 0cfd16b58a..a778de910b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java @@ -671,8 +671,7 @@ public class DirCache { // Write the individual file entries. - final int smudge_s; - final int smudge_ns; + Instant smudge; if (myLock != null) { // For new files we need to smudge the index entry // if they have been modified "now". Ideally we'd @@ -680,12 +679,10 @@ public class DirCache { // so we use the current timestamp as a approximation. myLock.createCommitSnapshot(); snapshot = myLock.getCommitSnapshot(); - smudge_s = (int) (snapshot.lastModifiedInstant().getEpochSecond()); - smudge_ns = snapshot.lastModifiedInstant().getNano(); + smudge = snapshot.lastModifiedInstant(); } else { // Used in unit tests only - smudge_ns = 0; - smudge_s = 0; + smudge = Instant.EPOCH; } // Check if tree is non-null here since calling updateSmudgedEntries @@ -697,8 +694,9 @@ public class DirCache { for (int i = 0; i < entryCnt; i++) { final DirCacheEntry e = sortedEntries[i]; - if (e.mightBeRacilyClean(smudge_s, smudge_ns)) + if (e.mightBeRacilyClean(smudge)) { e.smudgeRacilyClean(); + } e.write(dos); } -- cgit v1.2.3 From c130e5e708a34619a90474afd8f259931fc8e7c2 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 21 Aug 2019 00:29:45 +0200 Subject: Avoid sign extension when comparing mtime with Instant#getEpochSecond Ensure we use the same type when comparing seconds since the epoch. This does not prevent that in 2038 timestamps in seconds since the epoch stored in a 32 bit integer will overflow. Integer.MAX_VALUE translates to 2038-01-19T03:14:07Z. After this date we'll have an issue since we store seconds since the epoch in a 32 bit integer in some places. Bug: 319142 Change-Id: If0c03003d40b480f044686e2f7a2f62c9f4e2fe1 Signed-off-by: Matthias Sohn --- org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'org.eclipse.jgit/src') 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 d2a59c1310..b118fd6bc9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java @@ -378,7 +378,7 @@ public class DirCacheEntry { // final int base = infoOffset + P_MTIME; final int mtime = NB.decodeInt32(info, base); - if (smudge.getEpochSecond() == mtime) { + if ((int) smudge.getEpochSecond() == mtime) { return smudge.getNano() <= NB.decodeInt32(info, base + 4); } return false; -- cgit v1.2.3 From e80a62e226f83cde5778ff455d9406c3cc247cf0 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 21 Aug 2019 11:52:20 +0200 Subject: Add missing @since tag on FileTreeIterator#getLastModifiedInstant Change-Id: I809399e6a71e0079d2f0007b0d3f00b531d451bb Signed-off-by: Matthias Sohn --- org.eclipse.jgit/src/org/eclipse/jgit/treewalk/FileTreeIterator.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'org.eclipse.jgit/src') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/FileTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/FileTreeIterator.java index d432c94450..4f3eb05b11 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/FileTreeIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/FileTreeIterator.java @@ -412,6 +412,9 @@ public class FileTreeIterator extends WorkingTreeIterator { return attributes.getLastModifiedInstant().toEpochMilli(); } + /** + * @since 5.1.9 + */ @Override public Instant getLastModifiedInstant() { return attributes.getLastModifiedInstant(); -- cgit v1.2.3