[vcs-log] only work with VcsIndexableDetails in path index

This commit is contained in:
Julia Beliaeva
2018-08-09 19:05:54 +03:00
parent c54ec30987
commit 2c4f1f00ae
6 changed files with 25 additions and 37 deletions
@@ -39,18 +39,18 @@ import java.util.Set;
import java.util.function.BiPredicate;
import java.util.function.ObjIntConsumer;
public class VcsLogFullDetailsIndex<T> implements Disposable {
public class VcsLogFullDetailsIndex<T, D extends VcsFullCommitDetails> implements Disposable {
protected static final String INDEX = "index";
@NotNull protected final MyMapReduceIndex myMapReduceIndex;
@NotNull protected final StorageId myStorageId;
@NotNull protected final String myName;
@NotNull protected final DataIndexer<Integer, T, VcsFullCommitDetails> myIndexer;
@NotNull protected final DataIndexer<Integer, T, D> myIndexer;
@NotNull private final FatalErrorHandler myFatalErrorHandler;
private volatile boolean myDisposed = false;
public VcsLogFullDetailsIndex(@NotNull StorageId storageId,
@NotNull String name,
@NotNull DataIndexer<Integer, T, VcsFullCommitDetails> indexer,
@NotNull DataIndexer<Integer, T, D> indexer,
@NotNull DataExternalizer<T> externalizer,
@NotNull FatalErrorHandler fatalErrorHandler,
@NotNull Disposable disposableParent)
@@ -67,13 +67,13 @@ public class VcsLogFullDetailsIndex<T> implements Disposable {
@NotNull
private MyMapReduceIndex createMapReduceIndex(@NotNull DataExternalizer<T> dataExternalizer) throws IOException {
MyIndexExtension<T> extension = new MyIndexExtension<>(myName, myIndexer, dataExternalizer, myStorageId.getVersion());
MyIndexExtension<T, D> extension = new MyIndexExtension<>(myName, myIndexer, dataExternalizer, myStorageId.getVersion());
ForwardIndex<Integer, T> forwardIndex = createForwardIndex(extension);
return new MyMapReduceIndex(extension, new MyMapIndexStorage<>(myName, myStorageId, dataExternalizer), forwardIndex);
}
@NotNull
protected ForwardIndex<Integer, T> createForwardIndex(@NotNull IndexExtension<Integer, T, VcsFullCommitDetails> extension)
protected ForwardIndex<Integer, T> createForwardIndex(@NotNull IndexExtension<Integer, T, D> extension)
throws IOException {
return new EmptyForwardIndex<>();
}
@@ -126,7 +126,7 @@ public class VcsLogFullDetailsIndex<T> implements Disposable {
return index.getInput(commit);
}
public void update(int commitId, @NotNull VcsFullCommitDetails details) {
public void update(int commitId, @NotNull D details) {
checkDisposed();
myMapReduceIndex.update(commitId, details).compute();
}
@@ -146,8 +146,8 @@ public class VcsLogFullDetailsIndex<T> implements Disposable {
if (myDisposed) throw new ProcessCanceledException();
}
private class MyMapReduceIndex extends MapReduceIndex<Integer, T, VcsFullCommitDetails> {
public MyMapReduceIndex(@NotNull MyIndexExtension<T> extension,
private class MyMapReduceIndex extends MapReduceIndex<Integer, T, D> {
public MyMapReduceIndex(@NotNull MyIndexExtension<T, D> extension,
@NotNull MyMapIndexStorage<T> mapIndexStorage,
@NotNull ForwardIndex<Integer, T> forwardIndex) {
super(extension, mapIndexStorage, forwardIndex);
@@ -184,13 +184,13 @@ public class VcsLogFullDetailsIndex<T> implements Disposable {
}
}
private static class MyIndexExtension<T> extends IndexExtension<Integer, T, VcsFullCommitDetails> {
private static class MyIndexExtension<T, D> extends IndexExtension<Integer, T, D> {
@NotNull private final IndexId<Integer, T> myID;
@NotNull private final DataIndexer<Integer, T, VcsFullCommitDetails> myIndexer;
@NotNull private final DataIndexer<Integer, T, D> myIndexer;
@NotNull private final DataExternalizer<T> myExternalizer;
private final int myVersion;
public MyIndexExtension(@NotNull String name, @NotNull DataIndexer<Integer, T, VcsFullCommitDetails> indexer,
public MyIndexExtension(@NotNull String name, @NotNull DataIndexer<Integer, T, D> indexer,
@NotNull DataExternalizer<T> externalizer,
int version) {
myID = IndexId.create(name);
@@ -207,7 +207,7 @@ public class VcsLogFullDetailsIndex<T> implements Disposable {
@NotNull
@Override
public DataIndexer<Integer, T, VcsFullCommitDetails> getIndexer() {
public DataIndexer<Integer, T, D> getIndexer() {
return myIndexer;
}
@@ -31,7 +31,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.Map;
public class VcsLogMessagesTrigramIndex extends VcsLogFullDetailsIndex<Void> {
public class VcsLogMessagesTrigramIndex extends VcsLogFullDetailsIndex<Void, VcsFullCommitDetails> {
public static final String TRIGRAMS = "trigrams";
public VcsLogMessagesTrigramIndex(@NotNull StorageId storageId,
@@ -12,6 +12,7 @@ import com.intellij.util.indexing.impl.RemovedKeyProcessor;
import com.intellij.util.io.DataExternalizer;
import com.intellij.util.io.DataInputOutputUtil;
import com.intellij.vcs.log.VcsFullCommitDetails;
import com.intellij.vcs.log.impl.VcsIndexableDetails;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -26,7 +27,7 @@ import java.util.Set;
public abstract class VcsLogPathsForwardIndex
extends MapBasedForwardIndex<Integer, List<VcsLogPathsIndex.ChangeData>, List<Collection<Integer>>> {
protected VcsLogPathsForwardIndex(@NotNull IndexExtension<Integer, List<VcsLogPathsIndex.ChangeData>, VcsFullCommitDetails> extension)
protected VcsLogPathsForwardIndex(@NotNull IndexExtension<Integer, List<VcsLogPathsIndex.ChangeData>, VcsIndexableDetails> extension)
throws IOException {
super(extension);
}
@@ -22,7 +22,6 @@ import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
import com.intellij.util.PathUtil;
@@ -54,7 +53,7 @@ import java.util.function.ObjIntConsumer;
import static com.intellij.util.containers.ContainerUtil.newTroveSet;
public class VcsLogPathsIndex extends VcsLogFullDetailsIndex<List<VcsLogPathsIndex.ChangeData>> {
public class VcsLogPathsIndex extends VcsLogFullDetailsIndex<List<VcsLogPathsIndex.ChangeData>, VcsIndexableDetails> {
private static final Logger LOG = Logger.getInstance(VcsLogPathsIndex.class);
public static final String PATHS = "paths";
public static final String INDEX_PATHS_IDS = "paths-ids";
@@ -74,7 +73,7 @@ public class VcsLogPathsIndex extends VcsLogFullDetailsIndex<List<VcsLogPathsInd
@NotNull
@Override
protected ForwardIndex<Integer, List<VcsLogPathsIndex.ChangeData>> createForwardIndex(@NotNull IndexExtension<Integer, List<ChangeData>, VcsFullCommitDetails> extension)
protected ForwardIndex<Integer, List<VcsLogPathsIndex.ChangeData>> createForwardIndex(@NotNull IndexExtension<Integer, List<ChangeData>, VcsIndexableDetails> extension)
throws IOException {
if (!VcsLogIndexService.isPathsForwardIndexRequired()) return super.createForwardIndex(extension);
return new VcsLogPathsForwardIndex(extension) {
@@ -253,7 +252,7 @@ public class VcsLogPathsIndex extends VcsLogFullDetailsIndex<List<VcsLogPathsInd
return otherNames;
}
private static class PathsIndexer implements DataIndexer<Integer, List<ChangeData>, VcsFullCommitDetails> {
private static class PathsIndexer implements DataIndexer<Integer, List<ChangeData>, VcsIndexableDetails> {
@NotNull private final PersistentEnumeratorBase<LightFilePath> myPathsEnumerator;
@NotNull private final Set<String> myRoots;
@NotNull private Consumer<Exception> myFatalErrorConsumer = LOG::error;
@@ -272,28 +271,16 @@ public class VcsLogPathsIndex extends VcsLogFullDetailsIndex<List<VcsLogPathsInd
@NotNull
@Override
public Map<Integer, List<ChangeData>> map(@NotNull VcsFullCommitDetails inputData) {
public Map<Integer, List<ChangeData>> map(@NotNull VcsIndexableDetails inputData) {
Map<Integer, List<ChangeData>> result = new THashMap<>();
// its not exactly parents count since it is very convenient to assume that initial commit has one parent
int parentsCount = inputData.getParents().isEmpty() ? 1 : inputData.getParents().size();
for (int parent = 0; parent < parentsCount; parent++) {
Collection<Couple<LightFilePath>> moves = ContainerUtil.newHashSet();
Collection<LightFilePath> changedPaths = ContainerUtil.newHashSet();
if (inputData instanceof VcsIndexableDetails) {
changedPaths.addAll(toLightPaths(((VcsIndexableDetails)inputData).getModifiedPaths(parent)));
moves.addAll(ContainerUtil.map(((VcsIndexableDetails)inputData).getRenamedPaths(parent),
rename -> toLightPathCouple(rename.first, rename.second)));
}
else {
for (Change change : inputData.getChanges()) {
if (change.getAfterRevision() != null) changedPaths.add(new LightFilePath(change.getAfterRevision().getFile()));
if (change.getBeforeRevision() != null) changedPaths.add(new LightFilePath(change.getBeforeRevision().getFile()));
if (change.getType().equals(Change.Type.MOVED)) {
moves.add(toLightPathCouple(change.getBeforeRevision().getFile().getPath(), change.getAfterRevision().getFile().getPath()));
}
}
}
Collection<Couple<LightFilePath>> moves = ContainerUtil.newHashSet(ContainerUtil.map(inputData.getRenamedPaths(parent),
rename -> toLightPathCouple(rename.first,
rename.second)));
Collection<LightFilePath> changedPaths = ContainerUtil.newHashSet(toLightPaths(inputData.getModifiedPaths(parent)));
int finalParent = parent;
moves.forEach(move -> {
@@ -181,7 +181,7 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable
myIndexStorage.messages.put(index, detail.getFullMessage());
myIndexStorage.trigrams.update(index, detail);
myIndexStorage.users.update(index, detail);
myIndexStorage.paths.update(index, detail);
if (detail instanceof VcsIndexableDetails) myIndexStorage.paths.update(index, (VcsIndexableDetails)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 instanceof VcsIndexableDetails) || ((VcsIndexableDetails)detail).hasRenames()) {
@@ -44,7 +44,7 @@ import java.util.Set;
import static com.intellij.util.ObjectUtils.notNull;
import static com.intellij.util.containers.ContainerUtil.getFirstItem;
public class VcsLogUserIndex extends VcsLogFullDetailsIndex<Void> {
public class VcsLogUserIndex extends VcsLogFullDetailsIndex<Void, VcsFullCommitDetails> {
private static final Logger LOG = Logger.getInstance(VcsLogUserIndex.class);
public static final String USERS = "users";
@NotNull private final VcsUserRegistryImpl myUserRegistry;