mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[git] Better refresh VFS during cherry-pick & collecting unmerged files
This commit is contained in:
@@ -42,7 +42,8 @@ public class RefreshVFsSynchronously {
|
||||
refreshFiles(callback.getToRefresh());
|
||||
}
|
||||
|
||||
private static void refreshFiles(@NotNull Collection<File> files) {
|
||||
@NotNull
|
||||
public static Collection<VirtualFile> refreshFiles(@NotNull Collection<File> files) {
|
||||
Collection<VirtualFile> 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<File> deletedOrReplaced) {
|
||||
@@ -80,11 +82,11 @@ public class RefreshVFsSynchronously {
|
||||
updateChangesImpl(changes, RollbackChangeWrapper.ourInstance);
|
||||
}
|
||||
|
||||
public static void updateChanges(final List<Change> changes) {
|
||||
public static void updateChanges(final Collection<Change> changes) {
|
||||
updateChangesImpl(changes, DirectChangeWrapper.ourInstance);
|
||||
}
|
||||
|
||||
private static void updateChangesImpl(final List<Change> changes, final ChangeWrapper wrapper) {
|
||||
private static void updateChangesImpl(final Collection<Change> changes, final ChangeWrapper wrapper) {
|
||||
Collection<File> deletedOrReplaced = ContainerUtil.newHashSet();
|
||||
Collection<File> toRefresh = ContainerUtil.newHashSet();
|
||||
for (Change change : changes) {
|
||||
|
||||
@@ -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<FilePath> paths = ChangesUtil.getPaths(commit.getChanges());
|
||||
refreshChangedFiles(paths);
|
||||
Collection<Change> changes = commit.getChanges();
|
||||
RefreshVFsSynchronously.updateChanges(changes);
|
||||
final String commitMessage = createCommitMessage(commit);
|
||||
final Collection<FilePath> 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<FilePath> filePaths) {
|
||||
List<VirtualFile> virtualFiles = ContainerUtil.skipNulls(ContainerUtil.map(filePaths, new Function<FilePath, VirtualFile>() {
|
||||
@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<Change> originalChanges = commit.getChanges();
|
||||
|
||||
@@ -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<VirtualFile> unmergedFiles(VirtualFile root) throws VcsException {
|
||||
HashSet<VirtualFile> unmerged = new HashSet<VirtualFile>();
|
||||
String rootPath = root.getPath();
|
||||
|
||||
private List<VirtualFile> 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<String> 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<VirtualFile> rc = new ArrayList<VirtualFile>(unmerged.size());
|
||||
rc.addAll(unmerged);
|
||||
Collections.sort(rc, GitUtil.VIRTUAL_FILE_COMPARATOR);
|
||||
return rc;
|
||||
List<File> files = ContainerUtil.map(unmergedPaths, new Function<String, File>() {
|
||||
@Override
|
||||
public File fun(String path) {
|
||||
return new File(root.getPath(), path);
|
||||
}
|
||||
});
|
||||
return ContainerUtil.sorted(RefreshVFsSynchronously.refreshFiles(files), GitUtil.VIRTUAL_FILE_COMPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user