Fix pressing "Push" before completely loading the list of commits

Selected repositories are gotten from GitPushLog, which can be not constructed yet.
In that case use all repositories.
This commit is contained in:
Kirill Likhodedov
2012-03-10 16:14:54 +04:00
parent fd1cdddce3
commit 753b3ced72
2 changed files with 20 additions and 14 deletions
@@ -178,14 +178,13 @@ public class GitPushDialog extends DialogWrapper {
try {
LOG.info("collectInfoToPush...");
myPushSpecs = pushSpecsForCurrentOrEnteredBranches();
LOG.info("PushSpecsForCurrentOrEnteredBranches: " + myPushSpecs);
myGitCommitsToPush = myPusher.collectCommitsToPush(myPushSpecs);
LOG.info("Collected commits to push: " + logMessageForCommits(myGitCommitsToPush));
LOG.info("collectInfoToPush | Collected commits to push: " + logMessageForCommits(myGitCommitsToPush));
return null;
}
catch (VcsException e) {
myGitCommitsToPush = GitCommitsByRepoAndBranch.empty();
LOG.error("Couldn't collect commits to push. Push spec: " + myPushSpecs, e);
LOG.error("collectInfoToPush | Couldn't collect commits to push. Push spec: " + myPushSpecs, e);
return e.getMessage();
}
}
@@ -272,7 +271,7 @@ public class GitPushDialog extends DialogWrapper {
// waiting for commit list loading, because this information is needed to correctly handle rejected push situation and correctly
// notify about pushed commits
// TODO optimize: don't refresh: information about pushed commits can be achieved from the successful push output
LOG.info("getPushInfo");
LOG.info("getPushInfo start");
synchronized (COMMITS_LOADING_LOCK) {
GitCommitsByRepoAndBranch selectedCommits;
if (myGitCommitsToPush == null) {
@@ -61,6 +61,7 @@ class GitPushLog extends JPanel implements TypeSafeDataProvider {
private final DefaultTreeModel myTreeModel;
private final CheckedTreeNode myRootNode;
private final ReentrantReadWriteLock TREE_CONSTRUCTION_LOCK = new ReentrantReadWriteLock();
private boolean myTreeWasConstructed;
private final MyTreeCellRenderer myTreeCellRenderer;
GitPushLog(@NotNull Project project, @NotNull Collection<GitRepository> repositories, @NotNull final Consumer<Boolean> checkboxListener) {
@@ -166,6 +167,7 @@ class GitPushLog extends JPanel implements TypeSafeDataProvider {
myTree.setModel(myTreeModel); // TODO: why doesn't it repaint otherwise?
TreeUtil.expandAll(myTree);
selectFirstCommit();
myTreeWasConstructed = true;
}
finally {
TREE_CONSTRUCTION_LOCK.writeLock().unlock();
@@ -259,23 +261,28 @@ class GitPushLog extends JPanel implements TypeSafeDataProvider {
try {
TREE_CONSTRUCTION_LOCK.readLock().lock(); // wait for tree to be constructed
Collection<GitRepository> selectedRepositories = new ArrayList<GitRepository>(myAllRepositories.size());
if (myRootNode.getChildCount() == 0) { // the method is requested before tree construction began => returning all repos.
if (!myTreeWasConstructed) {
return myAllRepositories;
}
else {
Collection<GitRepository> selectedRepositories = new ArrayList<GitRepository>(myAllRepositories.size());
if (myRootNode.getChildCount() == 0) { // the method is requested before tree construction began => returning all repos.
return myAllRepositories;
}
for (int i = 0; i < myRootNode.getChildCount(); i++) {
TreeNode child = myRootNode.getChildAt(i);
if (child instanceof CheckedTreeNode) {
CheckedTreeNode node = (CheckedTreeNode)child;
if (node.isChecked()) {
if (node.getUserObject() instanceof GitRepository) {
selectedRepositories.add((GitRepository)node.getUserObject());
for (int i = 0; i < myRootNode.getChildCount(); i++) {
TreeNode child = myRootNode.getChildAt(i);
if (child instanceof CheckedTreeNode) {
CheckedTreeNode node = (CheckedTreeNode)child;
if (node.isChecked()) {
if (node.getUserObject() instanceof GitRepository) {
selectedRepositories.add((GitRepository)node.getUserObject());
}
}
}
}
return selectedRepositories;
}
return selectedRepositories;
}
finally {
TREE_CONSTRUCTION_LOCK.readLock().unlock();