Plugins/VcsPlugins/vcsMercurial/hg.py

changeset 3302
e92f0dd51979
parent 3290
dbb53746813f
child 3305
cf4f22a19dc6
equal deleted inserted replaced
3300:734353e7d679 3302:e92f0dd51979
23 from VCS.VersionControl import VersionControl 23 from VCS.VersionControl import VersionControl
24 from VCS.RepositoryInfoDialog import VcsRepositoryInfoDialog 24 from VCS.RepositoryInfoDialog import VcsRepositoryInfoDialog
25 25
26 from .HgDialog import HgDialog 26 from .HgDialog import HgDialog
27 27
28 import Preferences
29 import Utilities 28 import Utilities
30 29
31 30
32 class Hg(VersionControl): 31 class Hg(VersionControl):
33 """ 32 """
153 Public method to get a reference to the plugin object. 152 Public method to get a reference to the plugin object.
154 153
155 @return reference to the plugin object (VcsMercurialPlugin) 154 @return reference to the plugin object (VcsMercurialPlugin)
156 """ 155 """
157 return self.__plugin 156 return self.__plugin
157
158 def getEncoding(self):
159 """
160 Public method to get the encoding to be used by Mercurial.
161
162 @return encoding (string)
163 """
164 return self.__plugin.getPreferences("Encoding")
158 165
159 def vcsShutdown(self): 166 def vcsShutdown(self):
160 """ 167 """
161 Public method used to shutdown the Mercurial interface. 168 Public method used to shutdown the Mercurial interface.
162 """ 169 """
202 209
203 @return reference to the client (HgClient) 210 @return reference to the client (HgClient)
204 """ 211 """
205 return self.__client 212 return self.__client
206 213
214 def initCommand(self, command):
215 """
216 Public method to initialize a command arguments list.
217
218 @param command command name (string)
219 @return list of command options (list of string)
220 """
221 args = [command]
222 self.addArguments(args, self.__plugin.getGlobalOptions())
223 return args
224
207 def vcsExists(self): 225 def vcsExists(self):
208 """ 226 """
209 Public method used to test for the presence of the hg executable. 227 Public method used to test for the presence of the hg executable.
210 228
211 @return flag indicating the existance (boolean) and an error message 229 @return flag indicating the existance (boolean) and an error message
212 (string) 230 (string)
213 """ 231 """
214 self.versionStr = '' 232 self.versionStr = ''
215 errMsg = "" 233 errMsg = ""
216 ioEncoding = Preferences.getSystem("IOEncoding") 234
217 235 args = self.initCommand("version")
218 process = QProcess() 236 process = QProcess()
219 process.start('hg', ['version']) 237 process.start('hg', args)
220 procStarted = process.waitForStarted(5000) 238 procStarted = process.waitForStarted(5000)
221 if procStarted: 239 if procStarted:
222 finished = process.waitForFinished(30000) 240 finished = process.waitForFinished(30000)
223 if finished and process.exitCode() == 0: 241 if finished and process.exitCode() == 0:
224 output = \ 242 output = str(process.readAllStandardOutput(),
225 str(process.readAllStandardOutput(), ioEncoding, 'replace') 243 self.getEncoding(), 'replace')
226 self.versionStr = output.splitlines()[0].split()[-1][0:-1] 244 self.versionStr = output.splitlines()[0].split()[-1][0:-1]
227 v = list(re.match(r'.*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?', 245 v = list(re.match(r'.*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?',
228 self.versionStr).groups()) 246 self.versionStr).groups())
229 for i in range(3): 247 for i in range(3):
230 try: 248 try:
297 """ 315 """
298 msg = vcsDataDict["message"] 316 msg = vcsDataDict["message"]
299 if not msg: 317 if not msg:
300 msg = '***' 318 msg = '***'
301 319
302 args = [] 320 args = self.initCommand("init")
303 args.append('init')
304 args.append(projectDir) 321 args.append(projectDir)
305 # init is not possible with the command server 322 # init is not possible with the command server
306 dia = HgDialog(self.tr('Creating Mercurial repository'), self) 323 dia = HgDialog(self.tr('Creating Mercurial repository'), self)
307 res = dia.startProcess(args) 324 res = dia.startProcess(args)
308 if res: 325 if res:
313 ignoreName = os.path.join(projectDir, Hg.IgnoreFileName) 330 ignoreName = os.path.join(projectDir, Hg.IgnoreFileName)
314 if not os.path.exists(ignoreName): 331 if not os.path.exists(ignoreName):
315 status = self.hgCreateIgnoreFile(projectDir) 332 status = self.hgCreateIgnoreFile(projectDir)
316 333
317 if status: 334 if status:
318 args = [] 335 args = self.vcs.initCommand("commit")
319 args.append('commit')
320 args.append('--addremove') 336 args.append('--addremove')
321 args.append('--message') 337 args.append('--message')
322 args.append(msg) 338 args.append(msg)
323 dia = HgDialog( 339 dia = HgDialog(
324 self.tr('Initial commit to Mercurial repository'), 340 self.tr('Initial commit to Mercurial repository'),
349 if vcsUrl.startswith('/'): 365 if vcsUrl.startswith('/'):
350 vcsUrl = 'file://{0}'.format(vcsUrl) 366 vcsUrl = 'file://{0}'.format(vcsUrl)
351 elif vcsUrl[1] in ['|', ':']: 367 elif vcsUrl[1] in ['|', ':']:
352 vcsUrl = 'file:///{0}'.format(vcsUrl) 368 vcsUrl = 'file:///{0}'.format(vcsUrl)
353 369
354 args = [] 370 args = self.initCommand("clone")
355 args.append('clone')
356 self.addArguments(args, self.options['global'])
357 self.addArguments(args, self.options['checkout'])
358 if rev: 371 if rev:
359 args.append("--rev") 372 args.append("--rev")
360 args.append(rev) 373 args.append(rev)
361 args.append(self.__hgURL(vcsUrl)) 374 args.append(self.__hgURL(vcsUrl))
362 args.append(projectDir) 375 args.append(projectDir)
485 commitSubrepositories = False 498 commitSubrepositories = False
486 499
487 if not msg and not amend: 500 if not msg and not amend:
488 msg = '***' 501 msg = '***'
489 502
490 args = [] 503 args = self.initCommand("commit")
491 args.append('commit')
492 self.addArguments(args, self.options['global'])
493 self.addArguments(args, self.options['commit'])
494 args.append("-v") 504 args.append("-v")
495 if mq: 505 if mq:
496 args.append("--mq") 506 args.append("--mq")
497 else: 507 else:
498 if closeBranch: 508 if closeBranch:
556 @param noDialog flag indicating quiet operations (boolean) 566 @param noDialog flag indicating quiet operations (boolean)
557 @keyparam revision revision to update to (string) 567 @keyparam revision revision to update to (string)
558 @return flag indicating, that the update contained an add 568 @return flag indicating, that the update contained an add
559 or delete (boolean) 569 or delete (boolean)
560 """ 570 """
561 args = [] 571 args = self.initCommand("update")
562 args.append('update')
563 self.addArguments(args, self.options['global'])
564 self.addArguments(args, self.options['update'])
565 if "-v" not in args and "--verbose" not in args: 572 if "-v" not in args and "--verbose" not in args:
566 args.append("-v") 573 args.append("-v")
567 if revision is not None: 574 if revision is not None:
568 args.append("-r") 575 args.append("-r")
569 args.append(revision) 576 args.append(revision)
603 610
604 @param name file/directory name to be added (string) 611 @param name file/directory name to be added (string)
605 @param isDir flag indicating name is a directory (boolean) 612 @param isDir flag indicating name is a directory (boolean)
606 @param noDialog flag indicating quiet operations 613 @param noDialog flag indicating quiet operations
607 """ 614 """
608 args = [] 615 args = self.initCommand("add")
609 args.append('add')
610 self.addArguments(args, self.options['global'])
611 self.addArguments(args, self.options['add'])
612 args.append("-v") 616 args.append("-v")
613 617
614 if isinstance(name, list): 618 if isinstance(name, list):
615 if isDir: 619 if isDir:
616 dname, fname = os.path.split(name[0]) 620 dname, fname = os.path.split(name[0])
680 @param project flag indicating deletion of a project tree (boolean) 684 @param project flag indicating deletion of a project tree (boolean)
681 (not needed) 685 (not needed)
682 @param noDialog flag indicating quiet operations 686 @param noDialog flag indicating quiet operations
683 @return flag indicating successfull operation (boolean) 687 @return flag indicating successfull operation (boolean)
684 """ 688 """
685 args = [] 689 args = self.initCommand("remove")
686 args.append('remove')
687 self.addArguments(args, self.options['global'])
688 self.addArguments(args, self.options['remove'])
689 args.append("-v") 690 args.append("-v")
690 if noDialog and '--force' not in args: 691 if noDialog and '--force' not in args:
691 args.append('--force') 692 args.append('--force')
692 693
693 if isinstance(name, list): 694 if isinstance(name, list):
733 @param target new name of the file/directory (string) 734 @param target new name of the file/directory (string)
734 @param noDialog flag indicating quiet operations 735 @param noDialog flag indicating quiet operations
735 @return flag indicating successfull operation (boolean) 736 @return flag indicating successfull operation (boolean)
736 """ 737 """
737 isDir = os.path.isdir(name) 738 isDir = os.path.isdir(name)
738 opts = self.options['global'][:] 739 # TODO: get rid of this
739 force = '--force' in opts 740 force = False
740 if force:
741 opts.remove('--force')
742 741
743 res = False 742 res = False
744 if noDialog: 743 if noDialog:
745 if target is None: 744 if target is None:
746 return False 745 return False
752 accepted = dlg.exec_() == QDialog.Accepted 751 accepted = dlg.exec_() == QDialog.Accepted
753 if accepted: 752 if accepted:
754 target, force = dlg.getData() 753 target, force = dlg.getData()
755 754
756 if accepted: 755 if accepted:
757 args = [] 756 args = self.initCommand("rename")
758 args.append('rename')
759 self.addArguments(args, opts)
760 args.append("-v") 757 args.append("-v")
761 if force: 758 if force:
762 args.append('--force') 759 args.append('--force')
763 args.append(name) 760 args.append(name)
764 args.append(target) 761 args.append(target)
919 if dlg.exec_() == QDialog.Accepted: 916 if dlg.exec_() == QDialog.Accepted:
920 tag, revision, tagOp = dlg.getParameters() 917 tag, revision, tagOp = dlg.getParameters()
921 else: 918 else:
922 return False 919 return False
923 920
924 args = [] 921 args = self.initCommand("tag")
925 args.append('tag')
926 msgPart = "" 922 msgPart = ""
927 if tagOp in [HgTagDialog.CreateLocalTag, HgTagDialog.DeleteLocalTag]: 923 if tagOp in [HgTagDialog.CreateLocalTag, HgTagDialog.DeleteLocalTag]:
928 args.append('--local') 924 args.append('--local')
929 msgPart = "local " 925 msgPart = "local "
930 else: 926 else:
957 953
958 @param name file/directory name to be reverted (string) 954 @param name file/directory name to be reverted (string)
959 @return flag indicating, that the update contained an add 955 @return flag indicating, that the update contained an add
960 or delete (boolean) 956 or delete (boolean)
961 """ 957 """
962 args = [] 958 args = self.initCommand("revert")
963 args.append('revert')
964 self.addArguments(args, self.options['global'])
965 if not self.getPlugin().getPreferences("CreateBackup"): 959 if not self.getPlugin().getPreferences("CreateBackup"):
966 args.append("--no-backup") 960 args.append("--no-backup")
967 args.append("-v") 961 args.append("-v")
968 if isinstance(name, list): 962 if isinstance(name, list):
969 dname, fnames = self.splitPathList(name) 963 dname, fnames = self.splitPathList(name)
1025 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1019 while not os.path.isdir(os.path.join(repodir, self.adminDir)):
1026 repodir = os.path.dirname(repodir) 1020 repodir = os.path.dirname(repodir)
1027 if os.path.splitdrive(repodir)[1] == os.sep: 1021 if os.path.splitdrive(repodir)[1] == os.sep:
1028 return 1022 return
1029 1023
1030 opts = self.options['global'][:] 1024 # TODO: get rid of this
1031 force = '--force' in opts 1025 force = False
1032 if force:
1033 del opts[opts.index('--force')]
1034 1026
1035 if self.isExtensionActive("bookmarks"): 1027 if self.isExtensionActive("bookmarks"):
1036 bookmarksList = \ 1028 bookmarksList = \
1037 self.getExtensionObject("bookmarks")\ 1029 self.getExtensionObject("bookmarks")\
1038 .hgGetBookmarksList(repodir) 1030 .hgGetBookmarksList(repodir)
1045 if dlg.exec_() == QDialog.Accepted: 1037 if dlg.exec_() == QDialog.Accepted:
1046 rev, force = dlg.getParameters() 1038 rev, force = dlg.getParameters()
1047 else: 1039 else:
1048 return 1040 return
1049 1041
1050 args = [] 1042 args = self.initCommand("merge")
1051 args.append('merge')
1052 self.addArguments(args, opts)
1053 if force: 1043 if force:
1054 args.append("--force") 1044 args.append("--force")
1055 if self.getPlugin().getPreferences("InternalMerge"): 1045 if self.getPlugin().getPreferences("InternalMerge"):
1056 args.append("--tool") 1046 args.append("--tool")
1057 args.append("internal:merge") 1047 args.append("internal:merge")
1122 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1112 while not os.path.isdir(os.path.join(repodir, self.adminDir)):
1123 repodir = os.path.dirname(repodir) 1113 repodir = os.path.dirname(repodir)
1124 if os.path.splitdrive(repodir)[1] == os.sep: 1114 if os.path.splitdrive(repodir)[1] == os.sep:
1125 return 0 1115 return 0
1126 1116
1127 args = [] 1117 args = self.initCommand("status")
1128 args.append('status')
1129 args.append('--all') 1118 args.append('--all')
1130 args.append('--noninteractive') 1119 args.append('--noninteractive')
1131 1120
1132 output = "" 1121 output = ""
1133 if self.__client is None: 1122 if self.__client is None:
1136 process.start('hg', args) 1125 process.start('hg', args)
1137 procStarted = process.waitForStarted(5000) 1126 procStarted = process.waitForStarted(5000)
1138 if procStarted: 1127 if procStarted:
1139 finished = process.waitForFinished(30000) 1128 finished = process.waitForFinished(30000)
1140 if finished and process.exitCode() == 0: 1129 if finished and process.exitCode() == 0:
1141 output = \ 1130 output = str(process.readAllStandardOutput(),
1142 str(process.readAllStandardOutput(), 1131 self.getEncoding(), 'replace')
1143 Preferences.getSystem("IOEncoding"),
1144 'replace')
1145 else: 1132 else:
1146 output, error = self.__client.runcommand(args) 1133 output, error = self.__client.runcommand(args)
1147 1134
1148 if output: 1135 if output:
1149 for line in output.splitlines(): 1136 for line in output.splitlines():
1192 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1179 while not os.path.isdir(os.path.join(repodir, self.adminDir)):
1193 repodir = os.path.dirname(repodir) 1180 repodir = os.path.dirname(repodir)
1194 if os.path.splitdrive(repodir)[1] == os.sep: 1181 if os.path.splitdrive(repodir)[1] == os.sep:
1195 return names 1182 return names
1196 1183
1197 args = [] 1184 args = self.initCommand("status")
1198 args.append('status')
1199 args.append('--all') 1185 args.append('--all')
1200 args.append('--noninteractive') 1186 args.append('--noninteractive')
1201 1187
1202 output = "" 1188 output = ""
1203 if self.__client is None: 1189 if self.__client is None:
1206 process.start('hg', args) 1192 process.start('hg', args)
1207 procStarted = process.waitForStarted(5000) 1193 procStarted = process.waitForStarted(5000)
1208 if procStarted: 1194 if procStarted:
1209 finished = process.waitForFinished(30000) 1195 finished = process.waitForFinished(30000)
1210 if finished and process.exitCode() == 0: 1196 if finished and process.exitCode() == 0:
1211 output = str( 1197 output = str(process.readAllStandardOutput(),
1212 process.readAllStandardOutput(), 1198 self.getEncoding(), 'replace')
1213 Preferences.getSystem("IOEncoding"),
1214 'replace')
1215 else: 1199 else:
1216 output, error = self.__client.runcommand(args) 1200 output, error = self.__client.runcommand(args)
1217 1201
1218 if output: 1202 if output:
1219 dirs = [x for x in names.keys() if os.path.isdir(x)] 1203 dirs = [x for x in names.keys() if os.path.isdir(x)]
1353 Public method to retrieve information about the repository. 1337 Public method to retrieve information about the repository.
1354 1338
1355 @param ppath local path to get the repository infos (string) 1339 @param ppath local path to get the repository infos (string)
1356 @return string with ready formated info for display (string) 1340 @return string with ready formated info for display (string)
1357 """ 1341 """
1358 args = [] 1342 args = self.initCommand("parents")
1359 args.append('parents')
1360 args.append('--template') 1343 args.append('--template')
1361 args.append('{rev}:{node|short}@@@{tags}@@@{author|xmlescape}@@@' 1344 args.append('{rev}:{node|short}@@@{tags}@@@{author|xmlescape}@@@'
1362 '{date|isodate}@@@{branches}@@@{bookmarks}\n') 1345 '{date|isodate}@@@{branches}@@@{bookmarks}\n')
1363 1346
1364 output = "" 1347 output = ""
1368 process.start('hg', args) 1351 process.start('hg', args)
1369 procStarted = process.waitForStarted(5000) 1352 procStarted = process.waitForStarted(5000)
1370 if procStarted: 1353 if procStarted:
1371 finished = process.waitForFinished(30000) 1354 finished = process.waitForFinished(30000)
1372 if finished and process.exitCode() == 0: 1355 if finished and process.exitCode() == 0:
1373 output = str( 1356 output = str(process.readAllStandardOutput(),
1374 process.readAllStandardOutput(), 1357 self.getEncoding(), 'replace')
1375 Preferences.getSystem("IOEncoding"), 'replace')
1376 else: 1358 else:
1377 output, error = self.__client.runcommand(args) 1359 output, error = self.__client.runcommand(args)
1378 1360
1379 infoBlock = [] 1361 infoBlock = []
1380 if output: 1362 if output:
1416 infoStr = """<tr></tr>{0}""".format("<tr></tr>".join(infoBlock)) 1398 infoStr = """<tr></tr>{0}""".format("<tr></tr>".join(infoBlock))
1417 else: 1399 else:
1418 infoStr = "" 1400 infoStr = ""
1419 1401
1420 url = "" 1402 url = ""
1421 args = [] 1403 args = self.initCommand("showconfig")
1422 args.append('showconfig')
1423 args.append('paths.default') 1404 args.append('paths.default')
1424 1405
1425 output = "" 1406 output = ""
1426 if self.__client is None: 1407 if self.__client is None:
1427 process.setWorkingDirectory(ppath) 1408 process.setWorkingDirectory(ppath)
1428 process.start('hg', args) 1409 process.start('hg', args)
1429 procStarted = process.waitForStarted(5000) 1410 procStarted = process.waitForStarted(5000)
1430 if procStarted: 1411 if procStarted:
1431 finished = process.waitForFinished(30000) 1412 finished = process.waitForFinished(30000)
1432 if finished and process.exitCode() == 0: 1413 if finished and process.exitCode() == 0:
1433 output = str( 1414 output = str(process.readAllStandardOutput(),
1434 process.readAllStandardOutput(), 1415 self.getEncoding(), 'replace')
1435 Preferences.getSystem("IOEncoding"), 'replace')
1436 else: 1416 else:
1437 output, error = self.__client.runcommand(args) 1417 output, error = self.__client.runcommand(args)
1438 1418
1439 if output: 1419 if output:
1440 url = output.splitlines()[0].strip() 1420 url = output.splitlines()[0].strip()
1449 """<tr></tr>\n""" 1429 """<tr></tr>\n"""
1450 """<tr><td><b>URL</b></td><td>{1}</td></tr>\n""" 1430 """<tr><td><b>URL</b></td><td>{1}</td></tr>\n"""
1451 """{2}""" 1431 """{2}"""
1452 """</table></p>\n""" 1432 """</table></p>\n"""
1453 ).format(self.versionStr, url, infoStr) 1433 ).format(self.versionStr, url, infoStr)
1454 1434
1435 def vcsSupportCommandOptions(self):
1436 """
1437 Public method to signal the support of user settable command options.
1438
1439 @return flag indicating the support of user settable command options
1440 (boolean)
1441 """
1442 return False
1443
1455 ########################################################################### 1444 ###########################################################################
1456 ## Private Mercurial specific methods are below. 1445 ## Private Mercurial specific methods are below.
1457 ########################################################################### 1446 ###########################################################################
1458 1447
1459 def __hgURL(self, url): 1448 def __hgURL(self, url):
1512 dlg = HgCopyDialog(name) 1501 dlg = HgCopyDialog(name)
1513 res = False 1502 res = False
1514 if dlg.exec_() == QDialog.Accepted: 1503 if dlg.exec_() == QDialog.Accepted:
1515 target, force = dlg.getData() 1504 target, force = dlg.getData()
1516 1505
1517 args = [] 1506 args = self.initCommand("copy")
1518 args.append('copy')
1519 self.addArguments(args, self.options['global'])
1520 args.append("-v") 1507 args.append("-v")
1521 args.append(name) 1508 args.append(name)
1522 args.append(target) 1509 args.append(target)
1523 1510
1524 dname, fname = self.splitPath(name) 1511 dname, fname = self.splitPath(name)
1551 @param withType flag indicating to get the tag type as well (boolean) 1538 @param withType flag indicating to get the tag type as well (boolean)
1552 @return list of tags (list of string) or list of tuples of 1539 @return list of tags (list of string) or list of tuples of
1553 tag name and flag indicating a local tag (list of tuple of string 1540 tag name and flag indicating a local tag (list of tuple of string
1554 and boolean), if withType is True 1541 and boolean), if withType is True
1555 """ 1542 """
1556 args = [] 1543 args = self.initCommand("tags")
1557 args.append('tags')
1558 args.append('--verbose') 1544 args.append('--verbose')
1559 1545
1560 output = "" 1546 output = ""
1561 if self.__client is None: 1547 if self.__client is None:
1562 process = QProcess() 1548 process = QProcess()
1564 process.start('hg', args) 1550 process.start('hg', args)
1565 procStarted = process.waitForStarted(5000) 1551 procStarted = process.waitForStarted(5000)
1566 if procStarted: 1552 if procStarted:
1567 finished = process.waitForFinished(30000) 1553 finished = process.waitForFinished(30000)
1568 if finished and process.exitCode() == 0: 1554 if finished and process.exitCode() == 0:
1569 output = \ 1555 output = str(process.readAllStandardOutput(),
1570 str(process.readAllStandardOutput(), 1556 self.getEncoding(), 'replace')
1571 Preferences.getSystem("IOEncoding"),
1572 'replace')
1573 else: 1557 else:
1574 output, error = self.__client.runcommand(args) 1558 output, error = self.__client.runcommand(args)
1575 1559
1576 tagsList = [] 1560 tagsList = []
1577 if output: 1561 if output:
1603 Public method to get the list of branches. 1587 Public method to get the list of branches.
1604 1588
1605 @param repodir directory name of the repository (string) 1589 @param repodir directory name of the repository (string)
1606 @return list of branches (list of string) 1590 @return list of branches (list of string)
1607 """ 1591 """
1608 args = [] 1592 args = self.initCommand("branches")
1609 args.append('branches')
1610 args.append('--closed') 1593 args.append('--closed')
1611 1594
1612 output = "" 1595 output = ""
1613 if self.__client is None: 1596 if self.__client is None:
1614 process = QProcess() 1597 process = QProcess()
1616 process.start('hg', args) 1599 process.start('hg', args)
1617 procStarted = process.waitForStarted(5000) 1600 procStarted = process.waitForStarted(5000)
1618 if procStarted: 1601 if procStarted:
1619 finished = process.waitForFinished(30000) 1602 finished = process.waitForFinished(30000)
1620 if finished and process.exitCode() == 0: 1603 if finished and process.exitCode() == 0:
1621 output = \ 1604 output = str(process.readAllStandardOutput(),
1622 str(process.readAllStandardOutput(), 1605 self.getEncoding(), 'replace')
1623 Preferences.getSystem("IOEncoding"),
1624 'replace')
1625 else: 1606 else:
1626 output, error = self.__client.runcommand(args) 1607 output, error = self.__client.runcommand(args)
1627 1608
1628 if output: 1609 if output:
1629 self.branchesList = [] 1610 self.branchesList = []
1743 1724
1744 @param name file name to get from the repository (string) 1725 @param name file name to get from the repository (string)
1745 @keyparam rev revision to retrieve (string) 1726 @keyparam rev revision to retrieve (string)
1746 @return contents of the file (string) and an error message (string) 1727 @return contents of the file (string) and an error message (string)
1747 """ 1728 """
1748 args = [] 1729 args = self.initCommand("cat")
1749 args.append("cat")
1750 if rev: 1730 if rev:
1751 args.append("--rev") 1731 args.append("--rev")
1752 args.append(rev) 1732 args.append(rev)
1753 args.append(name) 1733 args.append(name)
1754 1734
1769 procStarted = process.waitForStarted(5000) 1749 procStarted = process.waitForStarted(5000)
1770 if procStarted: 1750 if procStarted:
1771 finished = process.waitForFinished(30000) 1751 finished = process.waitForFinished(30000)
1772 if finished: 1752 if finished:
1773 if process.exitCode() == 0: 1753 if process.exitCode() == 0:
1774 output = str( 1754 output = str(process.readAllStandardOutput(),
1775 process.readAllStandardOutput(), 1755 self.getEncoding(), 'replace')
1776 Preferences.getSystem("IOEncoding"), 'replace')
1777 else: 1756 else:
1778 error = str( 1757 error = str(process.readAllStandardError(),
1779 process.readAllStandardError(), 1758 self.getEncoding(), 'replace')
1780 Preferences.getSystem("IOEncoding"), 'replace')
1781 else: 1759 else:
1782 error = self.tr( 1760 error = self.tr(
1783 "The hg process did not finish within 30s.") 1761 "The hg process did not finish within 30s.")
1784 else: 1762 else:
1785 error = self.tr( 1763 error = self.tr(
1939 title = self.tr('Apply changegroups') 1917 title = self.tr('Apply changegroups')
1940 else: 1918 else:
1941 command = "pull" 1919 command = "pull"
1942 title = self.tr('Pulling from a remote Mercurial repository') 1920 title = self.tr('Pulling from a remote Mercurial repository')
1943 1921
1944 args = [] 1922 args = self.initCommand(command)
1945 args.append(command)
1946 self.addArguments(args, self.options['global'])
1947 args.append('-v') 1923 args.append('-v')
1948 if self.getPlugin().getPreferences("PullUpdate"): 1924 if self.getPlugin().getPreferences("PullUpdate"):
1949 args.append('--update') 1925 args.append('--update')
1950 if command == "unbundle": 1926 if command == "unbundle":
1951 args.append(self.bundleFile) 1927 args.append(self.bundleFile)
1975 1951
1976 @param name directory name of the project to be pushed from (string) 1952 @param name directory name of the project to be pushed from (string)
1977 @keyparam force flag indicating a forced push (boolean) 1953 @keyparam force flag indicating a forced push (boolean)
1978 @keyparam newBranch flag indicating to push a new branch (boolean) 1954 @keyparam newBranch flag indicating to push a new branch (boolean)
1979 """ 1955 """
1980 args = [] 1956 args = self.initCommand("push")
1981 args.append('push')
1982 self.addArguments(args, self.options['global'])
1983 args.append('-v') 1957 args.append('-v')
1984 if force: 1958 if force:
1985 args.append('-f') 1959 args.append('-f')
1986 if newBranch: 1960 if newBranch:
1987 args.append('--new-branch') 1961 args.append('--new-branch')
2012 if mode not in ("heads", "parents", "tip"): 1986 if mode not in ("heads", "parents", "tip"):
2013 mode = "heads" 1987 mode = "heads"
2014 1988
2015 info = [] 1989 info = []
2016 1990
2017 args = [] 1991 args = self.initCommand(mode)
2018 args.append(mode)
2019 args.append('--template') 1992 args.append('--template')
2020 args.append('{rev}:{node|short}@@@{tags}@@@{author|xmlescape}@@@' 1993 args.append('{rev}:{node|short}@@@{tags}@@@{author|xmlescape}@@@'
2021 '{date|isodate}@@@{branches}@@@{parents}@@@{bookmarks}\n') 1994 '{date|isodate}@@@{branches}@@@{parents}@@@{bookmarks}\n')
2022 1995
2023 output = "" 1996 output = ""
2034 process.start('hg', args) 2007 process.start('hg', args)
2035 procStarted = process.waitForStarted(5000) 2008 procStarted = process.waitForStarted(5000)
2036 if procStarted: 2009 if procStarted:
2037 finished = process.waitForFinished(30000) 2010 finished = process.waitForFinished(30000)
2038 if finished and process.exitCode() == 0: 2011 if finished and process.exitCode() == 0:
2039 output = str( 2012 output = str(process.readAllStandardOutput(),
2040 process.readAllStandardOutput(), 2013 self.getEncoding(), 'replace')
2041 Preferences.getSystem("IOEncoding"), 'replace')
2042 else: 2014 else:
2043 output, error = self.__client.runcommand(args) 2015 output, error = self.__client.runcommand(args)
2044 2016
2045 if output: 2017 if output:
2046 index = 0 2018 index = 0
2103 """ 2075 """
2104 Public method used to resolve conflicts of a file/directory. 2076 Public method used to resolve conflicts of a file/directory.
2105 2077
2106 @param name file/directory name to be resolved (string) 2078 @param name file/directory name to be resolved (string)
2107 """ 2079 """
2108 args = [] 2080 args = self.initCommand("resolve")
2109 args.append('resolve')
2110 self.addArguments(args, self.options['global'])
2111 args.append("--mark") 2081 args.append("--mark")
2112 2082
2113 if isinstance(name, list): 2083 if isinstance(name, list):
2114 dname, fnames = self.splitPathList(name) 2084 dname, fnames = self.splitPathList(name)
2115 self.addArguments(args, name) 2085 self.addArguments(args, name)
2150 self.tr("Create Branch"), 2120 self.tr("Create Branch"),
2151 self.tr("Enter branch name"), 2121 self.tr("Enter branch name"),
2152 sorted(self.hgGetBranchesList(repodir)), 2122 sorted(self.hgGetBranchesList(repodir)),
2153 0, True) 2123 0, True)
2154 if ok and name: 2124 if ok and name:
2155 args = [] 2125 args = self.initCommand("branch")
2156 args.append('branch')
2157 args.append(name.strip().replace(" ", "_")) 2126 args.append(name.strip().replace(" ", "_"))
2158 2127
2159 dia = HgDialog( 2128 dia = HgDialog(
2160 self.tr('Creating branch in the Mercurial repository'), 2129 self.tr('Creating branch in the Mercurial repository'),
2161 self) 2130 self)
2176 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2145 while not os.path.isdir(os.path.join(repodir, self.adminDir)):
2177 repodir = os.path.dirname(repodir) 2146 repodir = os.path.dirname(repodir)
2178 if os.path.splitdrive(repodir)[1] == os.sep: 2147 if os.path.splitdrive(repodir)[1] == os.sep:
2179 return 2148 return
2180 2149
2181 args = [] 2150 args = self.initCommand("branch")
2182 args.append("branch")
2183 2151
2184 dia = HgDialog(self.tr('Showing current branch'), self) 2152 dia = HgDialog(self.tr('Showing current branch'), self)
2185 res = dia.startProcess(args, repodir, False) 2153 res = dia.startProcess(args, repodir, False)
2186 if res: 2154 if res:
2187 dia.exec_() 2155 dia.exec_()
2272 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2240 while not os.path.isdir(os.path.join(repodir, self.adminDir)):
2273 repodir = os.path.dirname(repodir) 2241 repodir = os.path.dirname(repodir)
2274 if os.path.splitdrive(repodir)[1] == os.sep: 2242 if os.path.splitdrive(repodir)[1] == os.sep:
2275 return 2243 return
2276 2244
2277 args = [] 2245 args = self.initCommand("verify")
2278 args.append('verify')
2279 2246
2280 dia = HgDialog( 2247 dia = HgDialog(
2281 self.tr('Verifying the integrity of the Mercurial repository'), 2248 self.tr('Verifying the integrity of the Mercurial repository'),
2282 self) 2249 self)
2283 res = dia.startProcess(args, repodir) 2250 res = dia.startProcess(args, repodir)
2297 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2264 while not os.path.isdir(os.path.join(repodir, self.adminDir)):
2298 repodir = os.path.dirname(repodir) 2265 repodir = os.path.dirname(repodir)
2299 if os.path.splitdrive(repodir)[1] == os.sep: 2266 if os.path.splitdrive(repodir)[1] == os.sep:
2300 return 2267 return
2301 2268
2302 args = [] 2269 args = self.initCommand("showconfig")
2303 args.append('showconfig')
2304 args.append("--untrusted") 2270 args.append("--untrusted")
2305 2271
2306 dia = HgDialog( 2272 dia = HgDialog(
2307 self.tr('Showing the combined configuration settings'), 2273 self.tr('Showing the combined configuration settings'),
2308 self) 2274 self)
2323 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2289 while not os.path.isdir(os.path.join(repodir, self.adminDir)):
2324 repodir = os.path.dirname(repodir) 2290 repodir = os.path.dirname(repodir)
2325 if os.path.splitdrive(repodir)[1] == os.sep: 2291 if os.path.splitdrive(repodir)[1] == os.sep:
2326 return 2292 return
2327 2293
2328 args = [] 2294 args = self.initCommand("paths")
2329 args.append('paths')
2330 2295
2331 dia = HgDialog( 2296 dia = HgDialog(
2332 self.tr('Showing aliases for remote repositories'), 2297 self.tr('Showing aliases for remote repositories'),
2333 self) 2298 self)
2334 res = dia.startProcess(args, repodir, False) 2299 res = dia.startProcess(args, repodir, False)
2348 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2313 while not os.path.isdir(os.path.join(repodir, self.adminDir)):
2349 repodir = os.path.dirname(repodir) 2314 repodir = os.path.dirname(repodir)
2350 if os.path.splitdrive(repodir)[1] == os.sep: 2315 if os.path.splitdrive(repodir)[1] == os.sep:
2351 return 2316 return
2352 2317
2353 args = [] 2318 args = self.initCommand("recover")
2354 args.append('recover')
2355 2319
2356 dia = HgDialog( 2320 dia = HgDialog(
2357 self.tr('Recovering from interrupted transaction'), 2321 self.tr('Recovering from interrupted transaction'),
2358 self) 2322 self)
2359 res = dia.startProcess(args, repodir, False) 2323 res = dia.startProcess(args, repodir, False)
2373 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2337 while not os.path.isdir(os.path.join(repodir, self.adminDir)):
2374 repodir = os.path.dirname(repodir) 2338 repodir = os.path.dirname(repodir)
2375 if os.path.splitdrive(repodir)[1] == os.sep: 2339 if os.path.splitdrive(repodir)[1] == os.sep:
2376 return 2340 return
2377 2341
2378 args = [] 2342 args = self.initCommand("identify")
2379 args.append('identify')
2380 2343
2381 dia = HgDialog(self.tr('Identifying project directory'), self) 2344 dia = HgDialog(self.tr('Identifying project directory'), self)
2382 res = dia.startProcess(args, repodir, False) 2345 res = dia.startProcess(args, repodir, False)
2383 if res: 2346 if res:
2384 dia.exec_() 2347 dia.exec_()
2495 if not res: 2458 if not res:
2496 return 2459 return
2497 fname = Utilities.toNativeSeparators(fname) 2460 fname = Utilities.toNativeSeparators(fname)
2498 self.__lastChangeGroupPath = os.path.dirname(fname) 2461 self.__lastChangeGroupPath = os.path.dirname(fname)
2499 2462
2500 args = [] 2463 args = self.initCommand("bundle")
2501 args.append('bundle')
2502 if all: 2464 if all:
2503 args.append("--all") 2465 args.append("--all")
2504 for rev in revs: 2466 for rev in revs:
2505 args.append("--rev") 2467 args.append("--rev")
2506 args.append(rev) 2468 args.append(rev)
2575 self.__lastChangeGroupPath or repodir, 2537 self.__lastChangeGroupPath or repodir,
2576 self.tr("Mercurial Changegroup Files (*.hg);;All Files (*)")) 2538 self.tr("Mercurial Changegroup Files (*.hg);;All Files (*)"))
2577 if file: 2539 if file:
2578 self.__lastChangeGroupPath = os.path.dirname(file) 2540 self.__lastChangeGroupPath = os.path.dirname(file)
2579 2541
2580 args = [] 2542 args = self.initCommand("identify")
2581 args.append('identify')
2582 args.append(file) 2543 args.append(file)
2583 2544
2584 dia = HgDialog(self.tr('Identifying changegroup file'), self) 2545 dia = HgDialog(self.tr('Identifying changegroup file'), self)
2585 res = dia.startProcess(args, repodir, False) 2546 res = dia.startProcess(args, repodir, False)
2586 if res: 2547 if res:
2616 self.__ui, 2577 self.__ui,
2617 self.tr("Apply changegroups"), 2578 self.tr("Apply changegroups"),
2618 self.tr("""Shall the working directory be updated?"""), 2579 self.tr("""Shall the working directory be updated?"""),
2619 yesDefault=True) 2580 yesDefault=True)
2620 2581
2621 args = [] 2582 args = self.initCommand("unbundle")
2622 args.append('unbundle')
2623 if update: 2583 if update:
2624 args.append("--update") 2584 args.append("--update")
2625 args.append("--verbose") 2585 args.append("--verbose")
2626 args.extend(files) 2586 args.extend(files)
2627 2587
2672 if dlg.exec_() == QDialog.Accepted: 2632 if dlg.exec_() == QDialog.Accepted:
2673 rev = dlg.getRevision() 2633 rev = dlg.getRevision()
2674 else: 2634 else:
2675 return 2635 return
2676 2636
2677 args = [] 2637 args = self.initCommand("bisect")
2678 args.append("bisect")
2679 args.append("--{0}".format(subcommand)) 2638 args.append("--{0}".format(subcommand))
2680 if rev: 2639 if rev:
2681 args.append(rev) 2640 args.append(rev)
2682 2641
2683 dia = HgDialog( 2642 dia = HgDialog(
2693 This will not remove the file from the project directory. 2652 This will not remove the file from the project directory.
2694 2653
2695 @param name file/directory name to be removed (string or list of 2654 @param name file/directory name to be removed (string or list of
2696 strings)) 2655 strings))
2697 """ 2656 """
2698 args = [] 2657 args = self.initCommand("forget")
2699 args.append('forget')
2700 self.addArguments(args, self.options['global'])
2701 args.append('-v') 2658 args.append('-v')
2702 2659
2703 if isinstance(name, list): 2660 if isinstance(name, list):
2704 dname, fnames = self.splitPathList(name) 2661 dname, fnames = self.splitPathList(name)
2705 self.addArguments(args, name) 2662 self.addArguments(args, name)
2758 self.__ui, 2715 self.__ui,
2759 self.tr("Backing out changeset"), 2716 self.tr("Backing out changeset"),
2760 self.tr("""No revision given. Aborting...""")) 2717 self.tr("""No revision given. Aborting..."""))
2761 return 2718 return
2762 2719
2763 args = [] 2720 args = self.initCommand("backout")
2764 args.append('backout')
2765 args.append('-v') 2721 args.append('-v')
2766 if merge: 2722 if merge:
2767 args.append('--merge') 2723 args.append('--merge')
2768 if date: 2724 if date:
2769 args.append('--date') 2725 args.append('--date')
2847 dlg = HgImportDialog() 2803 dlg = HgImportDialog()
2848 if dlg.exec_() == QDialog.Accepted: 2804 if dlg.exec_() == QDialog.Accepted:
2849 patchFile, noCommit, message, date, user, stripCount, force = \ 2805 patchFile, noCommit, message, date, user, stripCount, force = \
2850 dlg.getParameters() 2806 dlg.getParameters()
2851 2807
2852 args = [] 2808 args = self.initCommand("import")
2853 args.append("import")
2854 args.append("--verbose") 2809 args.append("--verbose")
2855 if noCommit: 2810 if noCommit:
2856 args.append("--no-commit") 2811 args.append("--no-commit")
2857 else: 2812 else:
2858 if message: 2813 if message:
2901 dlg = HgExportDialog() 2856 dlg = HgExportDialog()
2902 if dlg.exec_() == QDialog.Accepted: 2857 if dlg.exec_() == QDialog.Accepted:
2903 filePattern, revisions, switchParent, allText, noDates, git = \ 2858 filePattern, revisions, switchParent, allText, noDates, git = \
2904 dlg.getParameters() 2859 dlg.getParameters()
2905 2860
2906 args = [] 2861 args = self.initCommand("export")
2907 args.append("export")
2908 args.append("--output") 2862 args.append("--output")
2909 args.append(filePattern) 2863 args.append(filePattern)
2910 args.append("--verbose") 2864 args.append("--verbose")
2911 if switchParent: 2865 if switchParent:
2912 args.append("--switch-parent") 2866 args.append("--switch-parent")
2950 data = dlg.getData() 2904 data = dlg.getData()
2951 2905
2952 if data: 2906 if data:
2953 revs, phase, force = data 2907 revs, phase, force = data
2954 2908
2955 args = [] 2909 args = self.initCommand("phase")
2956 args.append("phase")
2957 if phase == "p": 2910 if phase == "p":
2958 args.append("--public") 2911 args.append("--public")
2959 elif phase == "d": 2912 elif phase == "d":
2960 args.append("--draft") 2913 args.append("--draft")
2961 elif phase == "s": 2914 elif phase == "s":
2998 dlg = HgGraftDialog(self, revs) 2951 dlg = HgGraftDialog(self, revs)
2999 if dlg.exec_() == QDialog.Accepted: 2952 if dlg.exec_() == QDialog.Accepted:
3000 revs, (userData, currentUser, userName), \ 2953 revs, (userData, currentUser, userName), \
3001 (dateData, currentDate, dateStr), log, dryrun = dlg.getData() 2954 (dateData, currentDate, dateStr), log, dryrun = dlg.getData()
3002 2955
3003 args = [] 2956 args = self.initCommand("graft")
3004 args.append("graft")
3005 args.append("--verbose") 2957 args.append("--verbose")
3006 if userData: 2958 if userData:
3007 if currentUser: 2959 if currentUser:
3008 args.append("--currentuser") 2960 args.append("--currentuser")
3009 else: 2961 else:
3041 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2993 while not os.path.isdir(os.path.join(repodir, self.adminDir)):
3042 repodir = os.path.dirname(repodir) 2994 repodir = os.path.dirname(repodir)
3043 if os.path.splitdrive(repodir)[1] == os.sep: 2995 if os.path.splitdrive(repodir)[1] == os.sep:
3044 return 2996 return
3045 2997
3046 args = [] 2998 args = self.initCommand("graft")
3047 args.append("graft")
3048 args.append("--continue") 2999 args.append("--continue")
3049 args.append("--verbose") 3000 args.append("--verbose")
3050 3001
3051 dia = HgDialog(self.tr('Copy Changesets (Continue)'), self) 3002 dia = HgDialog(self.tr('Copy Changesets (Continue)'), self)
3052 res = dia.startProcess(args, repodir) 3003 res = dia.startProcess(args, repodir)
3070 from .HgArchiveDialog import HgArchiveDialog 3021 from .HgArchiveDialog import HgArchiveDialog
3071 dlg = HgArchiveDialog(self) 3022 dlg = HgArchiveDialog(self)
3072 if dlg.exec_() == QDialog.Accepted: 3023 if dlg.exec_() == QDialog.Accepted:
3073 archive, type_, prefix, subrepos = dlg.getData() 3024 archive, type_, prefix, subrepos = dlg.getData()
3074 3025
3075 args = [] 3026 args = self.initCommand("archive")
3076 args.append("archive")
3077 if type_: 3027 if type_:
3078 args.append("--type") 3028 args.append("--type")
3079 args.append(type_) 3029 args.append(type_)
3080 if prefix: 3030 if prefix:
3081 args.append("--prefix") 3031 args.append("--prefix")
3241 def __checkDefaults(self): 3191 def __checkDefaults(self):
3242 """ 3192 """
3243 Private method to check, if the default and default-push URLs 3193 Private method to check, if the default and default-push URLs
3244 have been configured. 3194 have been configured.
3245 """ 3195 """
3246 args = [] 3196 args = self.initCommand("showconfig")
3247 args.append('showconfig')
3248 args.append('paths') 3197 args.append('paths')
3249 3198
3250 output = "" 3199 output = ""
3251 if self.__client is None: 3200 if self.__client is None:
3252 process = QProcess() 3201 process = QProcess()
3254 process.start('hg', args) 3203 process.start('hg', args)
3255 procStarted = process.waitForStarted(5000) 3204 procStarted = process.waitForStarted(5000)
3256 if procStarted: 3205 if procStarted:
3257 finished = process.waitForFinished(30000) 3206 finished = process.waitForFinished(30000)
3258 if finished and process.exitCode() == 0: 3207 if finished and process.exitCode() == 0:
3259 output = str( 3208 output = str(process.readAllStandardOutput(),
3260 process.readAllStandardOutput(), 3209 self.getEncoding(), 'replace')
3261 Preferences.getSystem("IOEncoding"), 'replace')
3262 else: 3210 else:
3263 output, error = self.__client.runcommand(args) 3211 output, error = self.__client.runcommand(args)
3264 3212
3265 if output: 3213 if output:
3266 self.__defaultConfigured = False 3214 self.__defaultConfigured = False
3342 Private method to get the active extensions from Mercurial. 3290 Private method to get the active extensions from Mercurial.
3343 """ 3291 """
3344 activeExtensions = sorted(self.__activeExtensions) 3292 activeExtensions = sorted(self.__activeExtensions)
3345 self.__activeExtensions = [] 3293 self.__activeExtensions = []
3346 3294
3347 args = [] 3295 args = self.initCommand("showconfig")
3348 args.append('showconfig')
3349 args.append('extensions') 3296 args.append('extensions')
3350 3297
3351 output = "" 3298 output = ""
3352 if self.__client is None: 3299 if self.__client is None:
3353 process = QProcess() 3300 process = QProcess()
3355 process.start('hg', args) 3302 process.start('hg', args)
3356 procStarted = process.waitForStarted(5000) 3303 procStarted = process.waitForStarted(5000)
3357 if procStarted: 3304 if procStarted:
3358 finished = process.waitForFinished(30000) 3305 finished = process.waitForFinished(30000)
3359 if finished and process.exitCode() == 0: 3306 if finished and process.exitCode() == 0:
3360 output = str( 3307 output = str(process.readAllStandardOutput(),
3361 process.readAllStandardOutput(), 3308 self.getEncoding(), 'replace')
3362 Preferences.getSystem("IOEncoding"), 'replace')
3363 else: 3309 else:
3364 output, error = self.__client.runcommand(args) 3310 output, error = self.__client.runcommand(args)
3365 3311
3366 if output: 3312 if output:
3367 for line in output.splitlines(): 3313 for line in output.splitlines():

eric ide

mercurial