]> source.dussan.org Git - jgit.git/commitdiff
Fix offset64 creation for objects at 2 GiB 69/3969/3
authorShawn O. Pearce <spearce@spearce.org>
Sat, 6 Aug 2011 01:18:16 +0000 (18:18 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Mon, 8 Aug 2011 23:36:56 +0000 (16:36 -0700)
The offset32 format is used for objects <= 2^31-1, while the offset64
format is used for all other objects.  This condition was missing
the = needed to ensure an object placed exactly at 2^31 would have
its 64 bit offset in the index.

Change-Id: I293fac0e829c9baa12cb59411dffde666051d6c5
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackIndexWriterV2.java

index 21ebd1ca9cd5f834642064fb116cea7a19ecfcde..7671cd6f1cc5b7de0758fbdd04deb5ed9c24641d 100644 (file)
@@ -56,6 +56,9 @@ import org.eclipse.jgit.util.NB;
  * @see PackIndexV2
  */
 class PackIndexWriterV2 extends PackIndexWriter {
+       private static final int MAX_OFFSET_32 = 0x7fffffff;
+       private static final int IS_OFFSET_64 = 0x80000000;
+
        PackIndexWriterV2(final OutputStream dst) {
                super(dst);
        }
@@ -87,10 +90,10 @@ class PackIndexWriterV2 extends PackIndexWriter {
                int o64 = 0;
                for (final PackedObjectInfo oe : entries) {
                        final long o = oe.getOffset();
-                       if (o < Integer.MAX_VALUE)
+                       if (o <= MAX_OFFSET_32)
                                NB.encodeInt32(tmp, 0, (int) o);
                        else
-                               NB.encodeInt32(tmp, 0, (1 << 31) | o64++);
+                               NB.encodeInt32(tmp, 0, IS_OFFSET_64 | o64++);
                        out.write(tmp, 0, 4);
                }
        }
@@ -98,7 +101,7 @@ class PackIndexWriterV2 extends PackIndexWriter {
        private void writeOffset64() throws IOException {
                for (final PackedObjectInfo oe : entries) {
                        final long o = oe.getOffset();
-                       if (o > Integer.MAX_VALUE) {
+                       if (MAX_OFFSET_32 < o) {
                                NB.encodeInt64(tmp, 0, o);
                                out.write(tmp, 0, 8);
                        }