diff options
author | Ivan Frade <ifrade@google.com> | 2024-03-28 14:55:09 -0700 |
---|---|---|
committer | Ivan Frade <ifrade@google.com> | 2024-05-08 10:47:54 -0700 |
commit | 13212d7ec32e52d51698b5bf97f34b4ffd2e0439 (patch) | |
tree | b74276c76310e2ee3452e60addca85762c570c47 /org.eclipse.jgit | |
parent | da37921221075f024b3a4107e12830c1c622e435 (diff) | |
download | jgit-13212d7ec32e52d51698b5bf97f34b4ffd2e0439.tar.gz jgit-13212d7ec32e52d51698b5bf97f34b4ffd2e0439.zip |
PackIndex: move checksum to the subclasses
PackIndex is almost an interface, and making it so simplifies writing
implementations over other storages. Checksum and its getter is the
only functionality that is class specific.
Make getChecksum abstract and implement it in the subclasses.
Change-Id: I3746515d816abab075210505f1bb31b1936962e9
Diffstat (limited to 'org.eclipse.jgit')
4 files changed, 21 insertions, 10 deletions
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 f87329ccc2..be457644d9 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 @@ -187,18 +187,18 @@ public class Pack implements Iterable<PackIndex.MutableEntry> { } if (packChecksum == null) { - packChecksum = idx.packChecksum; + packChecksum = idx.getChecksum(); fileSnapshot.setChecksum( ObjectId.fromRaw(packChecksum)); } else if (!Arrays.equals(packChecksum, - idx.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.packChecksum))); + Hex.toHexString(idx.getChecksum()))); } loadedIdx = optionally(idx); return idx; @@ -791,7 +791,7 @@ public class Pack implements Iterable<PackIndex.MutableEntry> { MessageFormat.format(JGitText.get().packChecksumMismatch, getPackFile(), PackExt.PACK.getExtension(), Hex.toHexString(buf), PackExt.INDEX.getExtension(), - Hex.toHexString(idx.packChecksum))); + Hex.toHexString(idx.getChecksum()))); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java index c2c3775d67..8a64c3247a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java @@ -116,9 +116,6 @@ public abstract class PackIndex return true; } - /** Footer checksum applied on the bottom of the pack file. */ - protected byte[] packChecksum; - /** * Determine if an object is contained within the pack file. * @@ -297,9 +294,7 @@ public abstract class PackIndex * @return the checksum of the pack; caller must not modify it * @since 5.5 */ - public byte[] getChecksum() { - return packChecksum; - } + public abstract byte[] getChecksum(); /** * Represent mutable entry of pack index consisting of object id and offset diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java index 5180df46bf..21f7314f33 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java @@ -36,6 +36,9 @@ class PackIndexV1 extends PackIndex { private final long[] idxHeader; + /** Footer checksum applied on the bottom of the pack file. */ + protected byte[] packChecksum; + byte[][] idxdata; private long objectCnt; @@ -238,6 +241,11 @@ class PackIndexV1 extends PackIndex { return (RECORD_SIZE * mid) + 4; } + @Override + public byte[] getChecksum() { + return packChecksum; + } + private class IndexV1Iterator extends EntriesIterator { int levelOne; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java index 751b62dc40..9a6f4a421a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java @@ -37,6 +37,9 @@ class PackIndexV2 extends PackIndex { private static final byte[] NO_BYTES = {}; + /** Footer checksum applied on the bottom of the pack file. */ + protected byte[] packChecksum; + private long objectCnt; private final long[] fanoutTable; @@ -281,6 +284,11 @@ class PackIndexV2 extends PackIndex { return -1; } + @Override + public byte[] getChecksum() { + return packChecksum; + } + private class EntriesIteratorV2 extends EntriesIterator { int levelOne; |