aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2024-12-15 21:25:23 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2024-12-15 21:25:23 +0100
commit6aefc8ec82276bc6f796e3ebc69e181de2638c3e (patch)
treeb6676849c0025fd8657c26a5b18c6748d3b60ebe
parentcca2ef12eec44b5b2140761baf13e2a611a654f3 (diff)
parent4f2e6f788fd7229a3d99fce5d0e64db1ddf5371e (diff)
downloadjgit-6aefc8ec82276bc6f796e3ebc69e181de2638c3e.tar.gz
jgit-6aefc8ec82276bc6f796e3ebc69e181de2638c3e.zip
Merge branch 'stable-7.0' into stable-7.1
* stable-7.0: FileSnapshot: fix warnings Optionally.Hard: avoid Optional creation on every use, Pack: fix threading bug getting idx Fix potential NPE in TreeWalk#getFilterCommandDefinition Advertise "agent" capability when using protocol v2 FileSnapshot: silence "Stale file handle" exceptions Change-Id: I4fdea7450f27eebfa7ae08002fd51e67b58bf6bb
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java12
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java15
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java86
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/util/Optionally.java8
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java3
6 files changed, 66 insertions, 59 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
index 064d863bf6..aaecfd290e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
@@ -502,15 +502,15 @@ public class UploadPackTest {
assertThat(hook.capabilitiesRequest, notNullValue());
assertThat(pckIn.readString(), is("version 2"));
assertThat(
- Arrays.asList(pckIn.readString(), pckIn.readString(),
- pckIn.readString()),
+ Arrays.asList(pckIn.readString(),pckIn.readString(),
+ pckIn.readString(), pckIn.readString()),
// TODO(jonathantanmy) This check is written this way
// to make it simple to see that we expect this list of
// capabilities, but probably should be loosened to
// allow additional commands to be added to the list,
// and additional capabilities to be added to existing
// commands without requiring test changes.
- hasItems("ls-refs", "fetch=shallow", "server-option"));
+ hasItems("agent=" + UserAgent.get() ,"ls-refs", "fetch=shallow", "server-option"));
assertTrue(PacketLineIn.isEnd(pckIn.readString()));
}
@@ -536,7 +536,7 @@ public class UploadPackTest {
lines.add(line);
}
}
- assertThat(lines, containsInAnyOrder("ls-refs", "fetch", "server-option"));
+ assertThat(lines, containsInAnyOrder("ls-refs", "fetch", "server-option", "agent=" + UserAgent.get()));
}
private void checkUnadvertisedIfUnallowed(String configSection,
@@ -643,9 +643,9 @@ public class UploadPackTest {
assertThat(pckIn.readString(), is("version 2"));
assertThat(
- Arrays.asList(pckIn.readString(), pckIn.readString(),
+ Arrays.asList(pckIn.readString(),pckIn.readString(), pckIn.readString(),
pckIn.readString()),
- hasItems("ls-refs", "fetch=shallow", "server-option"));
+ hasItems("agent="+ UserAgent.get(),"ls-refs", "fetch=shallow", "server-option"));
assertTrue(PacketLineIn.isEnd(pckIn.readString()));
}
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 8f83a37efc..b8911f55f0 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
@@ -28,6 +28,7 @@ import java.util.Objects;
import java.util.concurrent.TimeUnit;
import org.eclipse.jgit.annotations.NonNull;
+import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FS.FileStoreAttributes;
import org.slf4j.Logger;
@@ -546,11 +547,19 @@ public class FileSnapshot {
private static BasicFileAttributes getFileAttributes(File path) throws NoSuchElementException {
try {
- return FS.DETECTED.fileAttributes(path);
+ try {
+ return FS.DETECTED.fileAttributes(path);
+ } catch (IOException e) {
+ if (!FileUtils.isStaleFileHandle(e)) {
+ throw e;
+ }
+ }
} catch (NoSuchFileException e) {
+ // ignore
} catch (FileSystemException e) {
- if (!e.getMessage().endsWith("Not a directory")) {
- LOG.error(e.getMessage(), e);
+ String msg = e.getMessage();
+ if (!msg.endsWith("Not a directory")) { //$NON-NLS-1$
+ LOG.error(msg, e);
}
} catch (IOException e) {
LOG.error(e.getMessage(), e);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java
index 61577a956c..8d2a86386f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java
@@ -119,7 +119,7 @@ public class Pack implements Iterable<PackIndex.MutableEntry> {
private byte[] packChecksum;
- private volatile Optionally<PackIndex> loadedIdx = Optionally.empty();
+ private Optionally<PackIndex> loadedIdx = Optionally.empty();
private Optionally<PackReverseIndex> reverseIdx = Optionally.empty();
@@ -159,60 +159,54 @@ public class Pack implements Iterable<PackIndex.MutableEntry> {
length = Long.MAX_VALUE;
}
- private PackIndex idx() throws IOException {
+ private synchronized PackIndex idx() throws IOException {
Optional<PackIndex> optional = loadedIdx.getOptional();
if (optional.isPresent()) {
return optional.get();
}
- synchronized (this) {
- optional = loadedIdx.getOptional();
- if (optional.isPresent()) {
- return optional.get();
- }
- if (invalid) {
- throw new PackInvalidException(packFile, invalidatingCause);
+ if (invalid) {
+ throw new PackInvalidException(packFile, invalidatingCause);
+ }
+ try {
+ long start = System.currentTimeMillis();
+ PackFile idxFile = packFile.create(INDEX);
+ PackIndex idx = PackIndex.open(idxFile);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(String.format(
+ "Opening pack index %s, size %.3f MB took %d ms", //$NON-NLS-1$
+ idxFile.getAbsolutePath(),
+ Float.valueOf(idxFile.length()
+ / (1024f * 1024)),
+ Long.valueOf(System.currentTimeMillis()
+ - start)));
}
- try {
- long start = System.currentTimeMillis();
- PackFile idxFile = packFile.create(INDEX);
- PackIndex idx = PackIndex.open(idxFile);
- if (LOG.isDebugEnabled()) {
- LOG.debug(String.format(
- "Opening pack index %s, size %.3f MB took %d ms", //$NON-NLS-1$
- idxFile.getAbsolutePath(),
- Float.valueOf(idxFile.length()
- / (1024f * 1024)),
- Long.valueOf(System.currentTimeMillis()
- - start)));
- }
-
if (packChecksum == null) {
- packChecksum = idx.getChecksum();
- fileSnapshot.setChecksum(
- ObjectId.fromRaw(packChecksum));
- } else if (!Arrays.equals(packChecksum,
- idx.getChecksum())) {
- throw new PackMismatchException(MessageFormat
- .format(JGitText.get().packChecksumMismatch,
- packFile.getPath(),
- PackExt.PACK.getExtension(),
- Hex.toHexString(packChecksum),
- PackExt.INDEX.getExtension(),
- Hex.toHexString(idx.getChecksum())));
- }
- loadedIdx = optionally(idx);
- return idx;
- } catch (InterruptedIOException e) {
- // don't invalidate the pack, we are interrupted from
- // another thread
- throw e;
- } catch (IOException e) {
- invalid = true;
- invalidatingCause = e;
- throw e;
+ packChecksum = idx.getChecksum();
+ fileSnapshot.setChecksum(
+ ObjectId.fromRaw(packChecksum));
+ } else if (!Arrays.equals(packChecksum,
+ idx.getChecksum())) {
+ throw new PackMismatchException(MessageFormat
+ .format(JGitText.get().packChecksumMismatch,
+ packFile.getPath(),
+ PackExt.PACK.getExtension(),
+ Hex.toHexString(packChecksum),
+ PackExt.INDEX.getExtension(),
+ Hex.toHexString(idx.getChecksum())));
}
+ loadedIdx = optionally(idx);
+ return idx;
+ } catch (InterruptedIOException e) {
+ // don't invalidate the pack, we are interrupted from
+ // another thread
+ throw e;
+ } catch (IOException e) {
+ invalid = true;
+ invalidatingCause = e;
+ throw e;
}
}
+
/**
* Get the File object which locates this pack on disk.
*
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/util/Optionally.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/util/Optionally.java
index 3447f669ab..270b760562 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/util/Optionally.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/util/Optionally.java
@@ -53,24 +53,24 @@ public interface Optionally<T> {
/**
* The mutable optional object
*/
- protected T element;
+ protected Optional<T> optional;
/**
* @param element
* the mutable optional object
*/
public Hard(T element) {
- this.element = element;
+ optional = Optional.ofNullable(element);
}
@Override
public void clear() {
- element = null;
+ optional = Optional.empty();
}
@Override
public Optional<T> getOptional() {
- return Optional.ofNullable(element);
+ return optional;
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
index 6013832cac..d972067e40 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
@@ -1394,6 +1394,7 @@ public class UploadPack implements Closeable {
if (transferConfig.isAdvertiseObjectInfo()) {
caps.add(COMMAND_OBJECT_INFO);
}
+ caps.add(OPTION_AGENT + "=" + UserAgent.get());
return caps;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
index aaac2a72e0..b789c5120e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
@@ -1587,6 +1587,9 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
*/
private String getFilterCommandDefinition(String filterDriverName,
String filterCommandType) {
+ if (config == null) {
+ return null;
+ }
String key = filterDriverName + "." + filterCommandType; //$NON-NLS-1$
String filterCommand = filterCommandsByNameDotType.get(key);
if (filterCommand != null)