]> source.dussan.org Git - jgit.git/commitdiff
PackIndex: move checksum to the subclasses 72/1194472/2
authorIvan Frade <ifrade@google.com>
Thu, 28 Mar 2024 21:55:09 +0000 (14:55 -0700)
committerIvan Frade <ifrade@google.com>
Wed, 8 May 2024 17:47:54 +0000 (10:47 -0700)
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

org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java

index f87329ccc2b94a5b872ed35980cdc9c4cf1d488c..be457644d9dd2441123399c26f82154781ff5f69 100644 (file)
@@ -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())));
                }
        }
 
index c2c3775d67e2e5bc39b1dd58e29a49a047c85743..8a64c3247a862d4083a30998eee7fced6082e780 100644 (file)
@@ -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
index 5180df46bfa034f98d72f7cc2c2616f7cfe0b206..21f7314f33b366e0942b1359ee368be47ef49fb6 100644 (file)
@@ -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;
 
index 751b62dc40978860422508654b937f93d3e520dc..9a6f4a421abc79004bef61094ab7bcbd86cb61ba 100644 (file)
@@ -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;