/** * The rebase operation is needed if the current branch is behind remote branch or if some commit * is not selected. * * @return true if rebase is needed for at least one vcs root */ private boolean isRebaseNeeded() { for (int i = 0; i < myTreeRoot.getChildCount(); i++) { CheckedTreeNode node = (CheckedTreeNode) myTreeRoot.getChildAt(i); Root r = (Root) node.getUserObject(); if (r.commits.size() == 0) { continue; } boolean seenCheckedNode = false; for (int j = 0; j < node.getChildCount(); j++) { if (node.getChildAt(j) instanceof CheckedTreeNode) { CheckedTreeNode commitNode = (CheckedTreeNode) node.getChildAt(j); if (commitNode.isChecked()) { seenCheckedNode = true; } else { if (seenCheckedNode) { return true; } } } } if (seenCheckedNode && r.remoteCommits > 0) { return true; } } return false; }
/** * From the dialog collects roots and commits to be pushed. * * @return roots to be pushed. */ private Collection<Root> getRootsToPush() { final ArrayList<Root> rootsToPush = new ArrayList<Root>(); for (int i = 0; i < myTreeRoot.getChildCount(); i++) { CheckedTreeNode node = (CheckedTreeNode) myTreeRoot.getChildAt(i); Root r = (Root) node.getUserObject(); if (r.remoteName == null || r.commits.size() == 0) { continue; } boolean topCommit = true; 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(); if (!topCommit) { r.commitToPush = commit.revision.asString(); } rootsToPush.add(r); break; } topCommit = false; } } } return rootsToPush; }
private void rebuildTree() { final TreeStateSnapshot treeStateSnapshot = new TreeStateSnapshot(this); myRootNode.removeAllChildren(); myDescriptorToNodeMap.clear(); myDescriptorToNodeMap.put((TreeDescriptor) myRootNode.getUserObject(), myRootNode); // build tree for (final Breakpoint breakpoint : myBreakpoints) { CheckedTreeNode node = createNode(new BreakpointDescriptor(breakpoint)); node.setChecked(breakpoint.ENABLED); addNode(node); } // remove all package nodes with one child final int count = myRootNode.getChildCount(); final List<CheckedTreeNode> children = new ArrayList<CheckedTreeNode>(); for (int idx = 0; idx < count; idx++) { CheckedTreeNode child = (CheckedTreeNode) myRootNode.getChildAt(idx); if (!(child.getUserObject() instanceof PackageDescriptor)) { children.add(child); continue; } while (child.getUserObject() instanceof PackageDescriptor && child.getChildCount() <= 1) { child = (CheckedTreeNode) child.getChildAt(0); } if (!(child.getUserObject() instanceof PackageDescriptor)) { child = (CheckedTreeNode) child.getParent(); } for (CheckedTreeNode childToRemove = (CheckedTreeNode) child.getParent(); !childToRemove.equals(myRootNode); childToRemove = (CheckedTreeNode) childToRemove.getParent()) { myDescriptorToNodeMap.remove(childToRemove.getUserObject()); } children.add(child); } for (final CheckedTreeNode aChildren : children) { aChildren.removeFromParent(); } myRootNode.removeAllChildren(); for (final CheckedTreeNode child : children) { myRootNode.add(child); } sortChildren(myRootNode); ((DefaultTreeModel) getModel()).nodeStructureChanged(myRootNode); treeStateSnapshot.restore(this); expandPath(new TreePath(myRootNode)); }
/** * Executes when FETCH button is pressed. Fetches repository in background. Then updates the * commit tree. */ private void fetch() { Map<VirtualFile, Set<String>> unchecked = new HashMap<VirtualFile, Set<String>>(); for (int i = 0; i < myTreeRoot.getChildCount(); i++) { Set<String> uncheckedCommits = new HashSet<String>(); CheckedTreeNode node = (CheckedTreeNode) myTreeRoot.getChildAt(i); Root r = (Root) node.getUserObject(); for (int j = 0; j < node.getChildCount(); j++) { if (node.getChildAt(j) instanceof CheckedTreeNode) { CheckedTreeNode commitNode = (CheckedTreeNode) node.getChildAt(j); if (!commitNode.isChecked()) { uncheckedCommits.add(((Commit) commitNode.getUserObject()).commitId()); } } } if (!uncheckedCommits.isEmpty()) { unchecked.put(r.root, uncheckedCommits); } } refreshTree(true, unchecked); }
private ToolsGroup[] getGroupList() { ArrayList<ToolsGroup> result = new ArrayList<ToolsGroup>(); MutableTreeNode root = (MutableTreeNode) myTree.getModel().getRoot(); for (int i = 0; i < root.getChildCount(); i++) { final CheckedTreeNode node = (CheckedTreeNode) root.getChildAt(i); for (int j = 0; j < node.getChildCount(); j++) { final CheckedTreeNode toolNode = (CheckedTreeNode) node.getChildAt(j); ((Tool) toolNode.getUserObject()).setEnabled(toolNode.isChecked()); } result.add((ToolsGroup) node.getUserObject()); } return result.toArray(new ToolsGroup[result.size()]); }
private void sortChildren(CheckedTreeNode node) { final int childCount = node.getChildCount(); if (childCount == 0) { return; } final List<CheckedTreeNode> children = new ArrayList<CheckedTreeNode>(childCount); for (int idx = 0; idx < childCount; idx++) { children.add((CheckedTreeNode) node.getChildAt(idx)); } for (CheckedTreeNode child : children) { sortChildren(child); child.removeFromParent(); } Collections.sort(children, myNodeComparator); for (CheckedTreeNode child : children) { node.add(child); } }
/** Update buttons on the form */ private void updateButtons() { String error = null; boolean wasCheckedNode = false; boolean reorderMerges = false; for (int i = 0; i < myTreeRoot.getChildCount(); i++) { CheckedTreeNode node = (CheckedTreeNode) myTreeRoot.getChildAt(i); boolean seenCheckedNode = false; boolean reorderNeeded = false; boolean seenMerges = false; boolean seenUnchecked = 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 { seenUnchecked = true; if (seenCheckedNode) { reorderNeeded = true; } } } } if (!seenCheckedNode) { continue; } Root r = (Root) node.getUserObject(); if (seenMerges && seenUnchecked) { error = GitBundle.getString("push.active.error.merges.unchecked"); } if (seenMerges && reorderNeeded) { reorderMerges = true; error = GitBundle.getString("push.active.error.reorder.merges"); } if (reorderNeeded) { if (error == null) { error = GitBundle.getString("push.active.error.reorder.needed"); } } if (r.currentBranch == null) { if (error == null) { error = GitBundle.getString("push.active.error.no.branch"); } break; } wasCheckedNode |= r.remoteBranch != null; if (r.remoteCommits != 0 && r.commits.size() != 0) { if (error == null) { error = GitBundle.getString("push.active.error.behind"); } break; } } boolean rebaseNeeded = isRebaseNeeded(); myPushButton.setEnabled(wasCheckedNode && error == null && !rebaseNeeded); setErrorText(error); myRebaseButton.setEnabled(rebaseNeeded && !reorderMerges); setOKActionEnabled(myPushButton.isEnabled() || myRebaseButton.isEnabled()); }
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); }