Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py

branch
Py2 comp.
changeset 2677
3d4277929fb3
parent 2546
dd9f912d5bd9
parent 2642
c9f965bd21d2
child 2678
6e40469b845b
equal deleted inserted replaced
2670:e60ea6cb8e11 2677:3d4277929fb3
382 @return list of parent revisions (list of integers) 382 @return list of parent revisions (list of integers)
383 """ 383 """
384 errMsg = "" 384 errMsg = ""
385 parents = [-1] 385 parents = [-1]
386 386
387 if int(rev) > 0:
388 args = []
389 args.append("parents")
390 if self.commandMode == "incoming":
391 if self.bundle:
392 args.append("--repository")
393 args.append(self.bundle)
394 elif self.vcs.bundleFile and os.path.exists(self.vcs.bundleFile):
395 args.append("--repository")
396 args.append(self.vcs.bundleFile)
397 args.append("--template")
398 args.append("{rev}\n")
399 args.append("-r")
400 args.append(rev)
401 if not self.projectMode:
402 args.append(self.filename)
403
404 output = ""
405 if self.__hgClient:
406 output, errMsg = self.__hgClient.runcommand(args)
407 else:
408 process = QProcess()
409 process.setWorkingDirectory(self.repodir)
410 process.start('hg', args)
411 procStarted = process.waitForStarted()
412 if procStarted:
413 finished = process.waitForFinished(30000)
414 if finished and process.exitCode() == 0:
415 output = \
416 str(process.readAllStandardOutput(),
417 Preferences.getSystem("IOEncoding"),
418 'replace')
419 else:
420 if not finished:
421 errMsg = self.trUtf8(
422 "The hg process did not finish within 30s.")
423 else:
424 errMsg = self.trUtf8("Could not start the hg executable.")
425
426 if errMsg:
427 E5MessageBox.critical(self,
428 self.trUtf8("Mercurial Error"),
429 errMsg)
430
431 if output:
432 parents = [int(p) for p in output.strip().splitlines()]
433
434 return parents
435
436 def __identifyProject(self):
437 """
438 Private method to determine the revision of the project directory.
439 """
440 errMsg = ""
441
387 args = [] 442 args = []
388 args.append("parents") 443 args.append("identify")
389 if self.commandMode == "incoming": 444 args.append("-nb")
390 if self.bundle:
391 args.append("--repository")
392 args.append(self.bundle)
393 elif self.vcs.bundleFile and os.path.exists(self.vcs.bundleFile):
394 args.append("--repository")
395 args.append(self.vcs.bundleFile)
396 args.append("--template")
397 args.append("{rev}\n")
398 args.append("-r")
399 args.append(rev)
400 if not self.projectMode:
401 args.append(self.filename)
402 445
403 output = "" 446 output = ""
404 if self.__hgClient: 447 if self.__hgClient:
405 output, errMsg = self.__hgClient.runcommand(args) 448 output, errMsg = self.__hgClient.runcommand(args)
406 else: 449 else:
426 E5MessageBox.critical(self, 469 E5MessageBox.critical(self,
427 self.trUtf8("Mercurial Error"), 470 self.trUtf8("Mercurial Error"),
428 errMsg) 471 errMsg)
429 472
430 if output: 473 if output:
431 parents = [int(p) for p in output.strip().splitlines()]
432
433 return parents
434
435 def __identifyProject(self):
436 """
437 Private method to determine the revision of the project directory.
438 """
439 errMsg = ""
440
441 args = []
442 args.append("identify")
443 args.append("-nb")
444
445 output = ""
446 if self.__hgClient:
447 output, errMsg = self.__hgClient.runcommand(args)
448 else:
449 process = QProcess()
450 process.setWorkingDirectory(self.repodir)
451 process.start('hg', args)
452 procStarted = process.waitForStarted()
453 if procStarted:
454 finished = process.waitForFinished(30000)
455 if finished and process.exitCode() == 0:
456 output = \
457 str(process.readAllStandardOutput(),
458 Preferences.getSystem("IOEncoding"),
459 'replace')
460 else:
461 if not finished:
462 errMsg = self.trUtf8(
463 "The hg process did not finish within 30s.")
464 else:
465 errMsg = self.trUtf8("Could not start the hg executable.")
466
467 if errMsg:
468 E5MessageBox.critical(self,
469 self.trUtf8("Mercurial Error"),
470 errMsg)
471
472 if output:
473 outputList = output.strip().split(None, 1) 474 outputList = output.strip().split(None, 1)
474 if len(outputList) == 2: 475 if len(outputList) == 2:
475 self.__projectRevision = outputList[0].strip() 476 self.__projectRevision = outputList[0].strip()
476 if self.__projectRevision.endswith("+"): 477 if self.__projectRevision.endswith("+"):
477 self.__projectRevision = self.__projectRevision[:-1] 478 self.__projectRevision = self.__projectRevision[:-1]
478 self.__projectBranch = outputList[1].strip() 479 self.__projectBranch = outputList[1].strip()
479 480
480 def __getClosedBranches(self): 481 def __getClosedBranches(self):
481 """ 482 """
482 Private method to get the list of closed branches. 483 Private method to get the list of closed branches.
483 """ 484 """
907 self.branchCombo.setCurrentIndex( 908 self.branchCombo.setCurrentIndex(
908 self.branchCombo.findText(branchFilter)) 909 self.branchCombo.findText(branchFilter))
909 910
910 self.__filterLogsEnabled = True 911 self.__filterLogsEnabled = True
911 self.__filterLogs() 912 self.__filterLogs()
913
914 self.__updateDiffButtons()
915 self.__updatePhaseButton()
916 self.__updateGraftButton()
912 917
913 def __readStdout(self): 918 def __readStdout(self):
914 """ 919 """
915 Private slot to handle the readyReadStandardOutput signal. 920 Private slot to handle the readyReadStandardOutput signal.
916 921
1006 1011
1007 def __updatePhaseButton(self): 1012 def __updatePhaseButton(self):
1008 """ 1013 """
1009 Private slot to update the status of the phase button. 1014 Private slot to update the status of the phase button.
1010 """ 1015 """
1011 # step 1: count entries with changeable phases 1016 if self.initialCommandMode == "log":
1012 secret = 0 1017 # step 1: count entries with changeable phases
1013 draft = 0 1018 secret = 0
1014 public = 0 1019 draft = 0
1015 for itm in self.logTree.selectedItems(): 1020 public = 0
1016 phase = itm.text(self.PhaseColumn) 1021 for itm in self.logTree.selectedItems():
1017 if phase == "draft": 1022 phase = itm.text(self.PhaseColumn)
1018 draft += 1 1023 if phase == "draft":
1019 elif phase == "secret": 1024 draft += 1
1020 secret += 1 1025 elif phase == "secret":
1026 secret += 1
1027 else:
1028 public += 1
1029
1030 # step 2: set the status of the phase button
1031 if public == 0 and \
1032 ((secret > 0 and draft == 0) or \
1033 (secret == 0 and draft > 0)):
1034 self.phaseButton.setEnabled(True)
1021 else: 1035 else:
1022 public += 1 1036 self.phaseButton.setEnabled(False)
1023
1024 # step 2: set the status of the phase button
1025 if public == 0 and \
1026 ((secret > 0 and draft == 0) or \
1027 (secret == 0 and draft > 0)):
1028 self.phaseButton.setEnabled(True)
1029 else: 1037 else:
1030 self.phaseButton.setEnabled(False) 1038 self.phaseButton.setEnabled(False)
1039
1040 def __updateGraftButton(self):
1041 """
1042 Private slot to update the status of the graft button.
1043 """
1044 if self.graftButton.isVisible():
1045 if self.initialCommandMode == "log":
1046 # step 1: count selected entries not belonging to the current branch
1047 otherBranches = 0
1048 for itm in self.logTree.selectedItems():
1049 branch = itm.text(self.BranchColumn)
1050 if branch != self.__projectBranch:
1051 otherBranches += 1
1052
1053 # step 2: set the status of the graft button
1054 self.graftButton.setEnabled(otherBranches > 0)
1055 else:
1056 self.graftButton.setEnabled(False)
1031 1057
1032 def __updateGraftButton(self): 1058 def __updateGraftButton(self):
1033 """ 1059 """
1034 Private slot to update the status of the graft button. 1060 Private slot to update the status of the graft button.
1035 """ 1061 """
1101 @pyqtSlot() 1127 @pyqtSlot()
1102 def on_diffP1Button_clicked(self): 1128 def on_diffP1Button_clicked(self):
1103 """ 1129 """
1104 Private slot to handle the Diff to Parent 1 button. 1130 Private slot to handle the Diff to Parent 1 button.
1105 """ 1131 """
1106 itm = self.logTree.selectedItems()[0] 1132 if len(self.logTree.selectedItems()):
1133 itm = self.logTree.selectedItems()[0]
1134 else:
1135 itm = self.logTree.currentItem()
1107 if itm is None: 1136 if itm is None:
1108 self.diffP1Button.setEnabled(False) 1137 self.diffP1Button.setEnabled(False)
1109 return 1138 return
1110 rev2 = int(itm.text(self.RevisionColumn).split(":")[0]) 1139 rev2 = int(itm.text(self.RevisionColumn).split(":")[0])
1111 1140
1119 @pyqtSlot() 1148 @pyqtSlot()
1120 def on_diffP2Button_clicked(self): 1149 def on_diffP2Button_clicked(self):
1121 """ 1150 """
1122 Private slot to handle the Diff to Parent 2 button. 1151 Private slot to handle the Diff to Parent 2 button.
1123 """ 1152 """
1124 itm = self.logTree.selectedItems()[0] 1153 if len(self.logTree.selectedItems()):
1154 itm = self.logTree.selectedItems()[0]
1155 else:
1156 itm = self.logTree.currentItem()
1125 if itm is None: 1157 if itm is None:
1126 self.diffP2Button.setEnabled(False) 1158 self.diffP2Button.setEnabled(False)
1127 return 1159 return
1128 rev2 = int(itm.text(self.RevisionColumn).split(":")[0]) 1160 rev2 = int(itm.text(self.RevisionColumn).split(":")[0])
1129 1161

eric ide

mercurial