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 5f408ffedf96..87e84adafa87 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 @@ -27,6 +27,7 @@ import com.intellij.util.indexing.DataIndexer; import com.intellij.util.indexing.StorageException; import com.intellij.util.io.*; import com.intellij.vcs.log.VcsFullCommitDetails; +import com.intellij.vcs.log.impl.VcsChangesLazilyParsedDetails; import com.intellij.vcs.log.util.PersistentUtil; import gnu.trove.THashMap; import gnu.trove.TIntHashSet; @@ -147,13 +148,21 @@ public class VcsLogPathsIndex extends VcsLogFullDetailsIndex { Map result = new THashMap<>(); - Collection> moves = ContainerUtil.newHashSet(); - Collection changedPaths = ContainerUtil.newHashSet(); - for (Change change : inputData.getChanges()) { - if (change.getAfterRevision() != null) changedPaths.add(change.getAfterRevision().getFile().getPath()); - if (change.getBeforeRevision() != null) changedPaths.add(change.getBeforeRevision().getFile().getPath()); - if (change.getType().equals(Change.Type.MOVED)) { - moves.add(Couple.of(change.getBeforeRevision().getFile().getPath(), change.getAfterRevision().getFile().getPath())); + Collection> moves; + Collection changedPaths; + if (inputData instanceof VcsChangesLazilyParsedDetails) { + changedPaths = ((VcsChangesLazilyParsedDetails)inputData).getModifiedPaths(); + moves = ((VcsChangesLazilyParsedDetails)inputData).getRenamedPaths(); + } + else { + moves = ContainerUtil.newHashSet(); + changedPaths = ContainerUtil.newHashSet(); + for (Change change : inputData.getChanges()) { + if (change.getAfterRevision() != null) changedPaths.add(change.getAfterRevision().getFile().getPath()); + if (change.getBeforeRevision() != null) changedPaths.add(change.getBeforeRevision().getFile().getPath()); + if (change.getType().equals(Change.Type.MOVED)) { + moves.add(Couple.of(change.getBeforeRevision().getFile().getPath(), change.getAfterRevision().getFile().getPath())); + } } } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsChangesLazilyParsedDetails.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsChangesLazilyParsedDetails.java index 1685d1ff2754..391037a4db18 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsChangesLazilyParsedDetails.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsChangesLazilyParsedDetails.java @@ -16,10 +16,12 @@ package com.intellij.vcs.log.impl; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.Couple; import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.vcs.LocalFilePath; import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.containers.ContainerUtil; import com.intellij.vcs.log.Hash; import com.intellij.vcs.log.VcsFullCommitDetails; import com.intellij.vcs.log.VcsUser; @@ -28,6 +30,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Set; /** * Allows to postpone changes parsing, which might take long for a large amount of commits, @@ -37,7 +40,7 @@ public class VcsChangesLazilyParsedDetails extends VcsCommitMetadataImpl impleme private static final Logger LOG = Logger.getInstance(VcsChangesLazilyParsedDetails.class); - @NotNull private final ThrowableComputable, ? extends Exception> myChangesGetter; + @NotNull protected final ThrowableComputable, ? extends Exception> myChangesGetter; public VcsChangesLazilyParsedDetails(@NotNull Hash hash, @NotNull List parents, long commitTime, @NotNull VirtualFile root, @NotNull String subject, @NotNull VcsUser author, @NotNull String message, @@ -58,4 +61,27 @@ public class VcsChangesLazilyParsedDetails extends VcsCommitMetadataImpl impleme return Collections.emptyList(); } } + + @NotNull + public Collection getModifiedPaths() { + Set changedPaths = ContainerUtil.newHashSet(); + for (Change change : getChanges()) { + if (change.getAfterRevision() != null) changedPaths.add(change.getAfterRevision().getFile().getPath()); + if (change.getBeforeRevision() != null) changedPaths.add(change.getBeforeRevision().getFile().getPath()); + } + return changedPaths; + } + + @NotNull + public Collection> getRenamedPaths() { + Set> renames = ContainerUtil.newHashSet(); + for (Change change : getChanges()) { + if (change.getType().equals(Change.Type.MOVED)) { + if (change.getAfterRevision() != null && change.getBeforeRevision() != null) { + renames.add(Couple.of(change.getBeforeRevision().getFile().getPath(), change.getAfterRevision().getFile().getPath())); + } + } + } + return renames; + } } diff --git a/plugins/git4idea/src/git4idea/GitCommit.java b/plugins/git4idea/src/git4idea/GitCommit.java index 3a1962bb23ee..bd66d3967c78 100644 --- a/plugins/git4idea/src/git4idea/GitCommit.java +++ b/plugins/git4idea/src/git4idea/GitCommit.java @@ -16,6 +16,7 @@ package git4idea; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Couple; import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.changes.Change; @@ -32,6 +33,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Set; /** * Represents a Git commit with its meta information (hash, author, message, etc.), its parents and the {@link Change changes}. @@ -45,7 +47,50 @@ public final class GitCommit extends VcsChangesLazilyParsedDetails { long authorTime, @NotNull List reportedChanges) { super(hash, parents, commitTime, root, subject, author, message, committer, authorTime, new MyChangesComputable(new Data(project, root, reportedChanges, hash, commitTime, parents))); + } + @NotNull + @Override + public Collection getModifiedPaths() { + Data data = ((MyChangesComputable)myChangesGetter).getData(); + if (data != null) { + Set changes = ContainerUtil.newHashSet(); + for (GitLogStatusInfo status : data.changesOutput) { + changes.add(absolutePath(status.getFirstPath())); + String secondPath = status.getSecondPath(); + if (secondPath != null) { + changes.add(absolutePath(secondPath)); + } + } + return changes; + } + return super.getModifiedPaths(); + } + + @NotNull + @Override + public Collection> getRenamedPaths() { + Data data = ((MyChangesComputable)myChangesGetter).getData(); + if (data != null) { + Set> changes = ContainerUtil.newHashSet(); + for (GitLogStatusInfo status : data.changesOutput) { + if (status.getSecondPath() != null) { + changes.add(Couple.of(absolutePath(status.getFirstPath()), absolutePath(status.getSecondPath()))); + } + } + return changes; + } + return super.getRenamedPaths(); + } + + @NotNull + private String absolutePath(@NotNull String path) { + try { + return getRoot().getPath() + "/" + GitUtil.unescapePath(path); + } + catch (VcsException e) { + return getRoot().getPath() + "/" + path; + } } private static class MyChangesComputable implements ThrowableComputable, VcsException> { @@ -72,6 +117,9 @@ public final class GitCommit extends VcsChangesLazilyParsedDetails { return myChanges; } + public Data getData() { + return myData; + } } private static class Data { @@ -91,5 +139,4 @@ public final class GitCommit extends VcsChangesLazilyParsedDetails { this.parents = parents; } } - }