Show More
commands.py
5500 lines
| 197.5 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 | |||
Gregory Szorc
|
r28323 | from __future__ import absolute_import | ||
import difflib | ||||
import errno | ||||
import os | ||||
import re | ||||
Yuya Nishihara
|
r32567 | import sys | ||
Gregory Szorc
|
r28323 | |||
from .i18n import _ | ||||
from .node import ( | ||||
hex, | ||||
nullid, | ||||
nullrev, | ||||
short, | ||||
) | ||||
from . import ( | ||||
archival, | ||||
bookmarks, | ||||
bundle2, | ||||
changegroup, | ||||
cmdutil, | ||||
copies, | ||||
Yuya Nishihara
|
r32377 | debugcommands as debugcommandsmod, | ||
Gregory Szorc
|
r28323 | destutil, | ||
Augie Fackler
|
r30491 | dirstateguard, | ||
Gregory Szorc
|
r28323 | discovery, | ||
encoding, | ||||
error, | ||||
exchange, | ||||
extensions, | ||||
Yuya Nishihara
|
r32578 | formatter, | ||
Gregory Szorc
|
r28323 | graphmod, | ||
hbisect, | ||||
help, | ||||
hg, | ||||
lock as lockmod, | ||||
merge as mergemod, | ||||
obsolete, | ||||
patch, | ||||
phases, | ||||
Pulkit Goyal
|
r30304 | pycompat, | ||
Jun Wu
|
r31679 | rcutil, | ||
Yuya Nishihara
|
r32337 | registrar, | ||
Yuya Nishihara
|
r31024 | revsetlang, | ||
Gregory Szorc
|
r28323 | scmutil, | ||
Yuya Nishihara
|
r30506 | server, | ||
Gregory Szorc
|
r28323 | sshserver, | ||
streamclone, | ||||
Pierre-Yves David
|
r31670 | tags as tagsmod, | ||
Gregory Szorc
|
r28323 | templatekw, | ||
ui as uimod, | ||||
util, | ||||
) | ||||
release = lockmod.release | ||||
Matt Mackall
|
r2731 | |||
Adrian Buehlmann
|
r14297 | table = {} | ||
Yuya Nishihara
|
r32377 | table.update(debugcommandsmod.command._table) | ||
Adrian Buehlmann
|
r14297 | |||
Yuya Nishihara
|
r32337 | command = registrar.command(table) | ||
Adrian Buehlmann
|
r14297 | |||
Ryan McElroy
|
r25347 | # label constants | ||
# until 3.5, bookmarks.current was the advertised name, not | ||||
# bookmarks.active, so we must use both to avoid breaking old | ||||
# custom styles | ||||
activebookmarklabel = 'bookmarks.active bookmarks.current' | ||||
Adrian Buehlmann
|
r14297 | # common command options | ||
globalopts = [ | ||||
('R', 'repository', '', | ||||
_('repository root directory or name of overlay bundle file'), | ||||
_('REPO')), | ||||
('', 'cwd', '', | ||||
_('change working directory'), _('DIR')), | ||||
('y', 'noninteractive', None, | ||||
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')), | ||||
Pierre-Yves David
|
r31110 | ('', 'color', '', | ||
Pierre-Yves David
|
r31104 | # i18n: 'always', 'auto', 'never', and 'debug' are keywords | ||
# and should not be translated | ||||
Pierre-Yves David
|
r31123 | _("when to colorize (boolean, always, auto, never, or debug)"), | ||
Pierre-Yves David
|
r31104 | _('TYPE')), | ||
Adrian Buehlmann
|
r14297 | ('', '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')), | ||||
Pierre-Yves David
|
r18267 | ('', 'hidden', False, _('consider hidden changesets')), | ||
Augie Fackler
|
r30993 | ('', 'pager', 'auto', | ||
_("when to paginate (boolean, always, auto, or never)"), _('TYPE')), | ||||
Adrian Buehlmann
|
r14297 | ] | ||
Yuya Nishihara
|
r32375 | dryrunopts = cmdutil.dryrunopts | ||
remoteopts = cmdutil.remoteopts | ||||
walkopts = cmdutil.walkopts | ||||
commitopts = cmdutil.commitopts | ||||
commitopts2 = cmdutil.commitopts2 | ||||
formatteropts = cmdutil.formatteropts | ||||
templateopts = cmdutil.templateopts | ||||
logopts = cmdutil.logopts | ||||
diffopts = cmdutil.diffopts | ||||
diffwsopts = cmdutil.diffwsopts | ||||
diffopts2 = cmdutil.diffopts2 | ||||
mergetoolopts = cmdutil.mergetoolopts | ||||
similarityopts = cmdutil.similarityopts | ||||
subrepoopts = cmdutil.subrepoopts | ||||
debugrevlogopts = cmdutil.debugrevlogopts | ||||
Gregory Szorc
|
r27255 | |||
mpm@selenic.com
|
r255 | # Commands start here, listed alphabetically | ||
mpm@selenic.com
|
r209 | |||
Adrian Buehlmann
|
r14297 | @command('^add', | ||
walkopts + subrepoopts + dryrunopts, | ||||
Gregory Szorc
|
r21778 | _('[OPTION]... [FILE]...'), | ||
inferrepo=True) | ||||
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
|
r27424 | If no names are given, add all files to the repository (except | ||
files matching ``.hgignore``). | ||||
Martin Geisler
|
r10446 | |||
.. container:: verbose | ||||
Mathias De Maré
|
r27143 | Examples: | ||
- New (unknown) files are added | ||||
automatically by :hg:`add`:: | ||||
$ ls | ||||
foo.c | ||||
$ hg status | ||||
? foo.c | ||||
$ hg add | ||||
adding foo.c | ||||
$ hg status | ||||
A foo.c | ||||
- Specific files to be added can be specified:: | ||||
$ ls | ||||
bar.c foo.c | ||||
$ hg status | ||||
? bar.c | ||||
? foo.c | ||||
$ hg add bar.c | ||||
$ hg status | ||||
A bar.c | ||||
? foo.c | ||||
Nicolas Dumazet
|
r11507 | |||
Returns 0 if all files are successfully added. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Pulkit Goyal
|
r32147 | m = scmutil.match(repo[None], pats, pycompat.byteskwargs(opts)) | ||
Matt Harbison
|
r23885 | rejected = cmdutil.add(ui, repo, m, "", False, **opts) | ||
Martin Geisler
|
r12269 | return rejected and 1 or 0 | ||
mpm@selenic.com
|
r213 | |||
Adrian Buehlmann
|
r14297 | @command('addremove', | ||
Matt Harbison
|
r23538 | similarityopts + subrepoopts + walkopts + dryrunopts, | ||
Gregory Szorc
|
r21778 | _('[OPTION]... [FILE]...'), | ||
inferrepo=True) | ||||
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. | ||||
timeless
|
r27425 | Unless names are given, new files are ignored if they match any of | ||
the patterns in ``.hgignore``. As with add, these changes take | ||||
effect at the next commit. | ||||
Vadim Gelfer
|
r2958 | |||
Patrick Mezard
|
r17266 | Use the -s/--similarity option to detect renamed files. This | ||
Martin Geisler
|
r9249 | option takes a percentage between 0 (disabled) and 100 (files must | ||
Patrick Mezard
|
r17266 | be identical) as its parameter. With a parameter greater than 0, | ||
this compares every removed file with every added file and records | ||||
those similar enough as renames. Detecting renamed files this way | ||||
Arnab Bose
|
r11518 | can be expensive. After using this option, :hg:`status -C` can be | ||
Patrick Mezard
|
r17266 | used to check which files were identified as moved or renamed. If | ||
not specified, -s/--similarity defaults to 100 and only renames of | ||||
identical files are detected. | ||||
Matt Mackall
|
r11177 | |||
Mathias De Maré
|
r27144 | .. container:: verbose | ||
Examples: | ||||
- A number of files (bar.c and foo.c) are new, | ||||
while foobar.c has been removed (without using :hg:`remove`) | ||||
from the repository:: | ||||
$ ls | ||||
bar.c foo.c | ||||
$ hg status | ||||
! foobar.c | ||||
? bar.c | ||||
? foo.c | ||||
$ hg addremove | ||||
adding bar.c | ||||
adding foo.c | ||||
removing foobar.c | ||||
$ hg status | ||||
A bar.c | ||||
A foo.c | ||||
R foobar.c | ||||
- A file foobar.c was moved to foo.c without using :hg:`rename`. | ||||
Afterwards, it was edited slightly:: | ||||
$ ls | ||||
foo.c | ||||
$ hg status | ||||
! foobar.c | ||||
? foo.c | ||||
$ hg addremove --similarity 90 | ||||
removing foobar.c | ||||
adding foo.c | ||||
recording removal of foobar.c as rename to foo.c (94% similar) | ||||
$ hg status -C | ||||
A foo.c | ||||
foobar.c | ||||
R foobar.c | ||||
Matt Mackall
|
r11177 | Returns 0 if all files are successfully added. | ||
Benoit Boissinot
|
r1437 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Bryan O'Sullivan
|
r4966 | try: | ||
Dirkjan Ochtman
|
r11551 | sim = float(opts.get('similarity') or 100) | ||
Bryan O'Sullivan
|
r4966 | except ValueError: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('similarity must be a number')) | ||
Vadim Gelfer
|
r2958 | if sim < 0 or sim > 100: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('similarity must be between 0 and 100')) | ||
Matt Harbison
|
r23533 | matcher = scmutil.match(repo[None], pats, opts) | ||
Matt Harbison
|
r23537 | return scmutil.addremove(repo, matcher, "", 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')), | ||||
Siddharth Agarwal
|
r32486 | ('l', 'line-number', None, _('show line number at the first appearance')), | ||
('', 'skip', [], _('revision to not display (EXPERIMENTAL)'), _('REV')), | ||||
Yuya Nishihara
|
r22480 | ] + diffwsopts + walkopts + formatteropts, | ||
Gregory Szorc
|
r21778 | _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'), | ||
inferrepo=True) | ||||
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 | ||
timeless
|
r27426 | each line. | ||
Martin Geisler
|
r8004 | |||
timeless
|
r8779 | This command is useful for discovering when a change was made and | ||
by whom. | ||||
Benoit Boissinot
|
r1437 | |||
timeless
|
r27540 | If you include --file, --user, or --date, the revision number is | ||
suppressed unless you also include --number. | ||||
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 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Yuya Nishihara
|
r22266 | if not pats: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('at least one filename or pattern is required')) | ||
Yuya Nishihara
|
r22266 | |||
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 | |||
Yuya Nishihara
|
r24421 | ctx = scmutil.revsingle(repo, opts.get('rev')) | ||
Yuya Nishihara
|
r22480 | fm = ui.formatter('annotate', opts) | ||
Jordi Gutiérrez Hermoso
|
r24306 | if ui.quiet: | ||
datefunc = util.shortdate | ||||
else: | ||||
datefunc = util.datestr | ||||
Yuya Nishihara
|
r24421 | if ctx.rev() is None: | ||
def hexfn(node): | ||||
if node is None: | ||||
return None | ||||
else: | ||||
return fm.hexfunc(node) | ||||
if opts.get('changeset'): | ||||
# omit "+" suffix which is appended to node hex | ||||
def formatrev(rev): | ||||
if rev is None: | ||||
return '%d' % ctx.p1().rev() | ||||
else: | ||||
return '%d' % rev | ||||
else: | ||||
def formatrev(rev): | ||||
if rev is None: | ||||
return '%d+' % ctx.p1().rev() | ||||
else: | ||||
return '%d ' % rev | ||||
def formathex(hex): | ||||
if hex is None: | ||||
return '%s+' % fm.hexfunc(ctx.p1().node()) | ||||
else: | ||||
return '%s ' % hex | ||||
else: | ||||
hexfn = fm.hexfunc | ||||
formatrev = formathex = str | ||||
Ion Savin
|
r15631 | |||
Yuya Nishihara
|
r22479 | opmap = [('user', ' ', lambda x: x[0].user(), ui.shortuser), | ||
Yuya Nishihara
|
r24421 | ('number', ' ', lambda x: x[0].rev(), formatrev), | ||
('changeset', ' ', lambda x: hexfn(x[0].node()), formathex), | ||||
Yuya Nishihara
|
r22479 | ('date', ' ', lambda x: x[0].date(), util.cachefunc(datefunc)), | ||
('file', ' ', lambda x: x[0].path(), str), | ||||
('line_number', ':', lambda x: x[1], str), | ||||
Thomas Arendsen Hein
|
r4857 | ] | ||
Yuya Nishihara
|
r22480 | fieldnamemap = {'number': 'rev', 'changeset': 'node'} | ||
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')): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('at least one of -n/-c is required for -l')) | ||
Thomas Arendsen Hein
|
r4857 | |||
Augie Fackler
|
r31028 | ui.pager('annotate') | ||
Mathias De Maré
|
r29949 | if fm.isplain(): | ||
def makefunc(get, fmt): | ||||
return lambda x: fmt(get(x)) | ||||
else: | ||||
Yuya Nishihara
|
r22480 | def makefunc(get, fmt): | ||
return get | ||||
Yuya Nishihara
|
r22479 | funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap | ||
if opts.get(op)] | ||||
Thomas Arendsen Hein
|
r14358 | funcmap[0] = (funcmap[0][0], '') # no separator in front of first column | ||
Yuya Nishihara
|
r22480 | fields = ' '.join(fieldnamemap.get(op, op) for op, sep, get, fmt in opmap | ||
if opts.get(op)) | ||||
Thomas Arendsen Hein
|
r4857 | |||
Matt Mackall
|
r13697 | def bad(x, y): | ||
Pierre-Yves David
|
r26587 | raise error.Abort("%s: %s" % (x, y)) | ||
Matt Mackall
|
r13697 | |||
Matt Harbison
|
r25468 | m = scmutil.match(ctx, pats, opts, badfn=bad) | ||
Dirkjan Ochtman
|
r10369 | follow = not opts.get('no_follow') | ||
Siddharth Agarwal
|
r23455 | diffopts = patch.difffeatureopts(ui, opts, section='annotate', | ||
whitespace=True) | ||||
Siddharth Agarwal
|
r32486 | skiprevs = opts.get('skip') | ||
if skiprevs: | ||||
skiprevs = scmutil.revrange(repo, skiprevs) | ||||
Matt Mackall
|
r6764 | for abs in ctx.walk(m): | ||
fctx = ctx[abs] | ||||
Jun Wu
|
r32135 | if not opts.get('text') and fctx.isbinary(): | ||
Yuya Nishihara
|
r22480 | fm.plain(_("%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, | ||
Siddharth Agarwal
|
r32486 | skiprevs=skiprevs, diffopts=diffopts) | ||
Denis Laxalde
|
r29528 | if not lines: | ||
continue | ||||
Yuya Nishihara
|
r22477 | formats = [] | ||
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] | ||
Mathias De Maré
|
r29949 | if fm.isplain(): | ||
Denis Laxalde
|
r29528 | sizes = [encoding.colwidth(x) for x in l] | ||
ml = max(sizes) | ||||
formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes]) | ||||
Mathias De Maré
|
r29949 | else: | ||
formats.append(['%s' for x in l]) | ||||
Denis Laxalde
|
r29528 | pieces.append(l) | ||
Yuya Nishihara
|
r22477 | |||
for f, p, l in zip(zip(*formats), zip(*pieces), lines): | ||||
Yuya Nishihara
|
r22480 | fm.startitem() | ||
fm.write(fields, "".join(f), *p) | ||||
fm.write('line', ": %s", l[1]) | ||||
Yuya Nishihara
|
r22452 | |||
Denis Laxalde
|
r29528 | if not lines[-1][1].endswith('\n'): | ||
Yuya Nishihara
|
r22480 | fm.plain('\n') | ||
fm.end() | ||||
Ion Savin
|
r15829 | |||
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 | ||
timeless
|
r27427 | extension (to override, use -t/--type). | ||
David Wolever
|
r10650 | |||
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 | ''' | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Matt Mackall
|
r14319 | ctx = scmutil.revsingle(repo, opts.get('rev')) | ||
Brendan Cully
|
r5061 | if not ctx: | ||
Pierre-Yves David
|
r26587 | raise error.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: | ||
Pierre-Yves David
|
r26587 | raise error.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': | ||||
Pierre-Yves David
|
r26587 | raise error.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')), | ||||
Ruslan Sayfutdinov
|
r27890 | ('', 'commit', None, | ||
_('commit if no conflicts were encountered (DEPRECATED)')), | ||||
('', 'no-commit', None, _('do not commit')), | ||||
Matt Mackall
|
r15211 | ('', 'parent', '', | ||
_('parent to choose when backing out merge (DEPRECATED)'), _('REV')), | ||||
Adrian Buehlmann
|
r14297 | ('r', 'rev', '', _('revision to backout'), _('REV')), | ||
FUJIWARA Katsunori
|
r21712 | ('e', 'edit', False, _('invoke editor on commit messages')), | ||
Martin Geisler
|
r14852 | ] + mergetoolopts + walkopts + commitopts + commitopts2, | ||
Adrian Buehlmann
|
r14297 | _('[OPTION]... [-r] REV')) | ||
Ruslan Sayfutdinov
|
r27890 | 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 | ||
Ruslan Sayfutdinov
|
r27890 | current working directory. If no conflicts were encountered, | ||
it will be committed immediately. | ||||
Jonathan Nieder
|
r13340 | |||
Jonathan Nieder
|
r13473 | If REV is the parent of the working directory, then this new changeset | ||
Ruslan Sayfutdinov
|
r27890 | is committed automatically (unless --no-commit is specified). | ||
Jonathan Nieder
|
r13340 | |||
Matt Mackall
|
r15210 | .. note:: | ||
Simon Heimberg
|
r19997 | |||
timeless
|
r27476 | :hg:`backout` cannot be used to fix either an unwanted or | ||
timeless
|
r27471 | incorrect merge. | ||
Matt Mackall
|
r15210 | |||
Matt Mackall
|
r15209 | .. container:: verbose | ||
Mathias De Maré
|
r27118 | Examples: | ||
- Reverse the effect of the parent of the working directory. | ||||
This backout will be committed immediately:: | ||||
hg backout -r . | ||||
- Reverse the effect of previous bad revision 23:: | ||||
hg backout -r 23 | ||||
- Reverse the effect of previous bad revision 23 and | ||||
Ruslan Sayfutdinov
|
r27890 | leave changes uncommitted:: | ||
hg backout -r 23 --no-commit | ||||
hg commit -m "Backout revision 23" | ||||
Mathias De Maré
|
r27118 | |||
Matt Mackall
|
r15209 | 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 | |||
Mathias De Maré
|
r26476 | See :hg:`help revert` for a way to restore files to the state | ||
of another revision. | ||||
Yuya Nishihara
|
r20872 | Returns 0 on success, 1 if nothing to backout or there are unresolved | ||
files. | ||||
Thomas Arendsen Hein
|
r6163 | ''' | ||
FUJIWARA Katsunori
|
r27193 | wlock = lock = None | ||
try: | ||||
wlock = repo.wlock() | ||||
lock = repo.lock() | ||||
Ruslan Sayfutdinov
|
r27890 | return _dobackout(ui, repo, node, rev, **opts) | ||
FUJIWARA Katsunori
|
r27193 | finally: | ||
release(lock, wlock) | ||||
Ruslan Sayfutdinov
|
r27890 | def _dobackout(ui, repo, node=None, rev=None, **opts): | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Ruslan Sayfutdinov
|
r27890 | if opts.get('commit') and opts.get('no_commit'): | ||
raise error.Abort(_("cannot use --commit with --no-commit")) | ||||
Yuya Nishihara
|
r27954 | if opts.get('merge') and opts.get('no_commit'): | ||
raise error.Abort(_("cannot use --merge with --no-commit")) | ||||
Ruslan Sayfutdinov
|
r27890 | |||
Daniel Holth
|
r4450 | if rev and node: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("please specify just one revision")) | ||
Daniel Holth
|
r4450 | |||
if not rev: | ||||
rev = node | ||||
Vadim Gelfer
|
r2158 | |||
Thomas Arendsen Hein
|
r4726 | if not rev: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("please specify a revision to backout")) | ||
Thomas Arendsen Hein
|
r4726 | |||
Thomas Arendsen Hein
|
r6139 | date = opts.get('date') | ||
if date: | ||||
opts['date'] = util.parsedate(date) | ||||
Matt Mackall
|
r19476 | cmdutil.checkunfinished(repo) | ||
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() | ||
Mads Kiilerich
|
r22381 | if not repo.changelog.isancestor(node, op1): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot backout change that is not an ancestor')) | ||
Matt Mackall
|
r5568 | |||
Vadim Gelfer
|
r2614 | p1, p2 = repo.changelog.parents(node) | ||
if p1 == nullid: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot backout a change with no parents')) | ||
Vadim Gelfer
|
r2158 | if p2 != nullid: | ||
Alexander Solovyov
|
r7131 | if not opts.get('parent'): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot backout a merge changeset')) | ||
Vadim Gelfer
|
r2614 | p = repo.lookup(opts['parent']) | ||
if p not in (p1, p2): | ||||
Pierre-Yves David
|
r26587 | raise error.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'): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot use --parent on non-merge changeset')) | ||
Vadim Gelfer
|
r2614 | parent = p1 | ||
Matt Mackall
|
r5568 | |||
Matt Mackall
|
r6423 | # the backout should appear on the same branch | ||
Bryan O'Sullivan
|
r27709 | branch = repo.dirstate.branch() | ||
bheads = repo.branchheads(branch) | ||||
rctx = scmutil.revsingle(repo, hex(parent)) | ||||
if not opts.get('merge') and op1 != node: | ||||
Augie Fackler
|
r30491 | dsguard = dirstateguard.dirstateguard(repo, 'backout') | ||
Bryan O'Sullivan
|
r27709 | try: | ||
ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), | ||||
'backout') | ||||
stats = mergemod.update(repo, parent, True, True, node, False) | ||||
repo.setparents(op1, op2) | ||||
dsguard.close() | ||||
hg._showstats(repo, stats) | ||||
if stats[3]: | ||||
repo.ui.status(_("use 'hg resolve' to retry unresolved " | ||||
"file merges\n")) | ||||
return 1 | ||||
finally: | ||||
ui.setconfig('ui', 'forcemerge', '', '') | ||||
lockmod.release(dsguard) | ||||
else: | ||||
hg.clean(repo, node, show_stats=False) | ||||
repo.dirstate.setbranch(branch) | ||||
cmdutil.revert(ui, repo, rctx, repo.dirstate.parents()) | ||||
Ruslan Sayfutdinov
|
r27912 | if opts.get('no_commit'): | ||
msg = _("changeset %s backed out, " | ||||
"don't forget to commit.\n") | ||||
ui.status(msg % short(node)) | ||||
return 0 | ||||
Bryan O'Sullivan
|
r27709 | |||
def commitfunc(ui, repo, message, match, opts): | ||||
editform = 'backout' | ||||
Pulkit Goyal
|
r32192 | e = cmdutil.getcommiteditor(editform=editform, | ||
**pycompat.strkwargs(opts)) | ||||
Bryan O'Sullivan
|
r27709 | if not message: | ||
# we don't translate commit messages | ||||
message = "Backed out changeset %s" % short(node) | ||||
e = cmdutil.getcommiteditor(edit=True, editform=editform) | ||||
return repo.commit(message, opts.get('user'), opts.get('date'), | ||||
match, editor=e) | ||||
newnode = cmdutil.commit(ui, repo, commitfunc, [], opts) | ||||
if not newnode: | ||||
ui.status(_("nothing changed\n")) | ||||
return 1 | ||||
cmdutil.commitstatus(repo, newnode, branch, bheads) | ||||
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', ''), | ||||
'backout') | ||||
return hg.merge(repo, hex(repo.changelog.tip())) | ||||
finally: | ||||
ui.setconfig('ui', 'forcemerge', '', '') | ||||
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: | ||||
Santiago Pay=C3=A0 i Miralta
|
r20151 | - start a bisection with known bad revision 34, and good revision 12:: | ||
"Yann E. MORIN"
|
r15139 | |||
hg bisect --bad 34 | ||||
hg bisect --good 12 | ||||
- advance the current bisection by marking current revision as good or | ||||
bad:: | ||||
hg bisect --good | ||||
hg bisect --bad | ||||
Mads Kiilerich
|
r17424 | - mark the current revision, or a known revision, to be skipped (e.g. if | ||
"Yann E. MORIN"
|
r15139 | that revision is not usable because of another issue):: | ||
hg bisect --skip | ||||
hg bisect --skip 23 | ||||
FUJIWARA Katsunori
|
r19958 | - skip all revisions that do not touch directories ``foo`` or ``bar``:: | ||
Jordi Gutiérrez Hermoso
|
r17969 | |||
FUJIWARA Katsunori
|
r19959 | hg bisect --skip "!( file('path:foo') & file('path:bar') )" | ||
Jordi Gutiérrez Hermoso
|
r17969 | |||
"Yann E. MORIN"
|
r15139 | - forget the current bisection:: | ||
hg bisect --reset | ||||
- use 'make && make tests' to automatically find the first broken | ||||
revision:: | ||||
hg bisect --reset | ||||
hg bisect --bad 34 | ||||
hg bisect --good 12 | ||||
FUJIWARA Katsunori
|
r19959 | hg bisect --command "make && make tests" | ||
"Yann E. MORIN"
|
r15139 | |||
- 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)" | ||||
Martin Geisler
|
r20146 | - you can even get a nice graph:: | ||
"Yann E. MORIN"
|
r15139 | |||
hg log --graph -r "bisect(range)" | ||||
Martin von Zweigbergk
|
r30787 | See :hg:`help revisions.bisect` for more about the `bisect()` predicate. | ||
"Yann E. MORIN"
|
r15147 | |||
Matt Mackall
|
r11177 | Returns 0 on success. | ||
Matt Mackall
|
r5775 | """ | ||
Alexander Solovyov
|
r7227 | # 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: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('incompatible arguments')) | ||
Alexander Solovyov
|
r7227 | |||
if reset: | ||||
Pierre-Yves David
|
r30065 | hbisect.resetstate(repo) | ||
Alexander Solovyov
|
r7227 | return | ||
state = hbisect.load_state(repo) | ||||
Pierre-Yves David
|
r30122 | # update state | ||
if good or bad or skip: | ||||
if rev: | ||||
nodes = [repo.lookup(i) for i in scmutil.revrange(repo, [rev])] | ||||
else: | ||||
nodes = [repo.lookup('.')] | ||||
if good: | ||||
state['good'] += nodes | ||||
elif bad: | ||||
state['bad'] += nodes | ||||
elif skip: | ||||
state['skip'] += nodes | ||||
hbisect.save_state(repo, state) | ||||
Pierre-Yves David
|
r30124 | if not (state['good'] and state['bad']): | ||
return | ||||
Pierre-Yves David
|
r30122 | |||
Pierre-Yves David
|
r30127 | def mayupdate(repo, node, show_stats=True): | ||
"""common used update sequence""" | ||||
if noupdate: | ||||
return | ||||
Martin von Zweigbergk
|
r32131 | cmdutil.checkunfinished(repo) | ||
Pierre-Yves David
|
r30127 | cmdutil.bailifchanged(repo) | ||
return hg.clean(repo, node, show_stats=show_stats) | ||||
Pierre-Yves David
|
r30128 | displayer = cmdutil.show_changeset(ui, repo, {}) | ||
Alexander Solovyov
|
r7227 | if command: | ||
changesets = 1 | ||||
Mads Kiilerich
|
r20237 | if noupdate: | ||
try: | ||||
node = state['current'][0] | ||||
except LookupError: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('current bisect revision is unknown - ' | ||
Bryan O'Sullivan
|
r16647 | 'start a new bisect to fix')) | ||
Mads Kiilerich
|
r20237 | else: | ||
Bryan O'Sullivan
|
r16647 | node, p2 = repo.dirstate.parents() | ||
if p2 != nullid: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('current bisect revision is a merge')) | ||
Pierre-Yves David
|
r30134 | if rev: | ||
node = repo[scmutil.revsingle(repo, rev, node)].node() | ||||
Bryan O'Sullivan
|
r16647 | try: | ||
Benoit Boissinot
|
r7590 | while changesets: | ||
# update state | ||||
Bryan O'Sullivan
|
r16647 | state['current'] = [node] | ||
Bryan O'Sullivan
|
r16593 | hbisect.save_state(repo, state) | ||
Simon Farnsworth
|
r31200 | status = ui.system(command, environ={'HG_NODE': hex(node)}, | ||
blockedtag='bisect_check') | ||||
Benoit Boissinot
|
r7590 | if status == 125: | ||
transition = "skip" | ||||
elif status == 0: | ||||
transition = "good" | ||||
# status < 0 means process was killed | ||||
elif status == 127: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("failed to execute %s") % command) | ||
Benoit Boissinot
|
r7590 | elif status < 0: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("%s killed") % command) | ||
Benoit Boissinot
|
r7590 | else: | ||
transition = "bad" | ||||
Pierre-Yves David
|
r30134 | state[transition].append(node) | ||
ctx = repo[node] | ||||
Martin Geisler
|
r16936 | ui.status(_('changeset %d:%s: %s\n') % (ctx, ctx, transition)) | ||
Pierre-Yves David
|
r30126 | hbisect.checkstate(state) | ||
Benoit Boissinot
|
r7590 | # bisect | ||
Mads Kiilerich
|
r20052 | nodes, changesets, bgood = hbisect.bisect(repo.changelog, state) | ||
Benoit Boissinot
|
r7590 | # update to next check | ||
Bryan O'Sullivan
|
r16647 | node = nodes[0] | ||
Pierre-Yves David
|
r30127 | mayupdate(repo, node, show_stats=False) | ||
Benoit Boissinot
|
r7590 | finally: | ||
Bryan O'Sullivan
|
r16647 | state['current'] = [node] | ||
Benoit Boissinot
|
r7590 | hbisect.save_state(repo, state) | ||
Pierre-Yves David
|
r30067 | hbisect.printresult(ui, repo, state, displayer, nodes, bgood) | ||
Matt Mackall
|
r11177 | return | ||
Alexander Solovyov
|
r7227 | |||
Pierre-Yves David
|
r30126 | hbisect.checkstate(state) | ||
Alexander Solovyov
|
r7227 | |||
# actually bisect | ||||
nodes, changesets, good = hbisect.bisect(repo.changelog, state) | ||||
Benoit Boissinot
|
r13601 | if extend: | ||
if not changesets: | ||||
Pierre-Yves David
|
r30066 | extendnode = hbisect.extendrange(repo, state, nodes, good) | ||
Benoit Boissinot
|
r13601 | if extendnode is not None: | ||
FUJIWARA Katsunori
|
r20868 | ui.write(_("Extending search to changeset %d:%s\n") | ||
% (extendnode.rev(), extendnode)) | ||||
Bryan O'Sullivan
|
r16647 | state['current'] = [extendnode.node()] | ||
hbisect.save_state(repo, state) | ||||
Pierre-Yves David
|
r30127 | return mayupdate(repo, extendnode.node()) | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("nothing to extend")) | ||
Benoit Boissinot
|
r13601 | |||
Alexander Solovyov
|
r7227 | if changesets == 0: | ||
Pierre-Yves David
|
r30067 | hbisect.printresult(ui, repo, state, displayer, 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) | ||||
Pierre-Yves David
|
r30127 | return mayupdate(repo, node) | ||
Matt Mackall
|
r5775 | |||
Kevin Bullock
|
r18075 | @command('bookmarks|bookmark', | ||
Adrian Buehlmann
|
r14297 | [('f', 'force', False, _('force')), | ||
Nathan Goldbaum
|
r27950 | ('r', 'rev', '', _('revision for bookmark action'), _('REV')), | ||
Adrian Buehlmann
|
r14297 | ('d', 'delete', False, _('delete a given bookmark')), | ||
timeless@mozdev.org
|
r26190 | ('m', 'rename', '', _('rename a given bookmark'), _('OLD')), | ||
Yuya Nishihara
|
r22776 | ('i', 'inactive', False, _('mark a bookmark inactive')), | ||
] + formatteropts, | ||||
Kevin Bullock
|
r19147 | _('hg bookmarks [OPTIONS]... [NAME]...')) | ||
def bookmark(ui, repo, *names, **opts): | ||||
Matt Mackall
|
r21762 | '''create a new bookmark or list existing bookmarks | ||
Bookmarks are labels on changesets to help track lines of development. | ||||
Bookmarks are unversioned and can be moved, renamed and deleted. | ||||
Deleting or moving a bookmark has no effect on the associated changesets. | ||||
Creating or updating to a bookmark causes it to be marked as 'active'. | ||||
Kevin Bullock
|
r22314 | The active bookmark is indicated with a '*'. | ||
When a commit is made, the active bookmark will advance to the new commit. | ||||
Matt Mackall
|
r21762 | A plain :hg:`update` will also advance an active bookmark, if possible. | ||
Updating away from a bookmark will cause it to be deactivated. | ||||
Bookmarks can be pushed and pulled between repositories (see | ||||
:hg:`help push` and :hg:`help pull`). If a shared bookmark has | ||||
diverged, a new 'divergent bookmark' of the form 'name@path' will | ||||
FUJIWARA Katsunori
|
r23114 | be created. Using :hg:`merge` will resolve the divergence. | ||
Matt Mackall
|
r21762 | |||
A bookmark named '@' has the special property that :hg:`clone` will | ||||
check it out by default if it exists. | ||||
.. container:: verbose | ||||
Examples: | ||||
- create an active bookmark for a new line of development:: | ||||
hg book new-feature | ||||
- create an inactive bookmark as a place marker:: | ||||
hg book -i reviewed | ||||
- create an inactive bookmark on another changeset:: | ||||
hg book -r .^ tested | ||||
timeless@mozdev.org
|
r26190 | - rename bookmark turkey to dinner:: | ||
hg book -m turkey dinner | ||||
Matt Mackall
|
r21762 | - move the '@' bookmark from another branch:: | ||
hg book -f @ | ||||
Matt Mackall
|
r13368 | ''' | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Kevin Bullock
|
r19147 | force = opts.get('force') | ||
rev = opts.get('rev') | ||||
delete = opts.get('delete') | ||||
rename = opts.get('rename') | ||||
inactive = opts.get('inactive') | ||||
David Soria Parra
|
r17789 | def checkformat(mark): | ||
mark = mark.strip() | ||||
if not mark: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("bookmark names cannot consist entirely of " | ||
David Soria Parra
|
r17789 | "whitespace")) | ||
Kevin Bullock
|
r17821 | scmutil.checknewlabel(repo, mark, 'bookmark') | ||
David Soria Parra
|
r17789 | return mark | ||
Siddharth Agarwal
|
r20233 | def checkconflict(repo, mark, cur, force=False, target=None): | ||
David Soria Parra
|
r17789 | if mark in marks and not force: | ||
Kevin Bullock
|
r18773 | if target: | ||
Kevin Bullock
|
r18781 | if marks[mark] == target and target == cur: | ||
# re-activating a bookmark | ||||
return | ||||
Kevin Bullock
|
r18773 | anc = repo.changelog.ancestors([repo[target].rev()]) | ||
bmctx = repo[marks[mark]] | ||||
Sean Farley
|
r19109 | divs = [repo[b].node() for b in marks | ||
if b.split('@', 1)[0] == mark.split('@', 1)[0]] | ||||
Sean Farley
|
r19111 | |||
# allow resolving a single divergent bookmark even if moving | ||||
# the bookmark across branches when a revision is specified | ||||
# that contains a divergent bookmark | ||||
if bmctx.rev() not in anc and target in divs: | ||||
bookmarks.deletedivergent(repo, [target], mark) | ||||
return | ||||
Sean Farley
|
r19109 | deletefrom = [b for b in divs | ||
if repo[b].rev() in anc or b == target] | ||||
bookmarks.deletedivergent(repo, deletefrom, mark) | ||||
Sean Farley
|
r20282 | if bookmarks.validdest(repo, bmctx, repo[target]): | ||
Kevin Bullock
|
r18773 | ui.status(_("moving bookmark '%s' forward from %s\n") % | ||
(mark, short(bmctx.node()))) | ||||
return | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("bookmark '%s' already exists " | ||
David Soria Parra
|
r17789 | "(use -f to force)") % mark) | ||
if ((mark in repo.branchmap() or mark == repo.dirstate.branch()) | ||||
and not force): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort( | ||
David Soria Parra
|
r17789 | _("a bookmark cannot have the name of an existing branch")) | ||
Yuya Nishihara
|
r32482 | if len(mark) > 3 and not force: | ||
try: | ||||
shadowhash = (mark in repo) | ||||
except error.LookupError: # ambiguous identifier | ||||
shadowhash = False | ||||
if shadowhash: | ||||
repo.ui.warn( | ||||
_("bookmark %s matches a changeset hash\n" | ||||
"(did you leave a -r out of an 'hg bookmark' command?)\n") | ||||
% mark) | ||||
David Soria Parra
|
r17789 | |||
David Soria Parra
|
r17790 | if delete and rename: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("--delete and --rename are incompatible")) | ||
David Soria Parra
|
r17790 | if delete and rev: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("--rev is incompatible with --delete")) | ||
David Soria Parra
|
r17790 | if rename and rev: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("--rev is incompatible with --rename")) | ||
Kevin Bullock
|
r19147 | if not names and (delete or rev): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("bookmark name required")) | ||
David Soria Parra
|
r17790 | |||
Siddharth Agarwal
|
r20232 | if delete or rename or names or inactive: | ||
Pierre-Yves David
|
r25744 | wlock = lock = tr = None | ||
Siddharth Agarwal
|
r20232 | try: | ||
Pierre-Yves David
|
r25744 | wlock = repo.wlock() | ||
lock = repo.lock() | ||||
Siddharth Agarwal
|
r20234 | cur = repo.changectx('.').node() | ||
Siddharth Agarwal
|
r20232 | marks = repo._bookmarks | ||
if delete: | ||||
Pierre-Yves David
|
r25744 | tr = repo.transaction('bookmark') | ||
Siddharth Agarwal
|
r20232 | for mark in names: | ||
if mark not in marks: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("bookmark '%s' does not exist") % | ||
Siddharth Agarwal
|
r20232 | mark) | ||
Ryan McElroy
|
r24947 | if mark == repo._activebookmark: | ||
Ryan McElroy
|
r24944 | bookmarks.deactivate(repo) | ||
Siddharth Agarwal
|
r20232 | del marks[mark] | ||
elif rename: | ||||
Pierre-Yves David
|
r25744 | tr = repo.transaction('bookmark') | ||
Siddharth Agarwal
|
r20232 | if not names: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("new bookmark name required")) | ||
Siddharth Agarwal
|
r20232 | elif len(names) > 1: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("only one new bookmark name allowed")) | ||
Siddharth Agarwal
|
r20232 | mark = checkformat(names[0]) | ||
if rename not in marks: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("bookmark '%s' does not exist") | ||
% rename) | ||||
Siddharth Agarwal
|
r20233 | checkconflict(repo, mark, cur, force) | ||
Siddharth Agarwal
|
r20232 | marks[mark] = marks[rename] | ||
Ryan McElroy
|
r24947 | if repo._activebookmark == rename and not inactive: | ||
Ryan McElroy
|
r24945 | bookmarks.activate(repo, mark) | ||
Siddharth Agarwal
|
r20232 | del marks[rename] | ||
elif names: | ||||
Pierre-Yves David
|
r25744 | tr = repo.transaction('bookmark') | ||
Siddharth Agarwal
|
r20232 | newact = None | ||
for mark in names: | ||||
mark = checkformat(mark) | ||||
if newact is None: | ||||
newact = mark | ||||
Ryan McElroy
|
r24947 | if inactive and mark == repo._activebookmark: | ||
Ryan McElroy
|
r24944 | bookmarks.deactivate(repo) | ||
Siddharth Agarwal
|
r20232 | return | ||
tgt = cur | ||||
if rev: | ||||
tgt = scmutil.revsingle(repo, rev).node() | ||||
Siddharth Agarwal
|
r20233 | checkconflict(repo, mark, cur, force, tgt) | ||
Siddharth Agarwal
|
r20232 | marks[mark] = tgt | ||
if not inactive and cur == marks[newact] and not rev: | ||||
Ryan McElroy
|
r24945 | bookmarks.activate(repo, newact) | ||
Ryan McElroy
|
r24947 | elif cur != tgt and newact == repo._activebookmark: | ||
Ryan McElroy
|
r24944 | bookmarks.deactivate(repo) | ||
Siddharth Agarwal
|
r20232 | elif inactive: | ||
if len(marks) == 0: | ||||
ui.status(_("no bookmarks set\n")) | ||||
Ryan McElroy
|
r24947 | elif not repo._activebookmark: | ||
Siddharth Agarwal
|
r20232 | ui.status(_("no active bookmark\n")) | ||
else: | ||||
Ryan McElroy
|
r24944 | bookmarks.deactivate(repo) | ||
Pierre-Yves David
|
r25744 | if tr is not None: | ||
marks.recordchange(tr) | ||||
tr.close() | ||||
Siddharth Agarwal
|
r20232 | finally: | ||
Pierre-Yves David
|
r25744 | lockmod.release(tr, lock, wlock) | ||
Kevin Bullock
|
r17822 | else: # show bookmarks | ||
Yuya Nishihara
|
r22776 | fm = ui.formatter('bookmarks', opts) | ||
hexfn = fm.hexfunc | ||||
Siddharth Agarwal
|
r20232 | marks = repo._bookmarks | ||
Mathias De Maré
|
r29949 | if len(marks) == 0 and fm.isplain(): | ||
Siddharth Agarwal
|
r20231 | ui.status(_("no bookmarks set\n")) | ||
Yuya Nishihara
|
r22774 | for bmark, n in sorted(marks.iteritems()): | ||
Ryan McElroy
|
r25349 | active = repo._activebookmark | ||
if bmark == active: | ||||
Ryan McElroy
|
r25347 | prefix, label = '*', activebookmarklabel | ||
Yuya Nishihara
|
r22774 | else: | ||
prefix, label = ' ', '' | ||||
Yuya Nishihara
|
r22776 | fm.startitem() | ||
Yuya Nishihara
|
r22775 | if not ui.quiet: | ||
Yuya Nishihara
|
r22776 | fm.plain(' %s ' % prefix, label=label) | ||
fm.write('bookmark', '%s', bmark, label=label) | ||||
pad = " " * (25 - encoding.colwidth(bmark)) | ||||
fm.condwrite(not ui.quiet, 'rev node', pad + ' %d:%s', | ||||
repo.changelog.rev(n), hexfn(n), label=label) | ||||
Ryan McElroy
|
r25349 | fm.data(active=(bmark == active)) | ||
Yuya Nishihara
|
r22776 | fm.plain('\n') | ||
fm.end() | ||||
Matt Mackall
|
r13368 | |||
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:: | ||
Simon Heimberg
|
r19997 | |||
Matt Mackall
|
r15610 | Branch names are permanent and global. Use :hg:`bookmark` to create a | ||
light-weight bookmark instead. See :hg:`help glossary` for more | ||||
information about named branches and bookmarks. | ||||
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 | ||
Matt Mackall
|
r23620 | branch name that already exists. | ||
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 | ||
Matt Mackall
|
r25304 | :hg:`commit --close-branch` to mark this branch head as closed. | ||
timeless
|
r27428 | When all heads of a branch are closed, the branch will be | ||
Matt Mackall
|
r25304 | considered closed. | ||
Matt Mackall
|
r11177 | |||
Returns 0 on success. | ||||
Matt Mackall
|
r3502 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Yuya Nishihara
|
r19180 | if label: | ||
label = label.strip() | ||||
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 | ||
Bryan O'Sullivan
|
r27804 | with repo.wlock(): | ||
Idan Kamara
|
r16471 | 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: | ||||
Brodie Rao
|
r16719 | if not opts.get('force') and label in repo.branchmap(): | ||
Augie Fackler
|
r27167 | if label not in [p.branch() for p in repo[None].parents()]: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('a branch of the same name already' | ||
Idan Kamara
|
r16471 | ' exists'), | ||
# i18n: "it" refers to an existing branch | ||||
hint=_("use 'hg update' to switch to it")) | ||||
Tim Henigan
|
r17990 | scmutil.checknewlabel(repo, label, 'branch') | ||
Idan Kamara
|
r16471 | repo.dirstate.setbranch(label) | ||
ui.status(_('marked working directory as branch %s\n') % label) | ||||
Matt Mackall
|
r25295 | |||
# find any open named branches aside from default | ||||
others = [n for n, h, t, c in repo.branchmap().iterbranches() | ||||
if n != "default" and not c] | ||||
if not others: | ||||
ui.status(_('(branches are permanent and global, ' | ||||
'did you want a bookmark?)\n')) | ||||
Matt Mackall
|
r3502 | |||
Adrian Buehlmann
|
r14297 | @command('branches', | ||
Matt Mackall
|
r23620 | [('a', 'active', False, | ||
_('show only branches that have unmerged heads (DEPRECATED)')), | ||||
Yuya Nishihara
|
r22703 | ('c', 'closed', False, _('show normal and closed branches')), | ||
] + formatteropts, | ||||
FUJIWARA Katsunori
|
r28288 | _('[-c]')) | ||
Yuya Nishihara
|
r22703 | def branches(ui, repo, active=False, closed=False, **opts): | ||
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 | |||
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 | |||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Martin von Zweigbergk
|
r31386 | ui.pager('branches') | ||
Yuya Nishihara
|
r22703 | fm = ui.formatter('branches', opts) | ||
hexfunc = fm.hexfunc | ||||
Brodie Rao
|
r16721 | |||
Brodie Rao
|
r20182 | allheads = set(repo.heads()) | ||
Brodie Rao
|
r16721 | branches = [] | ||
Brodie Rao
|
r20192 | for tag, heads, tip, isclosed in repo.branchmap().iterbranches(): | ||
isactive = not isclosed and bool(set(heads) & allheads) | ||||
branches.append((tag, repo[tip], isactive, not isclosed)) | ||||
Brodie Rao
|
r20182 | branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]), | ||
Brodie Rao
|
r16721 | reverse=True) | ||
Brodie Rao
|
r20182 | for tag, ctx, isactive, isopen in branches: | ||
Yuya Nishihara
|
r22639 | if active and not isactive: | ||
continue | ||||
if isactive: | ||||
label = 'branches.active' | ||||
notice = '' | ||||
elif not isopen: | ||||
if not closed: | ||||
continue | ||||
label = 'branches.closed' | ||||
notice = _(' (closed)') | ||||
else: | ||||
label = 'branches.inactive' | ||||
notice = _(' (inactive)') | ||||
Yuya Nishihara
|
r22705 | current = (tag == repo.dirstate.branch()) | ||
if current: | ||||
Yuya Nishihara
|
r22639 | label = 'branches.current' | ||
Yuya Nishihara
|
r22703 | |||
fm.startitem() | ||||
fm.write('branch', '%s', tag, label=label) | ||||
Yuya Nishihara
|
r22702 | rev = ctx.rev() | ||
padsize = max(31 - len(str(rev)) - encoding.colwidth(tag), 0) | ||||
Yuya Nishihara
|
r22704 | fmt = ' ' * padsize + ' %d:%s' | ||
Yuya Nishihara
|
r22703 | fm.condwrite(not ui.quiet, 'rev node', fmt, rev, hexfunc(ctx.node()), | ||
label='log.changeset changeset.%s' % ctx.phasestr()) | ||||
Yuya Nishihara
|
r31173 | fm.context(ctx=ctx) | ||
Yuya Nishihara
|
r22705 | fm.data(active=isactive, closed=not isopen, current=current) | ||
Yuya Nishihara
|
r22703 | if not ui.quiet: | ||
fm.plain(notice) | ||||
fm.plain('\n') | ||||
fm.end() | ||||
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, | ||||
Gregory Szorc
|
r31794 | _('[-f] [-t BUNDLESPEC] [-a] [-r REV]... [--base REV]... FILE [DEST]')) | ||
Vadim Gelfer
|
r2494 | def bundle(ui, repo, fname, dest=None, **opts): | ||
Gregory Szorc
|
r31794 | """create a bundle file | ||
Generate a bundle file containing data to be added to a repository. | ||||
timeless
|
r27420 | |||
To create a bundle containing all changesets, use -a/--all | ||||
(or --base null). Otherwise, hg assumes the destination will have | ||||
all the nodes you specify with --base parameters. Otherwise, hg | ||||
will assume the repository has all the nodes in destination, or | ||||
default-push/default if no destination is specified. | ||||
Henrik Stuart
|
r8903 | |||
Gregory Szorc
|
r31794 | You can change bundle format with the -t/--type option. See | ||
:hg:`help bundlespec` for documentation on this format. By default, | ||||
the most appropriate format is used and compression defaults to | ||||
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 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Matt Mackall
|
r12925 | revs = None | ||
if 'rev' in opts: | ||||
Durham Goode
|
r27911 | revstrings = opts['rev'] | ||
revs = scmutil.revrange(repo, revstrings) | ||||
if revstrings and not revs: | ||||
raise error.Abort(_('no commits to bundle')) | ||||
Matt Mackall
|
r12925 | |||
Bryan O'Sullivan
|
r16427 | bundletype = opts.get('type', 'bzip2').lower() | ||
Gregory Szorc
|
r26640 | try: | ||
Gregory Szorc
|
r26759 | bcompression, cgversion, params = exchange.parsebundlespec( | ||
Gregory Szorc
|
r26640 | repo, bundletype, strict=False) | ||
except error.UnsupportedBundleSpecification as e: | ||||
raise error.Abort(str(e), | ||||
Gregory Szorc
|
r31794 | hint=_("see 'hg help bundlespec' for supported " | ||
timeless
|
r29971 | "values for --type")) | ||
Bryan O'Sullivan
|
r16427 | |||
Gregory Szorc
|
r26757 | # Packed bundles are a pseudo bundle format for now. | ||
if cgversion == 's1': | ||||
raise error.Abort(_('packed bundles cannot be produced by "hg bundle"'), | ||||
timeless
|
r28961 | hint=_("use 'hg debugcreatestreamclonebundle'")) | ||
Gregory Szorc
|
r26757 | |||
John Mulligan
|
r6171 | if opts.get('all'): | ||
timeless
|
r27422 | if dest: | ||
raise error.Abort(_("--all is incompatible with specifying " | ||||
"a destination")) | ||||
timeless
|
r27423 | if opts.get('base'): | ||
ui.warn(_("ignoring --base because --all was specified\n")) | ||||
John Mulligan
|
r6171 | base = ['null'] | ||
else: | ||||
Matt Mackall
|
r14319 | base = scmutil.revrange(repo, opts.get('base')) | ||
Martin von Zweigbergk
|
r28669 | if cgversion not in changegroup.supportedoutgoingversions(repo): | ||
raise error.Abort(_("repository does not support bundle version %s") % | ||||
cgversion) | ||||
Benoit Boissinot
|
r3284 | if base: | ||
if dest: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("--base is incompatible with specifying " | ||
Benoit Boissinot
|
r3284 | "a destination")) | ||
Peter Arrenbrecht
|
r14073 | common = [repo.lookup(rev) for rev in base] | ||
Ryan McElroy
|
r29901 | heads = revs and map(repo.lookup, revs) or None | ||
Pierre-Yves David
|
r29807 | outgoing = discovery.outgoing(repo, common, heads) | ||
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) | ||
FUJIWARA Katsunori
|
r18701 | revs, checkout = hg.addbranchrevs(repo, repo, 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, | ||||
Sune Foldager
|
r16736 | force=opts.get('force'), | ||
portable=True) | ||||
r32213 | ||||
if not outgoing.missing: | ||||
r32169 | scmutil.nochangesfound(ui, repo, not base and outgoing.excluded) | |||
Matt Mackall
|
r11177 | return 1 | ||
Benoit Boissinot
|
r10616 | |||
Pierre-Yves David
|
r26531 | if cgversion == '01': #bundle1 | ||
if bcompression is None: | ||||
bcompression = 'UN' | ||||
bversion = 'HG10' + bcompression | ||||
bcompression = None | ||||
Jun Wu
|
r31831 | elif cgversion in ('02', '03'): | ||
bversion = 'HG20' | ||||
Pierre-Yves David
|
r26531 | else: | ||
Jun Wu
|
r31831 | raise error.ProgrammingError( | ||
'bundle: unexpected changegroup version %s' % cgversion) | ||||
Pierre-Yves David
|
r26531 | |||
Gregory Szorc
|
r30758 | # TODO compression options should be derived from bundlespec parsing. | ||
# This is a temporary hack to allow adjusting bundle compression | ||||
# level without a) formalizing the bundlespec changes to declare it | ||||
# b) introducing a command flag. | ||||
compopts = {} | ||||
complevel = ui.configint('experimental', 'bundlecomplevel') | ||||
if complevel is not None: | ||||
compopts['level'] = complevel | ||||
r32216 | ||||
contentopts = {'cg.version': cgversion} | ||||
r32516 | if repo.ui.configbool('experimental', 'evolution.bundle-obsmarker', False): | |||
contentopts['obsolescence'] = True | ||||
r32216 | bundle2.writenewbundle(ui, repo, 'bundle', fname, bversion, outgoing, | |||
contentopts, compression=bcompression, | ||||
compopts=compopts) | ||||
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')), | ||||
Yuya Nishihara
|
r32578 | ] + walkopts + formatteropts, | ||
Gregory Szorc
|
r21778 | _('[OPTION]... FILE...'), | ||
inferrepo=True) | ||||
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 | ||
Matt Mackall
|
r19400 | no revision is given, the parent of the working directory is used. | ||
Benoit Boissinot
|
r1437 | |||
Output may be to a file, in which case the name of the file is | ||||
Matt Harbison
|
r21078 | given using a format string. The formatting rules as follows: | ||
:``%%``: literal "%" character | ||||
Martin Geisler
|
r9892 | :``%s``: basename of file being printed | ||
:``%d``: dirname of file being printed, or '.' if in repository root | ||||
:``%p``: root-relative path name of file being printed | ||||
Matt Harbison
|
r21078 | :``%H``: changeset hash (40 hexadecimal digits) | ||
:``%R``: changeset revision number | ||||
:``%h``: short-form changeset hash (12 hexadecimal digits) | ||||
:``%r``: zero-padded changeset revision number | ||||
:``%b``: basename of the exporting repository | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r14319 | ctx = scmutil.revsingle(repo, opts.get('rev')) | ||
Matt Mackall
|
r14671 | m = scmutil.match(ctx, (file1,) + pats, opts) | ||
Yuya Nishihara
|
r32540 | fntemplate = opts.pop('output', '') | ||
Yuya Nishihara
|
r32541 | if cmdutil.isstdiofilename(fntemplate): | ||
fntemplate = '' | ||||
Yuya Nishihara
|
r32578 | if fntemplate: | ||
fm = formatter.nullformatter(ui, 'cat') | ||||
else: | ||||
Yuya Nishihara
|
r32541 | ui.pager('cat') | ||
Yuya Nishihara
|
r32578 | fm = ui.formatter('cat', opts) | ||
with fm: | ||||
return cmdutil.cat(ui, repo, ctx, m, fm, fntemplate, '', **opts) | ||||
mpm@selenic.com
|
r248 | |||
Adrian Buehlmann
|
r14297 | @command('^clone', | ||
Yuya Nishihara
|
r24364 | [('U', 'noupdate', None, _('the clone will include an empty working ' | ||
'directory (only a repository)')), | ||||
timeless
|
r27292 | ('u', 'updaterev', '', _('revision, tag, or branch to check out'), | ||
_('REV')), | ||||
Adrian Buehlmann
|
r14297 | ('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, | ||||
Gregory Szorc
|
r21768 | _('[OPTION]... SOURCE [DEST]'), | ||
norepo=True) | ||||
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 | |||
timeless
|
r27669 | If the source repository has a bookmark called '@' set, that | ||
revision will be checked out in the new repository by default. | ||||
To check out a particular version, use -u/--update, or | ||||
-U/--noupdate to create a clone with no working directory. | ||||
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 | ||||
timeless
|
r27490 | --pull, even for local source repositories. | ||
.. note:: | ||||
Specifying a tag will include the tagged changeset but not the | ||||
changeset containing the tag. | ||||
Adrian Buehlmann
|
r9714 | |||
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 | ||||
Kevin Bullock
|
r18476 | g) the revision marked with the '@' bookmark, if present | ||
h) the tipmost head of the default branch | ||||
i) tip | ||||
Matt Mackall
|
r11177 | |||
Gregory Szorc
|
r27887 | When cloning from servers that support it, Mercurial may fetch | ||
pre-generated data from a server-advertised URL. When this is done, | ||||
hooks operating on incoming changesets and changegroups may fire twice, | ||||
once for the bundle fetched from the URL and another for any additional | ||||
data not fetched from this URL. In addition, if an error occurs, the | ||||
repository may be rolled back to a partial clone. This behavior may | ||||
change in future releases. See :hg:`help -e clonebundles` for more. | ||||
Matt Mackall
|
r15179 | Examples: | ||
- clone a remote repository to a new directory named hg/:: | ||||
FUJIWARA Katsunori
|
r30243 | hg clone https://www.mercurial-scm.org/repo/hg/ | ||
Matt Mackall
|
r15179 | |||
- 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:: | ||||
FUJIWARA Katsunori
|
r30243 | hg clone https://www.mercurial-scm.org/repo/hg/#stable | ||
Matt Mackall
|
r15179 | |||
Matt Mackall
|
r15175 | See :hg:`help urls` for details on specifying URLs. | ||
Matt Mackall
|
r11177 | Returns 0 on success. | ||
Benoit Boissinot
|
r1437 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Adrian Buehlmann
|
r9714 | if opts.get('noupdate') and opts.get('updaterev'): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("cannot specify both --noupdate and --updaterev")) | ||
Adrian Buehlmann
|
r9714 | |||
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'), | ||||
Gregory Szorc
|
r25761 | branch=opts.get('branch'), | ||
shareopts=opts.get('shareopts')) | ||||
Matt Mackall
|
r11177 | |||
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, | ||||
Matt Mackall
|
r25304 | _('mark a branch head as closed')), | ||
Yuya Nishihara
|
r24365 | ('', 'amend', None, _('amend the parent of the working directory')), | ||
Jordi Gutiérrez Hermoso
|
r19440 | ('s', 'secret', None, _('use the secret phase for committing')), | ||
FUJIWARA Katsunori
|
r21952 | ('e', 'edit', None, _('invoke editor on commit messages')), | ||
Laurent Charignon
|
r24278 | ('i', 'interactive', None, _('use interactive mode')), | ||
Martin Geisler
|
r15321 | ] + walkopts + commitopts + commitopts2 + subrepoopts, | ||
Gregory Szorc
|
r21778 | _('[OPTION]... [FILE]...'), | ||
inferrepo=True) | ||||
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 | |||
Matt Mackall
|
r25304 | The --close-branch flag can be used to mark the current branch | ||
head closed. When all heads of a branch are closed, the branch | ||||
will be considered closed and no longer listed. | ||||
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. | ||||
Augie Fackler
|
r27242 | |||
.. container:: verbose | ||||
Examples: | ||||
Yuya Nishihara
|
r27254 | - commit all files ending in .py:: | ||
Augie Fackler
|
r27242 | |||
Matt Harbison
|
r27247 | hg commit --include "set:**.py" | ||
Augie Fackler
|
r27242 | |||
Yuya Nishihara
|
r27254 | - commit all non-binary files:: | ||
Augie Fackler
|
r27242 | |||
Matt Harbison
|
r27247 | hg commit --exclude "set:binary()" | ||
Augie Fackler
|
r27242 | |||
Yuya Nishihara
|
r27254 | - amend the current commit and set the date to now:: | ||
Augie Fackler
|
r27242 | |||
hg commit --amend --date now | ||||
Benoit Boissinot
|
r1437 | """ | ||
FUJIWARA Katsunori
|
r27192 | wlock = lock = None | ||
try: | ||||
wlock = repo.wlock() | ||||
lock = repo.lock() | ||||
return _docommit(ui, repo, *pats, **opts) | ||||
finally: | ||||
release(lock, wlock) | ||||
def _docommit(ui, repo, *pats, **opts): | ||||
Pulkit Goyal
|
r32142 | if opts.get(r'interactive'): | ||
opts.pop(r'interactive') | ||||
Philippe Pepiot
|
r30157 | ret = cmdutil.dorecord(ui, repo, commit, None, False, | ||
Augie Fackler
|
r31534 | cmdutil.recordfilter, *pats, | ||
Pulkit Goyal
|
r32142 | **opts) | ||
Philippe Pepiot
|
r30157 | # ret can be 0 (no changes to record) or the value returned by | ||
# commit(), 1 if nothing changed or None on success. | ||||
return 1 if ret == 0 else ret | ||||
Laurent Charignon
|
r24278 | |||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Martin Geisler
|
r15321 | if opts.get('subrepos'): | ||
Matt Mackall
|
r19232 | if opts.get('amend'): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot amend with --subrepos')) | ||
timeless@mozdev.org
|
r17504 | # Let --subrepos on the command line override config setting. | ||
Mads Kiilerich
|
r20790 | ui.setconfig('ui', 'commitsubrepos', True, 'commit') | ||
Martin Geisler
|
r15321 | |||
Matt Mackall
|
r19496 | cmdutil.checkunfinished(repo, commit=True) | ||
Simon King
|
r19253 | |||
Iulian Stana
|
r19305 | branch = repo[None].branch() | ||
bheads = repo.branchheads(branch) | ||||
John Mulligan
|
r7655 | extra = {} | ||
if opts.get('close_branch'): | ||||
extra['close'] = 1 | ||||
Dirkjan Ochtman
|
r6336 | |||
Iulian Stana
|
r19305 | if not bheads: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('can only close branch heads')) | ||
Iulian Stana
|
r19305 | elif opts.get('amend'): | ||
Augie Fackler
|
r27167 | if repo[None].parents()[0].p1().branch() != branch and \ | ||
repo[None].parents()[0].p2().branch() != branch: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('can only close branch heads')) | ||
Matt Mackall
|
r11173 | |||
Idan Kamara
|
r16458 | if opts.get('amend'): | ||
Adrian Buehlmann
|
r16505 | if ui.configbool('ui', 'commitsubrepos'): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot amend with ui.commitsubrepos enabled')) | ||
Idan Kamara
|
r16458 | |||
old = repo['.'] | ||||
Augie Fackler
|
r22417 | if not old.mutable(): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot amend public changesets')) | ||
Idan Kamara
|
r16458 | if len(repo[None].parents()) > 1: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot amend while merging')) | ||
Durham Goode
|
r22952 | allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt) | ||
if not allowunstable and old.children(): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot amend changeset with children')) | ||
Idan Kamara
|
r16458 | |||
timeless
|
r28359 | # Currently histedit gets confused if an amend happens while histedit | ||
# is in progress. Since we have a checkunfinished command, we are | ||||
# temporarily honoring it. | ||||
# | ||||
# Note: eventually this guard will be removed. Please do not expect | ||||
# this behavior to remain. | ||||
if not obsolete.isenabled(repo, obsolete.createmarkersopt): | ||||
cmdutil.checkunfinished(repo) | ||||
FUJIWARA Katsunori
|
r20700 | # commitfunc is used only for temporary amend commit by cmdutil.amend | ||
Idan Kamara
|
r16458 | def commitfunc(ui, repo, message, match, opts): | ||
FUJIWARA Katsunori
|
r20700 | return repo.commit(message, | ||
opts.get('user') or old.user(), | ||||
opts.get('date') or old.date(), | ||||
match, | ||||
extra=extra) | ||||
Idan Kamara
|
r16458 | |||
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: | ||||
def commitfunc(ui, repo, message, match, opts): | ||||
Jun Wu
|
r31455 | overrides = {} | ||
if opts.get('secret'): | ||||
overrides[('phases', 'new-commit')] = 'secret' | ||||
Pierre-Yves David
|
r22039 | baseui = repo.baseui | ||
Jun Wu
|
r31455 | with baseui.configoverride(overrides, 'commit'): | ||
with ui.configoverride(overrides, 'commit'): | ||||
editform = cmdutil.mergeeditform(repo[None], | ||||
'commit.normal') | ||||
Augie Fackler
|
r31534 | editor = cmdutil.getcommiteditor( | ||
editform=editform, **pycompat.strkwargs(opts)) | ||||
Jun Wu
|
r31455 | return repo.commit(message, | ||
opts.get('user'), | ||||
opts.get('date'), | ||||
match, | ||||
editor=editor, | ||||
extra=extra) | ||||
Idan Kamara
|
r16458 | |||
node = cmdutil.commit(ui, repo, commitfunc, pats, opts) | ||||
if not node: | ||||
Matt Harbison
|
r27943 | stat = cmdutil.postcommitstatus(repo, pats, opts) | ||
Idan Kamara
|
r16458 | 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 | |||
Kevin Bullock
|
r18688 | cmdutil.commitstatus(repo, node, branch, bheads, opts) | ||
Gilles Moris
|
r6935 | |||
Matt Mackall
|
r20570 | @command('config|showconfig|debugconfig', | ||
Matt Mackall
|
r20572 | [('u', 'untrusted', None, _('show untrusted configuration options')), | ||
Matt Mackall
|
r20782 | ('e', 'edit', None, _('edit user config')), | ||
('l', 'local', None, _('edit repository config')), | ||||
Mathias De Maré
|
r29950 | ('g', 'global', None, _('edit global config'))] + formatteropts, | ||
Gregory Szorc
|
r21775 | _('[-u] [NAME]...'), | ||
optionalrepo=True) | ||||
Matt Mackall
|
r20570 | def config(ui, repo, *values, **opts): | ||
"""show combined config settings from all hgrc files | ||||
With no arguments, print names and values of all config items. | ||||
With one argument of the form section.name, print just the value | ||||
of that config item. | ||||
With multiple arguments, print names and values of all config | ||||
items with matching section names. | ||||
Matt Mackall
|
r20783 | With --edit, start an editor on the user-level config file. With | ||
--global, edit the system-wide config file. With --local, edit the | ||||
repository-level config file. | ||||
Matt Mackall
|
r20570 | With --debug, the source (filename and line number) is printed | ||
for each config item. | ||||
Matt Mackall
|
r20783 | See :hg:`help config` for more information about config files. | ||
Aaron Kushner
|
r22316 | Returns 0 on success, 1 if NAME does not exist. | ||
Matt Mackall
|
r20783 | |||
Matt Mackall
|
r20570 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Matt Mackall
|
r20782 | if opts.get('edit') or opts.get('local') or opts.get('global'): | ||
if opts.get('local') and opts.get('global'): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("can't use --local and --global together")) | ||
Matt Mackall
|
r20782 | |||
if opts.get('local'): | ||||
if not repo: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("can't use --local outside a repository")) | ||
Pierre-Yves David
|
r31321 | paths = [repo.vfs.join('hgrc')] | ||
Matt Mackall
|
r20782 | elif opts.get('global'): | ||
Jun Wu
|
r31679 | paths = rcutil.systemrcpath() | ||
Matt Mackall
|
r20782 | else: | ||
Jun Wu
|
r31679 | paths = rcutil.userrcpath() | ||
Matt Mackall
|
r20782 | |||
Matt Mackall
|
r20572 | for f in paths: | ||
if os.path.exists(f): | ||||
break | ||||
else: | ||||
Jordi Gutiérrez Hermoso
|
r22383 | if opts.get('global'): | ||
Jordi Gutiérrez Hermoso
|
r22837 | samplehgrc = uimod.samplehgrcs['global'] | ||
Jordi Gutiérrez Hermoso
|
r22383 | elif opts.get('local'): | ||
Jordi Gutiérrez Hermoso
|
r22837 | samplehgrc = uimod.samplehgrcs['local'] | ||
Jordi Gutiérrez Hermoso
|
r22383 | else: | ||
Jordi Gutiérrez Hermoso
|
r22837 | samplehgrc = uimod.samplehgrcs['user'] | ||
Jordi Gutiérrez Hermoso
|
r22383 | |||
Matt Mackall
|
r20572 | f = paths[0] | ||
Matt Mackall
|
r20573 | fp = open(f, "w") | ||
Jordi Gutiérrez Hermoso
|
r22383 | fp.write(samplehgrc) | ||
Matt Mackall
|
r20573 | fp.close() | ||
Matt Mackall
|
r20572 | editor = ui.geteditor() | ||
Yuya Nishihara
|
r23270 | ui.system("%s \"%s\"" % (editor, f), | ||
Simon Farnsworth
|
r31201 | onerr=error.Abort, errprefix=_("edit failed"), | ||
blockedtag='config_edit') | ||||
Matt Mackall
|
r20572 | return | ||
Augie Fackler
|
r31034 | ui.pager('config') | ||
Mathias De Maré
|
r29950 | fm = ui.formatter('config', opts) | ||
Jun Wu
|
r31683 | for t, f in rcutil.rccomponents(): | ||
if t == 'path': | ||||
ui.debug('read config from: %s\n' % f) | ||||
Jun Wu
|
r31685 | elif t == 'items': | ||
Jun Wu
|
r31686 | for section, name, value, source in f: | ||
ui.debug('set config by: %s\n' % source) | ||||
Jun Wu
|
r31683 | else: | ||
raise error.ProgrammingError('unknown rctype: %s' % t) | ||||
Matt Mackall
|
r20570 | 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: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('only one config item permitted')) | ||
Aaron Kushner
|
r22316 | matched = False | ||
Matt Mackall
|
r20570 | for section, name, value in ui.walkconfig(untrusted=untrusted): | ||
Yuya Nishihara
|
r30618 | source = ui.configsource(section, name, untrusted) | ||
Rishabh Madan
|
r31477 | value = pycompat.bytestr(value) | ||
Mathias De Maré
|
r29950 | if fm.isplain(): | ||
Yuya Nishihara
|
r30618 | source = source or 'none' | ||
Mathias De Maré
|
r29950 | value = value.replace('\n', '\\n') | ||
entryname = section + '.' + name | ||||
Matt Mackall
|
r20570 | if values: | ||
for v in values: | ||||
if v == section: | ||||
Mathias De Maré
|
r29950 | fm.startitem() | ||
Yuya Nishihara
|
r30618 | fm.condwrite(ui.debugflag, 'source', '%s: ', source) | ||
Mathias De Maré
|
r29950 | fm.write('name value', '%s=%s\n', entryname, value) | ||
Aaron Kushner
|
r22316 | matched = True | ||
Mathias De Maré
|
r29950 | elif v == entryname: | ||
fm.startitem() | ||||
Yuya Nishihara
|
r30618 | fm.condwrite(ui.debugflag, 'source', '%s: ', source) | ||
Mathias De Maré
|
r29950 | fm.write('value', '%s\n', value) | ||
fm.data(name=entryname) | ||||
Aaron Kushner
|
r22316 | matched = True | ||
Matt Mackall
|
r20570 | else: | ||
Mathias De Maré
|
r29950 | fm.startitem() | ||
Yuya Nishihara
|
r30618 | fm.condwrite(ui.debugflag, 'source', '%s: ', source) | ||
Mathias De Maré
|
r29950 | fm.write('name value', '%s=%s\n', entryname, value) | ||
Aaron Kushner
|
r22316 | matched = True | ||
Mathias De Maré
|
r29950 | fm.end() | ||
Aaron Kushner
|
r22316 | if matched: | ||
return 0 | ||||
return 1 | ||||
Matt Mackall
|
r20570 | |||
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 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Bryan O'Sullivan
|
r27805 | with repo.wlock(False): | ||
Matt Mackall
|
r5610 | return cmdutil.copy(ui, repo, pats, opts) | ||
mpm@selenic.com
|
r363 | |||
Yuya Nishihara
|
r32376 | @command('debugcommands', [], _('[COMMAND]'), norepo=True) | ||
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'), | ||||
norepo=True) | ||||
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, unused_allcmds = cmdutil.findpossible(cmd, table) | ||||
if ui.verbose: | ||||
cmdlist = [' '.join(c[0]) for c in cmdlist.values()] | ||||
ui.write("%s\n" % "\n".join(sorted(cmdlist))) | ||||
Adrian Buehlmann
|
r14297 | @command('^diff', | ||
[('r', 'rev', [], _('revision'), _('REV')), | ||||
('c', 'change', '', _('change made by revision'), _('REV')) | ||||
] + diffopts + diffopts2 + walkopts + subrepoopts, | ||||
Gregory Szorc
|
r21778 | _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...'), | ||
inferrepo=True) | ||||
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:: | ||
Simon Heimberg
|
r19997 | |||
timeless
|
r27476 | :hg:`diff` may generate unexpected results for merges, as it will | ||
Erik Zielke
|
r12389 | 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 | ||||
timeless
|
r27452 | to its first parent. | ||
Benoit Boissinot
|
r1437 | |||
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 | |||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
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') | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(msg) | ||
Stepan Koltsov
|
r7628 | 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 | ||
Siddharth Agarwal
|
r23456 | diffopts = patch.diffallopts(ui, opts) | ||
Matt Mackall
|
r14671 | m = scmutil.match(repo[node2], pats, opts) | ||
Augie Fackler
|
r31030 | ui.pager('diff') | ||
Martin Geisler
|
r12167 | cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, | ||
Siddharth Agarwal
|
r24432 | listsubrepos=opts.get('subrepos'), | ||
Sean Farley
|
r24455 | root=opts.get('root')) | ||
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, | ||||
Mads Kiilerich
|
r18956 | _('[OPTION]... [-o OUTFILESPEC] [-r] [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. | ||||
Mads Kiilerich
|
r18956 | If no revision is given, the parent of the working directory is used. | ||
Benoit Boissinot
|
r1437 | |||
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:: | ||
Simon Heimberg
|
r19997 | |||
timeless
|
r27476 | :hg:`export` may generate unexpected diff output for merge | ||
Christian Ebert
|
r12390 | 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 | """ | ||
Pulkit Goyal
|
r31826 | opts = pycompat.byteskwargs(opts) | ||
Alexander Solovyov
|
r10015 | changesets += tuple(opts.get('rev', [])) | ||
Mads Kiilerich
|
r18956 | if not changesets: | ||
changesets = ['.'] | ||||
Thomas Arendsen Hein
|
r16357 | revs = scmutil.revrange(repo, changesets) | ||
if not revs: | ||||
Pierre-Yves David
|
r26587 | raise error.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')) | ||||
Augie Fackler
|
r31031 | ui.pager('export') | ||
Augie Fackler
|
r32431 | cmdutil.export(repo, revs, fntemplate=opts.get('output'), | ||
Alexander Solovyov
|
r7131 | switch_parent=opts.get('switch_parent'), | ||
Siddharth Agarwal
|
r23690 | opts=patch.diffallopts(ui, opts)) | ||
mpm@selenic.com
|
r246 | |||
Matt Mackall
|
r22423 | @command('files', | ||
[('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), | ||||
('0', 'print0', None, _('end filenames with NUL, for use with xargs')), | ||||
Matt Harbison
|
r24413 | ] + walkopts + formatteropts + subrepoopts, | ||
liscju
|
r29849 | _('[OPTION]... [FILE]...')) | ||
Matt Mackall
|
r22423 | def files(ui, repo, *pats, **opts): | ||
"""list tracked files | ||||
Print files under Mercurial control in the working directory or | ||||
liscju
|
r29849 | specified revision for given files (excluding removed files). | ||
Files can be specified as filenames or filesets. | ||||
If no files are given to match, this command prints the names | ||||
of all files under Mercurial control. | ||||
Matt Mackall
|
r22423 | |||
.. container:: verbose | ||||
Examples: | ||||
- list all files under the current directory:: | ||||
hg files . | ||||
- shows sizes and flags for current revision:: | ||||
hg files -vr . | ||||
- list all files named README:: | ||||
hg files -I "**/README" | ||||
- list all binary files:: | ||||
hg files "set:binary()" | ||||
Wagner Bruna
|
r23074 | - find files containing a regular expression:: | ||
Matt Mackall
|
r22423 | |||
hg files "set:grep('bob')" | ||||
- search tracked file contents with xargs and grep:: | ||||
hg files -0 | xargs -0 grep foo | ||||
Matt Mackall
|
r23414 | See :hg:`help patterns` and :hg:`help filesets` for more information | ||
Matt Mackall
|
r22423 | on specifying file patterns. | ||
Returns 0 if a match is found, 1 otherwise. | ||||
""" | ||||
Pulkit Goyal
|
r32142 | |||
opts = pycompat.byteskwargs(opts) | ||||
ctx = scmutil.revsingle(repo, opts.get('rev'), None) | ||||
Matt Mackall
|
r22423 | |||
end = '\n' | ||||
if opts.get('print0'): | ||||
end = '\0' | ||||
fmt = '%s' + end | ||||
m = scmutil.match(ctx, pats, opts) | ||||
Augie Fackler
|
r31035 | ui.pager('files') | ||
Yuya Nishihara
|
r29882 | with ui.formatter('files', opts) as fm: | ||
return cmdutil.files(ui, ctx, m, fm, fmt, opts.get('subrepos')) | ||||
Matt Mackall
|
r22423 | |||
Gregory Szorc
|
r21778 | @command('^forget', walkopts, _('[OPTION]... FILE...'), inferrepo=True) | ||
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. | ||||
Nathan Goldbaum
|
r25714 | To delete the file from the working directory, see :hg:`remove`. | ||
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 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Steve Losh
|
r8902 | if not pats: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('no files specified')) | ||
Steve Losh
|
r8902 | |||
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', | ||||
Thomas Arendsen Hein
|
r16992 | [('r', 'rev', [], _('revisions to graft'), _('REV')), | ||
('c', 'continue', False, _('resume interrupted graft')), | ||||
Matt Mackall
|
r15241 | ('e', 'edit', False, _('invoke editor on commit messages')), | ||
Levi Bard
|
r16660 | ('', 'log', None, _('append graft info to log message')), | ||
Siddharth Agarwal
|
r21979 | ('f', 'force', False, _('force graft')), | ||
Matt Mackall
|
r15241 | ('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, | ||
Mads Kiilerich
|
r27898 | _('[OPTION]... [-r REV]... REV...')) | ||
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. | ||||
Levi Bard
|
r16660 | If --log is specified, log messages will have a comment appended | ||
of the form:: | ||||
(grafted from CHANGESETHASH) | ||||
Siddharth Agarwal
|
r21979 | If --force is specified, revisions will be grafted even if they | ||
are already ancestors of or have been grafted to the destination. | ||||
This is useful when the revisions have since been backed out. | ||||
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:: | ||||
Simon Heimberg
|
r19997 | |||
timeless
|
r27471 | The -c/--continue option does not reapply earlier options, except | ||
for --force. | ||||
Matt Mackall
|
r15241 | |||
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:: | ||||
Matt Mackall
|
r19401 | hg log --debug -r . | ||
Matt Mackall
|
r15242 | |||
timeless
|
r27664 | - show revisions sorted by date:: | ||
timeless
|
r28797 | hg log -r "sort(all(), date)" | ||
timeless
|
r27664 | |||
Martin von Zweigbergk
|
r30785 | See :hg:`help revisions` for more about specifying revisions. | ||
Alexander Becher
|
r21949 | |||
Matt Mackall
|
r15238 | Returns 0 on successful completion. | ||
''' | ||||
Bryan O'Sullivan
|
r27808 | with repo.wlock(): | ||
FUJIWARA Katsunori
|
r27194 | return _dograft(ui, repo, *revs, **opts) | ||
def _dograft(ui, repo, *revs, **opts): | ||||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Gábor Stefanik
|
r29632 | if revs and opts.get('rev'): | ||
Mads Kiilerich
|
r27899 | ui.warn(_('warning: inconsistent use of --rev might give unexpected ' | ||
'revision ordering!\n')) | ||||
Thomas Arendsen Hein
|
r16992 | revs = list(revs) | ||
Gábor Stefanik
|
r29632 | revs.extend(opts.get('rev')) | ||
Thomas Arendsen Hein
|
r16992 | |||
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() | ||||
Pulkit Goyal
|
r32192 | editor = cmdutil.getcommiteditor(editform='graft', | ||
**pycompat.strkwargs(opts)) | ||||
Matt Mackall
|
r15239 | |||
Matt Mackall
|
r15241 | cont = False | ||
Gábor Stefanik
|
r29632 | if opts.get('continue'): | ||
Matt Mackall
|
r15241 | cont = True | ||
if revs: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("can't specify --continue and revisions")) | ||
Matt Mackall
|
r15241 | # read in unfinished revisions | ||
try: | ||||
Angel Ezquerra
|
r23877 | nodes = repo.vfs.read('graftstate').splitlines() | ||
Matt Mackall
|
r15241 | revs = [repo[node].rev() for node in nodes] | ||
Gregory Szorc
|
r25660 | except IOError as inst: | ||
Matt Mackall
|
r15241 | if inst.errno != errno.ENOENT: | ||
raise | ||||
timeless
|
r28121 | cmdutil.wrongtooltocontinue(repo, _('graft')) | ||
Matt Mackall
|
r15241 | else: | ||
Matt Mackall
|
r19476 | cmdutil.checkunfinished(repo) | ||
Matt Mackall
|
r15241 | cmdutil.bailifchanged(repo) | ||
if not revs: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('no revisions specified')) | ||
Matt Mackall
|
r15241 | revs = scmutil.revrange(repo, revs) | ||
Matt Mackall
|
r15238 | |||
Pierre-Yves David
|
r22824 | skipped = set() | ||
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) | ||||
Pierre-Yves David
|
r22824 | skipped.add(rev) | ||
revs = [r for r in revs if r not in skipped] | ||||
Matt Mackall
|
r15238 | if not revs: | ||
return -1 | ||||
Siddharth Agarwal
|
r21980 | # Don't check in the --continue case, in effect retaining --force across | ||
# --continues. That's because without --force, any revisions we decided to | ||||
# skip would have been filtered out here, so they wouldn't have made their | ||||
# way to the graftstate. With --force, any revisions we would have otherwise | ||||
# skipped would not have been filtered out, and if they hadn't been applied | ||||
# already, they'd have been in the graftstate. | ||||
if not (cont or opts.get('force')): | ||||
# check for ancestors of dest branch | ||||
Siddharth Agarwal
|
r21979 | crev = repo['.'].rev() | ||
ancestors = repo.changelog.ancestors([crev], inclusive=True) | ||||
# XXX make this lazy in the future | ||||
# don't mutate while iterating, create a copy | ||||
for rev in list(revs): | ||||
if rev in ancestors: | ||||
Mads Kiilerich
|
r23507 | ui.warn(_('skipping ancestor revision %d:%s\n') % | ||
(rev, repo[rev])) | ||||
Siddharth Agarwal
|
r21979 | # XXX remove on list is slow | ||
revs.remove(rev) | ||||
if not revs: | ||||
return -1 | ||||
# analyze revs for earlier grafts | ||||
ids = {} | ||||
for ctx in repo.set("%ld", revs): | ||||
ids[ctx.hex()] = ctx.rev() | ||||
n = ctx.extra().get('source') | ||||
if n: | ||||
ids[n] = ctx.rev() | ||||
# check ancestors for earlier grafts | ||||
ui.debug('scanning for duplicate grafts\n') | ||||
Mads Kiilerich
|
r32242 | # The only changesets we can be sure doesn't contain grafts of any | ||
# revs, are the ones that are common ancestors of *all* revs: | ||||
for rev in repo.revs('only(%d,ancestor(%ld))', crev, revs): | ||||
Siddharth Agarwal
|
r21979 | ctx = repo[rev] | ||
n = ctx.extra().get('source') | ||||
if n in ids: | ||||
Matt Mackall
|
r22305 | try: | ||
r = repo[n].rev() | ||||
except error.RepoLookupError: | ||||
r = None | ||||
Siddharth Agarwal
|
r21979 | if r in revs: | ||
Mads Kiilerich
|
r23507 | ui.warn(_('skipping revision %d:%s ' | ||
'(already grafted to %d:%s)\n') | ||||
% (r, repo[r], rev, ctx)) | ||||
Siddharth Agarwal
|
r21979 | revs.remove(r) | ||
elif ids[n] in revs: | ||||
Matt Mackall
|
r22305 | if r is None: | ||
Mads Kiilerich
|
r23507 | ui.warn(_('skipping already grafted revision %d:%s ' | ||
'(%d:%s also has unknown origin %s)\n') | ||||
% (ids[n], repo[ids[n]], rev, ctx, n[:12])) | ||||
Matt Mackall
|
r22305 | else: | ||
Mads Kiilerich
|
r23507 | ui.warn(_('skipping already grafted revision %d:%s ' | ||
'(%d:%s also has origin %d:%s)\n') | ||||
% (ids[n], repo[ids[n]], rev, ctx, r, n[:12])) | ||||
Siddharth Agarwal
|
r21979 | revs.remove(ids[n]) | ||
elif ctx.hex() in ids: | ||||
r = ids[ctx.hex()] | ||||
Mads Kiilerich
|
r23507 | ui.warn(_('skipping already grafted revision %d:%s ' | ||
'(was grafted from %d:%s)\n') % | ||||
(r, repo[r], rev, ctx)) | ||||
Matt Mackall
|
r15360 | revs.remove(r) | ||
Siddharth Agarwal
|
r21979 | if not revs: | ||
return -1 | ||||
Matt Mackall
|
r15238 | |||
Bryan O'Sullivan
|
r27710 | for pos, ctx in enumerate(repo.set("%ld", revs)): | ||
desc = '%d:%s "%s"' % (ctx.rev(), ctx, | ||||
ctx.description().split('\n', 1)[0]) | ||||
names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node()) | ||||
if names: | ||||
desc += ' (%s)' % ' '.join(names) | ||||
ui.status(_('grafting %s\n') % desc) | ||||
if opts.get('dry_run'): | ||||
continue | ||||
Siddharth Agarwal
|
r27974 | source = ctx.extra().get('source') | ||
extra = {} | ||||
Bryan O'Sullivan
|
r27710 | if source: | ||
Siddharth Agarwal
|
r27974 | extra['source'] = source | ||
Bryan O'Sullivan
|
r27710 | extra['intermediate-source'] = ctx.hex() | ||
else: | ||||
extra['source'] = ctx.hex() | ||||
user = ctx.user() | ||||
if opts.get('user'): | ||||
user = opts['user'] | ||||
date = ctx.date() | ||||
if opts.get('date'): | ||||
date = opts['date'] | ||||
message = ctx.description() | ||||
if opts.get('log'): | ||||
message += '\n(grafted from %s)' % ctx.hex() | ||||
# 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', ''), | ||||
'graft') | ||||
stats = mergemod.graft(repo, ctx, ctx.p1(), | ||||
['local', 'graft']) | ||||
finally: | ||||
repo.ui.setconfig('ui', 'forcemerge', '', 'graft') | ||||
# 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.vfs.write('graftstate', ''.join(nodelines)) | ||||
extra = '' | ||||
if opts.get('user'): | ||||
Adam Simpkins
|
r29029 | extra += ' --user %s' % util.shellquote(opts['user']) | ||
Bryan O'Sullivan
|
r27710 | if opts.get('date'): | ||
Adam Simpkins
|
r29029 | extra += ' --date %s' % util.shellquote(opts['date']) | ||
Bryan O'Sullivan
|
r27710 | if opts.get('log'): | ||
extra += ' --log' | ||||
timeless
|
r28961 | hint=_("use 'hg resolve' and 'hg graft --continue%s'") % extra | ||
Bryan O'Sullivan
|
r27710 | raise error.Abort( | ||
_("unresolved conflicts, can't continue"), | ||||
hint=hint) | ||||
else: | ||||
cont = False | ||||
# commit | ||||
node = repo.commit(text=message, user=user, | ||||
date=date, extra=extra, editor=editor) | ||||
if node is None: | ||||
ui.warn( | ||||
_('note: graft of %d:%s created no changes to commit\n') % | ||||
(ctx.rev(), ctx)) | ||||
Matt Mackall
|
r15238 | |||
Matt Mackall
|
r15241 | # remove state when we complete successfully | ||
Mads Kiilerich
|
r18386 | if not opts.get('dry_run'): | ||
Mads Kiilerich
|
r31311 | repo.vfs.unlinkpath('graftstate', ignoremissing=True) | ||
Matt Mackall
|
r15241 | |||
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)')), | ||||
Yuya Nishihara
|
r29858 | ] + formatteropts + walkopts, | ||
Gregory Szorc
|
r21778 | _('[OPTION]... PATTERN [FILE]...'), | ||
inferrepo=True) | ||||
Thomas Arendsen Hein
|
r1108 | def grep(ui, repo, pattern, *pats, **opts): | ||
Kevin Bullock
|
r30009 | """search revision history for a pattern in specified files | ||
Search revision history for a regular expression in the specified | ||||
files or the entire project. | ||||
By default, grep prints the most recent revision number for each | ||||
Christian Ebert
|
r6448 | file in which it finds a match. To get it to print every revision | ||
Kevin Bullock
|
r30009 | 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. | ||||
PATTERN can be any Python (roughly Perl-compatible) regular | ||||
expression. | ||||
If no FILEs are specified (and -f/--follow isn't set), all files in | ||||
the repository are searched, including those that don't exist in the | ||||
current branch or have been deleted in a prior changeset. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 if a match is found, 1 otherwise. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
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: | ||
Siddharth Agarwal
|
r21911 | regexp = util.re.compile(pattern, reflags) | ||
Gregory Szorc
|
r25660 | except re.error as 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 | ||||
Kevin Bullock
|
r17949 | while begin < len(body): | ||
bos@serpentine.internal.keyresearch.com
|
r1059 | 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 | |||
Yuya Nishihara
|
r29854 | def findpos(self): | ||
"""Iterate all (start, end) indices of matches""" | ||||
yield self.colstart, self.colend | ||||
p = self.colend | ||||
while p < len(self.line): | ||||
m = regexp.search(self.line, p) | ||||
if not m: | ||||
Takumi IINO
|
r21011 | break | ||
Yuya Nishihara
|
r29854 | yield m.span() | ||
p = m.end() | ||||
Takumi IINO
|
r21011 | |||
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]) | ||
Yuya Nishihara
|
r29858 | def display(fm, fn, ctx, pstates, states): | ||
Matt Mackall
|
r9655 | rev = ctx.rev() | ||
Mathias De Maré
|
r29949 | if fm.isplain(): | ||
formatuser = ui.shortuser | ||||
else: | ||||
Yuya Nishihara
|
r29858 | formatuser = str | ||
Jordi Gutiérrez Hermoso
|
r24306 | if ui.quiet: | ||
Yuya Nishihara
|
r29858 | datefmt = '%Y-%m-%d' | ||
Jordi Gutiérrez Hermoso
|
r24306 | else: | ||
Yuya Nishihara
|
r29858 | datefmt = '%a %b %d %H:%M:%S %Y %1%2' | ||
Benoit Boissinot
|
r3951 | found = False | ||
FUJIWARA Katsunori
|
r20836 | @util.cachefunc | ||
Md. O. Shayan
|
r13920 | def binary(): | ||
flog = getfile(fn) | ||||
return util.binary(flog.read(ctx.filenode(fn))) | ||||
Yuya Nishihara
|
r29858 | fieldnamemap = {'filename': 'file', 'linenumber': 'line_number'} | ||
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: | ||
Yuya Nishihara
|
r29858 | fm.startitem() | ||
fm.data(node=fm.hexfunc(ctx.node())) | ||||
Yuya Nishihara
|
r29857 | cols = [ | ||
('filename', fn, True), | ||||
Yuya Nishihara
|
r29858 | ('rev', rev, True), | ||
('linenumber', l.linenum, opts.get('line_number')), | ||||
Yuya Nishihara
|
r29857 | ] | ||
Alexander Solovyov
|
r7131 | if opts.get('all'): | ||
Yuya Nishihara
|
r29857 | cols.append(('change', change, True)) | ||
cols.extend([ | ||||
Yuya Nishihara
|
r29858 | ('user', formatuser(ctx.user()), opts.get('user')), | ||
('date', fm.formatdate(ctx.date(), datefmt), opts.get('date')), | ||||
Yuya Nishihara
|
r29857 | ]) | ||
lastcol = next(name for name, data, cond in reversed(cols) if cond) | ||||
for name, data, cond in cols: | ||||
Yuya Nishihara
|
r29858 | field = fieldnamemap.get(name, name) | ||
fm.condwrite(cond, field, '%s', data, label='grep.%s' % name) | ||||
Yuya Nishihara
|
r29857 | if cond and name != lastcol: | ||
Yuya Nishihara
|
r29858 | fm.plain(sep, label='grep.sep') | ||
Takumi IINO
|
r21011 | if not opts.get('files_with_matches'): | ||
Yuya Nishihara
|
r29858 | fm.plain(sep, label='grep.sep') | ||
Md. O. Shayan
|
r13920 | if not opts.get('text') and binary(): | ||
Yuya Nishihara
|
r29858 | fm.plain(_(" Binary file matches")) | ||
Md. O. Shayan
|
r13920 | else: | ||
Yuya Nishihara
|
r29858 | displaymatches(fm.nested('texts'), l) | ||
fm.plain(eol) | ||||
Benoit Boissinot
|
r3951 | found = True | ||
Takumi IINO
|
r21011 | if opts.get('files_with_matches'): | ||
FUJIWARA Katsunori
|
r20838 | break | ||
Benoit Boissinot
|
r3951 | return found | ||
Bryan O'Sullivan
|
r1057 | |||
Yuya Nishihara
|
r29858 | def displaymatches(fm, l): | ||
Yuya Nishihara
|
r29855 | p = 0 | ||
for s, e in l.findpos(): | ||||
Yuya Nishihara
|
r29858 | if p < s: | ||
fm.startitem() | ||||
fm.write('text', '%s', l.line[p:s]) | ||||
fm.data(matched=False) | ||||
fm.startitem() | ||||
fm.write('text', '%s', l.line[s:e], label='grep.match') | ||||
fm.data(matched=True) | ||||
Yuya Nishihara
|
r29855 | p = e | ||
Yuya Nishihara
|
r29858 | if p < len(l.line): | ||
fm.startitem() | ||||
fm.write('text', '%s', l.line[p:]) | ||||
fm.data(matched=False) | ||||
fm.end() | ||||
Yuya Nishihara
|
r29855 | |||
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 | ||
Augie Fackler
|
r31036 | ui.pager('grep') | ||
Yuya Nishihara
|
r29858 | fm = ui.formatter('grep', opts) | ||
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: | ||||
Yuya Nishihara
|
r29858 | r = display(fm, fn, ctx, pstates, states) | ||
Matt Mackall
|
r9662 | 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] | ||||
Yuya Nishihara
|
r29858 | fm.end() | ||
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, | ||||
Matt Mackall
|
r16869 | _('[-ct] [-r STARTREV] [REV]...')) | ||
Eric Hopper
|
r4648 | def heads(ui, repo, *branchrevs, **opts): | ||
Matt Mackall
|
r19469 | """show branch heads | ||
With no arguments, show all open branch heads in the repository. | ||||
Matt Mackall
|
r19493 | Branch heads are changesets that have no descendants on the | ||
Matt Mackall
|
r19469 | same branch. They are where development generally takes place and | ||
are the usual targets for update and merge operations. | ||||
If one or more REVs are given, only open branch heads on the | ||||
branches associated with the specified changesets are shown. This | ||||
means that you can use :hg:`heads .` to see the heads on the | ||||
currently checked-out branch. | ||||
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 | ||||
Matt Mackall
|
r19469 | topological heads (changesets with no children) will be shown. | ||
Matt Mackall
|
r11177 | |||
Returns 0 if matching heads are found, 1 if not. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Dirkjan Ochtman
|
r10328 | |||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
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 | |||
Martin von Zweigbergk
|
r31387 | ui.pager('heads') | ||
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')), | ||||
Augie Fackler
|
r16711 | ('c', 'command', None, _('show only help for commands')), | ||
timeless@mozdev.org
|
r26238 | ('k', 'keyword', None, _('show topics matching keyword')), | ||
timeless
|
r27763 | ('s', 'system', [], _('show help for specific platform(s)')), | ||
Augie Fackler
|
r16711 | ], | ||
timeless
|
r27763 | _('[-ecks] [TOPIC]'), | ||
Gregory Szorc
|
r21768 | norepo=True) | ||
Dan Villiom Podlaski Christiansen
|
r18746 | def help_(ui, name=None, **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
|
r3655 | |||
Pulkit Goyal
|
r32143 | keep = opts.get(r'system') or [] | ||
timeless
|
r27763 | if len(keep) == 0: | ||
Pulkit Goyal
|
r30641 | if pycompat.sysplatform.startswith('win'): | ||
timeless
|
r27763 | keep.append('windows') | ||
Pulkit Goyal
|
r30641 | elif pycompat.sysplatform == 'OpenVMS': | ||
timeless
|
r27763 | keep.append('vms') | ||
Pulkit Goyal
|
r30641 | elif pycompat.sysplatform == 'plan9': | ||
timeless
|
r27763 | keep.append('plan9') | ||
else: | ||||
keep.append('unix') | ||||
Pulkit Goyal
|
r30641 | keep.append(pycompat.sysplatform.lower()) | ||
Matt Mackall
|
r22585 | if ui.verbose: | ||
keep.append('verbose') | ||||
Yuya Nishihara
|
r32567 | commands = sys.modules[__name__] | ||
formatted = help.formattedhelp(ui, commands, name, keep=keep, **opts) | ||||
Augie Fackler
|
r31037 | ui.pager('help') | ||
Olav Reinert
|
r16854 | ui.write(formatted) | ||
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, | ||||
Gregory Szorc
|
r21775 | _('[-nibtB] [-r REV] [SOURCE]'), | ||
optionalrepo=True) | ||||
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): | ||
Yuya Nishihara
|
r24364 | """identify the working directory or specified revision | ||
Matt Mackall
|
r4665 | |||
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:: | ||||
FUJIWARA Katsunori
|
r30243 | hg id -r tip https://www.mercurial-scm.org/repo/hg/ | ||
Matt Mackall
|
r15112 | |||
Mathias De Maré
|
r27120 | See :hg:`log` for generating more information about specific revisions, | ||
including full hash identifiers. | ||||
Matt Mackall
|
r11177 | Returns 0 if successful. | ||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r4662 | |||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Alexis S. L. Carvalho
|
r5330 | if not repo and not source: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("there is no Mercurial repository here " | ||
Alexis S. L. Carvalho
|
r5330 | "(.hg not found)")) | ||
Jordi Gutiérrez Hermoso
|
r24306 | if ui.debugflag: | ||
hexfunc = hex | ||||
else: | ||||
hexfunc = 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)) | ||
Simon Heimberg
|
r17875 | peer = hg.peer(repo or ui, opts, source) # only pass ui when no repo | ||
Sune Foldager
|
r17191 | repo = peer.local() | ||
revs, checkout = hg.addbranchrevs(repo, peer, branches, None) | ||||
if not repo: | ||||
Idan Kamara
|
r13953 | if num or branch or tags: | ||
Pierre-Yves David
|
r26587 | raise error.Abort( | ||
Idan Kamara
|
r13953 | _("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 | |||
Sune Foldager
|
r17191 | remoterev = peer.lookup(rev) | ||
Matt Mackall
|
r4666 | if default or id: | ||
Nils Adermann
|
r13644 | output = [hexfunc(remoterev)] | ||
Idan Kamara
|
r13953 | def getbms(): | ||
bms = [] | ||||
Sune Foldager
|
r17191 | if 'bookmarks' in peer.listkeys('namespaces'): | ||
Idan Kamara
|
r13953 | hexremoterev = hex(remoterev) | ||
Sune Foldager
|
r17191 | bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems() | ||
Idan Kamara
|
r13953 | if bmr == hexremoterev] | ||
Mads Kiilerich
|
r18366 | return sorted(bms) | ||
Idan Kamara
|
r13953 | |||
if bookmarks: | ||||
output.extend(getbms()) | ||||
elif default and not ui.quiet: | ||||
# multiple bookmarks for a single parent separated by '/' | ||||
bm = '/'.join(getbms()) | ||||
if bm: | ||||
output.append(bm) | ||||
Matt Mackall
|
r4665 | else: | ||
Matt Harbison
|
r25683 | ctx = scmutil.revsingle(repo, rev, None) | ||
if ctx.rev() is None: | ||||
Idan Kamara
|
r13953 | ctx = repo[None] | ||
parents = ctx.parents() | ||||
Matt Harbison
|
r25684 | taglist = [] | ||
for p in parents: | ||||
taglist.extend(p.tags()) | ||||
Idan Kamara
|
r13953 | changed = "" | ||
if default or id or num: | ||||
Augie Fackler
|
r25149 | if (any(repo.status()) | ||
or any(ctx.sub(s).dirty() for s in ctx.substate)): | ||||
Patrick Mezard
|
r17255 | changed = '+' | ||
Idan Kamara
|
r13953 | if default or id: | ||
output = ["%s%s" % | ||||
('+'.join([hexfunc(p.node()) for p in parents]), changed)] | ||||
if num: | ||||
output.append("%s%s" % | ||||
('+'.join([str(p.rev()) for p in parents]), changed)) | ||||
else: | ||||
if default or id: | ||||
output = [hexfunc(ctx.node())] | ||||
if num: | ||||
output.append(str(ctx.rev())) | ||||
Matt Harbison
|
r25684 | taglist = ctx.tags() | ||
Idan Kamara
|
r13953 | |||
if default and not ui.quiet: | ||||
b = ctx.branch() | ||||
if b != 'default': | ||||
output.append("(%s)" % b) | ||||
# multiple tags for a single parent separated by '/' | ||||
Matt Harbison
|
r25684 | t = '/'.join(taglist) | ||
Idan Kamara
|
r13953 | 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: | ||||
Matt Harbison
|
r25684 | output.extend(taglist) | ||
Idan Kamara
|
r13953 | |||
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')), | ||
Matt Mackall
|
r19409 | ('f', 'force', None, | ||
_('skip check for outstanding uncommitted changes (DEPRECATED)')), | ||||
Adrian Buehlmann
|
r14297 | ('', 'no-commit', None, | ||
_("don't commit, just update the working directory")), | ||||
Patrick Mezard
|
r14611 | ('', 'bypass', None, | ||
_("apply patch without touching the working directory")), | ||||
Pierre-Yves David
|
r21553 | ('', 'partial', None, | ||
_('commit even if some hunks fail')), | ||||
Adrian Buehlmann
|
r14297 | ('', 'exact', None, | ||
Matt Mackall
|
r28866 | _('abort if patch would apply lossily')), | ||
Siddharth Agarwal
|
r24258 | ('', 'prefix', '', | ||
Siddharth Agarwal
|
r24390 | _('apply patch to subdirectory'), _('DIR')), | ||
Adrian Buehlmann
|
r14297 | ('', '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 | |||
Martin von Zweigbergk
|
r30899 | To read a patch from standard input (stdin), use "-" as the patch | ||
name. If a URL is specified, the patch will be downloaded from | ||||
there. | ||||
timeless
|
r27390 | |||
Import first applies changes to the working directory (unless | ||||
--bypass is specified), import will abort if there are outstanding | ||||
changes. | ||||
Use --bypass to apply and commit patches directly to the | ||||
repository, without affecting the working directory. Without | ||||
--exact, patches will be applied on top of the working directory | ||||
parent revision. | ||||
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 | ||
timeless
|
r27389 | text/plain body parts before first diff are added to the commit | ||
Vadim Gelfer
|
r2515 | 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 | ||||
Matt Mackall
|
r28866 | the patch. This will guard against various ways that portable | ||
patch formats and mail systems might fail to transfer Mercurial | ||||
FUJIWARA Katsunori
|
r29648 | data or metadata. See :hg:`bundle` for lossless transmission. | ||
Brendan Cully
|
r4263 | |||
Pierre-Yves David
|
r21553 | Use --partial to ensure a changeset will be created from the patch | ||
even if some hunks fail to apply. Hunks that fail to apply will be | ||||
written to a <target-file>.rej file. Conflicts can then be resolved | ||||
by hand before :hg:`commit --amend` is run to update the created | ||||
changeset. This flag exists to let people import patches that | ||||
partially apply without losing the associated metadata (author, | ||||
timeless
|
r27488 | date, description, ...). | ||
.. note:: | ||||
When no hunks apply cleanly, :hg:`import --partial` will create | ||||
an empty changeset, importing only the patch metadata. | ||||
Pierre-Yves David
|
r21553 | |||
timeless
|
r27390 | With -s/--similarity, hg will attempt to discover renames and | ||
copies in the patch in the same way as :hg:`addremove`. | ||||
Pierre-Yves David
|
r21553 | |||
Jordi Gutiérrez Hermoso
|
r25650 | It is possible to use external patch programs to perform the patch | ||
Jordi Gutiérrez Hermoso
|
r25651 | by setting the ``ui.patch`` configuration option. For the default | ||
internal tool, the fuzz can also be configured via ``patch.fuzz``. | ||||
Jordi Gutiérrez Hermoso
|
r25650 | See :hg:`help config` for more information about configuration | ||
Jordi Gutiérrez Hermoso
|
r25651 | files and how to use these options. | ||
Jordi Gutiérrez Hermoso
|
r25650 | |||
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:: | ||||
FUJIWARA Katsunori
|
r30243 | hg import https://www.mercurial-scm.org/repo/hg/rev/5ca8c111e9aa | ||
Matt Mackall
|
r15113 | |||
- import all the patches in an Unix-style mbox:: | ||||
hg import incoming-patches.mbox | ||||
Martin von Zweigbergk
|
r30899 | - import patches from stdin:: | ||
hg import - | ||||
Matt Mackall
|
r15113 | - attempt to exactly restore an exported changeset (not always | ||
possible):: | ||||
hg import --exact proposed-fix.patch | ||||
Jordi Gutiérrez Hermoso
|
r25650 | - use an external tool to apply a patch which is too fuzzy for | ||
the default internal tool. | ||||
hg import --config ui.patch="patch --merge" fuzzy.patch | ||||
Jordi Gutiérrez Hermoso
|
r25651 | - change the default fuzzing from 2 to a less strict 7 | ||
hg import --config ui.fuzz=7 fuzz.patch | ||||
Pierre-Yves David
|
r21553 | Returns 0 on success, 1 on partial success (see --partial). | ||
Benoit Boissinot
|
r1437 | """ | ||
Kevin Bullock
|
r15327 | |||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Kevin Bullock
|
r15327 | if not patch1: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('need at least one patch to import')) | ||
Kevin Bullock
|
r15327 | |||
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) | ||||
timeless
|
r27388 | exact = opts.get('exact') | ||
Patrick Mezard
|
r14611 | update = not opts.get('bypass') | ||
if not update and opts.get('no_commit'): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot use --no-commit with --bypass')) | ||
Brendan Cully
|
r7402 | try: | ||
sim = float(opts.get('similarity') or 0) | ||||
except ValueError: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('similarity must be a number')) | ||
Brendan Cully
|
r7402 | if sim < 0 or sim > 100: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('similarity must be between 0 and 100')) | ||
Patrick Mezard
|
r14611 | if sim and not update: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot use --similarity with --bypass')) | ||
timeless
|
r27388 | if exact: | ||
if opts.get('edit'): | ||||
raise error.Abort(_('cannot use --exact with --edit')) | ||||
if opts.get('prefix'): | ||||
raise error.Abort(_('cannot use --exact with --prefix')) | ||||
mpm@selenic.com
|
r966 | |||
Greg Ward
|
r15195 | base = opts["base"] | ||
FUJIWARA Katsunori
|
r24994 | wlock = dsguard = lock = tr = None | ||
Steve Borho
|
r12913 | msgs = [] | ||
Pierre-Yves David
|
r21553 | ret = 0 | ||
Brendan Cully
|
r10384 | |||
Peter Arrenbrecht
|
r10405 | |||
Matt Mackall
|
r4915 | try: | ||
Bryan O'Sullivan
|
r27708 | wlock = repo.wlock() | ||
if update: | ||||
cmdutil.checkunfinished(repo) | ||||
if (exact or not opts.get('force')): | ||||
cmdutil.bailifchanged(repo) | ||||
if not opts.get('no_commit'): | ||||
lock = repo.lock() | ||||
tr = repo.transaction('import') | ||||
else: | ||||
Augie Fackler
|
r30491 | dsguard = dirstateguard.dirstateguard(repo, 'import') | ||
Bryan O'Sullivan
|
r27708 | parents = repo[None].parents() | ||
for patchurl in patches: | ||||
if patchurl == '-': | ||||
ui.status(_('applying patch from stdin\n')) | ||||
patchfile = ui.fin | ||||
patchurl = 'stdin' # for error message | ||||
FUJIWARA Katsunori
|
r26580 | else: | ||
Bryan O'Sullivan
|
r27708 | patchurl = os.path.join(base, patchurl) | ||
ui.status(_('applying %s\n') % patchurl) | ||||
patchfile = hg.openpath(ui, patchurl) | ||||
haspatch = False | ||||
for hunk in patch.split(patchfile): | ||||
(msg, node, rej) = cmdutil.tryimportone(ui, repo, hunk, | ||||
parents, opts, | ||||
msgs, hg.clean) | ||||
if msg: | ||||
haspatch = True | ||||
ui.note(msg + '\n') | ||||
if update or exact: | ||||
parents = repo[None].parents() | ||||
Patrick Mezard
|
r14611 | else: | ||
Bryan O'Sullivan
|
r27708 | parents = [repo[node]] | ||
if rej: | ||||
ui.write_err(_("patch applied partially\n")) | ||||
ui.write_err(_("(fix the .rej files and run " | ||||
"`hg commit --amend`)\n")) | ||||
ret = 1 | ||||
break | ||||
if not haspatch: | ||||
raise error.Abort(_('%s: no diffs found') % patchurl) | ||||
if tr: | ||||
tr.close() | ||||
if msgs: | ||||
repo.savecommitmessage('\n* * *\n'.join(msgs)) | ||||
if dsguard: | ||||
dsguard.close() | ||||
return ret | ||||
Matt Mackall
|
r4915 | finally: | ||
Greg Ward
|
r15198 | if tr: | ||
tr.release() | ||||
FUJIWARA Katsunori
|
r24994 | release(lock, dsguard, 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 | |||
Thomas Arendsen Hein
|
r1979 | See pull for valid source format details. | ||
Matt Mackall
|
r11177 | |||
Matt Mackall
|
r20834 | .. container:: verbose | ||
FUJIWARA Katsunori
|
r24660 | With -B/--bookmarks, the result of bookmark comparison between | ||
local and remote repositories is displayed. With -v/--verbose, | ||||
status is also displayed for each bookmark like below:: | ||||
BM1 01234567890a added | ||||
BM2 1234567890ab advanced | ||||
BM3 234567890abc diverged | ||||
BM4 34567890abcd changed | ||||
The action taken locally when pulling depends on the | ||||
status of each bookmark: | ||||
:``added``: pull will create it | ||||
:``advanced``: pull will update it | ||||
:``diverged``: pull will create a divergent bookmark | ||||
:``changed``: result depends on remote changesets | ||||
From the point of view of pulling behavior, bookmark | ||||
existing only in the remote repository are treated as ``added``, | ||||
even if it is in fact locally deleted. | ||||
.. container:: verbose | ||||
Yuya Nishihara
|
r24248 | For remote repository, using --bundle avoids downloading the | ||
changesets twice if the incoming is followed by a pull. | ||||
Matt Mackall
|
r20834 | Examples: | ||
- show incoming changes with patches and full description:: | ||||
hg incoming -vp | ||||
- show incoming changes excluding merges, store a bundle:: | ||||
hg in -vpM --bundle incoming.hg | ||||
hg pull incoming.hg | ||||
- briefly list changes inside a bundle:: | ||||
hg in changes.hg -T "{desc|firstline}\\n" | ||||
Matt Mackall
|
r11177 | Returns 0 if there are incoming changes, 1 otherwise. | ||
Benoit Boissinot
|
r1437 | """ | ||
Pulkit Goyal
|
r31826 | opts = pycompat.byteskwargs(opts) | ||
Patrick Mezard
|
r17182 | if opts.get('graph'): | ||
cmdutil.checkunsupportedgraphflags([], opts) | ||||
def display(other, chlist, displayer): | ||||
revdag = cmdutil.graphrevs(other, chlist, opts) | ||||
Yuya Nishihara
|
r27213 | cmdutil.displaygraph(ui, repo, revdag, displayer, | ||
Patrick Mezard
|
r17182 | graphmod.asciiedges) | ||
hg._incoming(display, lambda: 1, ui, repo, source, opts, buffered=True) | ||||
return 0 | ||||
Martin Geisler
|
r12274 | if opts.get('bundle') and opts.get('subrepos'): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('cannot combine --bundle and --subrepos')) | ||
Martin Geisler
|
r12274 | |||
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 | ||||
Augie Fackler
|
r31038 | ui.pager('incoming') | ||
Brodie Rao
|
r14076 | ui.status(_('comparing with %s\n') % util.hidepassword(source)) | ||
FUJIWARA Katsunori
|
r24397 | return bookmarks.incoming(ui, repo, other) | ||
Matt Mackall
|
r13366 | |||
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 | |||
Gregory Szorc
|
r21768 | @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]'), | ||
norepo=True) | ||||
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 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
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): | ||
Matt Mackall
|
r22431 | """locate files matching specific patterns (DEPRECATED) | ||
Benoit Boissinot
|
r1437 | |||
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 | |||
Matt Mackall
|
r22433 | See :hg:`help files` for a more versatile command. | ||
Matt Mackall
|
r11177 | Returns 0 if a match is found, 1 otherwise. | ||
Benoit Boissinot
|
r1437 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Jordi Gutiérrez Hermoso
|
r24306 | if opts.get('print0'): | ||
end = '\0' | ||||
else: | ||||
end = '\n' | ||||
Matt Mackall
|
r14319 | rev = scmutil.revsingle(repo, opts.get('rev'), None).node() | ||
mpm@selenic.com
|
r742 | |||
Alexis S. L. Carvalho
|
r4196 | ret = 1 | ||
Siddharth Agarwal
|
r21986 | ctx = repo[rev] | ||
Matt Harbison
|
r25468 | m = scmutil.match(ctx, pats, opts, default='relglob', | ||
badfn=lambda x, y: False) | ||||
Siddharth Agarwal
|
r21986 | |||
Augie Fackler
|
r31039 | ui.pager('locate') | ||
Siddharth Agarwal
|
r21986 | for abs in ctx.matches(m): | ||
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')), | ||||
Jordi Gutiérrez Hermoso
|
r23091 | ('r', 'rev', [], _('show the specified revision or revset'), _('REV')), | ||
Adrian Buehlmann
|
r14297 | ('', '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')), | ||||
] + logopts + walkopts, | ||||
Gregory Szorc
|
r21778 | _('[OPTION]... [FILE]'), | ||
inferrepo=True) | ||||
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 | |||
Mads Kiilerich
|
r20544 | With --graph the revisions are shown as an ASCII art DAG with the most | ||
recent changeset at the top. | ||||
'o' is a changeset, '@' is a working directory parent, 'x' is obsolete, | ||||
and '+' represents a fork where the changeset from the lines below is a | ||||
Wagner Bruna
|
r21174 | parent of the 'o' merge on the same line. | ||
Matt DeVore
|
r32075 | Paths in the DAG are represented with '|', '/' and so forth. ':' in place | ||
of a '|' indicates one or more revisions in a path are omitted. | ||||
Mads Kiilerich
|
r20544 | |||
Christian Ebert
|
r12390 | .. note:: | ||
Simon Heimberg
|
r19997 | |||
timeless
|
r27476 | :hg:`log --patch` may generate unexpected diff output for merge | ||
Christian Ebert
|
r12390 | 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:: | ||
Simon Heimberg
|
r19997 | |||
timeless
|
r27476 | For performance reasons, :hg:`log FILE` may omit duplicate changes | ||
Matt Mackall
|
r22493 | made on branches and will not show removals or mode changes. To | ||
see all such changes, use the --removed switch. | ||||
Matt Mackall
|
r15105 | |||
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" | ||||
Mathias De Maré
|
r27119 | - the full hash identifier of the working directory parent:: | ||
hg log -r . --template "{node}\\n" | ||||
Matt Mackall
|
r21944 | - list available log templates:: | ||
hg log -T list | ||||
Matt Mackall
|
r22576 | - check if a given changeset is included in a tagged release:: | ||
Matt Mackall
|
r15103 | |||
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. | ||
Martin von Zweigbergk
|
r30785 | See :hg:`help revisions` for more about specifying and ordering | ||
revisions. | ||||
Matt Mackall
|
r15104 | |||
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. | ||
Matt Mackall
|
r22493 | |||
Benoit Boissinot
|
r1437 | """ | ||
Yuya Nishihara
|
r31487 | opts = pycompat.byteskwargs(opts) | ||
Durham Goode
|
r24189 | if opts.get('follow') and opts.get('rev'): | ||
Yuya Nishihara
|
r31024 | opts['rev'] = [revsetlang.formatspec('reverse(::%lr)', opts.get('rev'))] | ||
Durham Goode
|
r24189 | del opts['follow'] | ||
Patrick Mezard
|
r17181 | if opts.get('graph'): | ||
Yuya Nishihara
|
r31486 | return cmdutil.graphlog(ui, repo, pats, opts) | ||
Vadim Gelfer
|
r1756 | |||
Lucas Moscovicz
|
r21127 | revs, expr, filematcher = cmdutil.getlogrevs(repo, pats, opts) | ||
Thomas Arendsen Hein
|
r6190 | limit = cmdutil.loglimit(opts) | ||
Vadim Gelfer
|
r1756 | count = 0 | ||
Lucas Moscovicz
|
r21127 | getrenamed = None | ||
Patrick Mezard
|
r16175 | if opts.get('copies'): | ||
Lucas Moscovicz
|
r21127 | endrev = None | ||
Patrick Mezard
|
r16175 | if opts.get('rev'): | ||
Lucas Moscovicz
|
r21127 | endrev = scmutil.revrange(repo, opts.get('rev')).max() + 1 | ||
Patrick Mezard
|
r16175 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) | ||
Brendan Cully
|
r3197 | |||
Augie Fackler
|
r31032 | ui.pager('log') | ||
Lucas Moscovicz
|
r21127 | displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) | ||
for rev in revs: | ||||
if count == limit: | ||||
break | ||||
ctx = repo[rev] | ||||
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])) | ||||
Jordi Gutiérrez Hermoso
|
r24306 | if filematcher: | ||
revmatchfn = filematcher(ctx.rev()) | ||||
else: | ||||
revmatchfn = None | ||||
Mads Kiilerich
|
r11488 | displayer.show(ctx, copies=copies, matchfn=revmatchfn) | ||
Yuya Nishihara
|
r25763 | if displayer.flush(ctx): | ||
Bryan O'Sullivan
|
r18711 | count += 1 | ||
Lucas Moscovicz
|
r21127 | |||
Robert Bachmann
|
r10152 | displayer.close() | ||
mpm@selenic.com
|
r255 | |||
Adrian Buehlmann
|
r14297 | @command('manifest', | ||
Adrian Buehlmann
|
r14399 | [('r', 'rev', '', _('revision to display'), _('REV')), | ||
Matt Mackall
|
r22429 | ('', 'all', False, _("list files from all revisions"))] | ||
+ formatteropts, | ||||
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 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Matt Mackall
|
r17911 | fm = ui.formatter('manifest', opts) | ||
Adrian Buehlmann
|
r14399 | if opts.get('all'): | ||
if rev or node: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("can't specify a revision with --all")) | ||
Adrian Buehlmann
|
r14399 | |||
res = [] | ||||
prefix = "data/" | ||||
suffix = ".i" | ||||
plen = len(prefix) | ||||
slen = len(suffix) | ||||
Bryan O'Sullivan
|
r27858 | with repo.lock(): | ||
Adrian Buehlmann
|
r14399 | for fn, b, size in repo.store.datafiles(): | ||
if size != 0 and fn[-slen:] == suffix and fn[:plen] == prefix: | ||||
res.append(fn[plen:-slen]) | ||||
Augie Fackler
|
r31040 | ui.pager('manifest') | ||
Adrian Buehlmann
|
r17376 | for f in res: | ||
Matt Mackall
|
r17911 | fm.startitem() | ||
fm.write("path", '%s\n', f) | ||||
fm.end() | ||||
Adrian Buehlmann
|
r14399 | return | ||
Matt Mackall
|
r3736 | |||
Bryan O'Sullivan
|
r5155 | if rev and node: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("please specify just one revision")) | ||
Bryan O'Sullivan
|
r5155 | |||
if not node: | ||||
node = rev | ||||
Matt Mackall
|
r17911 | char = {'l': '@', 'x': '*', '': ''} | ||
mode = {'l': '644', 'x': '755', '': '644'} | ||||
Matt Mackall
|
r14319 | ctx = scmutil.revsingle(repo, node) | ||
Matt Mackall
|
r17911 | mf = ctx.manifest() | ||
Augie Fackler
|
r31040 | ui.pager('manifest') | ||
Matt Mackall
|
r6749 | for f in ctx: | ||
Matt Mackall
|
r17911 | fm.startitem() | ||
fl = ctx[f].flags() | ||||
fm.condwrite(ui.debugflag, 'hash', '%s ', hex(mf[f])) | ||||
fm.condwrite(ui.verbose, 'mode type', '%s %1s ', mode[fl], char[fl]) | ||||
fm.write('path', '%s\n', f) | ||||
fm.end() | ||||
mpm@selenic.com
|
r255 | |||
Adrian Buehlmann
|
r14297 | @command('^merge', | ||
Florence Laguzet
|
r19439 | [('f', 'force', None, | ||
_('force a merge including outstanding changes (DEPRECATED)')), | ||||
Adrian Buehlmann
|
r14297 | ('r', 'rev', '', _('revision to merge'), _('REV')), | ||
('P', 'preview', None, | ||||
Martin Geisler
|
r14852 | _('review revisions to merge (no merge is performed)')) | ||
] + mergetoolopts, | ||||
FUJIWARA Katsunori
|
r28288 | _('[-P] [[-r] REV]')) | ||
Dirkjan Ochtman
|
r8387 | def merge(ui, repo, node=None, **opts): | ||
anatoly techtonik
|
r23400 | """merge another revision into working directory | ||
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 | |||
timeless
|
r27487 | See :hg:`help resolve` for information on handling file conflicts. | ||
Steve Borho
|
r12750 | |||
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 | |||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Dirkjan Ochtman
|
r8387 | if opts.get('rev') and node: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("please specify just one revision")) | ||
Daniel Holth
|
r4450 | if not node: | ||
Dirkjan Ochtman
|
r8387 | node = opts.get('rev') | ||
Daniel Holth
|
r4450 | |||
David Soria Parra
|
r16708 | if node: | ||
node = scmutil.revsingle(repo, node).node() | ||||
Pierre-Yves David
|
r26303 | if not node: | ||
Pierre-Yves David
|
r26715 | node = repo[destutil.destmerge(repo)].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 | ||||
Mads Kiilerich
|
r20790 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'merge') | ||
Siddharth Agarwal
|
r28020 | force = opts.get('force') | ||
Simon Farnsworth
|
r30062 | labels = ['working copy', 'merge rev'] | ||
return hg.merge(repo, node, force=force, mergeforce=force, | ||||
labels=labels) | ||||
Steve Borho
|
r12788 | finally: | ||
Mads Kiilerich
|
r20790 | ui.setconfig('ui', 'forcemerge', '', 'merge') | ||
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 | |||
FUJIWARA Katsunori
|
r24661 | .. container:: verbose | ||
With -B/--bookmarks, the result of bookmark comparison between | ||||
local and remote repositories is displayed. With -v/--verbose, | ||||
status is also displayed for each bookmark like below:: | ||||
BM1 01234567890a added | ||||
BM2 deleted | ||||
BM3 234567890abc advanced | ||||
BM4 34567890abcd diverged | ||||
BM5 4567890abcde changed | ||||
The action taken when pushing depends on the | ||||
status of each bookmark: | ||||
:``added``: push with ``-B`` will create it | ||||
:``deleted``: push with ``-B`` will delete it | ||||
:``advanced``: push will update it | ||||
:``diverged``: push with ``-B`` will update it | ||||
:``changed``: push with ``-B`` will update it | ||||
From the point of view of pushing behavior, bookmarks | ||||
existing only in the remote repository are treated as | ||||
``deleted``, even if it is in fact added remotely. | ||||
Matt Mackall
|
r11177 | Returns 0 if there are outgoing changes, 1 otherwise. | ||
Benoit Boissinot
|
r1437 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Patrick Mezard
|
r17182 | if opts.get('graph'): | ||
cmdutil.checkunsupportedgraphflags([], opts) | ||||
FUJIWARA Katsunori
|
r21050 | o, other = hg._outgoing(ui, repo, dest, opts) | ||
FUJIWARA Katsunori
|
r21049 | if not o: | ||
FUJIWARA Katsunori
|
r21051 | cmdutil.outgoinghooks(ui, repo, other, opts, o) | ||
Patrick Mezard
|
r17182 | return | ||
revdag = cmdutil.graphrevs(repo, o, opts) | ||||
Augie Fackler
|
r31058 | ui.pager('outgoing') | ||
Patrick Mezard
|
r17182 | displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) | ||
Yuya Nishihara
|
r27213 | cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges) | ||
FUJIWARA Katsunori
|
r21051 | cmdutil.outgoinghooks(ui, repo, other, opts, o) | ||
Patrick Mezard
|
r17182 | return 0 | ||
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 | ||||
Augie Fackler
|
r31058 | ui.status(_('comparing with %s\n') % util.hidepassword(dest)) | ||
Augie Fackler
|
r31041 | ui.pager('outgoing') | ||
FUJIWARA Katsunori
|
r24398 | return bookmarks.outgoing(ui, repo, other) | ||
Matt Mackall
|
r13366 | |||
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, | ||||
Gregory Szorc
|
r21778 | _('[-r REV] [FILE]'), | ||
inferrepo=True) | ||||
Matt Mackall
|
r3658 | def parents(ui, repo, file_=None, **opts): | ||
Matt Mackall
|
r22501 | """show the parents of the working directory or revision (DEPRECATED) | ||
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 | |||
timeless
|
r27317 | This command is equivalent to:: | ||
timeless
|
r27568 | hg log -r "p1()+p2()" or | ||
hg log -r "p1(REV)+p2(REV)" or | ||||
hg log -r "max(::p1() and file(FILE))+max(::p2() and file(FILE))" or | ||||
hg log -r "max(::p1(REV) and file(FILE))+max(::p2(REV) and file(FILE))" | ||||
timeless
|
r27317 | |||
Matt Mackall
|
r22501 | See :hg:`summary` and :hg:`help revsets` for related information. | ||
Matt Mackall
|
r11177 | Returns 0 on success. | ||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r12925 | |||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
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: | ||
Pierre-Yves David
|
r26587 | raise error.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: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("'%s' not found in manifest!") % file_) | ||
Durham Goode
|
r19333 | p = [] | ||
for fn in filenodes: | ||||
fctx = repo.filectx(file_, fileid=fn) | ||||
p.append(fctx.node()) | ||||
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 | |||
Yuya Nishihara
|
r27728 | @command('paths', formatteropts, _('[NAME]'), optionalrepo=True) | ||
def paths(ui, repo, search=None, **opts): | ||||
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 | ||||
timeless
|
r27490 | source is written as ``default`` in ``.hg/hgrc``. | ||
.. note:: | ||||
``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 | """ | ||
Pulkit Goyal
|
r32142 | |||
opts = pycompat.byteskwargs(opts) | ||||
Augie Fackler
|
r31042 | ui.pager('paths') | ||
TK Soh
|
r779 | if search: | ||
Yuya Nishihara
|
r27726 | pathitems = [(name, path) for name, path in ui.paths.iteritems() | ||
if name == search] | ||||
TK Soh
|
r779 | else: | ||
Yuya Nishihara
|
r27725 | pathitems = sorted(ui.paths.iteritems()) | ||
Yuya Nishihara
|
r27728 | fm = ui.formatter('paths', opts) | ||
Mathias De Maré
|
r29949 | if fm.isplain(): | ||
hidepassword = util.hidepassword | ||||
else: | ||||
Yuya Nishihara
|
r27728 | hidepassword = str | ||
Yuya Nishihara
|
r27727 | if ui.quiet: | ||
namefmt = '%s\n' | ||||
else: | ||||
namefmt = '%s = ' | ||||
showsubopts = not search and not ui.quiet | ||||
Yuya Nishihara
|
r27725 | for name, path in pathitems: | ||
Yuya Nishihara
|
r27728 | fm.startitem() | ||
fm.condwrite(not search, 'name', namefmt, name) | ||||
fm.condwrite(not ui.quiet, 'url', '%s\n', hidepassword(path.rawloc)) | ||||
Yuya Nishihara
|
r27727 | for subopt, value in sorted(path.suboptions.items()): | ||
Yuya Nishihara
|
r27728 | assert subopt not in ('name', 'url') | ||
Yuya Nishihara
|
r27727 | if showsubopts: | ||
Yuya Nishihara
|
r27728 | fm.plain('%s:%s = ' % (name, subopt)) | ||
fm.condwrite(showsubopts, subopt, '%s\n', value) | ||||
fm.end() | ||||
TK Soh
|
r779 | |||
Yuya Nishihara
|
r27726 | if search and not pathitems: | ||
if not ui.quiet: | ||||
ui.warn(_("not found!\n")) | ||||
return 1 | ||||
else: | ||||
return 0 | ||||
Pierre-Yves David
|
r17981 | @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 | ], | ||
Gilles Moris
|
r25120 | _('[-p|-d|-s] [-f] [-r] [REV...]')) | ||
Pierre-Yves David
|
r15830 | def phase(ui, repo, *revs, **opts): | ||
"""set or show the current phase name | ||||
Gilles Moris
|
r25120 | With no argument, show the phase name of the current revision(s). | ||
Pierre-Yves David
|
r15830 | |||
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 | |||
Jordi Gutiérrez Hermoso
|
r26366 | Returns 0 on success, 1 if some phases could not be changed. | ||
Pierre-Yves David
|
r25626 | |||
(For more information about the phases concept, see :hg:`help phases`.) | ||||
Pierre-Yves David
|
r15830 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
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: | ||||
Pierre-Yves David
|
r26587 | raise error.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: | ||||
Gilles Moris
|
r25120 | # display both parents as the second parent phase can influence | ||
# the phase of a merge commit | ||||
revs = [c.rev() for c in repo[None].parents()] | ||||
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: | ||||
Pierre-Yves David
|
r22050 | tr = None | ||
Pierre-Yves David
|
r15830 | lock = repo.lock() | ||
try: | ||||
Pierre-Yves David
|
r22050 | tr = repo.transaction("phase") | ||
Pierre-Yves David
|
r15830 | # set phase | ||
Patrick Mezard
|
r16659 | if not revs: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('empty revision set')) | ||
Patrick Mezard
|
r16659 | nodes = [repo[r].node() for r in revs] | ||
Durham Goode
|
r22892 | # moving revision from public to draft may hide them | ||
# We have to check result on an unfiltered repository | ||||
unfi = repo.unfiltered() | ||||
getphase = unfi._phasecache.phase | ||||
olddata = [getphase(unfi, r) for r in unfi] | ||||
Pierre-Yves David
|
r22069 | phases.advanceboundary(repo, tr, targetphase, nodes) | ||
Pierre-Yves David
|
r15830 | if opts['force']: | ||
Pierre-Yves David
|
r22070 | phases.retractboundary(repo, tr, targetphase, nodes) | ||
Pierre-Yves David
|
r22050 | tr.close() | ||
Pierre-Yves David
|
r15830 | finally: | ||
Pierre-Yves David
|
r22050 | if tr is not None: | ||
tr.release() | ||||
Pierre-Yves David
|
r15830 | lock.release() | ||
Durham Goode
|
r22892 | getphase = unfi._phasecache.phase | ||
newdata = [getphase(unfi, r) for r in unfi] | ||||
changes = sum(newdata[r] != olddata[r] for r in unfi) | ||||
Pierre-Yves David
|
r18210 | cl = unfi.changelog | ||
Patrick Mezard
|
r16715 | rejected = [n for n in nodes | ||
Pierre-Yves David
|
r18209 | if newdata[cl.rev(n)] < targetphase] | ||
Patrick Mezard
|
r16715 | if rejected: | ||
Martin Geisler
|
r20093 | ui.warn(_('cannot move %i changesets to a higher ' | ||
Patrick Mezard
|
r16715 | 'phase, use --force\n') % len(rejected)) | ||
ret = 1 | ||||
if changes: | ||||
msg = _('phase changed for %i changesets\n') % changes | ||||
if ret: | ||||
ui.status(msg) | ||||
Pierre-Yves David
|
r15906 | else: | ||
Patrick Mezard
|
r16715 | ui.note(msg) | ||
else: | ||||
ui.warn(_('no phases changed\n')) | ||||
Pierre-Yves David
|
r15968 | return ret | ||
Pierre-Yves David
|
r15830 | |||
FUJIWARA Katsunori
|
r28269 | def postincoming(ui, repo, modheads, optupdate, checkout, brev): | ||
FUJIWARA Katsunori
|
r28502 | """Run after a changegroup has been added via pull/unbundle | ||
This takes arguments below: | ||||
:modheads: change of heads by pull/unbundle | ||||
:optupdate: updating working directory is needed or not | ||||
:checkout: update destination revision (or None to default destination) | ||||
:brev: a name, which might be a bookmark to be activated after updating | ||||
""" | ||||
Vadim Gelfer
|
r2019 | if modheads == 0: | ||
Matt Mackall
|
r16107 | return | ||
Vadim Gelfer
|
r2019 | if optupdate: | ||
Brendan Cully
|
r14485 | try: | ||
FUJIWARA Katsunori
|
r28501 | return hg.updatetotally(ui, repo, checkout, brev) | ||
Pierre-Yves David
|
r26683 | except error.UpdateAbort as inst: | ||
liscju
|
r26968 | msg = _("not updating: %s") % str(inst) | ||
hint = inst.hint | ||||
raise error.UpdateAbort(msg, hint=hint) | ||||
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: | ||
Brodie Rao
|
r16683 | 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 | |||
liscju
|
r29384 | Specifying bookmark as ``.`` is equivalent to specifying the active | ||
bookmark's name. | ||||
Matt Mackall
|
r16107 | Returns 0 on success, 1 if an update had unresolved files. | ||
Benoit Boissinot
|
r1437 | """ | ||
Ryan McElroy
|
r31845 | |||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Ryan McElroy
|
r31845 | if ui.configbool('commands', 'update.requiredest') and opts.get('update'): | ||
msg = _('update destination required by configuration') | ||||
hint = _('use hg pull followed by hg update DEST') | ||||
raise error.Abort(msg, hint=hint) | ||||
Sune Foldager
|
r10379 | source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) | ||
Thomas Arendsen Hein
|
r24138 | ui.status(_('pulling from %s\n') % util.hidepassword(source)) | ||
Matt Mackall
|
r14556 | other = hg.peer(repo, opts, source) | ||
Piotr Klecha
|
r20576 | try: | ||
revs, checkout = hg.addbranchrevs(repo, other, branches, | ||||
opts.get('rev')) | ||||
Pierre-Yves David
|
r25445 | pullopargs = {} | ||
Piotr Klecha
|
r20576 | if opts.get('bookmark'): | ||
if not revs: | ||||
revs = [] | ||||
Pierre-Yves David
|
r25368 | # The list of bookmark used here is not the one used to actually | ||
# update the bookmark name. This can result in the revision pulled | ||||
# not ending up with the name of the bookmark because of a race | ||||
# condition on the server. (See issue 4689 for details) | ||||
Pierre-Yves David
|
r25367 | remotebookmarks = other.listkeys('bookmarks') | ||
Pierre-Yves David
|
r25446 | pullopargs['remotebookmarks'] = remotebookmarks | ||
Piotr Klecha
|
r20576 | for b in opts['bookmark']: | ||
liscju
|
r29376 | b = repo._bookmarks.expandname(b) | ||
Piotr Klecha
|
r20576 | if b not in remotebookmarks: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('remote bookmark %s not found!') % b) | ||
Piotr Klecha
|
r20576 | revs.append(remotebookmarks[b]) | ||
if revs: | ||||
try: | ||||
Pierre-Yves David
|
r25368 | # When 'rev' is a bookmark name, we cannot guarantee that it | ||
# will be updated with that name because of a race condition | ||||
# server side. (See issue 4689 for details) | ||||
Pierre-Yves David
|
r25425 | oldrevs = revs | ||
revs = [] # actually, nodes | ||||
for r in oldrevs: | ||||
node = other.lookup(r) | ||||
revs.append(node) | ||||
if r == checkout: | ||||
checkout = node | ||||
Piotr Klecha
|
r20576 | except error.CapabilityError: | ||
err = _("other repository doesn't support revision lookup, " | ||||
"so a rev cannot be specified.") | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(err) | ||
Piotr Klecha
|
r20576 | |||
Sean Farley
|
r26810 | pullopargs.update(opts.get('opargs', {})) | ||
Pierre-Yves David
|
r22694 | modheads = exchange.pull(repo, other, heads=revs, | ||
force=opts.get('force'), | ||||
Pierre-Yves David
|
r25445 | bookmarks=opts.get('bookmark', ()), | ||
opargs=pullopargs).cgresult | ||||
FUJIWARA Katsunori
|
r28269 | |||
# brev is a name, which might be a bookmark to be activated at | ||||
# the end of the update. In other words, it is an explicit | ||||
# destination of the update | ||||
brev = None | ||||
Piotr Klecha
|
r20576 | if checkout: | ||
Pierre-Yves David
|
r25425 | checkout = str(repo.changelog.rev(checkout)) | ||
FUJIWARA Katsunori
|
r28269 | |||
# order below depends on implementation of | ||||
# hg.addbranchrevs(). opts['bookmark'] is ignored, | ||||
# because 'checkout' is determined without it. | ||||
if opts.get('rev'): | ||||
brev = opts['rev'][0] | ||||
elif opts.get('branch'): | ||||
brev = opts['branch'][0] | ||||
else: | ||||
brev = branches[0] | ||||
Piotr Klecha
|
r20576 | repo._subtoppath = source | ||
Bryan O'Sullivan
|
r5259 | try: | ||
FUJIWARA Katsunori
|
r28269 | ret = postincoming(ui, repo, modheads, opts.get('update'), | ||
checkout, brev) | ||||
Piotr Klecha
|
r20576 | |||
finally: | ||||
del repo._subtoppath | ||||
Mads Kiilerich
|
r12852 | finally: | ||
Piotr Klecha
|
r20576 | other.close() | ||
Matt Mackall
|
r13368 | 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. | ||||
FUJIWARA Katsunori
|
r19935 | .. note:: | ||
Simon Heimberg
|
r19997 | |||
timeless
|
r27471 | Extra care should be taken with the -f/--force option, | ||
which will push all new heads on all branches, an action which will | ||||
almost always cause confusion for collaborators. | ||||
Faheem Mitha
|
r11217 | |||
If -r/--rev is used, the specified revision and all its ancestors | ||||
will be pushed to the remote repository. | ||||
Bill Barry
|
r7693 | |||
Augie Fackler
|
r17190 | If -B/--bookmark is used, the specified bookmarked revision, its | ||
ancestors, and the bookmark will be pushed to the remote | ||||
liscju
|
r28182 | repository. Specifying ``.`` is equivalent to specifying the active | ||
bookmark's name. | ||||
Augie Fackler
|
r17190 | |||
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 | |||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Matt Mackall
|
r13368 | if opts.get('bookmark'): | ||
Mads Kiilerich
|
r20790 | ui.setconfig('bookmarks', 'pushing', opts['bookmark'], 'push') | ||
Matt Mackall
|
r13368 | for b in opts['bookmark']: | ||
# translate -B options to -r so changesets get pushed | ||||
liscju
|
r28182 | b = repo._bookmarks.expandname(b) | ||
Matt Mackall
|
r13368 | 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") | ||||
Yuya Nishihara
|
r27562 | path = ui.paths.getpath(dest, default=('default-push', 'default')) | ||
Gregory Szorc
|
r26057 | if not path: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('default repository not configured!'), | ||
timeless
|
r29965 | hint=_("see 'hg help config.paths'")) | ||
Gregory Szorc
|
r27264 | dest = path.pushloc or path.loc | ||
branches = (path.branch, opts.get('branch') or []) | ||||
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')) | ||
Gregory Szorc
|
r26057 | other = hg.peer(repo, opts, dest) | ||
anuraggoel
|
r20558 | |||
Matt Mackall
|
r4478 | if revs: | ||
Pierre-Yves David
|
r17168 | revs = [repo.lookup(r) for r in scmutil.revrange(repo, revs)] | ||
Gregory Szorc
|
r24429 | if not revs: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("specified revisions evaluate to an empty set"), | ||
Gregory Szorc
|
r24429 | hint=_("use different revision arguments")) | ||
Gregory Szorc
|
r29413 | elif path.pushrev: | ||
# It doesn't make any sense to specify ancestor revisions. So limit | ||||
# to DAG heads to make discovery simpler. | ||||
Yuya Nishihara
|
r31024 | expr = revsetlang.formatspec('heads(%r)', path.pushrev) | ||
Gregory Szorc
|
r29413 | revs = scmutil.revrange(repo, [expr]) | ||
revs = [repo[rev].node() for rev in revs] | ||||
if not revs: | ||||
raise error.Abort(_('default push revset for path evaluates to an ' | ||||
'empty set')) | ||||
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
|
r21034 | result = c.sub(s).push(opts) | ||
if result == 0: | ||||
return not result | ||||
Mads Kiilerich
|
r12852 | finally: | ||
del repo._subtoppath | ||||
Pierre-Yves David
|
r22617 | pushop = exchange.push(repo, other, opts.get('force'), revs=revs, | ||
Pierre-Yves David
|
r22623 | newbranch=opts.get('new_branch'), | ||
Sean Farley
|
r26809 | bookmarks=opts.get('bookmark', ()), | ||
opargs=opts.get('opargs')) | ||||
Pierre-Yves David
|
r22617 | |||
result = not pushop.cgresult | ||||
Matt Mackall
|
r13368 | |||
Pierre-Yves David
|
r22625 | if pushop.bkresult is not None: | ||
if pushop.bkresult == 2: | ||||
Pierre-Yves David
|
r22621 | result = 2 | ||
Pierre-Yves David
|
r22625 | elif not result and pushop.bkresult: | ||
FUJIWARA Katsunori
|
r20026 | result = 2 | ||
Matt Mackall
|
r13368 | |||
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, | ||||
liscju
|
r28902 | _('forget added files, delete modified files')), | ||
Matt Harbison
|
r23325 | ] + subrepoopts + walkopts, | ||
Gregory Szorc
|
r21778 | _('[OPTION]... FILE...'), | ||
inferrepo=True) | ||||
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 | |||
FUJIWARA Katsunori
|
r19960 | ========= == == == == | ||
opt/state A C M ! | ||||
========= == == == == | ||||
none W RD W R | ||||
-f R RD RD R | ||||
-A W W W R | ||||
-Af R R R R | ||||
========= == == == == | ||||
Vadim Gelfer
|
r2309 | |||
timeless
|
r27489 | .. note:: | ||
:hg:`remove` never deletes files in Added [A] state from the | ||||
working directory, not even if ``--force`` is specified. | ||||
Matt Mackall
|
r11177 | |||
Returns 0 on success, 1 if any warnings encountered. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Dirkjan Ochtman
|
r6346 | |||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Dirkjan Ochtman
|
r6346 | after, force = opts.get('after'), opts.get('force') | ||
if not pats and not after: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('no files specified')) | ||
Dirkjan Ochtman
|
r6346 | |||
Matt Mackall
|
r14671 | m = scmutil.match(repo[None], pats, opts) | ||
Matt Harbison
|
r23325 | subrepos = opts.get('subrepos') | ||
return cmdutil.remove(ui, repo, m, "", after, force, subrepos) | ||||
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 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Bryan O'Sullivan
|
r27857 | with repo.wlock(False): | ||
Matt Mackall
|
r5610 | return cmdutil.copy(ui, repo, pats, opts, rename=True) | ||
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'))] | ||||
Yuya Nishihara
|
r24127 | + mergetoolopts + walkopts + formatteropts, | ||
Gregory Szorc
|
r21778 | _('[OPTION]... [FILE]...'), | ||
inferrepo=True) | ||||
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. | ||||
Yuya Nishihara
|
r31022 | You can use ``set:unresolved()`` or ``set:resolved()`` to filter | ||
the list. See :hg:`help filesets` for details. | ||||
Mark Edgington
|
r11836 | |||
timeless
|
r27490 | .. note:: | ||
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 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
timeless
|
r28402 | flaglist = 'all mark unmark list no_status'.split() | ||
timeless
|
r9646 | all, mark, unmark, show, nostatus = \ | ||
timeless
|
r28402 | [opts.get(o) for o in flaglist] | ||
Matt Mackall
|
r7527 | |||
if (show and (mark or unmark)) or (mark and unmark): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("too many options specified")) | ||
Matt Mackall
|
r7527 | if pats and all: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("can't specify --all and patterns")) | ||
Matt Mackall
|
r7527 | if not (all or pats or show or mark or unmark): | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('no files or directories specified'), | ||
timeless@mozdev.org
|
r26352 | hint=('use --all to re-merge all unresolved files')) | ||
Matt Mackall
|
r6518 | |||
Yuya Nishihara
|
r24126 | if show: | ||
Augie Fackler
|
r31043 | ui.pager('resolve') | ||
Yuya Nishihara
|
r24127 | fm = ui.formatter('resolve', opts) | ||
Siddharth Agarwal
|
r26993 | ms = mergemod.mergestate.read(repo) | ||
Yuya Nishihara
|
r24126 | m = scmutil.match(repo[None], pats, opts) | ||
for f in ms: | ||||
if not m(f): | ||||
continue | ||||
Siddharth Agarwal
|
r26764 | l = 'resolve.' + {'u': 'unresolved', 'r': 'resolved', | ||
'd': 'driverresolved'}[ms[f]] | ||||
Yuya Nishihara
|
r24127 | fm.startitem() | ||
fm.condwrite(not nostatus, 'status', '%s ', ms[f].upper(), label=l) | ||||
fm.write('path', '%s\n', f, label=l) | ||||
fm.end() | ||||
Yuya Nishihara
|
r24126 | return 0 | ||
Bryan O'Sullivan
|
r27856 | with repo.wlock(): | ||
Siddharth Agarwal
|
r26993 | ms = mergemod.mergestate.read(repo) | ||
Matt Mackall
|
r21720 | |||
Yuya Nishihara
|
r24126 | if not (ms.active() or repo.dirstate.p2() != nullid): | ||
Pierre-Yves David
|
r26587 | raise error.Abort( | ||
Matt Mackall
|
r21720 | _('resolve command not applicable when not merging')) | ||
Siddharth Agarwal
|
r26783 | wctx = repo[None] | ||
Siddharth Agarwal
|
r26788 | if ms.mergedriver and ms.mdstate() == 'u': | ||
proceed = mergemod.driverpreprocess(repo, ms, wctx) | ||||
ms.commit() | ||||
# allow mark and unmark to go through | ||||
if not mark and not unmark and not proceed: | ||||
return 1 | ||||
Siddharth Agarwal
|
r26783 | m = scmutil.match(wctx, pats, opts) | ||
Mads Kiilerich <madski at unity3d.com>
|
r21709 | ret = 0 | ||
Matt Mackall
|
r21720 | didwork = False | ||
Siddharth Agarwal
|
r26789 | runconclude = False | ||
Mads Kiilerich <madski at unity3d.com>
|
r21709 | |||
Siddharth Agarwal
|
r26621 | tocomplete = [] | ||
Mads Kiilerich <madski at unity3d.com>
|
r21709 | for f in ms: | ||
Matt Mackall
|
r21720 | if not m(f): | ||
continue | ||||
didwork = True | ||||
Siddharth Agarwal
|
r26789 | # don't let driver-resolved files be marked, and run the conclude | ||
# step if asked to resolve | ||||
Siddharth Agarwal
|
r26784 | if ms[f] == "d": | ||
exact = m.exact(f) | ||||
if mark: | ||||
if exact: | ||||
ui.warn(_('not marking %s as it is driver-resolved\n') | ||||
% f) | ||||
elif unmark: | ||||
if exact: | ||||
ui.warn(_('not unmarking %s as it is driver-resolved\n') | ||||
% f) | ||||
Siddharth Agarwal
|
r26789 | else: | ||
runconclude = True | ||||
Siddharth Agarwal
|
r26784 | continue | ||
Yuya Nishihara
|
r24126 | if mark: | ||
Matt Mackall
|
r21720 | ms.mark(f, "r") | ||
elif unmark: | ||||
ms.mark(f, "u") | ||||
Matt Mackall
|
r6518 | else: | ||
Matt Mackall
|
r21720 | # backup pre-resolve (merge uses .orig for its own purposes) | ||
a = repo.wjoin(f) | ||||
Siddharth Agarwal
|
r26899 | try: | ||
util.copyfile(a, a + ".resolve") | ||||
except (IOError, OSError) as inst: | ||||
if inst.errno != errno.ENOENT: | ||||
raise | ||||
Matt Mackall
|
r21720 | |||
try: | ||||
Siddharth Agarwal
|
r26621 | # preresolve file | ||
Matt Mackall
|
r21720 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), | ||
'resolve') | ||||
Siddharth Agarwal
|
r26617 | complete, r = ms.preresolve(f, wctx) | ||
if not complete: | ||||
Siddharth Agarwal
|
r26621 | tocomplete.append(f) | ||
elif r: | ||||
Matt Mackall
|
r21720 | ret = 1 | ||
finally: | ||||
ui.setconfig('ui', 'forcemerge', '', 'resolve') | ||||
ms.commit() | ||||
Siddharth Agarwal
|
r26959 | # replace filemerge's .orig file with our resolve file, but only | ||
# for merges that are complete | ||||
if complete: | ||||
Matt Mackall
|
r27010 | try: | ||
util.rename(a + ".resolve", | ||||
Siddharth Agarwal
|
r27651 | scmutil.origpath(ui, repo, a)) | ||
Matt Mackall
|
r27010 | except OSError as inst: | ||
if inst.errno != errno.ENOENT: | ||||
raise | ||||
Mads Kiilerich <madski at unity3d.com>
|
r21709 | |||
Siddharth Agarwal
|
r26621 | for f in tocomplete: | ||
try: | ||||
# resolve file | ||||
ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), | ||||
'resolve') | ||||
r = ms.resolve(f, wctx) | ||||
if r: | ||||
ret = 1 | ||||
finally: | ||||
ui.setconfig('ui', 'forcemerge', '', 'resolve') | ||||
ms.commit() | ||||
Siddharth Agarwal
|
r26959 | # replace filemerge's .orig file with our resolve file | ||
a = repo.wjoin(f) | ||||
Siddharth Agarwal
|
r27025 | try: | ||
Siddharth Agarwal
|
r27651 | util.rename(a + ".resolve", scmutil.origpath(ui, repo, a)) | ||
Siddharth Agarwal
|
r27025 | except OSError as inst: | ||
if inst.errno != errno.ENOENT: | ||||
raise | ||||
Siddharth Agarwal
|
r26959 | |||
Mads Kiilerich <madski at unity3d.com>
|
r21709 | ms.commit() | ||
Siddharth Agarwal
|
r27089 | ms.recordactions() | ||
Matt Mackall
|
r21720 | |||
Yuya Nishihara
|
r24126 | if not didwork and pats: | ||
timeless
|
r28402 | hint = None | ||
if not any([p for p in pats if p.find(':') >= 0]): | ||||
pats = ['path:%s' % p for p in pats] | ||||
m = scmutil.match(wctx, pats, opts) | ||||
for f in ms: | ||||
if not m(f): | ||||
continue | ||||
flags = ''.join(['-%s ' % o[0] for o in flaglist | ||||
if opts.get(o)]) | ||||
hint = _("(try: hg resolve %s%s)\n") % ( | ||||
flags, | ||||
' '.join(pats)) | ||||
break | ||||
Matt Mackall
|
r21721 | ui.warn(_("arguments do not match paths that need resolving\n")) | ||
timeless
|
r28402 | if hint: | ||
ui.warn(hint) | ||||
Siddharth Agarwal
|
r26789 | elif ms.mergedriver and ms.mdstate() != 's': | ||
# run conclude step when either a driver-resolved file is requested | ||||
# or there are no driver-resolved files | ||||
# we can't use 'ret' to determine whether any files are unresolved | ||||
# because we might not have tried to resolve some | ||||
if ((runconclude or not list(ms.driverresolved())) | ||||
and not list(ms.unresolved())): | ||||
proceed = mergemod.driverconclude(repo, ms, wctx) | ||||
ms.commit() | ||||
if not proceed: | ||||
return 1 | ||||
Matt Mackall
|
r21720 | |||
Yuya Nishihara
|
r24126 | # Nudge users into finishing an unfinished operation | ||
Siddharth Agarwal
|
r26770 | unresolvedf = list(ms.unresolved()) | ||
driverresolvedf = list(ms.driverresolved()) | ||||
if not unresolvedf and not driverresolvedf: | ||||
Pierre-Yves David
|
r21947 | ui.status(_('(no more unresolved files)\n')) | ||
timeless
|
r27624 | cmdutil.checkafterresolved(repo) | ||
Siddharth Agarwal
|
r26770 | elif not unresolvedf: | ||
ui.status(_('(no more unresolved files -- ' | ||||
'run "hg resolve --all" to conclude)\n')) | ||||
Gregory Szorc
|
r21266 | |||
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')), | ||
Laurent Charignon
|
r24873 | ('i', 'interactive', None, | ||
_('interactively select the changes (EXPERIMENTAL)')), | ||||
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:: | ||
Simon Heimberg
|
r19997 | |||
Matt Mackall
|
r14541 | To check out earlier revisions, you should use :hg:`update REV`. | ||
Matt Mackall
|
r19217 | To cancel an uncommitted 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. | ||
Nathan Goldbaum
|
r29061 | To disable these backups, use --no-backup. It is possible to store | ||
the backup files in a custom directory relative to the root of the | ||||
repository by setting the ``ui.origbackuppath`` configuration | ||||
option. | ||||
Matt Mackall
|
r11177 | |||
Matt Mackall
|
r14544 | See :hg:`help dates` for a list of formats valid for -d/--date. | ||
Mathias De Maré
|
r26477 | See :hg:`help backout` for a way to reverse the effect of an | ||
earlier changeset. | ||||
Matt Mackall
|
r11177 | Returns 0 on success. | ||
Benoit Boissinot
|
r1437 | """ | ||
Vadim Gelfer
|
r2982 | |||
Xavier Snelgrove
|
r11941 | if opts.get("date"): | ||
if opts.get("rev"): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("you can't specify a revision and a date")) | ||
Matt Mackall
|
r3814 | 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) | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('uncommitted merge with no revision specified'), | ||
timeless
|
r28961 | hint=_("use 'hg update' or see 'hg help revert'")) | ||
Matt Mackall
|
r14903 | |||
Adrian Buehlmann
|
r14726 | ctx = scmutil.revsingle(repo, opts.get('rev')) | ||
timeless
|
r13022 | |||
Martin von Zweigbergk
|
r24841 | if (not (pats or opts.get('include') or opts.get('exclude') or | ||
opts.get('all') or opts.get('interactive'))): | ||||
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") | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(msg, hint=hint) | ||
Augie Fackler
|
r25149 | dirty = 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") | ||||
Pierre-Yves David
|
r26587 | raise error.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
|
r19409 | """roll back the last transaction (DANGEROUS) (DEPRECATED) | ||
Matt Mackall
|
r5575 | |||
Martin Geisler
|
r19421 | Please use :hg:`commit --amend` instead of rollback to correct | ||
mistakes in the last commit. | ||||
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 | ||||
Adrian Buehlmann
|
r17141 | repository. | ||
Adrian Buehlmann
|
r17142 | .. container:: verbose | ||
For example, the following commands are transactional, and their | ||||
effects can be rolled back: | ||||
- commit | ||||
- import | ||||
- pull | ||||
- push (with this repository as the destination) | ||||
- unbundle | ||||
To avoid permanent data loss, rollback will refuse to rollback a | ||||
commit transaction if it isn't checked out. Use --force to | ||||
override this protection. | ||||
Greg Ward
|
r15183 | |||
Augie Fackler
|
r29086 | The rollback command can be entirely disabled by setting the | ||
``ui.rollback`` configuration setting to false. If you're here | ||||
because you want to use rollback and it's disabled, you can | ||||
re-enable the command by setting ``ui.rollback`` to true. | ||||
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 | """ | ||
Augie Fackler
|
r29086 | if not ui.configbool('ui', 'rollback', True): | ||
raise error.Abort(_('rollback is disabled because it is unsafe'), | ||||
hint=('see `hg help -v rollback` for information')) | ||||
Pulkit Goyal
|
r32146 | return repo.rollback(dryrun=opts.get(r'dry_run'), | ||
force=opts.get(r'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')), | ||||
Jun Wu
|
r28451 | ('', 'daemon-postexec', [], _('used internally by daemon mode')), | ||
Adrian Buehlmann
|
r14297 | ('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', '', | ||||
timeless
|
r29972 | _("name of the hgweb config file (see 'hg help hgweb')"), _('FILE')), | ||
Adrian Buehlmann
|
r14297 | ('', 'webdir-conf', '', _('name of the hgweb config file (DEPRECATED)'), | ||
_('FILE')), | ||||
('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')), | ||||
Jun Wu
|
r31081 | ('', 'stdio', None, _('for remote clients (ADVANCED)')), | ||
('', 'cmdserver', '', _('for remote clients (ADVANCED)'), _('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')), | ||||
Matt Harbison
|
r32005 | ('', 'certificate', '', _('SSL certificate file'), _('FILE'))] | ||
+ subrepoopts, | ||||
Gregory Szorc
|
r21775 | _('[OPTION]...'), | ||
optionalrepo=True) | ||||
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 | |||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Idan Kamara
|
r14647 | if opts["stdio"] and opts["cmdserver"]: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("cannot use --stdio with --cmdserver")) | ||
Idan Kamara
|
r14647 | |||
Yuya Nishihara
|
r21818 | if opts["stdio"]: | ||
Thomas Arendsen Hein
|
r2127 | if repo is None: | ||
Martin Geisler
|
r16935 | raise error.RepoError(_("there is no Mercurial repository here" | ||
Yuya Nishihara
|
r21819 | " (.hg not found)")) | ||
Vadim Gelfer
|
r2396 | s = sshserver.sshserver(ui, repo) | ||
s.serve_forever() | ||||
Matt Mackall
|
r2363 | |||
Yuya Nishihara
|
r30510 | service = server.createservice(ui, repo, opts) | ||
Yuya Nishihara
|
r30506 | return server.runservice(opts, initfn=service.init, runfn=service.run) | ||
Mads Kiilerich
|
r19919 | |||
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')), | ||||
Matt Mackall
|
r22429 | ] + walkopts + subrepoopts + formatteropts, | ||
Gregory Szorc
|
r21778 | _('[OPTION]... [FILE]...'), | ||
inferrepo=True) | ||||
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:: | ||
Simon Heimberg
|
r19997 | |||
timeless
|
r27476 | :hg:`status` may appear to disagree with diff if permissions have | ||
Christian Ebert
|
r12390 | 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 | ||||
Matt Mackall
|
r20660 | = origin of the previous file (with --copies) | ||
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 | ||||
Yung-Jin (Joey) Hu
|
r24456 | - show changes in the working directory relative to the | ||
current directory (see :hg:`help patterns` for more information):: | ||||
hg status re: | ||||
Matt Mackall
|
r15119 | - 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 | |||
Pulkit Goyal
|
r31427 | opts = pycompat.byteskwargs(opts) | ||
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') | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(msg) | ||
Gilles Moris
|
r10014 | 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 | |||
Martin von Zweigbergk
|
r31589 | if pats or ui.configbool('commands', 'status.relative'): | ||
Jordi Gutiérrez Hermoso
|
r24306 | cwd = repo.getcwd() | ||
else: | ||||
cwd = '' | ||||
if opts.get('print0'): | ||||
end = '\0' | ||||
else: | ||||
end = '\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: | ||||
Jordi Gutiérrez Hermoso
|
r24306 | if ui.quiet: | ||
show = states[:4] | ||||
else: | ||||
show = states[:5] | ||||
Matt Mackall
|
r6605 | |||
Martin von Zweigbergk
|
r24819 | m = scmutil.match(repo[node2], pats, opts) | ||
stat = repo.status(node1, node2, m, | ||||
Martin Geisler
|
r12166 | 'ignored' in show, 'clean' in show, 'unknown' in show, | ||
opts.get('subrepos')) | ||||
Pulkit Goyal
|
r31463 | changestates = zip(states, pycompat.iterbytestr('MAR!?IC'), stat) | ||
Matt Mackall
|
r6605 | |||
Mathias De Maré
|
r24663 | if (opts.get('all') or opts.get('copies') | ||
or ui.configbool('ui', 'statuscopies')) and not opts.get('no_status'): | ||||
Martin von Zweigbergk
|
r24819 | copy = copies.pathcopies(repo[node1], repo[node2], m) | ||
Matt Mackall
|
r6276 | |||
Augie Fackler
|
r31044 | ui.pager('status') | ||
Matt Mackall
|
r16136 | fm = ui.formatter('status', opts) | ||
Matt Mackall
|
r17910 | fmt = '%s' + end | ||
showchar = not opts.get('no_status') | ||||
Matt Mackall
|
r16136 | |||
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
|
r17910 | fm.condwrite(showchar, 'status', '%s ', char, label=label) | ||
fm.write('path', fmt, 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, | ||||
Gilles Moris
|
r25111 | including parents, branch, commit status, phase 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 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Augie Fackler
|
r31045 | ui.pager('summary') | ||
Matt Mackall
|
r9603 | ctx = repo[None] | ||
parents = ctx.parents() | ||||
pnode = parents[0].node() | ||||
Augie Fackler
|
r14906 | marks = [] | ||
Matt Mackall
|
r9603 | |||
timeless
|
r28641 | ms = None | ||
try: | ||||
ms = mergemod.mergestate.read(repo) | ||||
except error.UnsupportedMergeRecords as e: | ||||
s = ' '.join(e.recordtypes) | ||||
ui.warn( | ||||
_('warning: merge state has unsupported record types: %s\n') % s) | ||||
unresolved = 0 | ||||
else: | ||||
unresolved = [f for f in ms if ms[f] == 'u'] | ||||
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*: | ||||
FUJIWARA Katsunori
|
r17892 | # i18n: column positioning for "hg summary" | ||
Augie Fackler
|
r31345 | ui.write(_('parent: %d:%s ') % (p.rev(), p), | ||
Denis Laxalde
|
r30714 | label=cmdutil._changesetlabels(p)) | ||
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)')) | ||
Denis Laxalde
|
r31703 | if p.obsolete(): | ||
ui.write(_(' (obsolete)')) | ||||
Denis Laxalde
|
r30715 | if p.troubled(): | ||
Denis Laxalde
|
r30721 | ui.write(' (' | ||
+ ', '.join(ui.label(trouble, 'trouble.%s' % trouble) | ||||
for trouble in p.troubles()) | ||||
+ ')') | ||||
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) | ||||
FUJIWARA Katsunori
|
r17892 | # i18n: column positioning for "hg summary" | ||
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: | ||
Ryan McElroy
|
r25349 | active = repo._activebookmark | ||
FUJIWARA Katsunori
|
r17892 | # i18n: column positioning for "hg summary" | ||
Augie Fackler
|
r14907 | ui.write(_('bookmarks:'), label='log.bookmark') | ||
Ryan McElroy
|
r25349 | if active is not None: | ||
if active in marks: | ||||
ui.write(' *' + active, label=activebookmarklabel) | ||||
marks.remove(active) | ||||
Kevin Bullock
|
r18622 | else: | ||
Ryan McElroy
|
r25349 | ui.write(' [%s]' % active, label=activebookmarklabel) | ||
Augie Fackler
|
r14907 | for m in marks: | ||
Mads Kiilerich
|
r17299 | ui.write(' ' + m, label='log.bookmark') | ||
Augie Fackler
|
r14907 | ui.write('\n', label='log.bookmark') | ||
Augie Fackler
|
r14906 | |||
Martin von Zweigbergk
|
r22926 | status = repo.status(unknown=True) | ||
Matt Mackall
|
r11088 | |||
Matt Mackall
|
r11331 | c = repo.dirstate.copies() | ||
copied, renamed = [], [] | ||||
for d, s in c.iteritems(): | ||||
Martin von Zweigbergk
|
r22926 | if s in status.removed: | ||
status.removed.remove(s) | ||||
Matt Mackall
|
r11331 | renamed.append(d) | ||
else: | ||||
copied.append(d) | ||||
Martin von Zweigbergk
|
r22926 | if d in status.added: | ||
status.added.remove(d) | ||||
Matt Mackall
|
r11331 | |||
Matt Mackall
|
r11088 | subs = [s for s in ctx.substate if ctx.sub(s).dirty()] | ||
Martin von Zweigbergk
|
r22926 | |||
labels = [(ui.label(_('%d modified'), 'status.modified'), status.modified), | ||||
(ui.label(_('%d added'), 'status.added'), status.added), | ||||
(ui.label(_('%d removed'), 'status.removed'), status.removed), | ||||
(ui.label(_('%d renamed'), 'status.copied'), renamed), | ||||
(ui.label(_('%d copied'), 'status.copied'), copied), | ||||
(ui.label(_('%d deleted'), 'status.deleted'), status.deleted), | ||||
(ui.label(_('%d unknown'), 'status.unknown'), status.unknown), | ||||
(ui.label(_('%d unresolved'), 'resolve.unresolved'), unresolved), | ||||
(ui.label(_('%d subrepos'), 'status.modified'), subs)] | ||||
Matt Mackall
|
r9603 | t = [] | ||
Martin von Zweigbergk
|
r22926 | for l, s in 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 | |||
timeless
|
r27172 | if repo.vfs.exists('graftstate'): | ||
t += _(' (graft in progress)') | ||||
Matt Mackall
|
r19482 | if repo.vfs.exists('updatestate'): | ||
t += _(' (interrupted update)') | ||||
elif len(parents) > 1: | ||||
Steve Borho
|
r11310 | t += _(' (merge)') | ||
Matt Mackall
|
r9603 | elif branch != parents[0].branch(): | ||
Steve Borho
|
r11310 | t += _(' (new branch)') | ||
Brodie Rao
|
r16720 | elif (parents[0].closesbranch() and | ||
Gilles Moris
|
r11165 | pnode in repo.branchheads(branch, closed=True)): | ||
Steve Borho
|
r11310 | t += _(' (head closed)') | ||
Martin von Zweigbergk
|
r22926 | elif not (status.modified or status.added or status.removed or renamed or | ||
copied or subs): | ||||
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 | |||
Gilles Moris
|
r25382 | if parents: | ||
pendingphase = max(p.phase() for p in parents) | ||||
else: | ||||
pendingphase = phases.public | ||||
if pendingphase > phases.newcommitphase(ui): | ||||
t += ' (%s)' % phases.phasenames[pendingphase] | ||||
FUJIWARA Katsunori
|
r10269 | if cleanworkdir: | ||
FUJIWARA Katsunori
|
r17892 | # i18n: column positioning for "hg summary" | ||
Steve Borho
|
r11310 | ui.status(_('commit: %s\n') % t.strip()) | ||
Matt Mackall
|
r9605 | else: | ||
FUJIWARA Katsunori
|
r17892 | # i18n: column positioning for "hg summary" | ||
Steve Borho
|
r11310 | ui.write(_('commit: %s\n') % t.strip()) | ||
Matt Mackall
|
r9603 | |||
# all ancestors of branch heads - all ancestors of parent = new csets | ||||
Mads Kiilerich
|
r22201 | new = len(repo.changelog.findmissing([pctx.node() for pctx in parents], | ||
Siddharth Agarwal
|
r19394 | bheads)) | ||
Matt Mackall
|
r9603 | |||
if new == 0: | ||||
FUJIWARA Katsunori
|
r17892 | # i18n: column positioning for "hg summary" | ||
Matt Mackall
|
r9605 | ui.status(_('update: (current)\n')) | ||
Matt Mackall
|
r9603 | elif pnode not in bheads: | ||
FUJIWARA Katsunori
|
r17892 | # i18n: column positioning for "hg summary" | ||
Matt Mackall
|
r9603 | ui.write(_('update: %d new changesets (update)\n') % new) | ||
else: | ||||
FUJIWARA Katsunori
|
r17892 | # i18n: column positioning for "hg summary" | ||
Matt Mackall
|
r9603 | ui.write(_('update: %d new changesets, %d branch heads (merge)\n') % | ||
(new, len(bheads))) | ||||
Gilles Moris
|
r25111 | t = [] | ||
draft = len(repo.revs('draft()')) | ||||
if draft: | ||||
t.append(_('%d draft') % draft) | ||||
secret = len(repo.revs('secret()')) | ||||
if secret: | ||||
t.append(_('%d secret') % secret) | ||||
if draft or secret: | ||||
Gilles Moris
|
r25382 | ui.status(_('phases: %s\n') % ', '.join(t)) | ||
Gilles Moris
|
r25111 | |||
Laurent Charignon
|
r27385 | if obsolete.isenabled(repo, obsolete.createmarkersopt): | ||
for trouble in ("unstable", "divergent", "bumped"): | ||||
numtrouble = len(repo.revs(trouble + "()")) | ||||
# We write all the possibilities to ease translation | ||||
troublemsg = { | ||||
Matt Harbison
|
r27722 | "unstable": _("unstable: %d changesets"), | ||
"divergent": _("divergent: %d changesets"), | ||||
"bumped": _("bumped: %d changesets"), | ||||
Laurent Charignon
|
r27385 | } | ||
if numtrouble > 0: | ||||
ui.status(troublemsg[trouble] % numtrouble + "\n") | ||||
Bryan O'Sullivan
|
r19211 | cmdutil.summaryhooks(ui, repo) | ||
Matt Mackall
|
r9620 | if opts.get('remote'): | ||
FUJIWARA Katsunori
|
r21045 | needsincoming, needsoutgoing = True, True | ||
else: | ||||
needsincoming, needsoutgoing = False, False | ||||
FUJIWARA Katsunori
|
r21047 | for i, o in cmdutil.summaryremotehooks(ui, repo, opts, None): | ||
if i: | ||||
needsincoming = True | ||||
if o: | ||||
needsoutgoing = True | ||||
if not needsincoming and not needsoutgoing: | ||||
return | ||||
FUJIWARA Katsunori
|
r21045 | |||
def getincoming(): | ||||
Sune Foldager
|
r10389 | source, branches = hg.parseurl(ui.expandpath('default')) | ||
FUJIWARA Katsunori
|
r18997 | sbranch = branches[0] | ||
FUJIWARA Katsunori
|
r21047 | try: | ||
other = hg.peer(repo, {}, source) | ||||
except error.RepoError: | ||||
if opts.get('remote'): | ||||
raise | ||||
return source, sbranch, None, None, None | ||||
Simon Heimberg
|
r19379 | revs, checkout = hg.addbranchrevs(repo, other, branches, None) | ||
FUJIWARA Katsunori
|
r18996 | if revs: | ||
revs = [other.lookup(rev) for rev in revs] | ||||
Brodie Rao
|
r14076 | ui.debug('comparing with %s\n' % util.hidepassword(source)) | ||
Matt Mackall
|
r9620 | repo.ui.pushbuffer() | ||
FUJIWARA Katsunori
|
r18996 | commoninc = discovery.findcommonincoming(repo, other, heads=revs) | ||
Matt Mackall
|
r9620 | repo.ui.popbuffer() | ||
FUJIWARA Katsunori
|
r21045 | return source, sbranch, other, commoninc, commoninc[1] | ||
if needsincoming: | ||||
source, sbranch, sother, commoninc, incoming = getincoming() | ||||
else: | ||||
source = sbranch = sother = commoninc = incoming = None | ||||
def getoutgoing(): | ||||
Sune Foldager
|
r10389 | dest, branches = hg.parseurl(ui.expandpath('default-push', 'default')) | ||
FUJIWARA Katsunori
|
r18997 | dbranch = branches[0] | ||
Sune Foldager
|
r10389 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) | ||
Peter Arrenbrecht
|
r14214 | if source != dest: | ||
FUJIWARA Katsunori
|
r21047 | try: | ||
dother = hg.peer(repo, {}, dest) | ||||
except error.RepoError: | ||||
if opts.get('remote'): | ||||
raise | ||||
return dest, dbranch, None, None | ||||
FUJIWARA Katsunori
|
r18997 | ui.debug('comparing with %s\n' % util.hidepassword(dest)) | ||
FUJIWARA Katsunori
|
r21047 | elif sother is None: | ||
# there is no explicit destination peer, but source one is invalid | ||||
return dest, dbranch, None, None | ||||
FUJIWARA Katsunori
|
r21045 | else: | ||
dother = sother | ||||
FUJIWARA Katsunori
|
r18997 | if (source != dest or (sbranch is not None and sbranch != dbranch)): | ||
FUJIWARA Katsunori
|
r21045 | common = None | ||
else: | ||||
common = commoninc | ||||
FUJIWARA Katsunori
|
r18994 | if revs: | ||
revs = [repo.lookup(rev) for rev in revs] | ||||
Matt Mackall
|
r9620 | repo.ui.pushbuffer() | ||
FUJIWARA Katsunori
|
r21045 | outgoing = discovery.findcommonoutgoing(repo, dother, onlyheads=revs, | ||
commoninc=common) | ||||
Matt Mackall
|
r9620 | repo.ui.popbuffer() | ||
FUJIWARA Katsunori
|
r21045 | return dest, dbranch, dother, outgoing | ||
if needsoutgoing: | ||||
dest, dbranch, dother, outgoing = getoutgoing() | ||||
else: | ||||
dest = dbranch = dother = outgoing = None | ||||
if opts.get('remote'): | ||||
t = [] | ||||
if incoming: | ||||
t.append(_('1 or more incoming')) | ||||
Pierre-Yves David
|
r15837 | o = outgoing.missing | ||
Matt Mackall
|
r9620 | if o: | ||
t.append(_('%d outgoing') % len(o)) | ||||
FUJIWARA Katsunori
|
r21045 | other = dother or sother | ||
David Soria Parra
|
r13454 | if 'bookmarks' in other.listkeys('namespaces'): | ||
FUJIWARA Katsunori
|
r24400 | counts = bookmarks.summary(repo, other) | ||
if counts[0] > 0: | ||||
t.append(_('%d incoming bookmarks') % counts[0]) | ||||
if counts[1] > 0: | ||||
t.append(_('%d outgoing bookmarks') % counts[1]) | ||||
Matt Mackall
|
r9620 | |||
if t: | ||||
FUJIWARA Katsunori
|
r17892 | # i18n: column positioning for "hg summary" | ||
Matt Mackall
|
r9620 | ui.write(_('remote: %s\n') % (', '.join(t))) | ||
else: | ||||
FUJIWARA Katsunori
|
r17892 | # i18n: column positioning for "hg summary" | ||
Matt Mackall
|
r9620 | ui.status(_('remote: (synced)\n')) | ||
FUJIWARA Katsunori
|
r21047 | cmdutil.summaryremotehooks(ui, repo, opts, | ||
((source, sbranch, sother, commoninc), | ||||
(dest, dbranch, dother, outgoing))) | ||||
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 | ||||
FUJIWARA Katsunori
|
r21952 | ('e', 'edit', None, _('invoke editor on commit messages')), | ||
FUJIWARA Katsunori
|
r21951 | ('m', 'message', '', _('use text as commit message'), _('TEXT')), | ||
Adrian Buehlmann
|
r14297 | ] + 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 | ||
Matt Mackall
|
r19402 | used. | ||
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 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
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)): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('tag names must be unique')) | ||
John Coomes
|
r6321 | for n in names: | ||
Kevin Bullock
|
r17821 | scmutil.checknewlabel(repo, n, 'tag') | ||
Mads Kiilerich
|
r15877 | if not n: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('tag names cannot consist entirely of ' | ||
Mads Kiilerich
|
r15877 | 'whitespace')) | ||
if opts.get('rev') and opts.get('remove'): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("--rev and --remove are incompatible")) | ||
Mads Kiilerich
|
r15877 | if opts.get('rev'): | ||
rev_ = opts['rev'] | ||||
message = opts.get('message') | ||||
if opts.get('remove'): | ||||
Jordi Gutiérrez Hermoso
|
r24306 | if opts.get('local'): | ||
expectedtype = 'local' | ||||
else: | ||||
expectedtype = 'global' | ||||
Mads Kiilerich
|
r15877 | for n in names: | ||
if not repo.tagtype(n): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("tag '%s' does not exist") % n) | ||
Mads Kiilerich
|
r15877 | if repo.tagtype(n) != expectedtype: | ||
if expectedtype == 'global': | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("tag '%s' is not a global tag") % n) | ||
Mads Kiilerich
|
r15877 | else: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("tag '%s' is not a local tag") % n) | ||
Yuya Nishihara
|
r25903 | rev_ = 'null' | ||
Mads Kiilerich
|
r15877 | 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(): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("tag '%s' already exists " | ||
Mads Kiilerich
|
r15877 | "(use -f to force)") % n) | ||
if not opts.get('local'): | ||||
p1, p2 = repo.dirstate.parents() | ||||
if p2 != nullid: | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_('uncommitted merge')) | ||
Mads Kiilerich
|
r15877 | bheads = repo.branchheads() | ||
if not opts.get('force') and bheads and p1 not in bheads: | ||||
Nathan Goldbaum
|
r30247 | raise error.Abort(_('working directory is not at a branch head ' | ||
'(use -f to force)')) | ||||
Mads Kiilerich
|
r15877 | 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) | ||||
FUJIWARA Katsunori
|
r22009 | if opts.get('remove'): | ||
editform = 'tag.remove' | ||||
else: | ||||
editform = 'tag.add' | ||||
Pulkit Goyal
|
r32192 | editor = cmdutil.getcommiteditor(editform=editform, | ||
**pycompat.strkwargs(opts)) | ||||
Mads Kiilerich
|
r15877 | |||
Brad Hall
|
r17260 | # don't allow tagging the null rev | ||
if (not opts.get('remove') and | ||||
scmutil.revsingle(repo, rev_).rev() == nullrev): | ||||
Pierre-Yves David
|
r26587 | raise error.Abort(_("cannot tag null revision")) | ||
Brad Hall
|
r17260 | |||
Pierre-Yves David
|
r31670 | tagsmod.tag(repo, names, r, message, opts.get('local'), | ||
opts.get('user'), date, editor=editor) | ||||
Mads Kiilerich
|
r15877 | finally: | ||
release(lock, wlock) | ||||
mpm@selenic.com
|
r401 | |||
Matt Mackall
|
r22429 | @command('tags', formatteropts, '') | ||
Matt Mackall
|
r17912 | def tags(ui, repo, **opts): | ||
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. | ||||
Thu Trang Pham
|
r27409 | When the -q/--quiet switch is used, only the tag name is printed. | ||
Matt Mackall
|
r11177 | |||
Returns 0 on success. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Thomas Arendsen Hein
|
r477 | |||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Augie Fackler
|
r31046 | ui.pager('tags') | ||
Matt Mackall
|
r17912 | fm = ui.formatter('tags', opts) | ||
Yuya Nishihara
|
r22701 | hexfunc = fm.hexfunc | ||
Osku Salerma
|
r5658 | tagtype = "" | ||
Matt Mackall
|
r8210 | for t, n in reversed(repo.tagslist()): | ||
Idan Kamara
|
r13893 | hn = hexfunc(n) | ||
Matt Mackall
|
r17912 | label = 'tags.normal' | ||
tagtype = '' | ||||
if repo.tagtype(t) == 'local': | ||||
label = 'tags.local' | ||||
tagtype = 'local' | ||||
fm.startitem() | ||||
fm.write('tag', '%s', t, label=label) | ||||
fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s' | ||||
Yuya Nishihara
|
r22553 | fm.condwrite(not ui.quiet, 'rev node', fmt, | ||
Matt Mackall
|
r17912 | repo.changelog.rev(n), hn, label=label) | ||
fm.condwrite(ui.verbose and tagtype, 'type', ' %s', | ||||
tagtype, label=label) | ||||
fm.plain('\n') | ||||
fm.end() | ||||
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): | ||
Matt Mackall
|
r19403 | """show the tip revision (DEPRECATED) | ||
Benoit Boissinot
|
r1437 | |||
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 | |||
Matt Mackall
|
r19403 | This command is deprecated, please use :hg:`heads` instead. | ||
Matt Mackall
|
r11177 | Returns 0 on success. | ||
Benoit Boissinot
|
r1437 | """ | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Robert Bachmann
|
r10152 | displayer = cmdutil.show_changeset(ui, repo, opts) | ||
Pierre-Yves David
|
r18464 | displayer.show(repo['tip']) | ||
Robert Bachmann
|
r10152 | 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): | ||
Gregory Szorc
|
r31795 | """apply one or more bundle files | ||
Apply one or more bundle files generated by :hg:`bundle`. | ||||
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 | |||
Bryan O'Sullivan
|
r27855 | with repo.lock(): | ||
Patrick Mezard
|
r6180 | for fname in fnames: | ||
Siddharth Agarwal
|
r17887 | f = hg.openpath(ui, fname) | ||
Pierre-Yves David
|
r21064 | gen = exchange.readbundle(ui, f, fname) | ||
Eric Sumner
|
r23891 | if isinstance(gen, bundle2.unbundle20): | ||
tr = repo.transaction('unbundle') | ||||
try: | ||||
Pierre-Yves David
|
r26796 | op = bundle2.applybundle(repo, gen, tr, source='unbundle', | ||
url='bundle:' + fname) | ||||
Eric Sumner
|
r23891 | tr.close() | ||
Pierre-Yves David
|
r26410 | except error.BundleUnknownFeatureError as exc: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_('%s: unknown bundle feature, %s') | ||
Pierre-Yves David
|
r26874 | % (fname, exc), | ||
hint=_("see https://mercurial-scm.org/" | ||||
"wiki/BundleFeature for more " | ||||
"information")) | ||||
Eric Sumner
|
r23891 | finally: | ||
if tr: | ||||
tr.release() | ||||
Pierre-Yves David
|
r26539 | changes = [r.get('return', 0) | ||
Eric Sumner
|
r23891 | for r in op.records['changegroup']] | ||
modheads = changegroup.combineresults(changes) | ||||
Gregory Szorc
|
r26758 | elif isinstance(gen, streamclone.streamcloneapplier): | ||
raise error.Abort( | ||||
_('packed bundles cannot be applied with ' | ||||
'"hg unbundle"'), | ||||
hint=_('use "hg debugapplystreamclonebundle"')) | ||||
Eric Sumner
|
r23891 | else: | ||
Augie Fackler
|
r26699 | modheads = gen.apply(repo, 'unbundle', 'bundle:' + fname) | ||
Matt Mackall
|
r22091 | |||
Pulkit Goyal
|
r32145 | return postincoming(ui, repo, modheads, opts.get(r'update'), None, None) | ||
mpm@selenic.com
|
r1218 | |||
Adrian Buehlmann
|
r14297 | @command('^update|up|checkout|co', | ||
[('C', 'clean', None, _('discard uncommitted changes (no backup)')), | ||||
Martin von Zweigbergk
|
r29018 | ('c', 'check', None, _('require clean working directory')), | ||
Martin von Zweigbergk
|
r31166 | ('m', 'merge', None, _('merge uncommitted changes')), | ||
Adrian Buehlmann
|
r14297 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), | ||
Mads Kiilerich
|
r21552 | ('r', 'rev', '', _('revision'), _('REV')) | ||
] + mergetoolopts, | ||||
Martin von Zweigbergk
|
r31166 | _('[-C|-c|-m] [-d DATE] [[-r] REV]')) | ||
Mads Kiilerich
|
r21552 | def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False, | ||
Martin von Zweigbergk
|
r31166 | merge=None, tool=None): | ||
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 | ||
Ryan McElroy
|
r25349 | current named branch and move the active bookmark (see :hg:`help | ||
Kevin Bullock
|
r15957 | bookmarks`). | ||
Kevin Bullock
|
r12688 | |||
Adrian Buehlmann
|
r17343 | Update sets the working directory's parent revision to the specified | ||
Adrian Buehlmann
|
r17143 | changeset (see :hg:`help parents`). | ||
Kevin Bullock
|
r16877 | If the changeset is not a descendant or ancestor of the working | ||
Pulkit Goyal
|
r30834 | directory's parent and there are uncommitted changes, 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 changeset. | ||||
Stuart W Marks
|
r9718 | |||
Adrian Buehlmann
|
r17218 | .. container:: verbose | ||
Martin von Zweigbergk
|
r31166 | The -C/--clean, -c/--check, and -m/--merge options control what | ||
happens if the working directory contains uncommitted changes. | ||||
Martin von Zweigbergk
|
r30964 | At most of one of them can be specified. | ||
1. If no option is specified, and if | ||||
Adrian Buehlmann
|
r17218 | the requested changeset is an ancestor or descendant of | ||
the working directory's parent, the uncommitted changes | ||||
are merged into the requested changeset and the merged | ||||
result is left uncommitted. If the requested changeset is | ||||
not an ancestor or descendant (that is, it is on another | ||||
branch), the update is aborted and the uncommitted changes | ||||
are preserved. | ||||
Martin von Zweigbergk
|
r31166 | 2. With the -m/--merge option, the update is allowed even if the | ||
requested changeset is not an ancestor or descendant of | ||||
the working directory's parent. | ||||
3. With the -c/--check option, the update is aborted and the | ||||
Adrian Buehlmann
|
r17218 | uncommitted changes are preserved. | ||
Martin von Zweigbergk
|
r31166 | 4. With the -C/--clean option, uncommitted changes are discarded and | ||
Adrian Buehlmann
|
r17218 | the working directory is updated to the requested changeset. | ||
Stuart W Marks
|
r9718 | |||
Adrian Buehlmann
|
r17144 | To cancel an uncommitted merge (and lose your changes), use | ||
:hg:`update --clean .`. | ||||
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: | ||
Pierre-Yves David
|
r26587 | raise error.Abort(_("please specify just one revision")) | ||
Daniel Holth
|
r4450 | |||
Martin von Zweigbergk
|
r31588 | if ui.configbool('commands', 'update.requiredest'): | ||
Ryan McElroy
|
r31557 | if not node and not rev and not date: | ||
raise error.Abort(_('you must specify a destination'), | ||||
hint=_('for example: hg update ".::"')) | ||||
Mark Drago
|
r13568 | if rev is None or rev == '': | ||
Daniel Holth
|
r4450 | rev = node | ||
Martin von Zweigbergk
|
r28032 | if date and rev is not None: | ||
raise error.Abort(_("you can't specify a revision and a date")) | ||||
Martin von Zweigbergk
|
r31166 | if len([x for x in (clean, check, merge) if x]) > 1: | ||
raise error.Abort(_("can only specify one of -C/--clean, -c/--check, " | ||||
"or -m/merge")) | ||||
updatecheck = None | ||||
if check: | ||||
updatecheck = 'abort' | ||||
elif merge: | ||||
updatecheck = 'none' | ||||
Martin von Zweigbergk
|
r28032 | |||
Bryan O'Sullivan
|
r27854 | with repo.wlock(): | ||
Pierre-Yves David
|
r26028 | cmdutil.clearunfinished(repo) | ||
Pierre-Yves David
|
r26286 | if date: | ||
rev = cmdutil.finddate(ui, repo, date) | ||||
Pierre-Yves David
|
r26028 | # if we defined a bookmark, we have to remember the original name | ||
brev = rev | ||||
rev = scmutil.revsingle(repo, rev, rev).rev() | ||||
repo.ui.setconfig('ui', 'forcemerge', tool, 'update') | ||||
Martin von Zweigbergk
|
r31166 | return hg.updatetotally(ui, repo, rev, brev, clean=clean, | ||
updatecheck=updatecheck) | ||||
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 | |||
Matt Mackall
|
r26421 | Please see https://mercurial-scm.org/wiki/RepositoryCorruption | ||
FUJIWARA Katsunori
|
r17717 | for more information about recovery from corruption of the | ||
repository. | ||||
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 | |||
Yuya Nishihara
|
r29840 | @command('version', [] + formatteropts, norepo=True) | ||
def version_(ui, **opts): | ||||
Matt Mackall
|
r3651 | """output version and copyright information""" | ||
Pulkit Goyal
|
r32142 | opts = pycompat.byteskwargs(opts) | ||
Augie Fackler
|
r31047 | if ui.verbose: | ||
ui.pager('version') | ||||
Yuya Nishihara
|
r29840 | fm = ui.formatter("version", opts) | ||
fm.startitem() | ||||
fm.write("ver", _("Mercurial Distributed SCM (version %s)\n"), | ||||
util.version()) | ||||
license = _( | ||||
Matt Mackall
|
r26421 | "(see https://mercurial-scm.org for more information)\n" | ||
FUJIWARA Katsunori
|
r30907 | "\nCopyright (C) 2005-2017 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" | ||||
Yuya Nishihara
|
r29840 | ) | ||
if not ui.quiet: | ||||
fm.plain(license) | ||||
anatoly techtonik
|
r21848 | if ui.verbose: | ||
Yuya Nishihara
|
r29840 | fm.plain(_("\nEnabled extensions:\n\n")) | ||
Yuya Nishihara
|
r29838 | # format names and versions into columns | ||
names = [] | ||||
vers = [] | ||||
Yuya Nishihara
|
r29839 | isinternals = [] | ||
Yuya Nishihara
|
r29838 | for name, module in extensions.extensions(): | ||
names.append(name) | ||||
Yuya Nishihara
|
r29840 | vers.append(extensions.moduleversion(module) or None) | ||
Yuya Nishihara
|
r29839 | isinternals.append(extensions.ismoduleinternal(module)) | ||
Yuya Nishihara
|
r29840 | fn = fm.nested("extensions") | ||
Yuya Nishihara
|
r29838 | if names: | ||
Yuya Nishihara
|
r29840 | namefmt = " %%-%ds " % max(len(n) for n in names) | ||
Yuya Nishihara
|
r29885 | places = [_("external"), _("internal")] | ||
Yuya Nishihara
|
r29840 | for n, v, p in zip(names, vers, isinternals): | ||
fn.startitem() | ||||
fn.condwrite(ui.verbose, "name", namefmt, n) | ||||
Yuya Nishihara
|
r29885 | if ui.verbose: | ||
fn.plain("%s " % places[p]) | ||||
fn.data(bundled=p) | ||||
Yuya Nishihara
|
r29840 | fn.condwrite(ui.verbose and v, "ver", "%s", v) | ||
Yuya Nishihara
|
r29838 | if ui.verbose: | ||
Yuya Nishihara
|
r29840 | fn.plain("\n") | ||
fn.end() | ||||
fm.end() | ||||
FUJIWARA Katsunori
|
r28391 | |||
def loadcmdtable(ui, name, cmdtable): | ||||
"""Load command functions from specified cmdtable | ||||
""" | ||||
overrides = [cmd for cmd in cmdtable if cmd in table] | ||||
if overrides: | ||||
ui.warn(_("extension '%s' overrides commands: %s\n") | ||||
% (name, " ".join(overrides))) | ||||
table.update(cmdtable) | ||||