Browse Source
* changes: PackBitmapIndex: Set distance threshold PackBitmapIndex: Not buffer inflated bitmap in BasePackBitmapIndex PackBitmapIndex: Remove convertedBitmaps in the Remapper PackBitmapIndex: Reduce memory usage in GC PackBitmapIndex: Add AddToBitmapWithCacheFilter class PackBitmapIndex: Add util methods and builder to BitmapCommit PackBitmapIndex: Move BitmapCommit to a top-level class Refactor: Make retriveCompressed an method of the Bitmap classmaster
Terry Parker
5 years ago
committed by
Gerrit Code Review @ Eclipse.org
11 changed files with 408 additions and 116 deletions
@ -0,0 +1,91 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2020, Google LLC and others |
||||||
|
* |
||||||
|
* This program and the accompanying materials are made available under the |
||||||
|
* terms of the Eclipse Distribution License v. 1.0 which is available at |
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
* |
||||||
|
* SPDX-License-Identifier: BSD-3-Clause |
||||||
|
*/ |
||||||
|
package org.eclipse.jgit.internal.revwalk; |
||||||
|
|
||||||
|
import org.eclipse.jgit.lib.BitmapIndex.Bitmap; |
||||||
|
import org.eclipse.jgit.lib.BitmapIndex.BitmapBuilder; |
||||||
|
import org.eclipse.jgit.lib.Constants; |
||||||
|
import org.eclipse.jgit.lib.AnyObjectId; |
||||||
|
import org.eclipse.jgit.revwalk.filter.RevFilter; |
||||||
|
import org.eclipse.jgit.revwalk.RevWalk; |
||||||
|
import org.eclipse.jgit.revwalk.RevCommit; |
||||||
|
import org.eclipse.jgit.revwalk.RevFlag; |
||||||
|
|
||||||
|
/** |
||||||
|
* A RevFilter that adds the visited commits to {@code bitmap} as a side effect. |
||||||
|
* <p> |
||||||
|
* When the walk hits a commit that is the same as {@code cachedCommit} or is |
||||||
|
* part of {@code bitmap}'s BitmapIndex, that entire bitmap is ORed into |
||||||
|
* {@code bitmap} and the commit and its parents are marked as SEEN so that the |
||||||
|
* walk does not have to visit its ancestors. This ensures the walk is very |
||||||
|
* short if there is good bitmap coverage. |
||||||
|
*/ |
||||||
|
public class AddToBitmapWithCacheFilter extends RevFilter { |
||||||
|
private final AnyObjectId cachedCommit; |
||||||
|
|
||||||
|
private final Bitmap cachedBitmap; |
||||||
|
|
||||||
|
private final BitmapBuilder bitmap; |
||||||
|
|
||||||
|
/** |
||||||
|
* Create a filter with a cached BitmapCommit that adds visited commits to |
||||||
|
* the given bitmap. |
||||||
|
* |
||||||
|
* @param cachedCommit |
||||||
|
* the cached commit |
||||||
|
* @param cachedBitmap |
||||||
|
* the bitmap corresponds to {@code cachedCommit}} |
||||||
|
* @param bitmap |
||||||
|
* bitmap to write visited commits to |
||||||
|
*/ |
||||||
|
public AddToBitmapWithCacheFilter(AnyObjectId cachedCommit, |
||||||
|
Bitmap cachedBitmap, |
||||||
|
BitmapBuilder bitmap) { |
||||||
|
this.cachedCommit = cachedCommit; |
||||||
|
this.cachedBitmap = cachedBitmap; |
||||||
|
this.bitmap = bitmap; |
||||||
|
} |
||||||
|
|
||||||
|
/** {@inheritDoc} */ |
||||||
|
@Override |
||||||
|
public final boolean include(RevWalk rw, RevCommit c) { |
||||||
|
Bitmap visitedBitmap; |
||||||
|
|
||||||
|
if (bitmap.contains(c)) { |
||||||
|
// already included
|
||||||
|
} else if ((visitedBitmap = bitmap.getBitmapIndex() |
||||||
|
.getBitmap(c)) != null) { |
||||||
|
bitmap.or(visitedBitmap); |
||||||
|
} else if (cachedCommit.equals(c)) { |
||||||
|
bitmap.or(cachedBitmap); |
||||||
|
} else { |
||||||
|
bitmap.addObject(c, Constants.OBJ_COMMIT); |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
for (RevCommit p : c.getParents()) { |
||||||
|
p.add(RevFlag.SEEN); |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** {@inheritDoc} */ |
||||||
|
@Override |
||||||
|
public final RevFilter clone() { |
||||||
|
throw new UnsupportedOperationException(); |
||||||
|
} |
||||||
|
|
||||||
|
/** {@inheritDoc} */ |
||||||
|
@Override |
||||||
|
public final boolean requiresCommitBody() { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
@ -0,0 +1,163 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2020, Google LLC and others |
||||||
|
* |
||||||
|
* This program and the accompanying materials are made available under the |
||||||
|
* terms of the Eclipse Distribution License v. 1.0 which is available at |
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
* |
||||||
|
* SPDX-License-Identifier: BSD-3-Clause |
||||||
|
*/ |
||||||
|
package org.eclipse.jgit.internal.storage.pack; |
||||||
|
|
||||||
|
import org.eclipse.jgit.lib.AnyObjectId; |
||||||
|
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() { |
||||||
|
return reuseWalker; |
||||||
|
} |
||||||
|
|
||||||
|
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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue