Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py

changeset 1241
09c6155ee612
parent 1131
7781e396c903
child 1242
dfb9609caf51
equal deleted inserted replaced
1240:4d5fc346bd3b 1241:09c6155ee612
78 if mode in ("log", "incoming", "outgoing"): 78 if mode in ("log", "incoming", "outgoing"):
79 self.commandMode = mode 79 self.commandMode = mode
80 else: 80 else:
81 self.commandMode = "log" 81 self.commandMode = "log"
82 self.bundle = bundle 82 self.bundle = bundle
83 self.__hgClient = vcs.getClient()
83 84
84 self.__initData() 85 self.__initData()
85 86
86 self.__allBranchesFilter = self.trUtf8("All") 87 self.__allBranchesFilter = self.trUtf8("All")
87 88
104 self.__messageRole = Qt.UserRole 105 self.__messageRole = Qt.UserRole
105 self.__changesRole = Qt.UserRole + 1 106 self.__changesRole = Qt.UserRole + 1
106 self.__edgesRole = Qt.UserRole + 2 107 self.__edgesRole = Qt.UserRole + 2
107 self.__parentsRole = Qt.UserRole + 3 108 self.__parentsRole = Qt.UserRole + 3
108 109
109 self.process = QProcess() 110 if self.__hgClient:
110 self.process.finished.connect(self.__procFinished) 111 self.process = None
111 self.process.readyReadStandardOutput.connect(self.__readStdout) 112 else:
112 self.process.readyReadStandardError.connect(self.__readStderr) 113 self.process = QProcess()
114 self.process.finished.connect(self.__procFinished)
115 self.process.readyReadStandardOutput.connect(self.__readStdout)
116 self.process.readyReadStandardError.connect(self.__readStderr)
113 117
114 self.flags = { 118 self.flags = {
115 'A': self.trUtf8('Added'), 119 'A': self.trUtf8('Added'),
116 'D': self.trUtf8('Deleted'), 120 'D': self.trUtf8('Deleted'),
117 'M': self.trUtf8('Modified'), 121 'M': self.trUtf8('Modified'),
358 @return list of parent revisions (list of integers) 362 @return list of parent revisions (list of integers)
359 """ 363 """
360 errMsg = "" 364 errMsg = ""
361 parents = [-1] 365 parents = [-1]
362 366
363 process = QProcess()
364 args = [] 367 args = []
365 args.append("parents") 368 args.append("parents")
366 if self.commandMode == "incoming": 369 if self.commandMode == "incoming":
367 if self.bundle: 370 if self.bundle:
368 args.append("--repository") 371 args.append("--repository")
375 args.append("-r") 378 args.append("-r")
376 args.append(rev) 379 args.append(rev)
377 if not self.projectMode: 380 if not self.projectMode:
378 args.append(self.filename) 381 args.append(self.filename)
379 382
380 process.setWorkingDirectory(self.repodir) 383 output = ""
381 process.start('hg', args) 384 if self.__hgClient:
382 procStarted = process.waitForStarted() 385 output, errMsg = self.__hgClient.runcommand(args)
383 if procStarted: 386 else:
384 finished = process.waitForFinished(30000) 387 process = QProcess()
385 if finished and process.exitCode() == 0: 388 process.setWorkingDirectory(self.repodir)
386 output = \ 389 process.start('hg', args)
387 str(process.readAllStandardOutput(), 390 procStarted = process.waitForStarted()
388 Preferences.getSystem("IOEncoding"), 391 if procStarted:
389 'replace') 392 finished = process.waitForFinished(30000)
390 parents = [int(p) for p in output.strip().splitlines()] 393 if finished and process.exitCode() == 0:
394 output = \
395 str(process.readAllStandardOutput(),
396 Preferences.getSystem("IOEncoding"),
397 'replace')
398 else:
399 if not finished:
400 errMsg = self.trUtf8(
401 "The hg process did not finish within 30s.")
391 else: 402 else:
392 if not finished: 403 errMsg = self.trUtf8("Could not start the hg executable.")
393 errMsg = self.trUtf8(
394 "The hg process did not finish within 30s.")
395 else:
396 errMsg = self.trUtf8("Could not start the hg executable.")
397 404
398 if errMsg: 405 if errMsg:
399 E5MessageBox.critical(self, 406 E5MessageBox.critical(self,
400 self.trUtf8("Mercurial Error"), 407 self.trUtf8("Mercurial Error"),
401 errMsg) 408 errMsg)
402 409
410 if output:
411 parents = [int(p) for p in output.strip().splitlines()]
412
403 return parents 413 return parents
404 414
405 def __identifyProject(self): 415 def __identifyProject(self):
406 """ 416 """
407 Private method to determine the revision of the project directory. 417 Private method to determine the revision of the project directory.
408 """ 418 """
409 errMsg = "" 419 errMsg = ""
410 420
411 process = QProcess()
412 args = [] 421 args = []
413 args.append("identify") 422 args.append("identify")
414 args.append("-n") 423 args.append("-n")
415 424
416 process.setWorkingDirectory(self.repodir) 425 output = ""
417 process.start('hg', args) 426 if self.__hgClient:
418 procStarted = process.waitForStarted() 427 output, errMsg = self.__hgClient.runcommand(args)
419 if procStarted: 428 else:
420 finished = process.waitForFinished(30000) 429 process = QProcess()
421 if finished and process.exitCode() == 0: 430 process.setWorkingDirectory(self.repodir)
422 output = \ 431 process.start('hg', args)
423 str(process.readAllStandardOutput(), 432 procStarted = process.waitForStarted()
424 Preferences.getSystem("IOEncoding"), 433 if procStarted:
425 'replace') 434 finished = process.waitForFinished(30000)
426 self.__projectRevision = output.strip() 435 if finished and process.exitCode() == 0:
427 if self.__projectRevision.endswith("+"): 436 output = \
428 self.__projectRevision = self.__projectRevision[:-1] 437 str(process.readAllStandardOutput(),
438 Preferences.getSystem("IOEncoding"),
439 'replace')
440 else:
441 if not finished:
442 errMsg = self.trUtf8(
443 "The hg process did not finish within 30s.")
429 else: 444 else:
430 if not finished: 445 errMsg = self.trUtf8("Could not start the hg executable.")
431 errMsg = self.trUtf8(
432 "The hg process did not finish within 30s.")
433 else:
434 errMsg = self.trUtf8("Could not start the hg executable.")
435 446
436 if errMsg: 447 if errMsg:
437 E5MessageBox.critical(self, 448 E5MessageBox.critical(self,
438 self.trUtf8("Mercurial Error"), 449 self.trUtf8("Mercurial Error"),
439 errMsg) 450 errMsg)
451
452 if output:
453 self.__projectRevision = output.strip()
454 if self.__projectRevision.endswith("+"):
455 self.__projectRevision = self.__projectRevision[:-1]
440 456
441 def __getClosedBranches(self): 457 def __getClosedBranches(self):
442 """ 458 """
443 Private method to get the list of closed branches. 459 Private method to get the list of closed branches.
444 """ 460 """
445 self.__closedBranchesRevs = [] 461 self.__closedBranchesRevs = []
446 errMsg = "" 462 errMsg = ""
447 463
448 process = QProcess()
449 args = [] 464 args = []
450 args.append("branches") 465 args.append("branches")
451 args.append("--closed") 466 args.append("--closed")
452 467
453 process.setWorkingDirectory(self.repodir) 468 output = ""
454 process.start('hg', args) 469 if self.__hgClient:
455 procStarted = process.waitForStarted() 470 output, errMsg = self.__hgClient.runcommand(args)
456 if procStarted: 471 else:
457 finished = process.waitForFinished(30000) 472 process = QProcess()
458 if finished and process.exitCode() == 0: 473 process.setWorkingDirectory(self.repodir)
459 output = \ 474 process.start('hg', args)
460 str(process.readAllStandardOutput(), 475 procStarted = process.waitForStarted()
461 Preferences.getSystem("IOEncoding"), 476 if procStarted:
462 'replace') 477 finished = process.waitForFinished(30000)
463 for line in output.splitlines(): 478 if finished and process.exitCode() == 0:
464 if line.strip().endswith("(closed)"): 479 output = \
465 parts = line.split() 480 str(process.readAllStandardOutput(),
466 self.__closedBranchesRevs.append( 481 Preferences.getSystem("IOEncoding"),
467 parts[-2].split(":", 1)[0]) 482 'replace')
483 else:
484 if not finished:
485 errMsg = self.trUtf8(
486 "The hg process did not finish within 30s.")
468 else: 487 else:
469 if not finished: 488 errMsg = self.trUtf8("Could not start the hg executable.")
470 errMsg = self.trUtf8(
471 "The hg process did not finish within 30s.")
472 else:
473 errMsg = self.trUtf8("Could not start the hg executable.")
474 489
475 if errMsg: 490 if errMsg:
476 E5MessageBox.critical(self, 491 E5MessageBox.critical(self,
477 self.trUtf8("Mercurial Error"), 492 self.trUtf8("Mercurial Error"),
478 errMsg) 493 errMsg)
494
495 if output:
496 for line in output.splitlines():
497 if line.strip().endswith("(closed)"):
498 parts = line.split()
499 self.__closedBranchesRevs.append(
500 parts[-2].split(":", 1)[0])
479 501
480 def __generateLogItem(self, author, date, message, revision, changedPaths, 502 def __generateLogItem(self, author, date, message, revision, changedPaths,
481 parents, branches, tags, bookmarks=None): 503 parents, branches, tags, bookmarks=None):
482 """ 504 """
483 Private method to generate a log tree entry. 505 Private method to generate a log tree entry.
583 QApplication.processEvents() 605 QApplication.processEvents()
584 606
585 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) 607 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
586 QApplication.processEvents() 608 QApplication.processEvents()
587 609
588 self.intercept = False
589 self.process.kill()
590
591 self.buf = [] 610 self.buf = []
592 self.cancelled = False 611 self.cancelled = False
593 self.errors.clear() 612 self.errors.clear()
594
595 self.inputGroup.setEnabled(True)
596 self.inputGroup.show()
597 613
598 args = [] 614 args = []
599 args.append(self.commandMode) 615 args.append(self.commandMode)
600 self.vcs.addArguments(args, self.vcs.options['global']) 616 self.vcs.addArguments(args, self.vcs.options['global'])
601 self.vcs.addArguments(args, self.vcs.options['log']) 617 self.vcs.addArguments(args, self.vcs.options['log'])
631 args.append('--bundle') 647 args.append('--bundle')
632 args.append(self.vcs.bundleFile) 648 args.append(self.vcs.bundleFile)
633 if not self.projectMode: 649 if not self.projectMode:
634 args.append(self.filename) 650 args.append(self.filename)
635 651
636 self.process.setWorkingDirectory(self.repodir) 652 if self.__hgClient:
637 653 out, err = self.__hgClient.runcommand(args)
638 self.process.start('hg', args) 654 self.buf = out.splitlines(True)
639 procStarted = self.process.waitForStarted() 655 if err:
640 if not procStarted: 656 self.__showError(err)
641 self.inputGroup.setEnabled(False) 657 self.__processBuffer()
642 E5MessageBox.critical(self, 658 self.__finish()
643 self.trUtf8('Process Generation Error'), 659 else:
644 self.trUtf8( 660 self.intercept = False
645 'The process {0} could not be started. ' 661 self.process.kill()
646 'Ensure, that it is in the search path.' 662
647 ).format('hg')) 663 self.process.setWorkingDirectory(self.repodir)
664
665 self.inputGroup.setEnabled(True)
666 self.inputGroup.show()
667
668 self.process.start('hg', args)
669 procStarted = self.process.waitForStarted()
670 if not procStarted:
671 self.inputGroup.setEnabled(False)
672 E5MessageBox.critical(self,
673 self.trUtf8('Process Generation Error'),
674 self.trUtf8(
675 'The process {0} could not be started. '
676 'Ensure, that it is in the search path.'
677 ).format('hg'))
648 678
649 def start(self, fn): 679 def start(self, fn):
650 """ 680 """
651 Public slot to start the hg log command. 681 Public slot to start the hg log command.
652 682
869 if self.process is not None: 899 if self.process is not None:
870 self.errorGroup.show() 900 self.errorGroup.show()
871 s = str(self.process.readAllStandardError(), 901 s = str(self.process.readAllStandardError(),
872 Preferences.getSystem("IOEncoding"), 902 Preferences.getSystem("IOEncoding"),
873 'replace') 903 'replace')
874 self.errors.insertPlainText(s) 904 self.__showError(s)
875 self.errors.ensureCursorVisible() 905
906 def __showError(self, out):
907 """
908 Private slot to show some error.
909
910 @param out error to be shown (string)
911 """
912 self.errorGroup.show()
913 self.errors.insertPlainText(out)
914 self.errors.ensureCursorVisible()
876 915
877 def __diffRevisions(self, rev1, rev2): 916 def __diffRevisions(self, rev1, rev2):
878 """ 917 """
879 Private method to do a diff of two revisions. 918 Private method to do a diff of two revisions.
880 919

eric ide

mercurial