commands.py
5752 lines
| 206.0 KiB
| text/x-python
|
PythonLexer
/ mercurial / commands.py
mpm@selenic.com
|
r249 | # commands.py - command processing for mercurial | ||
# | ||||
Thomas Arendsen Hein
|
r4635 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | ||
mpm@selenic.com
|
r249 | # | ||
Martin Geisler
|
r8225 | # This software may be used and distributed according to the terms of the | ||
Matt Mackall
|
r10263 | # GNU General Public License version 2 or any later version. | ||
mpm@selenic.com
|
r249 | |||
Peter Arrenbrecht
|
r13723 | from node import hex, bin, nullid, nullrev, short | ||
Ronny Pfannschmidt
|
r8109 | from lock import release | ||
Martin Geisler
|
r7013 | from i18n import _, gettext | ||
Idan Kamara
|
r14639 | import os, re, difflib, time, tempfile, errno | ||
Adrian Buehlmann
|
r13970 | import hg, scmutil, util, revlog, extensions, copies, error, bookmarks | ||
Alexander Solovyov
|
r14064 | import patch, help, url, encoding, templatekw, discovery | ||
Idan Kamara
|
r14647 | import archival, changegroup, cmdutil, hbisect | ||
import sshserver, hgweb, hgweb.server, commandserver | ||||
Martin Geisler
|
r15856 | import merge as mergemod | ||
Matt Mackall
|
r14511 | import minirst, revset, fileset | ||
Peter Arrenbrecht
|
r14163 | import dagparser, context, simplemerge | ||
Matt Mackall
|
r16249 | import random, setdiscovery, treediscovery, dagutil, pvec | ||
Martin Geisler
|
r15853 | import phases | ||
Matt Mackall
|
r2731 | |||
Adrian Buehlmann
|
r14297 | table = {} | ||
command = cmdutil.command(table) | ||||
# common command options | ||||
globalopts = [ | ||||
('R', 'repository', '', | ||||
_('repository root directory or name of overlay bundle file'), | ||||
_('REPO')), | ||||
('', 'cwd', '', | ||||
_('change working directory'), _('DIR')), | ||||
('y', 'noninteractive', None, | ||||
Martin Geisler
|
r14849 | _('do not prompt, automatically pick the first choice for all prompts')), | ||
Adrian Buehlmann
|
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')), | ||||
] | ||||
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', '', | ||||
_('display using template map file'), _('STYLE')), | ||||
('', 'template', '', | ||||
_('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')), | ||||
] + 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')) | ||||
] | ||||
Patrick Mezard
|
r15528 | diffwsopts = [ | ||
Adrian Buehlmann
|
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')), | ||||
Patrick Mezard
|
r15528 | ] | ||
diffopts2 = [ | ||||
('p', 'show-function', None, _('show which function each change is in')), | ||||
('', 'reverse', None, _('produce a diff that undoes the changes')), | ||||
] + diffwsopts + [ | ||||
Adrian Buehlmann
|
r14297 | ('U', 'unified', '', | ||
_('number of lines of context to show'), _('NUM')), | ||||
('', 'stat', None, _('output diffstat-style summary of changes')), | ||||
] | ||||
Martin Geisler
|
r14852 | mergetoolopts = [ | ||
('t', 'tool', '', _('specify merge tool')), | ||||
] | ||||
Adrian Buehlmann
|
r14297 | similarityopts = [ | ||
('s', 'similarity', '', | ||||
_('guess renamed files by similarity (0<=s<=100)'), _('SIMILARITY')) | ||||
] | ||||
subrepoopts = [ | ||||
('S', 'subrepos', None, | ||||
_('recurse into subrepositories')) | ||||
] | ||||
Matt Mackall
|
r2731 | |||
mpm@selenic.com
|
r255 | # Commands start here, listed alphabetically | ||
mpm@selenic.com
|
r209 | |||
Adrian Buehlmann
|
r14297 | @command('^add', | ||
walkopts + subrepoopts + dryrunopts, | ||||
_('[OPTION]... [FILE]...')) | ||||
Bryan O'Sullivan
|
r724 | def add(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """add the specified files on the next commit | ||
Martin Geisler
|
r8004 | Schedule files to be version controlled and added to the | ||
repository. | ||||
Benoit Boissinot
|
r1437 | |||
Matt Mackall
|
r3829 | The files will be added to the repository at the next commit. To | ||
Martin Geisler
|
r11193 | undo an add before that, see :hg:`forget`. | ||
Benoit Boissinot
|
r1437 | |||
timeless
|
r7807 | If no names are given, add all files to the repository. | ||
Martin Geisler
|
r10446 | |||
.. container:: verbose | ||||
An example showing how new (unknown) files are added | ||||
Martin Geisler
|
r10973 | automatically by :hg:`add`:: | ||
Martin Geisler
|
r10446 | |||
$ ls | ||||
foo.c | ||||
$ hg status | ||||
? foo.c | ||||
$ hg add | ||||
adding foo.c | ||||
$ hg status | ||||
Martin Geisler
|
r10448 | A foo.c | ||
Nicolas Dumazet
|
r11507 | |||
Returns 0 if all files are successfully added. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r14671 | m = scmutil.match(repo[None], pats, opts) | ||
Martin Geisler
|
r12270 | rejected = cmdutil.add(ui, repo, m, opts.get('dry_run'), | ||
David M. Carr
|
r15911 | opts.get('subrepos'), prefix="", explicitonly=False) | ||
Martin Geisler
|
r12269 | return rejected and 1 or 0 | ||
mpm@selenic.com
|
r213 | |||
Adrian Buehlmann
|
r14297 | @command('addremove', | ||
similarityopts + walkopts + dryrunopts, | ||||
_('[OPTION]... [FILE]...')) | ||||
Bryan O'Sullivan
|
r766 | def addremove(ui, repo, *pats, **opts): | ||
Thomas Arendsen Hein
|
r3181 | """add all new files, delete all missing files | ||
Vadim Gelfer
|
r2181 | |||
Martin Geisler
|
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 | ||||
Javi Merino
|
r13344 | ``.hgignore``. As with add, these changes take effect at the next | ||
Martin Geisler
|
r8004 | commit. | ||
Vadim Gelfer
|
r2958 | |||
Martin Geisler
|
r8033 | Use the -s/--similarity option to detect renamed files. With a | ||
Martin Geisler
|
r9249 | parameter greater than 0, this compares every removed file with | ||
every added file and records those similar enough as renames. This | ||||
option takes a percentage between 0 (disabled) and 100 (files must | ||||
be identical) as its parameter. Detecting renamed files this way | ||||
Arnab Bose
|
r11518 | can be expensive. After using this option, :hg:`status -C` can be | ||
used to check which files were identified as moved or renamed. | ||||
Levi Bard
|
r16637 | If this option is not specified, only renames of identical files | ||
are detected. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 if all files are successfully added. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Bryan O'Sullivan
|
r4966 | try: | ||
Dirkjan Ochtman
|
r11551 | sim = float(opts.get('similarity') or 100) | ||
Bryan O'Sullivan
|
r4966 | except ValueError: | ||
raise util.Abort(_('similarity must be a number')) | ||||
Vadim Gelfer
|
r2958 | if sim < 0 or sim > 100: | ||
raise util.Abort(_('similarity must be between 0 and 100')) | ||||
Matt Mackall
|
r14321 | return scmutil.addremove(repo, pats, opts, similarity=sim / 100.0) | ||
mpm@selenic.com
|
r219 | |||
Adrian Buehlmann
|
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')) | ||||
Patrick Mezard
|
r15528 | ] + diffwsopts + walkopts, | ||
Adrian Buehlmann
|
r14297 | _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...')) | ||
Bryan O'Sullivan
|
r733 | def annotate(ui, repo, *pats, **opts): | ||
timeless
|
r8779 | """show changeset information by line for each file | ||
Benoit Boissinot
|
r1437 | |||
Martin Geisler
|
r8004 | List changes in files, showing the revision id responsible for | ||
each line | ||||
timeless
|
r8779 | This command is useful for discovering when a change was made and | ||
by whom. | ||||
Benoit Boissinot
|
r1437 | |||
Martin Geisler
|
r8033 | Without the -a/--text option, annotate will avoid processing files | ||
timeless
|
r8779 | it detects as binary. With -a, annotate will annotate the file | ||
anyway, although the results will probably be neither useful | ||||
nor desirable. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Thomas Arendsen Hein
|
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 | ||||
Martin Geisler
|
r14216 | opts['file'] = True | ||
Thomas Arendsen Hein
|
r10579 | |||
Thomas Arendsen Hein
|
r6134 | datefunc = ui.quiet and util.shortdate or util.datestr | ||
getdate = util.cachefunc(lambda x: datefunc(x[0].date())) | ||||
lupus@debian.org
|
r1522 | |||
mpm@selenic.com
|
r744 | if not pats: | ||
timeless
|
r8761 | raise util.Abort(_('at least one filename or pattern is required')) | ||
mpm@selenic.com
|
r744 | |||
Ion Savin
|
r15631 | hexfn = ui.debugflag and hex or short | ||
Thomas Arendsen Hein
|
r14358 | opmap = [('user', ' ', lambda x: ui.shortuser(x[0].user())), | ||
('number', ' ', lambda x: str(x[0].rev())), | ||||
Ion Savin
|
r15631 | ('changeset', ' ', lambda x: hexfn(x[0].node())), | ||
Thomas Arendsen Hein
|
r14358 | ('date', ' ', getdate), | ||
('file', ' ', lambda x: x[0].path()), | ||||
('line_number', ':', lambda x: str(x[1])), | ||||
Thomas Arendsen Hein
|
r4857 | ] | ||
Matt Mackall
|
r10282 | if (not opts.get('user') and not opts.get('changeset') | ||
Dirkjan Ochtman
|
r10369 | and not opts.get('date') and not opts.get('file')): | ||
Martin Geisler
|
r14216 | opts['number'] = True | ||
mpm@selenic.com
|
r209 | |||
Thomas Arendsen Hein
|
r4857 | linenumber = opts.get('line_number') is not None | ||
Benoit Boissinot
|
r10394 | if linenumber and (not opts.get('changeset')) and (not opts.get('number')): | ||
Thomas Arendsen Hein
|
r4857 | raise util.Abort(_('at least one of -n/-c is required for -l')) | ||
Thomas Arendsen Hein
|
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 | ||||
Thomas Arendsen Hein
|
r4857 | |||
Matt Mackall
|
r13697 | def bad(x, y): | ||
raise util.Abort("%s: %s" % (x, y)) | ||||
Matt Mackall
|
r14319 | ctx = scmutil.revsingle(repo, opts.get('rev')) | ||
Matt Mackall
|
r14671 | m = scmutil.match(ctx, pats, opts) | ||
Matt Mackall
|
r13697 | m.bad = bad | ||
Dirkjan Ochtman
|
r10369 | follow = not opts.get('no_follow') | ||
Patrick Mezard
|
r15528 | diffopts = patch.diffopts(ui, opts, section='annotate') | ||
Matt Mackall
|
r6764 | for abs in ctx.walk(m): | ||
fctx = ctx[abs] | ||||
Alexander Solovyov
|
r7131 | if not opts.get('text') and util.binary(fctx.data()): | ||
Matt Mackall
|
r6584 | ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs)) | ||
mpm@selenic.com
|
r1016 | continue | ||
Patrick Mezard
|
r15528 | lines = fctx.annotate(follow=follow, linenumber=linenumber, | ||
diffopts=diffopts) | ||||
mpm@selenic.com
|
r209 | pieces = [] | ||
Thomas Arendsen Hein
|
r14358 | for f, sep in funcmap: | ||
Thomas Arendsen Hein
|
r4857 | l = [f(n) for n, dummy in lines] | ||
if l: | ||||
FUJIWARA Katsunori
|
r11611 | sized = [(x, encoding.colwidth(x)) for x in l] | ||
ml = max([w for x, w in sized]) | ||||
Thomas Arendsen Hein
|
r14358 | pieces.append(["%s%s%s" % (sep, ' ' * (ml - w), x) | ||
for x, w in sized]) | ||||
mpm@selenic.com
|
r209 | |||
mpm@selenic.com
|
r771 | if pieces: | ||
for p, l in zip(zip(*pieces), lines): | ||||
Thomas Arendsen Hein
|
r14358 | ui.write("%s: %s" % ("".join(p), l[1])) | ||
mpm@selenic.com
|
r209 | |||
Ion Savin
|
r15829 | if lines and not lines[-1][1].endswith('\n'): | ||
ui.write('\n') | ||||
Adrian Buehlmann
|
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')) | ||||
Vadim Gelfer
|
r2112 | def archive(ui, repo, dest, **opts): | ||
timeless
|
r8779 | '''create an unversioned archive of a repository revision | ||
Vadim Gelfer
|
r2112 | |||
By default, the revision used is the parent of the working | ||||
Martin Geisler
|
r8033 | directory; use -r/--rev to specify a different revision. | ||
David Wolever
|
r10650 | The archive type is automatically detected based on file | ||
extension (or override using -t/--type). | ||||
Matt Mackall
|
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*" | ||||
David Wolever
|
r10650 | Valid types are: | ||
Martin Geisler
|
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 | ||||
Vadim Gelfer
|
r2112 | |||
The exact name of the destination archive or directory is given | ||||
Martin Geisler
|
r10973 | using a format string; see :hg:`help export` for details. | ||
Vadim Gelfer
|
r2112 | |||
Each member added to an archive file has a directory prefix | ||||
Martin Geisler
|
r8033 | prepended. Use -p/--prefix to specify a format string for the | ||
prefix. The default is the basename of the archive, with suffixes | ||||
removed. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success. | ||||
Vadim Gelfer
|
r2112 | ''' | ||
Matt Mackall
|
r14319 | ctx = scmutil.revsingle(repo, opts.get('rev')) | ||
Brendan Cully
|
r5061 | if not ctx: | ||
Matt Mackall
|
r7528 | raise util.Abort(_('no working directory: please specify a revision')) | ||
Brendan Cully
|
r5061 | node = ctx.node() | ||
Matt Mackall
|
r14290 | dest = cmdutil.makefilename(repo, dest, node) | ||
Matt Mackall
|
r15381 | if os.path.realpath(dest) == repo.root: | ||
Vadim Gelfer
|
r2112 | raise util.Abort(_('repository root cannot be destination')) | ||
David Wolever
|
r10650 | |||
Martin Geisler
|
r11557 | kind = opts.get('type') or archival.guesskind(dest) or 'files' | ||
Alexander Solovyov
|
r7131 | prefix = opts.get('prefix') | ||
David Wolever
|
r10650 | |||
Vadim Gelfer
|
r2476 | if dest == '-': | ||
if kind == 'files': | ||||
raise util.Abort(_('cannot archive plain files to stdout')) | ||||
Idan Kamara
|
r14742 | dest = cmdutil.makefileobj(repo, dest) | ||
Matt Mackall
|
r10282 | if not prefix: | ||
prefix = os.path.basename(repo.root) + '-%h' | ||||
David Wolever
|
r10650 | |||
Matt Mackall
|
r14290 | prefix = cmdutil.makefilename(repo, prefix, node) | ||
Matt Mackall
|
r14671 | matchfn = scmutil.match(ctx, [], opts) | ||
Alexander Solovyov
|
r7131 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), | ||
Martin Geisler
|
r12323 | matchfn, prefix, subrepos=opts.get('subrepos')) | ||
Vadim Gelfer
|
r2112 | |||
Adrian Buehlmann
|
r14297 | @command('backout', | ||
[('', 'merge', None, _('merge with old dirstate parent after backout')), | ||||
Matt Mackall
|
r15211 | ('', 'parent', '', | ||
_('parent to choose when backing out merge (DEPRECATED)'), _('REV')), | ||||
Adrian Buehlmann
|
r14297 | ('r', 'rev', '', _('revision to backout'), _('REV')), | ||
Martin Geisler
|
r14852 | ] + mergetoolopts + walkopts + commitopts + commitopts2, | ||
Adrian Buehlmann
|
r14297 | _('[OPTION]... [-r] REV')) | ||
Daniel Holth
|
r4450 | def backout(ui, repo, node=None, rev=None, **opts): | ||
Vadim Gelfer
|
r2158 | '''reverse effect of earlier changeset | ||
Jonathan Nieder
|
r13340 | Prepare a new changeset with the effect of REV undone in the | ||
current working directory. | ||||
Jonathan Nieder
|
r13473 | If REV is the parent of the working directory, then this new changeset | ||
Jonathan Nieder
|
r13340 | is committed automatically. Otherwise, hg needs to merge the | ||
changes and the merged result is left uncommitted. | ||||
Matt Mackall
|
r15210 | .. note:: | ||
backout cannot be used to fix either an unwanted or | ||||
incorrect merge. | ||||
Matt Mackall
|
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. | ||||
Thomas Arendsen Hein
|
r6163 | |||
Martin Geisler
|
r10973 | See :hg:`help dates` for a list of formats valid for -d/--date. | ||
Matt Mackall
|
r11177 | |||
Returns 0 on success. | ||||
Thomas Arendsen Hein
|
r6163 | ''' | ||
Daniel Holth
|
r4450 | if rev and node: | ||
raise util.Abort(_("please specify just one revision")) | ||||
if not rev: | ||||
rev = node | ||||
Vadim Gelfer
|
r2158 | |||
Thomas Arendsen Hein
|
r4726 | if not rev: | ||
raise util.Abort(_("please specify a revision to backout")) | ||||
Thomas Arendsen Hein
|
r6139 | date = opts.get('date') | ||
if date: | ||||
opts['date'] = util.parsedate(date) | ||||
Matt Mackall
|
r14289 | cmdutil.bailifchanged(repo) | ||
Matt Mackall
|
r14319 | node = scmutil.revsingle(repo, rev).node() | ||
Matt Mackall
|
r5716 | |||
Vadim Gelfer
|
r2158 | op1, op2 = repo.dirstate.parents() | ||
Matt Mackall
|
r5568 | a = repo.changelog.ancestor(op1, node) | ||
if a != node: | ||||
timeless
|
r8779 | raise util.Abort(_('cannot backout change on a different branch')) | ||
Matt Mackall
|
r5568 | |||
Vadim Gelfer
|
r2614 | p1, p2 = repo.changelog.parents(node) | ||
if p1 == nullid: | ||||
timeless
|
r8779 | raise util.Abort(_('cannot backout a change with no parents')) | ||
Vadim Gelfer
|
r2158 | if p2 != nullid: | ||
Alexander Solovyov
|
r7131 | if not opts.get('parent'): | ||
Matt Mackall
|
r15211 | raise util.Abort(_('cannot backout a merge changeset')) | ||
Vadim Gelfer
|
r2614 | p = repo.lookup(opts['parent']) | ||
if p not in (p1, p2): | ||||
Marcos Chaves
|
r3679 | raise util.Abort(_('%s is not a parent of %s') % | ||
Thomas Arendsen Hein
|
r3680 | (short(p), short(node))) | ||
Vadim Gelfer
|
r2614 | parent = p | ||
else: | ||||
Alexander Solovyov
|
r7131 | if opts.get('parent'): | ||
Vadim Gelfer
|
r2614 | raise util.Abort(_('cannot use --parent on non-merge changeset')) | ||
parent = p1 | ||||
Matt Mackall
|
r5568 | |||
Matt Mackall
|
r6423 | # the backout should appear on the same branch | ||
Idan Kamara
|
r16470 | wlock = repo.wlock() | ||
try: | ||||
branch = repo.dirstate.branch() | ||||
hg.clean(repo, node, show_stats=False) | ||||
repo.dirstate.setbranch(branch) | ||||
revert_opts = opts.copy() | ||||
revert_opts['date'] = None | ||||
revert_opts['all'] = True | ||||
revert_opts['rev'] = hex(parent) | ||||
revert_opts['no_backup'] = None | ||||
revert(ui, repo, **revert_opts) | ||||
if not opts.get('merge') and op1 != node: | ||||
try: | ||||
ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) | ||||
return hg.update(repo, op1) | ||||
finally: | ||||
ui.setconfig('ui', 'forcemerge', '') | ||||
commit_opts = opts.copy() | ||||
commit_opts['addremove'] = False | ||||
if not commit_opts['message'] and not commit_opts['logfile']: | ||||
# we don't translate commit messages | ||||
commit_opts['message'] = "Backed out changeset %s" % short(node) | ||||
commit_opts['force_editor'] = True | ||||
commit(ui, repo, **commit_opts) | ||||
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: | ||||
ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) | ||||
return hg.merge(repo, hex(repo.changelog.tip())) | ||||
finally: | ||||
ui.setconfig('ui', 'forcemerge', '') | ||||
finally: | ||||
wlock.release() | ||||
Gilles Moris
|
r12727 | return 0 | ||
Vadim Gelfer
|
r2158 | |||
Adrian Buehlmann
|
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]")) | ||||
Alexander Solovyov
|
r7227 | def bisect(ui, repo, rev=None, extra=None, command=None, | ||
Benoit Boissinot
|
r13601 | reset=None, good=None, bad=None, skip=None, extend=None, | ||
noupdate=None): | ||||
Matt Mackall
|
r5775 | """subdivision search of changesets | ||
Martin Geisler
|
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 | ||||
Martin Geisler
|
r8033 | for testing (unless the -U/--noupdate option is specified). Once | ||
timeless
|
r8779 | you have performed tests, mark the working directory as good or | ||
bad, and bisect will either update to another candidate changeset | ||||
Dirkjan Ochtman
|
r6928 | or announce that it has found the bad revision. | ||
Dirkjan Ochtman
|
r7184 | |||
Dirkjan Ochtman
|
r6928 | As a shortcut, you can also use the revision argument to mark a | ||
revision as good or bad without checking it out first. | ||||
Alexander Solovyov
|
r7227 | |||
timeless
|
r8779 | If you supply a command, it will be used for automatic bisection. | ||
Bryan O'Sullivan
|
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. | ||||
Matt Mackall
|
r11177 | |||
"Yann E. MORIN"
|
r15139 | .. container:: verbose | ||
Some examples: | ||||
- start a bisection with known bad revision 12, and good revision 34:: | ||||
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 | ||||
- mark the current revision, or a known revision, to be skipped (eg. if | ||||
that revision is not usable because of another issue):: | ||||
hg bisect --skip | ||||
hg bisect --skip 23 | ||||
- 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 | ||||
hg bisect --command 'make && make tests' | ||||
- see all changesets whose states are already known in the current | ||||
bisection:: | ||||
hg log -r "bisect(pruned)" | ||||
Bryan O'Sullivan
|
r16647 | - see the changeset currently being bisected (especially useful | ||
if running with -U/--noupdate):: | ||||
hg log -r "bisect(current)" | ||||
"Yann E. MORIN"
|
r15139 | - see all changesets that took part in the current bisection:: | ||
hg log -r "bisect(range)" | ||||
- with the graphlog extension, you can even get a nice graph:: | ||||
hg log --graph -r "bisect(range)" | ||||
"Yann E. MORIN"
|
r15147 | See :hg:`help revsets` for more about the `bisect()` keyword. | ||
Matt Mackall
|
r11177 | Returns 0 on success. | ||
Matt Mackall
|
r5775 | """ | ||
Benoit Boissinot
|
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: | ||||
Yuya Nishihara
|
r14157 | return parents[0].ancestor(parents[1]) | ||
Benoit Boissinot
|
r13601 | return None | ||
Alexander Solovyov
|
r7227 | def print_result(nodes, good): | ||
Matt Mackall
|
r5775 | displayer = cmdutil.show_changeset(ui, repo, {}) | ||
Bernhard Leiner
|
r6858 | if len(nodes) == 1: | ||
# narrowed it down to a single revision | ||||
Wagner Bruna
|
r8088 | if good: | ||
ui.write(_("The first good revision is:\n")) | ||||
else: | ||||
ui.write(_("The first bad revision is:\n")) | ||||
Dirkjan Ochtman
|
r7369 | displayer.show(repo[nodes[0]]) | ||
Benoit Boissinot
|
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') | ||||
Alexander Solovyov
|
r14055 | % extendnode) | ||
Bernhard Leiner
|
r6858 | else: | ||
# multiple possible revisions | ||||
Wagner Bruna
|
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")) | ||||
Bernhard Leiner
|
r6858 | for n in nodes: | ||
Dirkjan Ochtman
|
r7369 | displayer.show(repo[n]) | ||
Robert Bachmann
|
r10152 | displayer.close() | ||
Alexander Solovyov
|
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 | ||||
Benoit Boissinot
|
r13601 | elif extra or good + bad + skip + reset + extend + bool(command) > 1: | ||
Alexander Solovyov
|
r7227 | raise util.Abort(_('incompatible arguments')) | ||
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 | ||||
Benoit Boissinot
|
r7590 | try: | ||
Bryan O'Sullivan
|
r16647 | node = state['current'][0] | ||
except LookupError: | ||||
if noupdate: | ||||
raise util.Abort(_('current bisect revision is unknown - ' | ||||
'start a new bisect to fix')) | ||||
node, p2 = repo.dirstate.parents() | ||||
if p2 != nullid: | ||||
raise util.Abort(_('current bisect revision is a merge')) | ||||
try: | ||||
Benoit Boissinot
|
r7590 | while changesets: | ||
# update state | ||||
Bryan O'Sullivan
|
r16647 | state['current'] = [node] | ||
Bryan O'Sullivan
|
r16593 | hbisect.save_state(repo, state) | ||
Bryan O'Sullivan
|
r16648 | status = util.system(command, | ||
environ={'HG_NODE': hex(node)}, | ||||
out=ui.fout) | ||||
Benoit Boissinot
|
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" | ||||
Bryan O'Sullivan
|
r16647 | ctx = scmutil.revsingle(repo, rev, node) | ||
Matt Mackall
|
r12925 | rev = None # clear for future iterations | ||
Patrick Mezard
|
r8805 | state[transition].append(ctx.node()) | ||
ui.status(_('Changeset %d:%s: %s\n') % (ctx, ctx, transition)) | ||||
Benoit Boissinot
|
r7590 | check_state(state, interactive=False) | ||
# bisect | ||||
nodes, changesets, good = hbisect.bisect(repo.changelog, state) | ||||
# update to next check | ||||
Bryan O'Sullivan
|
r16647 | node = nodes[0] | ||
if not noupdate: | ||||
cmdutil.bailifchanged(repo) | ||||
hg.clean(repo, node, show_stats=False) | ||||
Benoit Boissinot
|
r7590 | finally: | ||
Bryan O'Sullivan
|
r16647 | state['current'] = [node] | ||
Benoit Boissinot
|
r7590 | hbisect.save_state(repo, state) | ||
Matt Mackall
|
r11177 | print_result(nodes, good) | ||
return | ||||
Alexander Solovyov
|
r7227 | |||
# update state | ||||
Dirkjan Ochtman
|
r12177 | |||
if rev: | ||||
Matt Mackall
|
r14319 | nodes = [repo.lookup(i) for i in scmutil.revrange(repo, [rev])] | ||
Dirkjan Ochtman
|
r12177 | else: | ||
nodes = [repo.lookup('.')] | ||||
Benoit Boissinot
|
r9689 | if good or bad or skip: | ||
if good: | ||||
Dirkjan Ochtman
|
r12177 | state['good'] += nodes | ||
Benoit Boissinot
|
r9689 | elif bad: | ||
Dirkjan Ochtman
|
r12177 | state['bad'] += nodes | ||
Benoit Boissinot
|
r9689 | elif skip: | ||
Dirkjan Ochtman
|
r12177 | state['skip'] += nodes | ||
Benoit Boissinot
|
r9689 | hbisect.save_state(repo, state) | ||
Alexander Solovyov
|
r7227 | |||
if not check_state(state): | ||||
return | ||||
# actually bisect | ||||
nodes, changesets, good = hbisect.bisect(repo.changelog, state) | ||||
Benoit Boissinot
|
r13601 | if extend: | ||
if not changesets: | ||||
extendnode = extendbisectrange(nodes, good) | ||||
if extendnode is not None: | ||||
ui.write(_("Extending search to changeset %d:%s\n" | ||||
Alexander Solovyov
|
r14055 | % (extendnode.rev(), extendnode))) | ||
Bryan O'Sullivan
|
r16647 | state['current'] = [extendnode.node()] | ||
hbisect.save_state(repo, state) | ||||
Benoit Boissinot
|
r13601 | if noupdate: | ||
return | ||||
Matt Mackall
|
r14289 | cmdutil.bailifchanged(repo) | ||
Benoit Boissinot
|
r13601 | return hg.clean(repo, extendnode.node()) | ||
raise util.Abort(_("nothing to extend")) | ||||
Alexander Solovyov
|
r7227 | if changesets == 0: | ||
print_result(nodes, good) | ||||
Bernhard Leiner
|
r6858 | else: | ||
assert len(nodes) == 1 # only a single node can be tested next | ||||
node = nodes[0] | ||||
Matt Mackall
|
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) | ||||
Cédric Duval
|
r9012 | ui.write(_("Testing changeset %d:%s " | ||
"(%d changesets remaining, ~%d tests)\n") | ||||
Joel Rosdahl
|
r6217 | % (rev, short(node), changesets, tests)) | ||
Bryan O'Sullivan
|
r16647 | state['current'] = [node] | ||
hbisect.save_state(repo, state) | ||||
Matt Mackall
|
r5775 | if not noupdate: | ||
Matt Mackall
|
r14289 | cmdutil.bailifchanged(repo) | ||
Matt Mackall
|
r5775 | return hg.clean(repo, node) | ||
Adrian Buehlmann
|
r14297 | @command('bookmarks', | ||
[('f', 'force', False, _('force')), | ||||
('r', 'rev', '', _('revision'), _('REV')), | ||||
('d', 'delete', False, _('delete a given bookmark')), | ||||
('m', 'rename', '', _('rename a given bookmark'), _('NAME')), | ||||
Matt Mackall
|
r15959 | ('i', 'inactive', False, _('mark a bookmark inactive'))], | ||
Adrian Buehlmann
|
r14297 | _('hg bookmarks [-f] [-d] [-i] [-m NAME] [-r REV] [NAME]')) | ||
Kevin Bullock
|
r14188 | def bookmark(ui, repo, mark=None, rev=None, force=False, delete=False, | ||
rename=None, inactive=False): | ||||
Matt Mackall
|
r13368 | '''track a line of development with movable markers | ||
Kevin Bullock
|
r15620 | Bookmarks are pointers to certain commits that move when committing. | ||
Bookmarks are local. They can be renamed, copied and deleted. It is | ||||
possible to use :hg:`merge NAME` to merge from a given bookmark, and | ||||
:hg:`update NAME` to update to a given bookmark. | ||||
Matt Mackall
|
r13368 | |||
You can use :hg:`bookmark NAME` to set a bookmark on the working | ||||
directory's parent revision with the given name. If you specify | ||||
a revision using -r REV (where REV may be an existing bookmark), | ||||
the bookmark is assigned to that revision. | ||||
Bookmarks can be pushed and pulled between repositories (see :hg:`help | ||||
Kevin Bullock
|
r13407 | push` and :hg:`help pull`). This requires both the local and remote | ||
repositories to support bookmarks. For versions prior to 1.8, this means | ||||
the bookmarks extension must be enabled. | ||||
Kevin Bullock
|
r15939 | |||
With -i/--inactive, the new bookmark will not be made the active | ||||
bookmark. If -r/--rev is given, the new bookmark will not be made | ||||
active even if -i/--inactive is not given. If no NAME is given, the | ||||
current active bookmark will be marked inactive. | ||||
Matt Mackall
|
r13368 | ''' | ||
hexfn = ui.debugflag and hex or short | ||||
marks = repo._bookmarks | ||||
cur = repo.changectx('.').node() | ||||
Kevin Bullock
|
r15490 | if delete: | ||
if mark is None: | ||||
raise util.Abort(_("bookmark name required")) | ||||
if mark not in marks: | ||||
raise util.Abort(_("bookmark '%s' does not exist") % mark) | ||||
if mark == repo._bookmarkcurrent: | ||||
bookmarks.setcurrent(repo, None) | ||||
del marks[mark] | ||||
bookmarks.write(repo) | ||||
return | ||||
Matt Mackall
|
r13368 | if rename: | ||
if rename not in marks: | ||||
Idan Kamara
|
r13911 | raise util.Abort(_("bookmark '%s' does not exist") % rename) | ||
Matt Mackall
|
r13368 | if mark in marks and not force: | ||
Idan Kamara
|
r13911 | raise util.Abort(_("bookmark '%s' already exists " | ||
"(use -f to force)") % mark) | ||||
Matt Mackall
|
r13368 | if mark is None: | ||
raise util.Abort(_("new bookmark name required")) | ||||
marks[mark] = marks[rename] | ||||
Kevin Bullock
|
r14188 | if repo._bookmarkcurrent == rename and not inactive: | ||
Matt Mackall
|
r13368 | bookmarks.setcurrent(repo, mark) | ||
Benoit Boissinot
|
r13620 | del marks[rename] | ||
Matt Mackall
|
r13368 | bookmarks.write(repo) | ||
return | ||||
if mark is not None: | ||||
if "\n" in mark: | ||||
raise util.Abort(_("bookmark name cannot contain newlines")) | ||||
mark = mark.strip() | ||||
if not mark: | ||||
raise util.Abort(_("bookmark names cannot consist entirely of " | ||||
"whitespace")) | ||||
Kevin Bullock
|
r14189 | if inactive and mark == repo._bookmarkcurrent: | ||
bookmarks.setcurrent(repo, None) | ||||
return | ||||
Matt Mackall
|
r13368 | if mark in marks and not force: | ||
Idan Kamara
|
r13911 | raise util.Abort(_("bookmark '%s' already exists " | ||
"(use -f to force)") % mark) | ||||
Matt Mackall
|
r13368 | if ((mark in repo.branchtags() or mark == repo.dirstate.branch()) | ||
and not force): | ||||
raise util.Abort( | ||||
_("a bookmark cannot have the name of an existing branch")) | ||||
if rev: | ||||
marks[mark] = repo.lookup(rev) | ||||
else: | ||||
Kevin Bullock
|
r15491 | marks[mark] = cur | ||
if not inactive and cur == marks[mark]: | ||||
David Soria Parra
|
r13448 | bookmarks.setcurrent(repo, mark) | ||
Matt Mackall
|
r13368 | bookmarks.write(repo) | ||
return | ||||
if mark is None: | ||||
if rev: | ||||
raise util.Abort(_("bookmark name required")) | ||||
if len(marks) == 0: | ||||
ui.status(_("no bookmarks set\n")) | ||||
else: | ||||
David Soria Parra
|
r13388 | for bmark, n in sorted(marks.iteritems()): | ||
David Soria Parra
|
r13416 | current = repo._bookmarkcurrent | ||
if bmark == current and n == cur: | ||||
prefix, label = '*', 'bookmarks.current' | ||||
Matt Mackall
|
r13368 | else: | ||
David Soria Parra
|
r13416 | prefix, label = ' ', '' | ||
Matt Mackall
|
r13368 | |||
if ui.quiet: | ||||
ui.write("%s\n" % bmark, label=label) | ||||
else: | ||||
ui.write(" %s %-25s %d:%s\n" % ( | ||||
prefix, bmark, repo.changelog.rev(n), hexfn(n)), | ||||
label=label) | ||||
return | ||||
Adrian Buehlmann
|
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]')) | ||||
Brendan Cully
|
r4202 | def branch(ui, repo, label=None, **opts): | ||
Matt Mackall
|
r3502 | """set or show the current branch name | ||
Matt Mackall
|
r15610 | .. note:: | ||
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. | ||||
Brendan Cully
|
r4601 | With no argument, show the current branch name. With one argument, | ||
timeless
|
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. | ||||
Brendan Cully
|
r4202 | |||
Martin Geisler
|
r8033 | Unless -f/--force is specified, branch will not let you set a | ||
timeless
|
r8779 | branch name that already exists, even if it's inactive. | ||
Thomas Arendsen Hein
|
r5999 | |||
Martin Geisler
|
r8033 | Use -C/--clean to reset the working directory branch to that of | ||
the parent of the working directory, negating a previous branch | ||||
Martin Geisler
|
r8004 | change. | ||
Sune Foldager
|
r7006 | |||
Martin Geisler
|
r10973 | Use the command :hg:`update` to switch to an existing branch. Use | ||
:hg:`commit --close-branch` to mark this branch as closed. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success. | ||||
Matt Mackall
|
r3502 | """ | ||
Idan Kamara
|
r16471 | if not opts.get('clean') and not label: | ||
Matt Mackall
|
r13047 | ui.write("%s\n" % repo.dirstate.branch()) | ||
Idan Kamara
|
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: | ||||
if not opts.get('force') and label in repo.branchtags(): | ||||
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")) | ||||
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() | ||||
Matt Mackall
|
r3502 | |||
Adrian Buehlmann
|
r14297 | @command('branches', | ||
[('a', 'active', False, _('show only branches that have unmerged heads')), | ||||
('c', 'closed', False, _('show normal and closed branches'))], | ||||
_('[-ac]')) | ||||
Matt Mackall
|
r8991 | def branches(ui, repo, active=False, closed=False): | ||
Matt Mackall
|
r3502 | """list repository named branches | ||
Eric Hopper
|
r4675 | List the repository's named branches, indicating which ones are | ||
Matt Mackall
|
r8991 | inactive. If -c/--closed is specified, also list branches which have | ||
Martin Geisler
|
r11193 | been marked closed (see :hg:`commit --close-branch`). | ||
Matt Mackall
|
r8991 | |||
If -a/--active is specified, only show active branches. A branch | ||||
is considered active if it contains repository heads. | ||||
Thomas Arendsen Hein
|
r5999 | |||
Martin Geisler
|
r10973 | Use the command :hg:`update` to switch to an existing branch. | ||
Matt Mackall
|
r11177 | |||
Returns 0. | ||||
Matt Mackall
|
r3502 | """ | ||
Matt Mackall
|
r8991 | |||
Stefano Tortarolo
|
r6631 | hexfunc = ui.debugflag and hex or short | ||
Benoit Boissinot
|
r9675 | activebranches = [repo[n].branch() for n in repo.heads()] | ||
John Mulligan
|
r8796 | def testactive(tag, node): | ||
realhead = tag in activebranches | ||||
open = node in repo.branchheads(tag, closed=False) | ||||
return realhead and open | ||||
branches = sorted([(testactive(tag, node), repo.changelog.rev(node), tag) | ||||
Matt Mackall
|
r8210 | for tag, node in repo.branchtags().items()], | ||
reverse=True) | ||||
Stefano Tortarolo
|
r6631 | |||
for isactive, node, tag in branches: | ||||
if (not active) or isactive: | ||||
Travis Herrick
|
r16612 | hn = repo.lookup(node) | ||
if isactive: | ||||
label = 'branches.active' | ||||
notice = '' | ||||
elif hn not in repo.branchheads(tag, closed=False): | ||||
if not closed: | ||||
continue | ||||
label = 'branches.closed' | ||||
notice = _(' (closed)') | ||||
else: | ||||
label = 'branches.inactive' | ||||
notice = _(' (inactive)') | ||||
if tag == repo.dirstate.branch(): | ||||
label = 'branches.current' | ||||
rev = str(node).rjust(31 - encoding.colwidth(tag)) | ||||
rev = ui.label('%s:%s' % (rev, hexfunc(hn)), 'log.changeset') | ||||
tag = ui.label(tag, label) | ||||
Eric Hopper
|
r4675 | if ui.quiet: | ||
Matt Mackall
|
r13047 | ui.write("%s\n" % tag) | ||
Eric Hopper
|
r4675 | else: | ||
Matt Mackall
|
r13047 | ui.write("%s %s%s\n" % (tag, rev, notice)) | ||
Matt Mackall
|
r3502 | |||
Adrian Buehlmann
|
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]')) | ||||
Vadim Gelfer
|
r2494 | def bundle(ui, repo, fname, dest=None, **opts): | ||
Benoit Boissinot
|
r1437 | """create a changegroup file | ||
Thomas Arendsen Hein
|
r3511 | Generate a compressed changegroup file collecting changesets not | ||
timeless
|
r7807 | known to be in another repository. | ||
Thomas Arendsen Hein
|
r3511 | |||
timeless
|
r10376 | If you omit the destination repository, then hg assumes the | ||
destination will have all the nodes you specify with --base | ||||
Christian Ebert
|
r6448 | parameters. To create a bundle containing all changesets, use | ||
Henrik Stuart
|
r8903 | -a/--all (or --base null). | ||
Stefano Mioli
|
r8958 | You can change compression method with the -t/--type option. | ||
The available compression methods are: none, bzip2, and | ||||
Henrik Stuart
|
r8903 | gzip (by default, bundles are compressed using bzip2). | ||
Thomas Arendsen Hein
|
r3511 | |||
Martin Geisler
|
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. | ||||
Thomas Arendsen Hein
|
r3511 | |||
Applying bundles preserves all changeset contents including | ||||
permissions, copy/rename information, and revision history. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success, 1 if no changes found. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r12925 | revs = None | ||
if 'rev' in opts: | ||||
Matt Mackall
|
r14319 | revs = scmutil.revrange(repo, opts['rev']) | ||
Matt Mackall
|
r12925 | |||
Bryan O'Sullivan
|
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')) | ||||
John Mulligan
|
r6171 | if opts.get('all'): | ||
base = ['null'] | ||||
else: | ||||
Matt Mackall
|
r14319 | base = scmutil.revrange(repo, opts.get('base')) | ||
Benoit Boissinot
|
r3284 | if base: | ||
if dest: | ||||
Martin Geisler
|
r8669 | raise util.Abort(_("--base is incompatible with specifying " | ||
Benoit Boissinot
|
r3284 | "a destination")) | ||
Peter Arrenbrecht
|
r14073 | common = [repo.lookup(rev) for rev in base] | ||
Pierre-Yves David
|
r15837 | heads = revs and map(repo.lookup, revs) or revs | ||
cg = repo.getbundle('bundle', heads=heads, common=common) | ||||
Matt Mackall
|
r15993 | outgoing = None | ||
Benoit Boissinot
|
r3284 | else: | ||
Sune Foldager
|
r10365 | dest = ui.expandpath(dest or 'default-push', dest or 'default') | ||
Sune Foldager
|
r10379 | dest, branches = hg.parseurl(dest, opts.get('branch')) | ||
Matt Mackall
|
r14556 | other = hg.peer(repo, opts, dest) | ||
Sune Foldager
|
r10365 | revs, checkout = hg.addbranchrevs(repo, other, branches, revs) | ||
Peter Arrenbrecht
|
r14213 | heads = revs and map(repo.lookup, revs) or revs | ||
Pierre-Yves David
|
r15837 | outgoing = discovery.findcommonoutgoing(repo, other, | ||
onlyheads=heads, | ||||
force=opts.get('force')) | ||||
cg = repo.getlocalbundle('bundle', outgoing) | ||||
Peter Arrenbrecht
|
r14073 | if not cg: | ||
Matt Mackall
|
r15993 | scmutil.nochangesfound(ui, outgoing and outgoing.excluded) | ||
Matt Mackall
|
r11177 | return 1 | ||
Benoit Boissinot
|
r10616 | |||
Benoit Allard
|
r6570 | changegroup.writebundle(cg, fname, bundletype) | ||
mpm@selenic.com
|
r1218 | |||
Adrian Buehlmann
|
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, | ||||
_('[OPTION]... FILE...')) | ||||
Bryan O'Sullivan
|
r1254 | def cat(ui, repo, file1, *pats, **opts): | ||
Thomas Arendsen Hein
|
r3914 | """output the current or given revision of files | ||
Benoit Boissinot
|
r1437 | |||
Martin Geisler
|
r8004 | Print the specified files as they were at the given revision. If | ||
no revision is given, the parent of the working directory is used, | ||||
Thomas Arendsen Hein
|
r3915 | or tip if no revision is checked out. | ||
Benoit Boissinot
|
r1437 | |||
Output may be to a file, in which case the name of the file is | ||||
Christian Ebert
|
r6448 | given using a format string. The formatting rules are the same as | ||
Martin Geisler
|
r9892 | for the export command, with the following additions: | ||
:``%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 | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r14319 | ctx = scmutil.revsingle(repo, opts.get('rev')) | ||
Matt Mackall
|
r4697 | err = 1 | ||
Matt Mackall
|
r14671 | m = scmutil.match(ctx, (file1,) + pats, opts) | ||
Matt Mackall
|
r6764 | for abs in ctx.walk(m): | ||
Matt Mackall
|
r14291 | fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(), | ||
pathname=abs) | ||||
Matt Mackall
|
r6764 | data = ctx[abs].data() | ||
Thomas Arendsen Hein
|
r6094 | if opts.get('decode'): | ||
Jesse Glick
|
r6093 | data = repo.wwritedata(abs, data) | ||
fp.write(data) | ||||
Dan Villiom Podlaski Christiansen
|
r13400 | fp.close() | ||
Matt Mackall
|
r4697 | err = 0 | ||
return err | ||||
mpm@selenic.com
|
r248 | |||
Adrian Buehlmann
|
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, | ||||
_('[OPTION]... SOURCE [DEST]')) | ||||
Thomas Arendsen Hein
|
r698 | def clone(ui, source, dest=None, **opts): | ||
Benoit Boissinot
|
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 | ||||
Javi Merino
|
r13344 | ``.hg/hgrc`` file, as the default to be used for future pulls. | ||
Benoit Boissinot
|
r1437 | |||
Matt Mackall
|
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. | ||||
Matt Mackall
|
r7942 | |||
Matt Mackall
|
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. | ||||
Adrian Buehlmann
|
r9714 | |||
Matt Mackall
|
r15178 | To check out a particular version, use -u/--update, or | ||
-U/--noupdate to create a clone with no working directory. | ||||
Matt Mackall
|
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 | ||||
g) the tipmost head of the default branch | ||||
h) tip | ||||
Matt Mackall
|
r11177 | |||
Matt Mackall
|
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 | ||||
Matt Mackall
|
r15175 | See :hg:`help urls` for details on specifying URLs. | ||
Matt Mackall
|
r11177 | Returns 0 on success. | ||
Benoit Boissinot
|
r1437 | """ | ||
Adrian Buehlmann
|
r9714 | if opts.get('noupdate') and opts.get('updaterev'): | ||
raise util.Abort(_("cannot specify both --noupdate and --updaterev")) | ||||
Peter Arrenbrecht
|
r14553 | r = hg.clone(ui, opts, source, dest, | ||
Matt Mackall
|
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 | ||||
mpm@selenic.com
|
r515 | |||
Adrian Buehlmann
|
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')), | ||||
Idan Kamara
|
r16458 | ('', 'amend', None, _('amend the parent of the working dir')), | ||
Martin Geisler
|
r15321 | ] + walkopts + commitopts + commitopts2 + subrepoopts, | ||
Adrian Buehlmann
|
r14297 | _('[OPTION]... [FILE]...')) | ||
Bryan O'Sullivan
|
r813 | def commit(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """commit the specified files or all outstanding changes | ||
Martin Geisler
|
r7983 | Commit changes to the given files into the repository. Unlike a | ||
Adrian Buehlmann
|
r13303 | centralized SCM, this operation is a local operation. See | ||
Martin Geisler
|
r11193 | :hg:`push` for a way to actively distribute your changes. | ||
Benoit Boissinot
|
r1437 | |||
Martin Geisler
|
r10973 | If a list of files is omitted, all changes reported by :hg:`status` | ||
mcmillen@cs.cmu.edu
|
r1995 | will be committed. | ||
Benoit Boissinot
|
r1437 | |||
Bryan O'Sullivan
|
r6385 | If you are committing the result of a merge, do not provide any | ||
timeless
|
r8761 | filenames or -I/-X filters. | ||
Bryan O'Sullivan
|
r6385 | |||
Greg Ward
|
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``. | ||||
Thomas Arendsen Hein
|
r6163 | |||
Idan Kamara
|
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. | ||||
Martin Geisler
|
r10973 | See :hg:`help dates` for a list of formats valid for -d/--date. | ||
Matt Mackall
|
r11177 | |||
Returns 0 on success, 1 if nothing changed. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Martin Geisler
|
r15321 | if opts.get('subrepos'): | ||
# Let --subrepos on the command line overide config setting. | ||||
ui.setconfig('ui', 'commitsubrepos', True) | ||||
John Mulligan
|
r7655 | extra = {} | ||
if opts.get('close_branch'): | ||||
Gilles Moris
|
r11163 | if repo['.'].node() not in repo.branchheads(): | ||
# The topo heads set is included in the branch heads set of the | ||||
# current branch, so it's sufficient to test branchheads | ||||
raise util.Abort(_('can only close branch heads')) | ||||
John Mulligan
|
r7655 | extra['close'] = 1 | ||
Dirkjan Ochtman
|
r6336 | |||
Matt Mackall
|
r11173 | branch = repo[None].branch() | ||
bheads = repo.branchheads(branch) | ||||
Idan Kamara
|
r16458 | if opts.get('amend'): | ||
Adrian Buehlmann
|
r16505 | if ui.configbool('ui', 'commitsubrepos'): | ||
Idan Kamara
|
r16458 | raise util.Abort(_('cannot amend recursively')) | ||
old = repo['.'] | ||||
if old.phase() == phases.public: | ||||
raise util.Abort(_('cannot amend public changesets')) | ||||
if len(old.parents()) > 1: | ||||
raise util.Abort(_('cannot amend merge changesets')) | ||||
if len(repo[None].parents()) > 1: | ||||
raise util.Abort(_('cannot amend while merging')) | ||||
if old.children(): | ||||
raise util.Abort(_('cannot amend changeset with children')) | ||||
e = cmdutil.commiteditor | ||||
if opts.get('force_editor'): | ||||
e = cmdutil.commitforceeditor | ||||
def commitfunc(ui, repo, message, match, opts): | ||||
editor = e | ||||
# message contains text from -m or -l, if it's empty, | ||||
# open the editor with the old message | ||||
if not message: | ||||
message = old.description() | ||||
editor = cmdutil.commitforceeditor | ||||
return repo.commit(message, | ||||
opts.get('user') or old.user(), | ||||
opts.get('date') or old.date(), | ||||
match, | ||||
editor=editor, | ||||
extra=extra) | ||||
node = cmdutil.amend(ui, repo, commitfunc, old, extra, pats, opts) | ||||
if node == old.node(): | ||||
Martin Geisler
|
r13899 | ui.status(_("nothing changed\n")) | ||
Idan Kamara
|
r16458 | return 1 | ||
else: | ||||
e = cmdutil.commiteditor | ||||
if opts.get('force_editor'): | ||||
e = cmdutil.commitforceeditor | ||||
def commitfunc(ui, repo, message, match, opts): | ||||
return repo.commit(message, opts.get('user'), opts.get('date'), | ||||
match, editor=e, extra=extra) | ||||
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 | ||||
Matt Mackall
|
r11173 | |||
ctx = repo[node] | ||||
parents = ctx.parents() | ||||
Idan Kamara
|
r16458 | if (not opts.get('amend') and bheads and node not in bheads and not | ||
Matt Mackall
|
r14874 | [x for x in parents if x.node() in bheads and x.branch() == branch]): | ||
Dirkjan Ochtman
|
r6336 | ui.status(_('created new head\n')) | ||
Gilles Moris
|
r11317 | # The message is not printed for initial roots. For the other | ||
# changesets, it is printed in the following situations: | ||||
# | ||||
# Par column: for the 2 parents with ... | ||||
# N: null or no parent | ||||
# B: parent is on another named branch | ||||
# C: parent is a regular non head changeset | ||||
# H: parent was a branch head of the current branch | ||||
# Msg column: whether we print "created new head" message | ||||
# In the following, it is assumed that there already exists some | ||||
# initial branch heads of the current branch, otherwise nothing is | ||||
# printed anyway. | ||||
# | ||||
# Par Msg Comment | ||||
# NN y additional topo root | ||||
# | ||||
# BN y additional branch root | ||||
# CN y additional topo head | ||||
# HN n usual case | ||||
# | ||||
# BB y weird additional branch root | ||||
# CB y branch merge | ||||
# HB n merge with named branch | ||||
# | ||||
# CC y additional head from merge | ||||
# CH n merge with a head | ||||
# | ||||
# HH n head merge: head count decreases | ||||
mpm@selenic.com
|
r245 | |||
Gilles Moris
|
r11164 | if not opts.get('close_branch'): | ||
for r in parents: | ||||
Robert Bauck Hamar
|
r11515 | if r.extra().get('close') and r.branch() == branch: | ||
Gilles Moris
|
r11164 | ui.status(_('reopening closed branch head %d\n') % r) | ||
Gilles Moris
|
r6935 | if ui.debugflag: | ||
Matt Mackall
|
r11173 | ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx.hex())) | ||
Gilles Moris
|
r6935 | elif ui.verbose: | ||
Matt Mackall
|
r11173 | ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx)) | ||
Gilles Moris
|
r6935 | |||
Adrian Buehlmann
|
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')) | ||||
Bryan O'Sullivan
|
r1253 | def copy(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """mark files as copied for the next commit | ||
Christian Ebert
|
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, | ||||
timeless
|
r7807 | the source must be a single file. | ||
Benoit Boissinot
|
r1437 | |||
By default, this command copies the contents of files as they | ||||
timeless
|
r8779 | exist in the working directory. If invoked with -A/--after, the | ||
Benoit Boissinot
|
r1437 | operation is recorded, but no copying is performed. | ||
timeless
|
r7807 | This command takes effect with the next commit. To undo a copy | ||
Martin Geisler
|
r11193 | before that, see :hg:`revert`. | ||
Matt Mackall
|
r11177 | |||
Returns 0 on success, 1 if errors are encountered. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r4914 | wlock = repo.wlock(False) | ||
Matt Mackall
|
r4915 | try: | ||
Matt Mackall
|
r5610 | return cmdutil.copy(ui, repo, pats, opts) | ||
Matt Mackall
|
r4915 | finally: | ||
Ronny Pfannschmidt
|
r8109 | wlock.release() | ||
mpm@selenic.com
|
r363 | |||
Adrian Buehlmann
|
r14297 | @command('debugancestor', [], _('[INDEX] REV1 REV2')) | ||
Thomas Arendsen Hein
|
r6189 | def debugancestor(ui, repo, *args): | ||
mpm@selenic.com
|
r1262 | """find the ancestor revision of two revisions in a given index""" | ||
Thomas Arendsen Hein
|
r6188 | if len(args) == 3: | ||
index, rev1, rev2 = args | ||||
Adrian Buehlmann
|
r13970 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), index) | ||
Alexis S. L. Carvalho
|
r6253 | lookup = r.lookup | ||
Thomas Arendsen Hein
|
r6188 | elif len(args) == 2: | ||
Thomas Arendsen Hein
|
r6189 | if not repo: | ||
Martin Geisler
|
r12067 | raise util.Abort(_("there is no Mercurial repository here " | ||
Thomas Arendsen Hein
|
r6189 | "(.hg not found)")) | ||
Thomas Arendsen Hein
|
r6188 | rev1, rev2 = args | ||
Bryan O'Sullivan
|
r6178 | r = repo.changelog | ||
Alexis S. L. Carvalho
|
r6253 | lookup = repo.lookup | ||
Bryan O'Sullivan
|
r6178 | else: | ||
raise util.Abort(_('either two or three arguments required')) | ||||
Alexis S. L. Carvalho
|
r6253 | a = r.ancestor(lookup(rev1), lookup(rev2)) | ||
mpm@selenic.com
|
r1262 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) | ||
Adrian Buehlmann
|
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]')) | ||||
Martin Geisler
|
r14283 | def debugbuilddag(ui, repo, text=None, | ||
Peter Arrenbrecht
|
r11337 | mergeable_file=False, | ||
overwritten_file=False, | ||||
new_file=False): | ||||
Martin Geisler
|
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. | ||||
Peter Arrenbrecht
|
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 | ||||
Martin Geisler
|
r11881 | be enclosed in double quotes ("..."), with "\\" as escape character. | ||
Peter Arrenbrecht
|
r11337 | """ | ||
Martin Geisler
|
r14283 | if text is None: | ||
ui.status(_("reading DAG from stdin\n")) | ||||
Idan Kamara
|
r14639 | text = ui.fin.read() | ||
Martin Geisler
|
r14283 | |||
Peter Arrenbrecht
|
r14163 | cl = repo.changelog | ||
if len(cl) > 0: | ||||
Martin Geisler
|
r11342 | raise util.Abort(_('repository is not empty')) | ||
Peter Arrenbrecht
|
r11337 | |||
Martin Geisler
|
r14279 | # determine number of revs in DAG | ||
total = 0 | ||||
for type, data in dagparser.parsedag(text): | ||||
if type == 'n': | ||||
total += 1 | ||||
Peter Arrenbrecht
|
r11337 | |||
if mergeable_file: | ||||
linesperrev = 2 | ||||
# make a file with k lines per rev | ||||
Martin Geisler
|
r14279 | initialmergedlines = [str(i) for i in xrange(0, total * linesperrev)] | ||
Peter Arrenbrecht
|
r14163 | initialmergedlines.append("") | ||
tags = [] | ||||
Mads Kiilerich
|
r15875 | lock = tr = None | ||
Peter Arrenbrecht
|
r14163 | try: | ||
Mads Kiilerich
|
r15875 | lock = repo.lock() | ||
tr = repo.transaction("builddag") | ||||
Peter Arrenbrecht
|
r14163 | |||
at = -1 | ||||
atbranch = 'default' | ||||
nodeids = [] | ||||
Wagner Bruna
|
r16219 | id = 0 | ||
ui.progress(_('building'), id, unit=_('revisions'), total=total) | ||||
Peter Arrenbrecht
|
r11337 | for type, data in dagparser.parsedag(text): | ||
if type == 'n': | ||||
Peter Arrenbrecht
|
r14163 | ui.note('node %s\n' % str(data)) | ||
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) | ||||
base, local, other = [x[fn].data() for x in pa, p1, p2] | ||||
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) | ||||
fctxs[fn] = context.memfilectx(fn, mergedtext) | ||||
if overwritten_file: | ||||
fn = "of" | ||||
files.append(fn) | ||||
fctxs[fn] = context.memfilectx(fn, "r%i\n" % id) | ||||
if new_file: | ||||
fn = "nf%i" % id | ||||
files.append(fn) | ||||
fctxs[fn] = context.memfilectx(fn, "r%i\n" % id) | ||||
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 | ||||
ui.note('tag %s\n' % name) | ||||
tags.append("%s %s\n" % (hex(repo.changelog.node(id)), name)) | ||||
elif type == 'a': | ||||
ui.note('branch %s\n' % data) | ||||
atbranch = data | ||||
Martin Geisler
|
r14279 | ui.progress(_('building'), id, unit=_('revisions'), total=total) | ||
Peter Arrenbrecht
|
r14163 | tr.close() | ||
Mads Kiilerich
|
r15875 | |||
if tags: | ||||
repo.opener.write("localtags", "".join(tags)) | ||||
Peter Arrenbrecht
|
r14163 | finally: | ||
Martin Geisler
|
r14279 | ui.progress(_('building'), None) | ||
Mads Kiilerich
|
r15875 | release(tr, lock) | ||
Peter Arrenbrecht
|
r11337 | |||
Adrian Buehlmann
|
r14297 | @command('debugbundle', [('a', 'all', None, _('show all details'))], _('FILE')) | ||
Peter Arrenbrecht
|
r13724 | def debugbundle(ui, bundlepath, all=None, **opts): | ||
"""lists the contents of a bundle""" | ||||
f = url.open(ui, bundlepath) | ||||
Matt Mackall
|
r4915 | try: | ||
Patrick Mezard
|
r13747 | gen = changegroup.readbundle(f, bundlepath) | ||
if all: | ||||
Benoit Boissinot
|
r14141 | ui.write("format: id, p1, p2, cset, delta base, len(delta)\n") | ||
Patrick Mezard
|
r13747 | |||
def showchunks(named): | ||||
ui.write("\n%s\n" % named) | ||||
Benoit Boissinot
|
r14141 | chain = None | ||
Martin Geisler
|
r14494 | while True: | ||
Benoit Boissinot
|
r14144 | chunkdata = gen.deltachunk(chain) | ||
Peter Arrenbrecht
|
r13724 | if not chunkdata: | ||
break | ||||
node = chunkdata['node'] | ||||
Patrick Mezard
|
r13747 | p1 = chunkdata['p1'] | ||
p2 = chunkdata['p2'] | ||||
cs = chunkdata['cs'] | ||||
Benoit Boissinot
|
r14141 | deltabase = chunkdata['deltabase'] | ||
delta = chunkdata['delta'] | ||||
ui.write("%s %s %s %s %s %s\n" % | ||||
Patrick Mezard
|
r13747 | (hex(node), hex(p1), hex(p2), | ||
Benoit Boissinot
|
r14141 | hex(cs), hex(deltabase), len(delta))) | ||
chain = node | ||||
Patrick Mezard
|
r13747 | |||
Benoit Boissinot
|
r14144 | chunkdata = gen.changelogheader() | ||
Patrick Mezard
|
r13747 | showchunks("changelog") | ||
Benoit Boissinot
|
r14144 | chunkdata = gen.manifestheader() | ||
Patrick Mezard
|
r13747 | showchunks("manifest") | ||
Martin Geisler
|
r14494 | while True: | ||
Benoit Boissinot
|
r14144 | chunkdata = gen.filelogheader() | ||
if not chunkdata: | ||||
Patrick Mezard
|
r13747 | break | ||
Benoit Boissinot
|
r14144 | fname = chunkdata['filename'] | ||
Patrick Mezard
|
r13747 | showchunks(fname) | ||
else: | ||||
Benoit Boissinot
|
r14144 | chunkdata = gen.changelogheader() | ||
Benoit Boissinot
|
r14141 | chain = None | ||
Martin Geisler
|
r14494 | while True: | ||
Benoit Boissinot
|
r14144 | chunkdata = gen.deltachunk(chain) | ||
Patrick Mezard
|
r13747 | if not chunkdata: | ||
break | ||||
node = chunkdata['node'] | ||||
ui.write("%s\n" % hex(node)) | ||||
Benoit Boissinot
|
r14141 | chain = node | ||
Matt Mackall
|
r4915 | finally: | ||
Peter Arrenbrecht
|
r13724 | f.close() | ||
Sune Foldager
|
r14302 | @command('debugcheckstate', [], '') | ||
mpm@selenic.com
|
r596 | def debugcheckstate(ui, repo): | ||
"""validate the correctness of the current dirstate""" | ||||
mpm@selenic.com
|
r460 | parent1, parent2 = repo.dirstate.parents() | ||
Matt Mackall
|
r6747 | m1 = repo[parent1].manifest() | ||
m2 = repo[parent2].manifest() | ||||
mpm@selenic.com
|
r460 | errors = 0 | ||
Matt Mackall
|
r4906 | for f in repo.dirstate: | ||
state = repo.dirstate[f] | ||||
mpm@selenic.com
|
r460 | if state in "nr" and f not in m1: | ||
Benoit Boissinot
|
r1402 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) | ||
mpm@selenic.com
|
r460 | errors += 1 | ||
if state in "a" and f in m1: | ||||
Benoit Boissinot
|
r1402 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) | ||
mpm@selenic.com
|
r460 | errors += 1 | ||
if state in "m" and f not in m1 and f not in m2: | ||||
Benoit Boissinot
|
r1402 | ui.warn(_("%s in state %s, but not in either manifest\n") % | ||
mpm@selenic.com
|
r582 | (f, state)) | ||
mpm@selenic.com
|
r460 | errors += 1 | ||
for f in m1: | ||||
Matt Mackall
|
r4906 | state = repo.dirstate[f] | ||
mpm@selenic.com
|
r460 | if state not in "nrm": | ||
Benoit Boissinot
|
r1402 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) | ||
mpm@selenic.com
|
r460 | errors += 1 | ||
if errors: | ||||
Muli Ben-Yehuda
|
r1602 | error = _(".hg/dirstate inconsistent with current parent's manifest") | ||
raise util.Abort(error) | ||||
mpm@selenic.com
|
r460 | |||
Sune Foldager
|
r14302 | @command('debugcommands', [], _('[COMMAND]')) | ||
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'))], | ||||
_('[-o] CMD')) | ||||
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) | ||||
Matt Mackall
|
r11276 | if ui.verbose: | ||
Sune Foldager
|
r14302 | cmdlist = [' '.join(c[0]) for c in cmdlist.values()] | ||
ui.write("%s\n" % "\n".join(sorted(cmdlist))) | ||||
Matt Mackall
|
r8812 | |||
Adrian Buehlmann
|
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'))], | ||||
_('[OPTION]... [FILE [REV]...]')) | ||||
Peter Arrenbrecht
|
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 | ||||
revision numbers, they get labelled in the output as rN. | ||||
Otherwise, the changelog DAG of the current repo is emitted. | ||||
""" | ||||
spaces = opts.get('spaces') | ||||
dots = opts.get('dots') | ||||
if file_: | ||||
Adrian Buehlmann
|
r13970 | rlog = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) | ||
Peter Arrenbrecht
|
r11336 | revs = set((int(r) for r in revs)) | ||
def events(): | ||||
for r in rlog: | ||||
yield 'n', (r, list(set(p for p in rlog.parentrevs(r) if p != -1))) | ||||
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 | ||||
yield 'n', (r, list(set(p for p in cl.parentrevs(r) if p != -1))) | ||||
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") | ||||
Sune Foldager
|
r14323 | @command('debugdata', | ||
[('c', 'changelog', False, _('open changelog')), | ||||
('m', 'manifest', False, _('open manifest'))], | ||||
_('-c|-m|FILE REV')) | ||||
def debugdata(ui, repo, file_, rev = None, **opts): | ||||
Matt Mackall
|
r4258 | """dump the contents of a data file revision""" | ||
Sune Foldager
|
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) | ||||
Anupam Kapoor
|
r1313 | try: | ||
ui.write(r.revision(r.lookup(rev))) | ||||
except KeyError: | ||||
Thomas Arendsen Hein
|
r3072 | raise util.Abort(_('invalid revision identifier %s') % rev) | ||
mpm@selenic.com
|
r1039 | |||
Adrian Buehlmann
|
r14297 | @command('debugdate', | ||
[('e', 'extended', None, _('try extended date formats'))], | ||||
_('[-e] DATE [RANGE]')) | ||||
Matt Mackall
|
r3812 | def debugdate(ui, date, range=None, **opts): | ||
Matt Mackall
|
r3805 | """parse and display a date""" | ||
Matt Mackall
|
r3812 | if opts["extended"]: | ||
d = util.parsedate(date, util.extendeddateformats) | ||||
else: | ||||
d = util.parsedate(date) | ||||
Matt Mackall
|
r3805 | ui.write("internal: %s %s\n" % d) | ||
ui.write("standard: %s\n" % util.datestr(d)) | ||||
Matt Mackall
|
r3812 | if range: | ||
m = util.matchdate(range) | ||||
ui.write("match: %s\n" % m(d[0])) | ||||
Matt Mackall
|
r3805 | |||
Adrian Buehlmann
|
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]')) | ||||
Peter Arrenbrecht
|
r14164 | def debugdiscovery(ui, repo, remoteurl="default", **opts): | ||
"""runs the changeset discovery protocol in isolation""" | ||||
remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl), opts.get('branch')) | ||||
Matt Mackall
|
r14556 | remote = hg.peer(repo, opts, remoteurl) | ||
Peter Arrenbrecht
|
r14164 | ui.status(_('comparing with %s\n') % util.hidepassword(remoteurl)) | ||
# make sure tests are repeatable | ||||
random.seed(12323) | ||||
def doit(localheads, remoteheads): | ||||
if opts.get('old'): | ||||
if localheads: | ||||
raise util.Abort('cannot use localheads with old style discovery') | ||||
common, _in, hds = treediscovery.findcommonincoming(repo, remote, | ||||
force=True) | ||||
common = set(common) | ||||
if not opts.get('nonheads'): | ||||
ui.write("unpruned common: %s\n" % " ".join([short(n) | ||||
for n in common])) | ||||
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()) | ||||
ui.write("common heads: %s\n" % " ".join([short(n) for n in common])) | ||||
if lheads <= common: | ||||
ui.write("local is subset\n") | ||||
elif rheads <= common: | ||||
ui.write("remote is subset\n") | ||||
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) | ||||
Matt Mackall
|
r14511 | @command('debugfileset', [], ('REVSPEC')) | ||
def debugfileset(ui, repo, expr): | ||||
'''parse and apply a fileset specification''' | ||||
if ui.verbose: | ||||
tree = fileset.parse(expr)[0] | ||||
ui.note(tree, "\n") | ||||
Matt Mackall
|
r14673 | |||
for f in fileset.getfileset(repo[None], expr): | ||||
Matt Mackall
|
r14551 | ui.write("%s\n" % f) | ||
Matt Mackall
|
r14511 | |||
Sune Foldager
|
r14302 | @command('debugfsinfo', [], _('[PATH]')) | ||
def debugfsinfo(ui, path = "."): | ||||
"""show information detected about current filesystem""" | ||||
util.writefile('.debugfsinfo', '') | ||||
ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no')) | ||||
ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no')) | ||||
ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo') | ||||
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'))], | ||||
_('REPO FILE [-H|-C ID]...')) | ||||
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. | ||||
""" | ||||
Matt Mackall
|
r14556 | repo = hg.peer(ui, opts, repopath) | ||
Sune Foldager
|
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] | ||||
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', [], '') | ||||
jfh
|
r13396 | def debugignore(ui, repo, *values, **opts): | ||
"""display the combined ignore pattern""" | ||||
ignore = repo.dirstate._ignore | ||||
Augie Fackler
|
r14949 | includepat = getattr(ignore, 'includepat', None) | ||
if includepat is not None: | ||||
ui.write("%s\n" % includepat) | ||||
jfh
|
r13406 | else: | ||
raise util.Abort(_("no ignore patterns found")) | ||||
jfh
|
r13396 | |||
Adrian Buehlmann
|
r14297 | @command('debugindex', | ||
Sune Foldager
|
r14323 | [('c', 'changelog', False, _('open changelog')), | ||
('m', 'manifest', False, _('open manifest')), | ||||
('f', 'format', 0, _('revlog format'), _('FORMAT'))], | ||||
_('[-f FORMAT] -c|-m|FILE')) | ||||
def debugindex(ui, repo, file_ = None, **opts): | ||||
mpm@selenic.com
|
r596 | """dump the contents of an index file""" | ||
Sune Foldager
|
r14323 | r = cmdutil.openrevlog(repo, 'debugindex', file_, opts) | ||
Matt Mackall
|
r12893 | format = opts.get('format', 0) | ||
if format not in (0, 1): | ||||
Martin Geisler
|
r13470 | raise util.Abort(_("unknown format %d") % format) | ||
Matt Mackall
|
r12893 | |||
Sune Foldager
|
r14254 | generaldelta = r.version & revlog.REVLOGGENERALDELTA | ||
if generaldelta: | ||||
basehdr = ' delta' | ||||
else: | ||||
basehdr = ' base' | ||||
Matt Mackall
|
r12893 | |||
if format == 0: | ||||
Sune Foldager
|
r14254 | ui.write(" rev offset length " + basehdr + " linkrev" | ||
Matt Mackall
|
r12893 | " nodeid p1 p2\n") | ||
elif format == 1: | ||||
ui.write(" rev flag offset length" | ||||
Sune Foldager
|
r14254 | " size " + basehdr + " link p1 p2 nodeid\n") | ||
Matt Mackall
|
r12893 | |||
Matt Mackall
|
r6750 | for i in r: | ||
mason@suse.com
|
r2072 | node = r.node(i) | ||
Sune Foldager
|
r14254 | if generaldelta: | ||
base = r.deltaparent(i) | ||||
else: | ||||
base = r.chainbase(i) | ||||
Matt Mackall
|
r12893 | if format == 0: | ||
try: | ||||
pp = r.parents(node) | ||||
except: | ||||
pp = [nullid, nullid] | ||||
ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( | ||||
Sune Foldager
|
r14254 | i, r.start(i), r.length(i), base, r.linkrev(i), | ||
Matt Mackall
|
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), | ||||
Sune Foldager
|
r14254 | base, r.linkrev(i), pr[0], pr[1], short(node))) | ||
mpm@selenic.com
|
r248 | |||
Adrian Buehlmann
|
r14297 | @command('debugindexdot', [], _('FILE')) | ||
Sune Foldager
|
r12132 | def debugindexdot(ui, repo, file_): | ||
timeless
|
r8779 | """dump an index DAG as a graphviz dot file""" | ||
Sune Foldager
|
r12132 | r = None | ||
if repo: | ||||
filelog = repo.file(file_) | ||||
if len(filelog): | ||||
r = filelog | ||||
if not r: | ||||
Adrian Buehlmann
|
r13970 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) | ||
mpm@selenic.com
|
r582 | ui.write("digraph G {\n") | ||
Matt Mackall
|
r6750 | for i in r: | ||
Samuel Masham
|
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)) | ||||
mpm@selenic.com
|
r582 | ui.write("}\n") | ||
mpm@selenic.com
|
r248 | |||
Adrian Buehlmann
|
r14297 | @command('debuginstall', [], '') | ||
Matt Mackall
|
r3844 | def debuginstall(ui): | ||
Matt Mackall
|
r11177 | '''test Mercurial installation | ||
Returns 0 on success. | ||||
''' | ||||
Matt Mackall
|
r3844 | |||
Matt Mackall
|
r3846 | def writetemp(contents): | ||
Thomas Arendsen Hein
|
r4849 | (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-") | ||
Matt Mackall
|
r3846 | f = os.fdopen(fd, "wb") | ||
f.write(contents) | ||||
f.close() | ||||
return name | ||||
Matt Mackall
|
r3844 | problems = 0 | ||
# encoding | ||||
Matt Mackall
|
r7948 | ui.status(_("Checking encoding (%s)...\n") % encoding.encoding) | ||
Matt Mackall
|
r3844 | try: | ||
Matt Mackall
|
r7948 | encoding.fromlocal("test") | ||
Matt Mackall
|
r3844 | except util.Abort, inst: | ||
ui.write(" %s\n" % inst) | ||||
Matt Mackall
|
r3848 | ui.write(_(" (check that your locale is properly set)\n")) | ||
Matt Mackall
|
r3844 | problems += 1 | ||
# compiled modules | ||||
Matt Mackall
|
r12004 | ui.status(_("Checking installed modules (%s)...\n") | ||
% os.path.dirname(__file__)) | ||||
Matt Mackall
|
r3844 | try: | ||
Matt Mackall
|
r12004 | import bdiff, mpatch, base85, osutil | ||
Matt Mackall
|
r15223 | dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes | ||
Matt Mackall
|
r3844 | except Exception, inst: | ||
ui.write(" %s\n" % inst) | ||||
Matt Mackall
|
r3848 | ui.write(_(" One or more extensions could not be found")) | ||
ui.write(_(" (check that you compiled the extensions)\n")) | ||||
Matt Mackall
|
r3844 | problems += 1 | ||
# templates | ||||
Matt Mackall
|
r15200 | import templater | ||
p = templater.templatepath() | ||||
ui.status(_("Checking templates (%s)...\n") % ' '.join(p)) | ||||
Matt Mackall
|
r3844 | try: | ||
Peter Arrenbrecht
|
r7874 | templater.templater(templater.templatepath("map-cmdline.default")) | ||
Matt Mackall
|
r3844 | except Exception, inst: | ||
ui.write(" %s\n" % inst) | ||||
Matt Mackall
|
r3848 | ui.write(_(" (templates seem to have been installed incorrectly)\n")) | ||
Matt Mackall
|
r3844 | problems += 1 | ||
# editor | ||||
ui.status(_("Checking commit editor...\n")) | ||||
Osku Salerma
|
r5660 | editor = ui.geteditor() | ||
Adrian Buehlmann
|
r14271 | cmdpath = util.findexe(editor) or util.findexe(editor.split()[0]) | ||
Matt Mackall
|
r3844 | if not cmdpath: | ||
Benoit Boissinot
|
r3855 | if editor == 'vi': | ||
Matt Mackall
|
r3844 | ui.write(_(" No commit editor set and can't find vi in PATH\n")) | ||
Brodie Rao
|
r12083 | ui.write(_(" (specify a commit editor in your configuration" | ||
" file)\n")) | ||||
Matt Mackall
|
r3844 | else: | ||
ui.write(_(" Can't find editor '%s' in PATH\n") % editor) | ||||
Brodie Rao
|
r12083 | ui.write(_(" (specify a commit editor in your configuration" | ||
" file)\n")) | ||||
Matt Mackall
|
r3844 | problems += 1 | ||
Matt Mackall
|
r3848 | # check username | ||
ui.status(_("Checking username...\n")) | ||||
Martin Geisler
|
r9734 | try: | ||
Brodie Rao
|
r12063 | ui.username() | ||
Martin Geisler
|
r9734 | except util.Abort, e: | ||
ui.write(" %s\n" % e) | ||||
Brodie Rao
|
r12083 | ui.write(_(" (specify a username in your configuration file)\n")) | ||
Martin Geisler
|
r9734 | problems += 1 | ||
Matt Mackall
|
r3848 | |||
Matt Mackall
|
r3844 | if not problems: | ||
ui.status(_("No problems detected\n")) | ||||
else: | ||||
ui.write(_("%s problems detected," | ||||
" please check your install!\n") % problems) | ||||
return problems | ||||
Sune Foldager
|
r14302 | @command('debugknown', [], _('REPO ID...')) | ||
def debugknown(ui, repopath, *ids, **opts): | ||||
"""test whether node ids are known to a repo | ||||
Every ID must be a full-length hex node id string. Returns a list of 0s and 1s | ||||
indicating unknown/known. | ||||
""" | ||||
Matt Mackall
|
r14556 | repo = hg.peer(ui, opts, repopath) | ||
Sune Foldager
|
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]))) | ||||
@command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]')) | ||||
Matt Mackall
|
r14556 | def debugpushkey(ui, repopath, namespace, *keyinfo, **opts): | ||
Sune Foldager
|
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. | ||||
''' | ||||
Matt Mackall
|
r14556 | target = hg.peer(ui, {}, repopath) | ||
Sune Foldager
|
r14302 | if keyinfo: | ||
key, old, new = keyinfo | ||||
r = target.pushkey(namespace, key, old, new) | ||||
ui.status(str(r) + '\n') | ||||
return not r | ||||
else: | ||||
for k, v in target.listkeys(namespace).iteritems(): | ||||
ui.write("%s\t%s\n" % (k.encode('string-escape'), | ||||
v.encode('string-escape'))) | ||||
Matt Mackall
|
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)) | ||||
Sune Foldager
|
r14302 | @command('debugrebuildstate', | ||
[('r', 'rev', '', _('revision to rebuild to'), _('REV'))], | ||||
_('[-r REV] [REV]')) | ||||
def debugrebuildstate(ui, repo, rev="tip"): | ||||
"""rebuild the dirstate as it would look like for the given revision""" | ||||
Matt Mackall
|
r14319 | ctx = scmutil.revsingle(repo, rev) | ||
Sune Foldager
|
r14302 | wlock = repo.wlock() | ||
try: | ||||
repo.dirstate.rebuild(ctx.node(), ctx.manifest()) | ||||
finally: | ||||
wlock.release() | ||||
Adrian Buehlmann
|
r14297 | @command('debugrename', | ||
[('r', 'rev', '', _('revision to debug'), _('REV'))], | ||||
_('[-r REV] FILE')) | ||||
Matt Mackall
|
r3652 | def debugrename(ui, repo, file1, *pats, **opts): | ||
bos@serpentine.internal.keyresearch.com
|
r1194 | """dump rename information""" | ||
Matt Mackall
|
r3652 | |||
Matt Mackall
|
r14319 | ctx = scmutil.revsingle(repo, opts.get('rev')) | ||
Matt Mackall
|
r14671 | m = scmutil.match(ctx, (file1,) + pats, opts) | ||
Matt Mackall
|
r6764 | for abs in ctx.walk(m): | ||
fctx = ctx[abs] | ||||
Matt Mackall
|
r6579 | o = fctx.filelog().renamed(fctx.filenode()) | ||
Matt Mackall
|
r6584 | rel = m.rel(abs) | ||
Matt Mackall
|
r6579 | if o: | ||
ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1]))) | ||||
Matt Mackall
|
r3652 | else: | ||
ui.write(_("%s not renamed\n") % rel) | ||||
mpm@selenic.com
|
r1116 | |||
Sune Foldager
|
r14323 | @command('debugrevlog', | ||
[('c', 'changelog', False, _('open changelog')), | ||||
Matt Mackall
|
r14326 | ('m', 'manifest', False, _('open manifest')), | ||
('d', 'dump', False, _('dump index data'))], | ||||
Sune Foldager
|
r14323 | _('-c|-m|FILE')) | ||
def debugrevlog(ui, repo, file_ = None, **opts): | ||||
Sune Foldager
|
r14304 | """show data and statistics about a revlog""" | ||
Sune Foldager
|
r14323 | r = cmdutil.openrevlog(repo, 'debugrevlog', file_, opts) | ||
Matt Mackall
|
r14326 | |||
if opts.get("dump"): | ||||
numrevs = len(r) | ||||
ui.write("# rev p1rev p2rev start end deltastart base p1 p2" | ||||
" rawsize totalsize compression heads\n") | ||||
ts = 0 | ||||
heads = set() | ||||
for rev in xrange(numrevs): | ||||
Matt Mackall
|
r14371 | dbase = r.deltaparent(rev) | ||
if dbase == -1: | ||||
dbase = rev | ||||
Matt Mackall
|
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) | ||||
ui.write("%d %d %d %d %d %d %d %d %d %d %d %d %d\n" % | ||||
(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 | ||||
Sune Foldager
|
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') | ||||
Sune Foldager
|
r14305 | if not flags: | ||
flags = ['(none)'] | ||||
Sune Foldager
|
r14304 | |||
nummerges = 0 | ||||
Sune Foldager
|
r14305 | numfull = 0 | ||
Sune Foldager
|
r14304 | numprev = 0 | ||
nump1 = 0 | ||||
nump2 = 0 | ||||
numother = 0 | ||||
nump1prev = 0 | ||||
nump2prev = 0 | ||||
Sune Foldager
|
r14305 | chainlengths = [] | ||
Sune Foldager
|
r14304 | |||
datasize = [None, 0, 0L] | ||||
Sune Foldager
|
r14305 | fullsize = [None, 0, 0L] | ||
Sune Foldager
|
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: | ||||
Sune Foldager
|
r14305 | chainlengths.append(0) | ||
numfull += 1 | ||||
addsize(size, fullsize) | ||||
Sune Foldager
|
r14304 | else: | ||
Sune Foldager
|
r14305 | chainlengths.append(chainlengths[delta] + 1) | ||
Sune Foldager
|
r14304 | addsize(size, deltasize) | ||
Sune Foldager
|
r14305 | if delta == rev - 1: | ||
numprev += 1 | ||||
if delta == p1: | ||||
nump1prev += 1 | ||||
Sune Foldager
|
r14304 | elif delta == p2: | ||
Sune Foldager
|
r14305 | nump2prev += 1 | ||
elif delta == p1: | ||||
nump1 += 1 | ||||
elif delta == p2: | ||||
nump2 += 1 | ||||
elif delta != nullrev: | ||||
numother += 1 | ||||
numdeltas = numrevs - numfull | ||||
numoprev = numprev - nump1prev - nump2prev | ||||
totalrawsize = datasize[2] | ||||
Sune Foldager
|
r14304 | datasize[2] /= numrevs | ||
Sune Foldager
|
r14305 | fulltotal = fullsize[2] | ||
fullsize[2] /= numfull | ||||
deltatotal = deltasize[2] | ||||
deltasize[2] /= numrevs - numfull | ||||
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) | ||||
ui.write('format : %d\n' % format) | ||||
ui.write('flags : %s\n' % ', '.join(flags)) | ||||
ui.write('\n') | ||||
fmt = pcfmtstr(totalsize) | ||||
fmt2 = dfmtstr(totalsize) | ||||
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)) | ||||
ui.write('\n') | ||||
fmt = dfmtstr(max(avgchainlen, compratio)) | ||||
ui.write('avg chain length : ' + fmt % avgchainlen) | ||||
ui.write('compression ratio : ' + fmt % compratio) | ||||
Sune Foldager
|
r14304 | |||
if format > 0: | ||||
Sune Foldager
|
r14305 | ui.write('\n') | ||
ui.write('uncompressed data size (min/max/avg) : %d / %d / %d\n' | ||||
Sune Foldager
|
r14304 | % tuple(datasize)) | ||
Sune Foldager
|
r14305 | ui.write('full revision size (min/max/avg) : %d / %d / %d\n' | ||
% tuple(fullsize)) | ||||
ui.write('delta size (min/max/avg) : %d / %d / %d\n' | ||||
Sune Foldager
|
r14304 | % tuple(deltasize)) | ||
Sune Foldager
|
r14305 | if numdeltas > 0: | ||
ui.write('\n') | ||||
fmt = pcfmtstr(numdeltas) | ||||
fmt2 = pcfmtstr(numdeltas, 4) | ||||
ui.write('deltas against prev : ' + fmt % pcfmt(numprev, numdeltas)) | ||||
if numprev > 0: | ||||
ui.write(' where prev = p1 : ' + fmt2 % pcfmt(nump1prev, numprev)) | ||||
ui.write(' where prev = p2 : ' + fmt2 % pcfmt(nump2prev, numprev)) | ||||
ui.write(' other : ' + fmt2 % pcfmt(numoprev, numprev)) | ||||
if gdelta: | ||||
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, numdeltas)) | ||||
Sune Foldager
|
r14304 | |||
Sune Foldager
|
r14302 | @command('debugrevspec', [], ('REVSPEC')) | ||
def debugrevspec(ui, repo, expr): | ||||
Patrick Mezard
|
r16104 | """parse and apply a revision specification | ||
Use --verbose to print the parsed tree before and after aliases | ||||
expansion. | ||||
""" | ||||
Sune Foldager
|
r14302 | if ui.verbose: | ||
tree = revset.parse(expr)[0] | ||||
Patrick Mezard
|
r16218 | ui.note(revset.prettyformat(tree), "\n") | ||
Sune Foldager
|
r14302 | newtree = revset.findaliases(ui, tree) | ||
if newtree != tree: | ||||
Patrick Mezard
|
r16218 | ui.note(revset.prettyformat(newtree), "\n") | ||
Sune Foldager
|
r14302 | func = revset.match(ui, expr) | ||
for c in func(repo, range(len(repo))): | ||||
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. | ||||
""" | ||||
Matt Mackall
|
r14319 | r1 = scmutil.revsingle(repo, rev1).node() | ||
r2 = scmutil.revsingle(repo, rev2, 'null').node() | ||||
Sune Foldager
|
r14302 | |||
wlock = repo.wlock() | ||||
try: | ||||
Patrick Mezard
|
r16551 | repo.setparents(r1, r2) | ||
Sune Foldager
|
r14302 | finally: | ||
wlock.release() | ||||
@command('debugstate', | ||||
[('', '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: | ||||
Mads Kiilerich
|
r15440 | mode = '%3o' % (ent[1] & 0777 & ~util.umask) | ||
Sune Foldager
|
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): | ||||
Matt Mackall
|
r14319 | ctx = scmutil.revsingle(repo, rev, None) | ||
Sune Foldager
|
r14302 | for k, v in sorted(ctx.substate.items()): | ||
ui.write('path %s\n' % k) | ||||
ui.write(' source %s\n' % v[0]) | ||||
ui.write(' revision %s\n' % v[1]) | ||||
Adrian Buehlmann
|
r14297 | @command('debugwalk', walkopts, _('[OPTION]... [FILE]...')) | ||
Bryan O'Sullivan
|
r820 | def debugwalk(ui, repo, *pats, **opts): | ||
Thomas Arendsen Hein
|
r1053 | """show how files match on given patterns""" | ||
Matt Mackall
|
r14671 | m = scmutil.match(repo[None], pats, opts) | ||
Matt Mackall
|
r6585 | items = list(repo.walk(m)) | ||
Thomas Arendsen Hein
|
r1065 | if not items: | ||
return | ||||
Matt Mackall
|
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: | ||||
line = fmt % (abs, m.rel(abs), m.exact(abs) and 'exact' or '') | ||||
Thomas Arendsen Hein
|
r1309 | ui.write("%s\n" % line.rstrip()) | ||
Bryan O'Sullivan
|
r820 | |||
Adrian Buehlmann
|
r14297 | @command('debugwireargs', | ||
[('', 'three', '', 'three'), | ||||
('', 'four', '', 'four'), | ||||
('', 'five', '', 'five'), | ||||
] + remoteopts, | ||||
_('REPO [OPTIONS]... [ONE [TWO]]')) | ||||
Peter Arrenbrecht
|
r13720 | def debugwireargs(ui, repopath, *vals, **opts): | ||
Matt Mackall
|
r14556 | repo = hg.peer(ui, opts, repopath) | ||
Peter Arrenbrecht
|
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) | ||||
Adrian Buehlmann
|
r14297 | @command('^diff', | ||
[('r', 'rev', [], _('revision'), _('REV')), | ||||
('c', 'change', '', _('change made by revision'), _('REV')) | ||||
] + diffopts + diffopts2 + walkopts + subrepoopts, | ||||
_('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...')) | ||||
Bryan O'Sullivan
|
r732 | def diff(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1568 | """diff repository (or selected files) | ||
Benoit Boissinot
|
r1437 | |||
Show differences between revisions for the specified files. | ||||
Differences between files are shown using the unified diff format. | ||||
Erik Zielke
|
r12389 | .. note:: | ||
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. | ||||
Matt Mackall
|
r3822 | |||
Benoit Boissinot
|
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. | ||||
timeless
|
r10527 | Alternatively you can specify -c/--change with a revision to see | ||
the changes in that changeset relative to its first parent. | ||||
timeless
|
r10520 | |||
Martin Geisler
|
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 | ||||
Martin Geisler
|
r10973 | format. For more information, read :hg:`help diffs`. | ||
Matt Mackall
|
r11177 | |||
Matt Mackall
|
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 | ||||
Matt Mackall
|
r11177 | Returns 0 on success. | ||
Benoit Boissinot
|
r1437 | """ | ||
Stepan Koltsov
|
r7628 | |||
revs = opts.get('rev') | ||||
change = opts.get('change') | ||||
Brodie Rao
|
r9640 | stat = opts.get('stat') | ||
Martin Geisler
|
r9857 | reverse = opts.get('reverse') | ||
Stepan Koltsov
|
r7628 | |||
if revs and change: | ||||
msg = _('cannot specify --rev and --change at the same time') | ||||
raise util.Abort(msg) | ||||
elif change: | ||||
Matt Mackall
|
r14319 | node2 = scmutil.revsingle(repo, change, None).node() | ||
Matt Mackall
|
r13878 | node1 = repo[node2].p1().node() | ||
Stepan Koltsov
|
r7628 | else: | ||
Matt Mackall
|
r14319 | node1, node2 = scmutil.revpair(repo, revs) | ||
mpm@selenic.com
|
r245 | |||
Martin Geisler
|
r9857 | if reverse: | ||
Yannick Gingras
|
r9725 | node1, node2 = node2, node1 | ||
Brodie Rao
|
r9642 | diffopts = patch.diffopts(ui, opts) | ||
Matt Mackall
|
r14671 | m = scmutil.match(repo[node2], pats, opts) | ||
Martin Geisler
|
r12167 | cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, | ||
listsubrepos=opts.get('subrepos')) | ||||
Thomas Arendsen Hein
|
r396 | |||
Adrian Buehlmann
|
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, | ||||
_('[OPTION]... [-o OUTFILESPEC] REV...')) | ||||
mpm@selenic.com
|
r580 | def export(ui, repo, *changesets, **opts): | ||
Benoit Boissinot
|
r1437 | """dump the header and diffs for one or more changesets | ||
Print the changeset header and diffs for one or more revisions. | ||||
Steve Losh
|
r10334 | The information shown in the changeset header is: author, date, | ||
Steve Losh
|
r10335 | branch name (if non-default), changeset hash, parent(s) and commit | ||
comment. | ||||
Matt Mackall
|
r3822 | |||
Christian Ebert
|
r12390 | .. note:: | ||
export may generate unexpected diff output for merge | ||||
changesets, as it will compare the merge changeset against its | ||||
first parent only. | ||||
Benoit Boissinot
|
r1437 | |||
Output may be to a file, in which case the name of the file is | ||||
Martin Geisler
|
r9892 | given using a format string. The formatting rules are as follows: | ||
:``%%``: literal "%" character | ||||
Matt Mackall
|
r11718 | :``%H``: changeset hash (40 hexadecimal digits) | ||
Martin Geisler
|
r9892 | :``%N``: number of patches being generated | ||
:``%R``: changeset revision number | ||||
:``%b``: basename of the exporting repository | ||||
Matt Mackall
|
r11718 | :``%h``: short-form changeset hash (12 hexadecimal digits) | ||
Andrzej Bieniek
|
r14986 | :``%m``: first line of the commit message (only alphanumeric characters) | ||
Martin Geisler
|
r9892 | :``%n``: zero-padded sequence number, starting at 1 | ||
:``%r``: zero-padded changeset revision number | ||||
Benoit Boissinot
|
r1437 | |||
Martin Geisler
|
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 | ||||
Martin Geisler
|
r10973 | format. See :hg:`help diffs` for more information. | ||
Dirkjan Ochtman
|
r7307 | |||
Martin Geisler
|
r8004 | With the --switch-parent option, the diff will be against the | ||
second parent. It can be useful to review a merge. | ||||
Matt Mackall
|
r11177 | |||
Matt Mackall
|
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" | ||||
Matt Mackall
|
r11177 | Returns 0 on success. | ||
Benoit Boissinot
|
r1437 | """ | ||
Alexander Solovyov
|
r10015 | changesets += tuple(opts.get('rev', [])) | ||
Thomas Arendsen Hein
|
r16357 | revs = scmutil.revrange(repo, changesets) | ||
if not revs: | ||||
Benoit Boissinot
|
r1402 | raise util.Abort(_("export requires at least one changeset")) | ||
Vadim Gelfer
|
r2874 | if len(revs) > 1: | ||
ui.note(_('exporting patches:\n')) | ||||
else: | ||||
ui.note(_('exporting patch:\n')) | ||||
Benoit Boissinot
|
r10611 | cmdutil.export(repo, revs, template=opts.get('output'), | ||
Alexander Solovyov
|
r7131 | switch_parent=opts.get('switch_parent'), | ||
Matt Mackall
|
r2888 | opts=patch.diffopts(ui, opts)) | ||
mpm@selenic.com
|
r246 | |||
Adrian Buehlmann
|
r14297 | @command('^forget', walkopts, _('[OPTION]... FILE...')) | ||
Steve Losh
|
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. | ||||
Martin Geisler
|
r11193 | To undo a forget before the next commit, see :hg:`add`. | ||
Matt Mackall
|
r11177 | |||
Matt Mackall
|
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()" | ||||
Matt Mackall
|
r11177 | Returns 0 on success. | ||
Steve Losh
|
r8902 | """ | ||
if not pats: | ||||
raise util.Abort(_('no files specified')) | ||||
David M. Carr
|
r15912 | m = scmutil.match(repo[None], pats, opts) | ||
rejected = cmdutil.forget(ui, repo, m, prefix="", explicitonly=False)[0] | ||||
return rejected and 1 or 0 | ||||
Steve Losh
|
r8902 | |||
Matt Mackall
|
r15240 | @command( | ||
'graft', | ||||
Matt Mackall
|
r15241 | [('c', 'continue', False, _('resume interrupted graft')), | ||
('e', 'edit', False, _('invoke editor on commit messages')), | ||||
('D', 'currentdate', False, | ||||
_('record the current date as commit date')), | ||||
('U', 'currentuser', False, | ||||
_('record the current user as committer'), _('DATE'))] | ||||
Matt Mackall
|
r16389 | + commitopts2 + mergetoolopts + dryrunopts, | ||
Matt Mackall
|
r15238 | _('[OPTION]... REVISION...')) | ||
Matt Mackall
|
r15241 | def graft(ui, repo, *revs, **opts): | ||
Matt Mackall
|
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 | ||||
Matt Mackall
|
r15242 | 'cherry-picking'. By default, graft will copy user, date, and | ||
description from the source changesets. | ||||
Matt Mackall
|
r15238 | |||
Changesets that are ancestors of the current revision, that have | ||||
already been grafted, or that are merges will be skipped. | ||||
Matt Mackall
|
r15241 | If a graft merge results in conflicts, the graft process is | ||
Kevin Bullock
|
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. | ||||
Matt Mackall
|
r15241 | |||
.. note:: | ||||
The -c/--continue option does not reapply earlier options. | ||||
Matt Mackall
|
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:: | ||||
hg log --debug -r tip | ||||
Matt Mackall
|
r15238 | Returns 0 on successful completion. | ||
''' | ||||
Matt Mackall
|
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() | ||||
Matt Mackall
|
r15239 | editor = None | ||
if opts.get('edit'): | ||||
editor = cmdutil.commitforceeditor | ||||
Matt Mackall
|
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: | ||||
cmdutil.bailifchanged(repo) | ||||
if not revs: | ||||
raise util.Abort(_('no revisions specified')) | ||||
revs = scmutil.revrange(repo, revs) | ||||
Matt Mackall
|
r15238 | |||
# check for merges | ||||
Matt Mackall
|
r15404 | for rev in repo.revs('%ld and merge()', revs): | ||
ui.warn(_('skipping ungraftable merge revision %s\n') % rev) | ||||
revs.remove(rev) | ||||
Matt Mackall
|
r15238 | if not revs: | ||
return -1 | ||||
# check for ancestors of dest branch | ||||
Matt Mackall
|
r15404 | for rev in repo.revs('::. and %ld', revs): | ||
ui.warn(_('skipping ancestor revision %s\n') % rev) | ||||
revs.remove(rev) | ||||
Matt Mackall
|
r15238 | if not revs: | ||
return -1 | ||||
Stefano Tortarolo
|
r15508 | # 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() | ||||
Matt Mackall
|
r15238 | # check ancestors for earlier grafts | ||
Matt Mackall
|
r15359 | ui.debug('scanning for duplicate grafts\n') | ||
Matt Mackall
|
r15238 | for ctx in repo.set("::. - ::%ld", revs): | ||
n = ctx.extra().get('source') | ||||
Stefano Tortarolo
|
r15508 | if n in ids: | ||
Matt Mackall
|
r15238 | r = repo[n].rev() | ||
Matt Mackall
|
r15360 | if r in revs: | ||
ui.warn(_('skipping already grafted revision %s\n') % r) | ||||
revs.remove(r) | ||||
Stefano Tortarolo
|
r15508 | elif ids[n] in revs: | ||
ui.warn(_('skipping already grafted revision %s ' | ||||
'(same origin %d)\n') % (ids[n], 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, ctx.rev())) | ||||
revs.remove(r) | ||||
Matt Mackall
|
r15238 | if not revs: | ||
return -1 | ||||
Idan Kamara
|
r16473 | wlock = repo.wlock() | ||
try: | ||||
for pos, ctx in enumerate(repo.set("%ld", revs)): | ||||
current = repo['.'] | ||||
ui.status(_('grafting revision %s\n') % ctx.rev()) | ||||
if opts.get('dry_run'): | ||||
continue | ||||
# 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 | ||||
repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) | ||||
stats = mergemod.update(repo, ctx.node(), True, True, False, | ||||
ctx.p1().node()) | ||||
finally: | ||||
ui.setconfig('ui', 'forcemerge', '') | ||||
# drop the second merge parent | ||||
Patrick Mezard
|
r16551 | repo.setparents(current.node(), nullid) | ||
Idan Kamara
|
r16473 | repo.dirstate.write() | ||
# fix up dirstate for copies and renames | ||||
cmdutil.duplicatecopies(repo, ctx.rev(), ctx.p1().rev()) | ||||
# 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 | ||||
# commit | ||||
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'] | ||||
Matt Mackall
|
r16600 | node = repo.commit(text=ctx.description(), user=user, | ||
Idan Kamara
|
r16473 | date=date, extra=extra, editor=editor) | ||
Matt Mackall
|
r16600 | if node is None: | ||
ui.status(_('graft for revision %s is empty\n') % ctx.rev()) | ||||
Idan Kamara
|
r16473 | finally: | ||
wlock.release() | ||||
Matt Mackall
|
r15238 | |||
Matt Mackall
|
r15241 | # remove state when we complete successfully | ||
Matt Mackall
|
r16389 | if not opts.get('dry_run') and os.path.exists(repo.join('graftstate')): | ||
Matt Mackall
|
r15241 | util.unlinkpath(repo.join('graftstate')) | ||
Matt Mackall
|
r15238 | return 0 | ||
Adrian Buehlmann
|
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, | ||||
_('[OPTION]... PATTERN [FILE]...')) | ||||
Thomas Arendsen Hein
|
r1108 | def grep(ui, repo, pattern, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """search for a pattern in specified files and revisions | ||
Search revisions of files for a regular expression. | ||||
Christian Ebert
|
r6448 | This command behaves differently than Unix grep. It only accepts | ||
Python/Perl regexps. It searches repository history, not the | ||||
Martin Geisler
|
r8004 | working directory. It always prints the revision number in which a | ||
match appears. | ||||
Benoit Boissinot
|
r1437 | |||
By default, grep only prints output for the first revision of a | ||||
Christian Ebert
|
r6448 | file in which it finds a match. To get it to print every revision | ||
Benoit Boissinot
|
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. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 if a match is found, 1 otherwise. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r15765 | reflags = re.M | ||
Alexander Solovyov
|
r7131 | if opts.get('ignore_case'): | ||
Thomas Arendsen Hein
|
r1065 | reflags |= re.I | ||
Giorgos Keramidas
|
r4877 | try: | ||
regexp = re.compile(pattern, reflags) | ||||
Brodie Rao
|
r12385 | except re.error, inst: | ||
Thomas Arendsen Hein
|
r6057 | ui.warn(_("grep: invalid match pattern: %s\n") % inst) | ||
Matt Mackall
|
r11177 | return 1 | ||
bos@serpentine.internal.keyresearch.com
|
r1146 | sep, eol = ':', '\n' | ||
Alexander Solovyov
|
r7131 | if opts.get('print0'): | ||
bos@serpentine.internal.keyresearch.com
|
r1146 | sep = eol = '\0' | ||
Bryan O'Sullivan
|
r1057 | |||
Matt Mackall
|
r9097 | getfile = util.lrucachefunc(repo.file) | ||
Bryan O'Sullivan
|
r1057 | |||
def matchlines(body): | ||||
bos@serpentine.internal.keyresearch.com
|
r1059 | begin = 0 | ||
linenum = 0 | ||||
while True: | ||||
match = regexp.search(body, begin) | ||||
Thomas Arendsen Hein
|
r1065 | if not match: | ||
break | ||||
bos@serpentine.internal.keyresearch.com
|
r1059 | mstart, mend = match.span() | ||
linenum += body.count('\n', begin, mstart) + 1 | ||||
lstart = body.rfind('\n', begin, mstart) + 1 or begin | ||||
Mads Kiilerich
|
r15293 | begin = body.find('\n', mend) + 1 or len(body) + 1 | ||
Matt Mackall
|
r7230 | lend = begin - 1 | ||
bos@serpentine.internal.keyresearch.com
|
r1059 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] | ||
Bryan O'Sullivan
|
r1057 | |||
Eric Hopper
|
r1559 | class linestate(object): | ||
Bryan O'Sullivan
|
r1057 | def __init__(self, line, linenum, colstart, colend): | ||
self.line = line | ||||
self.linenum = linenum | ||||
self.colstart = colstart | ||||
self.colend = colend | ||||
Brendan Cully
|
r2869 | |||
Paul Moore
|
r6469 | def __hash__(self): | ||
return hash((self.linenum, self.line)) | ||||
Thomas Arendsen Hein
|
r1065 | def __eq__(self, other): | ||
return self.line == other.line | ||||
Bryan O'Sullivan
|
r1057 | |||
matches = {} | ||||
Brendan Cully
|
r2870 | copies = {} | ||
Bryan O'Sullivan
|
r1057 | def grepbody(fn, rev, body): | ||
Brendan Cully
|
r2869 | matches[rev].setdefault(fn, []) | ||
Bryan O'Sullivan
|
r1057 | m = matches[rev][fn] | ||
for lnum, cstart, cend, line in matchlines(body): | ||||
s = linestate(line, lnum, cstart, cend) | ||||
Brendan Cully
|
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': | ||||
Benoit Boissinot
|
r3472 | for i in xrange(blo, bhi): | ||
Brendan Cully
|
r2869 | yield ('+', b[i]) | ||
elif tag == 'delete': | ||||
Benoit Boissinot
|
r3472 | for i in xrange(alo, ahi): | ||
Brendan Cully
|
r2869 | yield ('-', a[i]) | ||
elif tag == 'replace': | ||||
Benoit Boissinot
|
r3472 | for i in xrange(alo, ahi): | ||
Brendan Cully
|
r2869 | yield ('-', a[i]) | ||
Benoit Boissinot
|
r3472 | for i in xrange(blo, bhi): | ||
Brendan Cully
|
r2869 | yield ('+', b[i]) | ||
Matt Mackall
|
r9655 | def display(fn, ctx, pstates, states): | ||
rev = ctx.rev() | ||||
Thomas Arendsen Hein
|
r6134 | datefunc = ui.quiet and util.shortdate or util.datestr | ||
Benoit Boissinot
|
r3951 | found = False | ||
bos@serpentine.internal.keyresearch.com
|
r1146 | filerevmatches = {} | ||
Md. O. Shayan
|
r13920 | def binary(): | ||
flog = getfile(fn) | ||||
return util.binary(flog.read(ctx.filenode(fn))) | ||||
Alexander Solovyov
|
r7131 | if opts.get('all'): | ||
FUJIWARA Katsunori
|
r8849 | iter = difflinestates(pstates, states) | ||
Brendan Cully
|
r2869 | else: | ||
FUJIWARA Katsunori
|
r8849 | iter = [('', l) for l in states] | ||
Benoit Boissinot
|
r3951 | for change, l in iter: | ||
Matt Mackall
|
r9655 | cols = [fn, str(rev)] | ||
Brodie Rao
|
r10816 | before, match, after = None, None, None | ||
Alexander Solovyov
|
r7131 | if opts.get('line_number'): | ||
Thomas Arendsen Hein
|
r1615 | cols.append(str(l.linenum)) | ||
Alexander Solovyov
|
r7131 | if opts.get('all'): | ||
Thomas Arendsen Hein
|
r1615 | cols.append(change) | ||
Alexander Solovyov
|
r7131 | if opts.get('user'): | ||
Matt Mackall
|
r9655 | cols.append(ui.shortuser(ctx.user())) | ||
Thomas Arendsen Hein
|
r6133 | if opts.get('date'): | ||
Matt Mackall
|
r9655 | cols.append(datefunc(ctx.date())) | ||
Alexander Solovyov
|
r7131 | if opts.get('files_with_matches'): | ||
Matt Mackall
|
r9655 | c = (fn, rev) | ||
Thomas Arendsen Hein
|
r1615 | if c in filerevmatches: | ||
continue | ||||
bos@serpentine.internal.keyresearch.com
|
r1146 | filerevmatches[c] = 1 | ||
else: | ||||
Brodie Rao
|
r10816 | before = l.line[:l.colstart] | ||
match = l.line[l.colstart:l.colend] | ||||
after = l.line[l.colend:] | ||||
ui.write(sep.join(cols)) | ||||
if before is not None: | ||||
Md. O. Shayan
|
r13920 | if not opts.get('text') and binary(): | ||
ui.write(sep + " Binary file matches") | ||||
else: | ||||
ui.write(sep + before) | ||||
ui.write(match, label='grep.match') | ||||
ui.write(after) | ||||
Brodie Rao
|
r10816 | ui.write(eol) | ||
Benoit Boissinot
|
r3951 | found = True | ||
return found | ||||
Bryan O'Sullivan
|
r1057 | |||
Bryan O'Sullivan
|
r1145 | skip = {} | ||
FUJIWARA Katsunori
|
r8849 | revfiles = {} | ||
Matt Mackall
|
r14671 | matchfn = scmutil.match(repo[None], pats, opts) | ||
Benoit Boissinot
|
r3951 | found = False | ||
Brendan Cully
|
r2870 | follow = opts.get('follow') | ||
Matt Mackall
|
r9662 | |||
def prep(ctx, fns): | ||||
rev = ctx.rev() | ||||
Matt Mackall
|
r13878 | pctx = ctx.p1() | ||
Matt Mackall
|
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]: | ||||
Bryan O'Sullivan
|
r1057 | try: | ||
Matt Mackall
|
r9662 | fnode = pctx.filenode(pfn) | ||
grepbody(pfn, parent, flog.read(fnode)) | ||||
Matt Mackall
|
r7633 | except error.LookupError: | ||
Matt Mackall
|
r9662 | pass | ||
Matt Mackall
|
r9665 | for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep): | ||
Matt Mackall
|
r9662 | rev = ctx.rev() | ||
Matt Mackall
|
r13878 | parent = ctx.p1().rev() | ||
Matt Mackall
|
r9662 | for fn in sorted(revfiles.get(rev, [])): | ||
states = matches[rev][fn] | ||||
copy = copies.get(rev, {}).get(fn) | ||||
if fn in skip: | ||||
FUJIWARA Katsunori
|
r8849 | if copy: | ||
Matt Mackall
|
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 | ||||
FUJIWARA Katsunori
|
r8849 | if copy: | ||
skip[copy] = True | ||||
Matt Mackall
|
r9662 | del matches[rev] | ||
del revfiles[rev] | ||||
Bryan O'Sullivan
|
r1057 | |||
Matt Mackall
|
r11177 | return not found | ||
Adrian Buehlmann
|
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, | ||||
_('[-ac] [-r STARTREV] [REV]...')) | ||||
Eric Hopper
|
r4648 | def heads(ui, repo, *branchrevs, **opts): | ||
"""show current repository heads or show branch heads | ||||
Dirkjan Ochtman
|
r10350 | With no arguments, show all repository branch heads. | ||
Eric Hopper
|
r4648 | |||
Greg Ward
|
r9502 | Repository "heads" are changesets with no child changesets. They are | ||
where development generally takes place and are the usual targets | ||||
Dirkjan Ochtman
|
r10350 | for update and merge operations. Branch heads are changesets that have | ||
no child changeset on the same branch. | ||||
If one or more REVs are given, only branch heads on the branches | ||||
Martin Geisler
|
r15044 | associated with the specified changesets are shown. This means | ||
that you can use :hg:`heads foo` to see the heads on a branch | ||||
named ``foo``. | ||||
Greg Ward
|
r9502 | |||
If -c/--closed is specified, also show branch heads marked closed | ||||
Martin Geisler
|
r11193 | (see :hg:`commit --close-branch`). | ||
Greg Ward
|
r9502 | |||
If STARTREV is specified, only those heads that are descendants of | ||||
STARTREV will be displayed. | ||||
Dirkjan Ochtman
|
r10350 | |||
If -t/--topo is specified, named branch mechanics will be ignored and only | ||||
changesets without children will be shown. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 if matching heads are found, 1 if not. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Dirkjan Ochtman
|
r10328 | |||
Matt Mackall
|
r12925 | start = None | ||
if 'rev' in opts: | ||||
Matt Mackall
|
r14319 | start = scmutil.revsingle(repo, opts['rev'], None).node() | ||
Dirkjan Ochtman
|
r10328 | |||
Dirkjan Ochtman
|
r10350 | if opts.get('topo'): | ||
heads = [repo[h] for h in repo.heads(start)] | ||||
Benoit Boissinot
|
r1550 | else: | ||
Dirkjan Ochtman
|
r10348 | heads = [] | ||
Martin Geisler
|
r14466 | for branch in repo.branchmap(): | ||
heads += repo.branchheads(branch, start, opts.get('closed')) | ||||
heads = [repo[h] for h in heads] | ||||
Dirkjan Ochtman
|
r10350 | |||
if branchrevs: | ||||
Matt Mackall
|
r13047 | branches = set(repo[br].branch() for br in branchrevs) | ||
Dirkjan Ochtman
|
r10350 | heads = [h for h in heads if h.branch() in branches] | ||
Dirkjan Ochtman
|
r10328 | |||
Dirkjan Ochtman
|
r10349 | if opts.get('active') and branchrevs: | ||
dagheads = repo.heads(start) | ||||
Dirkjan Ochtman
|
r10350 | heads = [h for h in heads if h.node() in dagheads] | ||
Dirkjan Ochtman
|
r10349 | |||
if branchrevs: | ||||
Dirkjan Ochtman
|
r10350 | haveheads = set(h.branch() for h in heads) | ||
Dirkjan Ochtman
|
r10346 | if branches - haveheads: | ||
Matt Mackall
|
r13047 | headless = ', '.join(b for b in branches - haveheads) | ||
Dirkjan Ochtman
|
r10346 | msg = _('no open branch heads found on branches %s') | ||
if opts.get('rev'): | ||||
Matt Mackall
|
r16231 | msg += _(' (started at %s)') % opts['rev'] | ||
Dirkjan Ochtman
|
r10346 | ui.warn((msg + '\n') % headless) | ||
Eric Hopper
|
r4648 | if not heads: | ||
return 1 | ||||
Dirkjan Ochtman
|
r10328 | |||
Dirkjan Ochtman
|
r10350 | heads = sorted(heads, key=lambda x: -x.rev()) | ||
Matt Mackall
|
r3643 | displayer = cmdutil.show_changeset(ui, repo, opts) | ||
Dirkjan Ochtman
|
r10331 | for ctx in heads: | ||
displayer.show(ctx) | ||||
Robert Bachmann
|
r10152 | displayer.close() | ||
mpm@selenic.com
|
r221 | |||
Adrian Buehlmann
|
r14297 | @command('help', | ||
[('e', 'extension', None, _('show only help for extensions')), | ||||
('c', 'command', None, _('show only help for commands'))], | ||||
_('[-ec] [TOPIC]')) | ||||
Matt Mackall
|
r15020 | def help_(ui, name=None, unknowncmd=False, full=True, **opts): | ||
Matt Mackall
|
r7210 | """show help for a given topic or a help overview | ||
Matt Mackall
|
r3655 | |||
timeless
|
r8779 | With no arguments, print a list of commands with short help messages. | ||
Matt Mackall
|
r3655 | |||
Martin Geisler
|
r8004 | Given a topic, extension, or command name, print help for that | ||
Matt Mackall
|
r11177 | topic. | ||
Returns 0 if successful. | ||||
""" | ||||
Matt Mackall
|
r15023 | |||
Dirkjan Ochtman
|
r13608 | textwidth = min(ui.termwidth(), 80) - 2 | ||
Matt Mackall
|
r3655 | |||
Matt Mackall
|
r15145 | def optrst(options): | ||
data = [] | ||||
multioccur = False | ||||
for option in options: | ||||
if len(option) == 5: | ||||
shortopt, longopt, default, desc, optlabel = option | ||||
else: | ||||
shortopt, longopt, default, desc = option | ||||
optlabel = _("VALUE") # default label | ||||
if _("DEPRECATED") in desc and not ui.verbose: | ||||
continue | ||||
so = '' | ||||
if shortopt: | ||||
so = '-' + shortopt | ||||
lo = '--' + longopt | ||||
if default: | ||||
desc += _(" (default: %s)") % default | ||||
if isinstance(default, list): | ||||
lo += " %s [+]" % optlabel | ||||
multioccur = True | ||||
elif (default is not None) and not isinstance(default, bool): | ||||
lo += " %s" % optlabel | ||||
data.append((so, lo, desc)) | ||||
rst = minirst.maketable(data, 1) | ||||
Matt Mackall
|
r15192 | |||
Matt Mackall
|
r15145 | if multioccur: | ||
Matt Mackall
|
r15203 | rst += _("\n[+] marked option can be specified multiple times\n") | ||
Matt Mackall
|
r15145 | |||
return rst | ||||
Matt Mackall
|
r15023 | # list all option lists | ||
def opttext(optlist, width): | ||||
Matt Mackall
|
r15145 | rst = '' | ||
if not optlist: | ||||
return '' | ||||
Matt Mackall
|
r15023 | for title, options in optlist: | ||
Matt Mackall
|
r15203 | rst += '\n%s\n' % title | ||
if options: | ||||
rst += "\n" | ||||
rst += optrst(options) | ||||
rst += '\n' | ||||
Matt Mackall
|
r15145 | |||
return '\n' + minirst.format(rst, width) | ||||
Matt Mackall
|
r15023 | |||
Matt Mackall
|
r15129 | def addglobalopts(optlist, aliases): | ||
if ui.quiet: | ||||
return [] | ||||
Alexis S. L. Carvalho
|
r4315 | if ui.verbose: | ||
Matt Mackall
|
r15022 | optlist.append((_("global options:"), globalopts)) | ||
Alexis S. L. Carvalho
|
r4315 | if name == 'shortlist': | ||
Matt Mackall
|
r15022 | optlist.append((_('use "hg help" for the full list ' | ||
Alexis S. L. Carvalho
|
r4315 | 'of commands'), ())) | ||
else: | ||||
if name == 'shortlist': | ||||
msg = _('use "hg help" for the full list of commands ' | ||||
'or "hg -v" for details') | ||||
Adrian Buehlmann
|
r13950 | elif name and not full: | ||
Matt Mackall
|
r16231 | msg = _('use "hg help %s" to show the full help text') % name | ||
Alexis S. L. Carvalho
|
r4315 | elif aliases: | ||
Martin Geisler
|
r13230 | msg = _('use "hg -v help%s" to show builtin aliases and ' | ||
Alexis S. L. Carvalho
|
r4315 | 'global options') % (name and " " + name or "") | ||
else: | ||||
Matt Mackall
|
r15202 | msg = _('use "hg -v help %s" to show more info') % name | ||
Matt Mackall
|
r15022 | optlist.append((msg, ())) | ||
Alexis S. L. Carvalho
|
r4315 | |||
Matt Mackall
|
r3655 | def helpcmd(name): | ||
Johannes Stezenbach
|
r6652 | try: | ||
Brodie Rao
|
r10364 | aliases, entry = cmdutil.findcmd(name, table, strict=unknowncmd) | ||
Matt Mackall
|
r7643 | except error.AmbiguousCommand, inst: | ||
Alejandro Santos
|
r9035 | # py3k fix: except vars can't be used outside the scope of the | ||
# except block, nor can be used inside a lambda. python issue4617 | ||||
prefix = inst.args[0] | ||||
select = lambda c: c.lstrip('^').startswith(prefix) | ||||
Matt Mackall
|
r15127 | helplist(select) | ||
Johannes Stezenbach
|
r6652 | return | ||
Brodie Rao
|
r10021 | # check if it's an invalid alias and display its error if it is | ||
if getattr(entry[0], 'badalias', False): | ||||
Brodie Rao
|
r10364 | if not unknowncmd: | ||
entry[0](ui) | ||||
Brodie Rao
|
r10021 | return | ||
Matt Mackall
|
r15203 | rst = "" | ||
Matt Mackall
|
r3655 | # synopsis | ||
Henri Wiechers
|
r9901 | if len(entry) > 2: | ||
if entry[2].startswith('hg'): | ||||
Matt Mackall
|
r15203 | rst += "%s\n" % entry[2] | ||
Matt Mackall
|
r7364 | else: | ||
Matt Mackall
|
r15203 | rst += 'hg %s %s\n' % (aliases[0], entry[2]) | ||
Matt Mackall
|
r7364 | else: | ||
Matt Mackall
|
r15203 | rst += 'hg %s\n' % aliases[0] | ||
Thomas Arendsen Hein
|
r5783 | |||
# aliases | ||||
Adrian Buehlmann
|
r13950 | if full and not ui.quiet and len(aliases) > 1: | ||
Matt Mackall
|
r15203 | rst += _("\naliases: %s\n") % ', '.join(aliases[1:]) | ||
Matt Mackall
|
r3655 | |||
# description | ||||
Henri Wiechers
|
r9901 | doc = gettext(entry[0].__doc__) | ||
Matt Mackall
|
r3655 | if not doc: | ||
Martin Geisler
|
r7598 | doc = _("(no help text available)") | ||
Augie Fackler
|
r14954 | if util.safehasattr(entry[0], 'definition'): # aliased command | ||
Steve Losh
|
r11524 | if entry[0].definition.startswith('!'): # shell alias | ||
doc = _('shell alias for::\n\n %s') % entry[0].definition[1:] | ||||
else: | ||||
doc = _('alias for: hg %s\n\n%s') % (entry[0].definition, doc) | ||||
Adrian Buehlmann
|
r13950 | if ui.quiet or not full: | ||
Nicolas Dumazet
|
r9136 | doc = doc.splitlines()[0] | ||
Matt Mackall
|
r15203 | rst += "\n" + doc + "\n" | ||
Alexis S. L. Carvalho
|
r4315 | |||
Martin Geisler
|
r14285 | # check if this command shadows a non-trivial (multi-line) | ||
# extension help text | ||||
try: | ||||
mod = extensions.find(name) | ||||
doc = gettext(mod.__doc__) or '' | ||||
if '\n' in doc.strip(): | ||||
msg = _('use "hg help -e %s" to show help for ' | ||||
'the %s extension') % (name, name) | ||||
Matt Mackall
|
r15203 | rst += '\n%s\n' % msg | ||
Martin Geisler
|
r14285 | except KeyError: | ||
pass | ||||
Matt Mackall
|
r15203 | # options | ||
if not ui.quiet and entry[1]: | ||||
Jens Bäckman
|
r15985 | rst += '\n' | ||
rst += _("options:") | ||||
rst += '\n\n' | ||||
Matt Mackall
|
r15203 | rst += optrst(entry[1]) | ||
if ui.verbose: | ||||
Jens Bäckman
|
r15985 | rst += '\n' | ||
rst += _("global options:") | ||||
rst += '\n\n' | ||||
Matt Mackall
|
r15203 | rst += optrst(globalopts) | ||
keep = ui.verbose and ['verbose'] or [] | ||||
formatted, pruned = minirst.format(rst, textwidth, keep=keep) | ||||
ui.write(formatted) | ||||
if not ui.verbose: | ||||
if not full: | ||||
ui.write(_('\nuse "hg help %s" to show the full help text\n') | ||||
% name) | ||||
elif not ui.quiet: | ||||
ui.write(_('\nuse "hg -v help %s" to show more info\n') % name) | ||||
Matt Mackall
|
r15128 | |||
Matt Mackall
|
r15127 | def helplist(select=None): | ||
# list of commands | ||||
if name == "shortlist": | ||||
header = _('basic commands:\n\n') | ||||
else: | ||||
header = _('list of commands:\n\n') | ||||
Matt Mackall
|
r3655 | h = {} | ||
cmds = {} | ||||
Dirkjan Ochtman
|
r7622 | for c, e in table.iteritems(): | ||
Matt Mackall
|
r3655 | f = c.split("|", 1)[0] | ||
if select and not select(f): | ||||
continue | ||||
Dirkjan Ochtman
|
r7197 | if (not select and name != 'shortlist' and | ||
e[0].__module__ != __name__): | ||||
Dirkjan Ochtman
|
r7126 | continue | ||
Matt Mackall
|
r3655 | if name == "shortlist" and not f.startswith("^"): | ||
continue | ||||
f = f.lstrip("^") | ||||
if not ui.debugflag and f.startswith("debug"): | ||||
continue | ||||
Dan Villiom Podlaski Christiansen
|
r9128 | doc = e[0].__doc__ | ||
if doc and 'DEPRECATED' in doc and not ui.verbose: | ||||
continue | ||||
doc = gettext(doc) | ||||
Matt Mackall
|
r3655 | if not doc: | ||
Martin Geisler
|
r7598 | doc = _("(no help text available)") | ||
Nicolas Dumazet
|
r9136 | h[f] = doc.splitlines()[0].rstrip() | ||
Matt Mackall
|
r3655 | cmds[f] = c.lstrip("^") | ||
Alexis S. L. Carvalho
|
r4950 | if not h: | ||
ui.status(_('no commands defined\n')) | ||||
return | ||||
ui.status(header) | ||||
Matt Mackall
|
r8209 | fns = sorted(h) | ||
Matt Mackall
|
r3655 | m = max(map(len, fns)) | ||
for f in fns: | ||||
if ui.verbose: | ||||
commands = cmds[f].replace("|",", ") | ||||
ui.write(" %s:\n %s\n"%(commands, h[f])) | ||||
else: | ||||
Matt Mackall
|
r12698 | ui.write('%s\n' % (util.wrap(h[f], textwidth, | ||
Olav Reinert
|
r15862 | initindent=' %-*s ' % (m, f), | ||
FUJIWARA Katsunori
|
r11297 | hangindent=' ' * (m + 4)))) | ||
Matt Mackall
|
r3655 | |||
Matt Mackall
|
r15126 | if not name: | ||
text = help.listexts(_('enabled extensions:'), extensions.enabled()) | ||||
if text: | ||||
ui.write("\n%s" % minirst.format(text, textwidth)) | ||||
ui.write(_("\nadditional help topics:\n\n")) | ||||
topics = [] | ||||
for names, header, doc in help.helptable: | ||||
topics.append((sorted(names, key=len, reverse=True)[0], header)) | ||||
topics_len = max([len(s[0]) for s in topics]) | ||||
for t, desc in topics: | ||||
Olav Reinert
|
r15862 | ui.write(" %-*s %s\n" % (topics_len, t, desc)) | ||
Matt Mackall
|
r15126 | |||
Matt Mackall
|
r15129 | optlist = [] | ||
addglobalopts(optlist, True) | ||||
Matt Mackall
|
r15128 | ui.write(opttext(optlist, textwidth)) | ||
Matt Mackall
|
r3795 | def helptopic(name): | ||
Martin Geisler
|
r7012 | for names, header, doc in help.helptable: | ||
if name in names: | ||||
break | ||||
else: | ||||
Matt Mackall
|
r7643 | raise error.UnknownCommand(name) | ||
Matt Mackall
|
r3795 | |||
# description | ||||
if not doc: | ||||
Martin Geisler
|
r7598 | doc = _("(no help text available)") | ||
Augie Fackler
|
r14943 | if util.safehasattr(doc, '__call__'): | ||
Matt Mackall
|
r3796 | doc = doc() | ||
Matt Mackall
|
r3795 | |||
Martin Geisler
|
r9157 | ui.write("%s\n\n" % header) | ||
Matt Mackall
|
r15125 | ui.write("%s" % minirst.format(doc, textwidth, indent=4)) | ||
Martin Geisler
|
r14286 | try: | ||
cmdutil.findcmd(name, table) | ||||
ui.write(_('\nuse "hg help -c %s" to see help for ' | ||||
'the %s command\n') % (name, name)) | ||||
except error.UnknownCommand: | ||||
pass | ||||
Matt Mackall
|
r3795 | |||
Matt Mackall
|
r3655 | def helpext(name): | ||
try: | ||||
Matt Mackall
|
r4544 | mod = extensions.find(name) | ||
Brodie Rao
|
r10364 | doc = gettext(mod.__doc__) or _('no help text available') | ||
Matt Mackall
|
r3655 | except KeyError: | ||
Brodie Rao
|
r10364 | mod = None | ||
doc = extensions.disabledext(name) | ||||
if not doc: | ||||
raise error.UnknownCommand(name) | ||||
David Soria Parra
|
r9280 | if '\n' not in doc: | ||
head, tail = doc, "" | ||||
else: | ||||
head, tail = doc.split('\n', 1) | ||||
Martin Geisler
|
r9157 | ui.write(_('%s extension - %s\n\n') % (name.split('.')[-1], head)) | ||
if tail: | ||||
ui.write(minirst.format(tail, textwidth)) | ||||
Matt Mackall
|
r15125 | ui.status('\n') | ||
Benoit Boissinot
|
r4009 | |||
Brodie Rao
|
r10364 | if mod: | ||
try: | ||||
ct = mod.cmdtable | ||||
except AttributeError: | ||||
ct = {} | ||||
modcmds = set([c.split('|', 1)[0] for c in ct]) | ||||
Matt Mackall
|
r15127 | helplist(modcmds.__contains__) | ||
Brodie Rao
|
r10364 | else: | ||
ui.write(_('use "hg help extensions" for information on enabling ' | ||||
'extensions\n')) | ||||
def helpextcmd(name): | ||||
Yuya Nishihara
|
r16591 | cmd, ext, mod = extensions.disabledcmd(ui, name, | ||
ui.configbool('ui', 'strict')) | ||||
Brodie Rao
|
r10364 | doc = gettext(mod.__doc__).splitlines()[0] | ||
msg = help.listexts(_("'%s' is provided by the following " | ||||
Matt Mackall
|
r14316 | "extension:") % cmd, {ext: doc}, indent=4) | ||
Brodie Rao
|
r10364 | ui.write(minirst.format(msg, textwidth)) | ||
Matt Mackall
|
r15125 | ui.write('\n') | ||
Brodie Rao
|
r10364 | ui.write(_('use "hg help extensions" for information on enabling ' | ||
'extensions\n')) | ||||
Matt Mackall
|
r3655 | |||
if name and name != 'shortlist': | ||||
Matt Mackall
|
r3795 | i = None | ||
Brodie Rao
|
r10364 | if unknowncmd: | ||
queries = (helpextcmd,) | ||||
Henri Wiechers
|
r14284 | elif opts.get('extension'): | ||
queries = (helpext,) | ||||
Martin Geisler
|
r14286 | elif opts.get('command'): | ||
queries = (helpcmd,) | ||||
Brodie Rao
|
r10364 | else: | ||
queries = (helptopic, helpcmd, helpext, helpextcmd) | ||||
for f in queries: | ||||
Matt Mackall
|
r3795 | try: | ||
f(name) | ||||
i = None | ||||
break | ||||
Matt Mackall
|
r7643 | except error.UnknownCommand, inst: | ||
Matt Mackall
|
r3795 | i = inst | ||
if i: | ||||
raise i | ||||
Matt Mackall
|
r3655 | else: | ||
# program name | ||||
Matt Mackall
|
r15020 | ui.status(_("Mercurial Distributed SCM\n")) | ||
Matt Mackall
|
r3655 | ui.status('\n') | ||
Matt Mackall
|
r15127 | helplist() | ||
Johannes Stezenbach
|
r6653 | |||
mpm@selenic.com
|
r221 | |||
Adrian Buehlmann
|
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')), | ||||
Mads Kiilerich
|
r15580 | ('B', 'bookmarks', None, _('show bookmarks')), | ||
] + remoteopts, | ||||
Adrian Buehlmann
|
r14297 | _('[-nibtB] [-r REV] [SOURCE]')) | ||
Kevin Bullock
|
r13477 | def identify(ui, repo, source=None, rev=None, | ||
Mads Kiilerich
|
r15580 | num=None, id=None, branch=None, tags=None, bookmarks=None, **opts): | ||
Matt Mackall
|
r4665 | """identify the working copy or specified revision | ||
Kevin Bullock
|
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. | ||||
Idan Kamara
|
r13952 | |||
When REV is not given, print a summary of the current state of the | ||||
Martin Geisler
|
r8027 | repository. | ||
Matt Mackall
|
r4671 | |||
timeless
|
r8779 | Specifying a path to a repository root or Mercurial bundle will | ||
cause lookup to operate on that repository/bundle. | ||||
Benoit Boissinot
|
r1437 | |||
Matt Mackall
|
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/ | ||||
Matt Mackall
|
r11177 | Returns 0 if successful. | ||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r4662 | |||
Alexis S. L. Carvalho
|
r5330 | if not repo and not source: | ||
Martin Geisler
|
r12067 | raise util.Abort(_("there is no Mercurial repository here " | ||
Alexis S. L. Carvalho
|
r5330 | "(.hg not found)")) | ||
Matt Mackall
|
r2966 | hexfunc = ui.debugflag and hex or short | ||
Kevin Bullock
|
r13477 | default = not (num or id or branch or tags or bookmarks) | ||
Matt Mackall
|
r4666 | output = [] | ||
Dirkjan Ochtman
|
r7757 | revs = [] | ||
Idan Kamara
|
r13953 | |||
Matt Mackall
|
r4671 | if source: | ||
Sune Foldager
|
r10365 | source, branches = hg.parseurl(ui.expandpath(source)) | ||
Mads Kiilerich
|
r15580 | repo = hg.peer(ui, opts, source) | ||
Sune Foldager
|
r10365 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) | ||
Dirkjan Ochtman
|
r7757 | |||
if not repo.local(): | ||||
Idan Kamara
|
r13953 | if num or branch or tags: | ||
raise util.Abort( | ||||
_("can't query remote revision number, branch, or tags")) | ||||
Matt Mackall
|
r4671 | if not rev and revs: | ||
rev = revs[0] | ||||
Matt Mackall
|
r4667 | if not rev: | ||
rev = "tip" | ||||
Nils Adermann
|
r13644 | |||
remoterev = repo.lookup(rev) | ||||
Matt Mackall
|
r4666 | if default or id: | ||
Nils Adermann
|
r13644 | output = [hexfunc(remoterev)] | ||
Idan Kamara
|
r13953 | def getbms(): | ||
bms = [] | ||||
if 'bookmarks' in repo.listkeys('namespaces'): | ||||
hexremoterev = hex(remoterev) | ||||
bms = [bm for bm, bmr in repo.listkeys('bookmarks').iteritems() | ||||
if bmr == hexremoterev] | ||||
return bms | ||||
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) | ||||
Matt Mackall
|
r4665 | else: | ||
Idan Kamara
|
r13953 | if not rev: | ||
ctx = repo[None] | ||||
parents = ctx.parents() | ||||
changed = "" | ||||
if default or id or num: | ||||
changed = util.any(repo.status()) and "+" or "" | ||||
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: | ||||
Matt Mackall
|
r14319 | ctx = scmutil.revsingle(repo, rev) | ||
Idan Kamara
|
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()) | ||||
Kevin Bullock
|
r13477 | |||
Thomas Arendsen Hein
|
r386 | ui.write("%s\n" % ' '.join(output)) | ||
Thomas Arendsen Hein
|
r339 | |||
Adrian Buehlmann
|
r14297 | @command('import|patch', | ||
[('p', 'strip', 1, | ||||
_('directory strip option for patch. This has the same ' | ||||
'meaning as the corresponding patch option'), _('NUM')), | ||||
Patrick Mezard
|
r14532 | ('b', 'base', '', _('base path (DEPRECATED)'), _('PATH')), | ||
Matt Mackall
|
r15221 | ('e', 'edit', False, _('invoke editor on commit messages')), | ||
Adrian Buehlmann
|
r14297 | ('f', 'force', None, _('skip check for outstanding uncommitted changes')), | ||
('', 'no-commit', None, | ||||
_("don't commit, just update the working directory")), | ||||
Patrick Mezard
|
r14611 | ('', 'bypass', None, | ||
_("apply patch without touching the working directory")), | ||||
Adrian Buehlmann
|
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...')) | ||||
Kevin Bullock
|
r15327 | def import_(ui, repo, patch1=None, *patches, **opts): | ||
Benoit Boissinot
|
r1437 | """import an ordered set of patches | ||
timeless@mozdev.org
|
r9649 | Import a list of patches and commit them individually (unless | ||
--no-commit is specified). | ||||
Benoit Boissinot
|
r1437 | |||
If there are outstanding changes in the working directory, import | ||||
Martin Geisler
|
r8033 | will abort unless given the -f/--force flag. | ||
Benoit Boissinot
|
r1437 | |||
Christian Ebert
|
r6448 | You can import a patch straight from a mail message. Even patches | ||
timeless
|
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 | ||||
Christian Ebert
|
r6448 | message are used as default committer and commit message. All | ||
Vadim Gelfer
|
r2515 | text/plain body parts before first diff are added to commit | ||
message. | ||||
Vadim Gelfer
|
r2504 | |||
Martin Geisler
|
r11193 | If the imported patch was generated by :hg:`export`, user and | ||
Martin Geisler
|
r8004 | description from patch override values from message headers and | ||
Martin Geisler
|
r8033 | body. Values given on command line with -m/--message and -u/--user | ||
override these. | ||||
Martin Geisler
|
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. | ||||
Brendan Cully
|
r4263 | |||
Patrick Mezard
|
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. | ||||
Martin Geisler
|
r8033 | With -s/--similarity, hg will attempt to discover renames and | ||
Martin Geisler
|
r15779 | copies in the patch in the same way as :hg:`addremove`. | ||
Brendan Cully
|
r7402 | |||
Dirkjan Ochtman
|
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. | ||||
Martin Geisler
|
r10973 | See :hg:`help dates` for a list of formats valid for -d/--date. | ||
Matt Mackall
|
r11177 | |||
Matt Mackall
|
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 | ||||
Matt Mackall
|
r11177 | Returns 0 on success. | ||
Benoit Boissinot
|
r1437 | """ | ||
Kevin Bullock
|
r15327 | |||
if not patch1: | ||||
raise util.Abort(_('need at least one patch to import')) | ||||
mpm@selenic.com
|
r437 | patches = (patch1,) + patches | ||
mpm@selenic.com
|
r500 | |||
Thomas Arendsen Hein
|
r6139 | date = opts.get('date') | ||
if date: | ||||
opts['date'] = util.parsedate(date) | ||||
Matt Mackall
|
r15221 | editor = cmdutil.commiteditor | ||
if opts.get('edit'): | ||||
editor = cmdutil.commitforceeditor | ||||
Patrick Mezard
|
r14611 | update = not opts.get('bypass') | ||
if not update and opts.get('no_commit'): | ||||
raise util.Abort(_('cannot use --no-commit with --bypass')) | ||||
Brendan Cully
|
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')) | ||||
Patrick Mezard
|
r14611 | if sim and not update: | ||
raise util.Abort(_('cannot use --similarity with --bypass')) | ||||
if (opts.get('exact') or not opts.get('force')) and update: | ||||
Matt Mackall
|
r14289 | cmdutil.bailifchanged(repo) | ||
mpm@selenic.com
|
r966 | |||
Greg Ward
|
r15195 | base = opts["base"] | ||
mpm@selenic.com
|
r437 | strip = opts["strip"] | ||
Greg Ward
|
r15198 | wlock = lock = tr = None | ||
Steve Borho
|
r12913 | msgs = [] | ||
Brendan Cully
|
r10384 | |||
Patrick Mezard
|
r14611 | def checkexact(repo, n, nodeid): | ||
if opts.get('exact') and hex(n) != nodeid: | ||||
repo.rollback() | ||||
raise util.Abort(_('patch is damaged or loses information')) | ||||
def tryone(ui, hunk, parents): | ||||
Matt Mackall
|
r10413 | tmpname, message, user, date, branch, nodeid, p1, p2 = \ | ||
patch.extract(ui, hunk) | ||||
Brendan Cully
|
r10384 | |||
if not tmpname: | ||||
Greg Ward
|
r15194 | return (None, None) | ||
msg = _('applied to working directory') | ||||
Brendan Cully
|
r10384 | |||
try: | ||||
Idan Kamara
|
r14635 | cmdline_message = cmdutil.logmessage(ui, opts) | ||
Brendan Cully
|
r10384 | if cmdline_message: | ||
# pickup the cmdline msg | ||||
message = cmdline_message | ||||
elif message: | ||||
# pickup the patch msg | ||||
message = message.strip() | ||||
else: | ||||
# launch the editor | ||||
message = None | ||||
ui.debug('message:\n%s\n' % message) | ||||
Patrick Mezard
|
r14611 | if len(parents) == 1: | ||
parents.append(repo[nullid]) | ||||
Brendan Cully
|
r10384 | if opts.get('exact'): | ||
if not nodeid or not p1: | ||||
raise util.Abort(_('not a Mercurial patch')) | ||||
Patrick Mezard
|
r14610 | p1 = repo[p1] | ||
p2 = repo[p2 or nullid] | ||||
Brendan Cully
|
r10384 | elif p2: | ||
try: | ||||
Patrick Mezard
|
r14610 | p1 = repo[p1] | ||
p2 = repo[p2] | ||||
Patrick Mezard
|
r15511 | # Without any options, consider p2 only if the | ||
# patch is being applied on top of the recorded | ||||
# first parent. | ||||
if p1 != parents[0]: | ||||
p1 = parents[0] | ||||
p2 = repo[nullid] | ||||
Brendan Cully
|
r10384 | except error.RepoError: | ||
Patrick Mezard
|
r14611 | p1, p2 = parents | ||
Patrick Mezard
|
r14610 | else: | ||
Patrick Mezard
|
r14611 | p1, p2 = parents | ||
n = None | ||||
if update: | ||||
Patrick Mezard
|
r15511 | if p1 != parents[0]: | ||
Patrick Mezard
|
r14611 | hg.clean(repo, p1.node()) | ||
Patrick Mezard
|
r15511 | if p2 != parents[1]: | ||
Patrick Mezard
|
r16551 | repo.setparents(p1.node(), p2.node()) | ||
Patrick Mezard
|
r14611 | |||
if opts.get('exact') or opts.get('import_branch'): | ||||
repo.dirstate.setbranch(branch or 'default') | ||||
files = set() | ||||
patch.patch(ui, repo, tmpname, strip=strip, files=files, | ||||
eolmode=None, similarity=sim / 100.0) | ||||
files = list(files) | ||||
if opts.get('no_commit'): | ||||
if message: | ||||
msgs.append(message) | ||||
else: | ||||
Patrick Mezard
|
r15511 | if opts.get('exact') or p2: | ||
# If you got here, you either use --force and know what | ||||
# you are doing or used --exact or a merge patch while | ||||
# being updated to its first parent. | ||||
Patrick Mezard
|
r14611 | m = None | ||
else: | ||||
m = scmutil.matchfiles(repo, files or []) | ||||
n = repo.commit(message, opts.get('user') or user, | ||||
opts.get('date') or date, match=m, | ||||
Matt Mackall
|
r15221 | editor=editor) | ||
Patrick Mezard
|
r14611 | checkexact(repo, n, nodeid) | ||
Steve Borho
|
r12913 | else: | ||
Patrick Mezard
|
r14611 | if opts.get('exact') or opts.get('import_branch'): | ||
branch = branch or 'default' | ||||
Brendan Cully
|
r10384 | else: | ||
Patrick Mezard
|
r14611 | branch = p1.branch() | ||
store = patch.filestore() | ||||
try: | ||||
files = set() | ||||
try: | ||||
patch.patchrepo(ui, repo, p1, store, tmpname, strip, | ||||
files, eolmode=None) | ||||
except patch.PatchError, e: | ||||
raise util.Abort(str(e)) | ||||
memctx = patch.makememctx(repo, (p1.node(), p2.node()), | ||||
message, | ||||
opts.get('user') or user, | ||||
opts.get('date') or date, | ||||
branch, files, store, | ||||
editor=cmdutil.commiteditor) | ||||
repo.savecommitmessage(memctx.description()) | ||||
n = memctx.commit() | ||||
checkexact(repo, n, nodeid) | ||||
finally: | ||||
store.close() | ||||
if n: | ||||
Wagner Bruna
|
r15307 | # i18n: refers to a short changeset id | ||
Greg Ward
|
r15194 | msg = _('created %s') % short(n) | ||
return (msg, n) | ||||
Brendan Cully
|
r10384 | finally: | ||
os.unlink(tmpname) | ||||
Peter Arrenbrecht
|
r10405 | |||
Matt Mackall
|
r4915 | try: | ||
Thomas Arendsen Hein
|
r15278 | try: | ||
wlock = repo.wlock() | ||||
Matt Mackall
|
r16274 | if not opts.get('no_commit'): | ||
lock = repo.lock() | ||||
tr = repo.transaction('import') | ||||
Thomas Arendsen Hein
|
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 | ||||
Patrick Mezard
|
r14611 | else: | ||
Thomas Arendsen Hein
|
r15278 | patchurl = os.path.join(base, patchurl) | ||
ui.status(_('applying %s\n') % patchurl) | ||||
patchfile = url.open(ui, patchurl) | ||||
haspatch = False | ||||
for hunk in patch.split(patchfile): | ||||
(msg, node) = tryone(ui, hunk, parents) | ||||
if msg: | ||||
haspatch = True | ||||
ui.note(msg + '\n') | ||||
if update or opts.get('exact'): | ||||
parents = repo.parents() | ||||
else: | ||||
parents = [repo[node]] | ||||
if not haspatch: | ||||
raise util.Abort(_('%s: no diffs found') % patchurl) | ||||
Matt Mackall
|
r16274 | if tr: | ||
tr.close() | ||||
Thomas Arendsen Hein
|
r15278 | if msgs: | ||
repo.savecommitmessage('\n* * *\n'.join(msgs)) | ||||
except: | ||||
# 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 | ||||
Matt Mackall
|
r4915 | finally: | ||
Greg Ward
|
r15198 | if tr: | ||
tr.release() | ||||
Ronny Pfannschmidt
|
r8109 | release(lock, wlock) | ||
mpm@selenic.com
|
r437 | |||
Adrian Buehlmann
|
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]')) | ||||
TK Soh
|
r1192 | def incoming(ui, repo, source="default", **opts): | ||
Benoit Boissinot
|
r1437 | """show new changesets found in source | ||
Thomas Arendsen Hein
|
r1979 | Show new changesets found in the specified path/URL or the default | ||
timeless
|
r8779 | pull location. These are the changesets that would have been pulled | ||
if a pull at the time you issued this command. | ||||
Martin Geisler
|
r8004 | |||
For remote repository, using --bundle avoids downloading the | ||||
changesets twice if the incoming is followed by a pull. | ||||
Thomas Arendsen Hein
|
r1979 | |||
See pull for valid source format details. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 if there are incoming changes, 1 otherwise. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Martin Geisler
|
r12274 | if opts.get('bundle') and opts.get('subrepos'): | ||
raise util.Abort(_('cannot combine --bundle and --subrepos')) | ||||
Matt Mackall
|
r13366 | if opts.get('bookmarks'): | ||
source, branches = hg.parseurl(ui.expandpath(source), | ||||
opts.get('branch')) | ||||
Matt Mackall
|
r14556 | other = hg.peer(repo, opts, source) | ||
David Soria Parra
|
r13453 | if 'bookmarks' not in other.listkeys('namespaces'): | ||
ui.warn(_("remote doesn't support bookmarks\n")) | ||||
return 0 | ||||
Brodie Rao
|
r14076 | ui.status(_('comparing with %s\n') % util.hidepassword(source)) | ||
Matt Mackall
|
r13366 | return bookmarks.diff(ui, repo, other) | ||
Martin Geisler
|
r14360 | repo._subtoppath = ui.expandpath(source) | ||
try: | ||||
Martin Geisler
|
r14362 | return hg.incoming(ui, repo, source, opts) | ||
Martin Geisler
|
r14360 | finally: | ||
del repo._subtoppath | ||||
Benoit Boissinot
|
r1944 | |||
Adrian Buehlmann
|
r14297 | @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]')) | ||
Thomas Arendsen Hein
|
r2598 | def init(ui, dest=".", **opts): | ||
Benoit Boissinot
|
r1437 | """create a new repository in the given directory | ||
Christian Ebert
|
r6448 | Initialize a new repository in the given directory. If the given | ||
timeless
|
r8779 | directory does not exist, it will be created. | ||
Benoit Boissinot
|
r1437 | |||
If no directory is given, the current directory is used. | ||||
Thomas Arendsen Hein
|
r2590 | |||
Martin Geisler
|
r9970 | It is possible to specify an ``ssh://`` URL as the destination. | ||
Martin Geisler
|
r10973 | See :hg:`help urls` for more information. | ||
Matt Mackall
|
r11177 | |||
Returns 0 on success. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r14556 | hg.peer(ui, opts, ui.expandpath(dest), create=True) | ||
mpm@selenic.com
|
r338 | |||
Adrian Buehlmann
|
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]...')) | ||||
Bryan O'Sullivan
|
r627 | def locate(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """locate files matching specific patterns | ||
timeless
|
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. | ||||
Benoit Boissinot
|
r1437 | |||
If you want to feed the output of this command into the "xargs" | ||||
Martin Geisler
|
r8032 | command, use the -0 option to both this command and "xargs". This | ||
will avoid the problem of "xargs" treating single filenames that | ||||
timeless
|
r8779 | contain whitespace as multiple filenames. | ||
Matt Mackall
|
r11177 | |||
Returns 0 if a match is found, 1 otherwise. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Alexander Solovyov
|
r7131 | end = opts.get('print0') and '\0' or '\n' | ||
Matt Mackall
|
r14319 | rev = scmutil.revsingle(repo, opts.get('rev'), None).node() | ||
mpm@selenic.com
|
r742 | |||
Alexis S. L. Carvalho
|
r4196 | ret = 1 | ||
Matt Mackall
|
r14671 | m = scmutil.match(repo[rev], pats, opts, default='relglob') | ||
Matt Mackall
|
r10282 | m.bad = lambda x, y: False | ||
Matt Mackall
|
r6764 | for abs in repo[rev].walk(m): | ||
if not rev and abs not in repo.dirstate: | ||||
Alexis S. L. Carvalho
|
r4308 | continue | ||
Alexander Solovyov
|
r7131 | if opts.get('fullpath'): | ||
Martin Geisler
|
r7570 | ui.write(repo.wjoin(abs), end) | ||
Bryan O'Sullivan
|
r724 | else: | ||
Matt Mackall
|
r6584 | ui.write(((pats and m.rel(abs)) or abs), end) | ||
Alexis S. L. Carvalho
|
r4196 | ret = 0 | ||
return ret | ||||
Bryan O'Sullivan
|
r627 | |||
Adrian Buehlmann
|
r14297 | @command('^log|history', | ||
[('f', 'follow', None, | ||||
_('follow changeset history, or file history across copies and renames')), | ||||
('', 'follow-first', None, | ||||
Matt Mackall
|
r15405 | _('only follow the first parent of merge changesets (DEPRECATED)')), | ||
Adrian Buehlmann
|
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')), | ||||
Matt Mackall
|
r15405 | ('m', 'only-merges', None, _('show only merges (DEPRECATED)')), | ||
Adrian Buehlmann
|
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')), | ||||
Matt Mackall
|
r15424 | ('', 'hidden', False, _('show hidden changesets (DEPRECATED)')), | ||
Adrian Buehlmann
|
r14297 | ] + logopts + walkopts, | ||
_('[OPTION]... [FILE]')) | ||||
Bryan O'Sullivan
|
r1031 | def log(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """show revision history of entire repository or files | ||
Vadim Gelfer
|
r2741 | Print the revision history of the specified files or the entire | ||
project. | ||||
Matt Mackall
|
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. | ||||
Vadim Gelfer
|
r2741 | File history is shown without following rename or copy history of | ||
timeless
|
r8761 | files. Use -f/--follow with a filename to follow history across | ||
renames and copies. --follow without a filename will only show | ||||
Matt Mackall
|
r15104 | ancestors or descendants of the starting revision. | ||
Thomas Arendsen Hein
|
r6163 | |||
timeless
|
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. | ||||
Matt Mackall
|
r3822 | |||
Christian Ebert
|
r12390 | .. note:: | ||
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:. | ||||
Matt Mackall
|
r11177 | |||
Matt Mackall
|
r15105 | .. note:: | ||
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. | ||||
Matt Mackall
|
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" | ||||
- 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" | ||||
Matt Mackall
|
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. | ||||
A. S. Budden
|
r16568 | See :hg:`help templates` for more about pre-packaged styles and | ||
specifying custom templates. | ||||
Matt Mackall
|
r11177 | Returns 0 on success. | ||
Benoit Boissinot
|
r1437 | """ | ||
Vadim Gelfer
|
r1756 | |||
Matt Mackall
|
r14671 | matchfn = scmutil.match(repo[None], pats, opts) | ||
Thomas Arendsen Hein
|
r6190 | limit = cmdutil.loglimit(opts) | ||
Vadim Gelfer
|
r1756 | count = 0 | ||
Patrick Mezard
|
r16175 | getrenamed, endrev = None, None | ||
if opts.get('copies'): | ||||
if opts.get('rev'): | ||||
endrev = max(scmutil.revrange(repo, opts.get('rev'))) + 1 | ||||
getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) | ||||
Brendan Cully
|
r3197 | |||
Matt Mackall
|
r3813 | df = False | ||
if opts["date"]: | ||||
df = util.matchdate(opts["date"]) | ||||
Benoit Boissinot
|
r10963 | branches = opts.get('branch', []) + opts.get('only_branch', []) | ||
opts['branch'] = [repo.lookupbranch(b) for b in branches] | ||||
Steve Losh
|
r10957 | |||
Mads Kiilerich
|
r11488 | displayer = cmdutil.show_changeset(ui, repo, opts, True) | ||
Matt Mackall
|
r9662 | def prep(ctx, fns): | ||
Matt Mackall
|
r9655 | rev = ctx.rev() | ||
Matt Mackall
|
r9662 | parents = [p for p in repo.changelog.parentrevs(rev) | ||
if p != nullrev] | ||||
if opts.get('no_merges') and len(parents) == 2: | ||||
return | ||||
if opts.get('only_merges') and len(parents) != 2: | ||||
return | ||||
Steve Losh
|
r10957 | if opts.get('branch') and ctx.branch() not in opts['branch']: | ||
Matt Mackall
|
r9662 | return | ||
Pierre-Yves David
|
r14645 | if not opts.get('hidden') and ctx.hidden(): | ||
return | ||||
Matt Mackall
|
r9662 | if df and not df(ctx.date()[0]): | ||
return | ||||
FUJIWARA Katsunori
|
r15725 | |||
lower = encoding.lower | ||||
if opts.get('user'): | ||||
luser = lower(ctx.user()) | ||||
for k in [lower(x) for x in opts['user']]: | ||||
if (k in luser): | ||||
break | ||||
else: | ||||
return | ||||
Matt Mackall
|
r9662 | if opts.get('keyword'): | ||
FUJIWARA Katsunori
|
r15725 | luser = lower(ctx.user()) | ||
ldesc = lower(ctx.description()) | ||||
lfiles = lower(" ".join(ctx.files())) | ||||
for k in [lower(x) for x in opts['keyword']]: | ||||
if (k in luser or k in ldesc or k in lfiles): | ||||
Matt Mackall
|
r9662 | break | ||
Matt Mackall
|
r9663 | else: | ||
Matt Mackall
|
r9662 | return | ||
Patrick Mezard
|
r10060 | copies = None | ||
Patrick Mezard
|
r16175 | if getrenamed is not None and rev: | ||
Patrick Mezard
|
r10060 | copies = [] | ||
Matt Mackall
|
r9662 | for fn in ctx.files(): | ||
rename = getrenamed(fn, rev) | ||||
if rename: | ||||
copies.append((fn, rename[0])) | ||||
Mads Kiilerich
|
r11488 | revmatchfn = None | ||
if opts.get('patch') or opts.get('stat'): | ||||
Mads Kiilerich
|
r12382 | if opts.get('follow') or opts.get('follow_first'): | ||
# note: this might be wrong when following through merges | ||||
Matt Mackall
|
r14671 | revmatchfn = scmutil.match(repo[None], fns, default='path') | ||
Mads Kiilerich
|
r12382 | else: | ||
revmatchfn = matchfn | ||||
Mads Kiilerich
|
r11488 | |||
displayer.show(ctx, copies=copies, matchfn=revmatchfn) | ||||
Matt Mackall
|
r9662 | |||
Matt Mackall
|
r9665 | for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep): | ||
Benoit Boissinot
|
r9687 | if count == limit: | ||
break | ||||
if displayer.flush(ctx.rev()): | ||||
count += 1 | ||||
Robert Bachmann
|
r10152 | displayer.close() | ||
mpm@selenic.com
|
r255 | |||
Adrian Buehlmann
|
r14297 | @command('manifest', | ||
Adrian Buehlmann
|
r14399 | [('r', 'rev', '', _('revision to display'), _('REV')), | ||
('', 'all', False, _("list files from all revisions"))], | ||||
Adrian Buehlmann
|
r14297 | _('[-r REV]')) | ||
Adrian Buehlmann
|
r14399 | def manifest(ui, repo, node=None, rev=None, **opts): | ||
Thomas Arendsen Hein
|
r3914 | """output the current or given revision of the project manifest | ||
Benoit Boissinot
|
r1437 | |||
Print a list of version controlled files for the given revision. | ||||
Patrick Mezard
|
r8041 | If no revision is given, the first parent of the working directory | ||
timeless
|
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. | ||||
Matt Mackall
|
r11177 | |||
Adrian Buehlmann
|
r14399 | If option --all is specified, the list of all files from all revisions | ||
is printed. This includes deleted and renamed files. | ||||
Matt Mackall
|
r11177 | Returns 0 on success. | ||
Benoit Boissinot
|
r1437 | """ | ||
Adrian Buehlmann
|
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() | ||||
for f in sorted(res): | ||||
ui.write("%s\n" % f) | ||||
return | ||||
Matt Mackall
|
r3736 | |||
Bryan O'Sullivan
|
r5155 | if rev and node: | ||
raise util.Abort(_("please specify just one revision")) | ||||
if not node: | ||||
node = rev | ||||
Matt Mackall
|
r6749 | decor = {'l':'644 @ ', 'x':'755 * ', '':'644 '} | ||
Matt Mackall
|
r14319 | ctx = scmutil.revsingle(repo, node) | ||
Matt Mackall
|
r6749 | for f in ctx: | ||
Matt Mackall
|
r3736 | if ui.debugflag: | ||
Matt Mackall
|
r6749 | ui.write("%40s " % hex(ctx.manifest()[f])) | ||
Matt Mackall
|
r3736 | if ui.verbose: | ||
Matt Mackall
|
r6749 | ui.write(decor[ctx.flags(f)]) | ||
Matt Mackall
|
r3736 | ui.write("%s\n" % f) | ||
mpm@selenic.com
|
r255 | |||
Adrian Buehlmann
|
r14297 | @command('^merge', | ||
[('f', 'force', None, _('force a merge with outstanding changes')), | ||||
('r', 'rev', '', _('revision to merge'), _('REV')), | ||||
('P', 'preview', None, | ||||
Martin Geisler
|
r14852 | _('review revisions to merge (no merge is performed)')) | ||
] + mergetoolopts, | ||||
Adrian Buehlmann
|
r14297 | _('[-P] [-f] [[-r] REV]')) | ||
Dirkjan Ochtman
|
r8387 | def merge(ui, repo, node=None, **opts): | ||
Benoit Boissinot
|
r4014 | """merge working directory with another revision | ||
Vadim Gelfer
|
r2019 | |||
timeless
|
r8779 | The current working directory is updated with all changes made in | ||
the requested revision since the last common predecessor revision. | ||||
Martin Geisler
|
r7977 | |||
Files that changed between either parent are marked as changed for | ||||
the next commit and a commit must be performed before any further | ||||
timeless
|
r8779 | updates to the repository are allowed. The next commit will have | ||
two parents. | ||||
Vadim Gelfer
|
r2915 | |||
Steve Borho
|
r12750 | ``--tool`` can be used to specify the merge tool used for file | ||
merges. It overrides the HGMERGE environment variable and your | ||||
Arne Babenhauserheide
|
r13891 | configuration files. See :hg:`help merge-tools` for options. | ||
Steve Borho
|
r12750 | |||
Vadim Gelfer
|
r2915 | If no revision is specified, the working directory's parent is a | ||
Martin Geisler
|
r8004 | head revision, and the current branch contains exactly one other | ||
head, the other head is merged with by default. Otherwise, an | ||||
timeless
|
r8779 | explicit revision with which to merge with must be provided. | ||
Matt Mackall
|
r11177 | |||
Steve Borho
|
r12750 | :hg:`resolve` must be used to resolve unresolved files. | ||
Matt Mackall
|
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. | ||||
Matt Mackall
|
r11177 | Returns 0 on success, 1 if there are unresolved files. | ||
Vadim Gelfer
|
r2019 | """ | ||
Matt Mackall
|
r2806 | |||
Dirkjan Ochtman
|
r8387 | if opts.get('rev') and node: | ||
Daniel Holth
|
r4450 | raise util.Abort(_("please specify just one revision")) | ||
if not node: | ||||
Dirkjan Ochtman
|
r8387 | node = opts.get('rev') | ||
Daniel Holth
|
r4450 | |||
Matt Mackall
|
r3876 | if not node: | ||
Matt Mackall
|
r13047 | branch = repo[None].branch() | ||
Dirkjan Ochtman
|
r6844 | bheads = repo.branchheads(branch) | ||
Dirkjan Ochtman
|
r6723 | if len(bheads) > 2: | ||
Martin Geisler
|
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")) | ||||
Dirkjan Ochtman
|
r6723 | |||
Matt Mackall
|
r13878 | parent = repo.dirstate.p1() | ||
Dirkjan Ochtman
|
r6723 | if len(bheads) == 1: | ||
if len(repo.heads()) > 1: | ||||
Martin Geisler
|
r14198 | raise util.Abort(_("branch '%s' has one head - " | ||
"please merge with an explicit rev") | ||||
% branch, | ||||
hint=_("run 'hg heads' to see all heads")) | ||||
Kevin Bullock
|
r15619 | msg, hint = _('nothing to merge'), None | ||
Kevin Bullock
|
r15618 | if parent != repo.lookup(branch): | ||
Kevin Bullock
|
r15619 | hint = _("use 'hg update' instead") | ||
raise util.Abort(msg, hint=hint) | ||||
Benoit Boissinot
|
r5242 | |||
Dirkjan Ochtman
|
r6723 | if parent not in bheads: | ||
Martin Geisler
|
r14198 | raise util.Abort(_('working directory not at a head revision'), | ||
hint=_("use 'hg update' or merge with an " | ||||
"explicit revision")) | ||||
Dirkjan Ochtman
|
r6723 | node = parent == bheads[0] and bheads[-1] or bheads[0] | ||
Matt Mackall
|
r12925 | else: | ||
Matt Mackall
|
r14319 | node = scmutil.revsingle(repo, node).node() | ||
Dirkjan Ochtman
|
r8387 | |||
Dirkjan Ochtman
|
r8834 | if opts.get('preview'): | ||
Greg Ward
|
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]) | ||||
Dirkjan Ochtman
|
r8387 | displayer = cmdutil.show_changeset(ui, repo, opts) | ||
Greg Ward
|
r10505 | for node in nodes: | ||
displayer.show(repo[node]) | ||||
Robert Bachmann
|
r10152 | displayer.close() | ||
Dirkjan Ochtman
|
r8387 | return 0 | ||
Steve Borho
|
r12788 | try: | ||
# ui.forcemerge is an internal variable, do not document | ||||
Idan Kamara
|
r14840 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) | ||
Steve Borho
|
r12788 | return hg.merge(repo, node, force=opts.get('force')) | ||
finally: | ||||
ui.setconfig('ui', 'forcemerge', '') | ||||
Vadim Gelfer
|
r2029 | |||
Adrian Buehlmann
|
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]')) | ||||
Vadim Gelfer
|
r2494 | def outgoing(ui, repo, dest=None, **opts): | ||
timeless
|
r10376 | """show changesets not found in the destination | ||
Benoit Boissinot
|
r1437 | |||
Martin Geisler
|
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. | ||||
Benoit Boissinot
|
r1811 | |||
timeless
|
r10376 | See pull for details of valid destination formats. | ||
Matt Mackall
|
r11177 | |||
Returns 0 if there are outgoing changes, 1 otherwise. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r13366 | |||
if opts.get('bookmarks'): | ||||
dest = ui.expandpath(dest or 'default-push', dest or 'default') | ||||
dest, branches = hg.parseurl(dest, opts.get('branch')) | ||||
Matt Mackall
|
r14556 | other = hg.peer(repo, opts, dest) | ||
David Soria Parra
|
r13453 | if 'bookmarks' not in other.listkeys('namespaces'): | ||
ui.warn(_("remote doesn't support bookmarks\n")) | ||||
return 0 | ||||
Brodie Rao
|
r14076 | ui.status(_('comparing with %s\n') % util.hidepassword(dest)) | ||
Matt Mackall
|
r13366 | return bookmarks.diff(ui, other, repo) | ||
Martin Geisler
|
r14360 | repo._subtoppath = ui.expandpath(dest or 'default-push', dest or 'default') | ||
try: | ||||
Martin Geisler
|
r14362 | return hg.outgoing(ui, repo, dest, opts) | ||
Martin Geisler
|
r14360 | finally: | ||
del repo._subtoppath | ||||
mpm@selenic.com
|
r920 | |||
Adrian Buehlmann
|
r14297 | @command('parents', | ||
[('r', 'rev', '', _('show parents of the specified revision'), _('REV')), | ||||
] + templateopts, | ||||
_('[-r REV] [FILE]')) | ||||
Matt Mackall
|
r3658 | def parents(ui, repo, file_=None, **opts): | ||
Martin Geisler
|
r8026 | """show the parents of the working directory or revision | ||
Benoit Boissinot
|
r1437 | |||
Martin Geisler
|
r8004 | Print the working directory's parent revisions. If a revision is | ||
Martin Geisler
|
r8033 | given via -r/--rev, the parent of that revision will be printed. | ||
timeless
|
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. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r12925 | |||
Matt Mackall
|
r14319 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) | ||
Patrick Mezard
|
r5298 | |||
Brendan Cully
|
r4586 | if file_: | ||
Matt Mackall
|
r14671 | m = scmutil.match(ctx, (file_,), opts) | ||
Matt Mackall
|
r6582 | if m.anypats() or len(m.files()) != 1: | ||
timeless
|
r8761 | raise util.Abort(_('can only specify an explicit filename')) | ||
Matt Mackall
|
r6582 | file_ = m.files()[0] | ||
Patrick Mezard
|
r5298 | filenodes = [] | ||
for cp in ctx.parents(): | ||||
if not cp: | ||||
continue | ||||
try: | ||||
filenodes.append(cp.filenode(file_)) | ||||
Matt Mackall
|
r7633 | except error.LookupError: | ||
Patrick Mezard
|
r5298 | pass | ||
if not filenodes: | ||||
raise util.Abort(_("'%s' not found in manifest!") % file_) | ||||
fl = repo.file(file_) | ||||
Matt Mackall
|
r7361 | p = [repo.lookup(fl.linkrev(fl.rev(fn))) for fn in filenodes] | ||
mpm@selenic.com
|
r255 | else: | ||
Patrick Mezard
|
r5298 | p = [cp.node() for cp in ctx.parents()] | ||
mpm@selenic.com
|
r255 | |||
Matt Mackall
|
r3643 | displayer = cmdutil.show_changeset(ui, repo, opts) | ||
mpm@selenic.com
|
r255 | for n in p: | ||
mpm@selenic.com
|
r1092 | if n != nullid: | ||
Martin Geisler
|
r7743 | displayer.show(repo[n]) | ||
Robert Bachmann
|
r10152 | displayer.close() | ||
mpm@selenic.com
|
r255 | |||
Adrian Buehlmann
|
r14297 | @command('paths', [], _('[NAME]')) | ||
Thomas Arendsen Hein
|
r1858 | def paths(ui, repo, search=None): | ||
Bill Barry
|
r7691 | """show aliases for remote repositories | ||
Martin Geisler
|
r8004 | Show definition of symbolic path name NAME. If no name is given, | ||
timeless
|
r8779 | show definition of all available names. | ||
Martin Geisler
|
r7743 | |||
Thomas Arendsen Hein
|
r14331 | Option -q/--quiet suppresses all output when searching for NAME | ||
and shows only the path names when listing all definitions. | ||||
Brodie Rao
|
r12083 | Path names are defined in the [paths] section of your | ||
configuration file and in ``/etc/mercurial/hgrc``. If run inside a | ||||
Martin Geisler
|
r11009 | repository, ``.hg/hgrc`` is used, too. | ||
Bill Barry
|
r7693 | |||
Faheem Mitha
|
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 | ||||
Martin Geisler
|
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. | ||||
Faheem Mitha
|
r10933 | |||
Martin Geisler
|
r10973 | See :hg:`help urls` for more information. | ||
Nicolas Dumazet
|
r11507 | |||
Returns 0 on success. | ||||
Benoit Boissinot
|
r1437 | """ | ||
TK Soh
|
r779 | if search: | ||
for name, path in ui.configitems("paths"): | ||||
if name == search: | ||||
Thomas Arendsen Hein
|
r14331 | ui.status("%s\n" % util.hidepassword(path)) | ||
TK Soh
|
r779 | return | ||
Thomas Arendsen Hein
|
r14331 | if not ui.quiet: | ||
ui.warn(_("not found!\n")) | ||||
TK Soh
|
r779 | return 1 | ||
else: | ||||
for name, path in ui.configitems("paths"): | ||||
Thomas Arendsen Hein
|
r14331 | if ui.quiet: | ||
ui.write("%s\n" % name) | ||||
else: | ||||
ui.write("%s = %s\n" % (name, util.hidepassword(path))) | ||||
TK Soh
|
r779 | |||
Pierre-Yves David
|
r15830 | @command('^phase', | ||
Martin Geisler
|
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')), | ||||
Pierre-Yves David
|
r15830 | ('f', 'force', False, _('allow to move boundary backward')), | ||
Martin Geisler
|
r15855 | ('r', 'rev', [], _('target revision'), _('REV')), | ||
Pierre-Yves David
|
r15830 | ], | ||
Martin Geisler
|
r15854 | _('[-p|-d|-s] [-f] [-r] REV...')) | ||
Pierre-Yves David
|
r15830 | def phase(ui, repo, *revs, **opts): | ||
"""set or show the current phase name | ||||
With no argument, show the phase name of specified revisions. | ||||
Martin Geisler
|
r15851 | With one of -p/--public, -d/--draft or -s/--secret, change the | ||
Martin Geisler
|
r15850 | phase value of the specified revisions. | ||
Pierre-Yves David
|
r15830 | |||
Unless -f/--force is specified, :hg:`phase` won't move changeset from a | ||||
Martin Geisler
|
r15850 | lower phase to an higher phase. Phases are ordered as follows:: | ||
Matt Mackall
|
r15832 | |||
public < draft < secret | ||||
Pierre-Yves David
|
r15906 | |||
Patrick Mezard
|
r16097 | Return 0 on success, 1 if no phases were changed or some could not | ||
be changed. | ||||
Pierre-Yves David
|
r15830 | """ | ||
# search for a unique phase argument | ||||
targetphase = None | ||||
Martin Geisler
|
r15853 | for idx, name in enumerate(phases.phasenames): | ||
Pierre-Yves David
|
r15830 | if opts[name]: | ||
if targetphase is not None: | ||||
Matt Mackall
|
r15833 | raise util.Abort(_('only one phase can be specified')) | ||
Pierre-Yves David
|
r15830 | targetphase = idx | ||
# look for specified revision | ||||
revs = list(revs) | ||||
revs.extend(opts['rev']) | ||||
if not revs: | ||||
Idan Kamara
|
r15958 | raise util.Abort(_('no revisions specified')) | ||
Matt Mackall
|
r15831 | |||
Pierre-Yves David
|
r16024 | revs = scmutil.revrange(repo, revs) | ||
Pierre-Yves David
|
r15830 | lock = None | ||
Pierre-Yves David
|
r15906 | ret = 0 | ||
Pierre-Yves David
|
r15830 | if targetphase is None: | ||
# display | ||||
Pierre-Yves David
|
r16024 | for r in revs: | ||
ctx = repo[r] | ||||
Pierre-Yves David
|
r15830 | ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr())) | ||
else: | ||||
lock = repo.lock() | ||||
try: | ||||
# set phase | ||||
Pierre-Yves David
|
r16024 | nodes = [ctx.node() for ctx in repo.set('%ld', revs)] | ||
Pierre-Yves David
|
r15830 | if not nodes: | ||
raise util.Abort(_('empty revision set')) | ||||
Pierre-Yves David
|
r15906 | olddata = repo._phaserev[:] | ||
Martin Geisler
|
r15853 | phases.advanceboundary(repo, targetphase, nodes) | ||
Pierre-Yves David
|
r15830 | if opts['force']: | ||
Martin Geisler
|
r15853 | phases.retractboundary(repo, targetphase, nodes) | ||
Pierre-Yves David
|
r15830 | finally: | ||
lock.release() | ||||
Pierre-Yves David
|
r15906 | if olddata is not None: | ||
changes = 0 | ||||
newdata = repo._phaserev | ||||
changes = sum(o != newdata[i] for i, o in enumerate(olddata)) | ||||
Patrick Mezard
|
r16097 | rejected = [n for n in nodes | ||
if newdata[repo[n].rev()] < targetphase] | ||||
if rejected: | ||||
ui.warn(_('cannot move %i changesets to a more permissive ' | ||||
'phase, use --force\n') % len(rejected)) | ||||
ret = 1 | ||||
Pierre-Yves David
|
r15906 | if changes: | ||
Patrick Mezard
|
r16097 | msg = _('phase changed for %i changesets\n') % changes | ||
if ret: | ||||
ui.status(msg) | ||||
else: | ||||
ui.note(msg) | ||||
Pierre-Yves David
|
r15906 | else: | ||
ui.warn(_('no phases changed\n')) | ||||
ret = 1 | ||||
Pierre-Yves David
|
r15968 | return ret | ||
Pierre-Yves David
|
r15830 | |||
Alexis S. L. Carvalho
|
r5224 | def postincoming(ui, repo, modheads, optupdate, checkout): | ||
Vadim Gelfer
|
r2019 | if modheads == 0: | ||
Matt Mackall
|
r16107 | return | ||
Vadim Gelfer
|
r2019 | if optupdate: | ||
Matt Mackall
|
r16019 | movemarkfrom = repo['.'].node() | ||
Brendan Cully
|
r14485 | try: | ||
Matt Mackall
|
r16019 | ret = hg.update(repo, checkout) | ||
Brendan Cully
|
r14485 | except util.Abort, inst: | ||
Javi Merino
|
r16230 | ui.warn(_("not updating: %s\n") % str(inst)) | ||
Brendan Cully
|
r14485 | return 0 | ||
Matt Mackall
|
r16019 | if not ret and not checkout: | ||
if bookmarks.update(repo, [movemarkfrom], repo['.'].node()): | ||||
ui.status(_("updating bookmark %s\n") % repo._bookmarkcurrent) | ||||
return ret | ||||
Vadim Gelfer
|
r2019 | if modheads > 1: | ||
Kevin Berridge
|
r13804 | currentbranchheads = len(repo.branchheads()) | ||
if currentbranchheads == modheads: | ||||
Kevin Berridge
|
r13803 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) | ||
Kevin Berridge
|
r13804 | elif currentbranchheads > 1: | ||
ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to merge)\n")) | ||||
Vadim Gelfer
|
r2019 | else: | ||
Kevin Berridge
|
r13803 | ui.status(_("(run 'hg heads' to see heads)\n")) | ||
Vadim Gelfer
|
r2019 | else: | ||
ui.status(_("(run 'hg update' to get a working copy)\n")) | ||||
Vadim Gelfer
|
r2029 | |||
Adrian Buehlmann
|
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]')) | ||||
mpm@selenic.com
|
r404 | def pull(ui, repo, source="default", **opts): | ||
Benoit Boissinot
|
r1437 | """pull changes from the specified source | ||
timeless
|
r8779 | Pull changes from a remote repository to a local one. | ||
Benoit Boissinot
|
r1437 | |||
This finds all changes from the repository at the specified path | ||||
timeless
|
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. | ||||
Martin Geisler
|
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`. | ||||
Martin Geisler
|
r7980 | |||
Bill Barry
|
r7693 | If SOURCE is omitted, the 'default' path will be used. | ||
Martin Geisler
|
r10973 | See :hg:`help urls` for more information. | ||
Matt Mackall
|
r11177 | |||
Matt Mackall
|
r16107 | Returns 0 on success, 1 if an update had unresolved files. | ||
Benoit Boissinot
|
r1437 | """ | ||
Sune Foldager
|
r10379 | source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) | ||
Matt Mackall
|
r14556 | other = hg.peer(repo, opts, source) | ||
Brodie Rao
|
r14076 | ui.status(_('pulling from %s\n') % util.hidepassword(source)) | ||
Sune Foldager
|
r10365 | revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev')) | ||
Matt Mackall
|
r13368 | |||
if opts.get('bookmark'): | ||||
if not revs: | ||||
revs = [] | ||||
rb = other.listkeys('bookmarks') | ||||
for b in opts['bookmark']: | ||||
if b not in rb: | ||||
raise util.Abort(_('remote bookmark %s not found!') % b) | ||||
revs.append(rb[b]) | ||||
Matt Mackall
|
r4478 | if revs: | ||
Bryan O'Sullivan
|
r5259 | try: | ||
Matt Mackall
|
r4478 | revs = [other.lookup(rev) for rev in revs] | ||
Matt Mackall
|
r7637 | except error.CapabilityError: | ||
Martin Geisler
|
r12128 | err = _("other repository doesn't support revision lookup, " | ||
Matt Mackall
|
r7637 | "so a rev cannot be specified.") | ||
raise util.Abort(err) | ||||
Matt Mackall
|
r4478 | |||
Alexander Solovyov
|
r7131 | modheads = repo.pull(other, heads=revs, force=opts.get('force')) | ||
Matt Mackall
|
r15614 | bookmarks.updatefromremote(ui, repo, other, source) | ||
timeless@mozdev.org
|
r9645 | if checkout: | ||
checkout = str(repo.changelog.rev(other.lookup(checkout))) | ||||
Mads Kiilerich
|
r12852 | repo._subtoppath = source | ||
try: | ||||
Matt Mackall
|
r13368 | ret = postincoming(ui, repo, modheads, opts.get('update'), checkout) | ||
Mads Kiilerich
|
r12852 | finally: | ||
del repo._subtoppath | ||||
mpm@selenic.com
|
r246 | |||
Matt Mackall
|
r13368 | # update specified bookmarks | ||
if opts.get('bookmark'): | ||||
for b in opts['bookmark']: | ||||
# explicit pull overrides local bookmark if any | ||||
ui.status(_("importing bookmark %s\n") % b) | ||||
repo._bookmarks[b] = repo[rb[b]].node() | ||||
bookmarks.write(repo) | ||||
return ret | ||||
Adrian Buehlmann
|
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]')) | ||||
Vadim Gelfer
|
r2494 | def push(ui, repo, dest=None, **opts): | ||
Benoit Boissinot
|
r1437 | """push changes to the specified destination | ||
Faheem Mitha
|
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. | ||||
Martin Geisler
|
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. | ||||
Faheem Mitha
|
r11217 | Use -f/--force to override the default behavior and push all | ||
changesets on all branches. | ||||
If -r/--rev is used, the specified revision and all its ancestors | ||||
will be pushed to the remote repository. | ||||
Bill Barry
|
r7693 | |||
Martin Geisler
|
r10973 | Please see :hg:`help urls` for important details about ``ssh://`` | ||
Martin Geisler
|
r8004 | URLs. If DESTINATION is omitted, a default path will be used. | ||
Matt Mackall
|
r11177 | |||
Returns 0 if push was successful, 1 if nothing to push. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r13368 | |||
if opts.get('bookmark'): | ||||
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") | ||||
Sune Foldager
|
r10365 | dest = ui.expandpath(dest or 'default-push', dest or 'default') | ||
Sune Foldager
|
r10379 | dest, branches = hg.parseurl(dest, opts.get('branch')) | ||
Brodie Rao
|
r14076 | ui.status(_('pushing to %s\n') % util.hidepassword(dest)) | ||
Sune Foldager
|
r10365 | revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) | ||
Matt Mackall
|
r14556 | other = hg.peer(repo, opts, dest) | ||
Matt Mackall
|
r4478 | if revs: | ||
revs = [repo.lookup(rev) for rev in revs] | ||||
Matt Mackall
|
r8815 | |||
Mads Kiilerich
|
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): | ||||
Matt Mackall
|
r16022 | if c.sub(s).push(opts) == 0: | ||
Mads Kiilerich
|
r12852 | return False | ||
finally: | ||||
del repo._subtoppath | ||||
Matt Mackall
|
r13368 | result = repo.push(other, opts.get('force'), revs=revs, | ||
newbranch=opts.get('new_branch')) | ||||
Matt Mackall
|
r16023 | result = not result | ||
Matt Mackall
|
r13368 | |||
if opts.get('bookmark'): | ||||
rb = other.listkeys('bookmarks') | ||||
for b in opts['bookmark']: | ||||
# explicit push overrides remote bookmark if any | ||||
if b in repo._bookmarks: | ||||
ui.status(_("exporting bookmark %s\n") % b) | ||||
new = repo[b].hex() | ||||
elif b in rb: | ||||
ui.status(_("deleting remote bookmark %s\n") % b) | ||||
new = '' # delete | ||||
else: | ||||
ui.warn(_('bookmark %s does not exist on the local ' | ||||
'or remote repository!\n') % b) | ||||
return 2 | ||||
old = rb.get(b, '') | ||||
r = other.pushkey('bookmarks', b, old, new) | ||||
if not r: | ||||
ui.warn(_('updating bookmark %s failed!\n') % b) | ||||
if not result: | ||||
result = 2 | ||||
return result | ||||
mpm@selenic.com
|
r319 | |||
Adrian Buehlmann
|
r14297 | @command('recover', []) | ||
mpm@selenic.com
|
r245 | def recover(ui, repo): | ||
Benoit Boissinot
|
r1437 | """roll back an interrupted transaction | ||
Recover from an interrupted commit or pull. | ||||
Martin Geisler
|
r8004 | This command tries to fix the repository status after an | ||
interrupted operation. It should only be necessary when Mercurial | ||||
suggests it. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 if successful, 1 if nothing to recover or verify fails. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r1516 | if repo.recover(): | ||
Matt Mackall
|
r2778 | return hg.verify(repo) | ||
Thomas Arendsen Hein
|
r2057 | return 1 | ||
mpm@selenic.com
|
r245 | |||
Adrian Buehlmann
|
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, | ||||
_('[OPTION]... FILE...')) | ||||
Vadim Gelfer
|
r2179 | def remove(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """remove the specified files on the next commit | ||
Matt Mackall
|
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): | ||||
Matt Mackall
|
r15037 | |||
======= == == == == | ||||
A C M ! | ||||
======= == == == == | ||||
none W RD W R | ||||
-f R RD RD R | ||||
-A W W W R | ||||
-Af R R R R | ||||
======= == == == == | ||||
Vadim Gelfer
|
r2309 | |||
Matt Mackall
|
r15114 | Note that remove never deletes files in Added [A] state from the | ||
working directory, not even if option --force is specified. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success, 1 if any warnings encountered. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Dirkjan Ochtman
|
r6346 | |||
Matt Mackall
|
r11177 | ret = 0 | ||
Dirkjan Ochtman
|
r6346 | after, force = opts.get('after'), opts.get('force') | ||
if not pats and not after: | ||||
Vadim Gelfer
|
r2179 | raise util.Abort(_('no files specified')) | ||
Dirkjan Ochtman
|
r6346 | |||
Matt Mackall
|
r14671 | m = scmutil.match(repo[None], pats, opts) | ||
Matt Mackall
|
r6761 | s = repo.status(match=m, clean=True) | ||
modified, added, deleted, clean = s[0], s[1], s[3], s[6] | ||||
Benoit Boissinot
|
r8533 | for f in m.files(): | ||
if f not in repo.dirstate and not os.path.isdir(m.rel(f)): | ||||
Idan Kamara
|
r14604 | if os.path.exists(m.rel(f)): | ||
ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) | ||||
Matt Mackall
|
r11177 | ret = 1 | ||
Benoit Boissinot
|
r8533 | |||
Matt Mackall
|
r6761 | if force: | ||
Adrian Buehlmann
|
r14450 | list = modified + deleted + clean + added | ||
Matt Mackall
|
r6761 | elif after: | ||
Adrian Buehlmann
|
r14450 | list = deleted | ||
Brodie Rao
|
r12129 | for f in modified + added + clean: | ||
ui.warn(_('not removing %s: file still exists (use -f' | ||||
' to force removal)\n') % m.rel(f)) | ||||
ret = 1 | ||||
Matt Mackall
|
r6761 | else: | ||
Adrian Buehlmann
|
r14450 | list = deleted + clean | ||
Brodie Rao
|
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: | ||||
Matt Mackall
|
r15115 | ui.warn(_('not removing %s: file has been marked for add' | ||
' (use forget to undo)\n') % m.rel(f)) | ||||
Brodie Rao
|
r12129 | ret = 1 | ||
Matt Mackall
|
r6761 | |||
Adrian Buehlmann
|
r14450 | for f in sorted(list): | ||
Matt Mackall
|
r6761 | if ui.verbose or not m.exact(f): | ||
ui.status(_('removing %s\n') % m.rel(f)) | ||||
Dirkjan Ochtman
|
r6346 | |||
Adrian Buehlmann
|
r14450 | wlock = repo.wlock() | ||
try: | ||||
if not after: | ||||
for f in list: | ||||
if f in added: | ||||
continue # we never unlink added files on remove | ||||
try: | ||||
util.unlinkpath(repo.wjoin(f)) | ||||
except OSError, inst: | ||||
if inst.errno != errno.ENOENT: | ||||
raise | ||||
repo[None].forget(list) | ||||
finally: | ||||
wlock.release() | ||||
Matt Mackall
|
r11177 | return ret | ||
mpm@selenic.com
|
r245 | |||
Adrian Buehlmann
|
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')) | ||||
Bryan O'Sullivan
|
r1253 | def rename(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """rename files; equivalent of copy + remove | ||
Martin Geisler
|
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. | ||||
Benoit Boissinot
|
r1437 | |||
By default, this command copies the contents of files as they | ||||
Martin Geisler
|
r8033 | exist in the working directory. If invoked with -A/--after, the | ||
Benoit Boissinot
|
r1437 | operation is recorded, but no copying is performed. | ||
timeless
|
r7807 | This command takes effect at the next commit. To undo a rename | ||
Martin Geisler
|
r11193 | before that, see :hg:`revert`. | ||
Matt Mackall
|
r11177 | |||
Returns 0 on success, 1 if errors are encountered. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r4914 | wlock = repo.wlock(False) | ||
Matt Mackall
|
r4915 | try: | ||
Matt Mackall
|
r5610 | return cmdutil.copy(ui, repo, pats, opts, rename=True) | ||
Matt Mackall
|
r4915 | finally: | ||
Ronny Pfannschmidt
|
r8109 | wlock.release() | ||
Bryan O'Sullivan
|
r1253 | |||
Adrian Buehlmann
|
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'))] | ||||
Martin Geisler
|
r14852 | + mergetoolopts + walkopts, | ||
Adrian Buehlmann
|
r14297 | _('[OPTION]... [FILE]...')) | ||
Matt Mackall
|
r6518 | def resolve(ui, repo, *pats, **opts): | ||
Mark Edgington
|
r11836 | """redo merges or set/view the merge status of files | ||
Merges with unresolved conflicts are often the result of | ||||
Brodie Rao
|
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 | ||||
Augie Fackler
|
r16009 | working directory must have two parents). See :hg:`help | ||
merge-tools` for information on configuring merge tools. | ||||
Mark Edgington
|
r11836 | |||
The resolve command can be used in the following ways: | ||||
Mads Kiilerich
|
r12809 | - :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified | ||
Steve Borho
|
r12750 | files, discarding any previous merge attempts. Re-merging is not | ||
Mark Edgington
|
r11836 | performed for files already marked as resolved. Use ``--all/-a`` | ||
Pang Yan Han
|
r15042 | to select all unresolved files. ``--tool`` can be used to specify | ||
Steve Borho
|
r12750 | the merge tool used for the given files. It overrides the HGMERGE | ||
Pierre-Yves David
|
r15232 | environment variable and your configuration files. Previous file | ||
contents are saved with a ``.orig`` suffix. | ||||
Mark Edgington
|
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. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success, 1 if any files fail a resolve attempt. | ||||
Matt Mackall
|
r6518 | """ | ||
timeless
|
r9646 | all, mark, unmark, show, nostatus = \ | ||
[opts.get(o) for o in 'all mark unmark list no_status'.split()] | ||||
Matt Mackall
|
r7527 | |||
if (show and (mark or unmark)) or (mark and unmark): | ||||
Matt Mackall
|
r6518 | raise util.Abort(_("too many options specified")) | ||
Matt Mackall
|
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): | ||||
raise util.Abort(_('no files or directories specified; ' | ||||
'use --all to remerge all files')) | ||||
Matt Mackall
|
r6518 | |||
Martin Geisler
|
r15856 | ms = mergemod.mergestate(repo) | ||
Matt Mackall
|
r14671 | m = scmutil.match(repo[None], pats, opts) | ||
Matt Mackall
|
r11177 | ret = 0 | ||
Matt Mackall
|
r6518 | |||
for f in ms: | ||||
Matt Mackall
|
r6594 | if m(f): | ||
Matt Mackall
|
r7527 | if show: | ||
timeless
|
r9646 | if nostatus: | ||
ui.write("%s\n" % f) | ||||
else: | ||||
Brodie Rao
|
r10817 | ui.write("%s %s\n" % (ms[f].upper(), f), | ||
label='resolve.' + | ||||
{'u': 'unresolved', 'r': 'resolved'}[ms[f]]) | ||||
Matt Mackall
|
r7527 | elif mark: | ||
Matt Mackall
|
r6518 | ms.mark(f, "r") | ||
Matt Mackall
|
r7527 | elif unmark: | ||
Matt Mackall
|
r6518 | ms.mark(f, "u") | ||
else: | ||||
Matt Mackall
|
r6747 | wctx = repo[None] | ||
Matt Mackall
|
r6518 | mctx = wctx.parents()[-1] | ||
Matt Mackall
|
r7847 | |||
# backup pre-resolve (merge uses .orig for its own purposes) | ||||
a = repo.wjoin(f) | ||||
util.copyfile(a, a + ".resolve") | ||||
Steve Borho
|
r12788 | try: | ||
# resolve file | ||||
ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) | ||||
if ms.resolve(f, wctx, mctx): | ||||
ret = 1 | ||||
finally: | ||||
ui.setconfig('ui', 'forcemerge', '') | ||||
Matt Mackall
|
r6518 | |||
Matt Mackall
|
r7847 | # replace filemerge's .orig file with our resolve file | ||
util.rename(a + ".resolve", a + ".orig") | ||||
Peter Arrenbrecht
|
r12369 | |||
ms.commit() | ||||
Matt Mackall
|
r11177 | return ret | ||
Matt Mackall
|
r7847 | |||
Adrian Buehlmann
|
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')), | ||||
Adrian Buehlmann
|
r15009 | ('C', 'no-backup', None, _('do not save backup copies of files')), | ||
Adrian Buehlmann
|
r14297 | ] + walkopts + dryrunopts, | ||
_('[OPTION]... [-r REV] [NAME]...')) | ||||
Benoit Boissinot
|
r1472 | def revert(ui, repo, *pats, **opts): | ||
Matt Mackall
|
r14540 | """restore files to their checkout state | ||
Matt Mackall
|
r5574 | |||
Christian Ebert
|
r12390 | .. note:: | ||
Matt Mackall
|
r14541 | To check out earlier revisions, you should use :hg:`update REV`. | ||
To cancel a merge (and lose your changes), use :hg:`update --clean .`. | ||||
Vadim Gelfer
|
r2204 | |||
Matt Mackall
|
r14544 | With no revision specified, revert the specified files or directories | ||
Matt Mackall
|
r14903 | to the contents they had in the parent of the working directory. | ||
Matt Mackall
|
r14544 | This restores the contents of files to an unmodified | ||
Matt Mackall
|
r14903 | state and unschedules adds, removes, copies, and renames. If the | ||
working directory has two parents, you must explicitly specify a | ||||
revision. | ||||
Benoit Boissinot
|
r1811 | |||
Matt Mackall
|
r14544 | Using the -r/--rev or -d/--date options, revert the given files or | ||
Adrian Buehlmann
|
r14557 | directories to their states as of a specific revision. Because | ||
Matt Mackall
|
r14546 | revert does not change the working directory parents, this will | ||
cause these files to appear modified. This can be helpful to "back | ||||
Matt Mackall
|
r14547 | out" some or all of an earlier change. See :hg:`backout` for a | ||
related method. | ||||
Benoit Boissinot
|
r1437 | |||
Matt Mackall
|
r5574 | Modified files are saved with a .orig suffix before reverting. | ||
To disable these backups, use --no-backup. | ||||
Matt Mackall
|
r11177 | |||
Matt Mackall
|
r14544 | See :hg:`help dates` for a list of formats valid for -d/--date. | ||
Matt Mackall
|
r11177 | Returns 0 on success. | ||
Benoit Boissinot
|
r1437 | """ | ||
Vadim Gelfer
|
r2982 | |||
Xavier Snelgrove
|
r11941 | if opts.get("date"): | ||
if opts.get("rev"): | ||||
Matt Mackall
|
r3814 | raise util.Abort(_("you can't specify a revision and a date")) | ||
opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) | ||||
timeless
|
r13022 | parent, p2 = repo.dirstate.parents() | ||
Matt Mackall
|
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"')) | ||||
Adrian Buehlmann
|
r14726 | ctx = scmutil.revsingle(repo, opts.get('rev')) | ||
timeless
|
r13022 | |||
Alexander Solovyov
|
r7131 | if not pats and not opts.get('all'): | ||
Adrian Buehlmann
|
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") | ||||
Adrian Buehlmann
|
r14755 | raise util.Abort(msg, hint=hint) | ||
dirty = util.any(repo.status()) | ||||
Angel Ezquerra
|
r16304 | node = ctx.node() | ||
Adrian Buehlmann
|
r14755 | if node != parent: | ||
if dirty: | ||||
Adrian Buehlmann
|
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() | ||||
Adrian Buehlmann
|
r14755 | elif dirty: | ||
hint = _("uncommitted changes, use --all to discard all changes") | ||||
else: | ||||
hint = _("use --all to revert all files") | ||||
Adrian Buehlmann
|
r14721 | raise util.Abort(msg, hint=hint) | ||
Vadim Gelfer
|
r2982 | |||
Angel Ezquerra
|
r16304 | return cmdutil.revert(ui, repo, ctx, (parent, p2), *pats, **opts) | ||
mpm@selenic.com
|
r588 | |||
Greg Ward
|
r15183 | @command('rollback', dryrunopts + | ||
[('f', 'force', False, _('ignore safety measures'))]) | ||||
Steve Borho
|
r10882 | def rollback(ui, repo, **opts): | ||
Matt Mackall
|
r10889 | """roll back the last transaction (dangerous) | ||
Matt Mackall
|
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 | ||||
Matt Mackall
|
r8856 | any dirstate changes since that time. This command does not alter | ||
the working directory. | ||||
Vadim Gelfer
|
r2227 | |||
Transactions are used to encapsulate the effects of all commands | ||||
that create new changesets or propagate existing changesets into a | ||||
repository. For example, the following commands are transactional, | ||||
Martin Geisler
|
r9893 | and their effects can be rolled back: | ||
- commit | ||||
- import | ||||
- pull | ||||
timeless
|
r10376 | - push (with this repository as the destination) | ||
Martin Geisler
|
r9893 | - unbundle | ||
Vadim Gelfer
|
r2227 | |||
Matt Mackall
|
r15744 | 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. | ||||
Greg Ward
|
r15183 | |||
Vadim Gelfer
|
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. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success, 1 if no rollback data is available. | ||||
Vadim Gelfer
|
r2227 | """ | ||
Greg Ward
|
r15183 | return repo.rollback(dryrun=opts.get('dry_run'), | ||
force=opts.get('force')) | ||||
Vadim Gelfer
|
r2227 | |||
Adrian Buehlmann
|
r14297 | @command('root', []) | ||
mpm@selenic.com
|
r468 | def root(ui, repo): | ||
Martin Geisler
|
r8026 | """print the root (top) of the current working directory | ||
Benoit Boissinot
|
r1437 | |||
Print the root directory of the current repository. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success. | ||||
Benoit Boissinot
|
r1437 | """ | ||
mpm@selenic.com
|
r468 | ui.write(repo.root + "\n") | ||
Adrian Buehlmann
|
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')), | ||||
Idan Kamara
|
r14647 | ('', 'cmdserver', '', _('for remote clients'), _('MODE')), | ||
Adrian Buehlmann
|
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'))], | ||||
_('[OPTION]...')) | ||||
mpm@selenic.com
|
r245 | def serve(ui, repo, **opts): | ||
Matt Mackall
|
r10889 | """start stand-alone webserver | ||
Benoit Boissinot
|
r1437 | |||
Martin Geisler
|
r11102 | Start a local HTTP repository browser and pull server. You can use | ||
Adrian Buehlmann
|
r13065 | this for ad-hoc sharing and browsing of repositories. It is | ||
Martin Geisler
|
r11102 | recommended to use a real web server to serve a repository for | ||
longer periods of time. | ||||
Benoit Boissinot
|
r1437 | |||
Martin Geisler
|
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. | ||||
Benoit Boissinot
|
r1437 | By default, the server logs accesses to stdout and errors to | ||
Martin Geisler
|
r8277 | stderr. Use the -A/--accesslog and -E/--errorlog options to log to | ||
files. | ||||
Bryan O'Sullivan
|
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. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r624 | |||
Idan Kamara
|
r14647 | if opts["stdio"] and opts["cmdserver"]: | ||
raise util.Abort(_("cannot use --stdio with --cmdserver")) | ||||
def checkrepo(): | ||||
Thomas Arendsen Hein
|
r2127 | if repo is None: | ||
Matt Mackall
|
r7637 | raise error.RepoError(_("There is no Mercurial repository here" | ||
Joel Rosdahl
|
r6217 | " (.hg not found)")) | ||
Idan Kamara
|
r14647 | |||
if opts["stdio"]: | ||||
checkrepo() | ||||
Vadim Gelfer
|
r2396 | s = sshserver.sshserver(ui, repo) | ||
s.serve_forever() | ||||
Matt Mackall
|
r2363 | |||
Idan Kamara
|
r14647 | if opts["cmdserver"]: | ||
checkrepo() | ||||
s = commandserver.server(ui, repo, opts["cmdserver"]) | ||||
return s.serve() | ||||
Benoit Boissinot
|
r10635 | # this way we can check if something was given in the command-line | ||
if opts.get('port'): | ||||
Brodie Rao
|
r12076 | opts['port'] = util.getport(opts.get('port')) | ||
Benoit Boissinot
|
r10635 | |||
Matt Mackall
|
r8190 | baseui = repo and repo.baseui or ui | ||
Michele Cella
|
r5835 | optlist = ("name templates style address port prefix ipv6" | ||
Dirkjan Ochtman
|
r10644 | " accesslog errorlog certificate encoding") | ||
mpm@selenic.com
|
r987 | for o in optlist.split(): | ||
Benoit Boissinot
|
r10630 | val = opts.get(o, '') | ||
Thomas Arendsen Hein
|
r10631 | if val in (None, ''): # should check against default options instead | ||
Benoit Boissinot
|
r10630 | continue | ||
baseui.setconfig("web", o, val) | ||||
if repo and repo.ui != baseui: | ||||
repo.ui.setconfig("web", o, val) | ||||
mpm@selenic.com
|
r987 | |||
Matt Mackall
|
r11003 | o = opts.get('web_conf') or opts.get('webdir_conf') | ||
Matt Mackall
|
r11004 | if not o: | ||
if not repo: | ||||
raise error.RepoError(_("There is no Mercurial repository" | ||||
" here (.hg not found)")) | ||||
o = repo.root | ||||
app = hgweb.hgweb(o, baseui=ui) | ||||
Thomas Arendsen Hein
|
r2127 | |||
Benoit Boissinot
|
r8778 | class service(object): | ||
Bryan O'Sullivan
|
r4380 | def init(self): | ||
Adrian Buehlmann
|
r14237 | util.setsignalhandler() | ||
Matt Mackall
|
r11004 | self.httpd = hgweb.server.create_server(ui, app) | ||
Bryan O'Sullivan
|
r4380 | |||
Bryan O'Sullivan
|
r10629 | if opts['port'] and not ui.verbose: | ||
Matt Mackall
|
r10282 | return | ||
Bryan O'Sullivan
|
r4380 | |||
Michele Cella
|
r5970 | if self.httpd.prefix: | ||
prefix = self.httpd.prefix.strip('/') + '/' | ||||
else: | ||||
prefix = '' | ||||
Stephen Deasey
|
r6262 | port = ':%d' % self.httpd.port | ||
if port == ':80': | ||||
port = '' | ||||
Benoit Boissinot
|
r6419 | 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 | ||||
Bryan O'Sullivan
|
r10629 | if opts['port']: | ||
Benoit Boissinot
|
r10630 | write = ui.status | ||
Bryan O'Sullivan
|
r10629 | else: | ||
write = ui.write | ||||
write(_('listening at http://%s%s/%s (bound to %s:%d)\n') % | ||||
(fqaddr, port, prefix, bindaddr, self.httpd.port)) | ||||
Bryan O'Sullivan
|
r4380 | |||
def run(self): | ||||
self.httpd.serve_forever() | ||||
service = service() | ||||
cmdutil.service(opts, initfn=service.init, runfn=service.run) | ||||
mpm@selenic.com
|
r500 | |||
Sune Foldager
|
r14302 | @command('showconfig|debugconfig', | ||
[('u', 'untrusted', None, _('show untrusted configuration options'))], | ||||
_('[-u] [NAME]...')) | ||||
def showconfig(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. | ||||
With --debug, the source (filename and line number) is printed | ||||
for each config item. | ||||
Returns 0 on success. | ||||
""" | ||||
for f in scmutil.rcpath(): | ||||
David Soria Parra
|
r14708 | ui.debug('read config from: %s\n' % f) | ||
Sune Foldager
|
r14302 | 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)) | ||||
Adrian Buehlmann
|
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, | ||||
_('[OPTION]... [FILE]...')) | ||||
Bryan O'Sullivan
|
r731 | def status(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """show changed files in the working directory | ||
mpm@selenic.com
|
r213 | |||
Christian Ebert
|
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 | ||||
timeless
|
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. | ||||
Benoit Boissinot
|
r1437 | |||
Thomas Arendsen Hein
|
r6201 | Option -q/--quiet hides untracked (unknown and ignored) files | ||
Wagner Bruna
|
r8009 | unless explicitly requested with -u/--unknown or -i/--ignored. | ||
Zoran Bosnjak
|
r6200 | |||
Christian Ebert
|
r12390 | .. note:: | ||
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. | ||||
Matt Mackall
|
r3822 | |||
Brendan Cully
|
r3467 | If one revision is given, it is used as the base revision. | ||
timeless
|
r8779 | If two revisions are given, the differences between them are | ||
Gilles Moris
|
r10014 | shown. The --change option can also be used as a shortcut to list | ||
the changed files of a revision from its first parent. | ||||
Brendan Cully
|
r3467 | |||
Martin Geisler
|
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 | ||||
= origin of the previous file listed as A (added) | ||||
Matt Mackall
|
r11177 | |||
Matt Mackall
|
r15119 | .. container:: verbose | ||
Examples: | ||||
Martin Geisler
|
r15633 | - show changes in the working directory relative to a | ||
changeset:: | ||||
Matt Mackall
|
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 | ||||
Matt Mackall
|
r11177 | Returns 0 on success. | ||
Benoit Boissinot
|
r1437 | """ | ||
mpm@selenic.com
|
r312 | |||
Gilles Moris
|
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: | ||||
Patrick Mezard
|
r15578 | node2 = scmutil.revsingle(repo, change, None).node() | ||
Matt Mackall
|
r13878 | node1 = repo[node2].p1().node() | ||
Gilles Moris
|
r10014 | else: | ||
Matt Mackall
|
r14319 | node1, node2 = scmutil.revpair(repo, revs) | ||
Gilles Moris
|
r10014 | |||
Benoit Boissinot
|
r1625 | cwd = (pats and repo.getcwd()) or '' | ||
Alexander Solovyov
|
r7131 | end = opts.get('print0') and '\0' or '\n' | ||
Matt Mackall
|
r6276 | copy = {} | ||
Matt Mackall
|
r6605 | states = 'modified added removed deleted unknown ignored clean'.split() | ||
Alexander Solovyov
|
r7684 | show = [k for k in states if opts.get(k)] | ||
Alexander Solovyov
|
r7131 | if opts.get('all'): | ||
Matt Mackall
|
r6605 | show += ui.quiet and (states[:4] + ['clean']) or states | ||
if not show: | ||||
show = ui.quiet and states[:4] or states[:5] | ||||
Matt Mackall
|
r14671 | stat = repo.status(node1, node2, scmutil.match(repo[node2], pats, opts), | ||
Martin Geisler
|
r12166 | 'ignored' in show, 'clean' in show, 'unknown' in show, | ||
opts.get('subrepos')) | ||||
Matt Mackall
|
r6605 | changestates = zip(states, 'MAR!?IC', stat) | ||
Alexander Solovyov
|
r7131 | if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'): | ||
Matt Mackall
|
r15775 | copy = copies.pathcopies(repo[node1], repo[node2]) | ||
Matt Mackall
|
r6276 | |||
Matt Mackall
|
r16136 | fm = ui.formatter('status', opts) | ||
format = '%s %s' + end | ||||
if opts.get('no_status'): | ||||
format = '%.0s%s' + end | ||||
Matt Mackall
|
r6605 | for state, char, files in changestates: | ||
if state in show: | ||||
Matt Mackall
|
r16136 | label = 'status.' + state | ||
Matt Mackall
|
r6605 | for f in files: | ||
Matt Mackall
|
r16136 | fm.startitem() | ||
Matt Mackall
|
r16142 | fm.write("status path", format, char, | ||
Matt Mackall
|
r16136 | repo.pathto(f, cwd), label=label) | ||
Matt Mackall
|
r6605 | if f in copy: | ||
Matt Mackall
|
r16136 | fm.write("copy", ' %s' + end, repo.pathto(copy[f], cwd), | ||
Brodie Rao
|
r10817 | label='status.copied') | ||
Matt Mackall
|
r16136 | fm.end() | ||
mpm@selenic.com
|
r213 | |||
Adrian Buehlmann
|
r14297 | @command('^summary|sum', | ||
[('', 'remote', None, _('check for push and pull'))], '[--remote]') | ||||
Matt Mackall
|
r9620 | def summary(ui, repo, **opts): | ||
Matt Mackall
|
r9603 | """summarize working directory state | ||
This generates a brief summary of the working directory state, | ||||
including parents, branch, commit status, and available updates. | ||||
Matt Mackall
|
r9620 | |||
With the --remote option, this will check the default paths for | ||||
incoming and outgoing changes. This can be time-consuming. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success. | ||||
Matt Mackall
|
r9603 | """ | ||
ctx = repo[None] | ||||
parents = ctx.parents() | ||||
pnode = parents[0].node() | ||||
Augie Fackler
|
r14906 | marks = [] | ||
Matt Mackall
|
r9603 | |||
for p in parents: | ||||
Eric Eisner
|
r10832 | # label with log.changeset (instead of log.parent) since this | ||
# shows a working directory parent *changeset*: | ||||
ui.write(_('parent: %d:%s ') % (p.rev(), str(p)), | ||||
label='log.changeset') | ||||
Martin Geisler
|
r10833 | ui.write(' '.join(p.tags()), label='log.tag') | ||
David Soria Parra
|
r13454 | if p.bookmarks(): | ||
Augie Fackler
|
r14906 | marks.extend(p.bookmarks()) | ||
Matt Mackall
|
r9618 | if p.rev() == -1: | ||
if not len(repo): | ||||
Martin Geisler
|
r10834 | ui.write(_(' (empty repository)')) | ||
Matt Mackall
|
r9618 | else: | ||
Martin Geisler
|
r10834 | ui.write(_(' (no revision checked out)')) | ||
Eric Eisner
|
r10832 | ui.write('\n') | ||
Matt Mackall
|
r9618 | if p.description(): | ||
Eric Eisner
|
r10832 | ui.status(' ' + p.description().splitlines()[0].strip() + '\n', | ||
label='log.summary') | ||||
Matt Mackall
|
r9603 | |||
branch = ctx.branch() | ||||
bheads = repo.branchheads(branch) | ||||
Matt Mackall
|
r9873 | m = _('branch: %s\n') % branch | ||
if branch != 'default': | ||||
Eric Eisner
|
r10832 | ui.write(m, label='log.branch') | ||
Matt Mackall
|
r9873 | else: | ||
Eric Eisner
|
r10832 | ui.status(m, label='log.branch') | ||
Matt Mackall
|
r9603 | |||
Augie Fackler
|
r14906 | if marks: | ||
current = repo._bookmarkcurrent | ||||
Augie Fackler
|
r14907 | ui.write(_('bookmarks:'), label='log.bookmark') | ||
Augie Fackler
|
r14906 | if current is not None: | ||
try: | ||||
marks.remove(current) | ||||
Augie Fackler
|
r14907 | ui.write(' *' + current, label='bookmarks.current') | ||
Augie Fackler
|
r14906 | except ValueError: | ||
# current bookmark not in parent ctx marks | ||||
pass | ||||
Augie Fackler
|
r14907 | for m in marks: | ||
ui.write(' ' + m, label='log.bookmark') | ||||
ui.write('\n', label='log.bookmark') | ||||
Augie Fackler
|
r14906 | |||
Matt Mackall
|
r10390 | st = list(repo.status(unknown=True))[:6] | ||
Matt Mackall
|
r11088 | |||
Matt Mackall
|
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) | ||||
Martin Geisler
|
r15856 | ms = mergemod.mergestate(repo) | ||
Matt Mackall
|
r10390 | st.append([f for f in ms if ms[f] == 'u']) | ||
Matt Mackall
|
r11088 | |||
subs = [s for s in ctx.substate if ctx.sub(s).dirty()] | ||||
st.append(subs) | ||||
Eric Eisner
|
r10832 | labels = [ui.label(_('%d modified'), 'status.modified'), | ||
ui.label(_('%d added'), 'status.added'), | ||||
ui.label(_('%d removed'), 'status.removed'), | ||||
Matt Mackall
|
r11331 | ui.label(_('%d renamed'), 'status.copied'), | ||
ui.label(_('%d copied'), 'status.copied'), | ||||
Eric Eisner
|
r10832 | ui.label(_('%d deleted'), 'status.deleted'), | ||
ui.label(_('%d unknown'), 'status.unknown'), | ||||
ui.label(_('%d ignored'), 'status.ignored'), | ||||
Matt Mackall
|
r11088 | ui.label(_('%d unresolved'), 'resolve.unresolved'), | ||
ui.label(_('%d subrepos'), 'status.modified')] | ||||
Matt Mackall
|
r9603 | t = [] | ||
Matt Mackall
|
r10282 | for s, l in zip(st, labels): | ||
Martin Geisler
|
r9607 | if s: | ||
t.append(l % len(s)) | ||||
Matt Mackall
|
r9603 | |||
t = ', '.join(t) | ||||
FUJIWARA Katsunori
|
r10269 | cleanworkdir = False | ||
Matt Mackall
|
r9603 | |||
if len(parents) > 1: | ||||
Steve Borho
|
r11310 | t += _(' (merge)') | ||
Matt Mackall
|
r9603 | elif branch != parents[0].branch(): | ||
Steve Borho
|
r11310 | t += _(' (new branch)') | ||
Gilles Moris
|
r11165 | elif (parents[0].extra().get('close') and | ||
pnode in repo.branchheads(branch, closed=True)): | ||||
Steve Borho
|
r11310 | t += _(' (head closed)') | ||
Matt Mackall
|
r11331 | elif not (st[0] or st[1] or st[2] or st[3] or st[4] or st[9]): | ||
Steve Borho
|
r11310 | t += _(' (clean)') | ||
FUJIWARA Katsunori
|
r10269 | cleanworkdir = True | ||
Matt Mackall
|
r9603 | elif pnode not in bheads: | ||
Steve Borho
|
r11310 | t += _(' (new branch head)') | ||
Matt Mackall
|
r9603 | |||
FUJIWARA Katsunori
|
r10269 | if cleanworkdir: | ||
Steve Borho
|
r11310 | ui.status(_('commit: %s\n') % t.strip()) | ||
Matt Mackall
|
r9605 | else: | ||
Steve Borho
|
r11310 | ui.write(_('commit: %s\n') % t.strip()) | ||
Matt Mackall
|
r9603 | |||
# all ancestors of branch heads - all ancestors of parent = new csets | ||||
new = [0] * len(repo) | ||||
cl = repo.changelog | ||||
Matt Mackall
|
r10390 | for a in [cl.rev(n) for n in bheads]: | ||
new[a] = 1 | ||||
Matt Mackall
|
r9603 | for a in cl.ancestors(*[cl.rev(n) for n in bheads]): | ||
new[a] = 1 | ||||
Matt Mackall
|
r10390 | for a in [p.rev() for p in parents]: | ||
if a >= 0: | ||||
new[a] = 0 | ||||
Matt Mackall
|
r9603 | for a in cl.ancestors(*[p.rev() for p in parents]): | ||
new[a] = 0 | ||||
new = sum(new) | ||||
if new == 0: | ||||
Matt Mackall
|
r9605 | ui.status(_('update: (current)\n')) | ||
Matt Mackall
|
r9603 | elif pnode not in bheads: | ||
ui.write(_('update: %d new changesets (update)\n') % new) | ||||
else: | ||||
ui.write(_('update: %d new changesets, %d branch heads (merge)\n') % | ||||
(new, len(bheads))) | ||||
Matt Mackall
|
r9620 | if opts.get('remote'): | ||
t = [] | ||||
Sune Foldager
|
r10389 | source, branches = hg.parseurl(ui.expandpath('default')) | ||
Matt Mackall
|
r14556 | other = hg.peer(repo, {}, source) | ||
Sune Foldager
|
r10389 | revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev')) | ||
Brodie Rao
|
r14076 | ui.debug('comparing with %s\n' % util.hidepassword(source)) | ||
Matt Mackall
|
r9620 | repo.ui.pushbuffer() | ||
Peter Arrenbrecht
|
r14214 | commoninc = discovery.findcommonincoming(repo, other) | ||
_common, incoming, _rheads = commoninc | ||||
Matt Mackall
|
r9620 | repo.ui.popbuffer() | ||
if incoming: | ||||
t.append(_('1 or more incoming')) | ||||
Sune Foldager
|
r10389 | dest, branches = hg.parseurl(ui.expandpath('default-push', 'default')) | ||
revs, checkout = hg.addbranchrevs(repo, repo, branches, None) | ||||
Peter Arrenbrecht
|
r14214 | if source != dest: | ||
Matt Mackall
|
r14556 | other = hg.peer(repo, {}, dest) | ||
Peter Arrenbrecht
|
r14214 | commoninc = None | ||
ui.debug('comparing with %s\n' % util.hidepassword(dest)) | ||||
Matt Mackall
|
r9620 | repo.ui.pushbuffer() | ||
Pierre-Yves David
|
r15837 | outgoing = discovery.findcommonoutgoing(repo, other, | ||
commoninc=commoninc) | ||||
Matt Mackall
|
r9620 | repo.ui.popbuffer() | ||
Pierre-Yves David
|
r15837 | o = outgoing.missing | ||
Matt Mackall
|
r9620 | if o: | ||
t.append(_('%d outgoing') % len(o)) | ||||
David Soria Parra
|
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)) | ||||
Matt Mackall
|
r9620 | |||
if t: | ||||
ui.write(_('remote: %s\n') % (', '.join(t))) | ||||
else: | ||||
ui.status(_('remote: (synced)\n')) | ||||
Adrian Buehlmann
|
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 | ||||
('e', 'edit', None, _('edit commit message')), | ||||
('m', 'message', '', _('use <text> as commit message'), _('TEXT')), | ||||
] + commitopts2, | ||||
_('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')) | ||||
John Coomes
|
r6321 | def tag(ui, repo, name1, *names, **opts): | ||
"""add one or more tags for the current or given revision | ||||
Benoit Boissinot
|
r1437 | |||
Name a particular revision using <name>. | ||||
Tags are used to name particular revisions of the repository and are | ||||
Thomas Arendsen Hein
|
r6220 | very useful to compare different revisions, to go back to significant | ||
Kevin Bullock
|
r13135 | earlier versions or to mark branch points as releases, etc. Changing | ||
an existing tag is normally disallowed; use -f/--force to override. | ||||
Benoit Boissinot
|
r1437 | |||
Martin Geisler
|
r8004 | If no revision is given, the parent of the working directory is | ||
used, or tip if no revision is checked out. | ||||
Benoit Boissinot
|
r1437 | |||
To facilitate version control, distribution, and merging of tags, | ||||
Kevin Bullock
|
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. | ||||
Thomas Arendsen Hein
|
r6163 | |||
Martin Geisler
|
r10973 | See :hg:`help dates` for a list of formats valid for -d/--date. | ||
Nicolas Dumazet
|
r11063 | |||
Since tag names have priority over branch names during revision | ||||
lookup, using an existing branch name as a tag name is discouraged. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Mads Kiilerich
|
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')) | ||||
John Coomes
|
r6321 | for n in names: | ||
Mads Kiilerich
|
r15877 | if n in ['tip', '.', 'null']: | ||
raise util.Abort(_("the name '%s' is reserved") % n) | ||||
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() | ||||
Matt Mackall
|
r4213 | if not message: | ||
Martin Geisler
|
r9183 | # we don't translate commit messages | ||
Mads Kiilerich
|
r15877 | message = ('Added tag %s for changeset %s' % | ||
(', '.join(names), short(r))) | ||||
date = opts.get('date') | ||||
if date: | ||||
date = util.parsedate(date) | ||||
if opts.get('edit'): | ||||
message = ui.edit(message, ui.username()) | ||||
repo.tag(names, r, message, opts.get('local'), opts.get('user'), date) | ||||
finally: | ||||
release(lock, wlock) | ||||
mpm@selenic.com
|
r401 | |||
Adrian Buehlmann
|
r14297 | @command('tags', [], '') | ||
mpm@selenic.com
|
r248 | def tags(ui, repo): | ||
Benoit Boissinot
|
r1437 | """list repository tags | ||
Martin Geisler
|
r8004 | This lists both regular and local tags. When the -v/--verbose | ||
switch is used, a third column "local" is printed for local tags. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Thomas Arendsen Hein
|
r477 | |||
Matt Mackall
|
r2966 | hexfunc = ui.debugflag and hex or short | ||
Osku Salerma
|
r5658 | tagtype = "" | ||
Matt Mackall
|
r8210 | for t, n in reversed(repo.tagslist()): | ||
Osku Salerma
|
r5658 | if ui.quiet: | ||
Marc Simpson
|
r15047 | ui.write("%s\n" % t, label='tags.normal') | ||
Osku Salerma
|
r5658 | continue | ||
Idan Kamara
|
r13893 | hn = hexfunc(n) | ||
r = "%5d:%s" % (repo.changelog.rev(n), hn) | ||||
Marc Simpson
|
r15047 | rev = ui.label(r, 'log.changeset') | ||
Idan Kamara
|
r13893 | spaces = " " * (30 - encoding.colwidth(t)) | ||
Marc Simpson
|
r15047 | tag = ui.label(t, 'tags.normal') | ||
Idan Kamara
|
r13893 | if ui.verbose: | ||
if repo.tagtype(t) == 'local': | ||||
tagtype = " local" | ||||
Marc Simpson
|
r15047 | tag = ui.label(t, 'tags.local') | ||
Idan Kamara
|
r13893 | else: | ||
tagtype = "" | ||||
Marc Simpson
|
r15047 | ui.write("%s%s %s%s\n" % (tag, spaces, rev, tagtype)) | ||
mpm@selenic.com
|
r248 | |||
Adrian Buehlmann
|
r14297 | @command('tip', | ||
[('p', 'patch', None, _('show patch')), | ||||
('g', 'git', None, _('use git extended diff format')), | ||||
] + templateopts, | ||||
_('[-p] [-g]')) | ||||
Vadim Gelfer
|
r1731 | def tip(ui, repo, **opts): | ||
Benoit Boissinot
|
r1437 | """show the tip revision | ||
timeless
|
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). | ||||
Patrick Mezard
|
r6364 | |||
Patrick Mezard
|
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. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Robert Bachmann
|
r10152 | displayer = cmdutil.show_changeset(ui, repo, opts) | ||
displayer.show(repo[len(repo) - 1]) | ||||
displayer.close() | ||||
mpm@selenic.com
|
r245 | |||
Adrian Buehlmann
|
r14297 | @command('unbundle', | ||
[('u', 'update', None, | ||||
_('update to new branch head if changesets were unbundled'))], | ||||
_('[-u] FILE...')) | ||||
Giorgos Keramidas
|
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. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success, 1 if an update has unresolved files. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Giorgos Keramidas
|
r4699 | fnames = (fname1,) + fnames | ||
Patrick Mezard
|
r6180 | |||
Ronny Pfannschmidt
|
r8109 | lock = repo.lock() | ||
David Soria Parra
|
r13663 | wc = repo['.'] | ||
Patrick Mezard
|
r6180 | try: | ||
for fname in fnames: | ||||
Benoit Boissinot
|
r7271 | f = url.open(ui, fname) | ||
Patrick Mezard
|
r6180 | gen = changegroup.readbundle(f, fname) | ||
Pierre-Yves David
|
r15585 | modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname) | ||
David Soria Parra
|
r13663 | bookmarks.updatecurrentbookmark(repo, wc.node(), wc.branch()) | ||
Patrick Mezard
|
r6180 | finally: | ||
Ronny Pfannschmidt
|
r8109 | lock.release() | ||
Alexander Solovyov
|
r7131 | return postincoming(ui, repo, modheads, opts.get('update'), None) | ||
mpm@selenic.com
|
r1218 | |||
Adrian Buehlmann
|
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')), | ||||
('r', 'rev', '', _('revision'), _('REV'))], | ||||
_('[-c] [-C] [-d DATE] [[-r] REV]')) | ||||
Matt Mackall
|
r8855 | def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False): | ||
Matt Mackall
|
r10889 | """update working directory (or switch revisions) | ||
Benoit Boissinot
|
r1437 | |||
Martin Geisler
|
r8004 | Update the repository's working directory to the specified | ||
Kevin Bullock
|
r12688 | changeset. If no changeset is specified, update to the tip of the | ||
Kevin Bullock
|
r15957 | current named branch and move the current bookmark (see :hg:`help | ||
bookmarks`). | ||||
Kevin Bullock
|
r12688 | |||
If the changeset is not a descendant 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 | ||||
Stuart W Marks
|
r9718 | changeset. | ||
Adrian Buehlmann
|
r14725 | Update sets the working directory's parent revison to the specified | ||
changeset (see :hg:`help parents`). | ||||
Stuart W Marks
|
r9718 | The following rules apply when the working directory contains | ||
uncommitted changes: | ||||
Stuart W Marks
|
r9831 | 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 | ||||
Martin Geisler
|
r9740 | are preserved. | ||
Stuart W Marks
|
r9718 | |||
2. With the -c/--check option, the update is aborted and the | ||||
Martin Geisler
|
r9740 | uncommitted changes are preserved. | ||
Stuart W Marks
|
r9718 | |||
3. With the -C/--clean option, uncommitted changes are discarded and | ||||
Martin Geisler
|
r9740 | the working directory is updated to the requested changeset. | ||
Stuart W Marks
|
r9718 | |||
Martin Geisler
|
r10973 | Use null as the changeset to remove the working directory (like | ||
:hg:`clone -U`). | ||||
Adrian Buehlmann
|
r14729 | If you want to revert just one file to an older revision, use | ||
:hg:`revert [-r REV] NAME`. | ||||
Martin Geisler
|
r10973 | |||
See :hg:`help dates` for a list of formats valid for -d/--date. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success, 1 if there are unresolved files. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Daniel Holth
|
r4450 | if rev and node: | ||
raise util.Abort(_("please specify just one revision")) | ||||
Mark Drago
|
r13568 | if rev is None or rev == '': | ||
Daniel Holth
|
r4450 | rev = node | ||
Matt Mackall
|
r15935 | # with no argument, we also move the current bookmark, if any | ||
movemarkfrom = None | ||||
Idan Kamara
|
r16189 | if rev is None or node == '': | ||
Matt Mackall
|
r15935 | movemarkfrom = repo['.'].node() | ||
David Soria Parra
|
r13415 | # if we defined a bookmark, we have to remember the original bookmark name | ||
brev = rev | ||||
Matt Mackall
|
r14319 | rev = scmutil.revsingle(repo, rev, rev).rev() | ||
Augie Fackler
|
r12726 | |||
Stuart W Marks
|
r9450 | if check and clean: | ||
Martin Geisler
|
r9451 | raise util.Abort(_("cannot specify both -c/--check and -C/--clean")) | ||
Stuart W Marks
|
r9450 | |||
Matt Mackall
|
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) | ||||
Stuart W Marks
|
r9450 | if check: | ||
Matt Mackall
|
r8855 | c = repo[None] | ||
Patrick Mezard
|
r16491 | if c.dirty(merge=False, branch=False): | ||
Matt Mackall
|
r8855 | raise util.Abort(_("uncommitted local changes")) | ||
Patrick Mezard
|
r16490 | if rev is None: | ||
Matt Mackall
|
r16092 | rev = repo[repo[None].branch()].rev() | ||
Matt Mackall
|
r16095 | mergemod._checkunknown(repo, repo[None], repo[rev]) | ||
Matt Mackall
|
r16092 | |||
if clean: | ||||
Matt Mackall
|
r13367 | ret = hg.clean(repo, rev) | ||
Matt Mackall
|
r2808 | else: | ||
Matt Mackall
|
r13367 | ret = hg.update(repo, rev) | ||
Matt Mackall
|
r15935 | if not ret and movemarkfrom: | ||
Kevin Bullock
|
r16010 | if bookmarks.update(repo, [movemarkfrom], repo['.'].node()): | ||
ui.status(_("updating bookmark %s\n") % repo._bookmarkcurrent) | ||||
Matt Mackall
|
r15935 | elif brev in repo._bookmarks: | ||
David Soria Parra
|
r13415 | bookmarks.setcurrent(repo, brev) | ||
Idan Kamara
|
r16191 | elif brev: | ||
bookmarks.unsetcurrent(repo) | ||||
Matt Mackall
|
r13367 | |||
return ret | ||||
mpm@selenic.com
|
r254 | |||
Adrian Buehlmann
|
r14297 | @command('verify', []) | ||
mpm@selenic.com
|
r247 | def verify(ui, repo): | ||
Benoit Boissinot
|
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. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success, 1 if errors are encountered. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r2778 | return hg.verify(repo) | ||
mpm@selenic.com
|
r247 | |||
Adrian Buehlmann
|
r14297 | @command('version', []) | ||
Matt Mackall
|
r3651 | def version_(ui): | ||
"""output version and copyright information""" | ||||
ui.write(_("Mercurial Distributed SCM (version %s)\n") | ||||
Matt Mackall
|
r7632 | % util.version()) | ||
Matt Mackall
|
r3651 | ui.status(_( | ||
Matt Mackall
|
r12829 | "(see http://mercurial.selenic.com for more information)\n" | ||
Martin Geisler
|
r15834 | "\nCopyright (C) 2005-2012 Matt Mackall and others\n" | ||
Matt Mackall
|
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" | ||||
)) | ||||
Sune Foldager
|
r12131 | norepo = ("clone init version help debugcommands debugcomplete" | ||
Peter Arrenbrecht
|
r13723 | " debugdate debuginstall debugfsinfo debugpushkey debugwireargs" | ||
Peter Arrenbrecht
|
r13741 | " debugknown debuggetbundle debugbundle") | ||
Sune Foldager
|
r12131 | optionalrepo = ("identify paths serve showconfig debugancestor debugdag" | ||
Sune Foldager
|
r14323 | " debugdata debugindex debugindexdot debugrevlog") | ||