private RebaseInfo collectRebaseInfo() { final Set<VirtualFile> roots = new HashSet<VirtualFile>(); final Set<VirtualFile> rootsWithMerges = new HashSet<VirtualFile>(); final Map<VirtualFile, List<String>> reorderedCommits = new HashMap<VirtualFile, List<String>>(); final Map<VirtualFile, Set<String>> uncheckedCommits = new HashMap<VirtualFile, Set<String>>(); for (int i = 0; i < myTreeRoot.getChildCount(); i++) { CheckedTreeNode node = (CheckedTreeNode) myTreeRoot.getChildAt(i); Root r = (Root) node.getUserObject(); Set<String> unchecked = new HashSet<String>(); uncheckedCommits.put(r.root, unchecked); if (r.commits.size() == 0) { if (r.remoteCommits > 0) { roots.add(r.root); } continue; } boolean seenCheckedNode = false; boolean reorderNeeded = false; boolean seenMerges = false; for (int j = 0; j < node.getChildCount(); j++) { if (node.getChildAt(j) instanceof CheckedTreeNode) { CheckedTreeNode commitNode = (CheckedTreeNode) node.getChildAt(j); Commit commit = (Commit) commitNode.getUserObject(); seenMerges |= commit.isMerge; if (commitNode.isChecked()) { seenCheckedNode = true; } else { unchecked.add(commit.commitId()); if (seenCheckedNode) { reorderNeeded = true; } } } } if (seenMerges) { rootsWithMerges.add(r.root); } if (r.remoteCommits > 0 || reorderNeeded) { roots.add(r.root); } if (reorderNeeded) { List<String> reordered = new ArrayList<String>(); for (int j = 0; j < node.getChildCount(); j++) { if (node.getChildAt(j) instanceof CheckedTreeNode) { CheckedTreeNode commitNode = (CheckedTreeNode) node.getChildAt(j); if (!commitNode.isChecked()) { Commit commit = (Commit) commitNode.getUserObject(); reordered.add(commit.revision.asString()); } } } for (int j = 0; j < node.getChildCount(); j++) { if (node.getChildAt(j) instanceof CheckedTreeNode) { CheckedTreeNode commitNode = (CheckedTreeNode) node.getChildAt(j); if (commitNode.isChecked()) { Commit commit = (Commit) commitNode.getUserObject(); reordered.add(commit.revision.asString()); } } } Collections.reverse(reordered); reorderedCommits.put(r.root, reordered); } } final GitVcsSettings.UpdateChangesPolicy p = UpdatePolicyUtils.getUpdatePolicy(myStashRadioButton, myShelveRadioButton); assert p == GitVcsSettings.UpdateChangesPolicy.STASH || p == GitVcsSettings.UpdateChangesPolicy.SHELVE; return new RebaseInfo(reorderedCommits, rootsWithMerges, uncheckedCommits, roots, p); }
/** * Constructs new dialog. Loads settings, registers listeners. * * @param project the project * @param vcsRoots the vcs roots * @param roots the loaded information about roots */ private GitPushActiveBranchesDialog( final Project project, List<VirtualFile> vcsRoots, List<Root> roots) { super(project, true); myVcs = GitVcs.getInstance(project); myProject = project; myVcsRoots = vcsRoots; myGeneralSettings = GeneralSettings.getInstance(); myProjectManager = ProjectManagerEx.getInstanceEx(); updateTree(roots, null); updateUI(); final GitVcsSettings settings = GitVcsSettings.getInstance(project); if (settings != null) { UpdatePolicyUtils.updatePolicyItem( settings.getPushActiveBranchesRebaseSavePolicy(), myStashRadioButton, myShelveRadioButton); } ChangeListener listener = new ChangeListener() { public void stateChanged(ChangeEvent e) { if (settings != null) { settings.setPushActiveBranchesRebaseSavePolicy( UpdatePolicyUtils.getUpdatePolicy(myStashRadioButton, myShelveRadioButton)); } } }; myStashRadioButton.addChangeListener(listener); myShelveRadioButton.addChangeListener(listener); myCommitTree .getSelectionModel() .addTreeSelectionListener( new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { TreePath path = myCommitTree.getSelectionModel().getSelectionPath(); if (path == null) { myViewButton.setEnabled(false); return; } DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); myViewButton.setEnabled( node != null && myCommitTree.getSelectionCount() == 1 && node.getUserObject() instanceof Commit); } }); myViewButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { TreePath path = myCommitTree.getSelectionModel().getSelectionPath(); if (path == null) { return; } DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); if (node == null || !(node.getUserObject() instanceof Commit)) { return; } Commit c = (Commit) node.getUserObject(); GitShowAllSubmittedFilesAction.showSubmittedFiles( project, c.revision.asString(), c.root.root); } }); myFetchButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { fetch(); } }); myRebaseButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { rebase(); } }); myPushButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { push(); } }); setTitle(GitBundle.getString("push.active.title")); setOKButtonText(GitBundle.getString("push.active.rebase.and.push")); setCancelButtonText(GitBundle.getString("git.push.active.close")); init(); }