From d1f2f472dd41d9dd3214a521ada267a7fff2c9e0 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Mon, 26 Sep 2016 16:56:51 +0300 Subject: [PATCH] [vcs-log] filter by regular expressions in memory using messages index --- .../log/data/index/VcsLogPersistentIndex.java | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPersistentIndex.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPersistentIndex.java index 96b6ab03b816..06a155cbd74a 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPersistentIndex.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPersistentIndex.java @@ -51,6 +51,7 @@ import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; +import java.util.regex.Pattern; import java.util.stream.IntStream; public class VcsLogPersistentIndex implements VcsLogIndex, Disposable { @@ -283,25 +284,31 @@ public class VcsLogPersistentIndex implements VcsLogIndex, Disposable { public TIntHashSet filterMessages(@NotNull String text) { if (myTrigramIndex != null) { try { - ValueContainer.IntIterator commitsForSearch = myTrigramIndex.getCommitsForSubstring(text); - if (commitsForSearch != null) { - TIntHashSet result = new TIntHashSet(); - while (commitsForSearch.hasNext()) { - int commit = commitsForSearch.next(); - try { - String value = myMessagesIndex.get(commit); - if (value != null) { - if (StringUtil.containsIgnoreCase(value, text)) { - result.add(commit); + if (VcsLogUtil.isRegexp(text)) { + Pattern pattern = Pattern.compile(text); + return filter(myMessagesIndex, message -> pattern.matcher(message).find()); + } + else { + ValueContainer.IntIterator commitsForSearch = myTrigramIndex.getCommitsForSubstring(text); + if (commitsForSearch != null) { + TIntHashSet result = new TIntHashSet(); + while (commitsForSearch.hasNext()) { + int commit = commitsForSearch.next(); + try { + String value = myMessagesIndex.get(commit); + if (value != null) { + if (StringUtil.containsIgnoreCase(value, text)) { + result.add(commit); + } } } + catch (IOException e) { + myFatalErrorsConsumer.consume(this, e); + break; + } } - catch (IOException e) { - myFatalErrorsConsumer.consume(this, e); - break; - } + return result; } - return result; } } catch (StorageException e) { @@ -316,7 +323,7 @@ public class VcsLogPersistentIndex implements VcsLogIndex, Disposable { public boolean canFilter(@NotNull List filters) { if (filters.isEmpty()) return false; for (VcsLogDetailsFilter filter : filters) { - if (filter instanceof VcsLogTextFilter && myTrigramIndex != null && !VcsLogUtil.isRegexp(((VcsLogTextFilter)filter).getText()) || + if (filter instanceof VcsLogTextFilter && myTrigramIndex != null || filter instanceof VcsLogUserFilterImpl && myUserIndex != null || filter instanceof VcsLogStructureFilter && myPathsIndex != null) { continue;