diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogFullDetailsIndex.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogFullDetailsIndex.java index 10f66e7aed04..56ae847755f4 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogFullDetailsIndex.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogFullDetailsIndex.java @@ -7,6 +7,7 @@ import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Ref; +import com.intellij.util.ThrowableRunnable; import com.intellij.util.indexing.*; import com.intellij.util.indexing.impl.IndexStorage; import com.intellij.util.indexing.impl.MapIndexStorage; @@ -128,6 +129,18 @@ public class VcsLogFullDetailsIndex implements Disposable { if (myDisposed) throw new ProcessCanceledException(); } + protected static void catchAndWarn(@NotNull Logger logger, @NotNull ThrowableRunnable runnable) { + try { + runnable.run(); + } + catch (ProcessCanceledException e) { + throw e; + } + catch (Throwable e) { + logger.warn(e); + } + } + private static final class MyMapReduceIndex extends MapReduceIndex { private final @NotNull VcsLogErrorHandler myErrorHandler; diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPathsIndex.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPathsIndex.java index 431c19ce060a..b612b485d644 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPathsIndex.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPathsIndex.java @@ -3,6 +3,7 @@ package com.intellij.vcs.log.data.index; import com.intellij.openapi.Disposable; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.Disposer; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vfs.VirtualFile; @@ -39,7 +40,7 @@ import java.util.function.Consumer; import static java.nio.charset.StandardCharsets.UTF_8; -final class VcsLogPathsIndex extends VcsLogFullDetailsIndex, CompressedDetails> { +public final class VcsLogPathsIndex extends VcsLogFullDetailsIndex, CompressedDetails> { private static final Logger LOG = Logger.getInstance(VcsLogPathsIndex.class); public static final String PATHS = "paths"; public static final String INDEX_PATHS_IDS = "paths-ids"; @@ -95,17 +96,6 @@ final class VcsLogPathsIndex extends VcsLogFullDetailsIndex, Co myPathsIndexer.myPathsEnumerator.force(); } - @Override - public void dispose() { - super.dispose(); - try { - myPathsIndexer.myPathsEnumerator.close(); - } - catch (IOException e) { - LOG.warn(e); - } - } - @Contract("null,_ -> null; !null,_ -> !null") static @Nullable FilePath toFilePath(@Nullable LightFilePath lightFilePath, boolean isDirectory) { if (lightFilePath == null) return null; @@ -117,11 +107,20 @@ final class VcsLogPathsIndex extends VcsLogFullDetailsIndex, Co @NotNull PersistentHashMap renamesMap, boolean useDurableEnumerator, @NotNull VcsLogErrorHandler errorHandler, @NotNull Disposable disposableParent) throws IOException { - DurableDataEnumerator pathsEnumerator = createPathsEnumerator(roots, storageId, storageLockContext, - useDurableEnumerator); - PathIndexer pathsIndex = new PathIndexer(storage, pathsEnumerator, renamesMap, - e -> errorHandler.handleError(VcsLogErrorHandler.Source.Index, e)); - return new VcsLogPathsIndex(storageId, storageLockContext, pathsIndex, errorHandler, disposableParent); + Disposable disposable = Disposer.newDisposable(disposableParent); + try { + DurableDataEnumerator pathsEnumerator = createPathsEnumerator(roots, storageId, storageLockContext, + useDurableEnumerator); + Disposer.register(disposable, () -> catchAndWarn(LOG, pathsEnumerator::close)); + + PathIndexer pathsIndex = new PathIndexer(storage, pathsEnumerator, renamesMap, + e -> errorHandler.handleError(VcsLogErrorHandler.Source.Index, e)); + return new VcsLogPathsIndex(storageId, storageLockContext, pathsIndex, errorHandler, disposable); + } + catch (Throwable t) { + Disposer.dispose(disposable); + throw t; + } } static final class PathIndexer implements DataIndexer, CompressedDetails> { diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogUserIndex.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogUserIndex.java index ff803461e85b..22c35afe9724 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogUserIndex.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogUserIndex.java @@ -3,9 +3,9 @@ package com.intellij.vcs.log.data.index; import com.intellij.openapi.Disposable; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.Disposer; import com.intellij.util.indexing.DataIndexer; import com.intellij.util.indexing.StorageException; -import com.intellij.util.indexing.impl.MapReduceIndex; import com.intellij.util.indexing.impl.forward.KeyCollectionForwardIndexAccessor; import com.intellij.util.indexing.impl.forward.PersistentMapBasedForwardIndex; import com.intellij.util.io.IntCollectionDataExternalizer; @@ -112,27 +112,27 @@ final class VcsLogUserIndex extends VcsLogFullDetailsIndex enumerator = createUserEnumerator(storageId, storageLockContext, userRegistry); - UserIndexer userIndexer = new UserIndexer(enumerator, e -> errorHandler.handleError(VcsLogErrorHandler.Source.Index, e)); - return new VcsLogUserIndex(storageId, userIndexer, forwardIndex, storageLockContext, errorHandler, disposableParent); + Disposable disposable = Disposer.newDisposable(disposableParent); + try { + PersistentMapBasedForwardIndex forwardIndex = new PersistentMapBasedForwardIndex(storageId.getStorageFile(USERS + ".idx"), + true, false, storageLockContext); + Disposer.register(disposable, () -> catchAndWarn(LOG, forwardIndex::close)); + + PersistentEnumerator userEnumerator = createUserEnumerator(storageId, storageLockContext, userRegistry); + Disposer.register(disposable, () -> catchAndWarn(LOG, userEnumerator::close)); + + UserIndexer userIndexer = new UserIndexer(userEnumerator, e -> errorHandler.handleError(VcsLogErrorHandler.Source.Index, e)); + return new VcsLogUserIndex(storageId, userIndexer, forwardIndex, storageLockContext, errorHandler, disposable); + } + catch (Throwable t) { + Disposer.dispose(disposable); + throw t; + } } private static final class UserIndexer implements DataIndexer {