commands.py
6060 lines
| 218.4 KiB
| text/x-python
|
PythonLexer
/ mercurial / commands.py
|
r249 | # commands.py - command processing for mercurial | ||
# | ||||
|
r4635 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | ||
|
r249 | # | ||
|
r8225 | # This software may be used and distributed according to the terms of the | ||
|
r10263 | # GNU General Public License version 2 or any later version. | ||
|
r249 | |||
|
r13723 | from node import hex, bin, nullid, nullrev, short | ||
|
r8109 | from lock import release | ||
|
r18746 | from i18n import _ | ||
|
r21957 | import os, re, difflib, time, tempfile, errno, shlex | ||
|
r20740 | import sys | ||
|
r18746 | import hg, scmutil, util, revlog, copies, error, bookmarks | ||
|
r17887 | import patch, help, encoding, templatekw, discovery | ||
|
r14647 | import archival, changegroup, cmdutil, hbisect | ||
|
r19757 | import sshserver, hgweb, commandserver | ||
|
r21848 | import extensions | ||
|
r19757 | from hgweb import server as hgweb_server | ||
|
r15856 | import merge as mergemod | ||
|
r14511 | import minirst, revset, fileset | ||
|
r17182 | import dagparser, context, simplemerge, graphmod | ||
|
r20034 | import random | ||
import setdiscovery, treediscovery, dagutil, pvec, localrepo | ||||
|
r21063 | import phases, obsolete, exchange | ||
|
r2731 | |||
|
r14297 | table = {} | ||
command = cmdutil.command(table) | ||||
|
r21768 | # Space delimited list of commands that don't require local repositories. | ||
# This should be populated by passing norepo=True into the @command decorator. | ||||
norepo = '' | ||||
|
r21775 | # Space delimited list of commands that optionally require local repositories. | ||
# This should be populated by passing optionalrepo=True into the @command | ||||
# decorator. | ||||
optionalrepo = '' | ||||
|
r21778 | # Space delimited list of commands that will examine arguments looking for | ||
# a repository. This should be populated by passing inferrepo=True into the | ||||
# @command decorator. | ||||
inferrepo = '' | ||||
|
r14297 | # common command options | ||
globalopts = [ | ||||
('R', 'repository', '', | ||||
_('repository root directory or name of overlay bundle file'), | ||||
_('REPO')), | ||||
('', 'cwd', '', | ||||
_('change working directory'), _('DIR')), | ||||
('y', 'noninteractive', None, | ||||
|
r14849 | _('do not prompt, automatically pick the first choice for all prompts')), | ||
|
r14297 | ('q', 'quiet', None, _('suppress output')), | ||
('v', 'verbose', None, _('enable additional output')), | ||||
('', 'config', [], | ||||
_('set/override config option (use \'section.name=value\')'), | ||||
_('CONFIG')), | ||||
('', 'debug', None, _('enable debugging output')), | ||||
('', 'debugger', None, _('start debugger')), | ||||
('', 'encoding', encoding.encoding, _('set the charset encoding'), | ||||
_('ENCODE')), | ||||
('', 'encodingmode', encoding.encodingmode, | ||||
_('set the charset encoding mode'), _('MODE')), | ||||
('', 'traceback', None, _('always print a traceback on exception')), | ||||
('', 'time', None, _('time how long the command takes')), | ||||
('', 'profile', None, _('print command execution profile')), | ||||
('', 'version', None, _('output version information and exit')), | ||||
('h', 'help', None, _('display help and exit')), | ||||
|
r18267 | ('', 'hidden', False, _('consider hidden changesets')), | ||
|
r14297 | ] | ||
dryrunopts = [('n', 'dry-run', None, | ||||
_('do not perform actions, just print output'))] | ||||
remoteopts = [ | ||||
('e', 'ssh', '', | ||||
_('specify ssh command to use'), _('CMD')), | ||||
('', 'remotecmd', '', | ||||
_('specify hg command to run on the remote side'), _('CMD')), | ||||
('', 'insecure', None, | ||||
_('do not verify server certificate (ignoring web.cacerts config)')), | ||||
] | ||||
walkopts = [ | ||||
('I', 'include', [], | ||||
_('include names matching the given patterns'), _('PATTERN')), | ||||
('X', 'exclude', [], | ||||
_('exclude names matching the given patterns'), _('PATTERN')), | ||||
] | ||||
commitopts = [ | ||||
('m', 'message', '', | ||||
_('use text as commit message'), _('TEXT')), | ||||
('l', 'logfile', '', | ||||
_('read commit message from file'), _('FILE')), | ||||
] | ||||
commitopts2 = [ | ||||
('d', 'date', '', | ||||
_('record the specified date as commit date'), _('DATE')), | ||||
('u', 'user', '', | ||||
_('record the specified user as committer'), _('USER')), | ||||
] | ||||
templateopts = [ | ||||
('', 'style', '', | ||||
|
r20669 | _('display using template map file (DEPRECATED)'), _('STYLE')), | ||
|
r20665 | ('T', 'template', '', | ||
|
r14297 | _('display with template'), _('TEMPLATE')), | ||
] | ||||
logopts = [ | ||||
('p', 'patch', None, _('show patch')), | ||||
('g', 'git', None, _('use git extended diff format')), | ||||
('l', 'limit', '', | ||||
_('limit number of changes displayed'), _('NUM')), | ||||
('M', 'no-merges', None, _('do not show merges')), | ||||
('', 'stat', None, _('output diffstat-style summary of changes')), | ||||
|
r17182 | ('G', 'graph', None, _("show the revision DAG")), | ||
|
r14297 | ] + templateopts | ||
diffopts = [ | ||||
('a', 'text', None, _('treat all files as text')), | ||||
('g', 'git', None, _('use git extended diff format')), | ||||
('', 'nodates', None, _('omit dates from diff headers')) | ||||
] | ||||
|
r15528 | diffwsopts = [ | ||
|
r14297 | ('w', 'ignore-all-space', None, | ||
_('ignore white space when comparing lines')), | ||||
('b', 'ignore-space-change', None, | ||||
_('ignore changes in the amount of white space')), | ||||
('B', 'ignore-blank-lines', None, | ||||
_('ignore changes whose lines are all blank')), | ||||
|
r15528 | ] | ||
diffopts2 = [ | ||||
('p', 'show-function', None, _('show which function each change is in')), | ||||
('', 'reverse', None, _('produce a diff that undoes the changes')), | ||||
] + diffwsopts + [ | ||||
|
r14297 | ('U', 'unified', '', | ||
_('number of lines of context to show'), _('NUM')), | ||||
('', 'stat', None, _('output diffstat-style summary of changes')), | ||||
] | ||||
|
r14852 | mergetoolopts = [ | ||
('t', 'tool', '', _('specify merge tool')), | ||||
] | ||||
|
r14297 | similarityopts = [ | ||
('s', 'similarity', '', | ||||
_('guess renamed files by similarity (0<=s<=100)'), _('SIMILARITY')) | ||||
] | ||||
subrepoopts = [ | ||||
('S', 'subrepos', None, | ||||
_('recurse into subrepositories')) | ||||
] | ||||
|
r2731 | |||
|
r255 | # Commands start here, listed alphabetically | ||
|
r209 | |||
|
r14297 | @command('^add', | ||
walkopts + subrepoopts + dryrunopts, | ||||
|
r21778 | _('[OPTION]... [FILE]...'), | ||
inferrepo=True) | ||||
|
r724 | def add(ui, repo, *pats, **opts): | ||
|
r1437 | """add the specified files on the next commit | ||
|
r8004 | Schedule files to be version controlled and added to the | ||
repository. | ||||
|
r1437 | |||
|
r3829 | The files will be added to the repository at the next commit. To | ||
|
r11193 | undo an add before that, see :hg:`forget`. | ||
|
r1437 | |||
|
r7807 | If no names are given, add all files to the repository. | ||
|
r10446 | |||
.. container:: verbose | ||||
An example showing how new (unknown) files are added | ||||
|
r10973 | automatically by :hg:`add`:: | ||
|
r10446 | |||
$ ls | ||||
foo.c | ||||
$ hg status | ||||
? foo.c | ||||
$ hg add | ||||
adding foo.c | ||||
$ hg status | ||||
|
r10448 | A foo.c | ||
|
r11507 | |||
Returns 0 if all files are successfully added. | ||||
|
r1437 | """ | ||
|
r14671 | m = scmutil.match(repo[None], pats, opts) | ||
|
r12270 | rejected = cmdutil.add(ui, repo, m, opts.get('dry_run'), | ||
|
r15911 | opts.get('subrepos'), prefix="", explicitonly=False) | ||
|
r12269 | return rejected and 1 or 0 | ||
|
r213 | |||
|
r14297 | @command('addremove', | ||
similarityopts + walkopts + dryrunopts, | ||||
|
r21778 | _('[OPTION]... [FILE]...'), | ||
inferrepo=True) | ||||
|
r766 | def addremove(ui, repo, *pats, **opts): | ||
|
r3181 | """add all new files, delete all missing files | ||
|
r2181 | |||
|
r8004 | Add all new files and remove all missing files from the | ||
repository. | ||||
New files are ignored if they match any of the patterns in | ||||
|
r13344 | ``.hgignore``. As with add, these changes take effect at the next | ||
|
r8004 | commit. | ||
|
r2958 | |||
|
r17266 | Use the -s/--similarity option to detect renamed files. This | ||
|
r9249 | option takes a percentage between 0 (disabled) and 100 (files must | ||
|
r17266 | be identical) as its parameter. With a parameter greater than 0, | ||
this compares every removed file with every added file and records | ||||
those similar enough as renames. Detecting renamed files this way | ||||
|
r11518 | can be expensive. After using this option, :hg:`status -C` can be | ||
|
r17266 | used to check which files were identified as moved or renamed. If | ||
not specified, -s/--similarity defaults to 100 and only renames of | ||||
identical files are detected. | ||||
|
r11177 | |||
Returns 0 if all files are successfully added. | ||||
|
r1437 | """ | ||
|
r4966 | try: | ||
|
r11551 | sim = float(opts.get('similarity') or 100) | ||
|
r4966 | except ValueError: | ||
raise util.Abort(_('similarity must be a number')) | ||||
|
r2958 | if sim < 0 or sim > 100: | ||
raise util.Abort(_('similarity must be between 0 and 100')) | ||||
|
r14321 | return scmutil.addremove(repo, pats, opts, similarity=sim / 100.0) | ||
|
r219 | |||
|
r14297 | @command('^annotate|blame', | ||
[('r', 'rev', '', _('annotate the specified revision'), _('REV')), | ||||
('', 'follow', None, | ||||
_('follow copies/renames and list the filename (DEPRECATED)')), | ||||
('', 'no-follow', None, _("don't follow copies and renames")), | ||||
('a', 'text', None, _('treat all files as text')), | ||||
('u', 'user', None, _('list the author (long with -v)')), | ||||
('f', 'file', None, _('list the filename')), | ||||
('d', 'date', None, _('list the date (short with -q)')), | ||||
('n', 'number', None, _('list the revision number (default)')), | ||||
('c', 'changeset', None, _('list the changeset')), | ||||
('l', 'line-number', None, _('show line number at the first appearance')) | ||||
|
r15528 | ] + diffwsopts + walkopts, | ||
|
r21778 | _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'), | ||
inferrepo=True) | ||||
|
r733 | def annotate(ui, repo, *pats, **opts): | ||
|
r8779 | """show changeset information by line for each file | ||
|
r1437 | |||
|
r8004 | List changes in files, showing the revision id responsible for | ||
each line | ||||
|
r8779 | This command is useful for discovering when a change was made and | ||
by whom. | ||||
|
r1437 | |||
|
r8033 | Without the -a/--text option, annotate will avoid processing files | ||
|
r8779 | it detects as binary. With -a, annotate will annotate the file | ||
anyway, although the results will probably be neither useful | ||||
nor desirable. | ||||
|
r11177 | |||
Returns 0 on success. | ||||
|
r1437 | """ | ||
|
r10579 | if opts.get('follow'): | ||
# --follow is deprecated and now just an alias for -f/--file | ||||
# to mimic the behavior of Mercurial before version 1.5 | ||||
|
r14216 | opts['file'] = True | ||
|
r10579 | |||
|
r6134 | datefunc = ui.quiet and util.shortdate or util.datestr | ||
getdate = util.cachefunc(lambda x: datefunc(x[0].date())) | ||||
|
r1522 | |||
|
r744 | if not pats: | ||
|
r8761 | raise util.Abort(_('at least one filename or pattern is required')) | ||
|
r744 | |||
|
r15631 | hexfn = ui.debugflag and hex or short | ||
|
r14358 | opmap = [('user', ' ', lambda x: ui.shortuser(x[0].user())), | ||
('number', ' ', lambda x: str(x[0].rev())), | ||||
|
r15631 | ('changeset', ' ', lambda x: hexfn(x[0].node())), | ||
|
r14358 | ('date', ' ', getdate), | ||
('file', ' ', lambda x: x[0].path()), | ||||
('line_number', ':', lambda x: str(x[1])), | ||||
|
r4857 | ] | ||
|
r10282 | if (not opts.get('user') and not opts.get('changeset') | ||
|
r10369 | and not opts.get('date') and not opts.get('file')): | ||
|
r14216 | opts['number'] = True | ||
|
r209 | |||
|
r4857 | linenumber = opts.get('line_number') is not None | ||
|
r10394 | if linenumber and (not opts.get('changeset')) and (not opts.get('number')): | ||
|
r4857 | raise util.Abort(_('at least one of -n/-c is required for -l')) | ||
|
r14358 | funcmap = [(func, sep) for op, sep, func in opmap if opts.get(op)] | ||
funcmap[0] = (funcmap[0][0], '') # no separator in front of first column | ||||
|
r4857 | |||
|
r13697 | def bad(x, y): | ||
raise util.Abort("%s: %s" % (x, y)) | ||||
|
r14319 | ctx = scmutil.revsingle(repo, opts.get('rev')) | ||
|
r14671 | m = scmutil.match(ctx, pats, opts) | ||
|
r13697 | m.bad = bad | ||
|
r10369 | follow = not opts.get('no_follow') | ||
|
r15528 | diffopts = patch.diffopts(ui, opts, section='annotate') | ||
|
r6764 | for abs in ctx.walk(m): | ||
fctx = ctx[abs] | ||||
|
r7131 | if not opts.get('text') and util.binary(fctx.data()): | ||
|
r6584 | ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs)) | ||
|
r1016 | continue | ||
|
r15528 | lines = fctx.annotate(follow=follow, linenumber=linenumber, | ||
diffopts=diffopts) | ||||
|
r209 | pieces = [] | ||
|
r14358 | for f, sep in funcmap: | ||
|
r4857 | l = [f(n) for n, dummy in lines] | ||
if l: | ||||
|
r11611 | sized = [(x, encoding.colwidth(x)) for x in l] | ||
ml = max([w for x, w in sized]) | ||||
|
r14358 | pieces.append(["%s%s%s" % (sep, ' ' * (ml - w), x) | ||
for x, w in sized]) | ||||
|
r209 | |||
|
r771 | if pieces: | ||
for p, l in zip(zip(*pieces), lines): | ||||
|
r14358 | ui.write("%s: %s" % ("".join(p), l[1])) | ||
|
r209 | |||
|
r15829 | if lines and not lines[-1][1].endswith('\n'): | ||
ui.write('\n') | ||||
|
r14297 | @command('archive', | ||
[('', 'no-decode', None, _('do not pass files through decoders')), | ||||
('p', 'prefix', '', _('directory prefix for files in archive'), | ||||
_('PREFIX')), | ||||
('r', 'rev', '', _('revision to distribute'), _('REV')), | ||||
('t', 'type', '', _('type of distribution to create'), _('TYPE')), | ||||
] + subrepoopts + walkopts, | ||||
_('[OPTION]... DEST')) | ||||
|
r2112 | def archive(ui, repo, dest, **opts): | ||
|
r8779 | '''create an unversioned archive of a repository revision | ||
|
r2112 | |||
By default, the revision used is the parent of the working | ||||
|
r8033 | directory; use -r/--rev to specify a different revision. | ||
|
r10650 | The archive type is automatically detected based on file | ||
extension (or override using -t/--type). | ||||
|
r15109 | .. container:: verbose | ||
Examples: | ||||
- create a zip file containing the 1.0 release:: | ||||
hg archive -r 1.0 project-1.0.zip | ||||
- create a tarball excluding .hg files:: | ||||
hg archive project.tar.gz -X ".hg*" | ||||
|
r10650 | Valid types are: | ||
|
r9892 | |||
:``files``: a directory full of files (default) | ||||
:``tar``: tar archive, uncompressed | ||||
:``tbz2``: tar archive, compressed using bzip2 | ||||
:``tgz``: tar archive, compressed using gzip | ||||
:``uzip``: zip archive, uncompressed | ||||
:``zip``: zip archive, compressed using deflate | ||||
|
r2112 | |||
The exact name of the destination archive or directory is given | ||||
|
r10973 | using a format string; see :hg:`help export` for details. | ||
|
r2112 | |||
Each member added to an archive file has a directory prefix | ||||
|
r8033 | prepended. Use -p/--prefix to specify a format string for the | ||
prefix. The default is the basename of the archive, with suffixes | ||||
removed. | ||||
|
r11177 | |||
Returns 0 on success. | ||||
|
r2112 | ''' | ||
|
r14319 | ctx = scmutil.revsingle(repo, opts.get('rev')) | ||
|
r5061 | if not ctx: | ||
|
r7528 | raise util.Abort(_('no working directory: please specify a revision')) | ||
|
r5061 | node = ctx.node() | ||
|
r14290 | dest = cmdutil.makefilename(repo, dest, node) | ||
|
r15381 | if os.path.realpath(dest) == repo.root: | ||
|
r2112 | raise util.Abort(_('repository root cannot be destination')) | ||
|
r10650 | |||
|
r11557 | kind = opts.get('type') or archival.guesskind(dest) or 'files' | ||
|
r7131 | prefix = opts.get('prefix') | ||
|
r10650 | |||
|
r2476 | if dest == '-': | ||
if kind == 'files': | ||||
raise util.Abort(_('cannot archive plain files to stdout')) | ||||
|
r14742 | dest = cmdutil.makefileobj(repo, dest) | ||
|
r10282 | if not prefix: | ||
prefix = os.path.basename(repo.root) + '-%h' | ||||
|
r10650 | |||
|
r14290 | prefix = cmdutil.makefilename(repo, prefix, node) | ||
|
r14671 | matchfn = scmutil.match(ctx, [], opts) | ||
|
r7131 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), | ||
|
r12323 | matchfn, prefix, subrepos=opts.get('subrepos')) | ||
|
r2112 | |||
|
r14297 | @command('backout', | ||
[('', 'merge', None, _('merge with old dirstate parent after backout')), | ||||
|
r15211 | ('', 'parent', '', | ||
_('parent to choose when backing out merge (DEPRECATED)'), _('REV')), | ||||
|
r14297 | ('r', 'rev', '', _('revision to backout'), _('REV')), | ||
|
r21712 | ('e', 'edit', False, _('invoke editor on commit messages')), | ||
|
r14852 | ] + mergetoolopts + walkopts + commitopts + commitopts2, | ||
|
r14297 | _('[OPTION]... [-r] REV')) | ||
|
r4450 | def backout(ui, repo, node=None, rev=None, **opts): | ||
|
r2158 | '''reverse effect of earlier changeset | ||
|
r13340 | Prepare a new changeset with the effect of REV undone in the | ||
current working directory. | ||||
|
r13473 | If REV is the parent of the working directory, then this new changeset | ||
|
r13340 | is committed automatically. Otherwise, hg needs to merge the | ||
changes and the merged result is left uncommitted. | ||||
|
r15210 | .. note:: | ||
|
r19997 | |||
|
r15210 | backout cannot be used to fix either an unwanted or | ||
incorrect merge. | ||||
|
r15209 | .. container:: verbose | ||
By default, the pending changeset will have one parent, | ||||
maintaining a linear history. With --merge, the pending | ||||
changeset will instead have two parents: the old parent of the | ||||
working directory and a new child of REV that simply undoes REV. | ||||
Before version 1.7, the behavior without --merge was equivalent | ||||
to specifying --merge followed by :hg:`update --clean .` to | ||||
cancel the merge and leave the child of REV as a head to be | ||||
merged separately. | ||||
|
r6163 | |||
|
r10973 | See :hg:`help dates` for a list of formats valid for -d/--date. | ||
|
r11177 | |||
|
r20872 | Returns 0 on success, 1 if nothing to backout or there are unresolved | ||
files. | ||||
|
r6163 | ''' | ||
|
r4450 | if rev and node: | ||
raise util.Abort(_("please specify just one revision")) | ||||
if not rev: | ||||
rev = node | ||||
|
r2158 | |||
|
r4726 | if not rev: | ||
raise util.Abort(_("please specify a revision to backout")) | ||||
|
r6139 | date = opts.get('date') | ||
if date: | ||||
opts['date'] = util.parsedate(date) | ||||
|
r19476 | cmdutil.checkunfinished(repo) | ||
|
r14289 | cmdutil.bailifchanged(repo) | ||
|
r14319 | node = scmutil.revsingle(repo, rev).node() | ||
|
r5716 | |||
|
r2158 | op1, op2 = repo.dirstate.parents() | ||
|
r21105 | if node not in repo.changelog.commonancestorsheads(op1, node): | ||
|
r20791 | raise util.Abort(_('cannot backout change that is not an ancestor')) | ||
|
r5568 | |||
|
r2614 | p1, p2 = repo.changelog.parents(node) | ||
if p1 == nullid: | ||||
|
r8779 | raise util.Abort(_('cannot backout a change with no parents')) | ||
|
r2158 | if p2 != nullid: | ||
|
r7131 | if not opts.get('parent'): | ||
|
r15211 | raise util.Abort(_('cannot backout a merge changeset')) | ||
|
r2614 | p = repo.lookup(opts['parent']) | ||
if p not in (p1, p2): | ||||
|
r3679 | raise util.Abort(_('%s is not a parent of %s') % | ||
|
r3680 | (short(p), short(node))) | ||
|
r2614 | parent = p | ||
else: | ||||
|
r7131 | if opts.get('parent'): | ||
|
r2614 | raise util.Abort(_('cannot use --parent on non-merge changeset')) | ||
parent = p1 | ||||
|
r5568 | |||
|
r6423 | # the backout should appear on the same branch | ||
|
r16470 | wlock = repo.wlock() | ||
try: | ||||
branch = repo.dirstate.branch() | ||||
|
r18689 | bheads = repo.branchheads(branch) | ||
|
r18685 | rctx = scmutil.revsingle(repo, hex(parent)) | ||
|
r16470 | if not opts.get('merge') and op1 != node: | ||
try: | ||||
|
r20790 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), | ||
'backout') | ||||
|
r20276 | stats = mergemod.update(repo, parent, True, True, False, | ||
node, False) | ||||
|
r20275 | repo.setparents(op1, op2) | ||
hg._showstats(repo, stats) | ||||
if stats[3]: | ||||
|
r20276 | repo.ui.status(_("use 'hg resolve' to retry unresolved " | ||
"file merges\n")) | ||||
else: | ||||
msg = _("changeset %s backed out, " | ||||
"don't forget to commit.\n") | ||||
ui.status(msg % short(node)) | ||||
|
r20275 | return stats[3] > 0 | ||
|
r16470 | finally: | ||
|
r20790 | ui.setconfig('ui', 'forcemerge', '', '') | ||
|
r20275 | else: | ||
hg.clean(repo, node, show_stats=False) | ||||
repo.dirstate.setbranch(branch) | ||||
cmdutil.revert(ui, repo, rctx, repo.dirstate.parents()) | ||||
|
r16470 | |||
|
r18689 | def commitfunc(ui, repo, message, match, opts): | ||
|
r22007 | editform = 'backout' | ||
e = cmdutil.getcommiteditor(editform=editform, **opts) | ||||
|
r21412 | if not message: | ||
# we don't translate commit messages | ||||
message = "Backed out changeset %s" % short(node) | ||||
|
r22007 | e = cmdutil.getcommiteditor(edit=True, editform=editform) | ||
|
r18689 | return repo.commit(message, opts.get('user'), opts.get('date'), | ||
match, editor=e) | ||||
newnode = cmdutil.commit(ui, repo, commitfunc, [], opts) | ||||
|
r20872 | if not newnode: | ||
ui.status(_("nothing changed\n")) | ||||
return 1 | ||||
|
r18689 | cmdutil.commitstatus(repo, newnode, branch, bheads) | ||
|
r18687 | |||
|
r16470 | def nice(node): | ||
return '%d:%s' % (repo.changelog.rev(node), short(node)) | ||||
ui.status(_('changeset %s backs out changeset %s\n') % | ||||
(nice(repo.changelog.tip()), nice(node))) | ||||
if opts.get('merge') and op1 != node: | ||||
hg.clean(repo, op1, show_stats=False) | ||||
ui.status(_('merging with changeset %s\n') | ||||
% nice(repo.changelog.tip())) | ||||
try: | ||||
|
r20790 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), | ||
'backout') | ||||
|
r16470 | return hg.merge(repo, hex(repo.changelog.tip())) | ||
finally: | ||||
|
r20790 | ui.setconfig('ui', 'forcemerge', '', '') | ||
|
r16470 | finally: | ||
wlock.release() | ||||
|
r12727 | return 0 | ||
|
r2158 | |||
|
r14297 | @command('bisect', | ||
[('r', 'reset', False, _('reset bisect state')), | ||||
('g', 'good', False, _('mark changeset good')), | ||||
('b', 'bad', False, _('mark changeset bad')), | ||||
('s', 'skip', False, _('skip testing changeset')), | ||||
('e', 'extend', False, _('extend the bisect range')), | ||||
('c', 'command', '', _('use command to check changeset state'), _('CMD')), | ||||
('U', 'noupdate', False, _('do not update to target'))], | ||||
_("[-gbsr] [-U] [-c CMD] [REV]")) | ||||
|
r7227 | def bisect(ui, repo, rev=None, extra=None, command=None, | ||
|
r13601 | reset=None, good=None, bad=None, skip=None, extend=None, | ||
noupdate=None): | ||||
|
r5775 | """subdivision search of changesets | ||
|
r8004 | This command helps to find changesets which introduce problems. To | ||
use, mark the earliest changeset you know exhibits the problem as | ||||
bad, then mark the latest changeset which is free from the problem | ||||
as good. Bisect will update your working directory to a revision | ||||
|
r8033 | for testing (unless the -U/--noupdate option is specified). Once | ||
|
r8779 | you have performed tests, mark the working directory as good or | ||
bad, and bisect will either update to another candidate changeset | ||||
|
r6928 | or announce that it has found the bad revision. | ||
|
r7184 | |||
|
r6928 | As a shortcut, you can also use the revision argument to mark a | ||
revision as good or bad without checking it out first. | ||||
|
r7227 | |||
|
r8779 | If you supply a command, it will be used for automatic bisection. | ||
|
r16648 | The environment variable HG_NODE will contain the ID of the | ||
changeset being tested. The exit status of the command will be | ||||
used to mark revisions as good or bad: status 0 means good, 125 | ||||
means to skip the revision, 127 (command not found) will abort the | ||||
bisection, and any other non-zero exit status means the revision | ||||
is bad. | ||||
|
r11177 | |||
|
r15139 | .. container:: verbose | ||
Some examples: | ||||
|
r20151 | - start a bisection with known bad revision 34, and good revision 12:: | ||
|
r15139 | |||
hg bisect --bad 34 | ||||
hg bisect --good 12 | ||||
- advance the current bisection by marking current revision as good or | ||||
bad:: | ||||
hg bisect --good | ||||
hg bisect --bad | ||||
|
r17424 | - mark the current revision, or a known revision, to be skipped (e.g. if | ||
|
r15139 | that revision is not usable because of another issue):: | ||
hg bisect --skip | ||||
hg bisect --skip 23 | ||||
|
r19958 | - skip all revisions that do not touch directories ``foo`` or ``bar``:: | ||
|
r17969 | |||
|
r19959 | hg bisect --skip "!( file('path:foo') & file('path:bar') )" | ||
|
r17969 | |||
|
r15139 | - forget the current bisection:: | ||
hg bisect --reset | ||||
- use 'make && make tests' to automatically find the first broken | ||||
revision:: | ||||
hg bisect --reset | ||||
hg bisect --bad 34 | ||||
hg bisect --good 12 | ||||
|
r19959 | hg bisect --command "make && make tests" | ||
|
r15139 | |||
- see all changesets whose states are already known in the current | ||||
bisection:: | ||||
hg log -r "bisect(pruned)" | ||||
|
r16647 | - see the changeset currently being bisected (especially useful | ||
if running with -U/--noupdate):: | ||||
hg log -r "bisect(current)" | ||||
|
r15139 | - see all changesets that took part in the current bisection:: | ||
hg log -r "bisect(range)" | ||||
|
r20146 | - you can even get a nice graph:: | ||
|
r15139 | |||
hg log --graph -r "bisect(range)" | ||||
|
r15147 | See :hg:`help revsets` for more about the `bisect()` keyword. | ||
|
r11177 | Returns 0 on success. | ||
|
r5775 | """ | ||
|
r13601 | def extendbisectrange(nodes, good): | ||
# bisect is incomplete when it ends on a merge node and | ||||
# one of the parent was not checked. | ||||
parents = repo[nodes[0]].parents() | ||||
if len(parents) > 1: | ||||
side = good and state['bad'] or state['good'] | ||||
num = len(set(i.node() for i in parents) & set(side)) | ||||
if num == 1: | ||||
|
r14157 | return parents[0].ancestor(parents[1]) | ||
|
r13601 | return None | ||
|
r7227 | def print_result(nodes, good): | ||
|
r5775 | displayer = cmdutil.show_changeset(ui, repo, {}) | ||
|
r6858 | if len(nodes) == 1: | ||
# narrowed it down to a single revision | ||||
|
r8088 | if good: | ||
ui.write(_("The first good revision is:\n")) | ||||
else: | ||||
ui.write(_("The first bad revision is:\n")) | ||||
|
r7369 | displayer.show(repo[nodes[0]]) | ||
|
r13601 | extendnode = extendbisectrange(nodes, good) | ||
if extendnode is not None: | ||||
ui.write(_('Not all ancestors of this changeset have been' | ||||
' checked.\nUse bisect --extend to continue the ' | ||||
'bisection from\nthe common ancestor, %s.\n') | ||||
|
r14055 | % extendnode) | ||
|
r6858 | else: | ||
# multiple possible revisions | ||||
|
r8088 | if good: | ||
ui.write(_("Due to skipped revisions, the first " | ||||
"good revision could be any of:\n")) | ||||
else: | ||||
ui.write(_("Due to skipped revisions, the first " | ||||
"bad revision could be any of:\n")) | ||||
|
r6858 | for n in nodes: | ||
|
r7369 | displayer.show(repo[n]) | ||
|
r10152 | displayer.close() | ||
|
r7227 | |||
def check_state(state, interactive=True): | ||||
if not state['good'] or not state['bad']: | ||||
if (good or bad or skip or reset) and interactive: | ||||
return | ||||
if not state['good']: | ||||
raise util.Abort(_('cannot bisect (no known good revisions)')) | ||||
else: | ||||
raise util.Abort(_('cannot bisect (no known bad revisions)')) | ||||
return True | ||||
# backward compatibility | ||||
if rev in "good bad reset init".split(): | ||||
ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n")) | ||||
cmd, rev, extra = rev, extra, None | ||||
if cmd == "good": | ||||
good = True | ||||
elif cmd == "bad": | ||||
bad = True | ||||
else: | ||||
reset = True | ||||
|
r13601 | elif extra or good + bad + skip + reset + extend + bool(command) > 1: | ||
|
r7227 | raise util.Abort(_('incompatible arguments')) | ||
|
r19476 | cmdutil.checkunfinished(repo) | ||
|
r7227 | if reset: | ||
p = repo.join("bisect.state") | ||||
if os.path.exists(p): | ||||
os.unlink(p) | ||||
return | ||||
state = hbisect.load_state(repo) | ||||
if command: | ||||
changesets = 1 | ||||
|
r20237 | if noupdate: | ||
try: | ||||
node = state['current'][0] | ||||
except LookupError: | ||||
|
r16647 | raise util.Abort(_('current bisect revision is unknown - ' | ||
'start a new bisect to fix')) | ||||
|
r20237 | else: | ||
|
r16647 | node, p2 = repo.dirstate.parents() | ||
if p2 != nullid: | ||||
raise util.Abort(_('current bisect revision is a merge')) | ||||
try: | ||||
|
r7590 | while changesets: | ||
# update state | ||||
|
r16647 | state['current'] = [node] | ||
|
r16593 | hbisect.save_state(repo, state) | ||
|
r16648 | status = util.system(command, | ||
environ={'HG_NODE': hex(node)}, | ||||
out=ui.fout) | ||||
|
r7590 | if status == 125: | ||
transition = "skip" | ||||
elif status == 0: | ||||
transition = "good" | ||||
# status < 0 means process was killed | ||||
elif status == 127: | ||||
raise util.Abort(_("failed to execute %s") % command) | ||||
elif status < 0: | ||||
raise util.Abort(_("%s killed") % command) | ||||
else: | ||||
transition = "bad" | ||||
|
r16647 | ctx = scmutil.revsingle(repo, rev, node) | ||
|
r12925 | rev = None # clear for future iterations | ||
|
r8805 | state[transition].append(ctx.node()) | ||
|
r16936 | ui.status(_('changeset %d:%s: %s\n') % (ctx, ctx, transition)) | ||
|
r7590 | check_state(state, interactive=False) | ||
# bisect | ||||
|
r20052 | nodes, changesets, bgood = hbisect.bisect(repo.changelog, state) | ||
|
r7590 | # update to next check | ||
|
r16647 | node = nodes[0] | ||
if not noupdate: | ||||
cmdutil.bailifchanged(repo) | ||||
hg.clean(repo, node, show_stats=False) | ||||
|
r7590 | finally: | ||
|
r16647 | state['current'] = [node] | ||
|
r7590 | hbisect.save_state(repo, state) | ||
|
r20052 | print_result(nodes, bgood) | ||
|
r11177 | return | ||
|
r7227 | |||
# update state | ||||
|
r12177 | |||
if rev: | ||||
|
r14319 | nodes = [repo.lookup(i) for i in scmutil.revrange(repo, [rev])] | ||
|
r12177 | else: | ||
nodes = [repo.lookup('.')] | ||||
|
r9689 | if good or bad or skip: | ||
if good: | ||||
|
r12177 | state['good'] += nodes | ||
|
r9689 | elif bad: | ||
|
r12177 | state['bad'] += nodes | ||
|
r9689 | elif skip: | ||
|
r12177 | state['skip'] += nodes | ||
|
r9689 | hbisect.save_state(repo, state) | ||
|
r7227 | |||
if not check_state(state): | ||||
return | ||||
# actually bisect | ||||
nodes, changesets, good = hbisect.bisect(repo.changelog, state) | ||||
|
r13601 | if extend: | ||
if not changesets: | ||||
extendnode = extendbisectrange(nodes, good) | ||||
if extendnode is not None: | ||||
|
r20868 | ui.write(_("Extending search to changeset %d:%s\n") | ||
% (extendnode.rev(), extendnode)) | ||||
|
r16647 | state['current'] = [extendnode.node()] | ||
hbisect.save_state(repo, state) | ||||
|
r13601 | if noupdate: | ||
return | ||||
|
r14289 | cmdutil.bailifchanged(repo) | ||
|
r13601 | return hg.clean(repo, extendnode.node()) | ||
raise util.Abort(_("nothing to extend")) | ||||
|
r7227 | if changesets == 0: | ||
print_result(nodes, good) | ||||
|
r6858 | else: | ||
assert len(nodes) == 1 # only a single node can be tested next | ||||
node = nodes[0] | ||||
|
r5775 | # compute the approximate number of remaining tests | ||
tests, size = 0, 2 | ||||
while size <= changesets: | ||||
tests, size = tests + 1, size * 2 | ||||
rev = repo.changelog.rev(node) | ||||
|
r9012 | ui.write(_("Testing changeset %d:%s " | ||
"(%d changesets remaining, ~%d tests)\n") | ||||
|
r6217 | % (rev, short(node), changesets, tests)) | ||
|
r16647 | state['current'] = [node] | ||
hbisect.save_state(repo, state) | ||||
|
r5775 | if not noupdate: | ||
|
r14289 | cmdutil.bailifchanged(repo) | ||
|
r5775 | return hg.clean(repo, node) | ||
|
r18075 | @command('bookmarks|bookmark', | ||
|
r14297 | [('f', 'force', False, _('force')), | ||
('r', 'rev', '', _('revision'), _('REV')), | ||||
('d', 'delete', False, _('delete a given bookmark')), | ||||
('m', 'rename', '', _('rename a given bookmark'), _('NAME')), | ||||
|
r15959 | ('i', 'inactive', False, _('mark a bookmark inactive'))], | ||
|
r19147 | _('hg bookmarks [OPTIONS]... [NAME]...')) | ||
def bookmark(ui, repo, *names, **opts): | ||||
|
r21762 | '''create a new bookmark or list existing bookmarks | ||
Bookmarks are labels on changesets to help track lines of development. | ||||
Bookmarks are unversioned and can be moved, renamed and deleted. | ||||
Deleting or moving a bookmark has no effect on the associated changesets. | ||||
Creating or updating to a bookmark causes it to be marked as 'active'. | ||||
Active bookmarks are indicated with a '*'. | ||||
When a commit is made, an active bookmark will advance to the new commit. | ||||
A plain :hg:`update` will also advance an active bookmark, if possible. | ||||
Updating away from a bookmark will cause it to be deactivated. | ||||
Bookmarks can be pushed and pulled between repositories (see | ||||
:hg:`help push` and :hg:`help pull`). If a shared bookmark has | ||||
diverged, a new 'divergent bookmark' of the form 'name@path' will | ||||
be created. Using :hg:'merge' will resolve the divergence. | ||||
A bookmark named '@' has the special property that :hg:`clone` will | ||||
check it out by default if it exists. | ||||
.. container:: verbose | ||||
Examples: | ||||
- create an active bookmark for a new line of development:: | ||||
hg book new-feature | ||||
- create an inactive bookmark as a place marker:: | ||||
hg book -i reviewed | ||||
- create an inactive bookmark on another changeset:: | ||||
hg book -r .^ tested | ||||
- move the '@' bookmark from another branch:: | ||||
hg book -f @ | ||||
|
r13368 | ''' | ||
|
r19147 | force = opts.get('force') | ||
rev = opts.get('rev') | ||||
delete = opts.get('delete') | ||||
rename = opts.get('rename') | ||||
inactive = opts.get('inactive') | ||||
|
r17789 | def checkformat(mark): | ||
mark = mark.strip() | ||||
if not mark: | ||||
raise util.Abort(_("bookmark names cannot consist entirely of " | ||||
"whitespace")) | ||||
|
r17821 | scmutil.checknewlabel(repo, mark, 'bookmark') | ||
|
r17789 | return mark | ||
|
r20233 | def checkconflict(repo, mark, cur, force=False, target=None): | ||
|
r17789 | if mark in marks and not force: | ||
|
r18773 | if target: | ||
|
r18781 | if marks[mark] == target and target == cur: | ||
# re-activating a bookmark | ||||
return | ||||
|
r18773 | anc = repo.changelog.ancestors([repo[target].rev()]) | ||
bmctx = repo[marks[mark]] | ||||
|
r19109 | divs = [repo[b].node() for b in marks | ||
if b.split('@', 1)[0] == mark.split('@', 1)[0]] | ||||
|
r19111 | |||
# allow resolving a single divergent bookmark even if moving | ||||
# the bookmark across branches when a revision is specified | ||||
# that contains a divergent bookmark | ||||
if bmctx.rev() not in anc and target in divs: | ||||
bookmarks.deletedivergent(repo, [target], mark) | ||||
return | ||||
|
r19109 | deletefrom = [b for b in divs | ||
if repo[b].rev() in anc or b == target] | ||||
bookmarks.deletedivergent(repo, deletefrom, mark) | ||||
|
r20282 | if bookmarks.validdest(repo, bmctx, repo[target]): | ||
|
r18773 | ui.status(_("moving bookmark '%s' forward from %s\n") % | ||
(mark, short(bmctx.node()))) | ||||
return | ||||
|
r17789 | raise util.Abort(_("bookmark '%s' already exists " | ||
"(use -f to force)") % mark) | ||||
if ((mark in repo.branchmap() or mark == repo.dirstate.branch()) | ||||
and not force): | ||||
raise util.Abort( | ||||
_("a bookmark cannot have the name of an existing branch")) | ||||
|
r17790 | if delete and rename: | ||
raise util.Abort(_("--delete and --rename are incompatible")) | ||||
if delete and rev: | ||||
raise util.Abort(_("--rev is incompatible with --delete")) | ||||
if rename and rev: | ||||
raise util.Abort(_("--rev is incompatible with --rename")) | ||||
|
r19147 | if not names and (delete or rev): | ||
|
r17791 | raise util.Abort(_("bookmark name required")) | ||
|
r17790 | |||
|
r20232 | if delete or rename or names or inactive: | ||
wlock = repo.wlock() | ||||
try: | ||||
|
r20234 | cur = repo.changectx('.').node() | ||
|
r20232 | marks = repo._bookmarks | ||
if delete: | ||||
for mark in names: | ||||
if mark not in marks: | ||||
raise util.Abort(_("bookmark '%s' does not exist") % | ||||
mark) | ||||
if mark == repo._bookmarkcurrent: | ||||
bookmarks.unsetcurrent(repo) | ||||
del marks[mark] | ||||
marks.write() | ||||
elif rename: | ||||
if not names: | ||||
raise util.Abort(_("new bookmark name required")) | ||||
elif len(names) > 1: | ||||
raise util.Abort(_("only one new bookmark name allowed")) | ||||
mark = checkformat(names[0]) | ||||
if rename not in marks: | ||||
raise util.Abort(_("bookmark '%s' does not exist") % rename) | ||||
|
r20233 | checkconflict(repo, mark, cur, force) | ||
|
r20232 | marks[mark] = marks[rename] | ||
if repo._bookmarkcurrent == rename and not inactive: | ||||
bookmarks.setcurrent(repo, mark) | ||||
del marks[rename] | ||||
marks.write() | ||||
elif names: | ||||
newact = None | ||||
for mark in names: | ||||
mark = checkformat(mark) | ||||
if newact is None: | ||||
newact = mark | ||||
if inactive and mark == repo._bookmarkcurrent: | ||||
bookmarks.unsetcurrent(repo) | ||||
return | ||||
tgt = cur | ||||
if rev: | ||||
tgt = scmutil.revsingle(repo, rev).node() | ||||
|
r20233 | checkconflict(repo, mark, cur, force, tgt) | ||
|
r20232 | marks[mark] = tgt | ||
if not inactive and cur == marks[newact] and not rev: | ||||
bookmarks.setcurrent(repo, newact) | ||||
elif cur != tgt and newact == repo._bookmarkcurrent: | ||||
bookmarks.unsetcurrent(repo) | ||||
marks.write() | ||||
elif inactive: | ||||
if len(marks) == 0: | ||||
ui.status(_("no bookmarks set\n")) | ||||
elif not repo._bookmarkcurrent: | ||||
ui.status(_("no active bookmark\n")) | ||||
else: | ||||
bookmarks.unsetcurrent(repo) | ||||
finally: | ||||
wlock.release() | ||||
|
r17822 | else: # show bookmarks | ||
|
r20235 | hexfn = ui.debugflag and hex or short | ||
|
r20232 | marks = repo._bookmarks | ||
|
r20231 | if len(marks) == 0: | ||
ui.status(_("no bookmarks set\n")) | ||||
else: | ||||
for bmark, n in sorted(marks.iteritems()): | ||||
current = repo._bookmarkcurrent | ||||
if bmark == current: | ||||
prefix, label = '*', 'bookmarks.current' | ||||
else: | ||||
prefix, label = ' ', '' | ||||
if ui.quiet: | ||||
ui.write("%s\n" % bmark, label=label) | ||||
else: | ||||
|
r21571 | pad = " " * (25 - encoding.colwidth(bmark)) | ||
ui.write(" %s %s%s %d:%s\n" % ( | ||||
prefix, bmark, pad, repo.changelog.rev(n), hexfn(n)), | ||||
|
r20231 | label=label) | ||
|
r13368 | |||
|
r14297 | @command('branch', | ||
[('f', 'force', None, | ||||
_('set branch name even if it shadows an existing branch')), | ||||
('C', 'clean', None, _('reset branch name to parent branch name'))], | ||||
_('[-fC] [NAME]')) | ||||
|
r4202 | def branch(ui, repo, label=None, **opts): | ||
|
r3502 | """set or show the current branch name | ||
|
r15610 | .. note:: | ||
|
r19997 | |||
|
r15610 | Branch names are permanent and global. Use :hg:`bookmark` to create a | ||
light-weight bookmark instead. See :hg:`help glossary` for more | ||||
information about named branches and bookmarks. | ||||
|
r4601 | With no argument, show the current branch name. With one argument, | ||
|
r8779 | set the working directory branch name (the branch will not exist | ||
in the repository until the next commit). Standard practice | ||||
recommends that primary development take place on the 'default' | ||||
branch. | ||||
|
r4202 | |||
|
r8033 | Unless -f/--force is specified, branch will not let you set a | ||
|
r8779 | branch name that already exists, even if it's inactive. | ||
|
r5999 | |||
|
r8033 | Use -C/--clean to reset the working directory branch to that of | ||
the parent of the working directory, negating a previous branch | ||||
|
r8004 | change. | ||
|
r7006 | |||
|
r10973 | Use the command :hg:`update` to switch to an existing branch. Use | ||
:hg:`commit --close-branch` to mark this branch as closed. | ||||
|
r11177 | |||
Returns 0 on success. | ||||
|
r3502 | """ | ||
|
r19180 | if label: | ||
label = label.strip() | ||||
|
r16471 | if not opts.get('clean') and not label: | ||
|
r13047 | ui.write("%s\n" % repo.dirstate.branch()) | ||
|
r16471 | return | ||
wlock = repo.wlock() | ||||
try: | ||||
if opts.get('clean'): | ||||
label = repo[None].p1().branch() | ||||
repo.dirstate.setbranch(label) | ||||
ui.status(_('reset working directory to branch %s\n') % label) | ||||
elif label: | ||||
|
r16719 | if not opts.get('force') and label in repo.branchmap(): | ||
|
r16471 | if label not in [p.branch() for p in repo.parents()]: | ||
raise util.Abort(_('a branch of the same name already' | ||||
' exists'), | ||||
# i18n: "it" refers to an existing branch | ||||
hint=_("use 'hg update' to switch to it")) | ||||
|
r17990 | scmutil.checknewlabel(repo, label, 'branch') | ||
|
r16471 | repo.dirstate.setbranch(label) | ||
ui.status(_('marked working directory as branch %s\n') % label) | ||||
ui.status(_('(branches are permanent and global, ' | ||||
'did you want a bookmark?)\n')) | ||||
finally: | ||||
wlock.release() | ||||
|
r3502 | |||
|
r14297 | @command('branches', | ||
[('a', 'active', False, _('show only branches that have unmerged heads')), | ||||
('c', 'closed', False, _('show normal and closed branches'))], | ||||
_('[-ac]')) | ||||
|
r8991 | def branches(ui, repo, active=False, closed=False): | ||
|
r3502 | """list repository named branches | ||
|
r4675 | List the repository's named branches, indicating which ones are | ||
|
r8991 | inactive. If -c/--closed is specified, also list branches which have | ||
|
r11193 | been marked closed (see :hg:`commit --close-branch`). | ||
|
r8991 | |||
If -a/--active is specified, only show active branches. A branch | ||||
is considered active if it contains repository heads. | ||||
|
r5999 | |||
|
r10973 | Use the command :hg:`update` to switch to an existing branch. | ||
|
r11177 | |||
Returns 0. | ||||
|
r3502 | """ | ||
|
r8991 | |||
|
r6631 | hexfunc = ui.debugflag and hex or short | ||
|
r16721 | |||
|
r20182 | allheads = set(repo.heads()) | ||
|
r16721 | branches = [] | ||
|
r20192 | for tag, heads, tip, isclosed in repo.branchmap().iterbranches(): | ||
isactive = not isclosed and bool(set(heads) & allheads) | ||||
branches.append((tag, repo[tip], isactive, not isclosed)) | ||||
|
r20182 | branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]), | ||
|
r16721 | reverse=True) | ||
|
r20182 | for tag, ctx, isactive, isopen in branches: | ||
|
r6631 | if (not active) or isactive: | ||
|
r16612 | if isactive: | ||
label = 'branches.active' | ||||
notice = '' | ||||
|
r16721 | elif not isopen: | ||
|
r16612 | if not closed: | ||
continue | ||||
label = 'branches.closed' | ||||
notice = _(' (closed)') | ||||
else: | ||||
label = 'branches.inactive' | ||||
notice = _(' (inactive)') | ||||
|
r20182 | if tag == repo.dirstate.branch(): | ||
|
r16612 | label = 'branches.current' | ||
|
r20182 | rev = str(ctx.rev()).rjust(31 - encoding.colwidth(tag)) | ||
|
r16721 | rev = ui.label('%s:%s' % (rev, hexfunc(ctx.node())), | ||
|
r17788 | 'log.changeset changeset.%s' % ctx.phasestr()) | ||
|
r20182 | labeledtag = ui.label(tag, label) | ||
|
r4675 | if ui.quiet: | ||
|
r20182 | ui.write("%s\n" % labeledtag) | ||
|
r4675 | else: | ||
|
r20182 | ui.write("%s %s%s\n" % (labeledtag, rev, notice)) | ||
|
r3502 | |||
|
r14297 | @command('bundle', | ||
[('f', 'force', None, _('run even when the destination is unrelated')), | ||||
('r', 'rev', [], _('a changeset intended to be added to the destination'), | ||||
_('REV')), | ||||
('b', 'branch', [], _('a specific branch you would like to bundle'), | ||||
_('BRANCH')), | ||||
('', 'base', [], | ||||
_('a base changeset assumed to be available at the destination'), | ||||
_('REV')), | ||||
('a', 'all', None, _('bundle all changesets in the repository')), | ||||
('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE')), | ||||
] + remoteopts, | ||||
_('[-f] [-t TYPE] [-a] [-r REV]... [--base REV]... FILE [DEST]')) | ||||
|
r2494 | def bundle(ui, repo, fname, dest=None, **opts): | ||
|
r1437 | """create a changegroup file | ||
|
r3511 | Generate a compressed changegroup file collecting changesets not | ||
|
r7807 | known to be in another repository. | ||
|
r3511 | |||
|
r10376 | If you omit the destination repository, then hg assumes the | ||
destination will have all the nodes you specify with --base | ||||
|
r6448 | parameters. To create a bundle containing all changesets, use | ||
|
r8903 | -a/--all (or --base null). | ||
|
r8958 | You can change compression method with the -t/--type option. | ||
The available compression methods are: none, bzip2, and | ||||
|
r8903 | gzip (by default, bundles are compressed using bzip2). | ||
|
r3511 | |||
|
r8004 | The bundle file can then be transferred using conventional means | ||
and applied to another repository with the unbundle or pull | ||||
command. This is useful when direct push and pull are not | ||||
available or when exporting an entire repository is undesirable. | ||||
|
r3511 | |||
Applying bundles preserves all changeset contents including | ||||
permissions, copy/rename information, and revision history. | ||||
|
r11177 | |||
Returns 0 on success, 1 if no changes found. | ||||
|
r1437 | """ | ||
|
r12925 | revs = None | ||
if 'rev' in opts: | ||||
|
r14319 | revs = scmutil.revrange(repo, opts['rev']) | ||
|
r12925 | |||
|
r16427 | bundletype = opts.get('type', 'bzip2').lower() | ||
btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'} | ||||
bundletype = btypes.get(bundletype) | ||||
if bundletype not in changegroup.bundletypes: | ||||
raise util.Abort(_('unknown bundle type specified with --type')) | ||||
|
r6171 | if opts.get('all'): | ||
base = ['null'] | ||||
else: | ||||
|
r14319 | base = scmutil.revrange(repo, opts.get('base')) | ||
|
r19201 | # TODO: get desired bundlecaps from command line. | ||
bundlecaps = None | ||||
|
r3284 | if base: | ||
if dest: | ||||
|
r8669 | raise util.Abort(_("--base is incompatible with specifying " | ||
|
r3284 | "a destination")) | ||
|
r14073 | common = [repo.lookup(rev) for rev in base] | ||
|
r15837 | heads = revs and map(repo.lookup, revs) or revs | ||
|
r20930 | cg = changegroup.getbundle(repo, 'bundle', heads=heads, common=common, | ||
bundlecaps=bundlecaps) | ||||
|
r15993 | outgoing = None | ||
|
r3284 | else: | ||
|
r10365 | dest = ui.expandpath(dest or 'default-push', dest or 'default') | ||
|
r10379 | dest, branches = hg.parseurl(dest, opts.get('branch')) | ||
|
r14556 | other = hg.peer(repo, opts, dest) | ||
|
r18701 | revs, checkout = hg.addbranchrevs(repo, repo, branches, revs) | ||
|
r14213 | heads = revs and map(repo.lookup, revs) or revs | ||
|
r15837 | outgoing = discovery.findcommonoutgoing(repo, other, | ||
onlyheads=heads, | ||||
|
r16736 | force=opts.get('force'), | ||
portable=True) | ||||
|
r20928 | cg = changegroup.getlocalbundle(repo, 'bundle', outgoing, bundlecaps) | ||
|
r14073 | if not cg: | ||
|
r17248 | scmutil.nochangesfound(ui, repo, outgoing and outgoing.excluded) | ||
|
r11177 | return 1 | ||
|
r10616 | |||
|
r6570 | changegroup.writebundle(cg, fname, bundletype) | ||
|
r1218 | |||
|
r14297 | @command('cat', | ||
[('o', 'output', '', | ||||
_('print output to file with formatted name'), _('FORMAT')), | ||||
('r', 'rev', '', _('print the given revision'), _('REV')), | ||||
('', 'decode', None, _('apply any matching decode filter')), | ||||
] + walkopts, | ||||
|
r21778 | _('[OPTION]... FILE...'), | ||
inferrepo=True) | ||||
|
r1254 | def cat(ui, repo, file1, *pats, **opts): | ||
|
r3914 | """output the current or given revision of files | ||
|
r1437 | |||
|
r8004 | Print the specified files as they were at the given revision. If | ||
|
r19400 | no revision is given, the parent of the working directory is used. | ||
|
r1437 | |||
Output may be to a file, in which case the name of the file is | ||||
|
r21078 | given using a format string. The formatting rules as follows: | ||
:``%%``: literal "%" character | ||||
|
r9892 | :``%s``: basename of file being printed | ||
:``%d``: dirname of file being printed, or '.' if in repository root | ||||
:``%p``: root-relative path name of file being printed | ||||
|
r21078 | :``%H``: changeset hash (40 hexadecimal digits) | ||
:``%R``: changeset revision number | ||||
:``%h``: short-form changeset hash (12 hexadecimal digits) | ||||
:``%r``: zero-padded changeset revision number | ||||
:``%b``: basename of the exporting repository | ||||
|
r11177 | |||
Returns 0 on success. | ||||
|
r1437 | """ | ||
|
r14319 | ctx = scmutil.revsingle(repo, opts.get('rev')) | ||
|
r14671 | m = scmutil.match(ctx, (file1,) + pats, opts) | ||
|
r20293 | |||
|
r21041 | return cmdutil.cat(ui, repo, ctx, m, '', **opts) | ||
|
r248 | |||
|
r14297 | @command('^clone', | ||
[('U', 'noupdate', None, | ||||
_('the clone will include an empty working copy (only a repository)')), | ||||
('u', 'updaterev', '', _('revision, tag or branch to check out'), _('REV')), | ||||
('r', 'rev', [], _('include the specified changeset'), _('REV')), | ||||
('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')), | ||||
('', 'pull', None, _('use pull protocol to copy metadata')), | ||||
('', 'uncompressed', None, _('use uncompressed transfer (fast over LAN)')), | ||||
] + remoteopts, | ||||
|
r21768 | _('[OPTION]... SOURCE [DEST]'), | ||
norepo=True) | ||||
|
r698 | def clone(ui, source, dest=None, **opts): | ||
|
r1437 | """make a copy of an existing repository | ||
Create a copy of an existing repository in a new directory. | ||||
If no destination directory name is specified, it defaults to the | ||||
basename of the source. | ||||
The location of the source is added to the new repository's | ||||
|
r13344 | ``.hg/hgrc`` file, as the default to be used for future pulls. | ||
|
r1437 | |||
|
r15177 | Only local paths and ``ssh://`` URLs are supported as | ||
destinations. For ``ssh://`` destinations, no working directory or | ||||
``.hg/hgrc`` will be created on the remote side. | ||||
|
r7942 | |||
|
r15174 | To pull only a subset of changesets, specify one or more revisions | ||
identifiers with -r/--rev or branches with -b/--branch. The | ||||
resulting clone will contain only the specified changesets and | ||||
their ancestors. These options (or 'clone src#rev dest') imply | ||||
--pull, even for local source repositories. Note that specifying a | ||||
tag will include the tagged changeset but not the changeset | ||||
containing the tag. | ||||
|
r9714 | |||
|
r18474 | If the source repository has a bookmark called '@' set, that | ||
revision will be checked out in the new repository by default. | ||||
|
r15178 | To check out a particular version, use -u/--update, or | ||
-U/--noupdate to create a clone with no working directory. | ||||
|
r15177 | .. container:: verbose | ||
For efficiency, hardlinks are used for cloning whenever the | ||||
source and destination are on the same filesystem (note this | ||||
applies only to the repository data, not to the working | ||||
directory). Some filesystems, such as AFS, implement hardlinking | ||||
incorrectly, but do not report errors. In these cases, use the | ||||
--pull option to avoid hardlinking. | ||||
In some cases, you can clone repositories and the working | ||||
directory using full hardlinks with :: | ||||
$ cp -al REPO REPOCLONE | ||||
This is the fastest way to clone, but it is not always safe. The | ||||
operation is not atomic (making sure REPO is not modified during | ||||
the operation is up to you) and you have to make sure your | ||||
editor breaks hardlinks (Emacs and most Linux Kernel tools do | ||||
so). Also, this is not compatible with certain extensions that | ||||
place their metadata under the .hg directory, such as mq. | ||||
Mercurial will update the working directory to the first applicable | ||||
revision from this list: | ||||
a) null if -U or the source repository has no changesets | ||||
b) if -u . and the source repository is local, the first parent of | ||||
the source repository's working directory | ||||
c) the changeset specified with -u (if a branch name, this means the | ||||
latest head of that branch) | ||||
d) the changeset specified with -r | ||||
e) the tipmost head specified with -b | ||||
f) the tipmost head specified with the url#branch source syntax | ||||
|
r18476 | g) the revision marked with the '@' bookmark, if present | ||
h) the tipmost head of the default branch | ||||
i) tip | ||||
|
r11177 | |||
|
r15179 | Examples: | ||
- clone a remote repository to a new directory named hg/:: | ||||
hg clone http://selenic.com/hg | ||||
- create a lightweight local clone:: | ||||
hg clone project/ project-feature/ | ||||
- clone from an absolute path on an ssh server (note double-slash):: | ||||
hg clone ssh://user@server//home/projects/alpha/ | ||||
- do a high-speed clone over a LAN while checking out a | ||||
specified version:: | ||||
hg clone --uncompressed http://server/repo -u 1.5 | ||||
- create a repository without changesets after a particular revision:: | ||||
hg clone -r 04e544 experimental/ good/ | ||||
- clone (and track) a particular named branch:: | ||||
hg clone http://selenic.com/hg#stable | ||||
|
r15175 | See :hg:`help urls` for details on specifying URLs. | ||
|
r11177 | Returns 0 on success. | ||
|
r1437 | """ | ||
|
r9714 | if opts.get('noupdate') and opts.get('updaterev'): | ||
raise util.Abort(_("cannot specify both --noupdate and --updaterev")) | ||||
|
r14553 | r = hg.clone(ui, opts, source, dest, | ||
|
r11177 | pull=opts.get('pull'), | ||
stream=opts.get('uncompressed'), | ||||
rev=opts.get('rev'), | ||||
update=opts.get('updaterev') or not opts.get('noupdate'), | ||||
branch=opts.get('branch')) | ||||
return r is None | ||||
|
r515 | |||
|
r14297 | @command('^commit|ci', | ||
[('A', 'addremove', None, | ||||
_('mark new/missing files as added/removed before committing')), | ||||
('', 'close-branch', None, | ||||
_('mark a branch as closed, hiding it from the branch list')), | ||||
|
r16458 | ('', 'amend', None, _('amend the parent of the working dir')), | ||
|
r19440 | ('s', 'secret', None, _('use the secret phase for committing')), | ||
|
r21952 | ('e', 'edit', None, _('invoke editor on commit messages')), | ||
|
r15321 | ] + walkopts + commitopts + commitopts2 + subrepoopts, | ||
|
r21778 | _('[OPTION]... [FILE]...'), | ||
inferrepo=True) | ||||
|
r813 | def commit(ui, repo, *pats, **opts): | ||
|
r1437 | """commit the specified files or all outstanding changes | ||
|
r7983 | Commit changes to the given files into the repository. Unlike a | ||
|
r13303 | centralized SCM, this operation is a local operation. See | ||
|
r11193 | :hg:`push` for a way to actively distribute your changes. | ||
|
r1437 | |||
|
r10973 | If a list of files is omitted, all changes reported by :hg:`status` | ||
|
r1995 | will be committed. | ||
|
r1437 | |||
|
r6385 | If you are committing the result of a merge, do not provide any | ||
|
r8761 | filenames or -I/-X filters. | ||
|
r6385 | |||
|
r11877 | If no commit message is specified, Mercurial starts your | ||
configured editor where you can enter a message. In case your | ||||
commit fails, you will find a backup of your message in | ||||
``.hg/last-message.txt``. | ||||
|
r6163 | |||
|
r16458 | The --amend flag can be used to amend the parent of the | ||
working directory with a new commit that contains the changes | ||||
in the parent in addition to those currently reported by :hg:`status`, | ||||
if there are any. The old commit is stored in a backup bundle in | ||||
``.hg/strip-backup`` (see :hg:`help bundle` and :hg:`help unbundle` | ||||
on how to restore it). | ||||
Message, user and date are taken from the amended commit unless | ||||
specified. When a message isn't specified on the command line, | ||||
the editor will open with the message of the amended commit. | ||||
It is not possible to amend public changesets (see :hg:`help phases`) | ||||
or changesets that have children. | ||||
|
r10973 | See :hg:`help dates` for a list of formats valid for -d/--date. | ||
|
r11177 | |||
Returns 0 on success, 1 if nothing changed. | ||||
|
r1437 | """ | ||
|
r15321 | if opts.get('subrepos'): | ||
|
r19232 | if opts.get('amend'): | ||
raise util.Abort(_('cannot amend with --subrepos')) | ||||
|
r17504 | # Let --subrepos on the command line override config setting. | ||
|
r20790 | ui.setconfig('ui', 'commitsubrepos', True, 'commit') | ||
|
r15321 | |||
|
r19496 | cmdutil.checkunfinished(repo, commit=True) | ||
|
r19253 | |||
|
r19305 | branch = repo[None].branch() | ||
bheads = repo.branchheads(branch) | ||||
|
r7655 | extra = {} | ||
if opts.get('close_branch'): | ||||
extra['close'] = 1 | ||||
|
r6336 | |||
|
r19305 | if not bheads: | ||
raise util.Abort(_('can only close branch heads')) | ||||
elif opts.get('amend'): | ||||
if repo.parents()[0].p1().branch() != branch and \ | ||||
repo.parents()[0].p2().branch() != branch: | ||||
raise util.Abort(_('can only close branch heads')) | ||||
|
r11173 | |||
|
r16458 | if opts.get('amend'): | ||
|
r16505 | if ui.configbool('ui', 'commitsubrepos'): | ||
|
r19232 | raise util.Abort(_('cannot amend with ui.commitsubrepos enabled')) | ||
|
r16458 | |||
old = repo['.'] | ||||
if old.phase() == phases.public: | ||||
raise util.Abort(_('cannot amend public changesets')) | ||||
if len(repo[None].parents()) > 1: | ||||
raise util.Abort(_('cannot amend while merging')) | ||||
|
r18163 | if (not obsolete._enabled) and old.children(): | ||
|
r16458 | raise util.Abort(_('cannot amend changeset with children')) | ||
|
r20700 | # commitfunc is used only for temporary amend commit by cmdutil.amend | ||
|
r16458 | def commitfunc(ui, repo, message, match, opts): | ||
|
r20700 | return repo.commit(message, | ||
opts.get('user') or old.user(), | ||||
opts.get('date') or old.date(), | ||||
match, | ||||
extra=extra) | ||||
|
r16458 | |||
|
r17264 | current = repo._bookmarkcurrent | ||
marks = old.bookmarks() | ||||
|
r16458 | node = cmdutil.amend(ui, repo, commitfunc, old, extra, pats, opts) | ||
if node == old.node(): | ||||
|
r13899 | ui.status(_("nothing changed\n")) | ||
|
r16458 | return 1 | ||
|
r17264 | elif marks: | ||
ui.debug('moving bookmarks %r from %s to %s\n' % | ||||
(marks, old.hex(), hex(node))) | ||||
|
r17922 | newmarks = repo._bookmarks | ||
|
r17264 | for bm in marks: | ||
|
r17922 | newmarks[bm] = node | ||
|
r17264 | if bm == current: | ||
bookmarks.setcurrent(repo, bm) | ||||
|
r17922 | newmarks.write() | ||
|
r16458 | else: | ||
def commitfunc(ui, repo, message, match, opts): | ||||
|
r22039 | backup = ui.backupconfig('phases', 'new-commit') | ||
baseui = repo.baseui | ||||
basebackup = baseui.backupconfig('phases', 'new-commit') | ||||
|
r19440 | try: | ||
if opts.get('secret'): | ||||
|
r20790 | ui.setconfig('phases', 'new-commit', 'secret', 'commit') | ||
|
r20772 | # Propagate to subrepos | ||
|
r22039 | baseui.setconfig('phases', 'new-commit', 'secret', 'commit') | ||
|
r19440 | |||
|
r22010 | editform = 'commit.normal' | ||
editor = cmdutil.getcommiteditor(editform=editform, **opts) | ||||
|
r19440 | return repo.commit(message, opts.get('user'), opts.get('date'), | ||
|
r21414 | match, | ||
|
r22010 | editor=editor, | ||
|
r21414 | extra=extra) | ||
|
r19440 | finally: | ||
|
r22039 | ui.restoreconfig(backup) | ||
repo.baseui.restoreconfig(basebackup) | ||||
|
r19440 | |||
|
r16458 | |||
node = cmdutil.commit(ui, repo, commitfunc, pats, opts) | ||||
if not node: | ||||
stat = repo.status(match=scmutil.match(repo[None], pats, opts)) | ||||
if stat[3]: | ||||
ui.status(_("nothing changed (%d missing files, see " | ||||
"'hg status')\n") % len(stat[3])) | ||||
else: | ||||
ui.status(_("nothing changed\n")) | ||||
return 1 | ||||
|
r11173 | |||
|
r18688 | cmdutil.commitstatus(repo, node, branch, bheads, opts) | ||
|
r6935 | |||
|
r20570 | @command('config|showconfig|debugconfig', | ||
|
r20572 | [('u', 'untrusted', None, _('show untrusted configuration options')), | ||
|
r20782 | ('e', 'edit', None, _('edit user config')), | ||
('l', 'local', None, _('edit repository config')), | ||||
('g', 'global', None, _('edit global config'))], | ||||
|
r21775 | _('[-u] [NAME]...'), | ||
optionalrepo=True) | ||||
|
r20570 | def config(ui, repo, *values, **opts): | ||
"""show combined config settings from all hgrc files | ||||
With no arguments, print names and values of all config items. | ||||
With one argument of the form section.name, print just the value | ||||
of that config item. | ||||
With multiple arguments, print names and values of all config | ||||
items with matching section names. | ||||
|
r20783 | With --edit, start an editor on the user-level config file. With | ||
--global, edit the system-wide config file. With --local, edit the | ||||
repository-level config file. | ||||
|
r20570 | With --debug, the source (filename and line number) is printed | ||
for each config item. | ||||
|
r20783 | See :hg:`help config` for more information about config files. | ||
|
r20570 | Returns 0 on success. | ||
|
r20783 | |||
|
r20570 | """ | ||
|
r20782 | if opts.get('edit') or opts.get('local') or opts.get('global'): | ||
if opts.get('local') and opts.get('global'): | ||||
raise util.Abort(_("can't use --local and --global together")) | ||||
if opts.get('local'): | ||||
if not repo: | ||||
raise util.Abort(_("can't use --local outside a repository")) | ||||
paths = [repo.join('hgrc')] | ||||
elif opts.get('global'): | ||||
paths = scmutil.systemrcpath() | ||||
else: | ||||
paths = scmutil.userrcpath() | ||||
|
r20572 | for f in paths: | ||
if os.path.exists(f): | ||||
break | ||||
else: | ||||
f = paths[0] | ||||
|
r20573 | fp = open(f, "w") | ||
fp.write( | ||||
'# example config (see "hg help config" for more info)\n' | ||||
'\n' | ||||
'[ui]\n' | ||||
|
r20664 | '# name and email, e.g.\n' | ||
'# username = Jane Doe <jdoe@example.com>\n' | ||||
|
r20573 | 'username =\n' | ||
'\n' | ||||
'[extensions]\n' | ||||
'# uncomment these lines to enable some popular extensions\n' | ||||
'# (see "hg help extensions" for more info)\n' | ||||
'# pager =\n' | ||||
'# progress =\n' | ||||
'# color =\n') | ||||
fp.close() | ||||
|
r20572 | editor = ui.geteditor() | ||
util.system("%s \"%s\"" % (editor, f), | ||||
onerr=util.Abort, errprefix=_("edit failed"), | ||||
out=ui.fout) | ||||
return | ||||
|
r20570 | for f in scmutil.rcpath(): | ||
ui.debug('read config from: %s\n' % f) | ||||
untrusted = bool(opts.get('untrusted')) | ||||
if values: | ||||
sections = [v for v in values if '.' not in v] | ||||
items = [v for v in values if '.' in v] | ||||
if len(items) > 1 or items and sections: | ||||
raise util.Abort(_('only one config item permitted')) | ||||
for section, name, value in ui.walkconfig(untrusted=untrusted): | ||||
value = str(value).replace('\n', '\\n') | ||||
sectname = section + '.' + name | ||||
if values: | ||||
for v in values: | ||||
if v == section: | ||||
ui.debug('%s: ' % | ||||
ui.configsource(section, name, untrusted)) | ||||
ui.write('%s=%s\n' % (sectname, value)) | ||||
elif v == sectname: | ||||
ui.debug('%s: ' % | ||||
ui.configsource(section, name, untrusted)) | ||||
ui.write(value, '\n') | ||||
else: | ||||
ui.debug('%s: ' % | ||||
ui.configsource(section, name, untrusted)) | ||||
ui.write('%s=%s\n' % (sectname, value)) | ||||
|
r14297 | @command('copy|cp', | ||
[('A', 'after', None, _('record a copy that has already occurred')), | ||||
('f', 'force', None, _('forcibly copy over an existing managed file')), | ||||
] + walkopts + dryrunopts, | ||||
_('[OPTION]... [SOURCE]... DEST')) | ||||
|
r1253 | def copy(ui, repo, *pats, **opts): | ||
|
r1437 | """mark files as copied for the next commit | ||
|
r6448 | Mark dest as having copies of source files. If dest is a | ||
directory, copies are put in that directory. If dest is a file, | ||||
|
r7807 | the source must be a single file. | ||
|
r1437 | |||
By default, this command copies the contents of files as they | ||||
|
r8779 | exist in the working directory. If invoked with -A/--after, the | ||
|
r1437 | operation is recorded, but no copying is performed. | ||
|
r7807 | This command takes effect with the next commit. To undo a copy | ||
|
r11193 | before that, see :hg:`revert`. | ||
|
r11177 | |||
Returns 0 on success, 1 if errors are encountered. | ||||
|
r1437 | """ | ||
|
r4914 | wlock = repo.wlock(False) | ||
|
r4915 | try: | ||
|
r5610 | return cmdutil.copy(ui, repo, pats, opts) | ||
|
r4915 | finally: | ||
|
r8109 | wlock.release() | ||
|
r363 | |||
|
r21775 | @command('debugancestor', [], _('[INDEX] REV1 REV2'), optionalrepo=True) | ||
|
r6189 | def debugancestor(ui, repo, *args): | ||
|
r1262 | """find the ancestor revision of two revisions in a given index""" | ||
|
r6188 | if len(args) == 3: | ||
index, rev1, rev2 = args | ||||
|
r13970 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), index) | ||
|
r6253 | lookup = r.lookup | ||
|
r6188 | elif len(args) == 2: | ||
|
r6189 | if not repo: | ||
|
r12067 | raise util.Abort(_("there is no Mercurial repository here " | ||
|
r6189 | "(.hg not found)")) | ||
|
r6188 | rev1, rev2 = args | ||
|
r6178 | r = repo.changelog | ||
|
r6253 | lookup = repo.lookup | ||
|
r6178 | else: | ||
raise util.Abort(_('either two or three arguments required')) | ||||
|
r6253 | a = r.ancestor(lookup(rev1), lookup(rev2)) | ||
|
r1262 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) | ||
|
r14297 | @command('debugbuilddag', | ||
[('m', 'mergeable-file', None, _('add single file mergeable changes')), | ||||
('o', 'overwritten-file', None, _('add single file all revs overwrite')), | ||||
('n', 'new-file', None, _('add new file at each rev'))], | ||||
_('[OPTION]... [TEXT]')) | ||||
|
r14283 | def debugbuilddag(ui, repo, text=None, | ||
|
r11337 | mergeable_file=False, | ||
overwritten_file=False, | ||||
new_file=False): | ||||
|
r14283 | """builds a repo with a given DAG from scratch in the current empty repo | ||
The description of the DAG is read from stdin if not given on the | ||||
command line. | ||||
|
r11337 | |||
Elements: | ||||
- "+n" is a linear run of n nodes based on the current default parent | ||||
- "." is a single node based on the current default parent | ||||
- "$" resets the default parent to null (implied at the start); | ||||
otherwise the default parent is always the last node created | ||||
- "<p" sets the default parent to the backref p | ||||
- "*p" is a fork at parent p, which is a backref | ||||
- "*p1/p2" is a merge of parents p1 and p2, which are backrefs | ||||
- "/p2" is a merge of the preceding node and p2 | ||||
- ":tag" defines a local tag for the preceding node | ||||
- "@branch" sets the named branch for subsequent nodes | ||||
- "#...\\n" is a comment up to the end of the line | ||||
Whitespace between the above elements is ignored. | ||||
A backref is either | ||||
- a number n, which references the node curr-n, where curr is the current | ||||
node, or | ||||
- the name of a local tag you placed earlier using ":tag", or | ||||
- empty to denote the default parent. | ||||
All string valued-elements are either strictly alphanumeric, or must | ||||
|
r11881 | be enclosed in double quotes ("..."), with "\\" as escape character. | ||
|
r11337 | """ | ||
|
r14283 | if text is None: | ||
ui.status(_("reading DAG from stdin\n")) | ||||
|
r14639 | text = ui.fin.read() | ||
|
r14283 | |||
|
r14163 | cl = repo.changelog | ||
if len(cl) > 0: | ||||
|
r11342 | raise util.Abort(_('repository is not empty')) | ||
|
r11337 | |||
|
r14279 | # determine number of revs in DAG | ||
total = 0 | ||||
for type, data in dagparser.parsedag(text): | ||||
if type == 'n': | ||||
total += 1 | ||||
|
r11337 | |||
if mergeable_file: | ||||
linesperrev = 2 | ||||
# make a file with k lines per rev | ||||
|
r14279 | initialmergedlines = [str(i) for i in xrange(0, total * linesperrev)] | ||
|
r14163 | initialmergedlines.append("") | ||
tags = [] | ||||
|
r15875 | lock = tr = None | ||
|
r14163 | try: | ||
|
r15875 | lock = repo.lock() | ||
tr = repo.transaction("builddag") | ||||
|
r14163 | |||
at = -1 | ||||
atbranch = 'default' | ||||
nodeids = [] | ||||
|
r16219 | id = 0 | ||
ui.progress(_('building'), id, unit=_('revisions'), total=total) | ||||
|
r11337 | for type, data in dagparser.parsedag(text): | ||
if type == 'n': | ||||
|
r17956 | ui.note(('node %s\n' % str(data))) | ||
|
r14163 | id, ps = data | ||
files = [] | ||||
fctxs = {} | ||||
p2 = None | ||||
if mergeable_file: | ||||
fn = "mf" | ||||
p1 = repo[ps[0]] | ||||
if len(ps) > 1: | ||||
p2 = repo[ps[1]] | ||||
pa = p1.ancestor(p2) | ||||
|
r18181 | base, local, other = [x[fn].data() for x in (pa, p1, | ||
p2)] | ||||
|
r14163 | m3 = simplemerge.Merge3Text(base, local, other) | ||
ml = [l.strip() for l in m3.merge_lines()] | ||||
ml.append("") | ||||
elif at > 0: | ||||
ml = p1[fn].data().split("\n") | ||||
else: | ||||
ml = initialmergedlines | ||||
ml[id * linesperrev] += " r%i" % id | ||||
mergedtext = "\n".join(ml) | ||||
files.append(fn) | ||||
|
r21689 | fctxs[fn] = context.memfilectx(repo, fn, mergedtext) | ||
|
r14163 | |||
if overwritten_file: | ||||
fn = "of" | ||||
files.append(fn) | ||||
|
r21689 | fctxs[fn] = context.memfilectx(repo, fn, "r%i\n" % id) | ||
|
r14163 | |||
if new_file: | ||||
fn = "nf%i" % id | ||||
files.append(fn) | ||||
|
r21689 | fctxs[fn] = context.memfilectx(repo, fn, "r%i\n" % id) | ||
|
r14163 | if len(ps) > 1: | ||
if not p2: | ||||
p2 = repo[ps[1]] | ||||
for fn in p2: | ||||
if fn.startswith("nf"): | ||||
files.append(fn) | ||||
fctxs[fn] = p2[fn] | ||||
def fctxfn(repo, cx, path): | ||||
return fctxs.get(path) | ||||
if len(ps) == 0 or ps[0] < 0: | ||||
pars = [None, None] | ||||
elif len(ps) == 1: | ||||
pars = [nodeids[ps[0]], None] | ||||
else: | ||||
pars = [nodeids[p] for p in ps] | ||||
cx = context.memctx(repo, pars, "r%i" % id, files, fctxfn, | ||||
date=(id, 0), | ||||
user="debugbuilddag", | ||||
extra={'branch': atbranch}) | ||||
nodeid = repo.commitctx(cx) | ||||
nodeids.append(nodeid) | ||||
at = id | ||||
elif type == 'l': | ||||
id, name = data | ||||
|
r17956 | ui.note(('tag %s\n' % name)) | ||
|
r14163 | tags.append("%s %s\n" % (hex(repo.changelog.node(id)), name)) | ||
elif type == 'a': | ||||
|
r17956 | ui.note(('branch %s\n' % data)) | ||
|
r14163 | atbranch = data | ||
|
r14279 | ui.progress(_('building'), id, unit=_('revisions'), total=total) | ||
|
r14163 | tr.close() | ||
|
r15875 | |||
if tags: | ||||
repo.opener.write("localtags", "".join(tags)) | ||||
|
r14163 | finally: | ||
|
r14279 | ui.progress(_('building'), None) | ||
|
r15875 | release(tr, lock) | ||
|
r11337 | |||
|
r21768 | @command('debugbundle', | ||
[('a', 'all', None, _('show all details'))], | ||||
_('FILE'), | ||||
norepo=True) | ||||
|
r13724 | def debugbundle(ui, bundlepath, all=None, **opts): | ||
"""lists the contents of a bundle""" | ||||
|
r17887 | f = hg.openpath(ui, bundlepath) | ||
|
r4915 | try: | ||
|
r21064 | gen = exchange.readbundle(ui, f, bundlepath) | ||
|
r13747 | if all: | ||
|
r17956 | ui.write(("format: id, p1, p2, cset, delta base, len(delta)\n")) | ||
|
r13747 | |||
def showchunks(named): | ||||
ui.write("\n%s\n" % named) | ||||
|
r14141 | chain = None | ||
|
r14494 | while True: | ||
|
r14144 | chunkdata = gen.deltachunk(chain) | ||
|
r13724 | if not chunkdata: | ||
break | ||||
node = chunkdata['node'] | ||||
|
r13747 | p1 = chunkdata['p1'] | ||
p2 = chunkdata['p2'] | ||||
cs = chunkdata['cs'] | ||||
|
r14141 | deltabase = chunkdata['deltabase'] | ||
delta = chunkdata['delta'] | ||||
ui.write("%s %s %s %s %s %s\n" % | ||||
|
r13747 | (hex(node), hex(p1), hex(p2), | ||
|
r14141 | hex(cs), hex(deltabase), len(delta))) | ||
chain = node | ||||
|
r13747 | |||
|
r14144 | chunkdata = gen.changelogheader() | ||
|
r13747 | showchunks("changelog") | ||
|
r14144 | chunkdata = gen.manifestheader() | ||
|
r13747 | showchunks("manifest") | ||
|
r14494 | while True: | ||
|
r14144 | chunkdata = gen.filelogheader() | ||
if not chunkdata: | ||||
|
r13747 | break | ||
|
r14144 | fname = chunkdata['filename'] | ||
|
r13747 | showchunks(fname) | ||
else: | ||||
|
r14144 | chunkdata = gen.changelogheader() | ||
|
r14141 | chain = None | ||
|
r14494 | while True: | ||
|
r14144 | chunkdata = gen.deltachunk(chain) | ||
|
r13747 | if not chunkdata: | ||
break | ||||
node = chunkdata['node'] | ||||
ui.write("%s\n" % hex(node)) | ||||
|
r14141 | chain = node | ||
|
r4915 | finally: | ||
|
r13724 | f.close() | ||
|
r14302 | @command('debugcheckstate', [], '') | ||
|
r596 | def debugcheckstate(ui, repo): | ||
"""validate the correctness of the current dirstate""" | ||||
|
r460 | parent1, parent2 = repo.dirstate.parents() | ||
|
r6747 | m1 = repo[parent1].manifest() | ||
m2 = repo[parent2].manifest() | ||||
|
r460 | errors = 0 | ||
|
r4906 | for f in repo.dirstate: | ||
state = repo.dirstate[f] | ||||
|
r460 | if state in "nr" and f not in m1: | ||
|
r1402 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) | ||
|
r460 | errors += 1 | ||
if state in "a" and f in m1: | ||||
|
r1402 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) | ||
|
r460 | errors += 1 | ||
if state in "m" and f not in m1 and f not in m2: | ||||
|
r1402 | ui.warn(_("%s in state %s, but not in either manifest\n") % | ||
|
r582 | (f, state)) | ||
|
r460 | errors += 1 | ||
for f in m1: | ||||
|
r4906 | state = repo.dirstate[f] | ||
|
r460 | if state not in "nrm": | ||
|
r1402 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) | ||
|
r460 | errors += 1 | ||
if errors: | ||||
|
r1602 | error = _(".hg/dirstate inconsistent with current parent's manifest") | ||
raise util.Abort(error) | ||||
|
r460 | |||
|
r21768 | @command('debugcommands', [], _('[COMMAND]'), norepo=True) | ||
|
r14302 | def debugcommands(ui, cmd='', *args): | ||
"""list all available commands and options""" | ||||
for cmd, vals in sorted(table.iteritems()): | ||||
cmd = cmd.split('|')[0].strip('^') | ||||
opts = ', '.join([i[1] for i in vals[1]]) | ||||
ui.write('%s: %s\n' % (cmd, opts)) | ||||
@command('debugcomplete', | ||||
[('o', 'options', None, _('show the command options'))], | ||||
|
r21768 | _('[-o] CMD'), | ||
norepo=True) | ||||
|
r14302 | def debugcomplete(ui, cmd='', **opts): | ||
"""returns the completion list associated with the given command""" | ||||
if opts.get('options'): | ||||
options = [] | ||||
otables = [globalopts] | ||||
if cmd: | ||||
aliases, entry = cmdutil.findcmd(cmd, table, False) | ||||
otables.append(entry[1]) | ||||
for t in otables: | ||||
for o in t: | ||||
if "(DEPRECATED)" in o[3]: | ||||
continue | ||||
if o[0]: | ||||
options.append('-%s' % o[0]) | ||||
options.append('--%s' % o[1]) | ||||
ui.write("%s\n" % "\n".join(options)) | ||||
return | ||||
cmdlist = cmdutil.findpossible(cmd, table) | ||||
|
r11276 | if ui.verbose: | ||
|
r14302 | cmdlist = [' '.join(c[0]) for c in cmdlist.values()] | ||
ui.write("%s\n" % "\n".join(sorted(cmdlist))) | ||||
|
r8812 | |||
|
r14297 | @command('debugdag', | ||
[('t', 'tags', None, _('use tags as labels')), | ||||
('b', 'branches', None, _('annotate with branch names')), | ||||
('', 'dots', None, _('use dots for runs')), | ||||
('s', 'spaces', None, _('separate elements by spaces'))], | ||||
|
r21775 | _('[OPTION]... [FILE [REV]...]'), | ||
optionalrepo=True) | ||||
|
r11336 | def debugdag(ui, repo, file_=None, *revs, **opts): | ||
"""format the changelog or an index DAG as a concise textual description | ||||
If you pass a revlog index, the revlog's DAG is emitted. If you list | ||||
|
r17500 | revision numbers, they get labeled in the output as rN. | ||
|
r11336 | |||
Otherwise, the changelog DAG of the current repo is emitted. | ||||
""" | ||||
spaces = opts.get('spaces') | ||||
dots = opts.get('dots') | ||||
if file_: | ||||
|
r13970 | rlog = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) | ||
|
r11336 | revs = set((int(r) for r in revs)) | ||
def events(): | ||||
for r in rlog: | ||||
|
r16683 | yield 'n', (r, list(set(p for p in rlog.parentrevs(r) | ||
if p != -1))) | ||||
|
r11336 | if r in revs: | ||
yield 'l', (r, "r%i" % r) | ||||
elif repo: | ||||
cl = repo.changelog | ||||
tags = opts.get('tags') | ||||
branches = opts.get('branches') | ||||
if tags: | ||||
labels = {} | ||||
for l, n in repo.tags().items(): | ||||
labels.setdefault(cl.rev(n), []).append(l) | ||||
def events(): | ||||
b = "default" | ||||
for r in cl: | ||||
if branches: | ||||
newb = cl.read(cl.node(r))[5]['branch'] | ||||
if newb != b: | ||||
yield 'a', newb | ||||
b = newb | ||||
|
r16683 | yield 'n', (r, list(set(p for p in cl.parentrevs(r) | ||
if p != -1))) | ||||
|
r11336 | if tags: | ||
ls = labels.get(r) | ||||
if ls: | ||||
for l in ls: | ||||
yield 'l', (r, l) | ||||
else: | ||||
raise util.Abort(_('need repo for changelog dag')) | ||||
for line in dagparser.dagtextlines(events(), | ||||
addspaces=spaces, | ||||
wraplabels=True, | ||||
wrapannotations=True, | ||||
wrapnonlinear=dots, | ||||
usedots=dots, | ||||
maxlinewidth=70): | ||||
ui.write(line) | ||||
ui.write("\n") | ||||
|
r14323 | @command('debugdata', | ||
[('c', 'changelog', False, _('open changelog')), | ||||
('m', 'manifest', False, _('open manifest'))], | ||||
_('-c|-m|FILE REV')) | ||||
|
r19872 | def debugdata(ui, repo, file_, rev=None, **opts): | ||
|
r4258 | """dump the contents of a data file revision""" | ||
|
r14323 | if opts.get('changelog') or opts.get('manifest'): | ||
file_, rev = None, file_ | ||||
elif rev is None: | ||||
raise error.CommandError('debugdata', _('invalid arguments')) | ||||
r = cmdutil.openrevlog(repo, 'debugdata', file_, opts) | ||||
|
r1313 | try: | ||
ui.write(r.revision(r.lookup(rev))) | ||||
except KeyError: | ||||
|
r3072 | raise util.Abort(_('invalid revision identifier %s') % rev) | ||
|
r1039 | |||
|
r14297 | @command('debugdate', | ||
[('e', 'extended', None, _('try extended date formats'))], | ||||
|
r21768 | _('[-e] DATE [RANGE]'), | ||
|
r21775 | norepo=True, optionalrepo=True) | ||
|
r3812 | def debugdate(ui, date, range=None, **opts): | ||
|
r3805 | """parse and display a date""" | ||
|
r3812 | if opts["extended"]: | ||
d = util.parsedate(date, util.extendeddateformats) | ||||
else: | ||||
d = util.parsedate(date) | ||||
|
r17956 | ui.write(("internal: %s %s\n") % d) | ||
ui.write(("standard: %s\n") % util.datestr(d)) | ||||
|
r3812 | if range: | ||
m = util.matchdate(range) | ||||
|
r17956 | ui.write(("match: %s\n") % m(d[0])) | ||
|
r3805 | |||
|
r14297 | @command('debugdiscovery', | ||
[('', 'old', None, _('use old-style discovery')), | ||||
('', 'nonheads', None, | ||||
_('use old-style discovery with non-heads included')), | ||||
] + remoteopts, | ||||
_('[-l REV] [-r REV] [-b BRANCH]... [OTHER]')) | ||||
|
r14164 | def debugdiscovery(ui, repo, remoteurl="default", **opts): | ||
"""runs the changeset discovery protocol in isolation""" | ||||
|
r16683 | remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl), | ||
opts.get('branch')) | ||||
|
r14556 | remote = hg.peer(repo, opts, remoteurl) | ||
|
r14164 | ui.status(_('comparing with %s\n') % util.hidepassword(remoteurl)) | ||
# make sure tests are repeatable | ||||
random.seed(12323) | ||||
|
r17191 | def doit(localheads, remoteheads, remote=remote): | ||
|
r14164 | if opts.get('old'): | ||
if localheads: | ||||
|
r16683 | raise util.Abort('cannot use localheads with old style ' | ||
'discovery') | ||||
|
r17192 | if not util.safehasattr(remote, 'branches'): | ||
# enable in-client legacy support | ||||
remote = localrepo.locallegacypeer(remote.local()) | ||||
|
r14164 | common, _in, hds = treediscovery.findcommonincoming(repo, remote, | ||
force=True) | ||||
common = set(common) | ||||
if not opts.get('nonheads'): | ||||
|
r18254 | ui.write(("unpruned common: %s\n") % | ||
" ".join(sorted(short(n) for n in common))) | ||||
|
r14164 | dag = dagutil.revlogdag(repo.changelog) | ||
all = dag.ancestorset(dag.internalizeall(common)) | ||||
common = dag.externalizeall(dag.headsetofconnecteds(all)) | ||||
else: | ||||
common, any, hds = setdiscovery.findcommonheads(ui, repo, remote) | ||||
common = set(common) | ||||
rheads = set(hds) | ||||
lheads = set(repo.heads()) | ||||
|
r18254 | ui.write(("common heads: %s\n") % | ||
" ".join(sorted(short(n) for n in common))) | ||||
|
r14164 | if lheads <= common: | ||
|
r17956 | ui.write(("local is subset\n")) | ||
|
r14164 | elif rheads <= common: | ||
|
r17956 | ui.write(("remote is subset\n")) | ||
|
r14164 | |||
serverlogs = opts.get('serverlog') | ||||
if serverlogs: | ||||
for filename in serverlogs: | ||||
logfile = open(filename, 'r') | ||||
try: | ||||
line = logfile.readline() | ||||
while line: | ||||
parts = line.strip().split(';') | ||||
op = parts[1] | ||||
if op == 'cg': | ||||
pass | ||||
elif op == 'cgss': | ||||
doit(parts[2].split(' '), parts[3].split(' ')) | ||||
elif op == 'unb': | ||||
doit(parts[3].split(' '), parts[2].split(' ')) | ||||
line = logfile.readline() | ||||
finally: | ||||
logfile.close() | ||||
else: | ||||
remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches, | ||||
opts.get('remote_head')) | ||||
localrevs = opts.get('local_head') | ||||
doit(localrevs, remoterevs) | ||||
|
r17370 | @command('debugfileset', | ||
[('r', 'rev', '', _('apply the filespec on this revision'), _('REV'))], | ||||
_('[-r REV] FILESPEC')) | ||||
def debugfileset(ui, repo, expr, **opts): | ||||
|
r14511 | '''parse and apply a fileset specification''' | ||
|
r17370 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) | ||
|
r14511 | if ui.verbose: | ||
tree = fileset.parse(expr)[0] | ||||
ui.note(tree, "\n") | ||||
|
r14673 | |||
|
r20404 | for f in ctx.getfileset(expr): | ||
|
r14551 | ui.write("%s\n" % f) | ||
|
r14511 | |||
|
r21768 | @command('debugfsinfo', [], _('[PATH]'), norepo=True) | ||
|
r19872 | def debugfsinfo(ui, path="."): | ||
|
r14302 | """show information detected about current filesystem""" | ||
util.writefile('.debugfsinfo', '') | ||||
|
r17956 | ui.write(('exec: %s\n') % (util.checkexec(path) and 'yes' or 'no')) | ||
ui.write(('symlink: %s\n') % (util.checklink(path) and 'yes' or 'no')) | ||||
|
r19616 | ui.write(('hardlink: %s\n') % (util.checknlink(path) and 'yes' or 'no')) | ||
|
r17956 | ui.write(('case-sensitive: %s\n') % (util.checkcase('.debugfsinfo') | ||
|
r14302 | and 'yes' or 'no')) | ||
os.unlink('.debugfsinfo') | ||||
@command('debuggetbundle', | ||||
[('H', 'head', [], _('id of head node'), _('ID')), | ||||
('C', 'common', [], _('id of common node'), _('ID')), | ||||
('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE'))], | ||||
|
r21768 | _('REPO FILE [-H|-C ID]...'), | ||
norepo=True) | ||||
|
r14302 | def debuggetbundle(ui, repopath, bundlepath, head=None, common=None, **opts): | ||
"""retrieves a bundle from a repo | ||||
Every ID must be a full-length hex node id string. Saves the bundle to the | ||||
given file. | ||||
""" | ||||
|
r14556 | repo = hg.peer(ui, opts, repopath) | ||
|
r14302 | if not repo.capable('getbundle'): | ||
raise util.Abort("getbundle() not supported by target repository") | ||||
args = {} | ||||
if common: | ||||
args['common'] = [bin(s) for s in common] | ||||
if head: | ||||
args['heads'] = [bin(s) for s in head] | ||||
|
r19201 | # TODO: get desired bundlecaps from command line. | ||
args['bundlecaps'] = None | ||||
|
r14302 | bundle = repo.getbundle('debug', **args) | ||
bundletype = opts.get('type', 'bzip2').lower() | ||||
btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'} | ||||
bundletype = btypes.get(bundletype) | ||||
if bundletype not in changegroup.bundletypes: | ||||
raise util.Abort(_('unknown bundle type specified with --type')) | ||||
changegroup.writebundle(bundle, bundlepath, bundletype) | ||||
@command('debugignore', [], '') | ||||
|
r13396 | def debugignore(ui, repo, *values, **opts): | ||
"""display the combined ignore pattern""" | ||||
ignore = repo.dirstate._ignore | ||||
|
r14949 | includepat = getattr(ignore, 'includepat', None) | ||
if includepat is not None: | ||||
ui.write("%s\n" % includepat) | ||||
|
r13406 | else: | ||
raise util.Abort(_("no ignore patterns found")) | ||||
|
r13396 | |||
|
r14297 | @command('debugindex', | ||
|
r14323 | [('c', 'changelog', False, _('open changelog')), | ||
('m', 'manifest', False, _('open manifest')), | ||||
('f', 'format', 0, _('revlog format'), _('FORMAT'))], | ||||
|
r21775 | _('[-f FORMAT] -c|-m|FILE'), | ||
optionalrepo=True) | ||||
|
r19872 | def debugindex(ui, repo, file_=None, **opts): | ||
|
r596 | """dump the contents of an index file""" | ||
|
r14323 | r = cmdutil.openrevlog(repo, 'debugindex', file_, opts) | ||
|
r12893 | format = opts.get('format', 0) | ||
if format not in (0, 1): | ||||
|
r13470 | raise util.Abort(_("unknown format %d") % format) | ||
|
r12893 | |||
|
r14254 | generaldelta = r.version & revlog.REVLOGGENERALDELTA | ||
if generaldelta: | ||||
basehdr = ' delta' | ||||
else: | ||||
basehdr = ' base' | ||||
|
r12893 | |||
if format == 0: | ||||
|
r14254 | ui.write(" rev offset length " + basehdr + " linkrev" | ||
|
r12893 | " nodeid p1 p2\n") | ||
elif format == 1: | ||||
ui.write(" rev flag offset length" | ||||
|
r16683 | " size " + basehdr + " link p1 p2" | ||
" nodeid\n") | ||||
|
r12893 | |||
|
r6750 | for i in r: | ||
|
r2072 | node = r.node(i) | ||
|
r14254 | if generaldelta: | ||
base = r.deltaparent(i) | ||||
else: | ||||
base = r.chainbase(i) | ||||
|
r12893 | if format == 0: | ||
try: | ||||
pp = r.parents(node) | ||||
|
r16689 | except Exception: | ||
|
r12893 | pp = [nullid, nullid] | ||
ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( | ||||
|
r14254 | i, r.start(i), r.length(i), base, r.linkrev(i), | ||
|
r12893 | short(node), short(pp[0]), short(pp[1]))) | ||
elif format == 1: | ||||
pr = r.parentrevs(i) | ||||
ui.write("% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d % 6d %s\n" % ( | ||||
i, r.flags(i), r.start(i), r.length(i), r.rawsize(i), | ||||
|
r14254 | base, r.linkrev(i), pr[0], pr[1], short(node))) | ||
|
r248 | |||
|
r21775 | @command('debugindexdot', [], _('FILE'), optionalrepo=True) | ||
|
r12132 | def debugindexdot(ui, repo, file_): | ||
|
r8779 | """dump an index DAG as a graphviz dot file""" | ||
|
r12132 | r = None | ||
if repo: | ||||
filelog = repo.file(file_) | ||||
if len(filelog): | ||||
r = filelog | ||||
if not r: | ||||
|
r13970 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) | ||
|
r17956 | ui.write(("digraph G {\n")) | ||
|
r6750 | for i in r: | ||
|
r2287 | node = r.node(i) | ||
pp = r.parents(node) | ||||
ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) | ||||
if pp[1] != nullid: | ||||
ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) | ||||
|
r582 | ui.write("}\n") | ||
|
r248 | |||
|
r21768 | @command('debuginstall', [], '', norepo=True) | ||
|
r3844 | def debuginstall(ui): | ||
|
r11177 | '''test Mercurial installation | ||
Returns 0 on success. | ||||
''' | ||||
|
r3844 | |||
|
r3846 | def writetemp(contents): | ||
|
r4849 | (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-") | ||
|
r3846 | f = os.fdopen(fd, "wb") | ||
f.write(contents) | ||||
f.close() | ||||
return name | ||||
|
r3844 | problems = 0 | ||
# encoding | ||||
|
r16934 | ui.status(_("checking encoding (%s)...\n") % encoding.encoding) | ||
|
r3844 | try: | ||
|
r7948 | encoding.fromlocal("test") | ||
|
r3844 | except util.Abort, inst: | ||
ui.write(" %s\n" % inst) | ||||
|
r3848 | ui.write(_(" (check that your locale is properly set)\n")) | ||
|
r3844 | problems += 1 | ||
|
r20740 | # Python | ||
|
r20741 | ui.status(_("checking Python executable (%s)\n") % sys.executable) | ||
ui.status(_("checking Python version (%s)\n") | ||||
|
r20740 | % ("%s.%s.%s" % sys.version_info[:3])) | ||
|
r17392 | ui.status(_("checking Python lib (%s)...\n") | ||
% os.path.dirname(os.__file__)) | ||||
|
r3844 | # compiled modules | ||
|
r16934 | ui.status(_("checking installed modules (%s)...\n") | ||
|
r12004 | % os.path.dirname(__file__)) | ||
|
r3844 | try: | ||
|
r12004 | import bdiff, mpatch, base85, osutil | ||
|
r15223 | dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes | ||
|
r3844 | except Exception, inst: | ||
ui.write(" %s\n" % inst) | ||||
|
r3848 | ui.write(_(" One or more extensions could not be found")) | ||
ui.write(_(" (check that you compiled the extensions)\n")) | ||||
|
r3844 | problems += 1 | ||
# templates | ||||
|
r15200 | import templater | ||
p = templater.templatepath() | ||||
|
r16934 | ui.status(_("checking templates (%s)...\n") % ' '.join(p)) | ||
|
r20389 | if p: | ||
m = templater.templatepath("map-cmdline.default") | ||||
if m: | ||||
# template found, check if it is working | ||||
try: | ||||
templater.templater(m) | ||||
except Exception, inst: | ||||
ui.write(" %s\n" % inst) | ||||
p = None | ||||
else: | ||||
ui.write(_(" template 'default' not found\n")) | ||||
p = None | ||||
else: | ||||
ui.write(_(" no template directories found\n")) | ||||
if not p: | ||||
|
r3848 | ui.write(_(" (templates seem to have been installed incorrectly)\n")) | ||
|
r3844 | problems += 1 | ||
# editor | ||||
|
r16934 | ui.status(_("checking commit editor...\n")) | ||
|
r5660 | editor = ui.geteditor() | ||
|
r21957 | cmdpath = util.findexe(shlex.split(editor)[0]) | ||
|
r3844 | if not cmdpath: | ||
|
r3855 | if editor == 'vi': | ||
|
r3844 | ui.write(_(" No commit editor set and can't find vi in PATH\n")) | ||
|
r12083 | ui.write(_(" (specify a commit editor in your configuration" | ||
" file)\n")) | ||||
|
r3844 | else: | ||
ui.write(_(" Can't find editor '%s' in PATH\n") % editor) | ||||
|
r12083 | ui.write(_(" (specify a commit editor in your configuration" | ||
" file)\n")) | ||||
|
r3844 | problems += 1 | ||
|
r3848 | # check username | ||
|
r16934 | ui.status(_("checking username...\n")) | ||
|
r9734 | try: | ||
|
r12063 | ui.username() | ||
|
r9734 | except util.Abort, e: | ||
ui.write(" %s\n" % e) | ||||
|
r12083 | ui.write(_(" (specify a username in your configuration file)\n")) | ||
|
r9734 | problems += 1 | ||
|
r3848 | |||
|
r3844 | if not problems: | ||
|
r16934 | ui.status(_("no problems detected\n")) | ||
|
r3844 | else: | ||
ui.write(_("%s problems detected," | ||||
" please check your install!\n") % problems) | ||||
return problems | ||||
|
r21768 | @command('debugknown', [], _('REPO ID...'), norepo=True) | ||
|
r14302 | def debugknown(ui, repopath, *ids, **opts): | ||
"""test whether node ids are known to a repo | ||||
|
r16683 | Every ID must be a full-length hex node id string. Returns a list of 0s | ||
and 1s indicating unknown/known. | ||||
|
r14302 | """ | ||
|
r14556 | repo = hg.peer(ui, opts, repopath) | ||
|
r14302 | if not repo.capable('known'): | ||
raise util.Abort("known() not supported by target repository") | ||||
flags = repo.known([bin(s) for s in ids]) | ||||
ui.write("%s\n" % ("".join([f and "1" or "0" for f in flags]))) | ||||
|
r18790 | @command('debuglabelcomplete', [], _('LABEL...')) | ||
def debuglabelcomplete(ui, repo, *args): | ||||
'''complete "labels" - tags, open branch names, bookmark names''' | ||||
labels = set() | ||||
labels.update(t[0] for t in repo.tagslist()) | ||||
labels.update(repo._bookmarks.keys()) | ||||
|
r20191 | labels.update(tag for (tag, heads, tip, closed) | ||
in repo.branchmap().iterbranches() if not closed) | ||||
|
r18790 | completions = set() | ||
if not args: | ||||
args = [''] | ||||
for a in args: | ||||
completions.update(l for l in labels if l.startswith(a)) | ||||
ui.write('\n'.join(sorted(completions))) | ||||
ui.write('\n') | ||||
|
r17830 | @command('debugobsolete', | ||
[('', 'flags', 0, _('markers flag')), | ||||
] + commitopts2, | ||||
|
r17074 | _('[OBSOLETED [REPLACEMENT] [REPL... ]')) | ||
def debugobsolete(ui, repo, precursor=None, *successors, **opts): | ||||
|
r18657 | """create arbitrary obsolete marker | ||
|
r18854 | With no arguments, displays the list of obsolescence markers.""" | ||
|
r21789 | |||
|
r17292 | def parsenodeid(s): | ||
try: | ||||
# We do not use revsingle/revrange functions here to accept | ||||
# arbitrary node identifiers, possibly not present in the | ||||
# local repository. | ||||
n = bin(s) | ||||
if len(n) != len(nullid): | ||||
raise TypeError() | ||||
return n | ||||
except TypeError: | ||||
raise util.Abort('changeset references must be full hexadecimal ' | ||||
'node identifiers') | ||||
|
r17074 | if precursor is not None: | ||
metadata = {} | ||||
if 'date' in opts: | ||||
metadata['date'] = opts['date'] | ||||
metadata['user'] = opts['user'] or ui.username() | ||||
|
r17292 | succs = tuple(parsenodeid(succ) for succ in successors) | ||
|
r17074 | l = repo.lock() | ||
try: | ||||
|
r17126 | tr = repo.transaction('debugobsolete') | ||
try: | ||||
|
r17830 | repo.obsstore.create(tr, parsenodeid(precursor), succs, | ||
opts['flags'], metadata) | ||||
|
r17126 | tr.close() | ||
finally: | ||||
tr.release() | ||||
|
r17074 | finally: | ||
l.release() | ||||
else: | ||||
|
r17123 | for m in obsolete.allmarkers(repo): | ||
|
r20470 | cmdutil.showmarker(ui, m) | ||
|
r17071 | |||
|
r18792 | @command('debugpathcomplete', | ||
[('f', 'full', None, _('complete an entire path')), | ||||
('n', 'normal', None, _('show only normal files')), | ||||
('a', 'added', None, _('show only added files')), | ||||
('r', 'removed', None, _('show only removed files'))], | ||||
_('FILESPEC...')) | ||||
def debugpathcomplete(ui, repo, *specs, **opts): | ||||
'''complete part or all of a tracked path | ||||
This command supports shells that offer path name completion. It | ||||
currently completes only files already known to the dirstate. | ||||
Completion extends only to the next path segment unless | ||||
--full is specified, in which case entire paths are used.''' | ||||
def complete(path, acceptable): | ||||
dirstate = repo.dirstate | ||||
spec = os.path.normpath(os.path.join(os.getcwd(), path)) | ||||
rootdir = repo.root + os.sep | ||||
if spec != repo.root and not spec.startswith(rootdir): | ||||
return [], [] | ||||
if os.path.isdir(spec): | ||||
spec += '/' | ||||
spec = spec[len(rootdir):] | ||||
fixpaths = os.sep != '/' | ||||
if fixpaths: | ||||
spec = spec.replace(os.sep, '/') | ||||
speclen = len(spec) | ||||
fullpaths = opts['full'] | ||||
files, dirs = set(), set() | ||||
adddir, addfile = dirs.add, files.add | ||||
for f, st in dirstate.iteritems(): | ||||
if f.startswith(spec) and st[0] in acceptable: | ||||
if fixpaths: | ||||
f = f.replace('/', os.sep) | ||||
if fullpaths: | ||||
addfile(f) | ||||
continue | ||||
s = f.find(os.sep, speclen) | ||||
if s >= 0: | ||||
|
r20136 | adddir(f[:s]) | ||
|
r18792 | else: | ||
addfile(f) | ||||
return files, dirs | ||||
acceptable = '' | ||||
if opts['normal']: | ||||
acceptable += 'nm' | ||||
if opts['added']: | ||||
acceptable += 'a' | ||||
if opts['removed']: | ||||
acceptable += 'r' | ||||
cwd = repo.getcwd() | ||||
if not specs: | ||||
specs = ['.'] | ||||
files, dirs = set(), set() | ||||
for spec in specs: | ||||
f, d = complete(spec, acceptable or 'nmar') | ||||
files.update(f) | ||||
dirs.update(d) | ||||
|
r18796 | files.update(dirs) | ||
|
r18792 | ui.write('\n'.join(repo.pathto(p, cwd) for p in sorted(files))) | ||
ui.write('\n') | ||||
|
r21768 | @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]'), norepo=True) | ||
|
r14556 | def debugpushkey(ui, repopath, namespace, *keyinfo, **opts): | ||
|
r14302 | '''access the pushkey key/value protocol | ||
With two args, list the keys in the given namespace. | ||||
With five args, set a key to new if it currently is set to old. | ||||
Reports success or failure. | ||||
''' | ||||
|
r14556 | target = hg.peer(ui, {}, repopath) | ||
|
r14302 | if keyinfo: | ||
key, old, new = keyinfo | ||||
r = target.pushkey(namespace, key, old, new) | ||||
ui.status(str(r) + '\n') | ||||
return not r | ||||
else: | ||||
|
r18255 | for k, v in sorted(target.listkeys(namespace).iteritems()): | ||
|
r14302 | ui.write("%s\t%s\n" % (k.encode('string-escape'), | ||
v.encode('string-escape'))) | ||||
|
r16249 | @command('debugpvec', [], _('A B')) | ||
def debugpvec(ui, repo, a, b=None): | ||||
ca = scmutil.revsingle(repo, a) | ||||
cb = scmutil.revsingle(repo, b) | ||||
pa = pvec.ctxpvec(ca) | ||||
pb = pvec.ctxpvec(cb) | ||||
if pa == pb: | ||||
rel = "=" | ||||
elif pa > pb: | ||||
rel = ">" | ||||
elif pa < pb: | ||||
rel = "<" | ||||
elif pa | pb: | ||||
rel = "|" | ||||
ui.write(_("a: %s\n") % pa) | ||||
ui.write(_("b: %s\n") % pb) | ||||
ui.write(_("depth(a): %d depth(b): %d\n") % (pa._depth, pb._depth)) | ||||
ui.write(_("delta: %d hdist: %d distance: %d relation: %s\n") % | ||||
(abs(pa._depth - pb._depth), pvec._hamming(pa._vec, pb._vec), | ||||
pa.distance(pb), rel)) | ||||
|
r18963 | @command('debugrebuilddirstate|debugrebuildstate', | ||
|
r14302 | [('r', 'rev', '', _('revision to rebuild to'), _('REV'))], | ||
|
r18961 | _('[-r REV]')) | ||
|
r18963 | def debugrebuilddirstate(ui, repo, rev): | ||
|
r18961 | """rebuild the dirstate as it would look like for the given revision | ||
If no revision is specified the first current parent will be used. | ||||
The dirstate will be set to the files of the given revision. | ||||
The actual working directory content or existing dirstate | ||||
information such as adds or removes is not considered. | ||||
One use of this command is to make the next :hg:`status` invocation | ||||
check the actual file content. | ||||
""" | ||||
|
r14319 | ctx = scmutil.revsingle(repo, rev) | ||
|
r14302 | wlock = repo.wlock() | ||
try: | ||||
repo.dirstate.rebuild(ctx.node(), ctx.manifest()) | ||||
finally: | ||||
wlock.release() | ||||
|
r14297 | @command('debugrename', | ||
[('r', 'rev', '', _('revision to debug'), _('REV'))], | ||||
_('[-r REV] FILE')) | ||||
|
r3652 | def debugrename(ui, repo, file1, *pats, **opts): | ||
|
r1194 | """dump rename information""" | ||
|
r3652 | |||
|
r14319 | ctx = scmutil.revsingle(repo, opts.get('rev')) | ||
|
r14671 | m = scmutil.match(ctx, (file1,) + pats, opts) | ||
|
r6764 | for abs in ctx.walk(m): | ||
fctx = ctx[abs] | ||||
|
r6579 | o = fctx.filelog().renamed(fctx.filenode()) | ||
|
r6584 | rel = m.rel(abs) | ||
|
r6579 | if o: | ||
ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1]))) | ||||
|
r3652 | else: | ||
ui.write(_("%s not renamed\n") % rel) | ||||
|
r1116 | |||
|
r14323 | @command('debugrevlog', | ||
[('c', 'changelog', False, _('open changelog')), | ||||
|
r14326 | ('m', 'manifest', False, _('open manifest')), | ||
('d', 'dump', False, _('dump index data'))], | ||||
|
r21775 | _('-c|-m|FILE'), | ||
optionalrepo=True) | ||||
|
r19872 | def debugrevlog(ui, repo, file_=None, **opts): | ||
|
r14304 | """show data and statistics about a revlog""" | ||
|
r14323 | r = cmdutil.openrevlog(repo, 'debugrevlog', file_, opts) | ||
|
r14326 | |||
if opts.get("dump"): | ||||
numrevs = len(r) | ||||
|
r21032 | ui.write("# rev p1rev p2rev start end deltastart base p1 p2" | ||
|
r14326 | " rawsize totalsize compression heads\n") | ||
ts = 0 | ||||
heads = set() | ||||
for rev in xrange(numrevs): | ||||
|
r14371 | dbase = r.deltaparent(rev) | ||
if dbase == -1: | ||||
dbase = rev | ||||
|
r14326 | cbase = r.chainbase(rev) | ||
p1, p2 = r.parentrevs(rev) | ||||
rs = r.rawsize(rev) | ||||
ts = ts + rs | ||||
heads -= set(r.parentrevs(rev)) | ||||
heads.add(rev) | ||||
|
r21032 | ui.write("%5d %5d %5d %5d %5d %10d %4d %4d %4d %7d %9d %11d %5d\n" % | ||
|
r14326 | (rev, p1, p2, r.start(rev), r.end(rev), | ||
r.start(dbase), r.start(cbase), | ||||
r.start(p1), r.start(p2), | ||||
rs, ts, ts / r.end(rev), len(heads))) | ||||
return 0 | ||||
|
r14304 | v = r.version | ||
format = v & 0xFFFF | ||||
flags = [] | ||||
gdelta = False | ||||
if v & revlog.REVLOGNGINLINEDATA: | ||||
flags.append('inline') | ||||
if v & revlog.REVLOGGENERALDELTA: | ||||
gdelta = True | ||||
flags.append('generaldelta') | ||||
|
r14305 | if not flags: | ||
flags = ['(none)'] | ||||
|
r14304 | |||
nummerges = 0 | ||||
|
r14305 | numfull = 0 | ||
|
r14304 | numprev = 0 | ||
nump1 = 0 | ||||
nump2 = 0 | ||||
numother = 0 | ||||
nump1prev = 0 | ||||
nump2prev = 0 | ||||
|
r14305 | chainlengths = [] | ||
|
r14304 | |||
datasize = [None, 0, 0L] | ||||
|
r14305 | fullsize = [None, 0, 0L] | ||
|
r14304 | deltasize = [None, 0, 0L] | ||
def addsize(size, l): | ||||
if l[0] is None or size < l[0]: | ||||
l[0] = size | ||||
if size > l[1]: | ||||
l[1] = size | ||||
l[2] += size | ||||
numrevs = len(r) | ||||
for rev in xrange(numrevs): | ||||
p1, p2 = r.parentrevs(rev) | ||||
delta = r.deltaparent(rev) | ||||
if format > 0: | ||||
addsize(r.rawsize(rev), datasize) | ||||
if p2 != nullrev: | ||||
nummerges += 1 | ||||
size = r.length(rev) | ||||
if delta == nullrev: | ||||
|
r14305 | chainlengths.append(0) | ||
numfull += 1 | ||||
addsize(size, fullsize) | ||||
|
r14304 | else: | ||
|
r14305 | chainlengths.append(chainlengths[delta] + 1) | ||
|
r14304 | addsize(size, deltasize) | ||
|
r14305 | if delta == rev - 1: | ||
numprev += 1 | ||||
if delta == p1: | ||||
nump1prev += 1 | ||||
|
r14304 | elif delta == p2: | ||
|
r14305 | nump2prev += 1 | ||
elif delta == p1: | ||||
nump1 += 1 | ||||
elif delta == p2: | ||||
nump2 += 1 | ||||
elif delta != nullrev: | ||||
numother += 1 | ||||
|
r17188 | # Adjust size min value for empty cases | ||
for size in (datasize, fullsize, deltasize): | ||||
if size[0] is None: | ||||
size[0] = 0 | ||||
|
r14305 | numdeltas = numrevs - numfull | ||
numoprev = numprev - nump1prev - nump2prev | ||||
totalrawsize = datasize[2] | ||||
|
r14304 | datasize[2] /= numrevs | ||
|
r14305 | fulltotal = fullsize[2] | ||
fullsize[2] /= numfull | ||||
deltatotal = deltasize[2] | ||||
|
r17188 | if numrevs - numfull > 0: | ||
deltasize[2] /= numrevs - numfull | ||||
|
r14305 | totalsize = fulltotal + deltatotal | ||
avgchainlen = sum(chainlengths) / numrevs | ||||
compratio = totalrawsize / totalsize | ||||
basedfmtstr = '%%%dd\n' | ||||
basepcfmtstr = '%%%dd %s(%%5.2f%%%%)\n' | ||||
def dfmtstr(max): | ||||
return basedfmtstr % len(str(max)) | ||||
def pcfmtstr(max, padding=0): | ||||
return basepcfmtstr % (len(str(max)), ' ' * padding) | ||||
def pcfmt(value, total): | ||||
return (value, 100 * float(value) / total) | ||||
|
r17956 | ui.write(('format : %d\n') % format) | ||
ui.write(('flags : %s\n') % ', '.join(flags)) | ||||
|
r14305 | |||
ui.write('\n') | ||||
fmt = pcfmtstr(totalsize) | ||||
fmt2 = dfmtstr(totalsize) | ||||
|
r17956 | ui.write(('revisions : ') + fmt2 % numrevs) | ||
ui.write((' merges : ') + fmt % pcfmt(nummerges, numrevs)) | ||||
ui.write((' normal : ') + fmt % pcfmt(numrevs - nummerges, numrevs)) | ||||
ui.write(('revisions : ') + fmt2 % numrevs) | ||||
ui.write((' full : ') + fmt % pcfmt(numfull, numrevs)) | ||||
ui.write((' deltas : ') + fmt % pcfmt(numdeltas, numrevs)) | ||||
ui.write(('revision size : ') + fmt2 % totalsize) | ||||
ui.write((' full : ') + fmt % pcfmt(fulltotal, totalsize)) | ||||
ui.write((' deltas : ') + fmt % pcfmt(deltatotal, totalsize)) | ||||
|
r14305 | |||
ui.write('\n') | ||||
fmt = dfmtstr(max(avgchainlen, compratio)) | ||||
|
r17956 | ui.write(('avg chain length : ') + fmt % avgchainlen) | ||
ui.write(('compression ratio : ') + fmt % compratio) | ||||
|
r14304 | |||
if format > 0: | ||||
|
r14305 | ui.write('\n') | ||
|
r17956 | ui.write(('uncompressed data size (min/max/avg) : %d / %d / %d\n') | ||
|
r14304 | % tuple(datasize)) | ||
|
r17956 | ui.write(('full revision size (min/max/avg) : %d / %d / %d\n') | ||
|
r14305 | % tuple(fullsize)) | ||
|
r17956 | ui.write(('delta size (min/max/avg) : %d / %d / %d\n') | ||
|
r14304 | % tuple(deltasize)) | ||
|
r14305 | if numdeltas > 0: | ||
ui.write('\n') | ||||
fmt = pcfmtstr(numdeltas) | ||||
fmt2 = pcfmtstr(numdeltas, 4) | ||||
|
r17956 | ui.write(('deltas against prev : ') + fmt % pcfmt(numprev, numdeltas)) | ||
|
r14305 | if numprev > 0: | ||
|
r17956 | ui.write((' where prev = p1 : ') + fmt2 % pcfmt(nump1prev, | ||
|
r16683 | numprev)) | ||
|
r17956 | ui.write((' where prev = p2 : ') + fmt2 % pcfmt(nump2prev, | ||
|
r16683 | numprev)) | ||
|
r17956 | ui.write((' other : ') + fmt2 % pcfmt(numoprev, | ||
|
r16683 | numprev)) | ||
|
r14305 | if gdelta: | ||
|
r17956 | ui.write(('deltas against p1 : ') | ||
+ fmt % pcfmt(nump1, numdeltas)) | ||||
ui.write(('deltas against p2 : ') | ||||
+ fmt % pcfmt(nump2, numdeltas)) | ||||
ui.write(('deltas against other : ') + fmt % pcfmt(numother, | ||||
|
r16683 | numdeltas)) | ||
|
r14304 | |||
|
r20497 | @command('debugrevspec', | ||
[('', 'optimize', None, _('print parsed tree after optimizing'))], | ||||
('REVSPEC')) | ||||
def debugrevspec(ui, repo, expr, **opts): | ||||
|
r16104 | """parse and apply a revision specification | ||
Use --verbose to print the parsed tree before and after aliases | ||||
expansion. | ||||
""" | ||||
|
r14302 | if ui.verbose: | ||
tree = revset.parse(expr)[0] | ||||
|
r16218 | ui.note(revset.prettyformat(tree), "\n") | ||
|
r14302 | newtree = revset.findaliases(ui, tree) | ||
if newtree != tree: | ||||
|
r16218 | ui.note(revset.prettyformat(newtree), "\n") | ||
|
r20497 | if opts["optimize"]: | ||
weight, optimizedtree = revset.optimize(newtree, True) | ||||
ui.note("* optimized:\n", revset.prettyformat(optimizedtree), "\n") | ||||
|
r14302 | func = revset.match(ui, expr) | ||
|
r20526 | for c in func(repo, revset.spanset(repo)): | ||
|
r14302 | ui.write("%s\n" % c) | ||
@command('debugsetparents', [], _('REV1 [REV2]')) | ||||
def debugsetparents(ui, repo, rev1, rev2=None): | ||||
"""manually set the parents of the current working directory | ||||
This is useful for writing repository conversion tools, but should | ||||
be used with care. | ||||
Returns 0 on success. | ||||
""" | ||||
|
r14319 | r1 = scmutil.revsingle(repo, rev1).node() | ||
r2 = scmutil.revsingle(repo, rev2, 'null').node() | ||||
|
r14302 | |||
wlock = repo.wlock() | ||||
try: | ||||
|
r16551 | repo.setparents(r1, r2) | ||
|
r14302 | finally: | ||
wlock.release() | ||||
|
r18962 | @command('debugdirstate|debugstate', | ||
|
r14302 | [('', 'nodates', None, _('do not display the saved mtime')), | ||
('', 'datesort', None, _('sort by saved mtime'))], | ||||
_('[OPTION]...')) | ||||
def debugstate(ui, repo, nodates=None, datesort=None): | ||||
"""show the contents of the current dirstate""" | ||||
timestr = "" | ||||
showdate = not nodates | ||||
if datesort: | ||||
keyfunc = lambda x: (x[1][3], x[0]) # sort by mtime, then by filename | ||||
else: | ||||
keyfunc = None # sort by filename | ||||
for file_, ent in sorted(repo.dirstate._map.iteritems(), key=keyfunc): | ||||
if showdate: | ||||
if ent[3] == -1: | ||||
# Pad or slice to locale representation | ||||
locale_len = len(time.strftime("%Y-%m-%d %H:%M:%S ", | ||||
time.localtime(0))) | ||||
timestr = 'unset' | ||||
timestr = (timestr[:locale_len] + | ||||
' ' * (locale_len - len(timestr))) | ||||
else: | ||||
timestr = time.strftime("%Y-%m-%d %H:%M:%S ", | ||||
time.localtime(ent[3])) | ||||
if ent[1] & 020000: | ||||
mode = 'lnk' | ||||
else: | ||||
|
r15440 | mode = '%3o' % (ent[1] & 0777 & ~util.umask) | ||
|
r14302 | ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_)) | ||
for f in repo.dirstate.copies(): | ||||
ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) | ||||
@command('debugsub', | ||||
[('r', 'rev', '', | ||||
_('revision to check'), _('REV'))], | ||||
_('[-r REV] [REV]')) | ||||
def debugsub(ui, repo, rev=None): | ||||
|
r14319 | ctx = scmutil.revsingle(repo, rev, None) | ||
|
r14302 | for k, v in sorted(ctx.substate.items()): | ||
|
r17956 | ui.write(('path %s\n') % k) | ||
ui.write((' source %s\n') % v[0]) | ||||
ui.write((' revision %s\n') % v[1]) | ||||
|
r14302 | |||
|
r18068 | @command('debugsuccessorssets', | ||
[], | ||||
_('[REV]')) | ||||
def debugsuccessorssets(ui, repo, *revs): | ||||
"""show set of successors for revision | ||||
A successors set of changeset A is a consistent group of revisions that | ||||
succeed A. It contains non-obsolete changesets only. | ||||
In most cases a changeset A has a single successors set containing a single | ||||
|
r18458 | successor (changeset A replaced by A'). | ||
|
r18068 | |||
A changeset that is made obsolete with no successors are called "pruned". | ||||
Such changesets have no successors sets at all. | ||||
A changeset that has been "split" will have a successors set containing | ||||
|
r18458 | more than one successor. | ||
|
r18068 | |||
A changeset that has been rewritten in multiple different ways is called | ||||
"divergent". Such changesets have multiple successor sets (each of which | ||||
may also be split, i.e. have multiple successors). | ||||
Results are displayed as follows:: | ||||
<rev1> | ||||
<successors-1A> | ||||
<rev2> | ||||
<successors-2A> | ||||
<successors-2B1> <successors-2B2> <successors-2B3> | ||||
Here rev2 has two possible (i.e. divergent) successors sets. The first | ||||
holds one element, whereas the second holds three (i.e. the changeset has | ||||
been split). | ||||
""" | ||||
# passed to successorssets caching computation from one call to another | ||||
cache = {} | ||||
ctx2str = str | ||||
node2str = short | ||||
if ui.debug(): | ||||
def ctx2str(ctx): | ||||
return ctx.hex() | ||||
node2str = hex | ||||
for rev in scmutil.revrange(repo, revs): | ||||
ctx = repo[rev] | ||||
ui.write('%s\n'% ctx2str(ctx)) | ||||
for succsset in obsolete.successorssets(repo, ctx.node(), cache): | ||||
if succsset: | ||||
ui.write(' ') | ||||
ui.write(node2str(succsset[0])) | ||||
for node in succsset[1:]: | ||||
ui.write(' ') | ||||
ui.write(node2str(node)) | ||||
ui.write('\n') | ||||
|
r14302 | |||
|
r21778 | @command('debugwalk', walkopts, _('[OPTION]... [FILE]...'), inferrepo=True) | ||
|
r820 | def debugwalk(ui, repo, *pats, **opts): | ||
|
r1053 | """show how files match on given patterns""" | ||
|
r14671 | m = scmutil.match(repo[None], pats, opts) | ||
|
r6585 | items = list(repo.walk(m)) | ||
|
r1065 | if not items: | ||
return | ||||
|
r16953 | f = lambda fn: fn | ||
if ui.configbool('ui', 'slash') and os.sep != '/': | ||||
f = lambda fn: util.normpath(fn) | ||||
|
r6586 | fmt = 'f %%-%ds %%-%ds %%s' % ( | ||
max([len(abs) for abs in items]), | ||||
max([len(m.rel(abs)) for abs in items])) | ||||
for abs in items: | ||||
|
r16953 | line = fmt % (abs, f(m.rel(abs)), m.exact(abs) and 'exact' or '') | ||
|
r1309 | ui.write("%s\n" % line.rstrip()) | ||
|
r820 | |||
|
r14297 | @command('debugwireargs', | ||
[('', 'three', '', 'three'), | ||||
('', 'four', '', 'four'), | ||||
('', 'five', '', 'five'), | ||||
] + remoteopts, | ||||
|
r21768 | _('REPO [OPTIONS]... [ONE [TWO]]'), | ||
norepo=True) | ||||
|
r13720 | def debugwireargs(ui, repopath, *vals, **opts): | ||
|
r14556 | repo = hg.peer(ui, opts, repopath) | ||
|
r13720 | for opt in remoteopts: | ||
del opts[opt[1]] | ||||
args = {} | ||||
for k, v in opts.iteritems(): | ||||
if v: | ||||
args[k] = v | ||||
# run twice to check that we don't mess up the stream for the next command | ||||
res1 = repo.debugwireargs(*vals, **args) | ||||
res2 = repo.debugwireargs(*vals, **args) | ||||
ui.write("%s\n" % res1) | ||||
if res1 != res2: | ||||
ui.warn("%s\n" % res2) | ||||
|
r14297 | @command('^diff', | ||
[('r', 'rev', [], _('revision'), _('REV')), | ||||
('c', 'change', '', _('change made by revision'), _('REV')) | ||||
] + diffopts + diffopts2 + walkopts + subrepoopts, | ||||
|
r21778 | _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...'), | ||
inferrepo=True) | ||||
|
r732 | def diff(ui, repo, *pats, **opts): | ||
|
r1568 | """diff repository (or selected files) | ||
|
r1437 | |||
Show differences between revisions for the specified files. | ||||
Differences between files are shown using the unified diff format. | ||||
|
r12389 | .. note:: | ||
|
r19997 | |||
|
r12389 | diff may generate unexpected results for merges, as it will | ||
default to comparing against the working directory's first | ||||
parent changeset if no revisions are specified. | ||||
|
r3822 | |||
|
r1437 | When two revision arguments are given, then changes are shown | ||
between those revisions. If only one revision is specified then | ||||
that revision is compared to the working directory, and, when no | ||||
revisions are specified, the working directory files are compared | ||||
to its parent. | ||||
|
r10527 | Alternatively you can specify -c/--change with a revision to see | ||
the changes in that changeset relative to its first parent. | ||||
|
r10520 | |||
|
r8033 | Without the -a/--text option, diff will avoid generating diffs of | ||
files it detects as binary. With -a, diff will generate a diff | ||||
anyway, probably with undesirable results. | ||||
Use the -g/--git option to generate diffs in the git extended diff | ||||
|
r10973 | format. For more information, read :hg:`help diffs`. | ||
|
r11177 | |||
|
r15110 | .. container:: verbose | ||
Examples: | ||||
- compare a file in the current working directory to its parent:: | ||||
hg diff foo.c | ||||
- compare two historical versions of a directory, with rename info:: | ||||
hg diff --git -r 1.0:1.2 lib/ | ||||
- get change stats relative to the last change on some date:: | ||||
hg diff --stat -r "date('may 2')" | ||||
- diff all newly-added files that contain a keyword:: | ||||
hg diff "set:added() and grep(GNU)" | ||||
- compare a revision and its parents:: | ||||
hg diff -c 9353 # compare against first parent | ||||
hg diff -r 9353^:9353 # same using revset syntax | ||||
hg diff -r 9353^2:9353 # compare against the second parent | ||||
|
r11177 | Returns 0 on success. | ||
|
r1437 | """ | ||
|
r7628 | |||
revs = opts.get('rev') | ||||
change = opts.get('change') | ||||
|
r9640 | stat = opts.get('stat') | ||
|
r9857 | reverse = opts.get('reverse') | ||
|
r7628 | |||
if revs and change: | ||||
msg = _('cannot specify --rev and --change at the same time') | ||||
raise util.Abort(msg) | ||||
elif change: | ||||
|
r14319 | node2 = scmutil.revsingle(repo, change, None).node() | ||
|
r13878 | node1 = repo[node2].p1().node() | ||
|
r7628 | else: | ||
|
r14319 | node1, node2 = scmutil.revpair(repo, revs) | ||
|
r245 | |||
|
r9857 | if reverse: | ||
|
r9725 | node1, node2 = node2, node1 | ||
|
r9642 | diffopts = patch.diffopts(ui, opts) | ||
|
r14671 | m = scmutil.match(repo[node2], pats, opts) | ||
|
r12167 | cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, | ||
listsubrepos=opts.get('subrepos')) | ||||
|
r396 | |||
|
r14297 | @command('^export', | ||
[('o', 'output', '', | ||||
_('print output to file with formatted name'), _('FORMAT')), | ||||
('', 'switch-parent', None, _('diff against the second parent')), | ||||
('r', 'rev', [], _('revisions to export'), _('REV')), | ||||
] + diffopts, | ||||
|
r18956 | _('[OPTION]... [-o OUTFILESPEC] [-r] [REV]...')) | ||
|
r580 | def export(ui, repo, *changesets, **opts): | ||
|
r1437 | """dump the header and diffs for one or more changesets | ||
Print the changeset header and diffs for one or more revisions. | ||||
|
r18956 | If no revision is given, the parent of the working directory is used. | ||
|
r1437 | |||
|
r10334 | The information shown in the changeset header is: author, date, | ||
|
r10335 | branch name (if non-default), changeset hash, parent(s) and commit | ||
comment. | ||||
|
r3822 | |||
|
r12390 | .. note:: | ||
|
r19997 | |||
|
r12390 | export may generate unexpected diff output for merge | ||
changesets, as it will compare the merge changeset against its | ||||
first parent only. | ||||
|
r1437 | |||
Output may be to a file, in which case the name of the file is | ||||
|
r9892 | given using a format string. The formatting rules are as follows: | ||
:``%%``: literal "%" character | ||||
|
r11718 | :``%H``: changeset hash (40 hexadecimal digits) | ||
|
r9892 | :``%N``: number of patches being generated | ||
:``%R``: changeset revision number | ||||
:``%b``: basename of the exporting repository | ||||
|
r11718 | :``%h``: short-form changeset hash (12 hexadecimal digits) | ||
|
r14986 | :``%m``: first line of the commit message (only alphanumeric characters) | ||
|
r9892 | :``%n``: zero-padded sequence number, starting at 1 | ||
:``%r``: zero-padded changeset revision number | ||||
|
r1437 | |||
|
r8033 | Without the -a/--text option, export will avoid generating diffs | ||
of files it detects as binary. With -a, export will generate a | ||||
diff anyway, probably with undesirable results. | ||||
Use the -g/--git option to generate diffs in the git extended diff | ||||
|
r10973 | format. See :hg:`help diffs` for more information. | ||
|
r7307 | |||
|
r8004 | With the --switch-parent option, the diff will be against the | ||
second parent. It can be useful to review a merge. | ||||
|
r11177 | |||
|
r15111 | .. container:: verbose | ||
Examples: | ||||
- use export and import to transplant a bugfix to the current | ||||
branch:: | ||||
hg export -r 9353 | hg import - | ||||
- export all the changesets between two revisions to a file with | ||||
rename information:: | ||||
hg export --git -r 123:150 > changes.txt | ||||
- split outgoing changes into a series of patches with | ||||
descriptive names:: | ||||
hg export -r "outgoing()" -o "%n-%m.patch" | ||||
|
r11177 | Returns 0 on success. | ||
|
r1437 | """ | ||
|
r10015 | changesets += tuple(opts.get('rev', [])) | ||
|
r18956 | if not changesets: | ||
changesets = ['.'] | ||||
|
r16357 | revs = scmutil.revrange(repo, changesets) | ||
if not revs: | ||||
|
r1402 | raise util.Abort(_("export requires at least one changeset")) | ||
|
r2874 | if len(revs) > 1: | ||
ui.note(_('exporting patches:\n')) | ||||
else: | ||||
ui.note(_('exporting patch:\n')) | ||||
|
r10611 | cmdutil.export(repo, revs, template=opts.get('output'), | ||
|
r7131 | switch_parent=opts.get('switch_parent'), | ||
|
r2888 | opts=patch.diffopts(ui, opts)) | ||
|
r246 | |||
|
r21778 | @command('^forget', walkopts, _('[OPTION]... FILE...'), inferrepo=True) | ||
|
r8902 | def forget(ui, repo, *pats, **opts): | ||
"""forget the specified files on the next commit | ||||
Mark the specified files so they will no longer be tracked | ||||
after the next commit. | ||||
This only removes files from the current branch, not from the | ||||
entire project history, and it does not delete them from the | ||||
working directory. | ||||
|
r11193 | To undo a forget before the next commit, see :hg:`add`. | ||
|
r11177 | |||
|
r15118 | .. container:: verbose | ||
Examples: | ||||
- forget newly-added binary files:: | ||||
hg forget "set:added() and binary()" | ||||
- forget files that would be excluded by .hgignore:: | ||||
hg forget "set:hgignore()" | ||||
|
r11177 | Returns 0 on success. | ||
|
r8902 | """ | ||
if not pats: | ||||
raise util.Abort(_('no files specified')) | ||||
|
r15912 | m = scmutil.match(repo[None], pats, opts) | ||
rejected = cmdutil.forget(ui, repo, m, prefix="", explicitonly=False)[0] | ||||
return rejected and 1 or 0 | ||||
|
r8902 | |||
|
r15240 | @command( | ||
'graft', | ||||
|
r16992 | [('r', 'rev', [], _('revisions to graft'), _('REV')), | ||
('c', 'continue', False, _('resume interrupted graft')), | ||||
|
r15241 | ('e', 'edit', False, _('invoke editor on commit messages')), | ||
|
r16660 | ('', 'log', None, _('append graft info to log message')), | ||
|
r21979 | ('f', 'force', False, _('force graft')), | ||
|
r15241 | ('D', 'currentdate', False, | ||
_('record the current date as commit date')), | ||||
('U', 'currentuser', False, | ||||
_('record the current user as committer'), _('DATE'))] | ||||
|
r16389 | + commitopts2 + mergetoolopts + dryrunopts, | ||
|
r16992 | _('[OPTION]... [-r] REV...')) | ||
|
r15241 | def graft(ui, repo, *revs, **opts): | ||
|
r15238 | '''copy changes from other branches onto the current branch | ||
This command uses Mercurial's merge logic to copy individual | ||||
changes from other branches without merging branches in the | ||||
history graph. This is sometimes known as 'backporting' or | ||||
|
r15242 | 'cherry-picking'. By default, graft will copy user, date, and | ||
description from the source changesets. | ||||
|
r15238 | |||
Changesets that are ancestors of the current revision, that have | ||||
already been grafted, or that are merges will be skipped. | ||||
|
r16660 | If --log is specified, log messages will have a comment appended | ||
of the form:: | ||||
(grafted from CHANGESETHASH) | ||||
|
r21979 | If --force is specified, revisions will be grafted even if they | ||
are already ancestors of or have been grafted to the destination. | ||||
This is useful when the revisions have since been backed out. | ||||
|
r15241 | If a graft merge results in conflicts, the graft process is | ||
|
r15701 | interrupted so that the current merge can be manually resolved. | ||
Once all conflicts are addressed, the graft process can be | ||||
continued with the -c/--continue option. | ||||
|
r15241 | |||
.. note:: | ||||
|
r19997 | |||
|
r21980 | The -c/--continue option does not reapply earlier options, except | ||
for --force. | ||||
|
r15241 | |||
|
r15242 | .. container:: verbose | ||
Examples: | ||||
- copy a single change to the stable branch and edit its description:: | ||||
hg update stable | ||||
hg graft --edit 9393 | ||||
- graft a range of changesets with one exception, updating dates:: | ||||
hg graft -D "2085::2093 and not 2091" | ||||
- continue a graft after resolving conflicts:: | ||||
hg graft -c | ||||
- show the source of a grafted changeset:: | ||||
|
r19401 | hg log --debug -r . | ||
|
r15242 | |||
|
r21949 | See :hg:`help revisions` and :hg:`help revsets` for more about | ||
specifying revisions. | ||||
|
r15238 | Returns 0 on successful completion. | ||
''' | ||||
|
r16992 | revs = list(revs) | ||
revs.extend(opts['rev']) | ||||
|
r15240 | if not opts.get('user') and opts.get('currentuser'): | ||
opts['user'] = ui.username() | ||||
if not opts.get('date') and opts.get('currentdate'): | ||||
opts['date'] = "%d %d" % util.makedate() | ||||
|
r22008 | editor = cmdutil.getcommiteditor(editform='graft', **opts) | ||
|
r15239 | |||
|
r15241 | cont = False | ||
if opts['continue']: | ||||
cont = True | ||||
if revs: | ||||
raise util.Abort(_("can't specify --continue and revisions")) | ||||
# read in unfinished revisions | ||||
try: | ||||
nodes = repo.opener.read('graftstate').splitlines() | ||||
revs = [repo[node].rev() for node in nodes] | ||||
except IOError, inst: | ||||
if inst.errno != errno.ENOENT: | ||||
raise | ||||
raise util.Abort(_("no graft state found, can't continue")) | ||||
else: | ||||
|
r19476 | cmdutil.checkunfinished(repo) | ||
|
r15241 | cmdutil.bailifchanged(repo) | ||
if not revs: | ||||
raise util.Abort(_('no revisions specified')) | ||||
revs = scmutil.revrange(repo, revs) | ||||
|
r15238 | |||
# check for merges | ||||
|
r15404 | for rev in repo.revs('%ld and merge()', revs): | ||
ui.warn(_('skipping ungraftable merge revision %s\n') % rev) | ||||
revs.remove(rev) | ||||
|
r15238 | if not revs: | ||
return -1 | ||||
|
r21980 | # Don't check in the --continue case, in effect retaining --force across | ||
# --continues. That's because without --force, any revisions we decided to | ||||
# skip would have been filtered out here, so they wouldn't have made their | ||||
# way to the graftstate. With --force, any revisions we would have otherwise | ||||
# skipped would not have been filtered out, and if they hadn't been applied | ||||
# already, they'd have been in the graftstate. | ||||
if not (cont or opts.get('force')): | ||||
# check for ancestors of dest branch | ||||
|
r21979 | crev = repo['.'].rev() | ||
ancestors = repo.changelog.ancestors([crev], inclusive=True) | ||||
# Cannot use x.remove(y) on smart set, this has to be a list. | ||||
# XXX make this lazy in the future | ||||
revs = list(revs) | ||||
# don't mutate while iterating, create a copy | ||||
for rev in list(revs): | ||||
if rev in ancestors: | ||||
ui.warn(_('skipping ancestor revision %s\n') % rev) | ||||
# XXX remove on list is slow | ||||
revs.remove(rev) | ||||
if not revs: | ||||
return -1 | ||||
# analyze revs for earlier grafts | ||||
ids = {} | ||||
for ctx in repo.set("%ld", revs): | ||||
ids[ctx.hex()] = ctx.rev() | ||||
n = ctx.extra().get('source') | ||||
if n: | ||||
ids[n] = ctx.rev() | ||||
# check ancestors for earlier grafts | ||||
ui.debug('scanning for duplicate grafts\n') | ||||
for rev in repo.changelog.findmissingrevs(revs, [crev]): | ||||
ctx = repo[rev] | ||||
n = ctx.extra().get('source') | ||||
if n in ids: | ||||
r = repo[n].rev() | ||||
if r in revs: | ||||
ui.warn(_('skipping revision %s (already grafted to %s)\n') | ||||
% (r, rev)) | ||||
revs.remove(r) | ||||
elif ids[n] in revs: | ||||
ui.warn(_('skipping already grafted revision %s ' | ||||
'(%s also has origin %d)\n') % (ids[n], rev, r)) | ||||
revs.remove(ids[n]) | ||||
elif ctx.hex() in ids: | ||||
r = ids[ctx.hex()] | ||||
ui.warn(_('skipping already grafted revision %s ' | ||||
'(was grafted from %d)\n') % (r, rev)) | ||||
|
r15360 | revs.remove(r) | ||
|
r21979 | if not revs: | ||
return -1 | ||||
|
r15238 | |||
|
r16473 | wlock = repo.wlock() | ||
try: | ||||
|
r18039 | current = repo['.'] | ||
|
r16473 | for pos, ctx in enumerate(repo.set("%ld", revs)): | ||
ui.status(_('grafting revision %s\n') % ctx.rev()) | ||||
if opts.get('dry_run'): | ||||
continue | ||||
|
r18038 | source = ctx.extra().get('source') | ||
if not source: | ||||
source = ctx.hex() | ||||
extra = {'source': source} | ||||
user = ctx.user() | ||||
if opts.get('user'): | ||||
user = opts['user'] | ||||
date = ctx.date() | ||||
if opts.get('date'): | ||||
date = opts['date'] | ||||
message = ctx.description() | ||||
if opts.get('log'): | ||||
message += '\n(grafted from %s)' % ctx.hex() | ||||
|
r16473 | # we don't merge the first commit when continuing | ||
if not cont: | ||||
# perform the graft merge with p1(rev) as 'ancestor' | ||||
try: | ||||
# ui.forcemerge is an internal variable, do not document | ||||
|
r20790 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), | ||
'graft') | ||||
|
r16473 | stats = mergemod.update(repo, ctx.node(), True, True, False, | ||
|
r21525 | ctx.p1().node(), | ||
labels=['local', 'graft']) | ||||
|
r16473 | finally: | ||
|
r20790 | repo.ui.setconfig('ui', 'forcemerge', '', 'graft') | ||
|
r16473 | # report any conflicts | ||
if stats and stats[3] > 0: | ||||
# write out state for --continue | ||||
nodelines = [repo[rev].hex() + "\n" for rev in revs[pos:]] | ||||
repo.opener.write('graftstate', ''.join(nodelines)) | ||||
raise util.Abort( | ||||
_("unresolved conflicts, can't continue"), | ||||
hint=_('use hg resolve and hg graft --continue')) | ||||
else: | ||||
cont = False | ||||
|
r17045 | # drop the second merge parent | ||
repo.setparents(current.node(), nullid) | ||||
repo.dirstate.write() | ||||
# fix up dirstate for copies and renames | ||||
cmdutil.duplicatecopies(repo, ctx.rev(), ctx.p1().rev()) | ||||
|
r16473 | # commit | ||
|
r16660 | node = repo.commit(text=message, user=user, | ||
|
r16473 | date=date, extra=extra, editor=editor) | ||
|
r16600 | if node is None: | ||
ui.status(_('graft for revision %s is empty\n') % ctx.rev()) | ||||
|
r18039 | else: | ||
current = repo[node] | ||||
|
r16473 | finally: | ||
wlock.release() | ||||
|
r15238 | |||
|
r15241 | # remove state when we complete successfully | ||
|
r18386 | if not opts.get('dry_run'): | ||
util.unlinkpath(repo.join('graftstate'), ignoremissing=True) | ||||
|
r15241 | |||
|
r15238 | return 0 | ||
|
r14297 | @command('grep', | ||
[('0', 'print0', None, _('end fields with NUL')), | ||||
('', 'all', None, _('print all revisions that match')), | ||||
('a', 'text', None, _('treat all files as text')), | ||||
('f', 'follow', None, | ||||
_('follow changeset history,' | ||||
' or file history across copies and renames')), | ||||
('i', 'ignore-case', None, _('ignore case when matching')), | ||||
('l', 'files-with-matches', None, | ||||
_('print only filenames and revisions that match')), | ||||
('n', 'line-number', None, _('print matching line numbers')), | ||||
('r', 'rev', [], | ||||
_('only search files changed within revision range'), _('REV')), | ||||
('u', 'user', None, _('list the author (long with -v)')), | ||||
('d', 'date', None, _('list the date (short with -q)')), | ||||
] + walkopts, | ||||
|
r21778 | _('[OPTION]... PATTERN [FILE]...'), | ||
inferrepo=True) | ||||
|
r1108 | def grep(ui, repo, pattern, *pats, **opts): | ||
|
r1437 | """search for a pattern in specified files and revisions | ||
Search revisions of files for a regular expression. | ||||
|
r6448 | This command behaves differently than Unix grep. It only accepts | ||
Python/Perl regexps. It searches repository history, not the | ||||
|
r8004 | working directory. It always prints the revision number in which a | ||
match appears. | ||||
|
r1437 | |||
By default, grep only prints output for the first revision of a | ||||
|
r6448 | file in which it finds a match. To get it to print every revision | ||
|
r1437 | that contains a change in match status ("-" for a match that | ||
becomes a non-match, or "+" for a non-match that becomes a match), | ||||
use the --all flag. | ||||
|
r11177 | |||
Returns 0 if a match is found, 1 otherwise. | ||||
|
r1437 | """ | ||
|
r15765 | reflags = re.M | ||
|
r7131 | if opts.get('ignore_case'): | ||
|
r1065 | reflags |= re.I | ||
|
r4877 | try: | ||
|
r21911 | regexp = util.re.compile(pattern, reflags) | ||
|
r12385 | except re.error, inst: | ||
|
r6057 | ui.warn(_("grep: invalid match pattern: %s\n") % inst) | ||
|
r11177 | return 1 | ||
|
r1146 | sep, eol = ':', '\n' | ||
|
r7131 | if opts.get('print0'): | ||
|
r1146 | sep = eol = '\0' | ||
|
r1057 | |||
|
r9097 | getfile = util.lrucachefunc(repo.file) | ||
|
r1057 | |||
def matchlines(body): | ||||
|
r1059 | begin = 0 | ||
linenum = 0 | ||||
|
r17949 | while begin < len(body): | ||
|
r1059 | match = regexp.search(body, begin) | ||
|
r1065 | if not match: | ||
break | ||||
|
r1059 | mstart, mend = match.span() | ||
linenum += body.count('\n', begin, mstart) + 1 | ||||
lstart = body.rfind('\n', begin, mstart) + 1 or begin | ||||
|
r15293 | begin = body.find('\n', mend) + 1 or len(body) + 1 | ||
|
r7230 | lend = begin - 1 | ||
|
r1059 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] | ||
|
r1057 | |||
|
r1559 | class linestate(object): | ||
|
r1057 | def __init__(self, line, linenum, colstart, colend): | ||
self.line = line | ||||
self.linenum = linenum | ||||
self.colstart = colstart | ||||
self.colend = colend | ||||
|
r2869 | |||
|
r6469 | def __hash__(self): | ||
return hash((self.linenum, self.line)) | ||||
|
r1065 | def __eq__(self, other): | ||
return self.line == other.line | ||||
|
r1057 | |||
|
r21011 | def __iter__(self): | ||
yield (self.line[:self.colstart], '') | ||||
yield (self.line[self.colstart:self.colend], 'grep.match') | ||||
rest = self.line[self.colend:] | ||||
while rest != '': | ||||
match = regexp.search(rest) | ||||
if not match: | ||||
yield (rest, '') | ||||
break | ||||
mstart, mend = match.span() | ||||
yield (rest[:mstart], '') | ||||
yield (rest[mstart:mend], 'grep.match') | ||||
rest = rest[mend:] | ||||
|
r1057 | matches = {} | ||
|
r2870 | copies = {} | ||
|
r1057 | def grepbody(fn, rev, body): | ||
|
r2869 | matches[rev].setdefault(fn, []) | ||
|
r1057 | m = matches[rev][fn] | ||
for lnum, cstart, cend, line in matchlines(body): | ||||
s = linestate(line, lnum, cstart, cend) | ||||
|
r2869 | m.append(s) | ||
def difflinestates(a, b): | ||||
sm = difflib.SequenceMatcher(None, a, b) | ||||
for tag, alo, ahi, blo, bhi in sm.get_opcodes(): | ||||
if tag == 'insert': | ||||
|
r3472 | for i in xrange(blo, bhi): | ||
|
r2869 | yield ('+', b[i]) | ||
elif tag == 'delete': | ||||
|
r3472 | for i in xrange(alo, ahi): | ||
|
r2869 | yield ('-', a[i]) | ||
elif tag == 'replace': | ||||
|
r3472 | for i in xrange(alo, ahi): | ||
|
r2869 | yield ('-', a[i]) | ||
|
r3472 | for i in xrange(blo, bhi): | ||
|
r2869 | yield ('+', b[i]) | ||
|
r9655 | def display(fn, ctx, pstates, states): | ||
rev = ctx.rev() | ||||
|
r6134 | datefunc = ui.quiet and util.shortdate or util.datestr | ||
|
r3951 | found = False | ||
|
r20836 | @util.cachefunc | ||
|
r13920 | def binary(): | ||
flog = getfile(fn) | ||||
return util.binary(flog.read(ctx.filenode(fn))) | ||||
|
r7131 | if opts.get('all'): | ||
|
r8849 | iter = difflinestates(pstates, states) | ||
|
r2869 | else: | ||
|
r8849 | iter = [('', l) for l in states] | ||
|
r3951 | for change, l in iter: | ||
|
r17806 | cols = [(fn, 'grep.filename'), (str(rev), 'grep.rev')] | ||
|
r7131 | if opts.get('line_number'): | ||
|
r17806 | cols.append((str(l.linenum), 'grep.linenumber')) | ||
|
r7131 | if opts.get('all'): | ||
|
r17806 | cols.append((change, 'grep.change')) | ||
|
r7131 | if opts.get('user'): | ||
|
r17806 | cols.append((ui.shortuser(ctx.user()), 'grep.user')) | ||
|
r6133 | if opts.get('date'): | ||
|
r17806 | cols.append((datefunc(ctx.date()), 'grep.date')) | ||
for col, label in cols[:-1]: | ||||
ui.write(col, label=label) | ||||
ui.write(sep, label='grep.sep') | ||||
ui.write(cols[-1][0], label=cols[-1][1]) | ||||
|
r21011 | if not opts.get('files_with_matches'): | ||
|
r17806 | ui.write(sep, label='grep.sep') | ||
|
r13920 | if not opts.get('text') and binary(): | ||
|
r17806 | ui.write(" Binary file matches") | ||
|
r13920 | else: | ||
|
r21011 | for s, label in l: | ||
ui.write(s, label=label) | ||||
|
r10816 | ui.write(eol) | ||
|
r3951 | found = True | ||
|
r21011 | if opts.get('files_with_matches'): | ||
|
r20838 | break | ||
|
r3951 | return found | ||
|
r1057 | |||
|
r1145 | skip = {} | ||
|
r8849 | revfiles = {} | ||
|
r14671 | matchfn = scmutil.match(repo[None], pats, opts) | ||
|
r3951 | found = False | ||
|
r2870 | follow = opts.get('follow') | ||
|
r9662 | |||
def prep(ctx, fns): | ||||
rev = ctx.rev() | ||||
|
r13878 | pctx = ctx.p1() | ||
|
r9662 | parent = pctx.rev() | ||
matches.setdefault(rev, {}) | ||||
matches.setdefault(parent, {}) | ||||
files = revfiles.setdefault(rev, []) | ||||
for fn in fns: | ||||
flog = getfile(fn) | ||||
try: | ||||
fnode = ctx.filenode(fn) | ||||
except error.LookupError: | ||||
continue | ||||
copied = flog.renamed(fnode) | ||||
copy = follow and copied and copied[0] | ||||
if copy: | ||||
copies.setdefault(rev, {})[fn] = copy | ||||
if fn in skip: | ||||
if copy: | ||||
skip[copy] = True | ||||
continue | ||||
files.append(fn) | ||||
if fn not in matches[rev]: | ||||
grepbody(fn, rev, flog.read(fnode)) | ||||
pfn = copy or fn | ||||
if pfn not in matches[parent]: | ||||
|
r1057 | try: | ||
|
r9662 | fnode = pctx.filenode(pfn) | ||
grepbody(pfn, parent, flog.read(fnode)) | ||||
|
r7633 | except error.LookupError: | ||
|
r9662 | pass | ||
|
r9665 | for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep): | ||
|
r9662 | rev = ctx.rev() | ||
|
r13878 | parent = ctx.p1().rev() | ||
|
r9662 | for fn in sorted(revfiles.get(rev, [])): | ||
states = matches[rev][fn] | ||||
copy = copies.get(rev, {}).get(fn) | ||||
if fn in skip: | ||||
|
r8849 | if copy: | ||
|
r9662 | skip[copy] = True | ||
continue | ||||
pstates = matches.get(parent, {}).get(copy or fn, []) | ||||
if pstates or states: | ||||
r = display(fn, ctx, pstates, states) | ||||
found = found or r | ||||
if r and not opts.get('all'): | ||||
skip[fn] = True | ||||
|
r8849 | if copy: | ||
skip[copy] = True | ||||
|
r9662 | del matches[rev] | ||
del revfiles[rev] | ||||
|
r1057 | |||
|
r11177 | return not found | ||
|
r14297 | @command('heads', | ||
[('r', 'rev', '', | ||||
_('show only heads which are descendants of STARTREV'), _('STARTREV')), | ||||
('t', 'topo', False, _('show topological heads only')), | ||||
('a', 'active', False, _('show active branchheads only (DEPRECATED)')), | ||||
('c', 'closed', False, _('show normal and closed branch heads')), | ||||
] + templateopts, | ||||
|
r16869 | _('[-ct] [-r STARTREV] [REV]...')) | ||
|
r4648 | def heads(ui, repo, *branchrevs, **opts): | ||
|
r19469 | """show branch heads | ||
With no arguments, show all open branch heads in the repository. | ||||
|
r19493 | Branch heads are changesets that have no descendants on the | ||
|
r19469 | same branch. They are where development generally takes place and | ||
are the usual targets for update and merge operations. | ||||
If one or more REVs are given, only open branch heads on the | ||||
branches associated with the specified changesets are shown. This | ||||
means that you can use :hg:`heads .` to see the heads on the | ||||
currently checked-out branch. | ||||
|
r9502 | |||
If -c/--closed is specified, also show branch heads marked closed | ||||
|
r11193 | (see :hg:`commit --close-branch`). | ||
|
r9502 | |||
If STARTREV is specified, only those heads that are descendants of | ||||
STARTREV will be displayed. | ||||
|
r10350 | |||
If -t/--topo is specified, named branch mechanics will be ignored and only | ||||
|
r19469 | topological heads (changesets with no children) will be shown. | ||
|
r11177 | |||
Returns 0 if matching heads are found, 1 if not. | ||||
|
r1437 | """ | ||
|
r10328 | |||
|
r12925 | start = None | ||
if 'rev' in opts: | ||||
|
r14319 | start = scmutil.revsingle(repo, opts['rev'], None).node() | ||
|
r10328 | |||
|
r10350 | if opts.get('topo'): | ||
heads = [repo[h] for h in repo.heads(start)] | ||||
|
r1550 | else: | ||
|
r10348 | heads = [] | ||
|
r14466 | for branch in repo.branchmap(): | ||
heads += repo.branchheads(branch, start, opts.get('closed')) | ||||
heads = [repo[h] for h in heads] | ||||
|
r10350 | |||
if branchrevs: | ||||
|
r13047 | branches = set(repo[br].branch() for br in branchrevs) | ||
|
r10350 | heads = [h for h in heads if h.branch() in branches] | ||
|
r10328 | |||
|
r10349 | if opts.get('active') and branchrevs: | ||
dagheads = repo.heads(start) | ||||
|
r10350 | heads = [h for h in heads if h.node() in dagheads] | ||
|
r10349 | |||
if branchrevs: | ||||
|
r10350 | haveheads = set(h.branch() for h in heads) | ||
|
r10346 | if branches - haveheads: | ||
|
r13047 | headless = ', '.join(b for b in branches - haveheads) | ||
|
r10346 | msg = _('no open branch heads found on branches %s') | ||
if opts.get('rev'): | ||||
|
r16231 | msg += _(' (started at %s)') % opts['rev'] | ||
|
r10346 | ui.warn((msg + '\n') % headless) | ||
|
r4648 | if not heads: | ||
return 1 | ||||
|
r10328 | |||
|
r10350 | heads = sorted(heads, key=lambda x: -x.rev()) | ||
|
r3643 | displayer = cmdutil.show_changeset(ui, repo, opts) | ||
|
r10331 | for ctx in heads: | ||
displayer.show(ctx) | ||||
|
r10152 | displayer.close() | ||
|
r221 | |||
|
r14297 | @command('help', | ||
[('e', 'extension', None, _('show only help for extensions')), | ||||
|
r16711 | ('c', 'command', None, _('show only help for commands')), | ||
('k', 'keyword', '', _('show topics matching keyword')), | ||||
], | ||||
|
r21768 | _('[-ec] [TOPIC]'), | ||
norepo=True) | ||||
|
r18746 | def help_(ui, name=None, **opts): | ||
|
r7210 | """show help for a given topic or a help overview | ||
|
r3655 | |||
|
r8779 | With no arguments, print a list of commands with short help messages. | ||
|
r3655 | |||
|
r8004 | Given a topic, extension, or command name, print help for that | ||
|
r11177 | topic. | ||
Returns 0 if successful. | ||||
""" | ||||
|
r15023 | |||
|
r13608 | textwidth = min(ui.termwidth(), 80) - 2 | ||
|
r3655 | |||
|
r16854 | keep = ui.verbose and ['verbose'] or [] | ||
|
r18746 | text = help.help_(ui, name, **opts) | ||
|
r17837 | formatted, pruned = minirst.format(text, textwidth, keep=keep) | ||
if 'verbose' in pruned: | ||||
keep.append('omitted') | ||||
else: | ||||
keep.append('notomitted') | ||||
formatted, pruned = minirst.format(text, textwidth, keep=keep) | ||||
|
r16854 | ui.write(formatted) | ||
|
r6653 | |||
|
r221 | |||
|
r14297 | @command('identify|id', | ||
[('r', 'rev', '', | ||||
_('identify the specified revision'), _('REV')), | ||||
('n', 'num', None, _('show local revision number')), | ||||
('i', 'id', None, _('show global revision id')), | ||||
('b', 'branch', None, _('show branch')), | ||||
('t', 'tags', None, _('show tags')), | ||||
|
r15580 | ('B', 'bookmarks', None, _('show bookmarks')), | ||
] + remoteopts, | ||||
|
r21775 | _('[-nibtB] [-r REV] [SOURCE]'), | ||
optionalrepo=True) | ||||
|
r13477 | def identify(ui, repo, source=None, rev=None, | ||
|
r15580 | num=None, id=None, branch=None, tags=None, bookmarks=None, **opts): | ||
|
r4665 | """identify the working copy or specified revision | ||
|
r13963 | Print a summary identifying the repository state at REV using one or | ||
two parent hash identifiers, followed by a "+" if the working | ||||
directory has uncommitted changes, the branch name (if not default), | ||||
a list of tags, and a list of bookmarks. | ||||
|
r13952 | |||
When REV is not given, print a summary of the current state of the | ||||
|
r8027 | repository. | ||
|
r4671 | |||
|
r8779 | Specifying a path to a repository root or Mercurial bundle will | ||
cause lookup to operate on that repository/bundle. | ||||
|
r1437 | |||
|
r15112 | .. container:: verbose | ||
Examples: | ||||
- generate a build identifier for the working directory:: | ||||
hg id --id > build-id.dat | ||||
- find the revision corresponding to a tag:: | ||||
hg id -n -r 1.3 | ||||
- check the most recent revision of a remote repository:: | ||||
hg id -r tip http://selenic.com/hg/ | ||||
|
r11177 | Returns 0 if successful. | ||
|
r1437 | """ | ||
|
r4662 | |||
|
r5330 | if not repo and not source: | ||
|
r12067 | raise util.Abort(_("there is no Mercurial repository here " | ||
|
r5330 | "(.hg not found)")) | ||
|
r2966 | hexfunc = ui.debugflag and hex or short | ||
|
r13477 | default = not (num or id or branch or tags or bookmarks) | ||
|
r4666 | output = [] | ||
|
r7757 | revs = [] | ||
|
r13953 | |||
|
r4671 | if source: | ||
|
r10365 | source, branches = hg.parseurl(ui.expandpath(source)) | ||
|
r17875 | peer = hg.peer(repo or ui, opts, source) # only pass ui when no repo | ||
|
r17191 | repo = peer.local() | ||
revs, checkout = hg.addbranchrevs(repo, peer, branches, None) | ||||
if not repo: | ||||
|
r13953 | if num or branch or tags: | ||
raise util.Abort( | ||||
_("can't query remote revision number, branch, or tags")) | ||||
|
r4671 | if not rev and revs: | ||
rev = revs[0] | ||||
|
r4667 | if not rev: | ||
rev = "tip" | ||||
|
r13644 | |||
|
r17191 | remoterev = peer.lookup(rev) | ||
|
r4666 | if default or id: | ||
|
r13644 | output = [hexfunc(remoterev)] | ||
|
r13953 | def getbms(): | ||
bms = [] | ||||
|
r17191 | if 'bookmarks' in peer.listkeys('namespaces'): | ||
|
r13953 | hexremoterev = hex(remoterev) | ||
|
r17191 | bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems() | ||
|
r13953 | if bmr == hexremoterev] | ||
|
r18366 | return sorted(bms) | ||
|
r13953 | |||
if bookmarks: | ||||
output.extend(getbms()) | ||||
elif default and not ui.quiet: | ||||
# multiple bookmarks for a single parent separated by '/' | ||||
bm = '/'.join(getbms()) | ||||
if bm: | ||||
output.append(bm) | ||||
|
r4665 | else: | ||
|
r13953 | if not rev: | ||
ctx = repo[None] | ||||
parents = ctx.parents() | ||||
changed = "" | ||||
if default or id or num: | ||||
|
r17255 | if (util.any(repo.status()) | ||
or util.any(ctx.sub(s).dirty() for s in ctx.substate)): | ||||
changed = '+' | ||||
|
r13953 | if default or id: | ||
output = ["%s%s" % | ||||
('+'.join([hexfunc(p.node()) for p in parents]), changed)] | ||||
if num: | ||||
output.append("%s%s" % | ||||
('+'.join([str(p.rev()) for p in parents]), changed)) | ||||
else: | ||||
|
r14319 | ctx = scmutil.revsingle(repo, rev) | ||
|
r13953 | if default or id: | ||
output = [hexfunc(ctx.node())] | ||||
if num: | ||||
output.append(str(ctx.rev())) | ||||
if default and not ui.quiet: | ||||
b = ctx.branch() | ||||
if b != 'default': | ||||
output.append("(%s)" % b) | ||||
# multiple tags for a single parent separated by '/' | ||||
t = '/'.join(ctx.tags()) | ||||
if t: | ||||
output.append(t) | ||||
# multiple bookmarks for a single parent separated by '/' | ||||
bm = '/'.join(ctx.bookmarks()) | ||||
if bm: | ||||
output.append(bm) | ||||
else: | ||||
if branch: | ||||
output.append(ctx.branch()) | ||||
if tags: | ||||
output.extend(ctx.tags()) | ||||
if bookmarks: | ||||
output.extend(ctx.bookmarks()) | ||||
|
r13477 | |||
|
r386 | ui.write("%s\n" % ' '.join(output)) | ||
|
r339 | |||
|
r14297 | @command('import|patch', | ||
[('p', 'strip', 1, | ||||
_('directory strip option for patch. This has the same ' | ||||
'meaning as the corresponding patch option'), _('NUM')), | ||||
|
r14532 | ('b', 'base', '', _('base path (DEPRECATED)'), _('PATH')), | ||
|
r15221 | ('e', 'edit', False, _('invoke editor on commit messages')), | ||
|
r19409 | ('f', 'force', None, | ||
_('skip check for outstanding uncommitted changes (DEPRECATED)')), | ||||
|
r14297 | ('', 'no-commit', None, | ||
_("don't commit, just update the working directory")), | ||||
|
r14611 | ('', 'bypass', None, | ||
_("apply patch without touching the working directory")), | ||||
|
r21553 | ('', 'partial', None, | ||
_('commit even if some hunks fail')), | ||||
|
r14297 | ('', 'exact', None, | ||
_('apply patch to the nodes from which it was generated')), | ||||
('', 'import-branch', None, | ||||
_('use any branch information in patch (implied by --exact)'))] + | ||||
commitopts + commitopts2 + similarityopts, | ||||
_('[OPTION]... PATCH...')) | ||||
|
r15327 | def import_(ui, repo, patch1=None, *patches, **opts): | ||
|
r1437 | """import an ordered set of patches | ||
|
r9649 | Import a list of patches and commit them individually (unless | ||
--no-commit is specified). | ||||
|
r1437 | |||
|
r19409 | Because import first applies changes to the working directory, | ||
import will abort if there are outstanding changes. | ||||
|
r1437 | |||
|
r6448 | You can import a patch straight from a mail message. Even patches | ||
|
r8779 | as attachments work (to use the body part, it must have type | ||
text/plain or text/x-patch). From and Subject headers of email | ||||
|
r6448 | message are used as default committer and commit message. All | ||
|
r2515 | text/plain body parts before first diff are added to commit | ||
message. | ||||
|
r2504 | |||
|
r11193 | If the imported patch was generated by :hg:`export`, user and | ||
|
r8004 | description from patch override values from message headers and | ||
|
r8033 | body. Values given on command line with -m/--message and -u/--user | ||
override these. | ||||
|
r8004 | |||
If --exact is specified, import will set the working directory to | ||||
the parent of each patch before applying it, and will abort if the | ||||
resulting changeset has a different ID than the one recorded in | ||||
the patch. This may happen due to character set problems or other | ||||
deficiencies in the text patch format. | ||||
|
r4263 | |||
|
r14611 | Use --bypass to apply and commit patches directly to the | ||
repository, not touching the working directory. Without --exact, | ||||
patches will be applied on top of the working directory parent | ||||
revision. | ||||
|
r8033 | With -s/--similarity, hg will attempt to discover renames and | ||
|
r15779 | copies in the patch in the same way as :hg:`addremove`. | ||
|
r7402 | |||
|
r21553 | Use --partial to ensure a changeset will be created from the patch | ||
even if some hunks fail to apply. Hunks that fail to apply will be | ||||
written to a <target-file>.rej file. Conflicts can then be resolved | ||||
by hand before :hg:`commit --amend` is run to update the created | ||||
changeset. This flag exists to let people import patches that | ||||
partially apply without losing the associated metadata (author, | ||||
|
r21929 | date, description, ...). Note that when none of the hunk applies | ||
|
r21553 | cleanly, :hg:`import --partial` will create an empty changeset, | ||
importing only the patch metadata. | ||||
|
r8931 | To read a patch from standard input, use "-" as the patch name. If | ||
a URL is specified, the patch will be downloaded from it. | ||||
|
r10973 | See :hg:`help dates` for a list of formats valid for -d/--date. | ||
|
r11177 | |||
|
r15113 | .. container:: verbose | ||
Examples: | ||||
- import a traditional patch from a website and detect renames:: | ||||
hg import -s 80 http://example.com/bugfix.patch | ||||
- import a changeset from an hgweb server:: | ||||
hg import http://www.selenic.com/hg/rev/5ca8c111e9aa | ||||
- import all the patches in an Unix-style mbox:: | ||||
hg import incoming-patches.mbox | ||||
- attempt to exactly restore an exported changeset (not always | ||||
possible):: | ||||
hg import --exact proposed-fix.patch | ||||
|
r21553 | Returns 0 on success, 1 on partial success (see --partial). | ||
|
r1437 | """ | ||
|
r15327 | |||
if not patch1: | ||||
raise util.Abort(_('need at least one patch to import')) | ||||
|
r437 | patches = (patch1,) + patches | ||
|
r500 | |||
|
r6139 | date = opts.get('date') | ||
if date: | ||||
opts['date'] = util.parsedate(date) | ||||
|
r14611 | update = not opts.get('bypass') | ||
if not update and opts.get('no_commit'): | ||||
raise util.Abort(_('cannot use --no-commit with --bypass')) | ||||
|
r7402 | try: | ||
sim = float(opts.get('similarity') or 0) | ||||
except ValueError: | ||||
raise util.Abort(_('similarity must be a number')) | ||||
if sim < 0 or sim > 100: | ||||
raise util.Abort(_('similarity must be between 0 and 100')) | ||||
|
r14611 | if sim and not update: | ||
raise util.Abort(_('cannot use --similarity with --bypass')) | ||||
|
r19476 | if update: | ||
cmdutil.checkunfinished(repo) | ||||
|
r14611 | if (opts.get('exact') or not opts.get('force')) and update: | ||
|
r14289 | cmdutil.bailifchanged(repo) | ||
|
r966 | |||
|
r15195 | base = opts["base"] | ||
|
r15198 | wlock = lock = tr = None | ||
|
r12913 | msgs = [] | ||
|
r21553 | ret = 0 | ||
|
r10384 | |||
|
r10405 | |||
|
r4915 | try: | ||
|
r15278 | try: | ||
wlock = repo.wlock() | ||||
|
r16274 | if not opts.get('no_commit'): | ||
lock = repo.lock() | ||||
tr = repo.transaction('import') | ||||
|
r15278 | parents = repo.parents() | ||
for patchurl in patches: | ||||
if patchurl == '-': | ||||
ui.status(_('applying patch from stdin\n')) | ||||
patchfile = ui.fin | ||||
patchurl = 'stdin' # for error message | ||||
|
r14611 | else: | ||
|
r15278 | patchurl = os.path.join(base, patchurl) | ||
ui.status(_('applying %s\n') % patchurl) | ||||
|
r17887 | patchfile = hg.openpath(ui, patchurl) | ||
|
r15278 | |||
haspatch = False | ||||
for hunk in patch.split(patchfile): | ||||
|
r21553 | (msg, node, rej) = cmdutil.tryimportone(ui, repo, hunk, | ||
parents, opts, | ||||
msgs, hg.clean) | ||||
|
r15278 | if msg: | ||
haspatch = True | ||||
ui.note(msg + '\n') | ||||
if update or opts.get('exact'): | ||||
parents = repo.parents() | ||||
else: | ||||
parents = [repo[node]] | ||||
|
r21553 | if rej: | ||
ui.write_err(_("patch applied partially\n")) | ||||
|
r21959 | ui.write_err(_("(fix the .rej files and run " | ||
"`hg commit --amend`)\n")) | ||||
|
r21553 | ret = 1 | ||
break | ||||
|
r15278 | |||
if not haspatch: | ||||
raise util.Abort(_('%s: no diffs found') % patchurl) | ||||
|
r16274 | if tr: | ||
tr.close() | ||||
|
r15278 | if msgs: | ||
repo.savecommitmessage('\n* * *\n'.join(msgs)) | ||||
|
r21553 | return ret | ||
|
r16705 | except: # re-raises | ||
|
r15278 | # wlock.release() indirectly calls dirstate.write(): since | ||
# we're crashing, we do not want to change the working dir | ||||
# parent after all, so make sure it writes nothing | ||||
repo.dirstate.invalidate() | ||||
raise | ||||
|
r4915 | finally: | ||
|
r15198 | if tr: | ||
tr.release() | ||||
|
r8109 | release(lock, wlock) | ||
|
r437 | |||
|
r14297 | @command('incoming|in', | ||
[('f', 'force', None, | ||||
_('run even if remote repository is unrelated')), | ||||
('n', 'newest-first', None, _('show newest record first')), | ||||
('', 'bundle', '', | ||||
_('file to store the bundles into'), _('FILE')), | ||||
('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), | ||||
('B', 'bookmarks', False, _("compare bookmarks")), | ||||
('b', 'branch', [], | ||||
_('a specific branch you would like to pull'), _('BRANCH')), | ||||
] + logopts + remoteopts + subrepoopts, | ||||
_('[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]')) | ||||
|
r1192 | def incoming(ui, repo, source="default", **opts): | ||
|
r1437 | """show new changesets found in source | ||
|
r1979 | Show new changesets found in the specified path/URL or the default | ||
|
r8779 | pull location. These are the changesets that would have been pulled | ||
if a pull at the time you issued this command. | ||||
|
r8004 | |||
For remote repository, using --bundle avoids downloading the | ||||
changesets twice if the incoming is followed by a pull. | ||||
|
r1979 | |||
See pull for valid source format details. | ||||
|
r11177 | |||
|
r20834 | .. container:: verbose | ||
Examples: | ||||
- show incoming changes with patches and full description:: | ||||
hg incoming -vp | ||||
- show incoming changes excluding merges, store a bundle:: | ||||
hg in -vpM --bundle incoming.hg | ||||
hg pull incoming.hg | ||||
- briefly list changes inside a bundle:: | ||||
hg in changes.hg -T "{desc|firstline}\\n" | ||||
|
r11177 | Returns 0 if there are incoming changes, 1 otherwise. | ||
|
r1437 | """ | ||
|
r17182 | if opts.get('graph'): | ||
cmdutil.checkunsupportedgraphflags([], opts) | ||||
def display(other, chlist, displayer): | ||||
revdag = cmdutil.graphrevs(other, chlist, opts) | ||||
showparents = [ctx.node() for ctx in repo[None].parents()] | ||||
cmdutil.displaygraph(ui, revdag, displayer, showparents, | ||||
graphmod.asciiedges) | ||||
hg._incoming(display, lambda: 1, ui, repo, source, opts, buffered=True) | ||||
return 0 | ||||
|
r12274 | if opts.get('bundle') and opts.get('subrepos'): | ||
raise util.Abort(_('cannot combine --bundle and --subrepos')) | ||||
|
r13366 | if opts.get('bookmarks'): | ||
source, branches = hg.parseurl(ui.expandpath(source), | ||||
opts.get('branch')) | ||||
|
r14556 | other = hg.peer(repo, opts, source) | ||
|
r13453 | if 'bookmarks' not in other.listkeys('namespaces'): | ||
ui.warn(_("remote doesn't support bookmarks\n")) | ||||
return 0 | ||||
|
r14076 | ui.status(_('comparing with %s\n') % util.hidepassword(source)) | ||
|
r13366 | return bookmarks.diff(ui, repo, other) | ||
|
r14360 | repo._subtoppath = ui.expandpath(source) | ||
try: | ||||
|
r14362 | return hg.incoming(ui, repo, source, opts) | ||
|
r14360 | finally: | ||
del repo._subtoppath | ||||
|
r1944 | |||
|
r21768 | @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]'), | ||
norepo=True) | ||||
|
r2598 | def init(ui, dest=".", **opts): | ||
|
r1437 | """create a new repository in the given directory | ||
|
r6448 | Initialize a new repository in the given directory. If the given | ||
|
r8779 | directory does not exist, it will be created. | ||
|
r1437 | |||
If no directory is given, the current directory is used. | ||||
|
r2590 | |||
|
r9970 | It is possible to specify an ``ssh://`` URL as the destination. | ||
|
r10973 | See :hg:`help urls` for more information. | ||
|
r11177 | |||
Returns 0 on success. | ||||
|
r1437 | """ | ||
|
r14556 | hg.peer(ui, opts, ui.expandpath(dest), create=True) | ||
|
r338 | |||
|
r14297 | @command('locate', | ||
[('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), | ||||
('0', 'print0', None, _('end filenames with NUL, for use with xargs')), | ||||
('f', 'fullpath', None, _('print complete paths from the filesystem root')), | ||||
] + walkopts, | ||||
_('[OPTION]... [PATTERN]...')) | ||||
|
r627 | def locate(ui, repo, *pats, **opts): | ||
|
r1437 | """locate files matching specific patterns | ||
|
r8779 | Print files under Mercurial control in the working directory whose | ||
names match the given patterns. | ||||
By default, this command searches all directories in the working | ||||
directory. To search just the current directory and its | ||||
subdirectories, use "--include .". | ||||
If no patterns are given to match, this command prints the names | ||||
of all files under Mercurial control in the working directory. | ||||
|
r1437 | |||
If you want to feed the output of this command into the "xargs" | ||||
|
r8032 | command, use the -0 option to both this command and "xargs". This | ||
will avoid the problem of "xargs" treating single filenames that | ||||
|
r8779 | contain whitespace as multiple filenames. | ||
|
r11177 | |||
Returns 0 if a match is found, 1 otherwise. | ||||
|
r1437 | """ | ||
|
r7131 | end = opts.get('print0') and '\0' or '\n' | ||
|
r14319 | rev = scmutil.revsingle(repo, opts.get('rev'), None).node() | ||
|
r742 | |||
|
r4196 | ret = 1 | ||
|
r21986 | ctx = repo[rev] | ||
m = scmutil.match(ctx, pats, opts, default='relglob') | ||||
|
r10282 | m.bad = lambda x, y: False | ||
|
r21986 | |||
for abs in ctx.matches(m): | ||||
|
r7131 | if opts.get('fullpath'): | ||
|
r7570 | ui.write(repo.wjoin(abs), end) | ||
|
r724 | else: | ||
|
r6584 | ui.write(((pats and m.rel(abs)) or abs), end) | ||
|
r4196 | ret = 0 | ||
return ret | ||||
|
r627 | |||
|
r14297 | @command('^log|history', | ||
[('f', 'follow', None, | ||||
_('follow changeset history, or file history across copies and renames')), | ||||
('', 'follow-first', None, | ||||
|
r15405 | _('only follow the first parent of merge changesets (DEPRECATED)')), | ||
|
r14297 | ('d', 'date', '', _('show revisions matching date spec'), _('DATE')), | ||
('C', 'copies', None, _('show copied files')), | ||||
('k', 'keyword', [], | ||||
_('do case-insensitive search for a given text'), _('TEXT')), | ||||
('r', 'rev', [], _('show the specified revision or range'), _('REV')), | ||||
('', 'removed', None, _('include revisions where files were removed')), | ||||
|
r15405 | ('m', 'only-merges', None, _('show only merges (DEPRECATED)')), | ||
|
r14297 | ('u', 'user', [], _('revisions committed by user'), _('USER')), | ||
('', 'only-branch', [], | ||||
_('show only changesets within the given named branch (DEPRECATED)'), | ||||
_('BRANCH')), | ||||
('b', 'branch', [], | ||||
_('show changesets within the given named branch'), _('BRANCH')), | ||||
('P', 'prune', [], | ||||
_('do not display revision or any of its ancestors'), _('REV')), | ||||
] + logopts + walkopts, | ||||
|
r21778 | _('[OPTION]... [FILE]'), | ||
inferrepo=True) | ||||
|
r1031 | def log(ui, repo, *pats, **opts): | ||
|
r1437 | """show revision history of entire repository or files | ||
|
r2741 | Print the revision history of the specified files or the entire | ||
project. | ||||
|
r15104 | If no revision range is specified, the default is ``tip:0`` unless | ||
--follow is set, in which case the working directory parent is | ||||
used as the starting revision. | ||||
|
r2741 | File history is shown without following rename or copy history of | ||
|
r8761 | files. Use -f/--follow with a filename to follow history across | ||
renames and copies. --follow without a filename will only show | ||||
|
r15104 | ancestors or descendants of the starting revision. | ||
|
r6163 | |||
|
r8779 | By default this command prints revision number and changeset id, | ||
tags, non-trivial parents, user, date and time, and a summary for | ||||
each commit. When the -v/--verbose switch is used, the list of | ||||
changed files and full commit message are shown. | ||||
|
r3822 | |||
|
r20544 | With --graph the revisions are shown as an ASCII art DAG with the most | ||
recent changeset at the top. | ||||
'o' is a changeset, '@' is a working directory parent, 'x' is obsolete, | ||||
and '+' represents a fork where the changeset from the lines below is a | ||||
|
r21174 | parent of the 'o' merge on the same line. | ||
|
r20544 | |||
|
r12390 | .. note:: | ||
|
r19997 | |||
|
r12390 | log -p/--patch may generate unexpected diff output for merge | ||
changesets, as it will only compare the merge changeset against | ||||
its first parent. Also, only files different from BOTH parents | ||||
will appear in files:. | ||||
|
r11177 | |||
|
r15105 | .. note:: | ||
|
r19997 | |||
|
r15105 | for performance reasons, log FILE may omit duplicate changes | ||
made on branches and will not show deletions. To see all | ||||
changes including duplicates and deletions, use the --removed | ||||
switch. | ||||
|
r15103 | .. container:: verbose | ||
Some examples: | ||||
- changesets with full descriptions and file lists:: | ||||
hg log -v | ||||
- changesets ancestral to the working directory:: | ||||
hg log -f | ||||
- last 10 commits on the current branch:: | ||||
hg log -l 10 -b . | ||||
- changesets showing all modifications of a file, including removals:: | ||||
hg log --removed file.c | ||||
- all changesets that touch a directory, with diffs, excluding merges:: | ||||
hg log -Mp lib/ | ||||
- all revision numbers that match a keyword:: | ||||
hg log -k bug --template "{rev}\\n" | ||||
|
r21944 | - list available log templates:: | ||
hg log -T list | ||||
|
r15103 | - check if a given changeset is included is a tagged release:: | ||
hg log -r "a21ccf and ancestor(1.9)" | ||||
- find all changesets by some user in a date range:: | ||||
hg log -k alice -d "may 2008 to jul 2008" | ||||
- summary of all changesets after the last tag:: | ||||
hg log -r "last(tagged())::" --template "{desc|firstline}\\n" | ||||
|
r15104 | See :hg:`help dates` for a list of formats valid for -d/--date. | ||
See :hg:`help revisions` and :hg:`help revsets` for more about | ||||
specifying revisions. | ||||
|
r16568 | See :hg:`help templates` for more about pre-packaged styles and | ||
specifying custom templates. | ||||
|
r11177 | Returns 0 on success. | ||
|
r1437 | """ | ||
|
r17181 | if opts.get('graph'): | ||
return cmdutil.graphlog(ui, repo, *pats, **opts) | ||||
|
r1756 | |||
|
r21127 | revs, expr, filematcher = cmdutil.getlogrevs(repo, pats, opts) | ||
|
r6190 | limit = cmdutil.loglimit(opts) | ||
|
r1756 | count = 0 | ||
|
r21127 | getrenamed = None | ||
|
r16175 | if opts.get('copies'): | ||
|
r21127 | endrev = None | ||
|
r16175 | if opts.get('rev'): | ||
|
r21127 | endrev = scmutil.revrange(repo, opts.get('rev')).max() + 1 | ||
|
r16175 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) | ||
|
r3197 | |||
|
r21127 | displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) | ||
for rev in revs: | ||||
if count == limit: | ||||
break | ||||
ctx = repo[rev] | ||||
|
r10060 | copies = None | ||
|
r16175 | if getrenamed is not None and rev: | ||
|
r10060 | copies = [] | ||
|
r9662 | for fn in ctx.files(): | ||
rename = getrenamed(fn, rev) | ||||
if rename: | ||||
copies.append((fn, rename[0])) | ||||
|
r21127 | revmatchfn = filematcher and filematcher(ctx.rev()) or None | ||
|
r11488 | displayer.show(ctx, copies=copies, matchfn=revmatchfn) | ||
|
r21127 | if displayer.flush(rev): | ||
|
r18711 | count += 1 | ||
|
r21127 | |||
|
r10152 | displayer.close() | ||
|
r255 | |||
|
r14297 | @command('manifest', | ||
|
r14399 | [('r', 'rev', '', _('revision to display'), _('REV')), | ||
('', 'all', False, _("list files from all revisions"))], | ||||
|
r14297 | _('[-r REV]')) | ||
|
r14399 | def manifest(ui, repo, node=None, rev=None, **opts): | ||
|
r3914 | """output the current or given revision of the project manifest | ||
|
r1437 | |||
Print a list of version controlled files for the given revision. | ||||
|
r8041 | If no revision is given, the first parent of the working directory | ||
|
r8779 | is used, or the null revision if no revision is checked out. | ||
With -v, print file permissions, symlink and executable bits. | ||||
With --debug, print file revision hashes. | ||||
|
r11177 | |||
|
r14399 | If option --all is specified, the list of all files from all revisions | ||
is printed. This includes deleted and renamed files. | ||||
|
r11177 | Returns 0 on success. | ||
|
r1437 | """ | ||
|
r17911 | |||
fm = ui.formatter('manifest', opts) | ||||
|
r14399 | if opts.get('all'): | ||
if rev or node: | ||||
raise util.Abort(_("can't specify a revision with --all")) | ||||
res = [] | ||||
prefix = "data/" | ||||
suffix = ".i" | ||||
plen = len(prefix) | ||||
slen = len(suffix) | ||||
lock = repo.lock() | ||||
try: | ||||
for fn, b, size in repo.store.datafiles(): | ||||
if size != 0 and fn[-slen:] == suffix and fn[:plen] == prefix: | ||||
res.append(fn[plen:-slen]) | ||||
finally: | ||||
lock.release() | ||||
|
r17376 | for f in res: | ||
|
r17911 | fm.startitem() | ||
fm.write("path", '%s\n', f) | ||||
fm.end() | ||||
|
r14399 | return | ||
|
r3736 | |||
|
r5155 | if rev and node: | ||
raise util.Abort(_("please specify just one revision")) | ||||
if not node: | ||||
node = rev | ||||
|
r17911 | char = {'l': '@', 'x': '*', '': ''} | ||
mode = {'l': '644', 'x': '755', '': '644'} | ||||
|
r14319 | ctx = scmutil.revsingle(repo, node) | ||
|
r17911 | mf = ctx.manifest() | ||
|
r6749 | for f in ctx: | ||
|
r17911 | fm.startitem() | ||
fl = ctx[f].flags() | ||||
fm.condwrite(ui.debugflag, 'hash', '%s ', hex(mf[f])) | ||||
fm.condwrite(ui.verbose, 'mode type', '%s %1s ', mode[fl], char[fl]) | ||||
fm.write('path', '%s\n', f) | ||||
fm.end() | ||||
|
r255 | |||
|
r14297 | @command('^merge', | ||
|
r19439 | [('f', 'force', None, | ||
_('force a merge including outstanding changes (DEPRECATED)')), | ||||
|
r14297 | ('r', 'rev', '', _('revision to merge'), _('REV')), | ||
('P', 'preview', None, | ||||
|
r14852 | _('review revisions to merge (no merge is performed)')) | ||
] + mergetoolopts, | ||||
|
r14297 | _('[-P] [-f] [[-r] REV]')) | ||
|
r8387 | def merge(ui, repo, node=None, **opts): | ||
|
r4014 | """merge working directory with another revision | ||
|
r2019 | |||
|
r8779 | The current working directory is updated with all changes made in | ||
the requested revision since the last common predecessor revision. | ||||
|
r7977 | |||
Files that changed between either parent are marked as changed for | ||||
the next commit and a commit must be performed before any further | ||||
|
r8779 | updates to the repository are allowed. The next commit will have | ||
two parents. | ||||
|
r2915 | |||
|
r12750 | ``--tool`` can be used to specify the merge tool used for file | ||
merges. It overrides the HGMERGE environment variable and your | ||||
|
r13891 | configuration files. See :hg:`help merge-tools` for options. | ||
|
r12750 | |||
|
r2915 | If no revision is specified, the working directory's parent is a | ||
|
r8004 | head revision, and the current branch contains exactly one other | ||
head, the other head is merged with by default. Otherwise, an | ||||
|
r8779 | explicit revision with which to merge with must be provided. | ||
|
r11177 | |||
|
r12750 | :hg:`resolve` must be used to resolve unresolved files. | ||
|
r11452 | To undo an uncommitted merge, use :hg:`update --clean .` which | ||
will check out a clean copy of the original merge parent, losing | ||||
all changes. | ||||
|
r11177 | Returns 0 on success, 1 if there are unresolved files. | ||
|
r2019 | """ | ||
|
r2806 | |||
|
r8387 | if opts.get('rev') and node: | ||
|
r4450 | raise util.Abort(_("please specify just one revision")) | ||
if not node: | ||||
|
r8387 | node = opts.get('rev') | ||
|
r4450 | |||
|
r16708 | if node: | ||
node = scmutil.revsingle(repo, node).node() | ||||
if not node and repo._bookmarkcurrent: | ||||
bmheads = repo.bookmarkheads(repo._bookmarkcurrent) | ||||
|
r18122 | curhead = repo[repo._bookmarkcurrent].node() | ||
|
r16708 | if len(bmheads) == 2: | ||
if curhead == bmheads[0]: | ||||
node = bmheads[1] | ||||
else: | ||||
node = bmheads[0] | ||||
elif len(bmheads) > 2: | ||||
raise util.Abort(_("multiple matching bookmarks to merge - " | ||||
"please merge with an explicit rev or bookmark"), | ||||
hint=_("run 'hg heads' to see all heads")) | ||||
elif len(bmheads) <= 1: | ||||
raise util.Abort(_("no matching bookmark to merge - " | ||||
"please merge with an explicit rev or bookmark"), | ||||
hint=_("run 'hg heads' to see all heads")) | ||||
if not node and not repo._bookmarkcurrent: | ||||
|
r13047 | branch = repo[None].branch() | ||
|
r6844 | bheads = repo.branchheads(branch) | ||
|
r16708 | nbhs = [bh for bh in bheads if not repo[bh].bookmarks()] | ||
if len(nbhs) > 2: | ||||
|
r14198 | raise util.Abort(_("branch '%s' has %d heads - " | ||
"please merge with an explicit rev") | ||||
% (branch, len(bheads)), | ||||
hint=_("run 'hg heads .' to see heads")) | ||||
|
r6723 | |||
|
r13878 | parent = repo.dirstate.p1() | ||
|
r17386 | if len(nbhs) <= 1: | ||
|
r16708 | if len(bheads) > 1: | ||
raise util.Abort(_("heads are bookmarked - " | ||||
"please merge with an explicit rev"), | ||||
hint=_("run 'hg heads' to see all heads")) | ||||
|
r6723 | if len(repo.heads()) > 1: | ||
|
r14198 | raise util.Abort(_("branch '%s' has one head - " | ||
"please merge with an explicit rev") | ||||
% branch, | ||||
hint=_("run 'hg heads' to see all heads")) | ||||
|
r15619 | msg, hint = _('nothing to merge'), None | ||
|
r15618 | if parent != repo.lookup(branch): | ||
|
r15619 | hint = _("use 'hg update' instead") | ||
raise util.Abort(msg, hint=hint) | ||||
|
r5242 | |||
|
r6723 | if parent not in bheads: | ||
|
r14198 | raise util.Abort(_('working directory not at a head revision'), | ||
hint=_("use 'hg update' or merge with an " | ||||
"explicit revision")) | ||||
|
r16708 | if parent == nbhs[0]: | ||
node = nbhs[-1] | ||||
else: | ||||
node = nbhs[0] | ||||
|
r8387 | |||
|
r8834 | if opts.get('preview'): | ||
|
r10505 | # find nodes that are ancestors of p2 but not of p1 | ||
p1 = repo.lookup('.') | ||||
p2 = repo.lookup(node) | ||||
nodes = repo.changelog.findmissing(common=[p1], heads=[p2]) | ||||
|
r8387 | displayer = cmdutil.show_changeset(ui, repo, opts) | ||
|
r10505 | for node in nodes: | ||
displayer.show(repo[node]) | ||||
|
r10152 | displayer.close() | ||
|
r8387 | return 0 | ||
|
r12788 | try: | ||
# ui.forcemerge is an internal variable, do not document | ||||
|
r20790 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'merge') | ||
|
r12788 | return hg.merge(repo, node, force=opts.get('force')) | ||
finally: | ||||
|
r20790 | ui.setconfig('ui', 'forcemerge', '', 'merge') | ||
|
r2029 | |||
|
r14297 | @command('outgoing|out', | ||
[('f', 'force', None, _('run even when the destination is unrelated')), | ||||
('r', 'rev', [], | ||||
_('a changeset intended to be included in the destination'), _('REV')), | ||||
('n', 'newest-first', None, _('show newest record first')), | ||||
('B', 'bookmarks', False, _('compare bookmarks')), | ||||
('b', 'branch', [], _('a specific branch you would like to push'), | ||||
_('BRANCH')), | ||||
] + logopts + remoteopts + subrepoopts, | ||||
_('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')) | ||||
|
r2494 | def outgoing(ui, repo, dest=None, **opts): | ||
|
r10376 | """show changesets not found in the destination | ||
|
r1437 | |||
|
r8004 | Show changesets not found in the specified destination repository | ||
or the default push location. These are the changesets that would | ||||
be pushed if a push was requested. | ||||
|
r1811 | |||
|
r10376 | See pull for details of valid destination formats. | ||
|
r11177 | |||
Returns 0 if there are outgoing changes, 1 otherwise. | ||||
|
r1437 | """ | ||
|
r17182 | if opts.get('graph'): | ||
cmdutil.checkunsupportedgraphflags([], opts) | ||||
|
r21050 | o, other = hg._outgoing(ui, repo, dest, opts) | ||
|
r21049 | if not o: | ||
|
r21051 | cmdutil.outgoinghooks(ui, repo, other, opts, o) | ||
|
r17182 | return | ||
revdag = cmdutil.graphrevs(repo, o, opts) | ||||
displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) | ||||
showparents = [ctx.node() for ctx in repo[None].parents()] | ||||
cmdutil.displaygraph(ui, revdag, displayer, showparents, | ||||
graphmod.asciiedges) | ||||
|
r21051 | cmdutil.outgoinghooks(ui, repo, other, opts, o) | ||
|
r17182 | return 0 | ||
|
r13366 | |||
if opts.get('bookmarks'): | ||||
dest = ui.expandpath(dest or 'default-push', dest or 'default') | ||||
dest, branches = hg.parseurl(dest, opts.get('branch')) | ||||
|
r14556 | other = hg.peer(repo, opts, dest) | ||
|
r13453 | if 'bookmarks' not in other.listkeys('namespaces'): | ||
ui.warn(_("remote doesn't support bookmarks\n")) | ||||
return 0 | ||||
|
r14076 | ui.status(_('comparing with %s\n') % util.hidepassword(dest)) | ||
|
r13366 | return bookmarks.diff(ui, other, repo) | ||
|
r14360 | repo._subtoppath = ui.expandpath(dest or 'default-push', dest or 'default') | ||
try: | ||||
|
r14362 | return hg.outgoing(ui, repo, dest, opts) | ||
|
r14360 | finally: | ||
del repo._subtoppath | ||||
|
r920 | |||
|
r14297 | @command('parents', | ||
[('r', 'rev', '', _('show parents of the specified revision'), _('REV')), | ||||
] + templateopts, | ||||
|
r21778 | _('[-r REV] [FILE]'), | ||
inferrepo=True) | ||||
|
r3658 | def parents(ui, repo, file_=None, **opts): | ||
|
r8026 | """show the parents of the working directory or revision | ||
|
r1437 | |||
|
r8004 | Print the working directory's parent revisions. If a revision is | ||
|
r8033 | given via -r/--rev, the parent of that revision will be printed. | ||
|
r8779 | If a file argument is given, the revision in which the file was | ||
last changed (before the working directory revision or the | ||||
argument to --rev if given) is printed. | ||||
|
r11177 | |||
Returns 0 on success. | ||||
|
r1437 | """ | ||
|
r12925 | |||
|
r14319 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) | ||
|
r5298 | |||
|
r4586 | if file_: | ||
|
r14671 | m = scmutil.match(ctx, (file_,), opts) | ||
|
r6582 | if m.anypats() or len(m.files()) != 1: | ||
|
r8761 | raise util.Abort(_('can only specify an explicit filename')) | ||
|
r6582 | file_ = m.files()[0] | ||
|
r5298 | filenodes = [] | ||
for cp in ctx.parents(): | ||||
if not cp: | ||||
continue | ||||
try: | ||||
filenodes.append(cp.filenode(file_)) | ||||
|
r7633 | except error.LookupError: | ||
|
r5298 | pass | ||
if not filenodes: | ||||
raise util.Abort(_("'%s' not found in manifest!") % file_) | ||||
|
r19333 | p = [] | ||
for fn in filenodes: | ||||
fctx = repo.filectx(file_, fileid=fn) | ||||
p.append(fctx.node()) | ||||
|
r255 | else: | ||
|
r5298 | p = [cp.node() for cp in ctx.parents()] | ||
|
r255 | |||
|
r3643 | displayer = cmdutil.show_changeset(ui, repo, opts) | ||
|
r255 | for n in p: | ||
|
r1092 | if n != nullid: | ||
|
r7743 | displayer.show(repo[n]) | ||
|
r10152 | displayer.close() | ||
|
r255 | |||
|
r21775 | @command('paths', [], _('[NAME]'), optionalrepo=True) | ||
|
r1858 | def paths(ui, repo, search=None): | ||
|
r7691 | """show aliases for remote repositories | ||
|
r8004 | Show definition of symbolic path name NAME. If no name is given, | ||
|
r8779 | show definition of all available names. | ||
|
r7743 | |||
|
r14331 | Option -q/--quiet suppresses all output when searching for NAME | ||
and shows only the path names when listing all definitions. | ||||
|
r12083 | Path names are defined in the [paths] section of your | ||
configuration file and in ``/etc/mercurial/hgrc``. If run inside a | ||||
|
r11009 | repository, ``.hg/hgrc`` is used, too. | ||
|
r7693 | |||
|
r11007 | The path names ``default`` and ``default-push`` have a special | ||
meaning. When performing a push or pull operation, they are used | ||||
as fallbacks if no location is specified on the command-line. | ||||
When ``default-push`` is set, it will be used for push and | ||||
``default`` will be used for pull; otherwise ``default`` is used | ||||
as the fallback for both. When cloning a repository, the clone | ||||
source is written as ``default`` in ``.hg/hgrc``. Note that | ||||
|
r11009 | ``default`` and ``default-push`` apply to all inbound (e.g. | ||
:hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email` and | ||||
:hg:`bundle`) operations. | ||||
|
r10933 | |||
|
r10973 | See :hg:`help urls` for more information. | ||
|
r11507 | |||
Returns 0 on success. | ||||
|
r1437 | """ | ||
|
r779 | if search: | ||
for name, path in ui.configitems("paths"): | ||||
if name == search: | ||||
|
r14331 | ui.status("%s\n" % util.hidepassword(path)) | ||
|
r779 | return | ||
|
r14331 | if not ui.quiet: | ||
ui.warn(_("not found!\n")) | ||||
|
r779 | return 1 | ||
else: | ||||
for name, path in ui.configitems("paths"): | ||||
|
r14331 | if ui.quiet: | ||
ui.write("%s\n" % name) | ||||
else: | ||||
ui.write("%s = %s\n" % (name, util.hidepassword(path))) | ||||
|
r779 | |||
|
r17981 | @command('phase', | ||
|
r15849 | [('p', 'public', False, _('set changeset phase to public')), | ||
('d', 'draft', False, _('set changeset phase to draft')), | ||||
('s', 'secret', False, _('set changeset phase to secret')), | ||||
|
r15830 | ('f', 'force', False, _('allow to move boundary backward')), | ||
|
r15855 | ('r', 'rev', [], _('target revision'), _('REV')), | ||
|
r15830 | ], | ||
|
r15854 | _('[-p|-d|-s] [-f] [-r] REV...')) | ||
|
r15830 | def phase(ui, repo, *revs, **opts): | ||
"""set or show the current phase name | ||||
With no argument, show the phase name of specified revisions. | ||||
|
r15851 | With one of -p/--public, -d/--draft or -s/--secret, change the | ||
|
r15850 | phase value of the specified revisions. | ||
|
r15830 | |||
Unless -f/--force is specified, :hg:`phase` won't move changeset from a | ||||
|
r15850 | lower phase to an higher phase. Phases are ordered as follows:: | ||
|
r15832 | |||
public < draft < secret | ||||
|
r15906 | |||
|
r20633 | Returns 0 on success, 1 if no phases were changed or some could not | ||
|
r16097 | be changed. | ||
|
r15830 | """ | ||
# search for a unique phase argument | ||||
targetphase = None | ||||
|
r15853 | for idx, name in enumerate(phases.phasenames): | ||
|
r15830 | if opts[name]: | ||
if targetphase is not None: | ||||
|
r15833 | raise util.Abort(_('only one phase can be specified')) | ||
|
r15830 | targetphase = idx | ||
# look for specified revision | ||||
revs = list(revs) | ||||
revs.extend(opts['rev']) | ||||
if not revs: | ||||
|
r15958 | raise util.Abort(_('no revisions specified')) | ||
|
r15831 | |||
|
r16024 | revs = scmutil.revrange(repo, revs) | ||
|
r15830 | lock = None | ||
|
r15906 | ret = 0 | ||
|
r15830 | if targetphase is None: | ||
# display | ||||
|
r16024 | for r in revs: | ||
ctx = repo[r] | ||||
|
r15830 | ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr())) | ||
else: | ||||
|
r22050 | tr = None | ||
|
r15830 | lock = repo.lock() | ||
try: | ||||
|
r22050 | tr = repo.transaction("phase") | ||
|
r15830 | # set phase | ||
|
r16659 | if not revs: | ||
|
r17299 | raise util.Abort(_('empty revision set')) | ||
|
r16659 | nodes = [repo[r].node() for r in revs] | ||
|
r16657 | olddata = repo._phasecache.getphaserevs(repo)[:] | ||
|
r22069 | phases.advanceboundary(repo, tr, targetphase, nodes) | ||
|
r15830 | if opts['force']: | ||
|
r22070 | phases.retractboundary(repo, tr, targetphase, nodes) | ||
|
r22050 | tr.close() | ||
|
r15830 | finally: | ||
|
r22050 | if tr is not None: | ||
tr.release() | ||||
|
r15830 | lock.release() | ||
|
r18210 | # moving revision from public to draft may hide them | ||
# We have to check result on an unfiltered repository | ||||
unfi = repo.unfiltered() | ||||
newdata = repo._phasecache.getphaserevs(unfi) | ||||
|
r16715 | changes = sum(o != newdata[i] for i, o in enumerate(olddata)) | ||
|
r18210 | cl = unfi.changelog | ||
|
r16715 | rejected = [n for n in nodes | ||
|
r18209 | if newdata[cl.rev(n)] < targetphase] | ||
|
r16715 | if rejected: | ||
|
r20093 | ui.warn(_('cannot move %i changesets to a higher ' | ||
|
r16715 | 'phase, use --force\n') % len(rejected)) | ||
ret = 1 | ||||
if changes: | ||||
msg = _('phase changed for %i changesets\n') % changes | ||||
if ret: | ||||
ui.status(msg) | ||||
|
r15906 | else: | ||
|
r16715 | ui.note(msg) | ||
else: | ||||
ui.warn(_('no phases changed\n')) | ||||
ret = 1 | ||||
|
r15968 | return ret | ||
|
r15830 | |||
|
r5224 | def postincoming(ui, repo, modheads, optupdate, checkout): | ||
|
r2019 | if modheads == 0: | ||
|
r16107 | return | ||
|
r2019 | if optupdate: | ||
|
r19523 | checkout, movemarkfrom = bookmarks.calculateupdate(ui, repo, checkout) | ||
|
r14485 | try: | ||
|
r16019 | ret = hg.update(repo, checkout) | ||
|
r14485 | except util.Abort, inst: | ||
|
r16230 | ui.warn(_("not updating: %s\n") % str(inst)) | ||
|
r19797 | if inst.hint: | ||
ui.warn(_("(%s)\n") % inst.hint) | ||||
|
r14485 | return 0 | ||
|
r16019 | if not ret and not checkout: | ||
if bookmarks.update(repo, [movemarkfrom], repo['.'].node()): | ||||
ui.status(_("updating bookmark %s\n") % repo._bookmarkcurrent) | ||||
return ret | ||||
|
r2019 | if modheads > 1: | ||
|
r13804 | currentbranchheads = len(repo.branchheads()) | ||
if currentbranchheads == modheads: | ||||
|
r13803 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) | ||
|
r13804 | elif currentbranchheads > 1: | ||
|
r16683 | ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to " | ||
"merge)\n")) | ||||
|
r2019 | else: | ||
|
r13803 | ui.status(_("(run 'hg heads' to see heads)\n")) | ||
|
r2019 | else: | ||
ui.status(_("(run 'hg update' to get a working copy)\n")) | ||||
|
r2029 | |||
|
r14297 | @command('^pull', | ||
[('u', 'update', None, | ||||
_('update to new branch head if changesets were pulled')), | ||||
('f', 'force', None, _('run even when remote repository is unrelated')), | ||||
('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), | ||||
('B', 'bookmark', [], _("bookmark to pull"), _('BOOKMARK')), | ||||
('b', 'branch', [], _('a specific branch you would like to pull'), | ||||
_('BRANCH')), | ||||
] + remoteopts, | ||||
_('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')) | ||||
|
r404 | def pull(ui, repo, source="default", **opts): | ||
|
r1437 | """pull changes from the specified source | ||
|
r8779 | Pull changes from a remote repository to a local one. | ||
|
r1437 | |||
This finds all changes from the repository at the specified path | ||||
|
r8779 | or URL and adds them to a local repository (the current one unless | ||
-R is specified). By default, this does not update the copy of the | ||||
project in the working directory. | ||||
|
r11193 | Use :hg:`incoming` if you want to see what would have been added | ||
by a pull at the time you issued this command. If you then decide | ||||
to add those changes to the repository, you should use :hg:`pull | ||||
-r X` where ``X`` is the last changeset listed by :hg:`incoming`. | ||||
|
r7980 | |||
|
r7693 | If SOURCE is omitted, the 'default' path will be used. | ||
|
r10973 | See :hg:`help urls` for more information. | ||
|
r11177 | |||
|
r16107 | Returns 0 on success, 1 if an update had unresolved files. | ||
|
r1437 | """ | ||
|
r10379 | source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) | ||
|
r14556 | other = hg.peer(repo, opts, source) | ||
|
r20576 | try: | ||
ui.status(_('pulling from %s\n') % util.hidepassword(source)) | ||||
revs, checkout = hg.addbranchrevs(repo, other, branches, | ||||
opts.get('rev')) | ||||
remotebookmarks = other.listkeys('bookmarks') | ||||
if opts.get('bookmark'): | ||||
if not revs: | ||||
revs = [] | ||||
for b in opts['bookmark']: | ||||
if b not in remotebookmarks: | ||||
raise util.Abort(_('remote bookmark %s not found!') % b) | ||||
revs.append(remotebookmarks[b]) | ||||
if revs: | ||||
try: | ||||
revs = [other.lookup(rev) for rev in revs] | ||||
except error.CapabilityError: | ||||
err = _("other repository doesn't support revision lookup, " | ||||
"so a rev cannot be specified.") | ||||
raise util.Abort(err) | ||||
modheads = repo.pull(other, heads=revs, force=opts.get('force')) | ||||
bookmarks.updatefromremote(ui, repo, remotebookmarks, source) | ||||
if checkout: | ||||
checkout = str(repo.changelog.rev(other.lookup(checkout))) | ||||
repo._subtoppath = source | ||||
|
r5259 | try: | ||
|
r20576 | ret = postincoming(ui, repo, modheads, opts.get('update'), checkout) | ||
finally: | ||||
del repo._subtoppath | ||||
# update specified bookmarks | ||||
if opts.get('bookmark'): | ||||
marks = repo._bookmarks | ||||
for b in opts['bookmark']: | ||||
# explicit pull overrides local bookmark if any | ||||
ui.status(_("importing bookmark %s\n") % b) | ||||
marks[b] = repo[remotebookmarks[b]].node() | ||||
marks.write() | ||||
|
r12852 | finally: | ||
|
r20576 | other.close() | ||
|
r13368 | return ret | ||
|
r14297 | @command('^push', | ||
[('f', 'force', None, _('force push')), | ||||
('r', 'rev', [], | ||||
_('a changeset intended to be included in the destination'), | ||||
_('REV')), | ||||
('B', 'bookmark', [], _("bookmark to push"), _('BOOKMARK')), | ||||
('b', 'branch', [], | ||||
_('a specific branch you would like to push'), _('BRANCH')), | ||||
('', 'new-branch', False, _('allow pushing a new branch')), | ||||
] + remoteopts, | ||||
_('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')) | ||||
|
r2494 | def push(ui, repo, dest=None, **opts): | ||
|
r1437 | """push changes to the specified destination | ||
|
r11217 | Push changesets from the local repository to the specified | ||
destination. | ||||
This operation is symmetrical to pull: it is identical to a pull | ||||
in the destination repository from the current one. | ||||
By default, push will not allow creation of new heads at the | ||||
destination, since multiple heads would make it unclear which head | ||||
to use. In this situation, it is recommended to pull and merge | ||||
before pushing. | ||||
|
r11219 | Use --new-branch if you want to allow push to create a new named | ||
branch that is not present at the destination. This allows you to | ||||
only create a new branch without forcing other changes. | ||||
|
r19935 | .. note:: | ||
|
r19997 | |||
|
r19941 | Extra care should be taken with the -f/--force option, | ||
|
r19935 | which will push all new heads on all branches, an action which will | ||
almost always cause confusion for collaborators. | ||||
|
r11217 | |||
If -r/--rev is used, the specified revision and all its ancestors | ||||
will be pushed to the remote repository. | ||||
|
r7693 | |||
|
r17190 | If -B/--bookmark is used, the specified bookmarked revision, its | ||
ancestors, and the bookmark will be pushed to the remote | ||||
repository. | ||||
|
r10973 | Please see :hg:`help urls` for important details about ``ssh://`` | ||
|
r8004 | URLs. If DESTINATION is omitted, a default path will be used. | ||
|
r11177 | |||
Returns 0 if push was successful, 1 if nothing to push. | ||||
|
r1437 | """ | ||
|
r13368 | |||
if opts.get('bookmark'): | ||||
|
r20790 | ui.setconfig('bookmarks', 'pushing', opts['bookmark'], 'push') | ||
|
r13368 | for b in opts['bookmark']: | ||
# translate -B options to -r so changesets get pushed | ||||
if b in repo._bookmarks: | ||||
opts.setdefault('rev', []).append(b) | ||||
else: | ||||
# if we try to push a deleted bookmark, translate it to null | ||||
# this lets simultaneous -r, -b options continue working | ||||
opts.setdefault('rev', []).append("null") | ||||
|
r10365 | dest = ui.expandpath(dest or 'default-push', dest or 'default') | ||
|
r10379 | dest, branches = hg.parseurl(dest, opts.get('branch')) | ||
|
r14076 | ui.status(_('pushing to %s\n') % util.hidepassword(dest)) | ||
|
r10365 | revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) | ||
|
r20558 | try: | ||
other = hg.peer(repo, opts, dest) | ||||
except error.RepoError: | ||||
if dest == "default-push": | ||||
raise util.Abort(_("default repository not configured!"), | ||||
hint=_('see the "path" section in "hg help config"')) | ||||
else: | ||||
raise | ||||
|
r4478 | if revs: | ||
|
r17168 | revs = [repo.lookup(r) for r in scmutil.revrange(repo, revs)] | ||
|
r8815 | |||
|
r12852 | repo._subtoppath = dest | ||
try: | ||||
# push subrepos depth-first for coherent ordering | ||||
c = repo[''] | ||||
subs = c.substate # only repos that are committed | ||||
for s in sorted(subs): | ||||
|
r21034 | result = c.sub(s).push(opts) | ||
if result == 0: | ||||
return not result | ||||
|
r12852 | finally: | ||
del repo._subtoppath | ||||
|
r13368 | result = repo.push(other, opts.get('force'), revs=revs, | ||
newbranch=opts.get('new_branch')) | ||||
|
r16023 | result = not result | ||
|
r13368 | |||
if opts.get('bookmark'): | ||||
|
r20026 | bresult = bookmarks.pushtoremote(ui, repo, other, opts['bookmark']) | ||
if bresult == 2: | ||||
return 2 | ||||
if not result and bresult: | ||||
result = 2 | ||||
|
r13368 | |||
return result | ||||
|
r319 | |||
|
r14297 | @command('recover', []) | ||
|
r245 | def recover(ui, repo): | ||
|
r1437 | """roll back an interrupted transaction | ||
Recover from an interrupted commit or pull. | ||||
|
r8004 | This command tries to fix the repository status after an | ||
interrupted operation. It should only be necessary when Mercurial | ||||
suggests it. | ||||
|
r11177 | |||
Returns 0 if successful, 1 if nothing to recover or verify fails. | ||||
|
r1437 | """ | ||
|
r1516 | if repo.recover(): | ||
|
r2778 | return hg.verify(repo) | ||
|
r2057 | return 1 | ||
|
r245 | |||
|
r14297 | @command('^remove|rm', | ||
[('A', 'after', None, _('record delete for missing files')), | ||||
('f', 'force', None, | ||||
_('remove (and delete) file even if added or modified')), | ||||
] + walkopts, | ||||
|
r21778 | _('[OPTION]... FILE...'), | ||
inferrepo=True) | ||||
|
r2179 | def remove(ui, repo, *pats, **opts): | ||
|
r1437 | """remove the specified files on the next commit | ||
|
r15114 | Schedule the indicated files for removal from the current branch. | ||
This command schedules the files to be removed at the next commit. | ||||
To undo a remove before that, see :hg:`revert`. To undo added | ||||
files, see :hg:`forget`. | ||||
.. container:: verbose | ||||
-A/--after can be used to remove only files that have already | ||||
been deleted, -f/--force can be used to force deletion, and -Af | ||||
can be used to remove files from the next revision without | ||||
deleting them from the working directory. | ||||
The following table details the behavior of remove for different | ||||
file states (columns) and option combinations (rows). The file | ||||
states are Added [A], Clean [C], Modified [M] and Missing [!] | ||||
(as reported by :hg:`status`). The actions are Warn, Remove | ||||
(from branch) and Delete (from disk): | ||||
|
r15037 | |||
|
r19960 | ========= == == == == | ||
opt/state A C M ! | ||||
========= == == == == | ||||
none W RD W R | ||||
-f R RD RD R | ||||
-A W W W R | ||||
-Af R R R R | ||||
========= == == == == | ||||
|
r2309 | |||
|
r15114 | Note that remove never deletes files in Added [A] state from the | ||
working directory, not even if option --force is specified. | ||||
|
r11177 | |||
Returns 0 on success, 1 if any warnings encountered. | ||||
|
r1437 | """ | ||
|
r6346 | |||
|
r11177 | ret = 0 | ||
|
r6346 | after, force = opts.get('after'), opts.get('force') | ||
if not pats and not after: | ||||
|
r2179 | raise util.Abort(_('no files specified')) | ||
|
r6346 | |||
|
r14671 | m = scmutil.match(repo[None], pats, opts) | ||
|
r6761 | s = repo.status(match=m, clean=True) | ||
modified, added, deleted, clean = s[0], s[1], s[3], s[6] | ||||
|
r17848 | # warn about failure to delete explicit files/dirs | ||
wctx = repo[None] | ||||
|
r8533 | for f in m.files(): | ||
|
r17848 | if f in repo.dirstate or f in wctx.dirs(): | ||
continue | ||||
if os.path.exists(m.rel(f)): | ||||
if os.path.isdir(m.rel(f)): | ||||
ui.warn(_('not removing %s: no tracked files\n') % m.rel(f)) | ||||
else: | ||||
|
r14604 | ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) | ||
|
r17848 | # missing files will generate a warning elsewhere | ||
ret = 1 | ||||
|
r8533 | |||
|
r6761 | if force: | ||
|
r14450 | list = modified + deleted + clean + added | ||
|
r6761 | elif after: | ||
|
r14450 | list = deleted | ||
|
r12129 | for f in modified + added + clean: | ||
|
r18053 | ui.warn(_('not removing %s: file still exists\n') % m.rel(f)) | ||
|
r12129 | ret = 1 | ||
|
r6761 | else: | ||
|
r14450 | list = deleted + clean | ||
|
r12129 | for f in modified: | ||
ui.warn(_('not removing %s: file is modified (use -f' | ||||
' to force removal)\n') % m.rel(f)) | ||||
ret = 1 | ||||
for f in added: | ||||
|
r15115 | ui.warn(_('not removing %s: file has been marked for add' | ||
' (use forget to undo)\n') % m.rel(f)) | ||||
|
r12129 | ret = 1 | ||
|
r6761 | |||
|
r14450 | for f in sorted(list): | ||
|
r6761 | if ui.verbose or not m.exact(f): | ||
ui.status(_('removing %s\n') % m.rel(f)) | ||||
|
r6346 | |||
|
r14450 | wlock = repo.wlock() | ||
try: | ||||
if not after: | ||||
for f in list: | ||||
if f in added: | ||||
continue # we never unlink added files on remove | ||||
|
r18143 | util.unlinkpath(repo.wjoin(f), ignoremissing=True) | ||
|
r14450 | repo[None].forget(list) | ||
finally: | ||||
wlock.release() | ||||
|
r11177 | return ret | ||
|
r245 | |||
|
r14297 | @command('rename|move|mv', | ||
[('A', 'after', None, _('record a rename that has already occurred')), | ||||
('f', 'force', None, _('forcibly copy over an existing managed file')), | ||||
] + walkopts + dryrunopts, | ||||
_('[OPTION]... SOURCE... DEST')) | ||||
|
r1253 | def rename(ui, repo, *pats, **opts): | ||
|
r1437 | """rename files; equivalent of copy + remove | ||
|
r8004 | Mark dest as copies of sources; mark sources for deletion. If dest | ||
is a directory, copies are put in that directory. If dest is a | ||||
file, there can only be one source. | ||||
|
r1437 | |||
By default, this command copies the contents of files as they | ||||
|
r8033 | exist in the working directory. If invoked with -A/--after, the | ||
|
r1437 | operation is recorded, but no copying is performed. | ||
|
r7807 | This command takes effect at the next commit. To undo a rename | ||
|
r11193 | before that, see :hg:`revert`. | ||
|
r11177 | |||
Returns 0 on success, 1 if errors are encountered. | ||||
|
r1437 | """ | ||
|
r4914 | wlock = repo.wlock(False) | ||
|
r4915 | try: | ||
|
r5610 | return cmdutil.copy(ui, repo, pats, opts, rename=True) | ||
|
r4915 | finally: | ||
|
r8109 | wlock.release() | ||
|
r1253 | |||
|
r14297 | @command('resolve', | ||
[('a', 'all', None, _('select all unresolved files')), | ||||
('l', 'list', None, _('list state of files needing merge')), | ||||
('m', 'mark', None, _('mark files as resolved')), | ||||
('u', 'unmark', None, _('mark files as unresolved')), | ||||
('n', 'no-status', None, _('hide status prefix'))] | ||||
|
r14852 | + mergetoolopts + walkopts, | ||
|
r21778 | _('[OPTION]... [FILE]...'), | ||
inferrepo=True) | ||||
|
r6518 | def resolve(ui, repo, *pats, **opts): | ||
|
r11836 | """redo merges or set/view the merge status of files | ||
Merges with unresolved conflicts are often the result of | ||||
|
r12083 | non-interactive merging using the ``internal:merge`` configuration | ||
setting, or a command-line merge tool like ``diff3``. The resolve | ||||
command is used to manage the files involved in a merge, after | ||||
:hg:`merge` has been run, and before :hg:`commit` is run (i.e. the | ||||
|
r16009 | working directory must have two parents). See :hg:`help | ||
merge-tools` for information on configuring merge tools. | ||||
|
r11836 | |||
The resolve command can be used in the following ways: | ||||
|
r12809 | - :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified | ||
|
r12750 | files, discarding any previous merge attempts. Re-merging is not | ||
|
r11836 | performed for files already marked as resolved. Use ``--all/-a`` | ||
|
r15042 | to select all unresolved files. ``--tool`` can be used to specify | ||
|
r12750 | the merge tool used for the given files. It overrides the HGMERGE | ||
|
r15232 | environment variable and your configuration files. Previous file | ||
contents are saved with a ``.orig`` suffix. | ||||
|
r11836 | |||
- :hg:`resolve -m [FILE]`: mark a file as having been resolved | ||||
(e.g. after having manually fixed-up the files). The default is | ||||
to mark all unresolved files. | ||||
- :hg:`resolve -u [FILE]...`: mark a file as unresolved. The | ||||
default is to mark all resolved files. | ||||
- :hg:`resolve -l`: list files which had or still have conflicts. | ||||
In the printed list, ``U`` = unresolved and ``R`` = resolved. | ||||
Note that Mercurial will not let you commit files with unresolved | ||||
merge conflicts. You must use :hg:`resolve -m ...` before you can | ||||
commit after a conflicting merge. | ||||
|
r11177 | |||
Returns 0 on success, 1 if any files fail a resolve attempt. | ||||
|
r6518 | """ | ||
|
r9646 | all, mark, unmark, show, nostatus = \ | ||
[opts.get(o) for o in 'all mark unmark list no_status'.split()] | ||||
|
r7527 | |||
if (show and (mark or unmark)) or (mark and unmark): | ||||
|
r6518 | raise util.Abort(_("too many options specified")) | ||
|
r7527 | if pats and all: | ||
raise util.Abort(_("can't specify --all and patterns")) | ||||
if not (all or pats or show or mark or unmark): | ||||
|
r21940 | raise util.Abort(_('no files or directories specified'), | ||
hint=('use --all to remerge all files')) | ||||
|
r6518 | |||
|
r21709 | wlock = repo.wlock() | ||
try: | ||||
ms = mergemod.mergestate(repo) | ||||
|
r21720 | |||
if not ms.active() and not show: | ||||
raise util.Abort( | ||||
_('resolve command not applicable when not merging')) | ||||
|
r21709 | m = scmutil.match(repo[None], pats, opts) | ||
ret = 0 | ||||
|
r21720 | didwork = False | ||
|
r21709 | |||
for f in ms: | ||||
|
r21720 | if not m(f): | ||
continue | ||||
didwork = True | ||||
if show: | ||||
if nostatus: | ||||
ui.write("%s\n" % f) | ||||
|
r9646 | else: | ||
|
r21720 | ui.write("%s %s\n" % (ms[f].upper(), f), | ||
label='resolve.' + | ||||
{'u': 'unresolved', 'r': 'resolved'}[ms[f]]) | ||||
elif mark: | ||||
ms.mark(f, "r") | ||||
elif unmark: | ||||
ms.mark(f, "u") | ||||
|
r6518 | else: | ||
|
r21720 | wctx = repo[None] | ||
# backup pre-resolve (merge uses .orig for its own purposes) | ||||
a = repo.wjoin(f) | ||||
util.copyfile(a, a + ".resolve") | ||||
try: | ||||
# resolve file | ||||
ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), | ||||
'resolve') | ||||
if ms.resolve(f, wctx): | ||||
ret = 1 | ||||
finally: | ||||
ui.setconfig('ui', 'forcemerge', '', 'resolve') | ||||
ms.commit() | ||||
# replace filemerge's .orig file with our resolve file | ||||
util.rename(a + ".resolve", a + ".orig") | ||||
|
r21709 | |||
ms.commit() | ||||
|
r21720 | |||
if not didwork and pats: | ||||
|
r21721 | ui.warn(_("arguments do not match paths that need resolving\n")) | ||
|
r21720 | |||
|
r21709 | finally: | ||
wlock.release() | ||||
|
r21266 | # Nudge users into finishing an unfinished operation. We don't print | ||
# this with the list/show operation because we want list/show to remain | ||||
# machine readable. | ||||
if not list(ms.unresolved()) and not show: | ||||
|
r21947 | ui.status(_('(no more unresolved files)\n')) | ||
|
r21266 | |||
|
r11177 | return ret | ||
|
r7847 | |||
|
r14297 | @command('revert', | ||
[('a', 'all', None, _('revert all changes when no arguments given')), | ||||
('d', 'date', '', _('tipmost revision matching date'), _('DATE')), | ||||
('r', 'rev', '', _('revert to the specified revision'), _('REV')), | ||||
|
r15009 | ('C', 'no-backup', None, _('do not save backup copies of files')), | ||
|
r14297 | ] + walkopts + dryrunopts, | ||
_('[OPTION]... [-r REV] [NAME]...')) | ||||
|
r1472 | def revert(ui, repo, *pats, **opts): | ||
|
r14540 | """restore files to their checkout state | ||
|
r5574 | |||
|
r12390 | .. note:: | ||
|
r19997 | |||
|
r14541 | To check out earlier revisions, you should use :hg:`update REV`. | ||
|
r19217 | To cancel an uncommitted merge (and lose your changes), | ||
use :hg:`update --clean .`. | ||||
|
r2204 | |||
|
r14544 | With no revision specified, revert the specified files or directories | ||
|
r14903 | to the contents they had in the parent of the working directory. | ||
|
r14544 | This restores the contents of files to an unmodified | ||
|
r14903 | state and unschedules adds, removes, copies, and renames. If the | ||
working directory has two parents, you must explicitly specify a | ||||
revision. | ||||
|
r1811 | |||
|
r14544 | Using the -r/--rev or -d/--date options, revert the given files or | ||
|
r14557 | directories to their states as of a specific revision. Because | ||
|
r14546 | revert does not change the working directory parents, this will | ||
cause these files to appear modified. This can be helpful to "back | ||||
|
r14547 | out" some or all of an earlier change. See :hg:`backout` for a | ||
related method. | ||||
|
r1437 | |||
|
r5574 | Modified files are saved with a .orig suffix before reverting. | ||
To disable these backups, use --no-backup. | ||||
|
r11177 | |||
|
r14544 | See :hg:`help dates` for a list of formats valid for -d/--date. | ||
|
r11177 | Returns 0 on success. | ||
|
r1437 | """ | ||
|
r2982 | |||
|
r11941 | if opts.get("date"): | ||
if opts.get("rev"): | ||||
|
r3814 | raise util.Abort(_("you can't specify a revision and a date")) | ||
opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) | ||||
|
r13022 | parent, p2 = repo.dirstate.parents() | ||
|
r14903 | if not opts.get('rev') and p2 != nullid: | ||
# revert after merge is a trap for new users (issue2915) | ||||
raise util.Abort(_('uncommitted merge with no revision specified'), | ||||
hint=_('use "hg update" or see "hg help revert"')) | ||||
|
r14726 | ctx = scmutil.revsingle(repo, opts.get('rev')) | ||
|
r13022 | |||
|
r7131 | if not pats and not opts.get('all'): | ||
|
r14721 | msg = _("no files or directories specified") | ||
if p2 != nullid: | ||||
hint = _("uncommitted merge, use --all to discard all changes," | ||||
" or 'hg update -C .' to abort the merge") | ||||
|
r14755 | raise util.Abort(msg, hint=hint) | ||
dirty = util.any(repo.status()) | ||||
|
r16304 | node = ctx.node() | ||
|
r14755 | if node != parent: | ||
if dirty: | ||||
|
r14726 | hint = _("uncommitted changes, use --all to discard all" | ||
" changes, or 'hg update %s' to update") % ctx.rev() | ||||
else: | ||||
hint = _("use --all to revert all files," | ||||
" or 'hg update %s' to update") % ctx.rev() | ||||
|
r14755 | elif dirty: | ||
hint = _("uncommitted changes, use --all to discard all changes") | ||||
else: | ||||
hint = _("use --all to revert all files") | ||||
|
r14721 | raise util.Abort(msg, hint=hint) | ||
|
r2982 | |||
|
r16304 | return cmdutil.revert(ui, repo, ctx, (parent, p2), *pats, **opts) | ||
|
r588 | |||
|
r15183 | @command('rollback', dryrunopts + | ||
[('f', 'force', False, _('ignore safety measures'))]) | ||||
|
r10882 | def rollback(ui, repo, **opts): | ||
|
r19409 | """roll back the last transaction (DANGEROUS) (DEPRECATED) | ||
|
r5575 | |||
|
r19421 | Please use :hg:`commit --amend` instead of rollback to correct | ||
mistakes in the last commit. | ||||
|
r5575 | This command should be used with care. There is only one level of | ||
rollback, and there is no way to undo a rollback. It will also | ||||
restore the dirstate at the time of the last transaction, losing | ||||
|
r8856 | any dirstate changes since that time. This command does not alter | ||
the working directory. | ||||
|
r2227 | |||
Transactions are used to encapsulate the effects of all commands | ||||
that create new changesets or propagate existing changesets into a | ||||
|
r17141 | repository. | ||
|
r17142 | .. container:: verbose | ||
For example, the following commands are transactional, and their | ||||
effects can be rolled back: | ||||
- commit | ||||
- import | ||||
- pull | ||||
- push (with this repository as the destination) | ||||
- unbundle | ||||
To avoid permanent data loss, rollback will refuse to rollback a | ||||
commit transaction if it isn't checked out. Use --force to | ||||
override this protection. | ||||
|
r15183 | |||
|
r2227 | This command is not intended for use on public repositories. Once | ||
changes are visible for pull by other users, rolling a transaction | ||||
back locally is ineffective (someone else may already have pulled | ||||
the changes). Furthermore, a race is possible with readers of the | ||||
repository; for example an in-progress pull from the repository | ||||
may fail if a rollback is performed. | ||||
|
r11177 | |||
Returns 0 on success, 1 if no rollback data is available. | ||||
|
r2227 | """ | ||
|
r15183 | return repo.rollback(dryrun=opts.get('dry_run'), | ||
force=opts.get('force')) | ||||
|
r2227 | |||
|
r14297 | @command('root', []) | ||
|
r468 | def root(ui, repo): | ||
|
r8026 | """print the root (top) of the current working directory | ||
|
r1437 | |||
Print the root directory of the current repository. | ||||
|
r11177 | |||
Returns 0 on success. | ||||
|
r1437 | """ | ||
|
r468 | ui.write(repo.root + "\n") | ||
|
r14297 | @command('^serve', | ||
[('A', 'accesslog', '', _('name of access log file to write to'), | ||||
_('FILE')), | ||||
('d', 'daemon', None, _('run server in background')), | ||||
('', 'daemon-pipefds', '', _('used internally by daemon mode'), _('NUM')), | ||||
('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')), | ||||
# use string type, then we can check if something was passed | ||||
('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')), | ||||
('a', 'address', '', _('address to listen on (default: all interfaces)'), | ||||
_('ADDR')), | ||||
('', 'prefix', '', _('prefix path to serve from (default: server root)'), | ||||
_('PREFIX')), | ||||
('n', 'name', '', | ||||
_('name to show in web pages (default: working directory)'), _('NAME')), | ||||
('', 'web-conf', '', | ||||
_('name of the hgweb config file (see "hg help hgweb")'), _('FILE')), | ||||
('', 'webdir-conf', '', _('name of the hgweb config file (DEPRECATED)'), | ||||
_('FILE')), | ||||
('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')), | ||||
('', 'stdio', None, _('for remote clients')), | ||||
|
r14647 | ('', 'cmdserver', '', _('for remote clients'), _('MODE')), | ||
|
r14297 | ('t', 'templates', '', _('web templates to use'), _('TEMPLATE')), | ||
('', 'style', '', _('template style to use'), _('STYLE')), | ||||
('6', 'ipv6', None, _('use IPv6 in addition to IPv4')), | ||||
('', 'certificate', '', _('SSL certificate file'), _('FILE'))], | ||||
|
r21775 | _('[OPTION]...'), | ||
optionalrepo=True) | ||||
|
r245 | def serve(ui, repo, **opts): | ||
|
r10889 | """start stand-alone webserver | ||
|
r1437 | |||
|
r11102 | Start a local HTTP repository browser and pull server. You can use | ||
|
r13065 | this for ad-hoc sharing and browsing of repositories. It is | ||
|
r11102 | recommended to use a real web server to serve a repository for | ||
longer periods of time. | ||||
|
r1437 | |||
|
r11103 | Please note that the server does not implement access control. | ||
This means that, by default, anybody can read from the server and | ||||
nobody can write to it by default. Set the ``web.allow_push`` | ||||
option to ``*`` to allow everybody to push to the server. You | ||||
should use a real web server if you need to authenticate users. | ||||
|
r1437 | By default, the server logs accesses to stdout and errors to | ||
|
r8277 | stderr. Use the -A/--accesslog and -E/--errorlog options to log to | ||
files. | ||||
|
r10629 | |||
To have the server choose a free port number to listen on, specify | ||||
a port number of 0; in this case, the server will print the port | ||||
number it uses. | ||||
|
r11177 | |||
Returns 0 on success. | ||||
|
r1437 | """ | ||
|
r624 | |||
|
r14647 | if opts["stdio"] and opts["cmdserver"]: | ||
raise util.Abort(_("cannot use --stdio with --cmdserver")) | ||||
|
r21818 | if opts["stdio"]: | ||
|
r2127 | if repo is None: | ||
|
r16935 | raise error.RepoError(_("there is no Mercurial repository here" | ||
|
r21819 | " (.hg not found)")) | ||
|
r2396 | s = sshserver.sshserver(ui, repo) | ||
s.serve_forever() | ||||
|
r2363 | |||
|
r14647 | if opts["cmdserver"]: | ||
s = commandserver.server(ui, repo, opts["cmdserver"]) | ||||
return s.serve() | ||||
|
r10635 | # this way we can check if something was given in the command-line | ||
if opts.get('port'): | ||||
|
r12076 | opts['port'] = util.getport(opts.get('port')) | ||
|
r10635 | |||
|
r8190 | baseui = repo and repo.baseui or ui | ||
|
r5835 | optlist = ("name templates style address port prefix ipv6" | ||
|
r10644 | " accesslog errorlog certificate encoding") | ||
|
r987 | for o in optlist.split(): | ||
|
r10630 | val = opts.get(o, '') | ||
|
r10631 | if val in (None, ''): # should check against default options instead | ||
|
r10630 | continue | ||
|
r20790 | baseui.setconfig("web", o, val, 'serve') | ||
|
r10630 | if repo and repo.ui != baseui: | ||
|
r20790 | repo.ui.setconfig("web", o, val, 'serve') | ||
|
r987 | |||
|
r11003 | o = opts.get('web_conf') or opts.get('webdir_conf') | ||
|
r11004 | if not o: | ||
if not repo: | ||||
|
r16935 | raise error.RepoError(_("there is no Mercurial repository" | ||
|
r11004 | " here (.hg not found)")) | ||
|
r18828 | o = repo | ||
|
r11004 | |||
|
r18827 | app = hgweb.hgweb(o, baseui=baseui) | ||
|
r19919 | service = httpservice(ui, app, opts) | ||
|
r4380 | cmdutil.service(opts, initfn=service.init, runfn=service.run) | ||
|
r500 | |||
|
r19919 | class httpservice(object): | ||
def __init__(self, ui, app, opts): | ||||
self.ui = ui | ||||
self.app = app | ||||
self.opts = opts | ||||
def init(self): | ||||
util.setsignalhandler() | ||||
self.httpd = hgweb_server.create_server(self.ui, self.app) | ||||
if self.opts['port'] and not self.ui.verbose: | ||||
return | ||||
if self.httpd.prefix: | ||||
prefix = self.httpd.prefix.strip('/') + '/' | ||||
else: | ||||
prefix = '' | ||||
port = ':%d' % self.httpd.port | ||||
if port == ':80': | ||||
port = '' | ||||
bindaddr = self.httpd.addr | ||||
if bindaddr == '0.0.0.0': | ||||
bindaddr = '*' | ||||
elif ':' in bindaddr: # IPv6 | ||||
bindaddr = '[%s]' % bindaddr | ||||
fqaddr = self.httpd.fqaddr | ||||
if ':' in fqaddr: | ||||
fqaddr = '[%s]' % fqaddr | ||||
if self.opts['port']: | ||||
write = self.ui.status | ||||
else: | ||||
write = self.ui.write | ||||
write(_('listening at http://%s%s/%s (bound to %s:%d)\n') % | ||||
(fqaddr, port, prefix, bindaddr, self.httpd.port)) | ||||
|
r21817 | self.ui.flush() # avoid buffering of status message | ||
|
r19919 | |||
def run(self): | ||||
self.httpd.serve_forever() | ||||
|
r14297 | @command('^status|st', | ||
[('A', 'all', None, _('show status of all files')), | ||||
('m', 'modified', None, _('show only modified files')), | ||||
('a', 'added', None, _('show only added files')), | ||||
('r', 'removed', None, _('show only removed files')), | ||||
('d', 'deleted', None, _('show only deleted (but tracked) files')), | ||||
('c', 'clean', None, _('show only files without changes')), | ||||
('u', 'unknown', None, _('show only unknown (not tracked) files')), | ||||
('i', 'ignored', None, _('show only ignored files')), | ||||
('n', 'no-status', None, _('hide status prefix')), | ||||
('C', 'copies', None, _('show source of copied files')), | ||||
('0', 'print0', None, _('end filenames with NUL, for use with xargs')), | ||||
('', 'rev', [], _('show difference from revision'), _('REV')), | ||||
('', 'change', '', _('list the changed files of a revision'), _('REV')), | ||||
] + walkopts + subrepoopts, | ||||
|
r21778 | _('[OPTION]... [FILE]...'), | ||
inferrepo=True) | ||||
|
r731 | def status(ui, repo, *pats, **opts): | ||
|
r1437 | """show changed files in the working directory | ||
|
r213 | |||
|
r6448 | Show status of files in the repository. If names are given, only | ||
files that match are shown. Files that are clean or ignored or | ||||
|
r8779 | the source of a copy/move operation, are not listed unless | ||
-c/--clean, -i/--ignored, -C/--copies or -A/--all are given. | ||||
Unless options described with "show only ..." are given, the | ||||
options -mardu are used. | ||||
|
r1437 | |||
|
r6201 | Option -q/--quiet hides untracked (unknown and ignored) files | ||
|
r8009 | unless explicitly requested with -u/--unknown or -i/--ignored. | ||
|
r6200 | |||
|
r12390 | .. note:: | ||
|
r19997 | |||
|
r12390 | status may appear to disagree with diff if permissions have | ||
changed or a merge has occurred. The standard diff format does | ||||
not report permission changes and diff only reports changes | ||||
relative to one merge parent. | ||||
|
r3822 | |||
|
r3467 | If one revision is given, it is used as the base revision. | ||
|
r8779 | If two revisions are given, the differences between them are | ||
|
r10014 | shown. The --change option can also be used as a shortcut to list | ||
the changed files of a revision from its first parent. | ||||
|
r3467 | |||
|
r9157 | The codes used to show the status of files are:: | ||
M = modified | ||||
A = added | ||||
R = removed | ||||
C = clean | ||||
! = missing (deleted by non-hg command, but still tracked) | ||||
? = not tracked | ||||
I = ignored | ||||
|
r20660 | = origin of the previous file (with --copies) | ||
|
r11177 | |||
|
r15119 | .. container:: verbose | ||
Examples: | ||||
|
r15633 | - show changes in the working directory relative to a | ||
changeset:: | ||||
|
r15119 | |||
hg status --rev 9353 | ||||
- show all changes including copies in an existing changeset:: | ||||
hg status --copies --change 9353 | ||||
- get a NUL separated list of added files, suitable for xargs:: | ||||
hg status -an0 | ||||
|
r11177 | Returns 0 on success. | ||
|
r1437 | """ | ||
|
r312 | |||
|
r10014 | revs = opts.get('rev') | ||
change = opts.get('change') | ||||
if revs and change: | ||||
msg = _('cannot specify --rev and --change at the same time') | ||||
raise util.Abort(msg) | ||||
elif change: | ||||
|
r15578 | node2 = scmutil.revsingle(repo, change, None).node() | ||
|
r13878 | node1 = repo[node2].p1().node() | ||
|
r10014 | else: | ||
|
r14319 | node1, node2 = scmutil.revpair(repo, revs) | ||
|
r10014 | |||
|
r1625 | cwd = (pats and repo.getcwd()) or '' | ||
|
r7131 | end = opts.get('print0') and '\0' or '\n' | ||
|
r6276 | copy = {} | ||
|
r6605 | states = 'modified added removed deleted unknown ignored clean'.split() | ||
|
r7684 | show = [k for k in states if opts.get(k)] | ||
|
r7131 | if opts.get('all'): | ||
|
r6605 | show += ui.quiet and (states[:4] + ['clean']) or states | ||
if not show: | ||||
show = ui.quiet and states[:4] or states[:5] | ||||
|
r14671 | stat = repo.status(node1, node2, scmutil.match(repo[node2], pats, opts), | ||
|
r12166 | 'ignored' in show, 'clean' in show, 'unknown' in show, | ||
opts.get('subrepos')) | ||||
|
r6605 | changestates = zip(states, 'MAR!?IC', stat) | ||
|
r7131 | if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'): | ||
|
r15775 | copy = copies.pathcopies(repo[node1], repo[node2]) | ||
|
r6276 | |||
|
r16136 | fm = ui.formatter('status', opts) | ||
|
r17910 | fmt = '%s' + end | ||
showchar = not opts.get('no_status') | ||||
|
r16136 | |||
|
r6605 | for state, char, files in changestates: | ||
if state in show: | ||||
|
r16136 | label = 'status.' + state | ||
|
r6605 | for f in files: | ||
|
r16136 | fm.startitem() | ||
|
r17910 | fm.condwrite(showchar, 'status', '%s ', char, label=label) | ||
fm.write('path', fmt, repo.pathto(f, cwd), label=label) | ||||
|
r6605 | if f in copy: | ||
|
r16136 | fm.write("copy", ' %s' + end, repo.pathto(copy[f], cwd), | ||
|
r10817 | label='status.copied') | ||
|
r16136 | fm.end() | ||
|
r213 | |||
|
r14297 | @command('^summary|sum', | ||
[('', 'remote', None, _('check for push and pull'))], '[--remote]') | ||||
|
r9620 | def summary(ui, repo, **opts): | ||
|
r9603 | """summarize working directory state | ||
This generates a brief summary of the working directory state, | ||||
including parents, branch, commit status, and available updates. | ||||
|
r9620 | |||
With the --remote option, this will check the default paths for | ||||
incoming and outgoing changes. This can be time-consuming. | ||||
|
r11177 | |||
Returns 0 on success. | ||||
|
r9603 | """ | ||
ctx = repo[None] | ||||
parents = ctx.parents() | ||||
pnode = parents[0].node() | ||||
|
r14906 | marks = [] | ||
|
r9603 | |||
for p in parents: | ||||
|
r10832 | # label with log.changeset (instead of log.parent) since this | ||
# shows a working directory parent *changeset*: | ||||
|
r17892 | # i18n: column positioning for "hg summary" | ||
|
r10832 | ui.write(_('parent: %d:%s ') % (p.rev(), str(p)), | ||
|
r17788 | label='log.changeset changeset.%s' % p.phasestr()) | ||
|
r10833 | ui.write(' '.join(p.tags()), label='log.tag') | ||
|
r13454 | if p.bookmarks(): | ||
|
r14906 | marks.extend(p.bookmarks()) | ||
|
r9618 | if p.rev() == -1: | ||
if not len(repo): | ||||
|
r10834 | ui.write(_(' (empty repository)')) | ||
|
r9618 | else: | ||
|
r10834 | ui.write(_(' (no revision checked out)')) | ||
|
r10832 | ui.write('\n') | ||
|
r9618 | if p.description(): | ||
|
r10832 | ui.status(' ' + p.description().splitlines()[0].strip() + '\n', | ||
label='log.summary') | ||||
|
r9603 | |||
branch = ctx.branch() | ||||
bheads = repo.branchheads(branch) | ||||
|
r17892 | # i18n: column positioning for "hg summary" | ||
|
r9873 | m = _('branch: %s\n') % branch | ||
if branch != 'default': | ||||
|
r10832 | ui.write(m, label='log.branch') | ||
|
r9873 | else: | ||
|
r10832 | ui.status(m, label='log.branch') | ||
|
r9603 | |||
|
r14906 | if marks: | ||
current = repo._bookmarkcurrent | ||||
|
r17892 | # i18n: column positioning for "hg summary" | ||
|
r14907 | ui.write(_('bookmarks:'), label='log.bookmark') | ||
|
r14906 | if current is not None: | ||
|
r18622 | if current in marks: | ||
|
r14907 | ui.write(' *' + current, label='bookmarks.current') | ||
|
r18622 | marks.remove(current) | ||
else: | ||||
|
r18623 | ui.write(' [%s]' % current, label='bookmarks.current') | ||
|
r14907 | for m in marks: | ||
|
r17299 | ui.write(' ' + m, label='log.bookmark') | ||
|
r14907 | ui.write('\n', label='log.bookmark') | ||
|
r14906 | |||
|
r10390 | st = list(repo.status(unknown=True))[:6] | ||
|
r11088 | |||
|
r11331 | c = repo.dirstate.copies() | ||
copied, renamed = [], [] | ||||
for d, s in c.iteritems(): | ||||
if s in st[2]: | ||||
st[2].remove(s) | ||||
renamed.append(d) | ||||
else: | ||||
copied.append(d) | ||||
if d in st[1]: | ||||
st[1].remove(d) | ||||
st.insert(3, renamed) | ||||
st.insert(4, copied) | ||||
|
r15856 | ms = mergemod.mergestate(repo) | ||
|
r10390 | st.append([f for f in ms if ms[f] == 'u']) | ||
|
r11088 | |||
subs = [s for s in ctx.substate if ctx.sub(s).dirty()] | ||||
st.append(subs) | ||||
|
r10832 | labels = [ui.label(_('%d modified'), 'status.modified'), | ||
ui.label(_('%d added'), 'status.added'), | ||||
ui.label(_('%d removed'), 'status.removed'), | ||||
|
r11331 | ui.label(_('%d renamed'), 'status.copied'), | ||
ui.label(_('%d copied'), 'status.copied'), | ||||
|
r10832 | ui.label(_('%d deleted'), 'status.deleted'), | ||
ui.label(_('%d unknown'), 'status.unknown'), | ||||
ui.label(_('%d ignored'), 'status.ignored'), | ||||
|
r11088 | ui.label(_('%d unresolved'), 'resolve.unresolved'), | ||
ui.label(_('%d subrepos'), 'status.modified')] | ||||
|
r9603 | t = [] | ||
|
r10282 | for s, l in zip(st, labels): | ||
|
r9607 | if s: | ||
t.append(l % len(s)) | ||||
|
r9603 | |||
t = ', '.join(t) | ||||
|
r10269 | cleanworkdir = False | ||
|
r9603 | |||
|
r19482 | if repo.vfs.exists('updatestate'): | ||
t += _(' (interrupted update)') | ||||
elif len(parents) > 1: | ||||
|
r11310 | t += _(' (merge)') | ||
|
r9603 | elif branch != parents[0].branch(): | ||
|
r11310 | t += _(' (new branch)') | ||
|
r16720 | elif (parents[0].closesbranch() and | ||
|
r11165 | pnode in repo.branchheads(branch, closed=True)): | ||
|
r11310 | t += _(' (head closed)') | ||
|
r11331 | elif not (st[0] or st[1] or st[2] or st[3] or st[4] or st[9]): | ||
|
r11310 | t += _(' (clean)') | ||
|
r10269 | cleanworkdir = True | ||
|
r9603 | elif pnode not in bheads: | ||
|
r11310 | t += _(' (new branch head)') | ||
|
r9603 | |||
|
r10269 | if cleanworkdir: | ||
|
r17892 | # i18n: column positioning for "hg summary" | ||
|
r11310 | ui.status(_('commit: %s\n') % t.strip()) | ||
|
r9605 | else: | ||
|
r17892 | # i18n: column positioning for "hg summary" | ||
|
r11310 | ui.write(_('commit: %s\n') % t.strip()) | ||
|
r9603 | |||
# all ancestors of branch heads - all ancestors of parent = new csets | ||||
|
r19394 | new = len(repo.changelog.findmissing([ctx.node() for ctx in parents], | ||
bheads)) | ||||
|
r9603 | |||
if new == 0: | ||||
|
r17892 | # i18n: column positioning for "hg summary" | ||
|
r9605 | ui.status(_('update: (current)\n')) | ||
|
r9603 | elif pnode not in bheads: | ||
|
r17892 | # i18n: column positioning for "hg summary" | ||
|
r9603 | ui.write(_('update: %d new changesets (update)\n') % new) | ||
else: | ||||
|
r17892 | # i18n: column positioning for "hg summary" | ||
|
r9603 | ui.write(_('update: %d new changesets, %d branch heads (merge)\n') % | ||
(new, len(bheads))) | ||||
|
r19211 | cmdutil.summaryhooks(ui, repo) | ||
|
r9620 | if opts.get('remote'): | ||
|
r21045 | needsincoming, needsoutgoing = True, True | ||
else: | ||||
needsincoming, needsoutgoing = False, False | ||||
|
r21047 | for i, o in cmdutil.summaryremotehooks(ui, repo, opts, None): | ||
if i: | ||||
needsincoming = True | ||||
if o: | ||||
needsoutgoing = True | ||||
if not needsincoming and not needsoutgoing: | ||||
return | ||||
|
r21045 | |||
def getincoming(): | ||||
|
r10389 | source, branches = hg.parseurl(ui.expandpath('default')) | ||
|
r18997 | sbranch = branches[0] | ||
|
r21047 | try: | ||
other = hg.peer(repo, {}, source) | ||||
except error.RepoError: | ||||
if opts.get('remote'): | ||||
raise | ||||
return source, sbranch, None, None, None | ||||
|
r19379 | revs, checkout = hg.addbranchrevs(repo, other, branches, None) | ||
|
r18996 | if revs: | ||
revs = [other.lookup(rev) for rev in revs] | ||||
|
r14076 | ui.debug('comparing with %s\n' % util.hidepassword(source)) | ||
|
r9620 | repo.ui.pushbuffer() | ||
|
r18996 | commoninc = discovery.findcommonincoming(repo, other, heads=revs) | ||
|
r9620 | repo.ui.popbuffer() | ||
|
r21045 | return source, sbranch, other, commoninc, commoninc[1] | ||
if needsincoming: | ||||
source, sbranch, sother, commoninc, incoming = getincoming() | ||||
else: | ||||
source = sbranch = sother = commoninc = incoming = None | ||||
def getoutgoing(): | ||||
|
r10389 | dest, branches = hg.parseurl(ui.expandpath('default-push', 'default')) | ||
|
r18997 | dbranch = branches[0] | ||
|
r10389 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) | ||
|
r14214 | if source != dest: | ||
|
r21047 | try: | ||
dother = hg.peer(repo, {}, dest) | ||||
except error.RepoError: | ||||
if opts.get('remote'): | ||||
raise | ||||
return dest, dbranch, None, None | ||||
|
r18997 | ui.debug('comparing with %s\n' % util.hidepassword(dest)) | ||
|
r21047 | elif sother is None: | ||
# there is no explicit destination peer, but source one is invalid | ||||
return dest, dbranch, None, None | ||||
|
r21045 | else: | ||
dother = sother | ||||
|
r18997 | if (source != dest or (sbranch is not None and sbranch != dbranch)): | ||
|
r21045 | common = None | ||
else: | ||||
common = commoninc | ||||
|
r18994 | if revs: | ||
revs = [repo.lookup(rev) for rev in revs] | ||||
|
r9620 | repo.ui.pushbuffer() | ||
|
r21045 | outgoing = discovery.findcommonoutgoing(repo, dother, onlyheads=revs, | ||
commoninc=common) | ||||
|
r9620 | repo.ui.popbuffer() | ||
|
r21045 | return dest, dbranch, dother, outgoing | ||
if needsoutgoing: | ||||
dest, dbranch, dother, outgoing = getoutgoing() | ||||
else: | ||||
dest = dbranch = dother = outgoing = None | ||||
if opts.get('remote'): | ||||
t = [] | ||||
if incoming: | ||||
t.append(_('1 or more incoming')) | ||||
|
r15837 | o = outgoing.missing | ||
|
r9620 | if o: | ||
t.append(_('%d outgoing') % len(o)) | ||||
|
r21045 | other = dother or sother | ||
|
r13454 | if 'bookmarks' in other.listkeys('namespaces'): | ||
lmarks = repo.listkeys('bookmarks') | ||||
rmarks = other.listkeys('bookmarks') | ||||
diff = set(rmarks) - set(lmarks) | ||||
if len(diff) > 0: | ||||
t.append(_('%d incoming bookmarks') % len(diff)) | ||||
diff = set(lmarks) - set(rmarks) | ||||
if len(diff) > 0: | ||||
t.append(_('%d outgoing bookmarks') % len(diff)) | ||||
|
r9620 | |||
if t: | ||||
|
r17892 | # i18n: column positioning for "hg summary" | ||
|
r9620 | ui.write(_('remote: %s\n') % (', '.join(t))) | ||
else: | ||||
|
r17892 | # i18n: column positioning for "hg summary" | ||
|
r9620 | ui.status(_('remote: (synced)\n')) | ||
|
r21047 | cmdutil.summaryremotehooks(ui, repo, opts, | ||
((source, sbranch, sother, commoninc), | ||||
(dest, dbranch, dother, outgoing))) | ||||
|
r14297 | @command('tag', | ||
[('f', 'force', None, _('force tag')), | ||||
('l', 'local', None, _('make the tag local')), | ||||
('r', 'rev', '', _('revision to tag'), _('REV')), | ||||
('', 'remove', None, _('remove a tag')), | ||||
# -l/--local is already there, commitopts cannot be used | ||||
|
r21952 | ('e', 'edit', None, _('invoke editor on commit messages')), | ||
|
r21951 | ('m', 'message', '', _('use text as commit message'), _('TEXT')), | ||
|
r14297 | ] + commitopts2, | ||
_('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')) | ||||
|
r6321 | def tag(ui, repo, name1, *names, **opts): | ||
"""add one or more tags for the current or given revision | ||||
|
r1437 | |||
Name a particular revision using <name>. | ||||
Tags are used to name particular revisions of the repository and are | ||||
|
r6220 | very useful to compare different revisions, to go back to significant | ||
|
r13135 | earlier versions or to mark branch points as releases, etc. Changing | ||
an existing tag is normally disallowed; use -f/--force to override. | ||||
|
r1437 | |||
|
r8004 | If no revision is given, the parent of the working directory is | ||
|
r19402 | used. | ||
|
r1437 | |||
To facilitate version control, distribution, and merging of tags, | ||||
|
r13135 | they are stored as a file named ".hgtags" which is managed similarly | ||
to other project files and can be hand-edited if necessary. This | ||||
also means that tagging creates a new commit. The file | ||||
".hg/localtags" is used for local tags (not shared among | ||||
repositories). | ||||
Tag commits are usually made at the head of a branch. If the parent | ||||
of the working directory is not a branch head, :hg:`tag` aborts; use | ||||
-f/--force to force the tag commit to be based on a non-head | ||||
changeset. | ||||
|
r6163 | |||
|
r10973 | See :hg:`help dates` for a list of formats valid for -d/--date. | ||
|
r11063 | |||
Since tag names have priority over branch names during revision | ||||
lookup, using an existing branch name as a tag name is discouraged. | ||||
|
r11177 | |||
Returns 0 on success. | ||||
|
r1437 | """ | ||
|
r15877 | wlock = lock = None | ||
try: | ||||
wlock = repo.wlock() | ||||
lock = repo.lock() | ||||
rev_ = "." | ||||
names = [t.strip() for t in (name1,) + names] | ||||
if len(names) != len(set(names)): | ||||
raise util.Abort(_('tag names must be unique')) | ||||
|
r6321 | for n in names: | ||
|
r17821 | scmutil.checknewlabel(repo, n, 'tag') | ||
|
r15877 | if not n: | ||
raise util.Abort(_('tag names cannot consist entirely of ' | ||||
'whitespace')) | ||||
if opts.get('rev') and opts.get('remove'): | ||||
raise util.Abort(_("--rev and --remove are incompatible")) | ||||
if opts.get('rev'): | ||||
rev_ = opts['rev'] | ||||
message = opts.get('message') | ||||
if opts.get('remove'): | ||||
expectedtype = opts.get('local') and 'local' or 'global' | ||||
for n in names: | ||||
if not repo.tagtype(n): | ||||
raise util.Abort(_("tag '%s' does not exist") % n) | ||||
if repo.tagtype(n) != expectedtype: | ||||
if expectedtype == 'global': | ||||
raise util.Abort(_("tag '%s' is not a global tag") % n) | ||||
else: | ||||
raise util.Abort(_("tag '%s' is not a local tag") % n) | ||||
rev_ = nullid | ||||
if not message: | ||||
# we don't translate commit messages | ||||
message = 'Removed tag %s' % ', '.join(names) | ||||
elif not opts.get('force'): | ||||
for n in names: | ||||
if n in repo.tags(): | ||||
raise util.Abort(_("tag '%s' already exists " | ||||
"(use -f to force)") % n) | ||||
if not opts.get('local'): | ||||
p1, p2 = repo.dirstate.parents() | ||||
if p2 != nullid: | ||||
raise util.Abort(_('uncommitted merge')) | ||||
bheads = repo.branchheads() | ||||
if not opts.get('force') and bheads and p1 not in bheads: | ||||
raise util.Abort(_('not at a branch head (use -f to force)')) | ||||
r = scmutil.revsingle(repo, rev_).node() | ||||
|
r4213 | if not message: | ||
|
r9183 | # we don't translate commit messages | ||
|
r15877 | message = ('Added tag %s for changeset %s' % | ||
(', '.join(names), short(r))) | ||||
date = opts.get('date') | ||||
if date: | ||||
date = util.parsedate(date) | ||||
|
r22009 | if opts.get('remove'): | ||
editform = 'tag.remove' | ||||
else: | ||||
editform = 'tag.add' | ||||
editor = cmdutil.getcommiteditor(editform=editform, **opts) | ||||
|
r15877 | |||
|
r17260 | # don't allow tagging the null rev | ||
if (not opts.get('remove') and | ||||
scmutil.revsingle(repo, rev_).rev() == nullrev): | ||||
|
r18906 | raise util.Abort(_("cannot tag null revision")) | ||
|
r17260 | |||
|
r21237 | repo.tag(names, r, message, opts.get('local'), opts.get('user'), date, | ||
editor=editor) | ||||
|
r15877 | finally: | ||
release(lock, wlock) | ||||
|
r401 | |||
|
r14297 | @command('tags', [], '') | ||
|
r17912 | def tags(ui, repo, **opts): | ||
|
r1437 | """list repository tags | ||
|
r8004 | This lists both regular and local tags. When the -v/--verbose | ||
switch is used, a third column "local" is printed for local tags. | ||||
|
r11177 | |||
Returns 0 on success. | ||||
|
r1437 | """ | ||
|
r477 | |||
|
r17912 | fm = ui.formatter('tags', opts) | ||
|
r2966 | hexfunc = ui.debugflag and hex or short | ||
|
r5658 | tagtype = "" | ||
|
r8210 | for t, n in reversed(repo.tagslist()): | ||
|
r13893 | hn = hexfunc(n) | ||
|
r17912 | label = 'tags.normal' | ||
tagtype = '' | ||||
if repo.tagtype(t) == 'local': | ||||
label = 'tags.local' | ||||
tagtype = 'local' | ||||
fm.startitem() | ||||
fm.write('tag', '%s', t, label=label) | ||||
fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s' | ||||
fm.condwrite(not ui.quiet, 'rev id', fmt, | ||||
repo.changelog.rev(n), hn, label=label) | ||||
fm.condwrite(ui.verbose and tagtype, 'type', ' %s', | ||||
tagtype, label=label) | ||||
fm.plain('\n') | ||||
fm.end() | ||||
|
r248 | |||
|
r14297 | @command('tip', | ||
[('p', 'patch', None, _('show patch')), | ||||
('g', 'git', None, _('use git extended diff format')), | ||||
] + templateopts, | ||||
_('[-p] [-g]')) | ||||
|
r1731 | def tip(ui, repo, **opts): | ||
|
r19403 | """show the tip revision (DEPRECATED) | ||
|
r1437 | |||
|
r8779 | The tip revision (usually just called the tip) is the changeset | ||
most recently added to the repository (and therefore the most | ||||
recently changed head). | ||||
|
r6364 | |||
|
r6367 | If you have just made a commit, that commit will be the tip. If | ||
you have just pulled changes from another repository, the tip of | ||||
that repository becomes the current tip. The "tip" tag is special | ||||
and cannot be renamed or assigned to a different changeset. | ||||
|
r11177 | |||
|
r19403 | This command is deprecated, please use :hg:`heads` instead. | ||
|
r11177 | Returns 0 on success. | ||
|
r1437 | """ | ||
|
r10152 | displayer = cmdutil.show_changeset(ui, repo, opts) | ||
|
r18464 | displayer.show(repo['tip']) | ||
|
r10152 | displayer.close() | ||
|
r245 | |||
|
r14297 | @command('unbundle', | ||
[('u', 'update', None, | ||||
_('update to new branch head if changesets were unbundled'))], | ||||
_('[-u] FILE...')) | ||||
|
r4699 | def unbundle(ui, repo, fname1, *fnames, **opts): | ||
"""apply one or more changegroup files | ||||
Apply one or more compressed changegroup files generated by the | ||||
bundle command. | ||||
|
r11177 | |||
Returns 0 on success, 1 if an update has unresolved files. | ||||
|
r1437 | """ | ||
|
r4699 | fnames = (fname1,) + fnames | ||
|
r6180 | |||
|
r8109 | lock = repo.lock() | ||
|
r6180 | try: | ||
for fname in fnames: | ||||
|
r17887 | f = hg.openpath(ui, fname) | ||
|
r21064 | gen = exchange.readbundle(ui, f, fname) | ||
|
r20933 | modheads = changegroup.addchangegroup(repo, gen, 'unbundle', | ||
'bundle:' + fname) | ||||
|
r6180 | finally: | ||
|
r8109 | lock.release() | ||
|
r22091 | |||
|
r7131 | return postincoming(ui, repo, modheads, opts.get('update'), None) | ||
|
r1218 | |||
|
r14297 | @command('^update|up|checkout|co', | ||
[('C', 'clean', None, _('discard uncommitted changes (no backup)')), | ||||
('c', 'check', None, | ||||
_('update across branches if no uncommitted changes')), | ||||
('d', 'date', '', _('tipmost revision matching date'), _('DATE')), | ||||
|
r21552 | ('r', 'rev', '', _('revision'), _('REV')) | ||
] + mergetoolopts, | ||||
|
r14297 | _('[-c] [-C] [-d DATE] [[-r] REV]')) | ||
|
r21552 | def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False, | ||
tool=None): | ||||
|
r10889 | """update working directory (or switch revisions) | ||
|
r1437 | |||
|
r8004 | Update the repository's working directory to the specified | ||
|
r12688 | changeset. If no changeset is specified, update to the tip of the | ||
|
r15957 | current named branch and move the current bookmark (see :hg:`help | ||
bookmarks`). | ||||
|
r12688 | |||
|
r17343 | Update sets the working directory's parent revision to the specified | ||
|
r17143 | changeset (see :hg:`help parents`). | ||
|
r16877 | If the changeset is not a descendant or ancestor of the working | ||
directory's parent, the update is aborted. With the -c/--check | ||||
option, the working directory is checked for uncommitted changes; if | ||||
none are found, the working directory is updated to the specified | ||||
|
r9718 | changeset. | ||
|
r17218 | .. container:: verbose | ||
The following rules apply when the working directory contains | ||||
uncommitted changes: | ||||
1. If neither -c/--check nor -C/--clean is specified, and if | ||||
the requested changeset is an ancestor or descendant of | ||||
the working directory's parent, the uncommitted changes | ||||
are merged into the requested changeset and the merged | ||||
result is left uncommitted. If the requested changeset is | ||||
not an ancestor or descendant (that is, it is on another | ||||
branch), the update is aborted and the uncommitted changes | ||||
are preserved. | ||||
2. With the -c/--check option, the update is aborted and the | ||||
uncommitted changes are preserved. | ||||
3. With the -C/--clean option, uncommitted changes are discarded and | ||||
the working directory is updated to the requested changeset. | ||||
|
r9718 | |||
|
r17144 | To cancel an uncommitted merge (and lose your changes), use | ||
:hg:`update --clean .`. | ||||
|
r10973 | Use null as the changeset to remove the working directory (like | ||
:hg:`clone -U`). | ||||
|
r14729 | If you want to revert just one file to an older revision, use | ||
:hg:`revert [-r REV] NAME`. | ||||
|
r10973 | |||
See :hg:`help dates` for a list of formats valid for -d/--date. | ||||
|
r11177 | |||
Returns 0 on success, 1 if there are unresolved files. | ||||
|
r1437 | """ | ||
|
r4450 | if rev and node: | ||
raise util.Abort(_("please specify just one revision")) | ||||
|
r13568 | if rev is None or rev == '': | ||
|
r4450 | rev = node | ||
|
r19475 | cmdutil.clearunfinished(repo) | ||
|
r15935 | # with no argument, we also move the current bookmark, if any | ||
|
r19523 | rev, movemarkfrom = bookmarks.calculateupdate(ui, repo, rev) | ||
|
r15935 | |||
|
r13415 | # if we defined a bookmark, we have to remember the original bookmark name | ||
brev = rev | ||||
|
r14319 | rev = scmutil.revsingle(repo, rev, rev).rev() | ||
|
r12726 | |||
|
r9450 | if check and clean: | ||
|
r9451 | raise util.Abort(_("cannot specify both -c/--check and -C/--clean")) | ||
|
r9450 | |||
|
r16092 | if date: | ||
if rev is not None: | ||||
raise util.Abort(_("you can't specify a revision and a date")) | ||||
rev = cmdutil.finddate(ui, repo, date) | ||||
|
r9450 | if check: | ||
|
r8855 | c = repo[None] | ||
|
r17849 | if c.dirty(merge=False, branch=False, missing=True): | ||
|
r19801 | raise util.Abort(_("uncommitted changes")) | ||
|
r16490 | if rev is None: | ||
|
r16092 | rev = repo[repo[None].branch()].rev() | ||
|
r16095 | mergemod._checkunknown(repo, repo[None], repo[rev]) | ||
|
r16092 | |||
|
r21552 | repo.ui.setconfig('ui', 'forcemerge', tool, 'update') | ||
|
r16092 | if clean: | ||
|
r13367 | ret = hg.clean(repo, rev) | ||
|
r2808 | else: | ||
|
r13367 | ret = hg.update(repo, rev) | ||
|
r15935 | if not ret and movemarkfrom: | ||
|
r16010 | if bookmarks.update(repo, [movemarkfrom], repo['.'].node()): | ||
ui.status(_("updating bookmark %s\n") % repo._bookmarkcurrent) | ||||
|
r15935 | elif brev in repo._bookmarks: | ||
|
r13415 | bookmarks.setcurrent(repo, brev) | ||
|
r21503 | ui.status(_("(activating bookmark %s)\n") % brev) | ||
|
r16191 | elif brev: | ||
|
r21404 | if repo._bookmarkcurrent: | ||
ui.status(_("(leaving bookmark %s)\n") % | ||||
repo._bookmarkcurrent) | ||||
|
r16191 | bookmarks.unsetcurrent(repo) | ||
|
r13367 | |||
return ret | ||||
|
r254 | |||
|
r14297 | @command('verify', []) | ||
|
r247 | def verify(ui, repo): | ||
|
r1437 | """verify the integrity of the repository | ||
Verify the integrity of the current repository. | ||||
This will perform an extensive check of the repository's | ||||
integrity, validating the hashes and checksums of each entry in | ||||
the changelog, manifest, and tracked files, as well as the | ||||
integrity of their crosslinks and indices. | ||||
|
r11177 | |||
|
r17717 | Please see http://mercurial.selenic.com/wiki/RepositoryCorruption | ||
for more information about recovery from corruption of the | ||||
repository. | ||||
|
r11177 | Returns 0 on success, 1 if errors are encountered. | ||
|
r1437 | """ | ||
|
r2778 | return hg.verify(repo) | ||
|
r247 | |||
|
r21768 | @command('version', [], norepo=True) | ||
|
r3651 | def version_(ui): | ||
"""output version and copyright information""" | ||||
ui.write(_("Mercurial Distributed SCM (version %s)\n") | ||||
|
r7632 | % util.version()) | ||
|
r3651 | ui.status(_( | ||
|
r12829 | "(see http://mercurial.selenic.com for more information)\n" | ||
|
r20227 | "\nCopyright (C) 2005-2014 Matt Mackall and others\n" | ||
|
r3651 | "This is free software; see the source for copying conditions. " | ||
"There is NO\nwarranty; " | ||||
"not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | ||||
)) | ||||
|
r21848 | |||
ui.note(_("\nEnabled extensions:\n\n")) | ||||
if ui.verbose: | ||||
# format names and versions into columns | ||||
names = [] | ||||
vers = [] | ||||
for name, module in extensions.extensions(): | ||||
names.append(name) | ||||
vers.append(extensions.moduleversion(module)) | ||||
|
r21937 | if names: | ||
maxnamelen = max(len(n) for n in names) | ||||
for i, name in enumerate(names): | ||||
ui.write(" %-*s %s\n" % (maxnamelen, name, vers[i])) | ||||