comparison hglib/client.py @ 134:1b47146a4a2c 1.4

style: fix long lines
author Matt Mackall <mpm@selenic.com>
date Tue, 30 Sep 2014 12:48:04 -0500
parents b6f601ba7f3c
children dc63978871ed
comparison
equal deleted inserted replaced
133:b6f601ba7f3c 134:1b47146a4a2c
76 76
77 msg = msg.split('\n') 77 msg = msg.split('\n')
78 78
79 self.capabilities = msg[0][len('capabilities: '):] 79 self.capabilities = msg[0][len('capabilities: '):]
80 if not self.capabilities: 80 if not self.capabilities:
81 raise error.ResponseError("bad hello message: expected 'capabilities: '" 81 raise error.ResponseError(
82 ", got %r" % msg[0]) 82 "bad hello message: expected 'capabilities: '"
83 ", got %r" % msg[0])
83 84
84 self.capabilities = set(self.capabilities.split()) 85 self.capabilities = set(self.capabilities.split())
85 86
86 # at the very least the server should be able to run commands 87 # at the very least the server should be able to run commands
87 assert 'runcommand' in self.capabilities 88 assert 'runcommand' in self.capabilities
101 else: 102 else:
102 return channel, self.server.stdout.read(length) 103 return channel, self.server.stdout.read(length)
103 104
104 @staticmethod 105 @staticmethod
105 def _parserevs(splitted): 106 def _parserevs(splitted):
106 ''' splitted is a list of fields according to our rev.style, where each 6 107 '''splitted is a list of fields according to our rev.style, where
107 fields compose one revision. ''' 108 each 6 fields compose one revision.
109 '''
108 revs = [] 110 revs = []
109 for rev in util.grouper(7, splitted): 111 for rev in util.grouper(7, splitted):
110 # truncate the timezone and convert to a local datetime 112 # truncate the timezone and convert to a local datetime
111 posixtime = float(rev[6].split('.', 1)[0]) 113 posixtime = float(rev[6].split('.', 1)[0])
112 dt = datetime.datetime.fromtimestamp(posixtime) 114 dt = datetime.datetime.fromtimestamp(posixtime)
113 revs.append(revision(rev[0], rev[1], rev[2], rev[3], rev[4], rev[5], dt)) 115 revs.append(revision(rev[0], rev[1], rev[2], rev[3],
116 rev[4], rev[5], dt))
114 return revs 117 return revs
115 118
116 def runcommand(self, args, inchannels, outchannels): 119 def runcommand(self, args, inchannels, outchannels):
117 def writeblock(data): 120 def writeblock(data):
118 self.server.stdin.write(struct.pack(self.inputfmt, len(data))) 121 self.server.stdin.write(struct.pack(self.inputfmt, len(data)))
137 # result channel, command finished 140 # result channel, command finished
138 elif channel == 'r': 141 elif channel == 'r':
139 return struct.unpack(hgclient.retfmt, data)[0] 142 return struct.unpack(hgclient.retfmt, data)[0]
140 # a channel that we don't know and can't ignore 143 # a channel that we don't know and can't ignore
141 elif channel.isupper(): 144 elif channel.isupper():
142 raise error.ResponseError("unexpected data on required channel '%s'" 145 raise error.ResponseError(
143 % channel) 146 "unexpected data on required channel '%s'" % channel)
144 # optional channel 147 # optional channel
145 else: 148 else:
146 pass 149 pass
147 150
148 def rawcommand(self, args, eh=None, prompt=None, input=None): 151 def rawcommand(self, args, eh=None, prompt=None, input=None):
189 self.server = util.popen(self._args, self._env) 192 self.server = util.popen(self._args, self._env)
190 self._readhello() 193 self._readhello()
191 return self 194 return self
192 195
193 def close(self): 196 def close(self):
194 """ 197 """Closes the command server instance and waits for it to exit,
195 Closes the command server instance and waits for it to exit, returns the 198 returns the exit code.
196 exit code. 199
197 200 Attempting to call any function afterwards that needs to
198 Attempting to call any function afterwards that needs to communicate with 201 communicate with the server will raise a ValueError.
199 the server will raise a ValueError.
200 """ 202 """
201 self.server.stdin.close() 203 self.server.stdin.close()
202 self.server.wait() 204 self.server.wait()
203 ret = self.server.returncode 205 ret = self.server.returncode
204 self.server = None 206 self.server = None
228 230
229 return bool(eh) 231 return bool(eh)
230 232
231 def addremove(self, files=[], similarity=None, dryrun=False, include=None, 233 def addremove(self, files=[], similarity=None, dryrun=False, include=None,
232 exclude=None): 234 exclude=None):
233 """ 235 """Add all new files and remove all missing files from the repository.
234 Add all new files and remove all missing files from the repository. 236
235 237 New files are ignored if they match any of the patterns in
236 New files are ignored if they match any of the patterns in ".hgignore". As 238 ".hgignore". As with add, these changes take effect at the
237 with add, these changes take effect at the next commit. 239 next commit.
238 240
239 similarity - used to detect renamed files. With a parameter 241 similarity - used to detect renamed files. With a parameter
240 greater than 0, this compares every removed file with every added file and 242 greater than 0, this compares every removed file with every
241 records those similar enough as renames. This option takes a percentage 243 added file and records those similar enough as renames. This
242 between 0 (disabled) and 100 (files must be identical) as its parameter. 244 option takes a percentage between 0 (disabled) and 100 (files
243 Detecting renamed files this way can be expensive. After using this 245 must be identical) as its parameter. Detecting renamed files
244 option, "hg status -C" can be used to check which files were identified as 246 this way can be expensive. After using this option, "hg status
245 moved or renamed. 247 -C" can be used to check which files were identified as moved
248 or renamed.
246 249
247 dryrun - do no perform actions 250 dryrun - do no perform actions
248 include - include names matching the given patterns 251 include - include names matching the given patterns
249 exclude - exclude names matching the given patterns 252 exclude - exclude names matching the given patterns
250 253
251 Return True if all files are successfully added. 254 Return True if all files are successfully added.
255
252 """ 256 """
253 if not isinstance(files, list): 257 if not isinstance(files, list):
254 files = [files] 258 files = [files]
255 259
256 args = cmdbuilder('addremove', s=similarity, n=dryrun, I=include, 260 args = cmdbuilder('addremove', s=similarity, n=dryrun, I=include,
295 for line in out.splitlines(): 299 for line in out.splitlines():
296 yield tuple(line.split(': ', 1)) 300 yield tuple(line.split(': ', 1))
297 301
298 def archive(self, dest, rev=None, nodecode=False, prefix=None, type=None, 302 def archive(self, dest, rev=None, nodecode=False, prefix=None, type=None,
299 subrepos=False, include=None, exclude=None): 303 subrepos=False, include=None, exclude=None):
300 """ 304 """Create an unversioned archive of a repository revision.
301 Create an unversioned archive of a repository revision.
302 305
303 The exact name of the destination archive or directory is given using a 306 The exact name of the destination archive or directory is given using a
304 format string; see export for details. 307 format string; see export for details.
305 308
306 Each member added to an archive file has a directory prefix prepended. Use 309 Each member added to an archive file has a directory prefix
307 prefix to specify a format string for the prefix. The default is the 310 prepended. Use prefix to specify a format string for the
308 basename of the archive, with suffixes removed. 311 prefix. The default is the basename of the archive, with
312 suffixes removed.
309 313
310 dest - destination path 314 dest - destination path
311 rev - revision to distribute. The revision used is the parent of the 315 rev - revision to distribute. The revision used is the parent of the
312 working directory if one isn't given. 316 working directory if one isn't given.
313 317
326 "zip" zip archive, compressed using deflate 330 "zip" zip archive, compressed using deflate
327 331
328 subrepos - recurse into subrepositories 332 subrepos - recurse into subrepositories
329 include - include names matching the given patterns 333 include - include names matching the given patterns
330 exclude - exclude names matching the given patterns 334 exclude - exclude names matching the given patterns
335
331 """ 336 """
332 args = cmdbuilder('archive', dest, r=rev, no_decode=nodecode, p=prefix, 337 args = cmdbuilder('archive', dest, r=rev, no_decode=nodecode, p=prefix,
333 t=type, S=subrepos, I=include, X=exclude, 338 t=type, S=subrepos, I=include, X=exclude,
334 hidden=self.hidden) 339 hidden=self.hidden)
335 340
336 self.rawcommand(args) 341 self.rawcommand(args)
337 342
338 def backout(self, rev, merge=False, parent=None, tool=None, message=None, 343 def backout(self, rev, merge=False, parent=None, tool=None, message=None,
339 logfile=None, date=None, user=None): 344 logfile=None, date=None, user=None):
340 """ 345 """Prepare a new changeset with the effect of rev undone in the current
341 Prepare a new changeset with the effect of rev undone in the current
342 working directory. 346 working directory.
343 347
344 If rev is the parent of the working directory, then this new changeset is 348 If rev is the parent of the working directory, then this new
345 committed automatically. Otherwise, hg needs to merge the changes and the 349 changeset is committed automatically. Otherwise, hg needs to
346 merged result is left uncommitted. 350 merge the changes and the merged result is left uncommitted.
347 351
348 rev - revision to backout 352 rev - revision to backout
349 merge - merge with old dirstate parent after backout 353 merge - merge with old dirstate parent after backout
350 parent - parent to choose when backing out merge 354 parent - parent to choose when backing out merge
351 tool - specify merge tool 355 tool - specify merge tool
352 message - use text as commit message 356 message - use text as commit message
353 logfile - read commit message from file 357 logfile - read commit message from file
354 date - record the specified date as commit date 358 date - record the specified date as commit date
355 user - record the specified user as committer 359 user - record the specified user as committer
360
356 """ 361 """
357 if message and logfile: 362 if message and logfile:
358 raise ValueError("cannot specify both a message and a logfile") 363 raise ValueError("cannot specify both a message and a logfile")
359 364
360 args = cmdbuilder('backout', r=rev, merge=merge, parent=parent, t=tool, 365 args = cmdbuilder('backout', r=rev, merge=merge, parent=parent, t=tool,
361 m=message, l=logfile, d=date, u=user, 366 m=message, l=logfile, d=date, u=user,
362 hidden=self.hidden) 367 hidden=self.hidden)
363 368
364 self.rawcommand(args) 369 self.rawcommand(args)
365 370
366 def bookmark(self, name, rev=None, force=False, delete=False, inactive=False, 371 def bookmark(self, name, rev=None, force=False, delete=False,
367 rename=None): 372 inactive=False, rename=None):
368 """ 373 """
369 Set a bookmark on the working directory's parent revision or rev, 374 Set a bookmark on the working directory's parent revision or rev,
370 with the given name. 375 with the given name.
371 376
372 name - bookmark name 377 name - bookmark name
402 rev, node = line.split(':') 407 rev, node = line.split(':')
403 bms.append((name, int(rev), node)) 408 bms.append((name, int(rev), node))
404 return bms, current 409 return bms, current
405 410
406 def branch(self, name=None, clean=False, force=False): 411 def branch(self, name=None, clean=False, force=False):
407 """ 412 """When name isn't given, return the current branch name. Otherwise
408 When name isn't given, return the current branch name. Otherwise set the 413 set the working directory branch name (the branch will not
409 working directory branch name (the branch will not exist in the repository 414 exist in the repository until the next commit). Standard
410 until the next commit). Standard practice recommends that primary 415 practice recommends that primary development take place on the
411 development take place on the 'default' branch. 416 'default' branch.
412 417
413 When clean is True, reset and return the working directory branch to that 418 When clean is True, reset and return the working directory
414 of the parent of the working directory, negating a previous branch change. 419 branch to that of the parent of the working directory,
420 negating a previous branch change.
415 421
416 name - new branch name 422 name - new branch name
417 clean - reset branch name to parent branch name 423 clean - reset branch name to parent branch name
418 force - set branch name even if it shadows an existing branch 424 force - set branch name even if it shadows an existing branch
425
419 """ 426 """
420 if name and clean: 427 if name and clean:
421 raise ValueError('cannot use both name and clean') 428 raise ValueError('cannot use both name and clean')
422 429
423 args = cmdbuilder('branch', name, f=force, C=clean) 430 args = cmdbuilder('branch', name, f=force, C=clean)
449 node = node.split()[0] # get rid of ' (inactive)' 456 node = node.split()[0] # get rid of ' (inactive)'
450 branches.append((name, int(rev), node)) 457 branches.append((name, int(rev), node))
451 return branches 458 return branches
452 459
453 def bundle(self, file, destrepo=None, rev=[], branch=[], base=[], all=False, 460 def bundle(self, file, destrepo=None, rev=[], branch=[], base=[], all=False,
454 force=False, type=None, ssh=None, remotecmd=None, insecure=False): 461 force=False, type=None, ssh=None, remotecmd=None,
455 """ 462 insecure=False):
456 Generate a compressed changegroup file collecting changesets not known to 463 """Generate a compressed changegroup file collecting changesets not
457 be in another repository. 464 known to be in another repository.
458 465
459 If destrepo isn't given, then hg assumes the destination will have all 466 If destrepo isn't given, then hg assumes the destination will have all
460 the nodes you specify with base. To create a bundle containing all 467 the nodes you specify with base. To create a bundle containing all
461 changesets, use all (or set base to 'null'). 468 changesets, use all (or set base to 'null').
462 469
464 destrepo - repository to look for changes 471 destrepo - repository to look for changes
465 rev - a changeset intended to be added to the destination 472 rev - a changeset intended to be added to the destination
466 branch - a specific branch you would like to bundle 473 branch - a specific branch you would like to bundle
467 base - a base changeset assumed to be available at the destination 474 base - a base changeset assumed to be available at the destination
468 all - bundle all changesets in the repository 475 all - bundle all changesets in the repository
469 type - bundle compression type to use, available compression methods are: 476 type - bundle compression type to use, available compression
470 none, bzip2, and gzip (default: bzip2) 477 methods are: none, bzip2, and gzip (default: bzip2)
471 478
472 force - run even when the destrepo is unrelated 479 force - run even when the destrepo is unrelated
473 ssh - specify ssh command to use 480 ssh - specify ssh command to use
474 remotecmd - specify hg command to run on the remote side 481 remotecmd - specify hg command to run on the remote side
475 insecure - do not verify server certificate (ignoring web.cacerts config) 482 insecure - do not verify server certificate (ignoring
483 web.cacerts config)
476 484
477 Return True if a bundle was created, False if no changes were found. 485 Return True if a bundle was created, False if no changes were found.
486
478 """ 487 """
479 args = cmdbuilder('bundle', file, destrepo, f=force, r=rev, b=branch, 488 args = cmdbuilder('bundle', file, destrepo, f=force, r=rev, b=branch,
480 base=base, a=all, t=type, e=ssh, remotecmd=remotecmd, 489 base=base, a=all, t=type, e=ssh, remotecmd=remotecmd,
481 insecure=insecure, hidden=self.hidden) 490 insecure=insecure, hidden=self.hidden)
482 491
484 self.rawcommand(args, eh=eh) 493 self.rawcommand(args, eh=eh)
485 494
486 return bool(eh) 495 return bool(eh)
487 496
488 def cat(self, files, rev=None, output=None): 497 def cat(self, files, rev=None, output=None):
489 """ 498 """Return a string containing the specified files as they were at the
490 Return a string containing the specified files as they were at the
491 given revision. If no revision is given, the parent of the working 499 given revision. If no revision is given, the parent of the working
492 directory is used, or tip if no revision is checked out. 500 directory is used, or tip if no revision is checked out.
493 501
494 If output is given, writes the contents to the specified file. 502 If output is given, writes the contents to the specified file.
495 The name of the file is given using a format string. The formatting rules 503 The name of the file is given using a format string. The
496 are the same as for the export command, with the following additions: 504 formatting rules are the same as for the export command, with
505 the following additions:
497 506
498 "%s" basename of file being printed 507 "%s" basename of file being printed
499 "%d" dirname of file being printed, or '.' if in repository root 508 "%d" dirname of file being printed, or '.' if in repository root
500 "%p" root-relative path name of file being printed 509 "%p" root-relative path name of file being printed
510
501 """ 511 """
502 args = cmdbuilder('cat', r=rev, o=output, hidden=self.hidden, *files) 512 args = cmdbuilder('cat', r=rev, o=output, hidden=self.hidden, *files)
503 out = self.rawcommand(args) 513 out = self.rawcommand(args)
504 514
505 if not output: 515 if not output:
515 525
516 branch - clone only the specified branch 526 branch - clone only the specified branch
517 updaterev - revision, tag or branch to check out 527 updaterev - revision, tag or branch to check out
518 revrange - include the specified changeset 528 revrange - include the specified changeset
519 """ 529 """
520 args = cmdbuilder('clone', source, dest, b=branch, u=updaterev, r=revrange) 530 args = cmdbuilder('clone', source, dest, b=branch,
531 u=updaterev, r=revrange)
521 self.rawcommand(args) 532 self.rawcommand(args)
522 533
523 def commit(self, message=None, logfile=None, addremove=False, closebranch=False, 534 def commit(self, message=None, logfile=None, addremove=False,
524 date=None, user=None, include=None, exclude=None): 535 closebranch=False, date=None, user=None, include=None,
536 exclude=None):
525 """ 537 """
526 Commit changes reported by status into the repository. 538 Commit changes reported by status into the repository.
527 539
528 message - the commit message 540 message - the commit message
529 logfile - read commit message from file 541 logfile - read commit message from file
547 out = self.rawcommand(args) 559 out = self.rawcommand(args)
548 rev, node = out.splitlines()[-1].rsplit(':') 560 rev, node = out.splitlines()[-1].rsplit(':')
549 return int(rev.split()[-1]), node 561 return int(rev.split()[-1]), node
550 562
551 def config(self, names=[], untrusted=False, showsource=False): 563 def config(self, names=[], untrusted=False, showsource=False):
552 """ 564 """Return a list of (section, key, value) config settings from all
553 Return a list of (section, key, value) config settings from all hgrc files 565 hgrc files
554 566
555 When showsource is specified, return (source, section, key, value) where 567 When showsource is specified, return (source, section, key, value) where
556 source is of the form filename:[line] 568 source is of the form filename:[line]
569
557 """ 570 """
558 def splitline(s): 571 def splitline(s):
559 k, value = s.rstrip().split('=', 1) 572 k, value = s.rstrip().split('=', 1)
560 section, key = k.split('.', 1) 573 section, key = k.split('.', 1)
561 return (section, key, value) 574 return (section, key, value)
593 606
594 return self._encoding 607 return self._encoding
595 608
596 def copy(self, source, dest, after=False, force=False, dryrun=False, 609 def copy(self, source, dest, after=False, force=False, dryrun=False,
597 include=None, exclude=None): 610 include=None, exclude=None):
598 """ 611 """Mark dest as having copies of source files. If dest is a
599 Mark dest as having copies of source files. If dest is a directory, copies 612 directory, copies are put in that directory. If dest is a
600 are put in that directory. If dest is a file, then source must be a string. 613 file, then source must be a string.
601 614
602 Returns True on success, False if errors are encountered. 615 Returns True on success, False if errors are encountered.
603 616
604 source - a file or a list of files 617 source - a file or a list of files
605 dest - a destination file or directory 618 dest - a destination file or directory
606 after - record a copy that has already occurred 619 after - record a copy that has already occurred
607 force - forcibly copy over an existing managed file 620 force - forcibly copy over an existing managed file
608 dryrun - do not perform actions, just print output 621 dryrun - do not perform actions, just print output
609 include - include names matching the given patterns 622 include - include names matching the given patterns
610 exclude - exclude names matching the given patterns 623 exclude - exclude names matching the given patterns
624
611 """ 625 """
612 if not isinstance(source, list): 626 if not isinstance(source, list):
613 source = [source] 627 source = [source]
614 628
615 source.append(dest) 629 source.append(dest)
620 self.rawcommand(args, eh=eh) 634 self.rawcommand(args, eh=eh)
621 635
622 return bool(eh) 636 return bool(eh)
623 637
624 def diff(self, files=[], revs=[], change=None, text=False, 638 def diff(self, files=[], revs=[], change=None, text=False,
625 git=False, nodates=False, showfunction=False, reverse=False, 639 git=False, nodates=False, showfunction=False,
626 ignoreallspace=False, ignorespacechange=False, ignoreblanklines=False, 640 reverse=False, ignoreallspace=False,
627 unified=None, stat=False, subrepos=False, include=None, exclude=None): 641 ignorespacechange=False, ignoreblanklines=False,
642 unified=None, stat=False, subrepos=False, include=None,
643 exclude=None):
628 """ 644 """
629 Return differences between revisions for the specified files. 645 Return differences between revisions for the specified files.
630 646
631 revs - a revision or a list of two revisions to diff 647 revs - a revision or a list of two revisions to diff
632 change - change made by revision 648 change - change made by revision
655 S=subrepos, I=include, X=exclude, hidden=self.hidden, 671 S=subrepos, I=include, X=exclude, hidden=self.hidden,
656 *files) 672 *files)
657 673
658 return self.rawcommand(args) 674 return self.rawcommand(args)
659 675
660 def export(self, revs, output=None, switchparent=False, text=False, git=False, 676 def export(self, revs, output=None, switchparent=False,
661 nodates=False): 677 text=False, git=False, nodates=False):
662 """ 678 """Return the header and diffs for one or more changesets. When
663 Return the header and diffs for one or more changesets. When output is 679 output is given, dumps to file. The name of the file is given
664 given, dumps to file. The name of the file is given using a format string. 680 using a format string. The formatting rules are as follows:
665 The formatting rules are as follows:
666 681
667 "%%" literal "%" character 682 "%%" literal "%" character
668 "%H" changeset hash (40 hexadecimal digits) 683 "%H" changeset hash (40 hexadecimal digits)
669 "%N" number of patches being generated 684 "%N" number of patches being generated
670 "%R" changeset revision number 685 "%R" changeset revision number
677 switchparent - diff against the second parent 692 switchparent - diff against the second parent
678 rev - a revision or list of revisions to export 693 rev - a revision or list of revisions to export
679 text - treat all files as text 694 text - treat all files as text
680 git - use git extended diff format 695 git - use git extended diff format
681 nodates - omit dates from diff headers 696 nodates - omit dates from diff headers
697
682 """ 698 """
683 if not isinstance(revs, list): 699 if not isinstance(revs, list):
684 revs = [revs] 700 revs = [revs]
685 args = cmdbuilder('export', o=output, switch_parent=switchparent, 701 args = cmdbuilder('export', o=output, switch_parent=switchparent,
686 a=text, g=git, nodates=nodates, hidden=self.hidden, 702 a=text, g=git, nodates=nodates, hidden=self.hidden,
690 706
691 if output is None: 707 if output is None:
692 return out 708 return out
693 709
694 def forget(self, files, include=None, exclude=None): 710 def forget(self, files, include=None, exclude=None):
695 """ 711 """Mark the specified files so they will no longer be tracked after
696 Mark the specified files so they will no longer be tracked after the next 712 the next commit.
697 commit.
698 713
699 This only removes files from the current branch, not from the entire 714 This only removes files from the current branch, not from the entire
700 project history, and it does not delete them from the working directory. 715 project history, and it does not delete them from the working directory.
701 716
702 Returns True on success. 717 Returns True on success.
703 718
704 include - include names matching the given patterns 719 include - include names matching the given patterns
705 exclude - exclude names matching the given patterns 720 exclude - exclude names matching the given patterns
721
706 """ 722 """
707 if not isinstance(files, list): 723 if not isinstance(files, list):
708 files = [files] 724 files = [files]
709 725
710 args = cmdbuilder('forget', I=include, X=exclude, *files) 726 args = cmdbuilder('forget', I=include, X=exclude, *files)
715 return bool(eh) 731 return bool(eh)
716 732
717 def grep(self, pattern, files=[], all=False, text=False, follow=False, 733 def grep(self, pattern, files=[], all=False, text=False, follow=False,
718 ignorecase=False, fileswithmatches=False, line=False, user=False, 734 ignorecase=False, fileswithmatches=False, line=False, user=False,
719 date=False, include=None, exclude=None): 735 date=False, include=None, exclude=None):
720 """ 736 """Search for a pattern in specified files and revisions.
721 Search for a pattern in specified files and revisions.
722 737
723 This behaves differently than Unix grep. It only accepts Python/Perl 738 This behaves differently than Unix grep. It only accepts Python/Perl
724 regexps. It searches repository history, not the working directory. 739 regexps. It searches repository history, not the working directory.
725 It always prints the revision number in which a match appears. 740 It always prints the revision number in which a match appears.
726 741
727 Yields (filename, revision, [line, [match status, [user, [date, [match]]]]]) 742 Yields (filename, revision, [line, [match status, [user,
728 per match depending on the given options. 743 [date, [match]]]]]) per match depending on the given options.
729 744
730 all - print all revisions that match 745 all - print all revisions that match
731 text - treat all files as text 746 text - treat all files as text
732 follow - follow changeset history, or file history across copies and renames 747 follow - follow changeset history, or file history across
748 copies and renames
733 ignorecase - ignore case when matching 749 ignorecase - ignore case when matching
734 fileswithmatches - return only filenames and revisions that match 750 fileswithmatches - return only filenames and revisions that match
735 line - return line numbers in the result tuple 751 line - return line numbers in the result tuple
736 user - return the author in the result tuple 752 user - return the author in the result tuple
737 date - return the date in the result tuple 753 date - return the date in the result tuple
738 include - include names matching the given patterns 754 include - include names matching the given patterns
739 exclude - exclude names matching the given patterns 755 exclude - exclude names matching the given patterns
756
740 """ 757 """
741 if not isinstance(files, list): 758 if not isinstance(files, list):
742 files = [files] 759 files = [files]
743 760
744 args = cmdbuilder('grep', all=all, a=text, f=follow, i=ignorecase, 761 args = cmdbuilder('grep', all=all, a=text, f=follow, i=ignorecase,
767 fieldcount -= 1 784 fieldcount -= 1
768 785
769 return util.grouper(fieldcount, out) 786 return util.grouper(fieldcount, out)
770 787
771 def heads(self, rev=[], startrev=[], topological=False, closed=False): 788 def heads(self, rev=[], startrev=[], topological=False, closed=False):
772 """ 789 """Return a list of current repository heads or branch heads.
773 Return a list of current repository heads or branch heads. 790
774 791 rev - return only branch heads on the branches associated with
775 rev - return only branch heads on the branches associated with the specified 792 the specified changesets.
776 changesets.
777 793
778 startrev - return only heads which are descendants of the given revs. 794 startrev - return only heads which are descendants of the given revs.
779 topological - named branch mechanics will be ignored and only changesets 795 topological - named branch mechanics will be ignored and only changesets
780 without children will be shown. 796 without children will be shown.
781 797
782 closed - normal and closed branch heads. 798 closed - normal and closed branch heads.
799
783 """ 800 """
784 if not isinstance(rev, list): 801 if not isinstance(rev, list):
785 rev = [rev] 802 rev = [rev]
786 803
787 args = cmdbuilder('heads', r=startrev, t=topological, c=closed, 804 args = cmdbuilder('heads', r=startrev, t=topological, c=closed,
796 out = self.rawcommand(args, eh=eh).split('\0')[:-1] 813 out = self.rawcommand(args, eh=eh).split('\0')[:-1]
797 return self._parserevs(out) 814 return self._parserevs(out)
798 815
799 def identify(self, rev=None, source=None, num=False, id=False, branch=False, 816 def identify(self, rev=None, source=None, num=False, id=False, branch=False,
800 tags=False, bookmarks=False): 817 tags=False, bookmarks=False):
801 """ 818 """Return a summary string identifying the repository state at rev
802 Return a summary string identifying the repository state at rev using one or 819 using one or two parent hash identifiers, followed by a "+" if
803 two parent hash identifiers, followed by a "+" if the working directory has 820 the working directory has uncommitted changes, the branch name
804 uncommitted changes, the branch name (if not default), a list of tags, and 821 (if not default), a list of tags, and a list of bookmarks.
805 a list of bookmarks. 822
806 823 When rev is not given, return a summary string of the current
807 When rev is not given, return a summary string of the current state of the 824 state of the repository.
808 repository.
809 825
810 Specifying source as a repository root or Mercurial bundle will cause 826 Specifying source as a repository root or Mercurial bundle will cause
811 lookup to operate on that repository/bundle. 827 lookup to operate on that repository/bundle.
812 828
813 num - show local revision number 829 num - show local revision number
814 id - show global revision id 830 id - show global revision id
815 branch - show branch 831 branch - show branch
816 tags - show tags 832 tags - show tags
817 bookmarks - show bookmarks 833 bookmarks - show bookmarks
818 """ 834
819 args = cmdbuilder('identify', source, r=rev, n=num, i=id, b=branch, t=tags, 835 """
820 B=bookmarks, hidden=self.hidden) 836 args = cmdbuilder('identify', source, r=rev, n=num, i=id,
837 b=branch, t=tags, B=bookmarks,
838 hidden=self.hidden)
821 839
822 return self.rawcommand(args) 840 return self.rawcommand(args)
823 841
824 def import_(self, patches, strip=None, force=False, nocommit=False, 842 def import_(self, patches, strip=None, force=False, nocommit=False,
825 bypass=False, exact=False, importbranch=False, message=None, 843 bypass=False, exact=False, importbranch=False, message=None,
826 date=None, user=None, similarity=None): 844 date=None, user=None, similarity=None):
827 """ 845 """Import the specified patches which can be a list of file names or a
828 Import the specified patches which can be a list of file names or a
829 file-like object and commit them individually (unless nocommit is 846 file-like object and commit them individually (unless nocommit is
830 specified). 847 specified).
831 848
832 strip - directory strip option for patch. This has the same meaning as the 849 strip - directory strip option for patch. This has the same
833 corresponding patch option (default: 1) 850 meaning as the corresponding patch option (default: 1)
834 851
835 force - skip check for outstanding uncommitted changes 852 force - skip check for outstanding uncommitted changes
836 nocommit - don't commit, just update the working directory 853 nocommit - don't commit, just update the working directory
837 bypass - apply patch without touching the working directory 854 bypass - apply patch without touching the working directory
838 exact - apply patch to the nodes from which it was generated 855 exact - apply patch to the nodes from which it was generated
839 importbranch - use any branch information in patch (implied by exact) 856 importbranch - use any branch information in patch (implied by exact)
840 message - the commit message 857 message - the commit message
841 date - record the specified date as commit date 858 date - record the specified date as commit date
842 user - record the specified user as committer 859 user - record the specified user as committer
843 similarity - guess renamed files by similarity (0<=s<=100) 860 similarity - guess renamed files by similarity (0<=s<=100)
861
844 """ 862 """
845 if hasattr(patches, 'read') and hasattr(patches, 'readline'): 863 if hasattr(patches, 'read') and hasattr(patches, 'readline'):
846 patch = patches 864 patch = patches
847 865
848 def readline(size, output): 866 def readline(size, output):
866 self.rawcommand(args, prompt=prompt, input=input) 884 self.rawcommand(args, prompt=prompt, input=input)
867 885
868 def incoming(self, revrange=None, path=None, force=False, newest=False, 886 def incoming(self, revrange=None, path=None, force=False, newest=False,
869 bundle=None, bookmarks=False, branch=None, limit=None, 887 bundle=None, bookmarks=False, branch=None, limit=None,
870 nomerges=False, subrepos=False): 888 nomerges=False, subrepos=False):
871 """ 889 """Return new changesets found in the specified path or the default pull
872 Return new changesets found in the specified path or the default pull
873 location. 890 location.
874 891
875 When bookmarks=True, return a list of (name, node) of incoming bookmarks. 892 When bookmarks=True, return a list of (name, node) of incoming
893 bookmarks.
876 894
877 revrange - a remote changeset or list of changesets intended to be added 895 revrange - a remote changeset or list of changesets intended to be added
878 force - run even if remote repository is unrelated 896 force - run even if remote repository is unrelated
879 newest - show newest record first 897 newest - show newest record first
880 bundle - avoid downloading the changesets twice and store the bundles into 898 bundle - avoid downloading the changesets twice and store the
881 the specified file. 899 bundles into the specified file.
882 900
883 bookmarks - compare bookmarks (this changes the return value) 901 bookmarks - compare bookmarks (this changes the return value)
884 branch - a specific branch you would like to pull 902 branch - a specific branch you would like to pull
885 limit - limit number of changes returned 903 limit - limit number of changes returned
886 nomerges - do not show merges 904 nomerges - do not show merges
887 ssh - specify ssh command to use 905 ssh - specify ssh command to use
888 remotecmd - specify hg command to run on the remote side 906 remotecmd - specify hg command to run on the remote side
889 insecure- do not verify server certificate (ignoring web.cacerts config) 907 insecure- do not verify server certificate (ignoring web.cacerts config)
890 subrepos - recurse into subrepositories 908 subrepos - recurse into subrepositories
891 """ 909
892 args = cmdbuilder('incoming', 910 """
893 path, 911 args = cmdbuilder('incoming', path,
894 template=templates.changeset, r=revrange, 912 template=templates.changeset, r=revrange,
895 f=force, n=newest, bundle=bundle, 913 f=force, n=newest, bundle=bundle,
896 B=bookmarks, b=branch, l=limit, M=nomerges, S=subrepos) 914 B=bookmarks, b=branch, l=limit, M=nomerges,
915 S=subrepos)
897 916
898 def eh(ret, out, err): 917 def eh(ret, out, err):
899 if ret != 1: 918 if ret != 1:
900 raise error.CommandError(args, ret, out, err) 919 raise error.CommandError(args, ret, out, err)
901 920
911 return bms 930 return bms
912 else: 931 else:
913 out = out.split('\0')[:-1] 932 out = out.split('\0')[:-1]
914 return self._parserevs(out) 933 return self._parserevs(out)
915 934
916 def log(self, revrange=None, files=[], follow=False, followfirst=False, 935 def log(self, revrange=None, files=[], follow=False,
917 date=None, copies=False, keyword=None, removed=False, onlymerges=False, 936 followfirst=False, date=None, copies=False, keyword=None,
918 user=None, branch=None, prune=None, hidden=None, limit=None, 937 removed=False, onlymerges=False, user=None, branch=None,
919 nomerges=False, include=None, exclude=None): 938 prune=None, hidden=None, limit=None, nomerges=False,
920 """ 939 include=None, exclude=None):
921 Return the revision history of the specified files or the entire project. 940 """Return the revision history of the specified files or the entire
941 project.
922 942
923 File history is shown without following rename or copy history of files. 943 File history is shown without following rename or copy history of files.
924 Use follow with a filename to follow history across renames and copies. 944 Use follow with a filename to follow history across renames and copies.
925 follow without a filename will only show ancestors or descendants of the 945 follow without a filename will only show ancestors or descendants of the
926 starting revision. followfirst only follows the first parent of merge 946 starting revision. followfirst only follows the first parent of merge
927 revisions. 947 revisions.
928 948
929 If revrange isn't specified, the default is "tip:0" unless follow is set, 949 If revrange isn't specified, the default is "tip:0" unless
930 in which case the working directory parent is used as the starting 950 follow is set, in which case the working directory parent is
931 revision. 951 used as the starting revision.
932 952
933 The returned changeset is a named tuple with the following string fields: 953 The returned changeset is a named tuple with the following
954 string fields:
955
934 - rev 956 - rev
935 - node 957 - node
936 - tags (space delimited) 958 - tags (space delimited)
937 - branch 959 - branch
938 - author 960 - author
939 - desc 961 - desc
940 962
941 follow - follow changeset history, or file history across copies and renames 963 follow - follow changeset history, or file history across
964 copies and renames
942 followfirst - only follow the first parent of merge changesets 965 followfirst - only follow the first parent of merge changesets
943 date - show revisions matching date spec 966 date - show revisions matching date spec
944 copies - show copied files 967 copies - show copied files
945 keyword - do case-insensitive search for a given text 968 keyword - do case-insensitive search for a given text
946 removed - include revisions where files were removed 969 removed - include revisions where files were removed
951 hidden - show hidden changesets 974 hidden - show hidden changesets
952 limit - limit number of changes displayed 975 limit - limit number of changes displayed
953 nomerges - do not show merges 976 nomerges - do not show merges
954 include - include names matching the given patterns 977 include - include names matching the given patterns
955 exclude - exclude names matching the given patterns 978 exclude - exclude names matching the given patterns
979
956 """ 980 """
957 if hidden is None: 981 if hidden is None:
958 hidden = self.hidden 982 hidden = self.hidden
959 args = cmdbuilder('log', template=templates.changeset, 983 args = cmdbuilder('log', template=templates.changeset,
960 r=revrange, f=follow, follow_first=followfirst, 984 r=revrange, f=follow, follow_first=followfirst,
967 out = out.split('\0')[:-1] 991 out = out.split('\0')[:-1]
968 992
969 return self._parserevs(out) 993 return self._parserevs(out)
970 994
971 def manifest(self, rev=None, all=False): 995 def manifest(self, rev=None, all=False):
972 """ 996 """Yields (nodeid, permission, executable, symlink, file path) tuples
973 Yields (nodeid, permission, executable, symlink, file path) tuples for 997 for version controlled files for the given revision. If no
974 version controlled files for the given revision. If no revision is given, 998 revision is given, the first parent of the working directory
975 the first parent of the working directory is used, or the null revision if 999 is used, or the null revision if no revision is checked out.
976 no revision is checked out. 1000
977 1001 When all is True, all files from all revisions are yielded
978 When all is True, all files from all revisions are yielded (just the name). 1002 (just the name). This includes deleted and renamed files.
979 This includes deleted and renamed files. 1003
980 """ 1004 """
981 args = cmdbuilder('manifest', r=rev, all=all, debug=True, 1005 args = cmdbuilder('manifest', r=rev, all=all, debug=True,
982 hidden=self.hidden) 1006 hidden=self.hidden)
983 1007
984 out = self.rawcommand(args) 1008 out = self.rawcommand(args)
993 symlink = line[45] == '@' 1017 symlink = line[45] == '@'
994 executable = line[45] == '*' 1018 executable = line[45] == '*'
995 yield (node, perm, executable, symlink, line[47:]) 1019 yield (node, perm, executable, symlink, line[47:])
996 1020
997 def merge(self, rev=None, force=False, tool=None, cb=merge.handlers.abort): 1021 def merge(self, rev=None, force=False, tool=None, cb=merge.handlers.abort):
998 """ 1022 """Merge working directory with rev. If no revision is specified, the
999 Merge working directory with rev. If no revision is specified, the working 1023 working directory's parent is a head revision, and the current
1000 directory's parent is a head revision, and the current branch contains 1024 branch contains exactly one other head, the other head is
1001 exactly one other head, the other head is merged with by default. 1025 merged with by default.
1002 1026
1003 The current working directory is updated with all changes made in the 1027 The current working directory is updated with all changes made in the
1004 requested revision since the last common predecessor revision. 1028 requested revision since the last common predecessor revision.
1005 1029
1006 Files that changed between either parent are marked as changed for the 1030 Files that changed between either parent are marked as changed for the
1009 1033
1010 force - force a merge with outstanding changes 1034 force - force a merge with outstanding changes
1011 tool - can be used to specify the merge tool used for file merges. It 1035 tool - can be used to specify the merge tool used for file merges. It
1012 overrides the HGMERGE environment variable and your configuration files. 1036 overrides the HGMERGE environment variable and your configuration files.
1013 1037
1014 cb - controls the behaviour when Mercurial prompts what to do with regard 1038 cb - controls the behaviour when Mercurial prompts what to do
1015 to a specific file, e.g. when one parent modified a file and the other 1039 with regard to a specific file, e.g. when one parent modified
1016 removed it. It can be one of merge.handlers, or a function that gets a 1040 a file and the other removed it. It can be one of
1017 single argument which are the contents of stdout. It should return one 1041 merge.handlers, or a function that gets a single argument
1018 of the expected choices (a single character). 1042 which are the contents of stdout. It should return one of the
1043 expected choices (a single character).
1044
1019 """ 1045 """
1020 # we can't really use --preview since merge doesn't support --template 1046 # we can't really use --preview since merge doesn't support --template
1021 args = cmdbuilder('merge', r=rev, f=force, t=tool) 1047 args = cmdbuilder('merge', r=rev, f=force, t=tool)
1022 1048
1023 prompt = None 1049 prompt = None
1030 1056
1031 self.rawcommand(args, prompt=prompt) 1057 self.rawcommand(args, prompt=prompt)
1032 1058
1033 def move(self, source, dest, after=False, force=False, dryrun=False, 1059 def move(self, source, dest, after=False, force=False, dryrun=False,
1034 include=None, exclude=None): 1060 include=None, exclude=None):
1035 """ 1061 """Mark dest as copies of source; mark source for deletion. If dest
1036 Mark dest as copies of source; mark source for deletion. If dest is a 1062 is a directory, copies are put in that directory. If dest is a
1037 directory, copies are put in that directory. If dest is a file, then source 1063 file, then source must be a string.
1038 must be a string.
1039 1064
1040 Returns True on success, False if errors are encountered. 1065 Returns True on success, False if errors are encountered.
1041 1066
1042 source - a file or a list of files 1067 source - a file or a list of files
1043 dest - a destination file or directory 1068 dest - a destination file or directory
1044 after - record a rename that has already occurred 1069 after - record a rename that has already occurred
1045 force - forcibly copy over an existing managed file 1070 force - forcibly copy over an existing managed file
1046 dryrun - do not perform actions, just print output 1071 dryrun - do not perform actions, just print output
1047 include - include names matching the given patterns 1072 include - include names matching the given patterns
1048 exclude - exclude names matching the given patterns 1073 exclude - exclude names matching the given patterns
1074
1049 """ 1075 """
1050 if not isinstance(source, list): 1076 if not isinstance(source, list):
1051 source = [source] 1077 source = [source]
1052 1078
1053 source.append(dest) 1079 source.append(dest)
1060 return bool(eh) 1086 return bool(eh)
1061 1087
1062 def outgoing(self, revrange=None, path=None, force=False, newest=False, 1088 def outgoing(self, revrange=None, path=None, force=False, newest=False,
1063 bookmarks=False, branch=None, limit=None, nomerges=False, 1089 bookmarks=False, branch=None, limit=None, nomerges=False,
1064 subrepos=False): 1090 subrepos=False):
1065 """ 1091 """Return changesets not found in the specified path or the default push
1066 Return changesets not found in the specified path or the default push
1067 location. 1092 location.
1068 1093
1069 When bookmarks=True, return a list of (name, node) of bookmarks that will 1094 When bookmarks=True, return a list of (name, node) of
1070 be pushed. 1095 bookmarks that will be pushed.
1071 1096
1072 revrange - a (list of) changeset intended to be included in the destination 1097 revrange - a (list of) changeset intended to be included in
1073 force - run even when the destination is unrelated 1098 the destination force - run even when the destination is
1074 newest - show newest record first 1099 unrelated newest - show newest record first branch - a
1075 branch - a specific branch you would like to push 1100 specific branch you would like to push limit - limit number of
1076 limit - limit number of changes displayed 1101 changes displayed nomerges - do not show merges ssh - specify
1077 nomerges - do not show merges 1102 ssh command to use remotecmd - specify hg command to run on
1078 ssh - specify ssh command to use 1103 the remote side insecure - do not verify server certificate
1079 remotecmd - specify hg command to run on the remote side 1104 (ignoring web.cacerts config) subrepos - recurse into
1080 insecure - do not verify server certificate (ignoring web.cacerts config) 1105 subrepositories
1081 subrepos - recurse into subrepositories 1106
1082 """ 1107 """
1083 args = cmdbuilder('outgoing', 1108 args = cmdbuilder('outgoing',
1084 path, 1109 path,
1085 template=templates.changeset, r=revrange, 1110 template=templates.changeset, r=revrange,
1086 f=force, n=newest, B=bookmarks, 1111 f=force, n=newest, B=bookmarks,
1103 else: 1128 else:
1104 out = out.split('\0')[:-1] 1129 out = out.split('\0')[:-1]
1105 return self._parserevs(out) 1130 return self._parserevs(out)
1106 1131
1107 def parents(self, rev=None, file=None): 1132 def parents(self, rev=None, file=None):
1108 """ 1133 """Return the working directory's parent revisions. If rev is given,
1109 Return the working directory's parent revisions. If rev is given, the 1134 the parent of that revision will be printed. If file is given,
1110 parent of that revision will be printed. If file is given, the revision 1135 the revision in which the file was last changed (before the
1111 in which the file was last changed (before the working directory revision 1136 working directory revision or the revision specified by rev)
1112 or the revision specified by rev) is returned. 1137 is returned.
1138
1113 """ 1139 """
1114 args = cmdbuilder('parents', file, template=templates.changeset, r=rev, 1140 args = cmdbuilder('parents', file, template=templates.changeset, r=rev,
1115 hidden=self.hidden) 1141 hidden=self.hidden)
1116 1142
1117 out = self.rawcommand(args) 1143 out = self.rawcommand(args)
1140 else: 1166 else:
1141 args = cmdbuilder('paths', name) 1167 args = cmdbuilder('paths', name)
1142 out = self.rawcommand(args) 1168 out = self.rawcommand(args)
1143 return out.rstrip() 1169 return out.rstrip()
1144 1170
1145 def pull(self, source=None, rev=None, update=False, force=False, bookmark=None, 1171 def pull(self, source=None, rev=None, update=False, force=False,
1146 branch=None, ssh=None, remotecmd=None, insecure=False, tool=None): 1172 bookmark=None, branch=None, ssh=None, remotecmd=None,
1147 """ 1173 insecure=False, tool=None):
1148 Pull changes from a remote repository. 1174 """Pull changes from a remote repository.
1149 1175
1150 This finds all changes from the repository specified by source and adds 1176 This finds all changes from the repository specified by source
1151 them to this repository. If source is omitted, the 'default' path will be 1177 and adds them to this repository. If source is omitted, the
1152 used. By default, this does not update the copy of the project in the 1178 'default' path will be used. By default, this does not update
1153 working directory. 1179 the copy of the project in the working directory.
1154 1180
1155 Returns True on success, False if update was given and there were 1181 Returns True on success, False if update was given and there were
1156 unresolved files. 1182 unresolved files.
1157 1183
1158 update - update to new branch head if changesets were pulled 1184 update - update to new branch head if changesets were pulled
1160 rev - a (list of) remote changeset intended to be added 1186 rev - a (list of) remote changeset intended to be added
1161 bookmark - (list of) bookmark to pull 1187 bookmark - (list of) bookmark to pull
1162 branch - a (list of) specific branch you would like to pull 1188 branch - a (list of) specific branch you would like to pull
1163 ssh - specify ssh command to use 1189 ssh - specify ssh command to use
1164 remotecmd - specify hg command to run on the remote side 1190 remotecmd - specify hg command to run on the remote side
1165 insecure - do not verify server certificate (ignoring web.cacerts config) 1191 insecure - do not verify server certificate (ignoring
1192 web.cacerts config)
1166 tool - specify merge tool for rebase 1193 tool - specify merge tool for rebase
1167 """ 1194
1168 args = cmdbuilder('pull', source, r=rev, u=update, f=force, B=bookmark, 1195 """
1169 b=branch, e=ssh, remotecmd=remotecmd, insecure=insecure, 1196 args = cmdbuilder('pull', source, r=rev, u=update, f=force,
1197 B=bookmark, b=branch, e=ssh,
1198 remotecmd=remotecmd, insecure=insecure,
1170 t=tool) 1199 t=tool)
1171 1200
1172 eh = util.reterrorhandler(args) 1201 eh = util.reterrorhandler(args)
1173 self.rawcommand(args, eh=eh) 1202 self.rawcommand(args, eh=eh)
1174 1203
1175 return bool(eh) 1204 return bool(eh)
1176 1205
1177 def push(self, dest=None, rev=None, force=False, bookmark=None, branch=None, 1206 def push(self, dest=None, rev=None, force=False, bookmark=None, branch=None,
1178 newbranch=False, ssh=None, remotecmd=None, insecure=False): 1207 newbranch=False, ssh=None, remotecmd=None, insecure=False):
1179 """ 1208 """Push changesets from this repository to the specified destination.
1180 Push changesets from this repository to the specified destination.
1181 1209
1182 This operation is symmetrical to pull: it is identical to a pull in the 1210 This operation is symmetrical to pull: it is identical to a pull in the
1183 destination repository from the current one. 1211 destination repository from the current one.
1184 1212
1185 Returns True if push was successful, False if nothing to push. 1213 Returns True if push was successful, False if nothing to push.
1186 1214
1187 rev - the (list of) specified revision and all its ancestors will be pushed 1215 rev - the (list of) specified revision and all its ancestors
1188 to the remote repository. 1216 will be pushed to the remote repository.
1189 1217
1190 force - override the default behavior and push all changesets on all 1218 force - override the default behavior and push all changesets on all
1191 branches. 1219 branches.
1192 1220
1193 bookmark - (list of) bookmark to push 1221 bookmark - (list of) bookmark to push
1194 branch - a (list of) specific branch you would like to push 1222 branch - a (list of) specific branch you would like to push
1195 newbranch - allows push to create a new named branch that is not present at 1223 newbranch - allows push to create a new named branch that is
1196 the destination. This allows you to only create a new branch without 1224 not present at the destination. This allows you to only create
1197 forcing other changes. 1225 a new branch without forcing other changes.
1198 1226
1199 ssh - specify ssh command to use 1227 ssh - specify ssh command to use
1200 remotecmd - specify hg command to run on the remote side 1228 remotecmd - specify hg command to run on the remote side
1201 insecure - do not verify server certificate (ignoring web.cacerts config) 1229 insecure - do not verify server certificate (ignoring
1230 web.cacerts config)
1231
1202 """ 1232 """
1203 args = cmdbuilder('push', dest, r=rev, f=force, B=bookmark, b=branch, 1233 args = cmdbuilder('push', dest, r=rev, f=force, B=bookmark, b=branch,
1204 new_branch=newbranch, e=ssh, remotecmd=remotecmd, 1234 new_branch=newbranch, e=ssh, remotecmd=remotecmd,
1205 insecure=insecure) 1235 insecure=insecure)
1206 1236
1207 eh = util.reterrorhandler(args) 1237 eh = util.reterrorhandler(args)
1208 self.rawcommand(args, eh=eh) 1238 self.rawcommand(args, eh=eh)
1209 1239
1210 return bool(eh) 1240 return bool(eh)
1211 1241
1212 def remove(self, files, after=False, force=False, include=None, exclude=None): 1242 def remove(self, files, after=False, force=False, include=None,
1213 """ 1243 exclude=None):
1214 Schedule the indicated files for removal from the repository. This only 1244 """Schedule the indicated files for removal from the repository. This
1215 removes files from the current branch, not from the entire project history. 1245 only removes files from the current branch, not from the
1246 entire project history.
1216 1247
1217 Returns True on success, False if any warnings encountered. 1248 Returns True on success, False if any warnings encountered.
1218 1249
1219 after - used to remove only files that have already been deleted 1250 after - used to remove only files that have already been deleted
1220 force - remove (and delete) file even if added or modified 1251 force - remove (and delete) file even if added or modified
1221 include - include names matching the given patterns 1252 include - include names matching the given patterns
1222 exclude - exclude names matching the given patterns 1253 exclude - exclude names matching the given patterns
1254
1223 """ 1255 """
1224 if not isinstance(files, list): 1256 if not isinstance(files, list):
1225 files = [files] 1257 files = [files]
1226 1258
1227 args = cmdbuilder('remove', A=after, f=force, I=include, X=exclude, 1259 args = cmdbuilder('remove', A=after, f=force, I=include, X=exclude,
1230 eh = util.reterrorhandler(args) 1262 eh = util.reterrorhandler(args)
1231 self.rawcommand(args, eh=eh) 1263 self.rawcommand(args, eh=eh)
1232 1264
1233 return bool(eh) 1265 return bool(eh)
1234 1266
1235 def resolve(self, file=[], all=False, listfiles=False, mark=False, unmark=False, 1267 def resolve(self, file=[], all=False, listfiles=False, mark=False,
1236 tool=None, include=None, exclude=None): 1268 unmark=False, tool=None, include=None, exclude=None):
1237 """ 1269 """
1238 Redo merges or set/view the merge status of given files. 1270 Redo merges or set/view the merge status of given files.
1239 1271
1240 Returns True on success, False if any files fail a resolve attempt. 1272 Returns True on success, False if any files fail a resolve attempt.
1241 1273
1263 l.append(tuple(line.split(' ', 1))) 1295 l.append(tuple(line.split(' ', 1)))
1264 return l 1296 return l
1265 1297
1266 def revert(self, files, rev=None, all=False, date=None, nobackup=False, 1298 def revert(self, files, rev=None, all=False, date=None, nobackup=False,
1267 dryrun=False, include=None, exclude=None): 1299 dryrun=False, include=None, exclude=None):
1268 """ 1300 """With no revision specified, revert the specified files or
1269 With no revision specified, revert the specified files or directories to 1301 directories to the contents they had in the parent of the
1270 the contents they had in the parent of the working directory. This 1302 working directory. This restores the contents of files to an
1271 restores the contents of files to an unmodified state and unschedules 1303 unmodified state and unschedules adds, removes, copies, and
1272 adds, removes, copies, and renames. If the working directory has two 1304 renames. If the working directory has two parents, you must
1273 parents, you must explicitly specify a revision. 1305 explicitly specify a revision.
1274 1306
1275 Specifying rev or date will revert the given files or directories to their 1307 Specifying rev or date will revert the given files or
1276 states as of a specific revision. Because revert does not change the 1308 directories to their states as of a specific revision. Because
1277 working directory parents, this will cause these files to appear modified. 1309 revert does not change the working directory parents, this
1278 This can be helpful to "back out" some or all of an earlier change. 1310 will cause these files to appear modified. This can be helpful
1279 1311 to "back out" some or all of an earlier change.
1280 Modified files are saved with a .orig suffix before reverting. To disable 1312
1281 these backups, use nobackup. 1313 Modified files are saved with a .orig suffix before reverting.
1314 To disable these backups, use nobackup.
1282 1315
1283 Returns True on success. 1316 Returns True on success.
1284 1317
1285 all - revert all changes when no arguments given 1318 all - revert all changes when no arguments given
1286 date - tipmost revision matching date 1319 date - tipmost revision matching date
1287 rev - revert to the specified revision 1320 rev - revert to the specified revision
1288 nobackup - do not save backup copies of files 1321 nobackup - do not save backup copies of files
1289 include - include names matching the given patterns 1322 include - include names matching the given patterns
1290 exclude - exclude names matching the given patterns 1323 exclude - exclude names matching the given patterns
1291 dryrun - do not perform actions, just print output 1324 dryrun - do not perform actions, just print output
1325
1292 """ 1326 """
1293 if not isinstance(files, list): 1327 if not isinstance(files, list):
1294 files = [files] 1328 files = [files]
1295 1329
1296 args = cmdbuilder('revert', r=rev, a=all, d=date, 1330 args = cmdbuilder('revert', r=rev, a=all, d=date,
1306 """ 1340 """
1307 Return the root directory of the current repository. 1341 Return the root directory of the current repository.
1308 """ 1342 """
1309 return self.rawcommand(['root']).rstrip() 1343 return self.rawcommand(['root']).rstrip()
1310 1344
1311 def status(self, rev=None, change=None, all=False, modified=False, added=False, 1345 def status(self, rev=None, change=None, all=False, modified=False,
1312 removed=False, deleted=False, clean=False, unknown=False, 1346 added=False, removed=False, deleted=False, clean=False,
1313 ignored=False, copies=False, subrepos=False, include=None, 1347 unknown=False, ignored=False, copies=False,
1314 exclude=None): 1348 subrepos=False, include=None, exclude=None):
1315 """ 1349 """
1316 Return status of files in the repository as a list of (code, file path) 1350 Return status of files in the repository as a list of (code, file path)
1317 where code can be: 1351 where code can be:
1318 1352
1319 M = modified 1353 M = modified
1362 1396
1363 return l 1397 return l
1364 1398
1365 def tag(self, names, rev=None, message=None, force=False, local=False, 1399 def tag(self, names, rev=None, message=None, force=False, local=False,
1366 remove=False, date=None, user=None): 1400 remove=False, date=None, user=None):
1367 """ 1401 """Add one or more tags specified by names for the current or given
1368 Add one or more tags specified by names for the current or given revision. 1402 revision.
1369 1403
1370 Changing an existing tag is normally disallowed; use force to override. 1404 Changing an existing tag is normally disallowed; use force to override.
1371 1405
1372 Tag commits are usually made at the head of a branch. If the parent of the 1406 Tag commits are usually made at the head of a branch. If the
1373 working directory is not a branch head, a CommandError will be raised. 1407 parent of the working directory is not a branch head, a
1374 force can be specified to force the tag commit to be based on a non-head 1408 CommandError will be raised. force can be specified to force
1375 changeset. 1409 the tag commit to be based on a non-head changeset.
1376 1410
1377 local - make the tag local 1411 local - make the tag local
1378 rev - revision to tag 1412 rev - revision to tag
1379 remove - remove a tag 1413 remove - remove a tag
1380 message - set commit message 1414 message - set commit message
1381 date - record the specified date as commit date 1415 date - record the specified date as commit date
1382 user - record the specified user as committer 1416 user - record the specified user as committer
1417
1383 """ 1418 """
1384 if not isinstance(names, list): 1419 if not isinstance(names, list):
1385 names = [names] 1420 names = [names]
1386 1421
1387 args = cmdbuilder('tag', r=rev, m=message, f=force, l=local, 1422 args = cmdbuilder('tag', r=rev, m=message, f=force, l=local,
1423 The arguments match the mercurial API. 1458 The arguments match the mercurial API.
1424 ''' 1459 '''
1425 if not isinstance(revs, (list, tuple)): 1460 if not isinstance(revs, (list, tuple)):
1426 revs = [revs] 1461 revs = [revs]
1427 args = util.cmdbuilder('phase', secret=secret, draft=draft, 1462 args = util.cmdbuilder('phase', secret=secret, draft=draft,
1428 public=public, force=force, hidden=self.hidden, *revs) 1463 public=public, force=force,
1464 hidden=self.hidden, *revs)
1429 out = self.rawcommand(args) 1465 out = self.rawcommand(args)
1430 if draft or public or secret: 1466 if draft or public or secret:
1431 return 1467 return
1432 else: 1468 else:
1433 output = [i.split(': ')for i in out.strip().split('\n')] 1469 output = [i.split(': ')for i in out.strip().split('\n')]
1555 m = re.search(r'^(\d+).+, (\d+).+, (\d+).+, (\d+)', out, re.MULTILINE) 1591 m = re.search(r'^(\d+).+, (\d+).+, (\d+).+, (\d+)', out, re.MULTILINE)
1556 return tuple(map(int, list(m.groups()))) 1592 return tuple(map(int, list(m.groups())))
1557 1593
1558 @property 1594 @property
1559 def version(self): 1595 def version(self):
1560 """ 1596 """Return hg version that runs the command server as a 4 fielded
1561 Return hg version that runs the command server as a 4 fielded tuple: major, 1597 tuple: major, minor, micro and local build info. e.g. (1, 9,
1562 minor, micro and local build info. e.g. (1, 9, 1, '+4-3095db9f5c2c') 1598 1, '+4-3095db9f5c2c')
1563 """ 1599 """
1564 if self._version is None: 1600 if self._version is None:
1565 v = self.rawcommand(cmdbuilder('version', q=True)) 1601 v = self.rawcommand(cmdbuilder('version', q=True))
1566 v = list(re.match(r'.*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?', 1602 v = list(re.match(r'.*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?',
1567 v).groups()) 1603 v).groups())