[vcs-log] introduce indexed details which gets subject and full message from index

This commit is contained in:
Julia Beliaeva
2017-01-13 14:16:41 +03:00
parent fb616e1fe7
commit 7bf373a565
8 changed files with 93 additions and 5 deletions
@@ -17,6 +17,8 @@ import com.intellij.util.ui.UIUtil;
import com.intellij.vcs.log.CommitId;
import com.intellij.vcs.log.VcsLogProvider;
import com.intellij.vcs.log.VcsShortCommitDetails;
import com.intellij.vcs.log.data.index.IndexedDetails;
import com.intellij.vcs.log.data.index.VcsLogIndex;
import com.intellij.vcs.log.util.SequentialLimitedLifoExecutor;
import gnu.trove.TIntHashSet;
import gnu.trove.TIntIntHashMap;
@@ -57,14 +59,17 @@ abstract class AbstractDataGetter<T extends VcsShortCommitDetails> implements Di
private long myCurrentTaskIndex = 0;
@NotNull private final Collection<Runnable> myLoadingFinishedListeners = new ArrayList<>();
@NotNull private VcsLogIndex myIndex;
AbstractDataGetter(@NotNull VcsLogStorage hashMap,
@NotNull Map<VirtualFile, VcsLogProvider> logProviders,
@NotNull VcsCommitCache<Integer, T> cache,
@NotNull VcsLogIndex index,
@NotNull Disposable parentDisposable) {
myHashMap = hashMap;
myLogProviders = logProviders;
myCache = cache;
myIndex = index;
Disposer.register(parentDisposable, this);
myLoader =
new SequentialLimitedLifoExecutor<>(this, MAX_LOADING_TASKS, task -> {
@@ -218,7 +223,7 @@ abstract class AbstractDataGetter<T extends VcsShortCommitDetails> implements Di
// fill the cache with temporary "Loading" values to avoid producing queries for each commit that has not been cached yet,
// even if it will be loaded within a previous query
if (!myCache.isKeyCached(commitId)) {
myCache.put(commitId, (T)new LoadingDetails(() -> myHashMap.getCommitId(commitId), taskNumber));
myCache.put(commitId, (T)new IndexedDetails(myIndex, myHashMap, commitId, taskNumber));
}
}
@@ -5,6 +5,7 @@ import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcs.log.VcsFullCommitDetails;
import com.intellij.vcs.log.VcsLogProvider;
import com.intellij.vcs.log.data.index.VcsLogIndex;
import com.intellij.vcs.log.impl.VcsLogUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -19,8 +20,9 @@ public class CommitDetailsGetter extends AbstractDataGetter<VcsFullCommitDetails
CommitDetailsGetter(@NotNull VcsLogStorage hashMap,
@NotNull Map<VirtualFile, VcsLogProvider> logProviders,
@NotNull VcsLogIndex index,
@NotNull Disposable parentDisposable) {
super(hashMap, logProviders, new VcsCommitCache<>(), parentDisposable);
super(hashMap, logProviders, new VcsCommitCache<>(), index, parentDisposable);
}
@Nullable
@@ -19,6 +19,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcs.log.VcsLogDetailsFilter;
import com.intellij.vcs.log.data.index.VcsLogIndex;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Set;
@@ -53,6 +54,12 @@ public class EmptyIndex implements VcsLogIndex {
throw new UnsupportedOperationException();
}
@Nullable
@Override
public String getFullMessage(int index) {
return null;
}
@Override
public void markCorrupted() {
}
@@ -5,6 +5,7 @@ import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcs.log.VcsLogProvider;
import com.intellij.vcs.log.VcsShortCommitDetails;
import com.intellij.vcs.log.data.index.VcsLogIndex;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -18,8 +19,9 @@ public class MiniDetailsGetter extends AbstractDataGetter<VcsShortCommitDetails>
MiniDetailsGetter(@NotNull VcsLogStorage hashMap,
@NotNull Map<VirtualFile, VcsLogProvider> logProviders,
@NotNull TopCommitsCache topCommitsDetailsCache,
@NotNull VcsLogIndex index,
@NotNull Disposable parentDisposable) {
super(hashMap, logProviders, new VcsCommitCache<>(), parentDisposable);
super(hashMap, logProviders, new VcsCommitCache<>(), index, parentDisposable);
myTopCommitsDetailsCache = topCommitsDetailsCache;
}
@@ -115,8 +115,8 @@ public class VcsLogData implements Disposable, VcsLogDataProvider {
}
myTopCommitsDetailsCache = new TopCommitsCache(myHashMap);
myMiniDetailsGetter = new MiniDetailsGetter(myHashMap, logProviders, myTopCommitsDetailsCache, this);
myDetailsGetter = new CommitDetailsGetter(myHashMap, logProviders, this);
myMiniDetailsGetter = new MiniDetailsGetter(myHashMap, logProviders, myTopCommitsDetailsCache, myIndex, this);
myDetailsGetter = new CommitDetailsGetter(myHashMap, logProviders, myIndex, this);
myRefresher = new VcsLogRefresherImpl(myProject, myHashMap, myLogProviders, myUserRegistry, myIndex, progress, myTopCommitsDetailsCache,
this::fireDataPackChangeEvent, FAILING_EXCEPTION_HANDLER, RECENT_COMMITS_COUNT);
@@ -0,0 +1,54 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.vcs.log.data.index;
import com.intellij.vcs.log.data.LoadingDetails;
import com.intellij.vcs.log.data.VcsLogStorage;
import org.jetbrains.annotations.NotNull;
public class IndexedDetails extends LoadingDetails {
@NotNull private final VcsLogIndex myIndex;
private final int myCommitIndex;
public IndexedDetails(@NotNull VcsLogIndex index,
@NotNull VcsLogStorage storage,
int commitIndex,
long loadingTaskIndex) {
super(() -> storage.getCommitId(commitIndex), loadingTaskIndex);
myIndex = index;
myCommitIndex = commitIndex;
}
@NotNull
@Override
public String getFullMessage() {
String message = myIndex.getFullMessage(myCommitIndex);
if (message != null) return message;
return super.getFullMessage();
}
@NotNull
@Override
public String getSubject() {
String message = myIndex.getFullMessage(myCommitIndex);
if (message != null) {
int subjectEnd = message.indexOf("\n\n");
if (subjectEnd > 0) return message.substring(0, subjectEnd).replace("\n", " ");
return message.replace("\n", " ");
}
return super.getSubject();
}
}
@@ -18,6 +18,7 @@ package com.intellij.vcs.log.data.index;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcs.log.VcsLogDetailsFilter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Set;
@@ -36,5 +37,8 @@ public interface VcsLogIndex {
@NotNull
Set<Integer> filter(@NotNull List<VcsLogDetailsFilter> detailsFilters);
@Nullable
String getFullMessage(int index);
void markCorrupted();
}
@@ -358,6 +358,20 @@ public class VcsLogPersistentIndex implements VcsLogIndex, Disposable {
return TroveUtil.intersect(filteredByMessage, filteredByPath, filteredByUser);
}
@Nullable
@Override
public String getFullMessage(int index) {
if (myIndexStorage != null) {
try {
return myIndexStorage.messages.get(index);
}
catch (IOException e) {
myFatalErrorsConsumer.consume(this, e);
}
}
return null;
}
@Override
public void dispose() {
}