comparison hglib/client.py @ 65:91ffa1de398c

document all commands in client.py
author Idan Kamara <idankk86@gmail.com>
date Tue, 23 Aug 2011 21:57:11 +0300
parents a7d98dc798c5
children 15485fa4b35e
comparison
equal deleted inserted replaced
64:a7d98dc798c5 65:91ffa1de398c
135 else: 135 else:
136 return eh(ret, out, err) 136 return eh(ret, out, err)
137 return out 137 return out
138 138
139 def close(self): 139 def close(self):
140 """
141 Closes the command server instance and waits for it to exit, returns the
142 exit code.
143
144 Attempting to call any function afterwards that needs to communicate with
145 the server will raise a ValueError.
146 """
140 self.server.stdin.close() 147 self.server.stdin.close()
141 self.server.wait() 148 self.server.wait()
142 ret = self.server.returncode 149 ret = self.server.returncode
143 self.server = None 150 self.server = None
144 return ret 151 return ret
147 exclude=None): 154 exclude=None):
148 """ 155 """
149 Add the specified files on the next commit. 156 Add the specified files on the next commit.
150 If no files are given, add all files to the repository. 157 If no files are given, add all files to the repository.
151 158
159 dryrun - do no perform actions
160 subrepos - recurse into subrepositories
161 include - include names matching the given patterns
162 exclude - exclude names matching the given patterns
163
152 Return whether all given files were added. 164 Return whether all given files were added.
153 """ 165 """
154 if not isinstance(files, list): 166 if not isinstance(files, list):
155 files = [files] 167 files = [files]
156 168
161 173
162 return bool(eh) 174 return bool(eh)
163 175
164 def addremove(self, files=[], similarity=None, dryrun=False, include=None, 176 def addremove(self, files=[], similarity=None, dryrun=False, include=None,
165 exclude=None): 177 exclude=None):
178 """
179 Add all new files and remove all missing files from the repository.
180
181 New files are ignored if they match any of the patterns in ".hgignore". As
182 with add, these changes take effect at the next commit.
183
184 similarity - used to detect renamed files. With a parameter
185 greater than 0, this compares every removed file with every added file and
186 records those similar enough as renames. This option takes a percentage
187 between 0 (disabled) and 100 (files must be identical) as its parameter.
188 Detecting renamed files this way can be expensive. After using this
189 option, "hg status -C" can be used to check which files were identified as
190 moved or renamed.
191
192 dryrun - do no perform actions
193 include - include names matching the given patterns
194 exclude - exclude names matching the given patterns
195
196 Return True if all files are successfully added.
197 """
166 if not isinstance(files, list): 198 if not isinstance(files, list):
167 files = [files] 199 files = [files]
168 200
169 args = cmdbuilder('addremove', *files, s=similarity, n=dryrun, I=include, 201 args = cmdbuilder('addremove', *files, s=similarity, n=dryrun, I=include,
170 X=exclude) 202 X=exclude)
178 file=False, date=False, number=False, changeset=False, 210 file=False, date=False, number=False, changeset=False,
179 line=False, verbose=False, include=None, exclude=None): 211 line=False, verbose=False, include=None, exclude=None):
180 """ 212 """
181 Show changeset information by line for each file in files. 213 Show changeset information by line for each file in files.
182 214
183 yields a (info, contents) tuple for each line in a file 215 rev - annotate the specified revision
216 nofollow - don't follow copies and renames
217 text - treat all files as text
218 user - list the author (long with -v)
219 file - list the filename
220 date - list the date
221 number - list the revision number (default)
222 changeset - list the changeset
223 line - show line number at the first appearance
224 include - include names matching the given patterns
225 exclude - exclude names matching the given patterns
226
227 Yields a (info, contents) tuple for each line in a file. Info is a space
228 separated string according to the given options.
184 """ 229 """
185 if not isinstance(files, list): 230 if not isinstance(files, list):
186 files = [files] 231 files = [files]
187 232
188 args = cmdbuilder('annotate', *files, r=rev, no_follow=nofollow, a=text, 233 args = cmdbuilder('annotate', *files, r=rev, no_follow=nofollow, a=text,
195 yield tuple(line.split(': ', 1)) 240 yield tuple(line.split(': ', 1))
196 241
197 def archive(self, dest, rev=None, nodecode=False, prefix=None, type=None, 242 def archive(self, dest, rev=None, nodecode=False, prefix=None, type=None,
198 subrepos=False, include=None, exclude=None): 243 subrepos=False, include=None, exclude=None):
199 """ 244 """
200 create an unversioned archive of a repository revision 245 Create an unversioned archive of a repository revision.
246
247 The exact name of the destination archive or directory is given using a
248 format string; see export for details.
249
250 Each member added to an archive file has a directory prefix prepended. Use
251 prefix to specify a format string for the prefix. The default is the
252 basename of the archive, with suffixes removed.
253
254 dest - destination path
255 rev - revision to distribute. The revision used is the parent of the
256 working directory if one isn't given.
257
258 nodecode - do not pass files through decoders
259 prefix - directory prefix for files in archive
260 type - type of distribution to create. The archive type is automatically
261 detected based on file extension if one isn't given.
262
263 Valid types are:
264
265 "files" a directory full of files (default)
266 "tar" tar archive, uncompressed
267 "tbz2" tar archive, compressed using bzip2
268 "tgz" tar archive, compressed using gzip
269 "uzip" zip archive, uncompressed
270 "zip" zip archive, compressed using deflate
271
272 subrepos - recurse into subrepositories
273 include - include names matching the given patterns
274 exclude - exclude names matching the given patterns
201 """ 275 """
202 args = cmdbuilder('archive', dest, r=rev, no_decode=nodecode, p=prefix, 276 args = cmdbuilder('archive', dest, r=rev, no_decode=nodecode, p=prefix,
203 t=type, S=subrepos, I=include, X=exclude) 277 t=type, S=subrepos, I=include, X=exclude)
204 278
205 self.rawcommand(args) 279 self.rawcommand(args)
206 280
207 def backout(self, rev, merge=False, parent=None, tool=None, message=None, 281 def backout(self, rev, merge=False, parent=None, tool=None, message=None,
208 logfile=None, date=None, user=None): 282 logfile=None, date=None, user=None):
283 """
284 Prepare a new changeset with the effect of rev undone in the current
285 working directory.
286
287 If rev is the parent of the working directory, then this new changeset is
288 committed automatically. Otherwise, hg needs to merge the changes and the
289 merged result is left uncommitted.
290
291 rev - revision to backout
292 merge - merge with old dirstate parent after backout
293 parent - parent to choose when backing out merge
294 tool - specify merge tool
295 message - use text as commit message
296 logfile - read commit message from file
297 date - record the specified date as commit date
298 user - record the specified user as committer
299 """
209 if message and logfile: 300 if message and logfile:
210 raise ValueError("cannot specify both a message and a logfile") 301 raise ValueError("cannot specify both a message and a logfile")
211 302
212 args = cmdbuilder('backout', r=rev, merge=merge, parent=parent, t=tool, 303 args = cmdbuilder('backout', r=rev, merge=merge, parent=parent, t=tool,
213 m=message, l=logfile, d=date, u=user) 304 m=message, l=logfile, d=date, u=user)
214 305
215 self.rawcommand(args) 306 self.rawcommand(args)
216 307
217 def bookmark(self, name, rev=None, force=False, delete=False, inactive=False, 308 def bookmark(self, name, rev=None, force=False, delete=False, inactive=False,
218 rename=None): 309 rename=None):
310 """
311 Set a bookmark on the working directory's parent revision or rev,
312 with the given name.
313
314 name - bookmark name
315 rev - revision to bookmark
316 force - bookmark even if another bookmark with the same name exists
317 delete - delete the given bookmark
318 inactive - do not mark the new bookmark active
319 rename - rename the bookmark given by rename to name
320 """
219 args = cmdbuilder('bookmark', name, r=rev, f=force, d=delete, 321 args = cmdbuilder('bookmark', name, r=rev, f=force, d=delete,
220 i=inactive, m=rename) 322 i=inactive, m=rename)
221 323
222 self.rawcommand(args) 324 self.rawcommand(args)
223 325
224 def bookmarks(self): 326 def bookmarks(self):
225 """ 327 """
226 Return the bookmarks as a list of (name, rev, node) and the 328 Return the bookmarks as a list of (name, rev, node) and the index of the
227 index of the current one. 329 current one.
228 330
229 If there isn't a current one, -1 is returned as the index 331 If there isn't a current one, -1 is returned as the index.
230 """ 332 """
231 out = self.rawcommand(['bookmarks']) 333 out = self.rawcommand(['bookmarks'])
232 334
233 bms = [] 335 bms = []
234 current = -1 336 current = -1
241 rev, node = line.split(':') 343 rev, node = line.split(':')
242 bms.append((name, int(rev), node)) 344 bms.append((name, int(rev), node))
243 return bms, current 345 return bms, current
244 346
245 def branch(self, name=None, clean=False, force=False): 347 def branch(self, name=None, clean=False, force=False):
348 """
349 When name isn't given, return the current branch name. Otherwise set the
350 working directory branch name (the branch will not exist in the repository
351 until the next commit). Standard practice recommends that primary
352 development take place on the 'default' branch.
353
354 When clean is True, reset and return the working directory branch to that
355 of the parent of the working directory, negating a previous branch change.
356
357 name - new branch name
358 clean - reset branch name to parent branch name
359 force - set branch name even if it shadows an existing branch
360 """
246 if name and clean: 361 if name and clean:
247 raise ValueError('cannot use both name and clean') 362 raise ValueError('cannot use both name and clean')
248 363
249 args = cmdbuilder('branch', name, f=force, C=clean) 364 args = cmdbuilder('branch', name, f=force, C=clean)
250 out = self.rawcommand(args).rstrip() 365 out = self.rawcommand(args).rstrip()
256 else: 371 else:
257 # len('reset working directory to branch ') == 34 372 # len('reset working directory to branch ') == 34
258 return out[34:] 373 return out[34:]
259 374
260 def branches(self, active=False, closed=False): 375 def branches(self, active=False, closed=False):
376 """
377 Returns the repository's named branches as a list of (name, rev, node).
378
379 active - show only branches that have unmerged heads
380 closed - show normal and closed branches
381 """
261 args = cmdbuilder('branches', a=active, c=closed) 382 args = cmdbuilder('branches', a=active, c=closed)
262 out = self.rawcommand(args) 383 out = self.rawcommand(args)
263 384
264 branches = [] 385 branches = []
265 for line in out.rstrip().splitlines(): 386 for line in out.rstrip().splitlines():
270 return branches 391 return branches
271 392
272 def bundle(self, file, destrepo=None, rev=[], branch=[], base=[], all=False, 393 def bundle(self, file, destrepo=None, rev=[], branch=[], base=[], all=False,
273 force=False, type=None, ssh=None, remotecmd=None, insecure=False): 394 force=False, type=None, ssh=None, remotecmd=None, insecure=False):
274 """ 395 """
275 create a changegroup file 396 Generate a compressed changegroup file collecting changesets not known to
397 be in another repository.
398
399 If destrepo isn't given, then hg assumes the destination will have all
400 the nodes you specify with base. To create a bundle containing all
401 changesets, use all (or set base to 'null').
402
403 file - destination file name
404 destrepo - repository to look for changes
405 rev - a changeset intended to be added to the destination
406 branch - a specific branch you would like to bundle
407 base - a base changeset assumed to be available at the destination
408 all - bundle all changesets in the repository
409 type - bundle compression type to use, available compression methods are:
410 none, bzip2, and gzip (default: bzip2)
411
412 force - run even when the destrepo is unrelated
413 ssh - specify ssh command to use
414 remotecmd - specify hg command to run on the remote side
415 insecure - do not verify server certificate (ignoring web.cacerts config)
276 416
277 Return True if a bundle was created, False if no changes were found. 417 Return True if a bundle was created, False if no changes were found.
278 """ 418 """
279 args = cmdbuilder('bundle', file, destrepo, f=force, r=rev, b=branch, 419 args = cmdbuilder('bundle', file, destrepo, f=force, r=rev, b=branch,
280 base=base, a=all, t=type, e=ssh, remotecmd=remotecmd, 420 base=base, a=all, t=type, e=ssh, remotecmd=remotecmd,
284 self.rawcommand(args, eh=eh) 424 self.rawcommand(args, eh=eh)
285 425
286 return bool(eh) 426 return bool(eh)
287 427
288 def cat(self, files, rev=None, output=None): 428 def cat(self, files, rev=None, output=None):
429 """
430 Return a string containing the specified files as they were at the
431 given revision. If no revision is given, the parent of the working
432 directory is used, or tip if no revision is checked out.
433
434 If output is given, writes the contents to the specified file.
435 The name of the file is given using a format string. The formatting rules
436 are the same as for the export command, with the following additions:
437
438 "%s" basename of file being printed
439 "%d" dirname of file being printed, or '.' if in repository root
440 "%p" root-relative path name of file being printed
441 """
289 args = cmdbuilder('cat', *files, r=rev, o=output) 442 args = cmdbuilder('cat', *files, r=rev, o=output)
290 out = self.rawcommand(args) 443 out = self.rawcommand(args)
291 444
292 if not output: 445 if not output:
293 return out 446 return out
294 447
295 def clone(self, source='.', dest=None, branch=None, updaterev=None, 448 def clone(self, source='.', dest=None, branch=None, updaterev=None,
296 revrange=None): 449 revrange=None):
450 """
451 Create a copy of an existing repository specified by source in a new
452 directory dest.
453
454 If dest isn't specified, it defaults to the basename of source.
455
456 branch - clone only the specified branch
457 updaterev - revision, tag or branch to check out
458 revrange - include the specified changeset
459 """
297 args = cmdbuilder('clone', source, dest, b=branch, u=updaterev, r=revrange) 460 args = cmdbuilder('clone', source, dest, b=branch, u=updaterev, r=revrange)
298 self.rawcommand(args) 461 self.rawcommand(args)
299 462
300 def commit(self, message=None, logfile=None, addremove=False, closebranch=False, 463 def commit(self, message=None, logfile=None, addremove=False, closebranch=False,
301 date=None, user=None, include=None, exclude=None): 464 date=None, user=None, include=None, exclude=None):
465 """
466 Commit changes reported by status into the repository.
467
468 message - the commit message
469 logfile - read commit message from file
470 addremove - mark new/missing files as added/removed before committing
471 closebranch - mark a branch as closed, hiding it from the branch list
472 date - record the specified date as commit date
473 user - record the specified user as committer
474 include - include names matching the given patterns
475 exclude - exclude names matching the given patterns
476 """
302 if message is None and logfile is None: 477 if message is None and logfile is None:
303 raise ValueError("must provide at least a message or a logfile") 478 raise ValueError("must provide at least a message or a logfile")
304 elif message and logfile: 479 elif message and logfile:
305 raise ValueError("cannot specify both a message and a logfile") 480 raise ValueError("cannot specify both a message and a logfile")
306 481
344 519
345 return conf 520 return conf
346 521
347 @property 522 @property
348 def encoding(self): 523 def encoding(self):
349 """ get the servers encoding """ 524 """
525 Return the server's encoding (as reported in the hello message).
526 """
350 if not 'getencoding' in self.capabilities: 527 if not 'getencoding' in self.capabilities:
351 raise CapabilityError('getencoding') 528 raise CapabilityError('getencoding')
352 529
353 if not self._encoding: 530 if not self._encoding:
354 self.server.stdin.write('getencoding\n') 531 self.server.stdin.write('getencoding\n')
356 533
357 return self._encoding 534 return self._encoding
358 535
359 def copy(self, source, dest, after=False, force=False, dryrun=False, 536 def copy(self, source, dest, after=False, force=False, dryrun=False,
360 include=None, exclude=None): 537 include=None, exclude=None):
538 """
539 Mark dest as having copies of source files. If dest is a directory, copies
540 are put in that directory. If dest is a file, then source must be a string.
541
542 Returns True on success, False if errors are encountered.
543
544 source - a file or a list of files
545 dest - a destination file or directory
546 after - record a copy that has already occurred
547 force - forcibly copy over an existing managed file
548 dryrun - do not perform actions, just print output
549 include - include names matching the given patterns
550 exclude - exclude names matching the given patterns
551 """
361 if not isinstance(source, list): 552 if not isinstance(source, list):
362 source = [source] 553 source = [source]
363 554
364 source.append(dest) 555 source.append(dest)
365 args = cmdbuilder('copy', *source, A=after, f=force, n=dryrun, 556 args = cmdbuilder('copy', *source, A=after, f=force, n=dryrun,
372 563
373 def diff(self, files=[], revs=[], change=None, text=False, 564 def diff(self, files=[], revs=[], change=None, text=False,
374 git=False, nodates=False, showfunction=False, reverse=False, 565 git=False, nodates=False, showfunction=False, reverse=False,
375 ignoreallspace=False, ignorespacechange=False, ignoreblanklines=False, 566 ignoreallspace=False, ignorespacechange=False, ignoreblanklines=False,
376 unified=None, stat=False, subrepos=False, include=None, exclude=None): 567 unified=None, stat=False, subrepos=False, include=None, exclude=None):
568 """
569 Return differences between revisions for the specified files.
570
571 revs - a revision or a list of two revisions to diff
572 change - change made by revision
573 text - treat all files as text
574 git - use git extended diff format
575 nodates - omit dates from diff headers
576 showfunction - show which function each change is in
577 reverse - produce a diff that undoes the changes
578 ignoreallspace - ignore white space when comparing lines
579 ignorespacechange - ignore changes in the amount of white space
580 ignoreblanklines - ignore changes whose lines are all blank
581 unified - number of lines of context to show
582 stat - output diffstat-style summary of changes
583 subrepos - recurse into subrepositories
584 include - include names matching the given patterns
585 exclude - exclude names matching the given patterns
586 """
377 if change and revs: 587 if change and revs:
378 raise ValueError('cannot specify both change and rev') 588 raise ValueError('cannot specify both change and rev')
379 589
380 args = cmdbuilder('diff', *files, r=revs, c=change, 590 args = cmdbuilder('diff', *files, r=revs, c=change,
381 a=text, g=git, nodates=nodates, 591 a=text, g=git, nodates=nodates,
388 598
389 def export(self, revs, output=None, switchparent=False, text=False, git=False, 599 def export(self, revs, output=None, switchparent=False, text=False, git=False,
390 nodates=False): 600 nodates=False):
391 """ 601 """
392 Return the header and diffs for one or more changesets. When output is 602 Return the header and diffs for one or more changesets. When output is
393 given, dumps to file. 603 given, dumps to file. The name of the file is given using a format string.
604 The formatting rules are as follows:
605
606 "%%" literal "%" character
607 "%H" changeset hash (40 hexadecimal digits)
608 "%N" number of patches being generated
609 "%R" changeset revision number
610 "%b" basename of the exporting repository
611 "%h" short-form changeset hash (12 hexadecimal digits)
612 "%n" zero-padded sequence number, starting at 1
613 "%r" zero-padded changeset revision number
614
615 output - print output to file with formatted name
616 switchparent - diff against the second parent
617 rev - a revision or list of revisions to export
618 text - treat all files as text
619 git - use git extended diff format
620 nodates - omit dates from diff headers
394 """ 621 """
395 if not isinstance(revs, list): 622 if not isinstance(revs, list):
396 revs = [revs] 623 revs = [revs]
397 args = cmdbuilder('export', *revs, o=output, switch_parent=switchparent, 624 args = cmdbuilder('export', *revs, o=output, switch_parent=switchparent,
398 a=text, g=git, nodates=nodates) 625 a=text, g=git, nodates=nodates)
401 628
402 if output is None: 629 if output is None:
403 return out 630 return out
404 631
405 def forget(self, files, include=None, exclude=None): 632 def forget(self, files, include=None, exclude=None):
633 """
634 Mark the specified files so they will no longer be tracked after the next
635 commit.
636
637 This only removes files from the current branch, not from the entire
638 project history, and it does not delete them from the working directory.
639
640 Returns True on success.
641
642 include - include names matching the given patterns
643 exclude - exclude names matching the given patterns
644 """
406 if not isinstance(files, list): 645 if not isinstance(files, list):
407 files = [files] 646 files = [files]
408 647
409 args = cmdbuilder('forget', *files, I=include, X=exclude) 648 args = cmdbuilder('forget', *files, I=include, X=exclude)
410 649
415 654
416 def grep(self, pattern, files=[], all=False, text=False, follow=False, 655 def grep(self, pattern, files=[], all=False, text=False, follow=False,
417 ignorecase=False, fileswithmatches=False, line=False, user=False, 656 ignorecase=False, fileswithmatches=False, line=False, user=False,
418 date=False, include=None, exclude=None): 657 date=False, include=None, exclude=None):
419 """ 658 """
420 search for a pattern in specified files and revisions 659 Search for a pattern in specified files and revisions.
421 660
422 yields (filename, revision, [line, [match status, [user, [date, [match]]]]]) 661 This behaves differently than Unix grep. It only accepts Python/Perl
662 regexps. It searches repository history, not the working directory.
663 It always prints the revision number in which a match appears.
664
665 Yields (filename, revision, [line, [match status, [user, [date, [match]]]]])
423 per match depending on the given options. 666 per match depending on the given options.
667
668 all - print all revisions that match
669 text - treat all files as text
670 follow - follow changeset history, or file history across copies and renames
671 ignorecase - ignore case when matching
672 fileswithmatches - return only filenames and revisions that match
673 line - return line numbers in the result tuple
674 user - return the author in the result tuple
675 date - return the date in the result tuple
676 include - include names matching the given patterns
677 exclude - exclude names matching the given patterns
424 """ 678 """
425 if not isinstance(files, list): 679 if not isinstance(files, list):
426 files = [files] 680 files = [files]
427 681
428 args = cmdbuilder('grep', *[pattern] + files, all=all, a=text, f=follow, 682 args = cmdbuilder('grep', *[pattern] + files, all=all, a=text, f=follow,
451 705
452 return util.grouper(fieldcount, out) 706 return util.grouper(fieldcount, out)
453 707
454 def heads(self, rev=[], startrev=[], topological=False, closed=False): 708 def heads(self, rev=[], startrev=[], topological=False, closed=False):
455 """ 709 """
456 Return a list of current repository heads or branch heads 710 Return a list of current repository heads or branch heads.
711
712 rev - return only branch heads on the branches associated with the specified
713 changesets.
714
715 startrev - return only heads which are descendants of the given revs.
716 topological - named branch mechanics will be ignored and only changesets
717 without children will be shown.
718
719 closed - normal and closed branch heads.
457 """ 720 """
458 if not isinstance(rev, list): 721 if not isinstance(rev, list):
459 rev = [rev] 722 rev = [rev]
460 723
461 args = cmdbuilder('heads', *rev, r=startrev, t=topological, c=closed, 724 args = cmdbuilder('heads', *rev, r=startrev, t=topological, c=closed,
469 out = self.rawcommand(args, eh=eh).split('\0')[:-1] 732 out = self.rawcommand(args, eh=eh).split('\0')[:-1]
470 return self._parserevs(out) 733 return self._parserevs(out)
471 734
472 def identify(self, rev=None, source=None, num=False, id=False, branch=False, 735 def identify(self, rev=None, source=None, num=False, id=False, branch=False,
473 tags=False, bookmarks=False): 736 tags=False, bookmarks=False):
737 """
738 Return a summary string identifying the repository state at rev using one or
739 two parent hash identifiers, followed by a "+" if the working directory has
740 uncommitted changes, the branch name (if not default), a list of tags, and
741 a list of bookmarks.
742
743 When rev is not given, return a summary string of the current state of the
744 repository.
745
746 Specifying source as a repository root or Mercurial bundle will cause
747 lookup to operate on that repository/bundle.
748
749 num - show local revision number
750 id - show global revision id
751 branch - show branch
752 tags - show tags
753 bookmarks - show bookmarks
754 """
474 args = cmdbuilder('identify', source, r=rev, n=num, i=id, b=branch, t=tags, 755 args = cmdbuilder('identify', source, r=rev, n=num, i=id, b=branch, t=tags,
475 B=bookmarks) 756 B=bookmarks)
476 757
477 return self.rawcommand(args) 758 return self.rawcommand(args)
478 759
479 def import_(self, patches, strip=None, force=False, nocommit=False, 760 def import_(self, patches, strip=None, force=False, nocommit=False,
480 bypass=False, exact=False, importbranch=False, message=None, 761 bypass=False, exact=False, importbranch=False, message=None,
481 date=None, user=None, similarity=None): 762 date=None, user=None, similarity=None):
482 """ 763 """
483 patches can be a list of file names with patches to apply 764 Import the specified patches which can be a list of file names or a
484 or a file-like object that contains a patch (needs read and readline) 765 file-like object and commit them individually (unless nocommit is
766 specified).
767
768 strip - directory strip option for patch. This has the same meaning as the
769 corresponding patch option (default: 1)
770
771 force - skip check for outstanding uncommitted changes
772 nocommit - don't commit, just update the working directory
773 bypass - apply patch without touching the working directory
774 exact - apply patch to the nodes from which it was generated
775 importbranch - use any branch information in patch (implied by exact)
776 message - the commit message
777 date - record the specified date as commit date
778 user - record the specified user as committer
779 similarity - guess renamed files by similarity (0<=s<=100)
485 """ 780 """
486 if hasattr(patches, 'read') and hasattr(patches, 'readline'): 781 if hasattr(patches, 'read') and hasattr(patches, 'readline'):
487 patch = patches 782 patch = patches
488 783
489 def readline(size, output): 784 def readline(size, output):
511 """ 806 """
512 Return new changesets found in the specified path or the default pull 807 Return new changesets found in the specified path or the default pull
513 location. 808 location.
514 809
515 When bookmarks=True, return a list of (name, node) of incoming bookmarks. 810 When bookmarks=True, return a list of (name, node) of incoming bookmarks.
811
812 revrange - a remote changeset or list of changesets intended to be added
813 force - run even if remote repository is unrelated
814 newest - show newest record first
815 bundle - avoid downloading the changesets twice and store the bundles into
816 the specified file.
817
818 bookmarks - compare bookmarks (this changes the return value)
819 branch - a specific branch you would like to pull
820 limit - limit number of changes returned
821 nomerges - do not show merges
822 ssh - specify ssh command to use
823 remotecmd - specify hg command to run on the remote side
824 insecure- do not verify server certificate (ignoring web.cacerts config)
825 subrepos - recurse into subrepositories
516 """ 826 """
517 args = cmdbuilder('incoming', 827 args = cmdbuilder('incoming',
518 path, 828 path,
519 template=templates.changeset, r=revrange, 829 template=templates.changeset, r=revrange,
520 f=force, n=newest, bundle=bundle, 830 f=force, n=newest, bundle=bundle,
540 850
541 def log(self, revrange=None, files=[], follow=False, followfirst=False, 851 def log(self, revrange=None, files=[], follow=False, followfirst=False,
542 date=None, copies=False, keyword=None, removed=False, onlymerges=False, 852 date=None, copies=False, keyword=None, removed=False, onlymerges=False,
543 user=None, branch=None, prune=None, hidden=False, limit=None, 853 user=None, branch=None, prune=None, hidden=False, limit=None,
544 nomerges=False, include=None, exclude=None): 854 nomerges=False, include=None, exclude=None):
855 """
856 Return the revision history of the specified files or the entire project.
857
858 File history is shown without following rename or copy history of files.
859 Use follow with a filename to follow history across renames and copies.
860 follow without a filename will only show ancestors or descendants of the
861 starting revision. followfirst only follows the first parent of merge
862 revisions.
863
864 If revrange isn't specified, the default is "tip:0" unless follow is set,
865 in which case the working directory parent is used as the starting
866 revision.
867
868 The returned changeset is a named tuple with the following string fields:
869 - rev
870 - node
871 - tags (space delimited)
872 - branch
873 - author
874 - desc
875
876 follow - follow changeset history, or file history across copies and renames
877 followfirst - only follow the first parent of merge changesets
878 date - show revisions matching date spec
879 copies - show copied files
880 keyword - do case-insensitive search for a given text
881 removed - include revisions where files were removed
882 onlymerges - show only merges
883 user - revisions committed by user
884 branch - show changesets within the given named branch
885 prune - do not display revision or any of its ancestors
886 hidden - show hidden changesets
887 limit - limit number of changes displayed
888 nomerges - do not show merges
889 include - include names matching the given patterns
890 exclude - exclude names matching the given patterns
891 """
545 args = cmdbuilder('log', *files, template=templates.changeset, 892 args = cmdbuilder('log', *files, template=templates.changeset,
546 r=revrange, f=follow, follow_first=followfirst, 893 r=revrange, f=follow, follow_first=followfirst,
547 d=date, C=copies, k=keyword, removed=removed, 894 d=date, C=copies, k=keyword, removed=removed,
548 m=onlymerges, u=user, b=branch, P=prune, h=hidden, 895 m=onlymerges, u=user, b=branch, P=prune, h=hidden,
549 l=limit, M=nomerges, I=include, X=exclude) 896 l=limit, M=nomerges, I=include, X=exclude)
578 executable = line[45] == '*' 925 executable = line[45] == '*'
579 yield (node, perm, executable, symlink, line[47:]) 926 yield (node, perm, executable, symlink, line[47:])
580 927
581 def merge(self, rev=None, force=False, tool=None, cb=merge.handlers.abort): 928 def merge(self, rev=None, force=False, tool=None, cb=merge.handlers.abort):
582 """ 929 """
583 merge working directory with another revision 930 Merge working directory with rev. If no revision is specified, the working
584 931 directory's parent is a head revision, and the current branch contains
585 cb can one of merge.handlers, or a function that gets a single argument 932 exactly one other head, the other head is merged with by default.
586 which are the contents of stdout. It should return one of the expected 933
587 choices (a single character). 934 The current working directory is updated with all changes made in the
935 requested revision since the last common predecessor revision.
936
937 Files that changed between either parent are marked as changed for the
938 next commit and a commit must be performed before any further updates to
939 the repository are allowed. The next commit will have two parents.
940
941 force - force a merge with outstanding changes
942 tool - can be used to specify the merge tool used for file merges. It
943 overrides the HGMERGE environment variable and your configuration files.
944
945 cb - controls the behaviour when Mercurial prompts what to do with regard
946 to a specific file, e.g. when one parent modified a file and the other
947 removed it. It can be one of merge.handlers, or a function that gets a
948 single argument which are the contents of stdout. It should return one
949 of the expected choices (a single character).
588 """ 950 """
589 # we can't really use --preview since merge doesn't support --template 951 # we can't really use --preview since merge doesn't support --template
590 args = cmdbuilder('merge', r=rev, f=force, t=tool) 952 args = cmdbuilder('merge', r=rev, f=force, t=tool)
591 953
592 prompt = None 954 prompt = None
599 961
600 self.rawcommand(args, prompt=prompt) 962 self.rawcommand(args, prompt=prompt)
601 963
602 def move(self, source, dest, after=False, force=False, dryrun=False, 964 def move(self, source, dest, after=False, force=False, dryrun=False,
603 include=None, exclude=None): 965 include=None, exclude=None):
966 """
967 Mark dest as copies of source; mark source for deletion. If dest is a
968 directory, copies are put in that directory. If dest is a file, then source
969 must be a string.
970
971 Returns True on success, False if errors are encountered.
972
973 source - a file or a list of files
974 dest - a destination file or directory
975 after - record a rename that has already occurred
976 force - forcibly copy over an existing managed file
977 dryrun - do not perform actions, just print output
978 include - include names matching the given patterns
979 exclude - exclude names matching the given patterns
980 """
604 if not isinstance(source, list): 981 if not isinstance(source, list):
605 source = [source] 982 source = [source]
606 983
607 source.append(dest) 984 source.append(dest)
608 args = cmdbuilder('move', *source, A=after, f=force, n=dryrun, 985 args = cmdbuilder('move', *source, A=after, f=force, n=dryrun,
620 Return changesets not found in the specified path or the default push 997 Return changesets not found in the specified path or the default push
621 location. 998 location.
622 999
623 When bookmarks=True, return a list of (name, node) of bookmarks that will 1000 When bookmarks=True, return a list of (name, node) of bookmarks that will
624 be pushed. 1001 be pushed.
1002
1003 revrange - a (list of) changeset intended to be included in the destination
1004 force - run even when the destination is unrelated
1005 newest - show newest record first
1006 branch - a specific branch you would like to push
1007 limit - limit number of changes displayed
1008 nomerges - do not show merges
1009 ssh - specify ssh command to use
1010 remotecmd - specify hg command to run on the remote side
1011 insecure - do not verify server certificate (ignoring web.cacerts config)
1012 subrepos - recurse into subrepositories
625 """ 1013 """
626 args = cmdbuilder('outgoing', 1014 args = cmdbuilder('outgoing',
627 path, 1015 path,
628 template=templates.changeset, r=revrange, 1016 template=templates.changeset, r=revrange,
629 f=force, n=newest, B=bookmarks, 1017 f=force, n=newest, B=bookmarks,
646 else: 1034 else:
647 out = out.split('\0')[:-1] 1035 out = out.split('\0')[:-1]
648 return self._parserevs(out) 1036 return self._parserevs(out)
649 1037
650 def parents(self, rev=None, file=None): 1038 def parents(self, rev=None, file=None):
1039 """
1040 Return the working directory's parent revisions. If rev is given, the
1041 parent of that revision will be printed. If file is given, the revision
1042 in which the file was last changed (before the working directory revision
1043 or the revision specified by rev) is returned.
1044 """
651 args = cmdbuilder('parents', file, template=templates.changeset, r=rev) 1045 args = cmdbuilder('parents', file, template=templates.changeset, r=rev)
652 1046
653 out = self.rawcommand(args) 1047 out = self.rawcommand(args)
654 if not out: 1048 if not out:
655 return 1049 return
657 out = out.split('\0')[:-1] 1051 out = out.split('\0')[:-1]
658 1052
659 return self._parserevs(out) 1053 return self._parserevs(out)
660 1054
661 def paths(self, name=None): 1055 def paths(self, name=None):
1056 """
1057 Return the definition of given symbolic path name. If no name is given,
1058 return a dictionary of pathname : url of all available names.
1059
1060 Path names are defined in the [paths] section of your configuration file
1061 and in "/etc/mercurial/hgrc". If run inside a repository, ".hg/hgrc" is
1062 used, too.
1063 """
662 if not name: 1064 if not name:
663 out = self.rawcommand(['paths']) 1065 out = self.rawcommand(['paths'])
664 if not out: 1066 if not out:
665 return {} 1067 return {}
666 1068
670 out = self.rawcommand(args) 1072 out = self.rawcommand(args)
671 return out.rstrip() 1073 return out.rstrip()
672 1074
673 def pull(self, source=None, rev=None, update=False, force=False, bookmark=None, 1075 def pull(self, source=None, rev=None, update=False, force=False, bookmark=None,
674 branch=None, ssh=None, remotecmd=None, insecure=False, tool=None): 1076 branch=None, ssh=None, remotecmd=None, insecure=False, tool=None):
1077 """
1078 Pull changes from a remote repository.
1079
1080 This finds all changes from the repository specified by source and adds
1081 them to this repository. If source is omitted, the 'default' path will be
1082 used. By default, this does not update the copy of the project in the
1083 working directory.
1084
1085 Returns True on success, False if update was given and there were
1086 unresolved files.
1087
1088 update - update to new branch head if changesets were pulled
1089 force - run even when remote repository is unrelated
1090 rev - a (list of) remote changeset intended to be added
1091 bookmark - (list of) bookmark to pull
1092 branch - a (list of) specific branch you would like to pull
1093 ssh - specify ssh command to use
1094 remotecmd - specify hg command to run on the remote side
1095 insecure - do not verify server certificate (ignoring web.cacerts config)
1096 tool - specify merge tool for rebase
1097 """
675 args = cmdbuilder('pull', source, r=rev, u=update, f=force, B=bookmark, 1098 args = cmdbuilder('pull', source, r=rev, u=update, f=force, B=bookmark,
676 b=branch, e=ssh, remotecmd=remotecmd, insecure=insecure, 1099 b=branch, e=ssh, remotecmd=remotecmd, insecure=insecure,
677 t=tool) 1100 t=tool)
678 1101
679 eh = util.reterrorhandler(args) 1102 eh = util.reterrorhandler(args)
681 1104
682 return bool(eh) 1105 return bool(eh)
683 1106
684 def push(self, dest=None, rev=None, force=False, bookmark=None, branch=None, 1107 def push(self, dest=None, rev=None, force=False, bookmark=None, branch=None,
685 newbranch=False, ssh=None, remotecmd=None, insecure=False): 1108 newbranch=False, ssh=None, remotecmd=None, insecure=False):
1109 """
1110 Push changesets from this repository to the specified destination.
1111
1112 This operation is symmetrical to pull: it is identical to a pull in the
1113 destination repository from the current one.
1114
1115 Returns True if push was successful, False if nothing to push.
1116
1117 rev - the (list of) specified revision and all its ancestors will be pushed
1118 to the remote repository.
1119
1120 force - override the default behavior and push all changesets on all
1121 branches.
1122
1123 bookmark - (list of) bookmark to push
1124 branch - a (list of) specific branch you would like to push
1125 newbranch - allows push to create a new named branch that is not present at
1126 the destination. This allows you to only create a new branch without
1127 forcing other changes.
1128
1129 ssh - specify ssh command to use
1130 remotecmd - specify hg command to run on the remote side
1131 insecure - do not verify server certificate (ignoring web.cacerts config)
1132 """
686 args = cmdbuilder('push', dest, r=rev, f=force, B=bookmark, b=branch, 1133 args = cmdbuilder('push', dest, r=rev, f=force, B=bookmark, b=branch,
687 new_branch=newbranch, e=ssh, remotecmd=remotecmd, 1134 new_branch=newbranch, e=ssh, remotecmd=remotecmd,
688 insecure=insecure) 1135 insecure=insecure)
689 1136
690 eh = util.reterrorhandler(args) 1137 eh = util.reterrorhandler(args)
691 self.rawcommand(args, eh=eh) 1138 self.rawcommand(args, eh=eh)
692 1139
693 return bool(eh) 1140 return bool(eh)
694 1141
695 def remove(self, files, after=False, force=False, include=None, exclude=None): 1142 def remove(self, files, after=False, force=False, include=None, exclude=None):
1143 """
1144 Schedule the indicated files for removal from the repository. This only
1145 removes files from the current branch, not from the entire project history.
1146
1147 Returns True on success, False if any warnings encountered.
1148
1149 after - used to remove only files that have already been deleted
1150 force - remove (and delete) file even if added or modified
1151 include - include names matching the given patterns
1152 exclude - exclude names matching the given patterns
1153 """
696 if not isinstance(files, list): 1154 if not isinstance(files, list):
697 files = [files] 1155 files = [files]
698 1156
699 args = cmdbuilder('remove', *files, A=after, f=force, I=include, X=exclude) 1157 args = cmdbuilder('remove', *files, A=after, f=force, I=include, X=exclude)
700 1158
704 return bool(eh) 1162 return bool(eh)
705 1163
706 def resolve(self, file=[], all=False, listfiles=False, mark=False, unmark=False, 1164 def resolve(self, file=[], all=False, listfiles=False, mark=False, unmark=False,
707 tool=None, include=None, exclude=None): 1165 tool=None, include=None, exclude=None):
708 """ 1166 """
709 redo merges or set/view the merge status of files 1167 Redo merges or set/view the merge status of given files.
1168
1169 Returns True on success, False if any files fail a resolve attempt.
710 1170
711 When listfiles is True, returns a list of (code, file path) of resolved 1171 When listfiles is True, returns a list of (code, file path) of resolved
712 and unresolved files. Code will be 'R' or 'U' accordingly. 1172 and unresolved files. Code will be 'R' or 'U' accordingly.
1173
1174 all - select all unresolved files
1175 mark - mark files as resolved
1176 unmark - mark files as unresolved
1177 tool - specify merge tool
1178 include - include names matching the given patterns
1179 exclude - exclude names matching the given patterns
713 """ 1180 """
714 if not isinstance(file, list): 1181 if not isinstance(file, list):
715 file = [file] 1182 file = [file]
716 1183
717 args = cmdbuilder('resolve', *file, a=all, l=listfiles, m=mark, u=unmark, 1184 args = cmdbuilder('resolve', *file, a=all, l=listfiles, m=mark, u=unmark,
725 l.append(tuple(line.split(' ', 1))) 1192 l.append(tuple(line.split(' ', 1)))
726 return l 1193 return l
727 1194
728 def revert(self, files, rev=None, all=False, date=None, nobackup=False, 1195 def revert(self, files, rev=None, all=False, date=None, nobackup=False,
729 dryrun=False, include=None, exclude=None): 1196 dryrun=False, include=None, exclude=None):
1197 """
1198 With no revision specified, revert the specified files or directories to
1199 the contents they had in the parent of the working directory. This
1200 restores the contents of files to an unmodified state and unschedules
1201 adds, removes, copies, and renames. If the working directory has two
1202 parents, you must explicitly specify a revision.
1203
1204 Specifying rev or date will revert the given files or directories to their
1205 states as of a specific revision. Because revert does not change the
1206 working directory parents, this will cause these files to appear modified.
1207 This can be helpful to "back out" some or all of an earlier change.
1208
1209 Modified files are saved with a .orig suffix before reverting. To disable
1210 these backups, use nobackup.
1211
1212 Returns True on success.
1213
1214 all - revert all changes when no arguments given
1215 date - tipmost revision matching date
1216 rev - revert to the specified revision
1217 nobackup - do not save backup copies of files
1218 include - include names matching the given patterns
1219 exclude - exclude names matching the given patterns
1220 dryrun - do not perform actions, just print output
1221 """
730 if not isinstance(files, list): 1222 if not isinstance(files, list):
731 files = [files] 1223 files = [files]
732 1224
733 args = cmdbuilder('revert', *files, r=rev, a=all, d=date, 1225 args = cmdbuilder('revert', *files, r=rev, a=all, d=date,
734 no_backup=nobackup, n=dryrun, I=include, X=exclude) 1226 no_backup=nobackup, n=dryrun, I=include, X=exclude)
737 self.rawcommand(args, eh=eh) 1229 self.rawcommand(args, eh=eh)
738 1230
739 return bool(eh) 1231 return bool(eh)
740 1232
741 def root(self): 1233 def root(self):
1234 """
1235 Return the root directory of the current repository.
1236 """
742 return self.rawcommand(['root']).rstrip() 1237 return self.rawcommand(['root']).rstrip()
743 1238
744 def status(self, rev=None, change=None, all=False, modified=False, added=False, 1239 def status(self, rev=None, change=None, all=False, modified=False, added=False,
745 removed=False, deleted=False, clean=False, unknown=False, 1240 removed=False, deleted=False, clean=False, unknown=False,
746 ignored=False, copies=False, subrepos=False, include=None, 1241 ignored=False, copies=False, subrepos=False, include=None,
747 exclude=None): 1242 exclude=None):
748 """ 1243 """
749 Return a list of (code, file path) where code can be: 1244 Return status of files in the repository as a list of (code, file path)
1245 where code can be:
750 1246
751 M = modified 1247 M = modified
752 A = added 1248 A = added
753 R = removed 1249 R = removed
754 C = clean 1250 C = clean
755 ! = missing (deleted by non-hg command, but still tracked) 1251 ! = missing (deleted by non-hg command, but still tracked)
756 ? = untracked 1252 ? = untracked
757 I = ignored 1253 I = ignored
758 = origin of the previous file listed as A (added) 1254 = origin of the previous file listed as A (added)
1255
1256 rev - show difference from (list of) revision
1257 change - list the changed files of a revision
1258 all - show status of all files
1259 modified - show only modified files
1260 added - show only added files
1261 removed - show only removed files
1262 deleted - show only deleted (but tracked) files
1263 clean - show only files without changes
1264 unknown - show only unknown (not tracked) files
1265 ignored - show only ignored files
1266 copies - show source of copied files
1267 subrepos - recurse into subrepositories
1268 include - include names matching the given patterns
1269 exclude - exclude names matching the given patterns
759 """ 1270 """
760 if rev and change: 1271 if rev and change:
761 raise ValueError('cannot specify both rev and change') 1272 raise ValueError('cannot specify both rev and change')
762 1273
763 args = cmdbuilder('status', rev=rev, change=change, A=all, m=modified, 1274 args = cmdbuilder('status', rev=rev, change=change, A=all, m=modified,
778 1289
779 return l 1290 return l
780 1291
781 def tag(self, names, rev=None, message=None, force=False, local=False, 1292 def tag(self, names, rev=None, message=None, force=False, local=False,
782 remove=False, date=None, user=None): 1293 remove=False, date=None, user=None):
1294 """
1295 Add one or more tags specified by names for the current or given revision.
1296
1297 Changing an existing tag is normally disallowed; use force to override.
1298
1299 Tag commits are usually made at the head of a branch. If the parent of the
1300 working directory is not a branch head, a CommandError will be raised.
1301 force can be specified to force the tag commit to be based on a non-head
1302 changeset.
1303
1304 local - make the tag local
1305 rev - revision to tag
1306 remove - remove a tag
1307 message - set commit message
1308 date - record the specified date as commit date
1309 user - record the specified user as committer
1310 """
783 if not isinstance(names, list): 1311 if not isinstance(names, list):
784 names = [names] 1312 names = [names]
785 1313
786 args = cmdbuilder('tag', *names, r=rev, m=message, f=force, l=local, 1314 args = cmdbuilder('tag', *names, r=rev, m=message, f=force, l=local,
787 remove=remove, d=date, u=user) 1315 remove=remove, d=date, u=user)
885 d[name] = value 1413 d[name] = value
886 1414
887 return d 1415 return d
888 1416
889 def tip(self): 1417 def tip(self):
1418 """
1419 Return the tip revision (usually just called the tip) which is the
1420 changeset most recently added to the repository (and therefore the most
1421 recently changed head).
1422 """
890 args = cmdbuilder('tip', template=templates.changeset) 1423 args = cmdbuilder('tip', template=templates.changeset)
891 out = self.rawcommand(args) 1424 out = self.rawcommand(args)
892 out = out.split('\0') 1425 out = out.split('\0')
893 1426
894 return self._parserevs(out)[0] 1427 return self._parserevs(out)[0]
897 """ 1430 """
898 Update the repository's working directory to changeset specified by rev. 1431 Update the repository's working directory to changeset specified by rev.
899 If rev isn't specified, update to the tip of the current named branch. 1432 If rev isn't specified, update to the tip of the current named branch.
900 1433
901 Return the number of files (updated, merged, removed, unresolved) 1434 Return the number of files (updated, merged, removed, unresolved)
1435
1436 clean - discard uncommitted changes (no backup)
1437 check - update across branches if no uncommitted changes
1438 date - tipmost revision matching date
902 """ 1439 """
903 if clean and check: 1440 if clean and check:
904 raise ValueError('clean and check cannot both be True') 1441 raise ValueError('clean and check cannot both be True')
905 1442
906 args = cmdbuilder('update', r=rev, C=clean, c=check, d=date) 1443 args = cmdbuilder('update', r=rev, C=clean, c=check, d=date)
920 counters = out.rstrip().split(', ') 1457 counters = out.rstrip().split(', ')
921 return tuple(int(s.split(' ', 1)[0]) for s in counters) 1458 return tuple(int(s.split(' ', 1)[0]) for s in counters)
922 1459
923 @property 1460 @property
924 def version(self): 1461 def version(self):
1462 """
1463 Return hg version that runs the command server as a 4 fielded tuple: major,
1464 minor, micro and local build info. e.g. (1, 9, 1, '+4-3095db9f5c2c')
1465 """
925 if self._version is None: 1466 if self._version is None:
926 v = self.rawcommand(cmdbuilder('version', q=True)) 1467 v = self.rawcommand(cmdbuilder('version', q=True))
927 v = list(re.match(r'.*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?', 1468 v = list(re.match(r'.*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?',
928 v).groups()) 1469 v).groups())
929 1470