[vcs-log] remove "reindex with renames" logic

Since file history can now use "follow" to find renames not available in the index, there is no need to reindex commits with bigger diff.renameLimit.

GitOrigin-RevId: 43e98588436555038e0cb346eb22a6250f034c9f
This commit is contained in:
Julia Beliaeva
2019-05-29 02:13:53 +03:00
committed by intellij-monorepo-bot
parent 80a630296c
commit ba0ae28e16
7 changed files with 19 additions and 101 deletions
@@ -45,10 +45,6 @@ public class EmptyIndex implements VcsLogModifiableIndex {
public void markForIndexing(int commit, @NotNull VirtualFile root) {
}
@Override
public void reindexWithRenames(int commit, @NotNull VirtualFile root) {
}
@Nullable
@Override
public IndexDataGetter getDataGetter() {
@@ -12,7 +12,5 @@ public interface VcsLogModifiableIndex extends VcsLogIndex {
void markForIndexing(int commit, @NotNull VirtualFile root);
void reindexWithRenames(int commit, @NotNull VirtualFile root);
void markCorrupted();
}
@@ -172,7 +172,7 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable
continue;
}
requestConsumer.consume(new IndexingRequest(root, myIndexStorage.paths.getPathsEncoder(), commits, isFull, false));
requestConsumer.consume(new IndexingRequest(root, myIndexStorage.paths.getPathsEncoder(), commits, isFull));
}
if (isFull) {
@@ -192,9 +192,6 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable
myIndexStorage.paths.update(index, detail);
myIndexStorage.parents.put(index, ContainerUtil.map(detail.getParents(), p -> myStorage.getCommitIndex(p, detail.getRoot())));
// we know the whole graph without timestamps now
if (detail.hasRenames()) {
myIndexStorage.renames.put(index);
}
if (!detail.getAuthor().equals(detail.getCommitter())) {
myIndexStorage.committers.put(index, myIndexStorage.users.getUserId(detail.getCommitter()));
}
@@ -215,7 +212,6 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable
myIndexStorage.users.flush();
myIndexStorage.paths.flush();
myIndexStorage.parents.force();
myIndexStorage.renames.flush();
myIndexStorage.commits.flush();
myIndexStorage.committers.force();
myIndexStorage.timestamps.force();
@@ -241,17 +237,7 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable
}
return false;
}
private boolean hasRenames(int commit) {
try {
return myIndexStorage == null || myIndexStorage.renames.contains(commit);
}
catch (IOException e) {
myFatalErrorsConsumer.consume(this, e);
}
return false;
}
@Override
public synchronized boolean isIndexed(@NotNull VirtualFile root) {
return isIndexingEnabled(root) &&
@@ -270,14 +256,6 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable
TroveUtil.add(myCommitsToIndex, root, index);
}
@Override
public synchronized void reindexWithRenames(int commit, @NotNull VirtualFile root) {
LOG.assertTrue(myRoots.contains(root));
if (hasRenames(commit) || myIndexStorage == null) return;
mySingleTaskController.request(new IndexingRequest(root, myIndexStorage.paths.getPathsEncoder(),
TroveUtil.singleton(commit), false, true));
}
@Nullable
@Override
public IndexDataGetter getDataGetter() {
@@ -321,14 +299,12 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable
private static final String COMMITS = "commits";
private static final String MESSAGES = "messages";
private static final String PARENTS = "parents";
private static final String RENAMES = "renames";
private static final String COMMITTERS = "committers";
private static final String TIMESTAMPS = "timestamps";
private static final int MESSAGES_VERSION = 0;
@NotNull public final PersistentSet<Integer> commits;
@NotNull public final PersistentMap<Integer, String> messages;
@NotNull public final PersistentMap<Integer, List<Integer>> parents;
@NotNull public final PersistentSet<Integer> renames;
@NotNull public final PersistentMap<Integer, Integer> committers;
@NotNull public final PersistentMap<Integer, Pair<Long, Long>> timestamps;
@NotNull public final VcsLogMessagesTrigramIndex trigrams;
@@ -369,11 +345,6 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable
new IntListDataExternalizer(), Page.PAGE_SIZE, storageId.getVersion());
Disposer.register(this, () -> catchAndWarn(parents::close));
File renamesStorage = storageId.getStorageFile(RENAMES);
renames = new PersistentSetImpl<>(renamesStorage, EnumeratorIntegerDescriptor.INSTANCE, Page.PAGE_SIZE, null,
storageId.getVersion());
Disposer.register(this, () -> catchAndWarn(renames::close));
File committersStorage = storageId.getStorageFile(COMMITTERS);
committers = new PersistentHashMap<>(committersStorage, EnumeratorIntegerDescriptor.INSTANCE, EnumeratorIntegerDescriptor.INSTANCE,
Page.PAGE_SIZE, storageId.getVersion());
@@ -489,7 +460,6 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable
@NotNull private final TIntHashSet myCommits;
@NotNull private final VcsLogIndexer.PathsEncoder myPathsEncoder;
private final boolean myFull;
private final boolean myReindex;
@NotNull private final AtomicInteger myNewIndexedCommits = new AtomicInteger();
@NotNull private final AtomicInteger myOldCommits = new AtomicInteger();
@@ -498,14 +468,11 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable
IndexingRequest(@NotNull VirtualFile root,
@NotNull VcsLogIndexer.PathsEncoder encoder,
@NotNull TIntHashSet commits,
boolean full,
boolean reindex) {
boolean full) {
myRoot = root;
myPathsEncoder = encoder;
myCommits = commits;
myFull = full;
myReindex = reindex;
LOG.assertTrue(!myFull || !myReindex);
}
public void run(@NotNull ProgressIndicator indicator) {
@@ -528,7 +495,7 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable
}
else {
IntStream commits = TroveUtil.stream(myCommits).filter(c -> {
if (myReindex ? hasRenames(c) : isIndexed(c)) {
if (isIndexed(c)) {
myOldCommits.incrementAndGet();
return false;
}
@@ -548,7 +515,7 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable
}
}
finally {
if (!myReindex) myNumberOfTasks.get(myRoot).decrementAndGet();
myNumberOfTasks.get(myRoot).decrementAndGet();
myIndexingTime.get(myRoot).updateAndGet(t -> t + (getCurrentTimeMillis() - myStartTime));
if (isIndexed(myRoot)) {
@@ -591,19 +558,11 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable
(myCommits.size() - myNewIndexedCommits.get() - myOldCommits.get()) +
" commits in " +
myRoot.getName());
if (myReindex) {
myCommits.forEach(value -> {
reindexWithRenames(value, myRoot);
return true;
});
}
else {
myCommits.forEach(value -> {
markForIndexing(value, myRoot);
return true;
});
scheduleIndex(false);
}
myCommits.forEach(value -> {
markForIndexing(value, myRoot);
return true;
});
scheduleIndex(false);
}
private void indexOneByOne(@NotNull IntStream commits, @NotNull ProgressIndicator indicator) throws VcsException {
@@ -619,7 +578,7 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable
myNewIndexedCommits.incrementAndGet();
checkRunningTooLong(indicator);
}, !myReindex);
});
displayProgress(indicator);
});
@@ -17,12 +17,10 @@ public interface VcsLogIndexer {
/**
* Reads full details for specified commits in the repository.
* Reports commits to the consumer to avoid creation & even temporary storage of a too large commits collection.
* Allows to skip full rename detection to make things faster. For git, for example, this would be adding diff.renameLimit=x to the command.
*/
void readFullDetails(@NotNull VirtualFile root, @NotNull List<String> hashes,
@NotNull VcsLogIndexer.PathsEncoder encoder,
@NotNull Consumer<? super CompressedDetails> commitConsumer,
boolean fast)
@NotNull Consumer<? super CompressedDetails> commitConsumer)
throws VcsException;
/**
@@ -42,8 +40,6 @@ public interface VcsLogIndexer {
@NotNull
TIntIntHashMap getRenamedPaths(int parent);
boolean hasRenames();
}
interface PathsEncoder {
@@ -3,7 +3,6 @@ package git4idea.history
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.registry.Registry
import com.intellij.openapi.vcs.changes.Change
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.PathUtil
@@ -13,7 +12,6 @@ import git4idea.log.GitCompressedDetails
import gnu.trove.TIntHashSet
import gnu.trove.TIntIntHashMap
import gnu.trove.TIntObjectHashMap
import kotlin.math.max
internal class GitCompressedDetailsCollector(project: Project, root: VirtualFile, pathsEncoder: VcsLogIndexer.PathsEncoder) :
GitDetailsCollector<GitCompressedRecord, GitCompressedDetails>(project, root, CompressedRecordBuilder(root, pathsEncoder)) {
@@ -21,17 +19,8 @@ internal class GitCompressedDetailsCollector(project: Project, root: VirtualFile
override fun createCommit(records: List<GitCompressedRecord>,
factory: VcsLogObjectsFactory,
renameLimit: GitCommitRequirements.DiffRenameLimit): GitCompressedDetails {
val hasRenames = when (renameLimit) {
GitCommitRequirements.DiffRenameLimit.INFINITY -> true
GitCommitRequirements.DiffRenameLimit.GIT_CONFIG -> false // need to know the value from git.config to give correct answer
GitCommitRequirements.DiffRenameLimit.NO_RENAMES -> false
GitCommitRequirements.DiffRenameLimit.REGISTRY -> {
val renameLimitEstimate = records.map { it.renameLimitEstimate }.max() ?: 0
renameLimitEstimate <= Registry.intValue("git.diff.renameLimit")
}
}
val metadata = GitLogUtil.createMetadata(root, records.first(), factory)
return GitCompressedDetails(metadata, records.map { it.changes }, records.map { it.renames }, hasRenames)
return GitCompressedDetails(metadata, records.map { it.changes }, records.map { it.renames })
}
override fun createRecordsCollector(consumer: (List<GitCompressedRecord>) -> Unit): GitLogRecordCollector<GitCompressedRecord> {
@@ -45,9 +34,6 @@ internal class CompressedRecordBuilder(root: VirtualFile,
private var changes = TIntObjectHashMap<Change.Type>()
private var parents = TIntHashSet()
private var renames = TIntIntHashMap()
private var sourcesCount = 0
private var targetsCount = 0
override fun addPath(type: Change.Type, firstPath: String, secondPath: String?) {
if (secondPath != null) {
@@ -64,12 +50,6 @@ internal class CompressedRecordBuilder(root: VirtualFile,
val pathId = pathsEncoder.encode(absolutePath, false)
addPath(absolutePath, pathId, type)
}
when (type) {
Change.Type.NEW -> targetsCount++
Change.Type.DELETED -> sourcesCount++
else -> {
}
}
}
private fun addPath(absolutePath: String, pathId: Int, type: Change.Type) {
@@ -98,20 +78,17 @@ internal class CompressedRecordBuilder(root: VirtualFile,
changes.put(it, Change.Type.MODIFICATION)
true
}
return GitCompressedRecord(options, changes, renames, max(sourcesCount, targetsCount), supportsRawBody)
return GitCompressedRecord(options, changes, renames, supportsRawBody)
}
override fun clear() {
changes = TIntObjectHashMap()
parents = TIntHashSet()
renames = TIntIntHashMap()
sourcesCount = 0
targetsCount = 0
}
}
internal class GitCompressedRecord(options: MutableMap<GitLogParser.GitLogOption, String>,
val changes: TIntObjectHashMap<Change.Type>,
val renames: TIntIntHashMap,
val renameLimitEstimate: Int,
supportsRawBody: Boolean) : GitLogRecord(options, supportsRawBody)
@@ -75,7 +75,7 @@ class GitLogUnorderedRecordCollector extends GitLogRecordCollector<GitCompressed
@Override
protected GitCompressedRecord createEmptyCopy(@NotNull GitCompressedRecord record) {
return new GitCompressedRecord(record.getOptions(), new TIntObjectHashMap<>(), new TIntIntHashMap(), 0, record.isSupportsRawBody());
return new GitCompressedRecord(record.getOptions(), new TIntObjectHashMap<>(), new TIntIntHashMap(), record.isSupportsRawBody());
}
@Override
@@ -42,16 +42,14 @@ class GitLogIndexer(private val project: Project,
override fun readFullDetails(root: VirtualFile,
hashes: List<String>,
encoder: VcsLogIndexer.PathsEncoder,
commitConsumer: Consumer<in VcsLogIndexer.CompressedDetails>,
fast: Boolean) {
commitConsumer: Consumer<in VcsLogIndexer.CompressedDetails>) {
if (!isRepositoryReady(repositoryManager, root)) {
return
}
val renameLimit = if (fast) DiffRenameLimit.REGISTRY else DiffRenameLimit.INFINITY
val requirements = GitCommitRequirements(shouldIncludeRootChanges(repositoryManager, root), renameLimit,
val requirements = GitCommitRequirements(shouldIncludeRootChanges(repositoryManager, root), DiffRenameLimit.REGISTRY,
DiffInMergeCommits.DIFF_TO_PARENTS)
GitCompressedDetailsCollector(project, root, encoder).readFullDetailsForHashes(hashes, requirements, fast, commitConsumer)
GitCompressedDetailsCollector(project, root, encoder).readFullDetailsForHashes(hashes, requirements, true, commitConsumer)
}
override fun getSupportedVcs(): VcsKey {
@@ -61,9 +59,7 @@ class GitLogIndexer(private val project: Project,
class GitCompressedDetails(private val metadata: VcsCommitMetadata,
private val changes: List<TIntObjectHashMap<Change.Type>>,
private val renames: List<TIntIntHashMap>,
private val hasRenames: Boolean) : VcsCommitMetadata by metadata,
VcsLogIndexer.CompressedDetails {
private val renames: List<TIntIntHashMap>) : VcsCommitMetadata by metadata, VcsLogIndexer.CompressedDetails {
override fun getModifiedPaths(parent: Int): TIntObjectHashMap<Change.Type> {
return changes[parent]
@@ -72,8 +68,4 @@ class GitCompressedDetails(private val metadata: VcsCommitMetadata,
override fun getRenamedPaths(parent: Int): TIntIntHashMap {
return renames[parent]
}
override fun hasRenames(): Boolean {
return hasRenames
}
}