summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYunjie Li <yunjieli@google.com>2020-04-22 13:17:47 -0700
committerYunjie Li <yunjieli@google.com>2020-05-12 17:32:15 -0700
commitb1d4b457081e7e31d292237991a4fe20e6d1b689 (patch)
treedc2a6d69b2d14694d8c2aaff927f44f1cf787c9d
parentd23254ee5751dd9dd154b338d73d5c23fffd1616 (diff)
downloadjgit-b1d4b457081e7e31d292237991a4fe20e6d1b689.tar.gz
jgit-b1d4b457081e7e31d292237991a4fe20e6d1b689.zip
PackBitmapIndex: Add util methods and builder to BitmapCommit
Add some utility methods and a builder class for BitmapCommit class in preparation for improving the memory footprint of GC's bitmap generation phase. Change-Id: Ice3d257fc26f3917a65a64eaf53b508b89043caa Signed-off-by: Yunjie Li <yunjieli@google.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/BitmapCommit.java128
1 files changed, 128 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/BitmapCommit.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/BitmapCommit.java
index cbf1ccfd94..33c478e4ab 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/BitmapCommit.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/BitmapCommit.java
@@ -16,13 +16,26 @@ import org.eclipse.jgit.lib.ObjectId;
* A commit object for which a bitmap index should be built.
*/
public final class BitmapCommit extends ObjectId {
+
private final boolean reuseWalker;
+
private final int flags;
+ private final boolean addToIndex;
+
BitmapCommit(AnyObjectId objectId, boolean reuseWalker, int flags) {
super(objectId);
this.reuseWalker = reuseWalker;
this.flags = flags;
+ this.addToIndex = false;
+ }
+
+ BitmapCommit(AnyObjectId objectId, boolean reuseWalker, int flags,
+ boolean addToIndex) {
+ super(objectId);
+ this.reuseWalker = reuseWalker;
+ this.flags = flags;
+ this.addToIndex = addToIndex;
}
boolean isReuseWalker() {
@@ -32,4 +45,119 @@ public final class BitmapCommit extends ObjectId {
int getFlags() {
return flags;
}
+
+ /**
+ * Whether corresponding bitmap should be added to PackBitmapIndexBuilder.
+ *
+ * @return true if the corresponding bitmap should be added to
+ * PackBitmapIndexBuilder.
+ */
+ public boolean isAddToIndex() {
+ return addToIndex;
+ }
+
+ /**
+ * Get a builder of BitmapCommit whose object id is {@code objId}.
+ *
+ * @param objId
+ * the object id of the BitmapCommit
+ * @return a BitmapCommit builder with object id set.
+ */
+ public static Builder newBuilder(AnyObjectId objId) {
+ return new Builder().setId(objId);
+ }
+
+ /**
+ * Get a builder of BitmapCommit whose fields are copied from
+ * {@code commit}.
+ *
+ * @param commit
+ * the bitmap commit the builder is copying from
+ * @return a BitmapCommit build with fields copied from an existing bitmap
+ * commit.
+ */
+ public static Builder copyFrom(BitmapCommit commit) {
+ return new Builder().setId(commit)
+ .setReuseWalker(commit.isReuseWalker())
+ .setFlags(commit.getFlags())
+ .setAddToIndex(commit.isAddToIndex());
+ }
+
+ /**
+ * Builder of BitmapCommit.
+ */
+ public static class Builder {
+ private AnyObjectId objectId;
+
+ private boolean reuseWalker;
+
+ private int flags;
+
+ private boolean addToIndex;
+
+ // Prevent default constructor.
+ private Builder() {
+ }
+
+ /**
+ * Set objectId of the builder.
+ *
+ * @param objectId
+ * the object id of the BitmapCommit
+ * @return the builder itself
+ */
+ public Builder setId(AnyObjectId objectId) {
+ this.objectId = objectId;
+ return this;
+ }
+
+ /**
+ * Set reuseWalker of the builder.
+ *
+ * @param reuseWalker
+ * whether the BitmapCommit should reuse bitmap walker when
+ * walking objects
+ * @return the builder itself
+ */
+ public Builder setReuseWalker(boolean reuseWalker) {
+ this.reuseWalker = reuseWalker;
+ return this;
+ }
+
+ /**
+ * Set flags of the builder.
+ *
+ * @param flags
+ * the flags of the BitmapCommit
+ * @return the builder itself
+ */
+ public Builder setFlags(int flags) {
+ this.flags = flags;
+ return this;
+ }
+
+ /**
+ * Set whether whether the bitmap of the BitmapCommit should be added to
+ * PackBitmapIndexBuilder when building bitmap index file.
+ *
+ * @param addToIndex
+ * whether the bitmap of the BitmapCommit should be added to
+ * PackBitmapIndexBuilder when building bitmap index file
+ * @return the builder itself
+ */
+ public Builder setAddToIndex(boolean addToIndex) {
+ this.addToIndex = addToIndex;
+ return this;
+ }
+
+ /**
+ * Builds BitmapCommit from the builder.
+ *
+ * @return the new BitmapCommit.
+ */
+ public BitmapCommit build() {
+ return new BitmapCommit(objectId, reuseWalker, flags,
+ addToIndex);
+ }
+ }
} \ No newline at end of file