mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-146022 IDEA-148275 filter affected roots by vcs and fresh state
After 00e2508e IDEA tried to call git log on a hg repository.
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.dvcs;
|
||||
|
||||
import com.intellij.dvcs.repo.Repository;
|
||||
import com.intellij.dvcs.repo.RepositoryManager;
|
||||
import com.intellij.dvcs.ui.DvcsBundle;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
@@ -38,6 +40,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Provides a checkbox to amend current commit to the previous commit.
|
||||
@@ -48,6 +51,7 @@ public abstract class AmendComponent {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(AmendComponent.class);
|
||||
|
||||
@NotNull private final RepositoryManager<? extends Repository> myRepoManager;
|
||||
@NotNull private final CheckinProjectPanel myCheckinPanel;
|
||||
@NotNull private final JCheckBox myAmend;
|
||||
@NotNull private final String myPreviousMessage;
|
||||
@@ -55,11 +59,17 @@ public abstract class AmendComponent {
|
||||
@Nullable private Map<VirtualFile, String> myMessagesForRoots;
|
||||
@Nullable private String myAmendedMessage;
|
||||
|
||||
public AmendComponent(@NotNull final Project project, @NotNull CheckinProjectPanel panel) {
|
||||
this(project, panel, DvcsBundle.message("commit.amend"));
|
||||
public AmendComponent(@NotNull Project project,
|
||||
@NotNull RepositoryManager<? extends Repository> repoManager,
|
||||
@NotNull CheckinProjectPanel panel) {
|
||||
this(project, repoManager, panel, DvcsBundle.message("commit.amend"));
|
||||
}
|
||||
|
||||
public AmendComponent(@NotNull final Project project, @NotNull CheckinProjectPanel panel, @NotNull String title) {
|
||||
public AmendComponent(@NotNull Project project,
|
||||
@NotNull RepositoryManager<? extends Repository> repoManager,
|
||||
@NotNull CheckinProjectPanel panel,
|
||||
@NotNull String title) {
|
||||
myRepoManager = repoManager;
|
||||
myCheckinPanel = panel;
|
||||
myAmend = new NonFocusableCheckBox(title);
|
||||
myAmend.setMnemonic('m');
|
||||
@@ -142,14 +152,23 @@ public abstract class AmendComponent {
|
||||
@Nullable
|
||||
private Map<VirtualFile, String> getLastCommitMessages() throws VcsException {
|
||||
Map<VirtualFile, String> messagesForRoots = new HashMap<>();
|
||||
Collection<VirtualFile> roots = myCheckinPanel.getRoots(); //all committed vcs roots, not only selected
|
||||
for (VirtualFile root : roots) {
|
||||
// load all vcs roots visible in the commit dialog (not only selected ones), to avoid another loading task if selection changes
|
||||
for (VirtualFile root : getAffectedRoots()) {
|
||||
String message = getLastCommitMessage(root);
|
||||
messagesForRoots.put(root, message);
|
||||
}
|
||||
return messagesForRoots;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Collection<VirtualFile> getAffectedRoots() {
|
||||
return myRepoManager.getRepositories().stream().
|
||||
filter(repo -> !repo.isFresh()).
|
||||
map(Repository::getRoot).
|
||||
filter(root -> myCheckinPanel.getRoots().contains(root)).
|
||||
collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<FilePath> getSelectedFilePaths() {
|
||||
return ContainerUtil.map(myCheckinPanel.getFiles(), VcsUtil::getFilePath);
|
||||
|
||||
@@ -89,6 +89,8 @@ import static com.intellij.openapi.vcs.changes.ChangesUtil.getBeforePath;
|
||||
import static com.intellij.util.ObjectUtils.assertNotNull;
|
||||
import static com.intellij.util.containers.ContainerUtil.*;
|
||||
import static git4idea.GitUtil.getLogString;
|
||||
import static git4idea.GitUtil.getRepositoryManager;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class GitCheckinEnvironment implements CheckinEnvironment {
|
||||
private static final Logger LOG = Logger.getInstance(GitCheckinEnvironment.class);
|
||||
@@ -132,8 +134,8 @@ public class GitCheckinEnvironment implements CheckinEnvironment {
|
||||
@Nullable
|
||||
public String getDefaultMessageFor(FilePath[] filesToCheckin) {
|
||||
LinkedHashSet<String> messages = newLinkedHashSet();
|
||||
GitRepositoryManager manager = GitUtil.getRepositoryManager(myProject);
|
||||
for (VirtualFile root : GitUtil.gitRoots(Arrays.asList(filesToCheckin))) {
|
||||
GitRepositoryManager manager = getRepositoryManager(myProject);
|
||||
for (VirtualFile root : GitUtil.gitRoots(asList(filesToCheckin))) {
|
||||
GitRepository repository = manager.getRepositoryForRoot(root);
|
||||
if (repository == null) { // unregistered nested submodule found by GitUtil.getGitRoot
|
||||
LOG.warn("Unregistered repository: " + root);
|
||||
@@ -254,7 +256,7 @@ public class GitCheckinEnvironment implements CheckinEnvironment {
|
||||
}
|
||||
}
|
||||
if (myNextCommitIsPushed != null && myNextCommitIsPushed.booleanValue() && exceptions.isEmpty()) {
|
||||
GitRepositoryManager manager = GitUtil.getRepositoryManager(myProject);
|
||||
GitRepositoryManager manager = getRepositoryManager(myProject);
|
||||
Collection<GitRepository> repositories = GitUtil.getRepositoriesFromRoots(manager, sortedChanges.keySet());
|
||||
final List<GitRepository> preselectedRepositories = newArrayList(repositories);
|
||||
GuiUtils.invokeLaterIfNeeded(() ->
|
||||
@@ -455,7 +457,7 @@ public class GitCheckinEnvironment implements CheckinEnvironment {
|
||||
// perform merge commit
|
||||
try {
|
||||
commitWithoutPaths(project, root, messageFile, author);
|
||||
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
|
||||
GitRepositoryManager manager = getRepositoryManager(project);
|
||||
manager.updateRepository(root);
|
||||
}
|
||||
catch (VcsException ex) {
|
||||
@@ -609,7 +611,7 @@ public class GitCheckinEnvironment implements CheckinEnvironment {
|
||||
handler.run();
|
||||
}
|
||||
if (!project.isDisposed()) {
|
||||
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
|
||||
GitRepositoryManager manager = getRepositoryManager(project);
|
||||
manager.updateRepository(root);
|
||||
}
|
||||
}
|
||||
@@ -712,7 +714,7 @@ public class GitCheckinEnvironment implements CheckinEnvironment {
|
||||
JLabel authorLabel = new JBLabel(GitBundle.message("commit.author"));
|
||||
authorLabel.setLabelFor(myAuthorField);
|
||||
|
||||
myAmendComponent = new MyAmendComponent(project, panel);
|
||||
myAmendComponent = new MyAmendComponent(project, getRepositoryManager(project), panel);
|
||||
mySignOffCheckbox = new JBCheckBox("Sign-off commit", mySettings.shouldSignOffCommit());
|
||||
mySignOffCheckbox.setMnemonic(KeyEvent.VK_G);
|
||||
mySignOffCheckbox.setToolTipText(getToolTip(project, panel));
|
||||
@@ -752,8 +754,8 @@ public class GitCheckinEnvironment implements CheckinEnvironment {
|
||||
}
|
||||
|
||||
private class MyAmendComponent extends AmendComponent {
|
||||
public MyAmendComponent(Project project, CheckinProjectPanel panel) {
|
||||
super(project, panel);
|
||||
public MyAmendComponent(@NotNull Project project, @NotNull GitRepositoryManager manager, @NotNull CheckinProjectPanel panel) {
|
||||
super(project, manager, panel);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -47,6 +47,7 @@ import org.zmlx.hg4idea.execution.HgCommandExecutor;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResult;
|
||||
import org.zmlx.hg4idea.provider.HgCurrentBinaryContentRevision;
|
||||
import org.zmlx.hg4idea.repo.HgRepository;
|
||||
import org.zmlx.hg4idea.repo.HgRepositoryManager;
|
||||
import org.zmlx.hg4idea.util.HgUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -56,6 +57,9 @@ import java.awt.event.ActionListener;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.util.ObjectUtils.assertNotNull;
|
||||
import static org.zmlx.hg4idea.util.HgUtil.getRepositoryManager;
|
||||
|
||||
public class HgCheckinEnvironment implements CheckinEnvironment {
|
||||
|
||||
private final Project myProject;
|
||||
@@ -316,17 +320,17 @@ public class HgCheckinEnvironment implements CheckinEnvironment {
|
||||
@NotNull private final JCheckBox myCommitSubrepos;
|
||||
|
||||
public HgCommitAdditionalComponent(@NotNull Project project, @NotNull CheckinProjectPanel panel) {
|
||||
HgVcs myVcs = HgVcs.getInstance(myProject);
|
||||
HgVcs vcs = assertNotNull(HgVcs.getInstance(myProject));
|
||||
|
||||
myAmend = new MyAmendComponent(project, panel, "Amend Commit (QRefresh)");
|
||||
myAmend.getComponent().setEnabled(myVcs != null && myVcs.getVersion().isAmendSupported());
|
||||
myAmend = new MyAmendComponent(project, getRepositoryManager(project), panel, "Amend Commit (QRefresh)");
|
||||
myAmend.getComponent().setEnabled(vcs.getVersion().isAmendSupported());
|
||||
|
||||
myCommitSubrepos = new JCheckBox("Commit subrepositories", false);
|
||||
myCommitSubrepos.setToolTipText(XmlStringUtil.wrapInHtml(
|
||||
"Commit all subrepos for selected repositories.<br>" +
|
||||
" <code>hg ci <i><b>files</b></i> -S <i><b>subrepos</b></i></code>"));
|
||||
myCommitSubrepos.setMnemonic('s');
|
||||
Collection<HgRepository> repos = HgActionUtil.collectRepositoriesFromFiles(HgUtil.getRepositoryManager(myProject), panel.getRoots());
|
||||
Collection<HgRepository> repos = HgActionUtil.collectRepositoriesFromFiles(getRepositoryManager(myProject), panel.getRoots());
|
||||
myCommitSubrepos.setVisible(ContainerUtil.exists(repos, HgRepository::hasSubrepos));
|
||||
|
||||
myCommitSubrepos.addActionListener(new MySelectionListener(myAmend.getCheckBox()));
|
||||
@@ -366,8 +370,11 @@ public class HgCheckinEnvironment implements CheckinEnvironment {
|
||||
}
|
||||
|
||||
private class MyAmendComponent extends AmendComponent {
|
||||
public MyAmendComponent(@NotNull Project project, @NotNull CheckinProjectPanel panel, @NotNull String title) {
|
||||
super(project, panel, title);
|
||||
public MyAmendComponent(@NotNull Project project,
|
||||
@NotNull HgRepositoryManager repoManager,
|
||||
@NotNull CheckinProjectPanel panel,
|
||||
@NotNull String title) {
|
||||
super(project, repoManager, panel, title);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user