]> source.dussan.org Git - jgit.git/commitdiff
Move wantWrite flag to be special offset 1 68/11668/1
authorShawn Pearce <spearce@spearce.org>
Fri, 5 Apr 2013 00:50:32 +0000 (17:50 -0700)
committerShawn Pearce <spearce@spearce.org>
Fri, 5 Apr 2013 00:53:01 +0000 (17:53 -0700)
Free up the WANT_WRITE flag in ObjectToPack by switching the test
to use the special offset value of 1. The Git pack file format
calls for the first 4 bytes to be 'PACK', which means any object
must start at an offset >= 4. Current versions require another 8
bytes in the header, placing the first object at offset = 12.

So offset = 1 is an invalid location for an object, and can be
used as a marker signal to indicate the writing loop has tried
to write the object, but recursed into the base first. When an
object is visited with offset == 1 it means there is a cycle in
the delta base path, and the cycle must be broken.

Change-Id: I2d05b9017c5f9bd9464b91d43e8d4b4a085e55bc

org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/ObjectToPack.java

index 57346ab51a6c47e15e8d7b4d858d280b299ca99f..c9f4274eeaba16cab5f8be73147e179386e8ff88 100644 (file)
@@ -57,8 +57,6 @@ import org.eclipse.jgit.transport.PackedObjectInfo;
  * each object as they are written to the output stream.
  */
 public class ObjectToPack extends PackedObjectInfo {
-       private static final int WANT_WRITE = 1 << 0;
-
        private static final int REUSE_AS_IS = 1 << 1;
 
        private static final int DO_NOT_DELTA = 1 << 2;
@@ -87,7 +85,7 @@ public class ObjectToPack extends PackedObjectInfo {
        /**
         * Bit field, from bit 0 to bit 31:
         * <ul>
-        * <li>1 bit: wantWrite</li>
+        * <li>1 bit: unused</li>
         * <li>1 bit: canReuseAsIs</li>
         * <li>1 bit: doNotDelta</li>
         * <li>1 bit: edgeObject</li>
@@ -190,7 +188,7 @@ public class ObjectToPack extends PackedObjectInfo {
         * @return true if object is already written; false otherwise.
         */
        public final boolean isWritten() {
-               return getOffset() != 0;
+               return 1 < getOffset(); // markWantWrite sets 1.
        }
 
        /** @return the type of this object. */
@@ -207,11 +205,11 @@ public class ObjectToPack extends PackedObjectInfo {
        }
 
        final boolean wantWrite() {
-               return (flags & WANT_WRITE) != 0;
+               return getOffset() == 1;
        }
 
        final void markWantWrite() {
-               flags |= WANT_WRITE;
+               setOffset(1);
        }
 
        /**