Browse Source

Move wantWrite flag to be special offset 1

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
stable-3.0
Shawn Pearce 12 years ago
parent
commit
241eed844d
  1. 10
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/ObjectToPack.java

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

@ -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);
}
/**

Loading…
Cancel
Save