aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2019-07-03 01:07:14 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2019-07-18 03:27:52 +0200
commit95e8264cc8d2689cec10b58fbf15149856000df4 (patch)
tree02c5e1673058615c71778b436fd50855b96aed0f /org.eclipse.jgit.pgm
parent4db39f50742706091ee66207526cc801db40b780 (diff)
downloadjgit-95e8264cc8d2689cec10b58fbf15149856000df4.tar.gz
jgit-95e8264cc8d2689cec10b58fbf15149856000df4.zip
Use Instant instead of milliseconds for filesystem timestamp handling
This enables higher file timestamp resolution on filesystems like ext4, Mac APFS (1ns) or NTFS (100ns) providing high timestamp resolution on filesystem level. Note: - on some OSes Java 8,9 truncate milliseconds, see https://bugs.openjdk.java.net/browse/JDK-8177809, fixed in Java 10 - UnixFileAttributes truncates timestamp resolution to microseconds when converting the internal representation to FileTime exposed in the API, see https://bugs.openjdk.java.net/browse/JDK-8181493 - WindowsFileAttributes also provides only microsecond resolution Change-Id: I25ffff31a3c6f725fc345d4ddc2f26da3b88f6f2 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.pgm')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowDirCache.java22
1 files changed, 13 insertions, 9 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowDirCache.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowDirCache.java
index 7f99d76bda..14a60a3b46 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowDirCache.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowDirCache.java
@@ -48,8 +48,10 @@ package org.eclipse.jgit.pgm.debug;
import static java.lang.Integer.valueOf;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.Locale;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEntry;
@@ -67,25 +69,27 @@ class ShowDirCache extends TextBuiltin {
/** {@inheritDoc} */
@Override
protected void run() throws Exception {
- final SimpleDateFormat fmt;
- fmt = new SimpleDateFormat("yyyy-MM-dd,HH:mm:ss.SSS"); //$NON-NLS-1$
+ final DateTimeFormatter fmt = DateTimeFormatter
+ .ofPattern("yyyy-MM-dd,HH:mm:ss.nnnnnnnnn") //$NON-NLS-1$
+ .withLocale(Locale.getDefault())
+ .withZone(ZoneId.systemDefault());
final DirCache cache = db.readDirCache();
for (int i = 0; i < cache.getEntryCount(); i++) {
final DirCacheEntry ent = cache.getEntry(i);
final FileMode mode = FileMode.fromBits(ent.getRawMode());
final int len = ent.getLength();
- long lastModified = ent.getLastModified();
- final Date mtime = new Date(lastModified);
+ Instant mtime = ent.getLastModifiedInstant();
final int stage = ent.getStage();
outw.print(mode);
outw.format(" %6d", valueOf(len)); //$NON-NLS-1$
outw.print(' ');
- if (millis)
- outw.print(lastModified);
- else
+ if (millis) {
+ outw.print(mtime.toEpochMilli());
+ } else {
outw.print(fmt.format(mtime));
+ }
outw.print(' ');
outw.print(ent.getObjectId().name());
outw.print(' ');