comparison mainwindow.cpp @ 108:8ae3b44c0073

* Enable/disable update and merge actions depending on whether default update and merge will actually do anything
author Chris Cannam
date Thu, 25 Nov 2010 21:08:17 +0000
parents fdca34c989c0
children 1721c580c10e
comparison
equal deleted inserted replaced
107:fdca34c989c0 108:8ae3b44c0073
360 } else { 360 } else {
361 // Commit all changes 361 // Commit all changes
362 params << "commit" << "--message" << comment << "--user" << getUserInfo(); 362 params << "commit" << "--message" << comment << "--user" << getUserInfo();
363 } 363 }
364 364
365 runner -> startHgCommand(workFolderPath, params, true); 365 runner -> startHgCommand(workFolderPath, params, false);
366 runningAction = ACT_COMMIT; 366 runningAction = ACT_COMMIT;
367 } 367 }
368 } 368 }
369 } 369 }
370 370
1120 runner -> hideProgBar(); 1120 runner -> hideProgBar();
1121 1121
1122 //Clumsy... 1122 //Clumsy...
1123 if ((EXITOK(exitCode)) || ((exitCode == 1) && (runningAction == ACT_INCOMING))) 1123 if ((EXITOK(exitCode)) || ((exitCode == 1) && (runningAction == ACT_INCOMING)))
1124 { 1124 {
1125 QString output = runner->getOutput();
1126
1125 //Successful running. 1127 //Successful running.
1126 switch(runningAction) 1128 switch(runningAction)
1127 { 1129 {
1128 case ACT_PATHS: 1130 case ACT_PATHS:
1129 { 1131 {
1130 QString sout = runner->getOutput(); 1132 DEBUG << "stdout is " << output << endl;
1131 DEBUG << "stdout is " << sout << endl; 1133 LogParser lp(output, "=");
1132 LogParser lp(sout, "=");
1133 LogList ll = lp.parse(); 1134 LogList ll = lp.parse();
1134 DEBUG << ll.size() << " results" << endl; 1135 DEBUG << ll.size() << " results" << endl;
1135 if (!ll.empty()) { 1136 if (!ll.empty()) {
1136 remoteRepoPath = lp.parse()[0]["default"].trimmed(); 1137 remoteRepoPath = lp.parse()[0]["default"].trimmed();
1137 DEBUG << "Set remote path to " << remoteRepoPath << endl; 1138 DEBUG << "Set remote path to " << remoteRepoPath << endl;
1142 enableDisableActions(); 1143 enableDisableActions();
1143 break; 1144 break;
1144 } 1145 }
1145 1146
1146 case ACT_BRANCH: 1147 case ACT_BRANCH:
1147 currentBranch = runner->getOutput().trimmed(); 1148 currentBranch = output.trimmed();
1148 hgTabs->setBranch(currentBranch); 1149 hgTabs->setBranch(currentBranch);
1149 break; 1150 break;
1150 1151
1151 case ACT_STAT: 1152 case ACT_STAT:
1152 hgTabs -> updateWorkFolderFileList(runner -> getOutput()); 1153 hgTabs -> updateWorkFolderFileList(output);
1153 updateFileSystemWatcher(); 1154 updateFileSystemWatcher();
1154 break; 1155 break;
1155 1156
1156 case ACT_INCOMING: 1157 case ACT_INCOMING:
1157 case ACT_ANNOTATE: 1158 case ACT_ANNOTATE:
1158 case ACT_RESOLVE_LIST: 1159 case ACT_RESOLVE_LIST:
1159 case ACT_RESOLVE_MARK: 1160 case ACT_RESOLVE_MARK:
1160 presentLongStdoutToUser(runner -> getOutput()); 1161 presentLongStdoutToUser(output);
1161 shouldHgStat = true; 1162 shouldHgStat = true;
1162 break; 1163 break;
1163 1164
1164 case ACT_PULL: 1165 case ACT_PULL:
1165 QMessageBox::information(this, "Pull", runner -> getOutput()); 1166 QMessageBox::information(this, "Pull", output);
1166 shouldHgStat = true; 1167 shouldHgStat = true;
1167 break; 1168 break;
1168 1169
1169 case ACT_PUSH: 1170 case ACT_PUSH:
1170 QMessageBox::information(this, "Push", runner -> getOutput()); 1171 QMessageBox::information(this, "Push", output);
1171 shouldHgStat = true; 1172 shouldHgStat = true;
1172 break; 1173 break;
1173 1174
1174 case ACT_INIT: 1175 case ACT_INIT:
1175 MultiChoiceDialog::addRecentArgument("init", workFolderPath); 1176 MultiChoiceDialog::addRecentArgument("init", workFolderPath);
1180 1181
1181 case ACT_CLONEFROMREMOTE: 1182 case ACT_CLONEFROMREMOTE:
1182 MultiChoiceDialog::addRecentArgument("local", workFolderPath); 1183 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
1183 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath); 1184 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
1184 MultiChoiceDialog::addRecentArgument("remote", workFolderPath, true); 1185 MultiChoiceDialog::addRecentArgument("remote", workFolderPath, true);
1185 QMessageBox::information(this, "Clone", runner -> getOutput()); 1186 QMessageBox::information(this, "Clone", output);
1186 enableDisableActions(); 1187 enableDisableActions();
1187 shouldHgStat = true; 1188 shouldHgStat = true;
1188 break; 1189 break;
1189 1190
1190 case ACT_LOG: 1191 case ACT_LOG:
1191 hgTabs -> updateLocalRepoHgLogList(runner -> getOutput()); 1192 hgTabs -> updateLocalRepoHgLogList(output);
1192 break; 1193 break;
1193 1194
1194 case ACT_PARENTS: 1195 case ACT_PARENTS:
1195 { 1196 foreach (Changeset *cs, currentParents) delete cs;
1196 //!!! hgTabs -> updateLocalRepoParentsList(runner -> getOutput()); 1197 currentParents = Changeset::parseChangesets(output);
1197 }
1198 break; 1198 break;
1199 1199
1200 case ACT_HEADS: 1200 case ACT_HEADS:
1201 { 1201 foreach (Changeset *cs, currentHeads) delete cs;
1202 foreach (Changeset *cs, currentHeads) delete cs; 1202 currentHeads = Changeset::parseChangesets(output);
1203 currentHeads.clear();
1204 QString output = runner -> getOutput();
1205 DEBUG << "heads output is: " << output << endl;
1206 LogList log = LogParser(output).parse();
1207 foreach (LogEntry e, log) {
1208 currentHeads.push_back(new Changeset(e));
1209 }
1210 }
1211 break; 1203 break;
1212 1204
1213 case ACT_REMOVE: 1205 case ACT_REMOVE:
1214 case ACT_ADD: 1206 case ACT_ADD:
1215 case ACT_COMMIT: 1207 case ACT_COMMIT:
1222 case ACT_HG_IGNORE: 1214 case ACT_HG_IGNORE:
1223 shouldHgStat = true; 1215 shouldHgStat = true;
1224 break; 1216 break;
1225 1217
1226 case ACT_UPDATE: 1218 case ACT_UPDATE:
1227 QMessageBox::information(this, tr("Update"), runner -> getOutput()); 1219 QMessageBox::information(this, tr("Update"), output);
1228 shouldHgStat = true; 1220 shouldHgStat = true;
1229 break; 1221 break;
1230 1222
1231 case ACT_MERGE: 1223 case ACT_MERGE:
1232 QMessageBox::information(this, tr("Merge"), runner -> getOutput()); 1224 QMessageBox::information(this, tr("Merge"), output);
1233 shouldHgStat = true; 1225 shouldHgStat = true;
1234 justMerged = true; 1226 justMerged = true;
1235 break; 1227 break;
1236 1228
1237 case ACT_RETRY_MERGE: 1229 case ACT_RETRY_MERGE:
1416 hgRemoveAct->setEnabled(localRepoActionsEnabled && hgTabs->canRemove()); 1408 hgRemoveAct->setEnabled(localRepoActionsEnabled && hgTabs->canRemove());
1417 hgCommitAct->setEnabled(localRepoActionsEnabled && hgTabs->canCommit()); 1409 hgCommitAct->setEnabled(localRepoActionsEnabled && hgTabs->canCommit());
1418 hgRevertAct->setEnabled(localRepoActionsEnabled && hgTabs->canCommit()); 1410 hgRevertAct->setEnabled(localRepoActionsEnabled && hgTabs->canCommit());
1419 hgFolderDiffAct->setEnabled(localRepoActionsEnabled && hgTabs->canDoDiff()); 1411 hgFolderDiffAct->setEnabled(localRepoActionsEnabled && hgTabs->canDoDiff());
1420 1412
1413 // A default merge makes sense if:
1414 // * there is only one parent (if there are two, we have an uncommitted merge) and
1415 // * there are exactly two heads that have the same branch as the current branch and
1416 // * our parent is one of those heads
1417 //
1418 // A default update makes sense if:
1419 // * there is only one parent and
1420 // * the parent is not one of the current heads
1421 //!!! test this
1422 bool canMerge = false;
1423 bool canUpdate = false;
1424 if (currentParents.size() == 1) {
1425 Changeset *parent = currentParents[0];
1426 int currentBranchHeads = 0;
1427 bool parentIsHead = false;
1428 foreach (Changeset *head, currentHeads) {
1429 DEBUG << "head branch " << head->branch() << ", current branch " << currentBranch << endl;
1430 if (head->isOnBranch(currentBranch)) {
1431 ++currentBranchHeads;
1432 if (parent->id() == head->id()) {
1433 parentIsHead = true;
1434 }
1435 }
1436 }
1437 if (currentBranchHeads == 2 && parentIsHead) {
1438 canMerge = true;
1439 }
1440 if (!parentIsHead) {
1441 canUpdate = true;
1442 DEBUG << "parent id = " << parent->id() << endl;
1443 DEBUG << " head ids "<<endl;
1444 foreach (Changeset *h, currentHeads) {
1445 DEBUG << "head id = " << h->id() << endl;
1446 }
1447 }
1448 }
1449 hgMergeAct->setEnabled(localRepoActionsEnabled && canMerge);
1450 hgUpdateAct->setEnabled(localRepoActionsEnabled && canUpdate);
1451
1421 /*!!! 1452 /*!!!
1422 int added, modified, removed, notTracked, selected, selectedAdded, selectedModified, selectedRemoved, selectedNotTracked; 1453 int added, modified, removed, notTracked, selected, selectedAdded, selectedModified, selectedRemoved, selectedNotTracked;
1423 1454
1424 countModifications(hgTabs -> workFolderFileList, 1455 countModifications(hgTabs -> workFolderFileList,
1425 added, modified, removed, notTracked, 1456 added, modified, removed, notTracked,