diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2019-03-12 00:13:59 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2019-03-12 00:14:14 +0100 |
commit | 51f2979f13e0baf8ab58518a5d998a21cac55a8a (patch) | |
tree | 828d9f84f4098a61cfffdc6b0c90227bdb87ac1a /org.eclipse.jgit | |
parent | 90e614a41d70ae5c3dabf06a5bfe3354ed525fad (diff) | |
parent | da8e47ddc1c618cb83139fa552ddb36ba6e2acac (diff) | |
download | jgit-51f2979f13e0baf8ab58518a5d998a21cac55a8a.tar.gz jgit-51f2979f13e0baf8ab58518a5d998a21cac55a8a.zip |
Merge branch 'stable-5.3'
* stable-5.3:
Reduce contention on PackFile.idx() function.
Use SystemReader in JSchConfigSessionFactoryTest
Avoid NPE in ObjectId.isId()
Change-Id: I1d13f6fb705258ae6d6e5fa5e733bfacd4f3d0e3
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java | 61 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java | 6 |
2 files changed, 40 insertions, 27 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java index ed238a40e7..7549274efd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java @@ -139,7 +139,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { private byte[] packChecksum; - private PackIndex loadedIdx; + private volatile PackIndex loadedIdx; private PackReverseIndex reverseIdx; @@ -174,35 +174,44 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { length = Long.MAX_VALUE; } - private synchronized PackIndex idx() throws IOException { - if (loadedIdx == null) { - if (invalid) - throw new PackInvalidException(packFile); - - try { - final PackIndex idx = PackIndex.open(extFile(INDEX)); - - if (packChecksum == null) { - packChecksum = idx.packChecksum; - } else if (!Arrays.equals(packChecksum, idx.packChecksum)) { - throw new PackMismatchException(MessageFormat.format( - JGitText.get().packChecksumMismatch, - packFile.getPath(), - ObjectId.fromRaw(packChecksum).name(), - ObjectId.fromRaw(idx.packChecksum).name())); + private PackIndex idx() throws IOException { + PackIndex idx = loadedIdx; + if (idx == null) { + synchronized (this) { + idx = loadedIdx; + if (idx == null) { + if (invalid) { + throw new PackInvalidException(packFile); + } + try { + idx = PackIndex.open(extFile(INDEX)); + + if (packChecksum == null) { + packChecksum = idx.packChecksum; + } else if (!Arrays.equals(packChecksum, + idx.packChecksum)) { + throw new PackMismatchException(MessageFormat + .format(JGitText.get().packChecksumMismatch, + packFile.getPath(), + ObjectId.fromRaw(packChecksum) + .name(), + ObjectId.fromRaw(idx.packChecksum) + .name())); + } + loadedIdx = idx; + } catch (InterruptedIOException e) { + // don't invalidate the pack, we are interrupted from + // another thread + throw e; + } catch (IOException e) { + invalid = true; + throw e; + } } - loadedIdx = idx; - } catch (InterruptedIOException e) { - // don't invalidate the pack, we are interrupted from another thread - throw e; - } catch (IOException e) { - invalid = true; - throw e; } } - return loadedIdx; + return idx; } - /** * Get the File object which locates this pack on disk. * diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java index 764f890158..0e96138c00 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java @@ -49,6 +49,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import org.eclipse.jgit.annotations.Nullable; import org.eclipse.jgit.errors.InvalidObjectIdException; import org.eclipse.jgit.util.NB; import org.eclipse.jgit.util.RawParseUtils; @@ -86,7 +87,10 @@ public class ObjectId extends AnyObjectId implements Serializable { * the string to test. * @return true if the string can converted into an ObjectId. */ - public static final boolean isId(String id) { + public static final boolean isId(@Nullable String id) { + if (id == null) { + return false; + } if (id.length() != Constants.OBJECT_ID_STRING_LENGTH) return false; try { |