Package org.eclipse.jgit.lfs.lib
Class AbbreviatedLongObjectId
java.lang.Object
org.eclipse.jgit.lfs.lib.AbbreviatedLongObjectId
- All Implemented Interfaces:
Serializable
A prefix abbreviation of an
LongObjectId
.
Enable abbreviating SHA-256 strings used by Git LFS, using sufficient leading digits from the LongObjectId 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.
Ported to SHA-256 from AbbreviatedObjectId
- Since:
- 4.3
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbbreviatedLongObjectId
(int n, long new_1, long new_2, long new_3, long new_4) -
Method Summary
Modifier and TypeMethodDescriptionboolean
private static final AbbreviatedLongObjectId
fromHexString
(byte[] bs, int ptr, int end) static final AbbreviatedLongObjectId
Convert an AbbreviatedObjectId from anAnyObjectId
.static final AbbreviatedLongObjectId
fromString
(byte[] buf, int offset, int end) Convert an AbbreviatedObjectId from hex characters (US-ASCII).static final AbbreviatedLongObjectId
fromString
(String str) Convert an AbbreviatedLongObjectId from hex characters.final int
Get the first byte of this idint
hashCode()
private static final long
hexUInt64
(byte[] bs, int p, int end) boolean
Check if this id is completestatic final boolean
Test a string of characters to verify it is a hex format.int
length()
Get length(package private) static long
mask
(int nibbles, long word, long v) private long
mask
(long word, long v) final String
name()
name.final int
prefixCompare
(byte[] bs, int p) Compare this abbreviation to a network-byte-order LongObjectId.final int
prefixCompare
(long[] bs, int p) Compare this abbreviation to a network-byte-order LongObjectId.final int
prefixCompare
(AnyLongObjectId other) Compares this abbreviation to a full object id.Convert to LongObjectIdtoString()
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
nibbles
final int nibblesNumber of half-bytes used by this id. -
w1
final long w1 -
w2
final long w2 -
w3
final long w3 -
w4
final long w4
-
-
Constructor Details
-
AbbreviatedLongObjectId
AbbreviatedLongObjectId(int n, long new_1, long new_2, long new_3, long new_4)
-
-
Method Details
-
isId
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
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.
-
fromLongObjectId
Convert an AbbreviatedObjectId from anAnyObjectId
.This method copies over all bits of the Id, and is therefore complete (see
isComplete()
).- Parameters:
id
- theObjectId
to convert from.- Returns:
- the converted object id.
-
fromString
Convert an AbbreviatedLongObjectId from hex characters.- Parameters:
str
- the string to read from. Must be <= 64 characters.- Returns:
- the converted object id.
-
fromHexString
-
hexUInt64
private static final long hexUInt64(byte[] bs, int p, int end) -
mask
static long mask(int nibbles, long word, long v) -
length
public int length()Get length- Returns:
- number of hex digits appearing in this id.
-
isComplete
public boolean isComplete()Check if this id is complete- Returns:
- true if this ObjectId is actually a complete id.
-
toLongObjectId
Convert to LongObjectId- Returns:
- a complete ObjectId; null if
isComplete()
is false.
-
prefixCompare
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 firstlength()
digits ofother.name()
; >0 if this abbreviation names an object that is afterother
.
-
prefixCompare
public final int prefixCompare(byte[] bs, int p) Compare this abbreviation to a network-byte-order LongObjectId.- Parameters:
bs
- array containing the other LongObjectId in network byte order.p
- position withinbs
to start the compare at. At least 32 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 firstlength()
digits ofother.name()
; >0 if this abbreviation names an object that is afterother
.
-
prefixCompare
public final int prefixCompare(long[] bs, int p) Compare this abbreviation to a network-byte-order LongObjectId.- Parameters:
bs
- array containing the other LongObjectId in network byte order.p
- position withinbs
to start the compare at. At least 4 longs, 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 firstlength()
digits ofother.name()
; >0 if this abbreviation names an object that is afterother
.
-
getFirstByte
public final int getFirstByte()Get the first byte of this id- Returns:
- value for a fan-out style map, only valid of length >= 2.
-
mask
private long mask(long word, long v) -
hashCode
public int hashCode() -
equals
-
name
name.
- Returns:
- string form of the abbreviation, in lower case hexadecimal.
-
toString
-