Make lookup methods on PackIndex public
There isn't a good reason to hide all of these as package-private. Make them public so applications can inspect pack files. Change-Id: Ia418daf65d63e9e015b8dafdf3d06a1ed91d190b
This commit is contained in:
parent
38c5b26245
commit
d60cb2a3f5
|
@ -183,7 +183,7 @@ public boolean hasObject(final AnyObjectId id) {
|
||||||
* @return number of objects in this index, and likewise in the associated
|
* @return number of objects in this index, and likewise in the associated
|
||||||
* pack that this index was generated from.
|
* pack that this index was generated from.
|
||||||
*/
|
*/
|
||||||
abstract long getObjectCount();
|
public abstract long getObjectCount();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain the total number of objects needing 64 bit offsets.
|
* Obtain the total number of objects needing 64 bit offsets.
|
||||||
|
@ -191,7 +191,7 @@ public boolean hasObject(final AnyObjectId id) {
|
||||||
* @return number of objects in this index using a 64 bit offset; that is an
|
* @return number of objects in this index using a 64 bit offset; that is an
|
||||||
* object positioned after the 2 GB position within the file.
|
* object positioned after the 2 GB position within the file.
|
||||||
*/
|
*/
|
||||||
abstract long getOffset64Count();
|
public abstract long getOffset64Count();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get ObjectId for the n-th object entry returned by {@link #iterator()}.
|
* Get ObjectId for the n-th object entry returned by {@link #iterator()}.
|
||||||
|
@ -212,7 +212,7 @@ public boolean hasObject(final AnyObjectId id) {
|
||||||
* {@link MutableEntry} is 0, the second is 1, etc.
|
* {@link MutableEntry} is 0, the second is 1, etc.
|
||||||
* @return the ObjectId for the corresponding entry.
|
* @return the ObjectId for the corresponding entry.
|
||||||
*/
|
*/
|
||||||
abstract ObjectId getObjectId(long nthPosition);
|
public abstract ObjectId getObjectId(long nthPosition);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get ObjectId for the n-th object entry returned by {@link #iterator()}.
|
* Get ObjectId for the n-th object entry returned by {@link #iterator()}.
|
||||||
|
@ -234,7 +234,7 @@ public boolean hasObject(final AnyObjectId id) {
|
||||||
* etc. Positions past 2**31-1 are negative, but still valid.
|
* etc. Positions past 2**31-1 are negative, but still valid.
|
||||||
* @return the ObjectId for the corresponding entry.
|
* @return the ObjectId for the corresponding entry.
|
||||||
*/
|
*/
|
||||||
final ObjectId getObjectId(final int nthPosition) {
|
public final ObjectId getObjectId(final int nthPosition) {
|
||||||
if (nthPosition >= 0)
|
if (nthPosition >= 0)
|
||||||
return getObjectId((long) nthPosition);
|
return getObjectId((long) nthPosition);
|
||||||
final int u31 = nthPosition >>> 1;
|
final int u31 = nthPosition >>> 1;
|
||||||
|
@ -251,7 +251,7 @@ final ObjectId getObjectId(final int nthPosition) {
|
||||||
* object does not exist in this index and is thus not stored in the
|
* object does not exist in this index and is thus not stored in the
|
||||||
* associated pack.
|
* associated pack.
|
||||||
*/
|
*/
|
||||||
abstract long findOffset(AnyObjectId objId);
|
public abstract long findOffset(AnyObjectId objId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve stored CRC32 checksum of the requested object raw-data
|
* Retrieve stored CRC32 checksum of the requested object raw-data
|
||||||
|
@ -265,17 +265,31 @@ final ObjectId getObjectId(final int nthPosition) {
|
||||||
* @throws UnsupportedOperationException
|
* @throws UnsupportedOperationException
|
||||||
* when this index doesn't support CRC32 checksum
|
* when this index doesn't support CRC32 checksum
|
||||||
*/
|
*/
|
||||||
abstract long findCRC32(AnyObjectId objId) throws MissingObjectException,
|
public abstract long findCRC32(AnyObjectId objId)
|
||||||
UnsupportedOperationException;
|
throws MissingObjectException, UnsupportedOperationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether this index supports (has) CRC32 checksums for objects.
|
* Check whether this index supports (has) CRC32 checksums for objects.
|
||||||
*
|
*
|
||||||
* @return true if CRC32 is stored, false otherwise
|
* @return true if CRC32 is stored, false otherwise
|
||||||
*/
|
*/
|
||||||
abstract boolean hasCRC32Support();
|
public abstract boolean hasCRC32Support();
|
||||||
|
|
||||||
abstract void resolve(Set<ObjectId> matches, AbbreviatedObjectId id,
|
/**
|
||||||
|
* Find objects matching the prefix abbreviation.
|
||||||
|
*
|
||||||
|
* @param matches
|
||||||
|
* set to add any located ObjectIds to. This is an output
|
||||||
|
* parameter.
|
||||||
|
* @param id
|
||||||
|
* prefix to search for.
|
||||||
|
* @param matchLimit
|
||||||
|
* maximum number of results to return. At most this many
|
||||||
|
* ObjectIds should be added to matches before returning.
|
||||||
|
* @throws IOException
|
||||||
|
* the index cannot be read.
|
||||||
|
*/
|
||||||
|
public abstract void resolve(Set<ObjectId> matches, AbbreviatedObjectId id,
|
||||||
int matchLimit) throws IOException;
|
int matchLimit) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -98,12 +98,13 @@ class PackIndexV1 extends PackIndex {
|
||||||
IO.readFully(fd, packChecksum, 0, packChecksum.length);
|
IO.readFully(fd, packChecksum, 0, packChecksum.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
long getObjectCount() {
|
@Override
|
||||||
|
public long getObjectCount() {
|
||||||
return objectCnt;
|
return objectCnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
long getOffset64Count() {
|
public long getOffset64Count() {
|
||||||
long n64 = 0;
|
long n64 = 0;
|
||||||
for (final MutableEntry e : this) {
|
for (final MutableEntry e : this) {
|
||||||
if (e.getOffset() >= Integer.MAX_VALUE)
|
if (e.getOffset() >= Integer.MAX_VALUE)
|
||||||
|
@ -113,7 +114,7 @@ long getOffset64Count() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
ObjectId getObjectId(final long nthPosition) {
|
public ObjectId getObjectId(final long nthPosition) {
|
||||||
int levelOne = Arrays.binarySearch(idxHeader, nthPosition + 1);
|
int levelOne = Arrays.binarySearch(idxHeader, nthPosition + 1);
|
||||||
long base;
|
long base;
|
||||||
if (levelOne >= 0) {
|
if (levelOne >= 0) {
|
||||||
|
@ -135,7 +136,8 @@ ObjectId getObjectId(final long nthPosition) {
|
||||||
return ObjectId.fromRaw(idxdata[levelOne], dataIdx);
|
return ObjectId.fromRaw(idxdata[levelOne], dataIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
long findOffset(final AnyObjectId objId) {
|
@Override
|
||||||
|
public long findOffset(final AnyObjectId objId) {
|
||||||
final int levelOne = objId.getFirstByte();
|
final int levelOne = objId.getFirstByte();
|
||||||
byte[] data = idxdata[levelOne];
|
byte[] data = idxdata[levelOne];
|
||||||
if (data == null)
|
if (data == null)
|
||||||
|
@ -161,22 +163,23 @@ else if (cmp == 0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
long findCRC32(AnyObjectId objId) {
|
public long findCRC32(AnyObjectId objId) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean hasCRC32Support() {
|
public boolean hasCRC32Support() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterator<MutableEntry> iterator() {
|
public Iterator<MutableEntry> iterator() {
|
||||||
return new IndexV1Iterator();
|
return new IndexV1Iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void resolve(Set<ObjectId> matches, AbbreviatedObjectId id, int matchLimit)
|
public void resolve(Set<ObjectId> matches, AbbreviatedObjectId id,
|
||||||
throws IOException {
|
int matchLimit) throws IOException {
|
||||||
byte[] data = idxdata[id.getFirstByte()];
|
byte[] data = idxdata[id.getFirstByte()];
|
||||||
if (data == null)
|
if (data == null)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -161,17 +161,17 @@ class PackIndexV2 extends PackIndex {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
long getObjectCount() {
|
public long getObjectCount() {
|
||||||
return objectCnt;
|
return objectCnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
long getOffset64Count() {
|
public long getOffset64Count() {
|
||||||
return offset64.length / 8;
|
return offset64.length / 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
ObjectId getObjectId(final long nthPosition) {
|
public ObjectId getObjectId(final long nthPosition) {
|
||||||
int levelOne = Arrays.binarySearch(fanoutTable, nthPosition + 1);
|
int levelOne = Arrays.binarySearch(fanoutTable, nthPosition + 1);
|
||||||
long base;
|
long base;
|
||||||
if (levelOne >= 0) {
|
if (levelOne >= 0) {
|
||||||
|
@ -194,7 +194,7 @@ ObjectId getObjectId(final long nthPosition) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
long findOffset(final AnyObjectId objId) {
|
public long findOffset(final AnyObjectId objId) {
|
||||||
final int levelOne = objId.getFirstByte();
|
final int levelOne = objId.getFirstByte();
|
||||||
final int levelTwo = binarySearchLevelTwo(objId, levelOne);
|
final int levelTwo = binarySearchLevelTwo(objId, levelOne);
|
||||||
if (levelTwo == -1)
|
if (levelTwo == -1)
|
||||||
|
@ -206,7 +206,7 @@ long findOffset(final AnyObjectId objId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
long findCRC32(AnyObjectId objId) throws MissingObjectException {
|
public long findCRC32(AnyObjectId objId) throws MissingObjectException {
|
||||||
final int levelOne = objId.getFirstByte();
|
final int levelOne = objId.getFirstByte();
|
||||||
final int levelTwo = binarySearchLevelTwo(objId, levelOne);
|
final int levelTwo = binarySearchLevelTwo(objId, levelOne);
|
||||||
if (levelTwo == -1)
|
if (levelTwo == -1)
|
||||||
|
@ -215,17 +215,18 @@ long findCRC32(AnyObjectId objId) throws MissingObjectException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean hasCRC32Support() {
|
public boolean hasCRC32Support() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterator<MutableEntry> iterator() {
|
public Iterator<MutableEntry> iterator() {
|
||||||
return new EntriesIteratorV2();
|
return new EntriesIteratorV2();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void resolve(Set<ObjectId> matches, AbbreviatedObjectId id, int matchLimit)
|
public void resolve(Set<ObjectId> matches, AbbreviatedObjectId id,
|
||||||
throws IOException {
|
int matchLimit) throws IOException {
|
||||||
int[] data = names[id.getFirstByte()];
|
int[] data = names[id.getFirstByte()];
|
||||||
int max = offset32[id.getFirstByte()].length >>> 2;
|
int max = offset32[id.getFirstByte()].length >>> 2;
|
||||||
int high = max;
|
int high = max;
|
||||||
|
|
Loading…
Reference in New Issue