Class AbbreviatedObjectId

java.lang.Object
org.eclipse.jgit.lib.AbbreviatedObjectId
All Implemented Interfaces:
Serializable

public final class AbbreviatedObjectId extends Object implements Serializable
A prefix abbreviation of an ObjectId.

Sometimes Git produces abbreviated SHA-1 strings, using sufficient leading digits from the ObjectId name to still be unique within the repository the string was generated from. These ids are likely to be unique for a useful period of time, especially if they contain at least 6-10 hex digits.

This class converts the hex string into a binary form, to make it more efficient for matching against an object.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) final int
    Number of half-bytes used by this id.
    private static final long
     
    (package private) final int
     
    (package private) final int
     
    (package private) final int
     
    (package private) final int
     
    (package private) final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbbreviatedObjectId(int n, int new_1, int new_2, int new_3, int new_4, int new_5)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    private static final AbbreviatedObjectId
    fromHexString(byte[] bs, int ptr, int end)
     
    static final AbbreviatedObjectId
    Convert an AbbreviatedObjectId from an AnyObjectId.
    static final AbbreviatedObjectId
    fromString(byte[] buf, int offset, int end)
    Convert an AbbreviatedObjectId from hex characters (US-ASCII).
    static final AbbreviatedObjectId
    Convert an AbbreviatedObjectId from hex characters.
    final int
    Get value for a fan-out style map, only valid of length >= 2.
    int
    private static final int
    hexUInt32(byte[] bs, int p, int end)
     
    boolean
    Whether this ObjectId is actually a complete id.
    static final boolean
    Test a string of characters to verify it is a hex format.
    int
    Get number of hex digits appearing in this id.
    private int
    mask(int word, int v)
     
    (package private) static int
    mask(int nibbles, int word, int v)
     
    final String
    Get string form of the abbreviation, in lower case hexadecimal.
    final int
    prefixCompare(byte[] bs, int p)
    Compare this abbreviation to a network-byte-order ObjectId.
    final int
    prefixCompare(int[] bs, int p)
    Compare this abbreviation to a network-byte-order ObjectId.
    final int
    Compares this abbreviation to a full object id.
    A complete ObjectId; null if isComplete() is false

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • nibbles

      final int nibbles
      Number of half-bytes used by this id.
    • w1

      final int w1
    • w2

      final int w2
    • w3

      final int w3
    • w4

      final int w4
    • w5

      final int w5
  • Constructor Details

    • AbbreviatedObjectId

      AbbreviatedObjectId(int n, int new_1, int new_2, int new_3, int new_4, int new_5)
  • Method Details

    • isId

      public static final boolean isId(String id)
      Test a string of characters to verify it is a hex format.

      If true the string can be parsed with fromString(String).

      Parameters:
      id - the string to test.
      Returns:
      true if the string can converted into an AbbreviatedObjectId.
    • fromString

      public static final AbbreviatedObjectId fromString(byte[] buf, int offset, int end)
      Convert an AbbreviatedObjectId from hex characters (US-ASCII).
      Parameters:
      buf - the US-ASCII buffer to read from.
      offset - position to read the first character from.
      end - one past the last position to read (end-offset is the length of the string).
      Returns:
      the converted object id.
    • fromObjectId

      public static final AbbreviatedObjectId fromObjectId(AnyObjectId id)
      Convert an AbbreviatedObjectId from an AnyObjectId.

      This method copies over all bits of the Id, and is therefore complete (see isComplete()).

      Parameters:
      id - the ObjectId to convert from.
      Returns:
      the converted object id.
    • fromString

      public static final AbbreviatedObjectId fromString(String str)
      Convert an AbbreviatedObjectId from hex characters.
      Parameters:
      str - the string to read from. Must be <= 40 characters.
      Returns:
      the converted object id.
    • fromHexString

      private static final AbbreviatedObjectId fromHexString(byte[] bs, int ptr, int end)
    • hexUInt32

      private static final int hexUInt32(byte[] bs, int p, int end)
    • mask

      static int mask(int nibbles, int word, int v)
    • length

      public int length()
      Get number of hex digits appearing in this id.
      Returns:
      number of hex digits appearing in this id.
    • isComplete

      public boolean isComplete()
      Whether this ObjectId is actually a complete id.
      Returns:
      true if this ObjectId is actually a complete id.
    • toObjectId

      public ObjectId toObjectId()
      A complete ObjectId; null if isComplete() is false
      Returns:
      a complete ObjectId; null if isComplete() is false
    • prefixCompare

      public final int prefixCompare(AnyObjectId other)
      Compares this abbreviation to a full object id.
      Parameters:
      other - the other object id.
      Returns:
      <0 if this abbreviation names an object that is less than other; 0 if this abbreviation exactly matches the first length() digits of other.name(); >0 if this abbreviation names an object that is after other.
    • prefixCompare

      public final int prefixCompare(byte[] bs, int p)
      Compare this abbreviation to a network-byte-order ObjectId.
      Parameters:
      bs - array containing the other ObjectId in network byte order.
      p - position within bs to start the compare at. At least 20 bytes, starting at this position are required.
      Returns:
      <0 if this abbreviation names an object that is less than other; 0 if this abbreviation exactly matches the first length() digits of other.name(); >0 if this abbreviation names an object that is after other.
    • prefixCompare

      public final int prefixCompare(int[] bs, int p)
      Compare this abbreviation to a network-byte-order ObjectId.
      Parameters:
      bs - array containing the other ObjectId in network byte order.
      p - position within bs to start the compare at. At least 5 ints, starting at this position are required.
      Returns:
      <0 if this abbreviation names an object that is less than other; 0 if this abbreviation exactly matches the first length() digits of other.name(); >0 if this abbreviation names an object that is after other.
    • getFirstByte

      public final int getFirstByte()
      Get value for a fan-out style map, only valid of length >= 2.
      Returns:
      value for a fan-out style map, only valid of length >= 2.
    • mask

      private int mask(int word, int v)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • name

      public final String name()
      Get string form of the abbreviation, in lower case hexadecimal.
      Returns:
      string form of the abbreviation, in lower case hexadecimal.
    • toString

      public String toString()
      Overrides:
      toString in class Object