RevCommitCG: Read changed-path-filters directly from commit graph
RevCommit and RevCommitCG were designed like "pointers" to data that load the content on demand, not on construction. This saves memory. Make the loading of changed-path-filter follow the same pattern. The ChangedPathFilters are only pointers to locations in the commit-graph (not the actual data), so the memory saving is not that big, but this is more consistent with the rest of the API. As 6.7 is not released, we can still change the RevWalk API. Change-Id: Id4186ea744b8a2418d0329facae69f785108d356
This commit is contained in:
parent
eecd93714b
commit
c8f5a3f99d
|
@ -48,6 +48,7 @@
|
||||||
import org.eclipse.jgit.lib.ObjectReader;
|
import org.eclipse.jgit.lib.ObjectReader;
|
||||||
import org.eclipse.jgit.lib.ProgressMonitor;
|
import org.eclipse.jgit.lib.ProgressMonitor;
|
||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
|
import org.eclipse.jgit.revwalk.RevWalk;
|
||||||
import org.eclipse.jgit.treewalk.EmptyTreeIterator;
|
import org.eclipse.jgit.treewalk.EmptyTreeIterator;
|
||||||
import org.eclipse.jgit.treewalk.TreeWalk;
|
import org.eclipse.jgit.treewalk.TreeWalk;
|
||||||
import org.eclipse.jgit.util.NB;
|
import org.eclipse.jgit.util.NB;
|
||||||
|
@ -405,25 +406,27 @@ private BloomFilterChunks computeBloomFilterChunks(Stats stats)
|
||||||
data.write(scratch);
|
data.write(scratch);
|
||||||
int dataHeaderSize = data.size();
|
int dataHeaderSize = data.size();
|
||||||
|
|
||||||
for (RevCommit cmit : graphCommits) {
|
try (RevWalk rw = new RevWalk(graphCommits.getObjectReader())) {
|
||||||
ChangedPathFilter cpf = cmit.getChangedPathFilter();
|
for (RevCommit cmit : graphCommits) {
|
||||||
if (cpf != null) {
|
ChangedPathFilter cpf = cmit.getChangedPathFilter(rw);
|
||||||
stats.changedPathFiltersReused++;
|
if (cpf != null) {
|
||||||
} else {
|
stats.changedPathFiltersReused++;
|
||||||
stats.changedPathFiltersComputed++;
|
|
||||||
Optional<HashSet<ByteBuffer>> paths = computeBloomFilterPaths(
|
|
||||||
graphCommits.getObjectReader(), cmit);
|
|
||||||
if (paths.isEmpty()) {
|
|
||||||
cpf = ChangedPathFilter.FULL;
|
|
||||||
} else {
|
} else {
|
||||||
cpf = ChangedPathFilter.fromPaths(paths.get());
|
stats.changedPathFiltersComputed++;
|
||||||
|
Optional<HashSet<ByteBuffer>> paths = computeBloomFilterPaths(
|
||||||
|
graphCommits.getObjectReader(), cmit);
|
||||||
|
if (paths.isEmpty()) {
|
||||||
|
cpf = ChangedPathFilter.FULL;
|
||||||
|
} else {
|
||||||
|
cpf = ChangedPathFilter.fromPaths(paths.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
cpf.writeTo(data);
|
||||||
|
NB.encodeInt32(scratch, 0, data.size() - dataHeaderSize);
|
||||||
|
index.write(scratch);
|
||||||
}
|
}
|
||||||
cpf.writeTo(data);
|
return new BloomFilterChunks(index, data);
|
||||||
NB.encodeInt32(scratch, 0, data.size() - dataHeaderSize);
|
|
||||||
index.write(scratch);
|
|
||||||
}
|
}
|
||||||
return new BloomFilterChunks(index, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeExtraEdges(CancellableDigestOutputStream out)
|
private void writeExtraEdges(CancellableDigestOutputStream out)
|
||||||
|
|
|
@ -694,10 +694,11 @@ int getGeneration() {
|
||||||
* commit graph file, or the commit graph file was generated without changed
|
* commit graph file, or the commit graph file was generated without changed
|
||||||
* path filters.
|
* path filters.
|
||||||
*
|
*
|
||||||
|
* @param rw A revwalk to load the commit graph (if available)
|
||||||
* @return the changed path filter
|
* @return the changed path filter
|
||||||
* @since 6.7
|
* @since 6.7
|
||||||
*/
|
*/
|
||||||
public ChangedPathFilter getChangedPathFilter() {
|
public ChangedPathFilter getChangedPathFilter(RevWalk rw) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,6 @@ class RevCommitCG extends RevCommit {
|
||||||
|
|
||||||
private final int graphPosition;
|
private final int graphPosition;
|
||||||
|
|
||||||
private final ChangedPathFilter changedPathFilter;
|
|
||||||
|
|
||||||
private int generation = Constants.COMMIT_GENERATION_UNKNOWN;
|
private int generation = Constants.COMMIT_GENERATION_UNKNOWN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,14 +39,10 @@ class RevCommitCG extends RevCommit {
|
||||||
* object name for the commit.
|
* object name for the commit.
|
||||||
* @param graphPosition
|
* @param graphPosition
|
||||||
* the position in the commit-graph of the object.
|
* the position in the commit-graph of the object.
|
||||||
* @param changedPathFilter
|
|
||||||
* the changed path filter if one exists
|
|
||||||
*/
|
*/
|
||||||
protected RevCommitCG(AnyObjectId id, int graphPosition,
|
protected RevCommitCG(AnyObjectId id, int graphPosition) {
|
||||||
ChangedPathFilter changedPathFilter) {
|
|
||||||
super(id);
|
super(id);
|
||||||
this.graphPosition = graphPosition;
|
this.graphPosition = graphPosition;
|
||||||
this.changedPathFilter = changedPathFilter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -110,7 +104,7 @@ int getGeneration() {
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public ChangedPathFilter getChangedPathFilter() {
|
public ChangedPathFilter getChangedPathFilter(RevWalk rw) {
|
||||||
return changedPathFilter;
|
return rw.commitGraph().getChangedPathFilter(graphPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1713,8 +1713,7 @@ protected RevCommit createCommit(AnyObjectId id) {
|
||||||
|
|
||||||
private RevCommit createCommit(AnyObjectId id, int graphPos) {
|
private RevCommit createCommit(AnyObjectId id, int graphPos) {
|
||||||
if (graphPos >= 0) {
|
if (graphPos >= 0) {
|
||||||
return new RevCommitCG(id, graphPos,
|
return new RevCommitCG(id, graphPos);
|
||||||
commitGraph().getChangedPathFilter(graphPos));
|
|
||||||
}
|
}
|
||||||
return new RevCommit(id);
|
return new RevCommit(id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ public boolean include(RevWalk walker, RevCommit c)
|
||||||
int chgs = 0, adds = 0;
|
int chgs = 0, adds = 0;
|
||||||
boolean changedPathFilterUsed = false;
|
boolean changedPathFilterUsed = false;
|
||||||
boolean mustCalculateChgs = true;
|
boolean mustCalculateChgs = true;
|
||||||
ChangedPathFilter cpf = c.getChangedPathFilter();
|
ChangedPathFilter cpf = c.getChangedPathFilter(walker);
|
||||||
if (cpf != null) {
|
if (cpf != null) {
|
||||||
Optional<Set<byte[]>> paths = pathFilter.getFilter()
|
Optional<Set<byte[]>> paths = pathFilter.getFilter()
|
||||||
.getPathsBestEffort();
|
.getPathsBestEffort();
|
||||||
|
|
Loading…
Reference in New Issue