mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-68087 hg: correctly parse "hg id" in case of 2 heads.
* HgWorkingCopyRevisionsCommand#identify returns 2 heads in the case of uncommitted merge. * In all places we take the first id. * HgIntegrateDialog removes current head accurate within "+". * HgIntegrateDialog modifies UI components in UI thread. [reviewed by irengrig]
This commit is contained in:
@@ -127,7 +127,7 @@ public class HgRevisionNumber implements VcsRevisionNumber {
|
||||
/**
|
||||
* Returns the numeric part of the revision, i. e. the revision without trailing '+' if one exists.
|
||||
*/
|
||||
private String getRevisionNumber() {
|
||||
public String getRevisionNumber() {
|
||||
if (isWorkingVersion) {
|
||||
return revision.substring(0, revision.length()-1);
|
||||
}
|
||||
|
||||
@@ -127,22 +127,37 @@ public class HgWorkingCopyRevisionsCommand {
|
||||
else return HgRevisionNumber.NULL_REVISION_NUMBER;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public HgRevisionNumber identify(@NotNull VirtualFile repo) {
|
||||
/**
|
||||
* Returns the result of 'hg id' execution, i.e. current state of the repository.
|
||||
* @return one or two revision numbers. Two revisions is the case of unresolved merge. In other cases there are only one revision.
|
||||
*/
|
||||
@NotNull
|
||||
public Pair<HgRevisionNumber, HgRevisionNumber> identify(@NotNull VirtualFile repo) {
|
||||
HgCommandExecutor commandExecutor = new HgCommandExecutor(myProject);
|
||||
commandExecutor.setSilent(true);
|
||||
HgCommandResult result = commandExecutor.executeInCurrentThread(repo, "identify", Arrays.asList("--num", "--id"));
|
||||
if (result == null) {
|
||||
return HgRevisionNumber.NULL_REVISION_NUMBER;
|
||||
return Pair.create(HgRevisionNumber.NULL_REVISION_NUMBER, null);
|
||||
}
|
||||
|
||||
final List<String> lines = result.getOutputLines();
|
||||
if (lines != null && !lines.isEmpty()) {
|
||||
String[] parts = StringUtils.split(lines.get(0), ' ');
|
||||
String changesets = parts[0];
|
||||
String revisions = parts[1];
|
||||
if (parts.length >= 2) {
|
||||
return HgRevisionNumber.getInstance(parts[1], parts[0]);
|
||||
if (changesets.indexOf('+') != changesets.lastIndexOf('+')) {
|
||||
// in the case of unresolved merge we have 2 revisions at once, both current, so with "+"
|
||||
// 9f2e6c02913c+b311eb4eb004+ 186+183+
|
||||
String[] chsets = StringUtils.split(changesets, "+");
|
||||
String[] revs = StringUtils.split(revisions, "+");
|
||||
return Pair.create(HgRevisionNumber.getInstance(revs[0] + "+", chsets[0] + "+"), HgRevisionNumber.getInstance(revs[1] + "+", chsets[1] + "+"));
|
||||
} else {
|
||||
return Pair.create(HgRevisionNumber.getInstance(revisions, changesets), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
return HgRevisionNumber.NULL_REVISION_NUMBER;
|
||||
return Pair.create(HgRevisionNumber.NULL_REVISION_NUMBER, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -80,7 +80,7 @@ public class HgChangeProvider implements ChangeProvider {
|
||||
for (Map.Entry<VirtualFile, Collection<FilePath>> entry : HgUtil.groupFilePathsByHgRoots(myProject, files).entrySet()) {
|
||||
VirtualFile repo = entry.getKey();
|
||||
|
||||
final HgRevisionNumber workingRevision = new HgWorkingCopyRevisionsCommand(myProject).identify(repo);
|
||||
final HgRevisionNumber workingRevision = new HgWorkingCopyRevisionsCommand(myProject).identify(repo).getFirst();
|
||||
final HgRevisionNumber parentRevision = new HgWorkingCopyRevisionsCommand(myProject).firstParent(repo);
|
||||
final Map<HgFile, HgResolveStatusEnum> list = new HgResolveCommand(myProject).getListSynchronously(repo);
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class HgDiffProvider implements DiffProvider {
|
||||
}
|
||||
|
||||
HgWorkingCopyRevisionsCommand command = new HgWorkingCopyRevisionsCommand(project);
|
||||
HgRevisionNumber currentRevision = command.identify(vcsRoot);
|
||||
HgRevisionNumber currentRevision = command.identify(vcsRoot).getFirst();
|
||||
if (currentRevision == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import javax.swing.event.ChangeListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -175,15 +176,24 @@ public class HgIntegrateDialog implements Configurable {
|
||||
return;
|
||||
}
|
||||
|
||||
otherHeadRadioButton.setVisible(true);
|
||||
otherHeadLabel.setVisible(true);
|
||||
|
||||
HgRevisionNumber currentParent = new HgWorkingCopyRevisionsCommand(project).identify(root);
|
||||
heads.remove(currentParent);
|
||||
HgRevisionNumber currentParent = new HgWorkingCopyRevisionsCommand(project).identify(root).getFirst();
|
||||
for (Iterator<HgRevisionNumber> it = heads.iterator() ; it.hasNext(); ) {
|
||||
final HgRevisionNumber rev = it.next();
|
||||
if (rev.getRevisionNumber().equals(currentParent.getRevisionNumber())) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
if (heads.size() == 1) {
|
||||
otherHead = heads.get(0);
|
||||
otherHeadLabel.setText(HgVcsMessages.message("hg4idea.integrate.other.head", otherHead.asString()));
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
otherHeadRadioButton.setVisible(true);
|
||||
otherHeadLabel.setVisible(true);
|
||||
otherHead = heads.get(0);
|
||||
otherHeadLabel.setText(HgVcsMessages.message("hg4idea.integrate.other.head", otherHead.asString()));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
//apparently we are not at one of the heads
|
||||
disableOtherHeadsChoice();
|
||||
@@ -193,8 +203,13 @@ public class HgIntegrateDialog implements Configurable {
|
||||
}
|
||||
|
||||
private void disableOtherHeadsChoice() {
|
||||
otherHeadLabel.setVisible(false);
|
||||
otherHeadRadioButton.setVisible(false);
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
otherHeadLabel.setVisible(false);
|
||||
otherHeadRadioButton.setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private List<VirtualFile> pathsToFiles(Collection<FilePath> paths) {
|
||||
|
||||
@@ -120,9 +120,9 @@ public class HgUpdateTest extends HgCollaborativeTest {
|
||||
List<HgRevisionNumber> branchHeads = new HgHeadsCommand(myProject, projectRepoVirtualFile).execute();
|
||||
assertEquals(branchHeads.size(), 2);
|
||||
|
||||
HgRevisionNumber parentBeforeUpdate = new HgWorkingCopyRevisionsCommand(myProject).identify(projectRepoVirtualFile);
|
||||
HgRevisionNumber parentBeforeUpdate = new HgWorkingCopyRevisionsCommand(myProject).identify(projectRepoVirtualFile).getFirst();
|
||||
assertUpdateThroughPluginFails();
|
||||
HgRevisionNumber parentAfterUpdate = new HgWorkingCopyRevisionsCommand(myProject).identify(projectRepoVirtualFile);
|
||||
HgRevisionNumber parentAfterUpdate = new HgWorkingCopyRevisionsCommand(myProject).identify(projectRepoVirtualFile).getFirst();
|
||||
List<HgRevisionNumber> branchHeadsAfterUpdate = new HgHeadsCommand(myProject, projectRepoVirtualFile).execute();
|
||||
|
||||
assertEquals(branchHeadsAfterUpdate.size(), 3);
|
||||
|
||||
Reference in New Issue
Block a user