comparison mainwindow.cpp @ 150:fb697ce0f625

* Attempt to make the sequence of hg commands after a change more rational; avoid incremental log if heads unchanged
author Chris Cannam
date Thu, 02 Dec 2010 11:31:42 +0000
parents 38faf16df9b6
children c91445ee3d57
comparison
equal deleted inserted replaced
149:38faf16df9b6 150:fb697ce0f625
196 params << Changeset::getLogTemplate(); 196 params << Changeset::getLogTemplate();
197 197
198 runner->requestAction(HgAction(ACT_LOG, workFolderPath, params)); 198 runner->requestAction(HgAction(ACT_LOG, workFolderPath, params));
199 } 199 }
200 200
201 void MainWindow::hgLogIncremental() 201 void MainWindow::hgLogIncremental(QStringList prune)
202 { 202 {
203 QStringList params; 203 QStringList params;
204 params << "log"; 204 params << "log";
205 205
206 foreach (Changeset *head, currentHeads) { 206 foreach (QString p, prune) {
207 int n = head->number(); 207 params << "--prune" << p;
208 params << "--prune" << QString("%1").arg(n);
209 } 208 }
210 209
211 params << "--template"; 210 params << "--template";
212 params << Changeset::getLogTemplate(); 211 params << Changeset::getLogTemplate();
213 212
1180 .arg(xmlEncode(output.left(800)) 1179 .arg(xmlEncode(output.left(800))
1181 .replace("\n", "<br>")) 1180 .replace("\n", "<br>"))
1182 : ""); 1181 : "");
1183 1182
1184 QMessageBox::warning(this, tr("Command failed"), message); 1183 QMessageBox::warning(this, tr("Command failed"), message);
1185 } 1184
1186 1185 /* todo:
1187 void MainWindow::commandCompleted(HgAction completedAction, QString output)
1188 {
1189 bool shouldHgStat = false;
1190
1191 HGACTIONS action = completedAction.action;
1192
1193 if (action == ACT_NONE) return;
1194
1195 switch(action) {
1196
1197 case ACT_QUERY_PATHS:
1198 {
1199 DEBUG << "stdout is " << output << endl;
1200 LogParser lp(output, "=");
1201 LogList ll = lp.parse();
1202 DEBUG << ll.size() << " results" << endl;
1203 if (!ll.empty()) {
1204 remoteRepoPath = lp.parse()[0]["default"].trimmed();
1205 DEBUG << "Set remote path to " << remoteRepoPath << endl;
1206 }
1207 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
1208 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
1209 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath);
1210 break;
1211 }
1212
1213 case ACT_QUERY_BRANCH:
1214 currentBranch = output.trimmed();
1215 break;
1216
1217 case ACT_STAT:
1218 hgTabs->updateWorkFolderFileList(output);
1219 updateFileSystemWatcher();
1220 break;
1221
1222 case ACT_INCOMING:
1223 showIncoming(output);
1224 break;
1225
1226 case ACT_ANNOTATE:
1227 case ACT_RESOLVE_LIST:
1228 case ACT_RESOLVE_MARK:
1229 presentLongStdoutToUser(output);
1230 shouldHgStat = true;
1231 break;
1232
1233 case ACT_PULL:
1234 showPullResult(output);
1235 shouldHgStat = true;
1236 break;
1237
1238 case ACT_PUSH:
1239 showPushResult(output);
1240 break;
1241
1242 case ACT_INIT:
1243 MultiChoiceDialog::addRecentArgument("init", workFolderPath);
1244 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
1245 enableDisableActions();
1246 shouldHgStat = true;
1247 break;
1248
1249 case ACT_CLONEFROMREMOTE:
1250 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
1251 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
1252 MultiChoiceDialog::addRecentArgument("remote", workFolderPath, true);
1253 QMessageBox::information(this, "Clone", output);
1254 enableDisableActions();
1255 shouldHgStat = true;
1256 break;
1257
1258 case ACT_LOG:
1259 hgTabs->setNewLog(output);
1260 needNewLog = false;
1261 break;
1262
1263 case ACT_LOG_INCREMENTAL:
1264 hgTabs->addIncrementalLog(output);
1265 break;
1266
1267 case ACT_QUERY_PARENTS:
1268 foreach (Changeset *cs, currentParents) delete cs;
1269 currentParents = Changeset::parseChangesets(output);
1270 break;
1271
1272 case ACT_QUERY_HEADS:
1273 foreach (Changeset *cs, currentHeads) delete cs;
1274 currentHeads = Changeset::parseChangesets(output);
1275 break;
1276
1277 case ACT_COMMIT:
1278 hgTabs->clearSelections();
1279 shouldHgStat = true;
1280 break;
1281
1282 case ACT_REMOVE:
1283 case ACT_ADD:
1284 case ACT_REVERT:
1285 hgTabs->clearSelections();
1286 shouldHgStat = true;
1287 break;
1288
1289 case ACT_FILEDIFF:
1290 case ACT_FOLDERDIFF:
1291 case ACT_CHGSETDIFF:
1292 case ACT_SERVE:
1293 case ACT_TAG:
1294 case ACT_HG_IGNORE:
1295 shouldHgStat = true;
1296 break;
1297
1298 case ACT_UPDATE:
1299 QMessageBox::information(this, tr("Update"), output);
1300 shouldHgStat = true;
1301 break;
1302
1303 case ACT_MERGE:
1304 QMessageBox::information(this, tr("Merge"), output);
1305 shouldHgStat = true;
1306 justMerged = true;
1307 break;
1308
1309 case ACT_RETRY_MERGE:
1310 QMessageBox::information(this, tr("Merge retry"), tr("Merge retry successful."));
1311 shouldHgStat = true;
1312 justMerged = true;
1313 break;
1314
1315 default:
1316 break;
1317 }
1318
1319 enableDisableActions();
1320
1321 // Sequence when no full log required:
1322 // paths -> branch -> stat -> incremental-log -> heads -> parents
1323 // Sequence when full log required:
1324 // paths -> branch -> stat -> heads -> parents -> log
1325 if (action == ACT_QUERY_PATHS) {
1326 hgQueryBranch();
1327 } else if (action == ACT_QUERY_BRANCH) {
1328 hgStat();
1329 } else if (action == ACT_STAT) {
1330 if (!needNewLog) {
1331 hgLogIncremental();
1332 } else {
1333 hgQueryHeads();
1334 }
1335 } else if (action == ACT_LOG_INCREMENTAL) {
1336 hgQueryHeads();
1337 } else if (action == ACT_QUERY_HEADS) {
1338 hgQueryParents();
1339 } else if (action == ACT_QUERY_PARENTS) {
1340 if (needNewLog) {
1341 hgLog();
1342 }
1343 } else
1344 /* Move to commandFailed
1345 if ((runningAction == ACT_MERGE) && (exitCode != 0)) 1186 if ((runningAction == ACT_MERGE) && (exitCode != 0))
1346 { 1187 {
1347 // If we had a failed merge, offer to retry 1188 // If we had a failed merge, offer to retry
1348 if (QMessageBox::Ok == QMessageBox::information(this, tr("Retry merge ?"), tr("Merge attempt failed. retry ?"), QMessageBox::Ok | QMessageBox::Cancel)) 1189 if (QMessageBox::Ok == QMessageBox::information(this, tr("Retry merge ?"), tr("Merge attempt failed. retry ?"), QMessageBox::Ok | QMessageBox::Cancel))
1349 { 1190 {
1357 } 1198 }
1358 } 1199 }
1359 else 1200 else
1360 { 1201 {
1361 */ 1202 */
1203 }
1204
1205 void MainWindow::commandCompleted(HgAction completedAction, QString output)
1206 {
1207 HGACTIONS action = completedAction.action;
1208
1209 if (action == ACT_NONE) return;
1210
1211 bool shouldHgStat = false;
1212 bool headsChanged = false;
1213 QStringList oldHeadIds;
1214
1215 switch (action) {
1216
1217 case ACT_QUERY_PATHS:
1218 {
1219 DEBUG << "stdout is " << output << endl;
1220 LogParser lp(output, "=");
1221 LogList ll = lp.parse();
1222 DEBUG << ll.size() << " results" << endl;
1223 if (!ll.empty()) {
1224 remoteRepoPath = lp.parse()[0]["default"].trimmed();
1225 DEBUG << "Set remote path to " << remoteRepoPath << endl;
1226 }
1227 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
1228 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
1229 hgTabs->setWorkFolderAndRepoNames(workFolderPath, remoteRepoPath);
1230 break;
1231 }
1232
1233 case ACT_QUERY_BRANCH:
1234 currentBranch = output.trimmed();
1235 break;
1236
1237 case ACT_STAT:
1238 hgTabs->updateWorkFolderFileList(output);
1239 updateFileSystemWatcher();
1240 break;
1241
1242 case ACT_INCOMING:
1243 showIncoming(output);
1244 break;
1245
1246 case ACT_ANNOTATE:
1247 case ACT_RESOLVE_LIST:
1248 case ACT_RESOLVE_MARK:
1249 presentLongStdoutToUser(output);
1250 shouldHgStat = true;
1251 break;
1252
1253 case ACT_PULL:
1254 showPullResult(output);
1255 shouldHgStat = true;
1256 break;
1257
1258 case ACT_PUSH:
1259 showPushResult(output);
1260 break;
1261
1262 case ACT_INIT:
1263 MultiChoiceDialog::addRecentArgument("init", workFolderPath);
1264 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
1265 enableDisableActions();
1266 shouldHgStat = true;
1267 break;
1268
1269 case ACT_CLONEFROMREMOTE:
1270 MultiChoiceDialog::addRecentArgument("local", workFolderPath);
1271 MultiChoiceDialog::addRecentArgument("remote", remoteRepoPath);
1272 MultiChoiceDialog::addRecentArgument("remote", workFolderPath, true);
1273 QMessageBox::information(this, "Clone", output);
1274 enableDisableActions();
1275 shouldHgStat = true;
1276 break;
1277
1278 case ACT_LOG:
1279 hgTabs->setNewLog(output);
1280 needNewLog = false;
1281 break;
1282
1283 case ACT_LOG_INCREMENTAL:
1284 hgTabs->addIncrementalLog(output);
1285 break;
1286
1287 case ACT_QUERY_PARENTS:
1288 foreach (Changeset *cs, currentParents) delete cs;
1289 currentParents = Changeset::parseChangesets(output);
1290 break;
1291
1292 case ACT_QUERY_HEADS:
1293 {
1294 oldHeadIds = Changeset::getIds(currentHeads);
1295 Changesets newHeads = Changeset::parseChangesets(output);
1296 QStringList newHeadIds = Changeset::getIds(newHeads);
1297 if (oldHeadIds != newHeadIds) {
1298 DEBUG << "Heads changed, will prompt an incremental log if appropriate" << endl;
1299 headsChanged = true;
1300 foreach (Changeset *cs, currentHeads) delete cs;
1301 currentHeads = newHeads;
1302 }
1303 }
1304 break;
1305
1306 case ACT_COMMIT:
1307 hgTabs->clearSelections();
1308 shouldHgStat = true;
1309 break;
1310
1311 case ACT_REMOVE:
1312 case ACT_ADD:
1313 case ACT_REVERT:
1314 hgTabs->clearSelections();
1315 shouldHgStat = true;
1316 break;
1317
1318 case ACT_FILEDIFF:
1319 case ACT_FOLDERDIFF:
1320 case ACT_CHGSETDIFF:
1321 case ACT_SERVE:
1322 case ACT_TAG:
1323 case ACT_HG_IGNORE:
1324 shouldHgStat = true;
1325 break;
1326
1327 case ACT_UPDATE:
1328 QMessageBox::information(this, tr("Update"), output);
1329 shouldHgStat = true;
1330 break;
1331
1332 case ACT_MERGE:
1333 QMessageBox::information(this, tr("Merge"), output);
1334 shouldHgStat = true;
1335 justMerged = true;
1336 break;
1337
1338 case ACT_RETRY_MERGE:
1339 QMessageBox::information(this, tr("Merge retry"),
1340 tr("Merge retry successful."));
1341 shouldHgStat = true;
1342 justMerged = true;
1343 break;
1344
1345 default:
1346 break;
1347 }
1348
1349 // Sequence when no full log required:
1350 // paths -> branch -> stat -> heads ->
1351 // incremental-log (only if heads changed) -> parents
1352 //
1353 // Sequence when full log required:
1354 // paths -> branch -> stat -> heads -> parents -> log
1355 //
1356 // Note we want to call enableDisableActions only once, at the end
1357 // of whichever sequence is in use.
1358
1359 switch (action) {
1360
1361 case ACT_QUERY_PATHS:
1362 hgQueryBranch();
1363 break;
1364
1365 case ACT_QUERY_BRANCH:
1366 hgStat();
1367 break;
1368
1369 case ACT_STAT:
1370 hgQueryHeads();
1371 break;
1372
1373 case ACT_QUERY_HEADS:
1374 if (headsChanged && !needNewLog) {
1375 hgLogIncremental(oldHeadIds);
1376 } else {
1377 hgQueryParents();
1378 }
1379 break;
1380
1381 case ACT_LOG_INCREMENTAL:
1382 hgQueryParents();
1383 break;
1384
1385 case ACT_QUERY_PARENTS:
1386 if (needNewLog) {
1387 hgLog();
1388 } else {
1389 // we're done
1390 enableDisableActions();
1391 }
1392 break;
1393
1394 case ACT_LOG:
1395 // we're done
1396 enableDisableActions();
1397
1398 default:
1362 if (shouldHgStat) { 1399 if (shouldHgStat) {
1363 hgQueryPaths(); 1400 hgQueryPaths();
1364 } 1401 } else {
1402 enableDisableActions();
1403 }
1404 break;
1405 }
1365 } 1406 }
1366 1407
1367 void MainWindow::connectActions() 1408 void MainWindow::connectActions()
1368 { 1409 {
1369 connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); 1410 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));