comparison src/hgrunner.cpp @ 691:5b3bcb2d0943

Update handling of auth extension load failures on Windows: hg itself is returning a successful error code, so we must check the output in the extension test phase. Also fix a failure & crash when trying to use fallback auth mechanism
author Chris Cannam
date Mon, 10 Dec 2018 12:03:04 +0000
parents 4283398d248f
children 7194ca023517
comparison
equal deleted inserted replaced
690:bfafe078df9a 691:5b3bcb2d0943
42 #include <process.h> 42 #include <process.h>
43 #endif 43 #endif
44 44
45 HgRunner::HgRunner(QString myDirPath, QWidget *parent) : 45 HgRunner::HgRunner(QString myDirPath, QWidget *parent) :
46 QWidget(parent), 46 QWidget(parent),
47 m_myDirPath(myDirPath) 47 m_myDirPath(myDirPath),
48 m_ptyFile(0)
48 { 49 {
49 QGridLayout *layout = new QGridLayout(this); 50 QGridLayout *layout = new QGridLayout(this);
50 layout->setMargin(0); 51 layout->setMargin(0);
51 52
52 m_progress = new QProgressBar; 53 m_progress = new QProgressBar;
264 bool ok = false; 265 bool ok = false;
265 QString prompt = tr("User name:"); 266 QString prompt = tr("User name:");
266 if (m_realm != "") { 267 if (m_realm != "") {
267 prompt = tr("User name for \"%1\":").arg(m_realm); 268 prompt = tr("User name for \"%1\":").arg(m_realm);
268 } 269 }
269 QString pwd = QInputDialog::getText 270 QString name = QInputDialog::getText
270 (qobject_cast<QWidget *>(parent()), 271 (qobject_cast<QWidget *>(parent()),
271 tr("Enter user name"), prompt, 272 tr("Enter user name"), prompt,
272 QLineEdit::Normal, QString(), &ok); 273 QLineEdit::Normal, QString(), &ok);
273 if (ok) { 274 if (ok) {
274 m_ptyFile->write(QString("%1\n").arg(pwd).toUtf8()); 275 m_ptyFile->write(QString("%1\n").arg(name).toUtf8());
275 m_ptyFile->flush(); 276 m_ptyFile->flush();
276 return; 277 return;
277 } else { 278 } else {
278 DEBUG << "HgRunner::getUsername: user cancelled" << endl; 279 DEBUG << "HgRunner::getUsername: user cancelled" << endl;
279 killCurrentCommand(); 280 killCurrentCommand();
280 return; 281 return;
281 } 282 }
283 } else { // usual on win32
284 DEBUG << "HgRunner::getUsername: can't handle without pty" << endl;
285 emit commandFailed(m_currentAction, "", "Host requires authentication, but we can't handle that without the EasyHg extension loaded");
282 } 286 }
283 // user cancelled or something went wrong 287 // user cancelled or something went wrong
284 DEBUG << "HgRunner::getUsername: something went wrong" << endl; 288 DEBUG << "HgRunner::getUsername: something went wrong" << endl;
285 killCurrentCommand(); 289 killCurrentCommand();
286 } 290 }
299 .arg(m_userName); 303 .arg(m_userName);
300 } 304 }
301 } 305 }
302 QString pwd = QInputDialog::getText 306 QString pwd = QInputDialog::getText
303 (qobject_cast<QWidget *>(parent()), 307 (qobject_cast<QWidget *>(parent()),
304 tr("Enter password"), prompt, 308 tr("Enter password"), prompt,
305 QLineEdit::Password, QString(), &ok); 309 QLineEdit::Password, QString(), &ok);
306 if (ok) { 310 if (ok) {
307 m_ptyFile->write(QString("%1\n").arg(pwd).toUtf8()); 311 m_ptyFile->write(QString("%1\n").arg(pwd).toUtf8());
308 m_ptyFile->flush(); 312 m_ptyFile->flush();
309 return; 313 return;
310 } else { 314 } else {
311 DEBUG << "HgRunner::getPassword: user cancelled" << endl; 315 DEBUG << "HgRunner::getPassword: user cancelled" << endl;
312 killCurrentCommand(); 316 killCurrentCommand();
313 return; 317 return;
314 } 318 }
319 } else { // usual on win32
320 DEBUG << "HgRunner::getPassword: can't handle without pty" << endl;
321 emit commandFailed(m_currentAction, "", "Host requires authentication, but we can't handle that without the EasyHg extension loaded");
315 } 322 }
316 // user cancelled or something went wrong 323 // user cancelled or something went wrong
317 DEBUG << "HgRunner::getPassword: something went wrong" << endl; 324 DEBUG << "HgRunner::getPassword: something went wrong" << endl;
318 killCurrentCommand(); 325 killCurrentCommand();
319 } 326 }
403 410
404 if (completedAction.action == ACT_NONE) { 411 if (completedAction.action == ACT_NONE) {
405 DEBUG << "HgRunner::finished: WARNING: completed action is ACT_NONE" << endl; 412 DEBUG << "HgRunner::finished: WARNING: completed action is ACT_NONE" << endl;
406 } else { 413 } else {
407 if (procExitCode == 0 && procExitStatus == QProcess::NormalExit) { 414 if (procExitCode == 0 && procExitStatus == QProcess::NormalExit) {
408 DEBUG << "HgRunner::finished: Command completed successfully" 415 DEBUG << "HgRunner::finished: Command completed successfully" << endl;
409 << endl;
410 // DEBUG << "stdout is " << m_stdout << endl; 416 // DEBUG << "stdout is " << m_stdout << endl;
411 emit commandCompleted(completedAction, m_stdout); 417 emit commandCompleted(completedAction, m_stdout, m_stderr);
412 } else { 418 } else {
413 DEBUG << "HgRunner::finished: Command failed, exit code " 419 DEBUG << "HgRunner::finished: Command failed, exit code "
414 << procExitCode << ", exit status " << int(procExitStatus) 420 << procExitCode << ", exit status " << int(procExitStatus)
415 << ", stderr follows" << endl; 421 << ", stderr follows" << endl;
416 DEBUG << m_stderr << endl; 422 DEBUG << m_stderr << endl;
417 emit commandFailed(completedAction, m_stderr, m_stdout); 423 emit commandFailed(completedAction, m_stdout, m_stderr);
418 } 424 }
419 } 425 }
420 426
421 checkQueue(); 427 checkQueue();
422 } 428 }
548 554
549 void HgRunner::startCommand(HgAction action) 555 void HgRunner::startCommand(HgAction action)
550 { 556 {
551 if (action.workingDir.isEmpty()) { 557 if (action.workingDir.isEmpty()) {
552 // We require a working directory, never just operate in pwd 558 // We require a working directory, never just operate in pwd
553 emit commandFailed(action, "EasyMercurial: No working directory supplied, will not run Mercurial command without one", ""); 559 emit commandFailed(action, "", "EasyMercurial: No working directory supplied, will not run Mercurial command without one");
554 return; 560 return;
555 } 561 }
556 562
557 m_isRunning = true; 563 m_isRunning = true;
558 m_progress->setRange(0, 0); 564 m_progress->setRange(0, 0);