From b9d2a2b1689381da61dc595a243ea4ecb91e40e3 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Tue, 23 Dec 2014 18:43:23 +0300 Subject: [PATCH] [git] Better refresh VFS during cherry-pick & collecting unmerged files --- .../vcs/update/RefreshVFsSynchronously.java | 8 ++-- .../git4idea/cherrypick/GitCherryPicker.java | 19 ++-------- .../git4idea/merge/GitConflictResolver.java | 38 +++++++++---------- 3 files changed, 26 insertions(+), 39 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/RefreshVFsSynchronously.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/RefreshVFsSynchronously.java index cd8d109ecab9..1b1fc87eef5d 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/RefreshVFsSynchronously.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/RefreshVFsSynchronously.java @@ -42,7 +42,8 @@ public class RefreshVFsSynchronously { refreshFiles(callback.getToRefresh()); } - private static void refreshFiles(@NotNull Collection files) { + @NotNull + public static Collection refreshFiles(@NotNull Collection files) { Collection filesToRefresh = ContainerUtil.newHashSet(); for (File file : files) { VirtualFile vf = findFirstValidVirtualParent(file); @@ -51,6 +52,7 @@ public class RefreshVFsSynchronously { } } VfsUtil.markDirtyAndRefresh(false, false, false, ArrayUtil.toObjectArray(filesToRefresh, VirtualFile.class)); + return filesToRefresh; } private static void refreshDeletedOrReplaced(@NotNull Collection deletedOrReplaced) { @@ -80,11 +82,11 @@ public class RefreshVFsSynchronously { updateChangesImpl(changes, RollbackChangeWrapper.ourInstance); } - public static void updateChanges(final List changes) { + public static void updateChanges(final Collection changes) { updateChangesImpl(changes, DirectChangeWrapper.ourInstance); } - private static void updateChangesImpl(final List changes, final ChangeWrapper wrapper) { + private static void updateChangesImpl(final Collection changes, final ChangeWrapper wrapper) { Collection deletedOrReplaced = ContainerUtil.newHashSet(); Collection toRefresh = ContainerUtil.newHashSet(); for (Change change : changes) { diff --git a/plugins/git4idea/src/git4idea/cherrypick/GitCherryPicker.java b/plugins/git4idea/src/git4idea/cherrypick/GitCherryPicker.java index 0a50a623af0a..4c1748ab8688 100644 --- a/plugins/git4idea/src/git4idea/cherrypick/GitCherryPicker.java +++ b/plugins/git4idea/src/git4idea/cherrypick/GitCherryPicker.java @@ -31,9 +31,8 @@ import com.intellij.openapi.vcs.VcsNotifier; import com.intellij.openapi.vcs.changes.*; import com.intellij.openapi.vcs.history.VcsRevisionNumber; import com.intellij.openapi.vcs.merge.MergeDialogCustomizer; -import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vcs.update.RefreshVFsSynchronously; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.ArrayUtil; import com.intellij.util.Consumer; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; @@ -236,9 +235,10 @@ public class GitCherryPicker extends VcsCherryPicker { @Nullable private CherryPickData updateChangeListManager(@NotNull final VcsFullCommitDetails commit) { - final Collection paths = ChangesUtil.getPaths(commit.getChanges()); - refreshChangedFiles(paths); + Collection changes = commit.getChanges(); + RefreshVFsSynchronously.updateChanges(changes); final String commitMessage = createCommitMessage(commit); + final Collection paths = ChangesUtil.getPaths(changes); LocalChangeList changeList = createChangeListAfterUpdate(commit, paths, commitMessage); return changeList == null ? null : new CherryPickData(changeList, commitMessage); } @@ -431,17 +431,6 @@ public class GitCherryPicker extends VcsCherryPicker { return commit.getCommit().getId().toShortString() + " " + commit.getOriginalSubject(); } - private void refreshChangedFiles(@NotNull Collection filePaths) { - List virtualFiles = ContainerUtil.skipNulls(ContainerUtil.map(filePaths, new Function() { - @Override - public VirtualFile fun(FilePath file) { - return myPlatformFacade.getLocalFileSystem().refreshAndFindFileByPath(file.getPath()); - } - })); - VfsUtil.markDirtyAndRefresh(false, false, false, ArrayUtil.toObjectArray(virtualFiles, VirtualFile.class)); - VcsDirtyScopeManager.getInstance(myProject).filePathsDirty(filePaths, null); - } - @Nullable private LocalChangeList createChangeListIfThereAreChanges(@NotNull VcsFullCommitDetails commit, @NotNull String commitMessage) { Collection originalChanges = commit.getChanges(); diff --git a/plugins/git4idea/src/git4idea/merge/GitConflictResolver.java b/plugins/git4idea/src/git4idea/merge/GitConflictResolver.java index 214c026307d5..99cd3eb0c386 100644 --- a/plugins/git4idea/src/git4idea/merge/GitConflictResolver.java +++ b/plugins/git4idea/src/git4idea/merge/GitConflictResolver.java @@ -26,8 +26,10 @@ import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.VcsNotifier; import com.intellij.openapi.vcs.merge.MergeDialogCustomizer; import com.intellij.openapi.vcs.merge.MergeProvider; -import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vcs.update.RefreshVFsSynchronously; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; import git4idea.GitPlatformFacade; import git4idea.GitUtil; @@ -40,6 +42,7 @@ import git4idea.util.StringScanner; import org.jetbrains.annotations.NotNull; import javax.swing.event.HyperlinkEvent; +import java.io.File; import java.util.*; /** @@ -283,10 +286,7 @@ public class GitConflictResolver { * @return a set of unmerged files * @throws com.intellij.openapi.vcs.VcsException if the input format does not matches expected format */ - private List unmergedFiles(VirtualFile root) throws VcsException { - HashSet unmerged = new HashSet(); - String rootPath = root.getPath(); - + private List unmergedFiles(final VirtualFile root) throws VcsException { GitRepository repository = myRepositoryManager.getRepositoryForRoot(root); if (repository == null) { LOG.error("Repository not found for root " + root); @@ -299,32 +299,28 @@ public class GitConflictResolver { } String output = StringUtil.join(result.getOutput(), "\n"); - - LocalFileSystem lfs = myPlatformFacade.getLocalFileSystem(); + HashSet unmergedPaths = ContainerUtil.newHashSet(); for (StringScanner s = new StringScanner(output); s.hasMoreData();) { if (s.isEol()) { s.nextLine(); continue; } s.boundedToken('\t'); - final String relative = s.line(); - String path = rootPath + "/" + GitUtil.unescapePath(relative); - VirtualFile file = lfs.refreshAndFindFileByPath(path); - if (file != null) { - // the file name is in the delete- or rename- conflict, so it is shown in the list of unmerged files, - // but the file itself doesn't exist. In that case we just ignore the file. - file.refresh(false, false); - unmerged.add(file); - } + String relative = s.line(); + unmergedPaths.add(GitUtil.unescapePath(relative)); } - if (unmerged.size() == 0) { + + if (unmergedPaths.size() == 0) { return Collections.emptyList(); } else { - ArrayList rc = new ArrayList(unmerged.size()); - rc.addAll(unmerged); - Collections.sort(rc, GitUtil.VIRTUAL_FILE_COMPARATOR); - return rc; + List files = ContainerUtil.map(unmergedPaths, new Function() { + @Override + public File fun(String path) { + return new File(root.getPath(), path); + } + }); + return ContainerUtil.sorted(RefreshVFsSynchronously.refreshFiles(files), GitUtil.VIRTUAL_FILE_COMPARATOR); } }