aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2021-12-04 17:52:04 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2021-12-04 18:06:32 +0100
commita1c9c82e8544932d712206088c1dbed226ccfe52 (patch)
tree515e6c570786d8a1b58fd9c55a56ba7fa3b0ec85 /org.eclipse.jgit/src/org
parent5f8c48413623ea4d1685063582c74a216207ef51 (diff)
parent8924b14d3afdb223d6e46e38e27a4cba25b26f23 (diff)
downloadjgit-a1c9c82e8544932d712206088c1dbed226ccfe52.tar.gz
jgit-a1c9c82e8544932d712206088c1dbed226ccfe52.zip
Merge branch 'stable-5.5' into stable-5.6
* stable-5.5: Add missing @since tags Remove unused import in ApacheSshTest Update maven plugins Ignore missing javadoc in test bundles storage: file: De-duplicate File.exists()+File.isFile() RefDirectory.scanRef: Re-use file existence check done in snapshot creation FileSnapshot: Lazy load file store attributes cache Update eclipse-jarsigner-plugin to 1.3.2 Fix p2 repository URLs Change-Id: I007e92c12fde8d765b75f103e9d530aa0834b7d7
Diffstat (limited to 'org.eclipse.jgit/src/org')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java36
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java6
3 files changed, 35 insertions, 9 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java
index 8650ebfe29..e4ee53e0a1 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java
@@ -218,6 +218,12 @@ public class FileSnapshot {
private FileStoreAttributes fileStoreAttributeCache;
/**
+ * if {@code true} read filesystem time resolution from configuration file
+ * otherwise use fallback resolution
+ */
+ private boolean useConfig;
+
+ /**
* Object that uniquely identifies the given file, or {@code
* null} if a file key is not available
*/
@@ -253,9 +259,7 @@ public class FileSnapshot {
protected FileSnapshot(File file, boolean useConfig) {
this.file = file;
this.lastRead = Instant.now();
- this.fileStoreAttributeCache = useConfig
- ? FS.getFileStoreAttributes(file.toPath().getParent())
- : FALLBACK_FILESTORE_ATTRIBUTES;
+ this.useConfig = useConfig;
BasicFileAttributes fileAttributes = null;
try {
fileAttributes = FS.DETECTED.fileAttributes(file);
@@ -399,7 +403,7 @@ public class FileSnapshot {
* if sleep was interrupted
*/
public void waitUntilNotRacy() throws InterruptedException {
- long timestampResolution = fileStoreAttributeCache
+ long timestampResolution = fileStoreAttributeCache()
.getFsTimestampResolution().toNanos();
while (isRacyClean(Instant.now())) {
TimeUnit.NANOSECONDS.sleep(timestampResolution);
@@ -436,6 +440,15 @@ public class FileSnapshot {
return equals(other);
}
+ /**
+ * Check if the file exists
+ *
+ * @return true if the file exists
+ */
+ public boolean fileExists() {
+ return !MISSING_FILEKEY.equals(this.fileKey);
+ }
+
/** {@inheritDoc} */
@Override
public int hashCode() {
@@ -520,10 +533,10 @@ public class FileSnapshot {
}
private long getEffectiveRacyThreshold() {
- long timestampResolution = fileStoreAttributeCache
+ long timestampResolution = fileStoreAttributeCache()
.getFsTimestampResolution().toNanos();
- long minRacyInterval = fileStoreAttributeCache.getMinimalRacyInterval()
- .toNanos();
+ long minRacyInterval = fileStoreAttributeCache()
+ .getMinimalRacyInterval().toNanos();
long max = Math.max(timestampResolution, minRacyInterval);
// safety margin: factor 2.5 below 100ms otherwise 1.25
return max < 100_000_000L ? max * 5 / 2 : max * 5 / 4;
@@ -583,4 +596,13 @@ public class FileSnapshot {
}
return changed;
}
+
+ private FileStoreAttributes fileStoreAttributeCache() {
+ if (fileStoreAttributeCache == null) {
+ fileStoreAttributeCache = useConfig
+ ? FS.getFileStoreAttributes(file.toPath().getParent())
+ : FALLBACK_FILESTORE_ATTRIBUTES;
+ }
+ return fileStoreAttributeCache;
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java
index 7d31673566..8fa683f5ee 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java
@@ -184,7 +184,7 @@ public class ObjectDirectoryPackParser extends PackParser {
String p = pack.getAbsolutePath();
String i = p.substring(0, p.length() - ".pack".length()) + ".idx"; //$NON-NLS-1$ //$NON-NLS-2$
File idx = new File(i);
- if (idx.exists() && idx.isFile())
+ if (idx.isFile())
size += idx.length();
return size;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
index 9476d35475..ae8fe0f562 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
@@ -1122,10 +1122,14 @@ public class RefDirectory extends RefDatabase {
final int limit = 4096;
final byte[] buf;
FileSnapshot otherSnapshot = FileSnapshot.save(path);
+ if (!otherSnapshot.fileExists()) {
+ return null;
+ }
+
try {
buf = IO.readSome(path, limit);
} catch (FileNotFoundException noFile) {
- if (path.exists() && path.isFile()) {
+ if (path.isFile()) {
throw noFile;
}
return null; // doesn't exist or no file; not a reference.