mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
git: simplify method signature: throw an exception instead of collecting it in a list
GitOrigin-RevId: ba3698bb2418d47904d872ffa6d31b234d8d151b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
909389b6c9
commit
f8b51e1906
@@ -26,7 +26,10 @@ import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.GuiUtils;
|
||||
import com.intellij.vcs.ViewUpdateInfoNotification;
|
||||
import git4idea.*;
|
||||
import git4idea.GitBranch;
|
||||
import git4idea.GitRevisionNumber;
|
||||
import git4idea.GitUtil;
|
||||
import git4idea.GitVcs;
|
||||
import git4idea.branch.GitBranchPair;
|
||||
import git4idea.commands.*;
|
||||
import git4idea.merge.GitConflictResolver;
|
||||
@@ -43,7 +46,6 @@ import git4idea.util.LocalChangesWouldBeOverwrittenHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.notification.NotificationType.INFORMATION;
|
||||
@@ -164,9 +166,7 @@ abstract class GitMergeAction extends GitRepositoryAction {
|
||||
}).buildAndShowNotification();
|
||||
}
|
||||
else {
|
||||
List<VcsException> exceptions = new ArrayList<>();
|
||||
showUpdates(project, exceptions, root, currentRev, beforeLabel, getActionName());
|
||||
GitVcs.getInstance(project).showErrors(exceptions, getActionName());
|
||||
showUpdates(project, root, currentRev, beforeLabel, getActionName());
|
||||
}
|
||||
}
|
||||
else if (localChangesDetector.wasMessageDetected()) {
|
||||
@@ -184,24 +184,27 @@ abstract class GitMergeAction extends GitRepositoryAction {
|
||||
}
|
||||
|
||||
private static void showUpdates(@NotNull Project project,
|
||||
@NotNull List<? super VcsException> exceptions,
|
||||
@NotNull VirtualFile root,
|
||||
@NotNull GitRevisionNumber currentRev,
|
||||
@NotNull Label beforeLabel,
|
||||
@NotNull String actionName) {
|
||||
UpdatedFiles files = UpdatedFiles.create();
|
||||
MergeChangeCollector collector = new MergeChangeCollector(project, root, currentRev);
|
||||
collector.collect(files, exceptions);
|
||||
if (!exceptions.isEmpty()) return;
|
||||
try {
|
||||
UpdatedFiles files = UpdatedFiles.create();
|
||||
MergeChangeCollector collector = new MergeChangeCollector(project, root, currentRev);
|
||||
collector.collect(files);
|
||||
|
||||
GuiUtils.invokeLaterIfNeeded(() -> {
|
||||
ProjectLevelVcsManagerEx manager = (ProjectLevelVcsManagerEx)ProjectLevelVcsManager.getInstance(project);
|
||||
UpdateInfoTree tree = manager.showUpdateProjectInfo(files, actionName, ActionInfo.UPDATE, false);
|
||||
if (tree != null) {
|
||||
tree.setBefore(beforeLabel);
|
||||
tree.setAfter(LocalHistory.getInstance().putSystemLabel(project, "After update"));
|
||||
ViewUpdateInfoNotification.focusUpdateInfoTree(project, tree);
|
||||
}
|
||||
}, ModalityState.defaultModalityState());
|
||||
GuiUtils.invokeLaterIfNeeded(() -> {
|
||||
ProjectLevelVcsManagerEx manager = (ProjectLevelVcsManagerEx)ProjectLevelVcsManager.getInstance(project);
|
||||
UpdateInfoTree tree = manager.showUpdateProjectInfo(files, actionName, ActionInfo.UPDATE, false);
|
||||
if (tree != null) {
|
||||
tree.setBefore(beforeLabel);
|
||||
tree.setAfter(LocalHistory.getInstance().putSystemLabel(project, "After update"));
|
||||
ViewUpdateInfoNotification.focusUpdateInfoTree(project, tree);
|
||||
}
|
||||
}, ModalityState.defaultModalityState());
|
||||
}
|
||||
catch (VcsException e) {
|
||||
GitVcs.getInstance(project).showErrors(singletonList(e), actionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,28 +60,24 @@ public class MergeChangeCollector {
|
||||
/**
|
||||
* Collects changed files during or after merge operation to the supplied container.
|
||||
*/
|
||||
public void collect(@NotNull UpdatedFiles updatedFiles, List<? super VcsException> exceptions) {
|
||||
try {
|
||||
// collect unmerged
|
||||
Set<String> paths = getUnmergedPaths();
|
||||
addAll(updatedFiles, FileGroup.MERGED_WITH_CONFLICT_ID, paths);
|
||||
public void collect(@NotNull UpdatedFiles updatedFiles) throws VcsException {
|
||||
// collect unmerged
|
||||
Set<String> paths = getUnmergedPaths();
|
||||
addAll(updatedFiles, FileGroup.MERGED_WITH_CONFLICT_ID, paths);
|
||||
|
||||
// collect other changes (ignoring unmerged)
|
||||
TreeSet<String> updated = new TreeSet<>();
|
||||
TreeSet<String> created = new TreeSet<>();
|
||||
TreeSet<String> removed = new TreeSet<>();
|
||||
// collect other changes (ignoring unmerged)
|
||||
TreeSet<String> updated = new TreeSet<>();
|
||||
TreeSet<String> created = new TreeSet<>();
|
||||
TreeSet<String> removed = new TreeSet<>();
|
||||
|
||||
String revisionsForDiff = getRevisionsForDiff();
|
||||
if (revisionsForDiff == null) {
|
||||
return;
|
||||
}
|
||||
getChangedFilesExceptUnmerged(updated, created, removed, revisionsForDiff);
|
||||
addAll(updatedFiles, FileGroup.UPDATED_ID, updated);
|
||||
addAll(updatedFiles, FileGroup.CREATED_ID, created);
|
||||
addAll(updatedFiles, FileGroup.REMOVED_FROM_REPOSITORY_ID, removed);
|
||||
} catch (VcsException e) {
|
||||
exceptions.add(e);
|
||||
String revisionsForDiff = getRevisionsForDiff();
|
||||
if (revisionsForDiff == null) {
|
||||
return;
|
||||
}
|
||||
getChangedFilesExceptUnmerged(updated, created, removed, revisionsForDiff);
|
||||
addAll(updatedFiles, FileGroup.UPDATED_ID, updated);
|
||||
addAll(updatedFiles, FileGroup.CREATED_ID, created);
|
||||
addAll(updatedFiles, FileGroup.REMOVED_FROM_REPOSITORY_ID, removed);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -337,11 +337,11 @@ public class GitPushOperation {
|
||||
|
||||
private void collectUpdatedFiles(@NotNull UpdatedFiles updatedFiles, @NotNull GitRepository repository,
|
||||
@NotNull String preUpdatePosition) {
|
||||
MergeChangeCollector collector = new MergeChangeCollector(myProject, repository.getRoot(), new GitRevisionNumber(preUpdatePosition));
|
||||
ArrayList<VcsException> exceptions = new ArrayList<>();
|
||||
collector.collect(updatedFiles, exceptions);
|
||||
for (VcsException exception : exceptions) {
|
||||
LOG.info(exception);
|
||||
try {
|
||||
new MergeChangeCollector(myProject, repository.getRoot(), new GitRevisionNumber(preUpdatePosition)).collect(updatedFiles);
|
||||
}
|
||||
catch (VcsException e) {
|
||||
LOG.info(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,10 @@ import com.intellij.openapi.vcs.AbstractVcsHelper;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.update.UpdatedFiles;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import git4idea.*;
|
||||
import git4idea.GitLocalBranch;
|
||||
import git4idea.GitRevisionNumber;
|
||||
import git4idea.GitUtil;
|
||||
import git4idea.GitVcs;
|
||||
import git4idea.branch.GitBranchPair;
|
||||
import git4idea.commands.Git;
|
||||
import git4idea.commands.GitCommand;
|
||||
@@ -35,8 +38,6 @@ import git4idea.repo.GitRepository;
|
||||
import git4idea.repo.GitRepositoryManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static git4idea.GitUtil.HEAD;
|
||||
import static git4idea.config.UpdateMethod.MERGE;
|
||||
import static git4idea.config.UpdateMethod.REBASE;
|
||||
@@ -187,12 +188,7 @@ public abstract class GitUpdater {
|
||||
|
||||
protected void markEnd(VirtualFile root) throws VcsException {
|
||||
// find out what have changed, this is done even if the process was cancelled.
|
||||
final MergeChangeCollector collector = new MergeChangeCollector(myProject, root, myBefore);
|
||||
final ArrayList<VcsException> exceptions = new ArrayList<>();
|
||||
collector.collect(myUpdatedFiles, exceptions);
|
||||
if (!exceptions.isEmpty()) {
|
||||
throw exceptions.get(0);
|
||||
}
|
||||
new MergeChangeCollector(myProject, root, myBefore).collect(myUpdatedFiles);
|
||||
}
|
||||
|
||||
protected boolean hasRemoteChanges(@NotNull String remoteBranch) throws VcsException {
|
||||
|
||||
Reference in New Issue
Block a user