diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2010-08-02 12:26:01 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-08-20 17:41:27 -0700 |
commit | fe18e521955e9b7011b0ed460a6f2c1901b8ae57 (patch) | |
tree | 9ba5505cac89da917f7d548d20ef4aa81ffdca92 /org.eclipse.jgit | |
parent | f048af3fd19547d3692f5df968571ffd7556b688 (diff) | |
download | jgit-fe18e521955e9b7011b0ed460a6f2c1901b8ae57.tar.gz jgit-fe18e521955e9b7011b0ed460a6f2c1901b8ae57.zip |
Allow ObjectToPack subclasses to use up to 4 bits of flags
Some instances may benefit from having access to memory efficient
storage for some small values, like single flag bits. Give up a
portion of our delta depth field to make 4 bits available to any
subclass that wants it.
This still gives us room for delta chains of 1,048,576 objects,
and that is just insane. Unpacking 1 million objects to get to
something is longer than most users are willing to wait for data
from Git.
Change-Id: If17ea598dc0ddbde63d69a6fcec0668106569125
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/ObjectToPack.java | 72 |
1 files changed, 69 insertions, 3 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/ObjectToPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/ObjectToPack.java index 047fa8e6cd..b3b92d6266 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/ObjectToPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/ObjectToPack.java @@ -68,9 +68,15 @@ public class ObjectToPack extends PackedObjectInfo { private static final int TYPE_SHIFT = 5; - private static final int DELTA_SHIFT = 8; + private static final int EXT_SHIFT = 8; - private static final int NON_DELTA_MASK = 0xff; + private static final int EXT_MASK = 0xf; + + private static final int DELTA_SHIFT = 12; + + private static final int NON_EXT_MASK = ~(EXT_MASK << EXT_SHIFT); + + private static final int NON_DELTA_MASK = 0xfff; /** Other object being packed that this will delta against. */ private ObjectId deltaBase; @@ -84,8 +90,9 @@ public class ObjectToPack extends PackedObjectInfo { * <li>1 bit: edgeObject</li> * <li>1 bit: unused</li> * <li>3 bits: type</li> + * <li>4 bits: subclass flags (if any)</li> * <li>--</li> - * <li>24 bits: deltaDepth</li> + * <li>20 bits: deltaDepth</li> * </ul> */ private int flags; @@ -254,6 +261,65 @@ public class ObjectToPack extends PackedObjectInfo { flags |= EDGE; } + /** @return the extended flags on this object, in the range [0x0, 0xf]. */ + protected int getExtendedFlags() { + return (flags >>> EXT_SHIFT) & EXT_MASK; + } + + /** + * Determine if a particular extended flag bit has been set. + * + * This implementation may be faster than calling + * {@link #getExtendedFlags()} and testing the result. + * + * @param flag + * the flag mask to test, must be between 0x0 and 0xf. + * @return true if any of the bits matching the mask are non-zero. + */ + protected boolean isExtendedFlag(int flag) { + return (flags & (flag << EXT_SHIFT)) != 0; + } + + /** + * Set an extended flag bit. + * + * This implementation is more efficient than getting the extended flags, + * adding the bit, and setting them all back. + * + * @param flag + * the bits to set, must be between 0x0 and 0xf. + */ + protected void setExtendedFlag(int flag) { + flags |= (flag & EXT_MASK) << EXT_SHIFT; + } + + /** + * Clear an extended flag bit. + * + * This implementation is more efficient than getting the extended flags, + * removing the bit, and setting them all back. + * + * @param flag + * the bits to clear, must be between 0x0 and 0xf. + */ + protected void clearExtendedFlag(int flag) { + flags &= ~((flag & EXT_MASK) << EXT_SHIFT); + } + + /** + * Set the extended flags used by the subclass. + * + * Subclass implementations may store up to 4 bits of information inside of + * the internal flags field already used by the base ObjectToPack instance. + * + * @param extFlags + * additional flag bits to store in the flags field. Due to space + * constraints only values [0x0, 0xf] are permitted. + */ + protected void setExtendedFlags(int extFlags) { + flags = ((extFlags & EXT_MASK) << EXT_SHIFT) | (flags & NON_EXT_MASK); + } + int getFormat() { if (isReuseAsIs()) { if (isDeltaRepresentation()) |