diff options
author | Ivan Frade <ifrade@google.com> | 2025-01-30 13:38:02 -0800 |
---|---|---|
committer | Ivan Frade <ifrade@google.com> | 2025-02-03 12:01:34 -0800 |
commit | ccef9d428c219d92a6300ec91af4f8245dc32cd4 (patch) | |
tree | 7bb7f6caea74daeca005e382499417df4470cba3 /org.eclipse.jgit/src/org/eclipse/jgit | |
parent | 68b1a314beac30ffadc7b88a01ecbede6971d100 (diff) | |
download | jgit-ccef9d428c219d92a6300ec91af4f8245dc32cd4.tar.gz jgit-ccef9d428c219d92a6300ec91af4f8245dc32cd4.zip |
PackIndex.MutableEntry: new methods to copy its contents
To build the multipack index, we will iterate over N indexes merging
the results in sha1 order. With the current MutableEntry API, we need
to create an instance of ObjectId to either compare and/or copy the
selected entry to the multi index iterator.
Allow MutableEntries to compare to each other without creating any new
object, and copy their object id directly to another MutableObjectId.
This allows to build other iterators with mutable entries that copy
the required memory (few ints) instead of creating short-lived instances
of ObjectId.
Change-Id: I0c0091420d7c0847c03afdc9e73b566bb4eeba40
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java index 7189ce20a6..b3e4efb4fc 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java @@ -286,7 +286,7 @@ public interface PackIndex * the index cannot be read. */ void resolve(Set<ObjectId> matches, AbbreviatedObjectId id, - int matchLimit) throws IOException; + int matchLimit) throws IOException; /** * Get pack checksum @@ -304,6 +304,7 @@ public interface PackIndex class MutableEntry { /** Buffer of the ObjectId visited by the EntriesIterator. */ final MutableObjectId idBuffer = new MutableObjectId(); + /** Offset into the packfile of the current object. */ long offset; @@ -345,6 +346,34 @@ public interface PackIndex r.offset = offset; return r; } + + /** + * Similar to {@link Comparable#compareTo(Object)}, using only the + * object id in the entry. + * + * @param other + * Another mutable entry (probably from another index) + * + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified + * object. + */ + public int compareBySha1To(MutableEntry other) { + return idBuffer.compareTo(other.idBuffer); + } + + /** + * Copy the current ObjectId to dest + * <p> + * Like {@link #toObjectId()}, but reusing the destination instead of + * creating a new ObjectId instance. + * + * @param dest + * destination for the object id + */ + public void copyOidTo(MutableObjectId dest) { + dest.fromObjectId(idBuffer); + } } /** @@ -368,7 +397,6 @@ public interface PackIndex this.objectCount = objectCount; } - @Override public boolean hasNext() { return returnedNumber < objectCount; @@ -393,7 +421,6 @@ public interface PackIndex */ protected abstract void readNext(); - /** * Copies to the entry an {@link ObjectId} from the int buffer and * position idx @@ -423,7 +450,8 @@ public interface PackIndex /** * Sets the {@code offset} to the entry * - * @param offset the offset in the pack file + * @param offset + * the offset in the pack file */ protected void setOffset(long offset) { entry.offset = offset; |