commands.py
3314 lines
| 120.7 KiB
| text/x-python
|
PythonLexer
/ mercurial / commands.py
mpm@selenic.com
|
r249 | # commands.py - command processing for mercurial | ||
# | ||||
Vadim Gelfer
|
r2859 | # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> | ||
mpm@selenic.com
|
r249 | # | ||
# This software may be used and distributed according to the terms | ||||
# of the GNU General Public License, incorporated herein by reference. | ||||
Thomas Arendsen Hein
|
r697 | from demandload import demandload | ||
mpm@selenic.com
|
r1092 | from node import * | ||
Benoit Boissinot
|
r1400 | from i18n import gettext as _ | ||
Alexis S. L. Carvalho
|
r3786 | demandload(globals(), "bisect os re sys signal imp urllib pdb shlex stat") | ||
Matt Mackall
|
r3643 | demandload(globals(), "fancyopts ui hg util lock revlog bundlerepo") | ||
Matt Mackall
|
r3846 | demandload(globals(), "difflib patch time help mdiff tempfile") | ||
Matt Mackall
|
r3660 | demandload(globals(), "traceback errno version atexit") | ||
Matt Mackall
|
r3627 | demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver") | ||
mpm@selenic.com
|
r209 | |||
Thomas Arendsen Hein
|
r697 | class UnknownCommand(Exception): | ||
"""Exception raised if command is not in the command table.""" | ||||
Thomas Arendsen Hein
|
r1518 | class AmbiguousCommand(Exception): | ||
"""Exception raised if command shortcut matches more than one command.""" | ||||
mpm@selenic.com
|
r209 | |||
Vadim Gelfer
|
r2158 | def bail_if_changed(repo): | ||
Vadim Gelfer
|
r2875 | modified, added, removed, deleted = repo.status()[:4] | ||
Vadim Gelfer
|
r2158 | if modified or added or removed or deleted: | ||
raise util.Abort(_("outstanding uncommitted changes")) | ||||
Vadim Gelfer
|
r2799 | def logmessage(opts): | ||
"Mathieu Clabaut "
|
r2694 | """ get the log message according to -m and -l option """ | ||
message = opts['message'] | ||||
logfile = opts['logfile'] | ||||
if message and logfile: | ||||
raise util.Abort(_('options --message and --logfile are mutually ' | ||||
'exclusive')) | ||||
if not message and logfile: | ||||
try: | ||||
if logfile == '-': | ||||
message = sys.stdin.read() | ||||
else: | ||||
message = open(logfile).read() | ||||
except IOError, inst: | ||||
raise util.Abort(_("can't read commit message '%s': %s") % | ||||
(logfile, inst.strerror)) | ||||
return message | ||||
Matt Mackall
|
r2731 | def setremoteconfig(ui, opts): | ||
"copy remote options to ui tree" | ||||
if opts.get('ssh'): | ||||
ui.setconfig("ui", "ssh", opts['ssh']) | ||||
if opts.get('remotecmd'): | ||||
ui.setconfig("ui", "remotecmd", opts['remotecmd']) | ||||
mpm@selenic.com
|
r255 | # Commands start here, listed alphabetically | ||
mpm@selenic.com
|
r209 | |||
Bryan O'Sullivan
|
r724 | def add(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """add the specified files on the next commit | ||
Schedule files to be version controlled and added to the repository. | ||||
Matt Mackall
|
r3829 | The files will be added to the repository at the next commit. To | ||
undo an add before that, see hg revert. | ||||
Benoit Boissinot
|
r1437 | |||
Benoit Boissinot
|
r1568 | If no names are given, add all files in the repository. | ||
Benoit Boissinot
|
r1437 | """ | ||
Bryan O'Sullivan
|
r724 | names = [] | ||
Vadim Gelfer
|
r2882 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts): | ||
Bryan O'Sullivan
|
r942 | if exact: | ||
Thomas Arendsen Hein
|
r1615 | if ui.verbose: | ||
ui.status(_('adding %s\n') % rel) | ||||
Bryan O'Sullivan
|
r724 | names.append(abs) | ||
elif repo.dirstate.state(abs) == '?': | ||||
Benoit Boissinot
|
r1402 | ui.status(_('adding %s\n') % rel) | ||
Bryan O'Sullivan
|
r724 | names.append(abs) | ||
Thomas Arendsen Hein
|
r2503 | if not opts.get('dry_run'): | ||
Vadim Gelfer
|
r2411 | repo.add(names) | ||
mpm@selenic.com
|
r213 | |||
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 | |||
Benoit Boissinot
|
r1437 | Add all new files and remove all missing files from the repository. | ||
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 | |||
Use the -s option to detect renamed files. With a parameter > 0, | ||||
this compares every removed file with every added file and records | ||||
those similar enough as renames. This option takes a percentage | ||||
between 0 (disabled) and 100 (files must be identical) as its | ||||
parameter. Detecting renamed files this way can be expensive. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Vadim Gelfer
|
r2958 | sim = float(opts.get('similarity') or 0) | ||
if sim < 0 or sim > 100: | ||||
raise util.Abort(_('similarity must be between 0 and 100')) | ||||
return cmdutil.addremove(repo, pats, opts, similarity=sim/100.) | ||||
mpm@selenic.com
|
r219 | |||
Bryan O'Sullivan
|
r733 | def annotate(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """show changeset information per file line | ||
List changes in files, showing the revision id responsible for each line | ||||
This command is useful to discover who did a change or when a change took | ||||
place. | ||||
Without the -a option, annotate will avoid processing files it | ||||
detects as binary. With -a, annotate will generate an annotation | ||||
anyway, probably with undesirable results. | ||||
""" | ||||
Brendan Cully
|
r3146 | getdate = util.cachefunc(lambda x: util.datestr(x.date())) | ||
lupus@debian.org
|
r1522 | |||
mpm@selenic.com
|
r744 | if not pats: | ||
Benoit Boissinot
|
r1402 | raise util.Abort(_('at least one file name or pattern required')) | ||
mpm@selenic.com
|
r744 | |||
Brendan Cully
|
r3146 | opmap = [['user', lambda x: ui.shortuser(x.user())], | ||
Brendan Cully
|
r3403 | ['number', lambda x: str(x.rev())], | ||
Brendan Cully
|
r3146 | ['changeset', lambda x: short(x.node())], | ||
Brendan Cully
|
r3172 | ['date', getdate], ['follow', lambda x: x.path()]] | ||
if (not opts['user'] and not opts['changeset'] and not opts['date'] | ||||
and not opts['follow']): | ||||
Thomas Arendsen Hein
|
r714 | opts['number'] = 1 | ||
mpm@selenic.com
|
r209 | |||
Brendan Cully
|
r3132 | ctx = repo.changectx(opts['rev']) | ||
mpm@selenic.com
|
r1016 | |||
Vadim Gelfer
|
r2882 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, | ||
node=ctx.node()): | ||||
Matt Mackall
|
r2566 | fctx = ctx.filectx(abs) | ||
if not opts['text'] and util.binary(fctx.data()): | ||||
Benoit Boissinot
|
r1625 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) | ||
mpm@selenic.com
|
r1016 | continue | ||
Brendan Cully
|
r3172 | lines = fctx.annotate(follow=opts.get('follow')) | ||
mpm@selenic.com
|
r209 | pieces = [] | ||
for o, f in opmap: | ||||
Thomas Arendsen Hein
|
r714 | if opts[o]: | ||
Thomas Arendsen Hein
|
r697 | l = [f(n) for n, dummy in lines] | ||
mpm@selenic.com
|
r771 | if l: | ||
m = max(map(len, l)) | ||||
pieces.append(["%*s" % (m, x) for x in l]) | ||||
mpm@selenic.com
|
r209 | |||
mpm@selenic.com
|
r771 | if pieces: | ||
for p, l in zip(zip(*pieces), lines): | ||||
ui.write("%s: %s" % (" ".join(p), l[1])) | ||||
mpm@selenic.com
|
r209 | |||
Vadim Gelfer
|
r2112 | def archive(ui, repo, dest, **opts): | ||
'''create unversioned archive of a repository revision | ||||
By default, the revision used is the parent of the working | ||||
directory; use "-r" to specify a different revision. | ||||
To specify the type of archive to create, use "-t". Valid | ||||
types are: | ||||
"files" (default): a directory full of files | ||||
"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 | ||||
The exact name of the destination archive or directory is given | ||||
using a format string; see "hg help export" for details. | ||||
Each member added to an archive file has a directory prefix | ||||
prepended. Use "-p" to specify a format string for the prefix. | ||||
The default is the basename of the archive, with suffixes removed. | ||||
''' | ||||
Brendan Cully
|
r3132 | node = repo.changectx(opts['rev']).node() | ||
Vadim Gelfer
|
r2874 | dest = cmdutil.make_filename(repo, dest, node) | ||
Vadim Gelfer
|
r2112 | if os.path.realpath(dest) == repo.root: | ||
raise util.Abort(_('repository root cannot be destination')) | ||||
Vadim Gelfer
|
r2882 | dummy, matchfn, dummy = cmdutil.matchpats(repo, [], opts) | ||
Vadim Gelfer
|
r2476 | kind = opts.get('type') or 'files' | ||
prefix = opts['prefix'] | ||||
if dest == '-': | ||||
if kind == 'files': | ||||
raise util.Abort(_('cannot archive plain files to stdout')) | ||||
dest = sys.stdout | ||||
if not prefix: prefix = os.path.basename(repo.root) + '-%h' | ||||
Vadim Gelfer
|
r2874 | prefix = cmdutil.make_filename(repo, prefix, node) | ||
Vadim Gelfer
|
r2476 | archival.archive(repo, dest, node, kind, not opts['no_decode'], | ||
matchfn, prefix) | ||||
Vadim Gelfer
|
r2112 | |||
Vadim Gelfer
|
r2158 | def backout(ui, repo, rev, **opts): | ||
'''reverse effect of earlier changeset | ||||
Vadim Gelfer
|
r2254 | Commit the backed out changes as a new changeset. The new | ||
changeset is a child of the backed out changeset. | ||||
Vadim Gelfer
|
r2158 | |||
If you back out a changeset other than the tip, a new head is | ||||
Vadim Gelfer
|
r2254 | created. This head is the parent of the working directory. If | ||
you back out an old changeset, your working directory will appear | ||||
old after the backout. You should merge the backout changeset | ||||
with another head. | ||||
The --merge option remembers the parent of the working directory | ||||
before starting the backout, then merges the new head with that | ||||
changeset afterwards. This saves you from doing the merge by | ||||
hand. The result of this merge is not committed, as for a normal | ||||
merge.''' | ||||
Vadim Gelfer
|
r2158 | |||
bail_if_changed(repo) | ||||
op1, op2 = repo.dirstate.parents() | ||||
if op2 != nullid: | ||||
raise util.Abort(_('outstanding uncommitted merge')) | ||||
node = repo.lookup(rev) | ||||
Vadim Gelfer
|
r2614 | p1, p2 = repo.changelog.parents(node) | ||
if p1 == nullid: | ||||
Vadim Gelfer
|
r2158 | raise util.Abort(_('cannot back out a change with no parents')) | ||
if p2 != nullid: | ||||
Vadim Gelfer
|
r2614 | if not opts['parent']: | ||
raise util.Abort(_('cannot back out a merge changeset without ' | ||||
'--parent')) | ||||
p = repo.lookup(opts['parent']) | ||||
if p not in (p1, p2): | ||||
Marcos Chaves
|
r3679 | raise util.Abort(_('%s is not a parent of %s') % | ||
Thomas Arendsen Hein
|
r3680 | (short(p), short(node))) | ||
Vadim Gelfer
|
r2614 | parent = p | ||
else: | ||||
if opts['parent']: | ||||
raise util.Abort(_('cannot use --parent on non-merge changeset')) | ||||
parent = p1 | ||||
Matt Mackall
|
r2808 | hg.clean(repo, node, show_stats=False) | ||
Vadim Gelfer
|
r2158 | revert_opts = opts.copy() | ||
Matt Mackall
|
r3814 | revert_opts['date'] = None | ||
Vadim Gelfer
|
r2982 | revert_opts['all'] = True | ||
Vadim Gelfer
|
r2158 | revert_opts['rev'] = hex(parent) | ||
revert(ui, repo, **revert_opts) | ||||
commit_opts = opts.copy() | ||||
commit_opts['addremove'] = False | ||||
Thomas Arendsen Hein
|
r2159 | if not commit_opts['message'] and not commit_opts['logfile']: | ||
Vadim Gelfer
|
r2158 | commit_opts['message'] = _("Backed out changeset %s") % (hex(node)) | ||
Vadim Gelfer
|
r2268 | commit_opts['force_editor'] = True | ||
Vadim Gelfer
|
r2158 | commit(ui, repo, **commit_opts) | ||
def nice(node): | ||||
return '%d:%s' % (repo.changelog.rev(node), short(node)) | ||||
ui.status(_('changeset %s backs out changeset %s\n') % | ||||
(nice(repo.changelog.tip()), nice(node))) | ||||
Vadim Gelfer
|
r2493 | if op1 != node: | ||
if opts['merge']: | ||||
ui.status(_('merging with changeset %s\n') % nice(op1)) | ||||
Matt Mackall
|
r2806 | n = _lookup(repo, hex(op1)) | ||
Matt Mackall
|
r2808 | hg.merge(repo, n) | ||
Vadim Gelfer
|
r2493 | else: | ||
ui.status(_('the backout changeset is a new head - ' | ||||
'do not forget to merge\n')) | ||||
Christian Ebert
|
r2761 | ui.status(_('(use "backout --merge" ' | ||
'if you want to auto-merge)\n')) | ||||
Vadim Gelfer
|
r2158 | |||
Matt Mackall
|
r3502 | def branch(ui, repo, label=None): | ||
"""set or show the current branch name | ||||
With <name>, set the current branch name. Otherwise, show the | ||||
current branch name. | ||||
""" | ||||
if label is not None: | ||||
Alexis S. L. Carvalho
|
r3862 | repo.opener("branch", "w").write(util.fromlocal(label) + '\n') | ||
Matt Mackall
|
r3502 | else: | ||
Alexis S. L. Carvalho
|
r3862 | b = util.tolocal(repo.workingctx().branch()) | ||
Matt Mackall
|
r3502 | if b: | ||
ui.write("%s\n" % b) | ||||
def branches(ui, repo): | ||||
"""list repository named branches | ||||
List the repository's named branches. | ||||
""" | ||||
b = repo.branchtags() | ||||
Thomas Arendsen Hein
|
r3673 | l = [(-repo.changelog.rev(n), n, t) for t, n in b.items()] | ||
Matt Mackall
|
r3502 | l.sort() | ||
for r, n, t in l: | ||||
hexfunc = ui.debugflag and hex or short | ||||
if ui.quiet: | ||||
ui.write("%s\n" % t) | ||||
else: | ||||
Matt Mackall
|
r3773 | t = util.localsub(t, 30) | ||
t += " " * (30 - util.locallen(t)) | ||||
ui.write("%s %s:%s\n" % (t, -r, hexfunc(n))) | ||||
Matt Mackall
|
r3502 | |||
Vadim Gelfer
|
r2494 | def bundle(ui, repo, fname, dest=None, **opts): | ||
Benoit Boissinot
|
r1437 | """create a changegroup file | ||
Thomas Arendsen Hein
|
r3511 | Generate a compressed changegroup file collecting changesets not | ||
found in the other repository. | ||||
If no destination repository is specified the destination is assumed | ||||
to have all the nodes specified by one or more --base parameters. | ||||
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. | ||||
Applying bundles preserves all changeset contents including | ||||
permissions, copy/rename information, and revision history. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Benoit Boissinot
|
r3284 | revs = opts.get('rev') or None | ||
if revs: | ||||
revs = [repo.lookup(rev) for rev in revs] | ||||
base = opts.get('base') | ||||
if base: | ||||
if dest: | ||||
raise util.Abort(_("--base is incompatible with specifiying " | ||||
"a destination")) | ||||
Benoit Boissinot
|
r3318 | base = [repo.lookup(rev) for rev in base] | ||
# create the right base | ||||
# XXX: nodesbetween / changegroup* should be "fixed" instead | ||||
Benoit Boissinot
|
r3284 | o = [] | ||
Matt Mackall
|
r3649 | has = {nullid: None} | ||
Benoit Boissinot
|
r3284 | for n in base: | ||
Matt Mackall
|
r3631 | has.update(repo.changelog.reachable(n)) | ||
Benoit Boissinot
|
r3284 | if revs: | ||
Benoit Boissinot
|
r3318 | visit = list(revs) | ||
Benoit Boissinot
|
r3284 | else: | ||
Benoit Boissinot
|
r3318 | visit = repo.changelog.heads() | ||
Matt Mackall
|
r3631 | seen = {} | ||
Benoit Boissinot
|
r3318 | while visit: | ||
n = visit.pop(0) | ||||
Matt Mackall
|
r3631 | parents = [p for p in repo.changelog.parents(n) if p not in has] | ||
Benoit Boissinot
|
r3318 | if len(parents) == 0: | ||
o.insert(0, n) | ||||
else: | ||||
Benoit Boissinot
|
r3512 | for p in parents: | ||
if p not in seen: | ||||
Matt Mackall
|
r3631 | seen[p] = 1 | ||
Benoit Boissinot
|
r3512 | visit.append(p) | ||
Benoit Boissinot
|
r3284 | else: | ||
setremoteconfig(ui, opts) | ||||
dest = ui.expandpath(dest or 'default-push', dest or 'default') | ||||
other = hg.repository(ui, dest) | ||||
o = repo.findoutgoing(other, force=opts['force']) | ||||
if revs: | ||||
cg = repo.changegroupsubset(o, revs, 'bundle') | ||||
else: | ||||
cg = repo.changegroup(o, 'bundle') | ||||
Benoit Boissinot
|
r3704 | changegroup.writebundle(cg, fname, "HG10BZ") | ||
mpm@selenic.com
|
r1218 | |||
Bryan O'Sullivan
|
r1254 | def cat(ui, repo, file1, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """output the latest or given revisions of files | ||
Print the specified files as they were at the given revision. | ||||
Brendan Cully
|
r3095 | If no revision is given then working dir parent is used, or tip | ||
if no revision is checked out. | ||||
Benoit Boissinot
|
r1437 | |||
Output may be to a file, in which case the name of the file is | ||||
given using a format string. The formatting rules are the same as | ||||
for the export command, with the following additions: | ||||
%s basename of file being printed | ||||
%d dirname of file being printed, or '.' if in repo root | ||||
%p root-relative path name of file being printed | ||||
""" | ||||
Brendan Cully
|
r3132 | ctx = repo.changectx(opts['rev']) | ||
Vadim Gelfer
|
r2882 | for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts, | ||
ctx.node()): | ||||
Vadim Gelfer
|
r2874 | fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs) | ||
Matt Mackall
|
r2565 | fp.write(ctx.filectx(abs).data()) | ||
mpm@selenic.com
|
r248 | |||
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 | ||||
.hg/hgrc file, as the default to be used for future pulls. | ||||
For efficiency, hardlinks are used for cloning whenever the source | ||||
Inaky Perez-Gonzalez
|
r2762 | and destination are on the same filesystem (note this applies only | ||
to the repository data, not to the checked out files). Some | ||||
filesystems, such as AFS, implement hardlinking incorrectly, but | ||||
do not report errors. In these cases, use the --pull option to | ||||
avoid hardlinking. | ||||
You can safely clone repositories and checked out files using full | ||||
hardlinks with | ||||
$ cp -al REPO REPOCLONE | ||||
which is the fastest way to clone. However, 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). | ||||
Benoit Boissinot
|
r1811 | |||
Vadim Gelfer
|
r2764 | If you use the -r option to clone up to a specific revision, no | ||
subsequent revisions will be present in the cloned repository. | ||||
This option implies --pull, even on local repositories. | ||||
Benoit Boissinot
|
r1811 | See pull for valid source format details. | ||
Thomas Arendsen Hein
|
r2590 | |||
It is possible to specify an ssh:// URL as the destination, but no | ||||
Benoit Boissinot
|
r3583 | .hg/hgrc and working directory will be created on the remote side. | ||
Look at the help text for the pull command for important details | ||||
about ssh:// URLs. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r2731 | setremoteconfig(ui, opts) | ||
Vadim Gelfer
|
r2597 | hg.clone(ui, ui.expandpath(source), dest, | ||
pull=opts['pull'], | ||||
Vadim Gelfer
|
r2620 | stream=opts['uncompressed'], | ||
Vadim Gelfer
|
r2597 | rev=opts['rev'], | ||
update=not opts['noupdate']) | ||||
mpm@selenic.com
|
r515 | |||
Bryan O'Sullivan
|
r813 | def commit(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """commit the specified files or all outstanding changes | ||
Commit changes to the given files into the repository. | ||||
If a list of files is omitted, all changes reported by "hg status" | ||||
mcmillen@cs.cmu.edu
|
r1995 | will be committed. | ||
Benoit Boissinot
|
r1437 | |||
Thomas Arendsen Hein
|
r1996 | If no commit message is specified, the editor configured in your hgrc | ||
or in the EDITOR environment variable is started to enter a message. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Vadim Gelfer
|
r2799 | message = logmessage(opts) | ||
mpm@selenic.com
|
r289 | |||
mpm@selenic.com
|
r354 | if opts['addremove']: | ||
Vadim Gelfer
|
r2883 | cmdutil.addremove(repo, pats, opts) | ||
Vadim Gelfer
|
r2882 | fns, match, anypats = cmdutil.matchpats(repo, pats, opts) | ||
Bryan O'Sullivan
|
r813 | if pats: | ||
Matt Mackall
|
r3663 | status = repo.status(files=fns, match=match) | ||
modified, added, removed, deleted, unknown = status[:5] | ||||
Thomas Arendsen Hein
|
r1619 | files = modified + added + removed | ||
Alexis S. L. Carvalho
|
r3786 | slist = None | ||
Matt Mackall
|
r3663 | for f in fns: | ||
Alexis S. L. Carvalho
|
r3786 | if f not in files: | ||
rf = repo.wjoin(f) | ||||
Matt Mackall
|
r3663 | if f in unknown: | ||
Alexis S. L. Carvalho
|
r3786 | raise util.Abort(_("file %s not tracked!") % rf) | ||
try: | ||||
mode = os.lstat(rf)[stat.ST_MODE] | ||||
except OSError: | ||||
raise util.Abort(_("file %s not found!") % rf) | ||||
if stat.S_ISDIR(mode): | ||||
name = f + '/' | ||||
if slist is None: | ||||
slist = list(files) | ||||
slist.sort() | ||||
i = bisect.bisect(slist, name) | ||||
if i >= len(slist) or not slist[i].startswith(name): | ||||
raise util.Abort(_("no match under directory %s!") | ||||
% rf) | ||||
elif not stat.S_ISREG(mode): | ||||
raise util.Abort(_("can't commit %s: " | ||||
"unsupported file type!") % rf) | ||||
Bryan O'Sullivan
|
r813 | else: | ||
files = [] | ||||
Bryan O'Sullivan
|
r1202 | try: | ||
john.levon@sun.com
|
r2267 | repo.commit(files, message, opts['user'], opts['date'], match, | ||
Vadim Gelfer
|
r2268 | force_editor=opts.get('force_editor')) | ||
Bryan O'Sullivan
|
r1202 | except ValueError, inst: | ||
raise util.Abort(str(inst)) | ||||
mpm@selenic.com
|
r245 | |||
Robin Farine
|
r1822 | def docopy(ui, repo, pats, opts, wlock): | ||
# called with the repo lock held | ||||
Alexis S. L. Carvalho
|
r3670 | # | ||
# hgsep => pathname that uses "/" to separate directories | ||||
# ossep => pathname that uses os.sep to separate directories | ||||
Robin Farine
|
r1512 | cwd = repo.getcwd() | ||
errors = 0 | ||||
copied = [] | ||||
Robin Farine
|
r1514 | targets = {} | ||
Bryan O'Sullivan
|
r1249 | |||
Alexis S. L. Carvalho
|
r3670 | # abs: hgsep | ||
# rel: ossep | ||||
# return: hgsep | ||||
Bryan O'Sullivan
|
r1249 | def okaytocopy(abs, rel, exact): | ||
Benoit Boissinot
|
r1402 | reasons = {'?': _('is not managed'), | ||
Robin Farine
|
r1634 | 'a': _('has been marked for add'), | ||
'r': _('has been marked for remove')} | ||||
Robin Farine
|
r1747 | state = repo.dirstate.state(abs) | ||
reason = reasons.get(state) | ||||
Bryan O'Sullivan
|
r1249 | if reason: | ||
Robin Farine
|
r1747 | if state == 'a': | ||
origsrc = repo.dirstate.copied(abs) | ||||
if origsrc is not None: | ||||
return origsrc | ||||
Thomas Arendsen Hein
|
r1615 | if exact: | ||
ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) | ||||
Bryan O'Sullivan
|
r1249 | else: | ||
Robin Farine
|
r1747 | return abs | ||
Alexis S. L. Carvalho
|
r3670 | # origsrc: hgsep | ||
# abssrc: hgsep | ||||
# relsrc: ossep | ||||
# target: ossep | ||||
Robin Farine
|
r1747 | def copy(origsrc, abssrc, relsrc, target, exact): | ||
Robin Farine
|
r1512 | abstarget = util.canonpath(repo.root, cwd, target) | ||
reltarget = util.pathto(cwd, abstarget) | ||||
Robin Farine
|
r1514 | prevsrc = targets.get(abstarget) | ||
if prevsrc is not None: | ||||
ui.warn(_('%s: not overwriting - %s collides with %s\n') % | ||||
Alexis S. L. Carvalho
|
r3670 | (reltarget, util.localpath(abssrc), | ||
util.localpath(prevsrc))) | ||||
Robin Farine
|
r1514 | return | ||
Robin Farine
|
r1565 | if (not opts['after'] and os.path.exists(reltarget) or | ||
opts['after'] and repo.dirstate.state(abstarget) not in '?r'): | ||||
if not opts['force']: | ||||
Robin Farine
|
r1513 | ui.warn(_('%s: not overwriting - file exists\n') % | ||
reltarget) | ||||
return | ||||
Thomas Arendsen Hein
|
r2503 | if not opts['after'] and not opts.get('dry_run'): | ||
Robin Farine
|
r1565 | os.unlink(reltarget) | ||
if opts['after']: | ||||
if not os.path.exists(reltarget): | ||||
return | ||||
else: | ||||
Robin Farine
|
r1512 | targetdir = os.path.dirname(reltarget) or '.' | ||
Thomas Arendsen Hein
|
r2503 | if not os.path.isdir(targetdir) and not opts.get('dry_run'): | ||
Robin Farine
|
r1512 | os.makedirs(targetdir) | ||
Bryan O'Sullivan
|
r1249 | try: | ||
Robin Farine
|
r1822 | restore = repo.dirstate.state(abstarget) == 'r' | ||
Thomas Arendsen Hein
|
r2503 | if restore and not opts.get('dry_run'): | ||
Robin Farine
|
r1822 | repo.undelete([abstarget], wlock) | ||
try: | ||||
Thomas Arendsen Hein
|
r2503 | if not opts.get('dry_run'): | ||
Matt Mackall
|
r3629 | util.copyfile(relsrc, reltarget) | ||
Robin Farine
|
r1822 | restore = False | ||
finally: | ||||
if restore: | ||||
repo.remove([abstarget], wlock) | ||||
Bryan O'Sullivan
|
r1249 | except IOError, inst: | ||
if inst.errno == errno.ENOENT: | ||||
Robin Farine
|
r1512 | ui.warn(_('%s: deleted in working copy\n') % relsrc) | ||
Bryan O'Sullivan
|
r1249 | else: | ||
Robin Farine
|
r1512 | ui.warn(_('%s: cannot copy - %s\n') % | ||
(relsrc, inst.strerror)) | ||||
errors += 1 | ||||
return | ||||
Robin Farine
|
r1565 | if ui.verbose or not exact: | ||
ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) | ||||
Robin Farine
|
r1514 | targets[abstarget] = abssrc | ||
Thomas Arendsen Hein
|
r2503 | if abstarget != origsrc and not opts.get('dry_run'): | ||
Robin Farine
|
r1822 | repo.copy(origsrc, abstarget, wlock) | ||
Robin Farine
|
r1512 | copied.append((abssrc, relsrc, exact)) | ||
Alexis S. L. Carvalho
|
r3670 | # pat: ossep | ||
# dest ossep | ||||
# srcs: list of (hgsep, hgsep, ossep, bool) | ||||
# return: function that takes hgsep and returns ossep | ||||
Robin Farine
|
r1565 | def targetpathfn(pat, dest, srcs): | ||
if os.path.isdir(pat): | ||||
Robin Farine
|
r1633 | abspfx = util.canonpath(repo.root, cwd, pat) | ||
Alexis S. L. Carvalho
|
r3670 | abspfx = util.localpath(abspfx) | ||
Robin Farine
|
r1565 | if destdirexists: | ||
Robin Farine
|
r1633 | striplen = len(os.path.split(abspfx)[0]) | ||
Robin Farine
|
r1565 | else: | ||
Robin Farine
|
r1633 | striplen = len(abspfx) | ||
Robin Farine
|
r1565 | if striplen: | ||
striplen += len(os.sep) | ||||
Alexis S. L. Carvalho
|
r3670 | res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) | ||
Robin Farine
|
r1565 | elif destdirexists: | ||
Alexis S. L. Carvalho
|
r3670 | res = lambda p: os.path.join(dest, | ||
os.path.basename(util.localpath(p))) | ||||
Robin Farine
|
r1565 | else: | ||
res = lambda p: dest | ||||
return res | ||||
Alexis S. L. Carvalho
|
r3670 | # pat: ossep | ||
# dest ossep | ||||
# srcs: list of (hgsep, hgsep, ossep, bool) | ||||
# return: function that takes hgsep and returns ossep | ||||
Robin Farine
|
r1565 | def targetpathafterfn(pat, dest, srcs): | ||
if util.patkind(pat, None)[0]: | ||||
# a mercurial pattern | ||||
Alexis S. L. Carvalho
|
r3670 | res = lambda p: os.path.join(dest, | ||
os.path.basename(util.localpath(p))) | ||||
Robin Farine
|
r1633 | else: | ||
abspfx = util.canonpath(repo.root, cwd, pat) | ||||
if len(abspfx) < len(srcs[0][0]): | ||||
# A directory. Either the target path contains the last | ||||
# component of the source path or it does not. | ||||
def evalpath(striplen): | ||||
score = 0 | ||||
for s in srcs: | ||||
Alexis S. L. Carvalho
|
r3670 | t = os.path.join(dest, util.localpath(s[0])[striplen:]) | ||
Robin Farine
|
r1633 | if os.path.exists(t): | ||
score += 1 | ||||
return score | ||||
Robin Farine
|
r1565 | |||
Alexis S. L. Carvalho
|
r3670 | abspfx = util.localpath(abspfx) | ||
Robin Farine
|
r1633 | striplen = len(abspfx) | ||
if striplen: | ||||
striplen += len(os.sep) | ||||
if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): | ||||
score = evalpath(striplen) | ||||
striplen1 = len(os.path.split(abspfx)[0]) | ||||
if striplen1: | ||||
striplen1 += len(os.sep) | ||||
if evalpath(striplen1) > score: | ||||
striplen = striplen1 | ||||
Alexis S. L. Carvalho
|
r3670 | res = lambda p: os.path.join(dest, | ||
util.localpath(p)[striplen:]) | ||||
Robin Farine
|
r1565 | else: | ||
Robin Farine
|
r1633 | # a file | ||
if destdirexists: | ||||
Alexis S. L. Carvalho
|
r3670 | res = lambda p: os.path.join(dest, | ||
os.path.basename(util.localpath(p))) | ||||
Robin Farine
|
r1633 | else: | ||
res = lambda p: dest | ||||
Robin Farine
|
r1565 | return res | ||
Robin Farine
|
r1512 | pats = list(pats) | ||
if not pats: | ||||
raise util.Abort(_('no source or destination specified')) | ||||
if len(pats) == 1: | ||||
raise util.Abort(_('no destination specified')) | ||||
dest = pats.pop() | ||||
destdirexists = os.path.isdir(dest) | ||||
Robin Farine
|
r1565 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: | ||
Robin Farine
|
r1512 | raise util.Abort(_('with multiple sources, destination must be an ' | ||
'existing directory')) | ||||
Robin Farine
|
r1565 | if opts['after']: | ||
tfn = targetpathafterfn | ||||
else: | ||||
tfn = targetpathfn | ||||
copylist = [] | ||||
Robin Farine
|
r1512 | for pat in pats: | ||
Robin Farine
|
r1565 | srcs = [] | ||
Vadim Gelfer
|
r2882 | for tag, abssrc, relsrc, exact in cmdutil.walk(repo, [pat], opts): | ||
Robin Farine
|
r1747 | origsrc = okaytocopy(abssrc, relsrc, exact) | ||
if origsrc: | ||||
srcs.append((origsrc, abssrc, relsrc, exact)) | ||||
Robin Farine
|
r1565 | if not srcs: | ||
continue | ||||
copylist.append((tfn(pat, dest, srcs), srcs)) | ||||
if not copylist: | ||||
raise util.Abort(_('no files to copy')) | ||||
Vadim Gelfer
|
r2414 | for targetpath, srcs in copylist: | ||
for origsrc, abssrc, relsrc, exact in srcs: | ||||
copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) | ||||
Robin Farine
|
r1512 | |||
if errors: | ||||
Benoit Boissinot
|
r1402 | ui.warn(_('(consider using --after)\n')) | ||
Robin Farine
|
r1512 | return errors, copied | ||
Bryan O'Sullivan
|
r1253 | |||
def copy(ui, repo, *pats, **opts): | ||||
Benoit Boissinot
|
r1437 | """mark files as copied for the next commit | ||
Mark dest as having copies of source files. If dest is a | ||||
directory, copies are put in that directory. If dest is a file, | ||||
there can only be one source. | ||||
By default, this command copies the contents of files as they | ||||
stand in the working directory. If invoked with --after, the | ||||
operation is recorded, but no copying is performed. | ||||
Matt Mackall
|
r3829 | This command takes effect in the next commit. To undo a copy | ||
before that, see hg revert. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Vadim Gelfer
|
r2016 | wlock = repo.wlock(0) | ||
errs, copied = docopy(ui, repo, pats, opts, wlock) | ||||
Bryan O'Sullivan
|
r1249 | return errs | ||
mpm@selenic.com
|
r363 | |||
mpm@selenic.com
|
r1262 | def debugancestor(ui, index, rev1, rev2): | ||
"""find the ancestor revision of two revisions in a given index""" | ||||
mason@suse.com
|
r2072 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "", 0) | ||
mpm@selenic.com
|
r1262 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) | ||
ui.write("%d:%s\n" % (r.rev(a), hex(a))) | ||||
Alexis S. L. Carvalho
|
r2034 | def debugcomplete(ui, cmd='', **opts): | ||
Benoit Boissinot
|
r1887 | """returns the completion list associated with the given command""" | ||
Alexis S. L. Carvalho
|
r2034 | |||
if opts['options']: | ||||
options = [] | ||||
otables = [globalopts] | ||||
if cmd: | ||||
Bryan O'Sullivan
|
r2988 | aliases, entry = findcmd(ui, cmd) | ||
Alexis S. L. Carvalho
|
r2034 | otables.append(entry[1]) | ||
for t in otables: | ||||
for o in t: | ||||
if o[0]: | ||||
options.append('-%s' % o[0]) | ||||
options.append('--%s' % o[1]) | ||||
ui.write("%s\n" % "\n".join(options)) | ||||
return | ||||
Bryan O'Sullivan
|
r2988 | clist = findpossible(ui, cmd).keys() | ||
Benoit Boissinot
|
r1887 | clist.sort() | ||
Alexis S. L. Carvalho
|
r2034 | ui.write("%s\n" % "\n".join(clist)) | ||
Benoit Boissinot
|
r1887 | |||
Benoit Boissinot
|
r1755 | def debugrebuildstate(ui, repo, rev=None): | ||
"""rebuild the dirstate as it would look like for the given revision""" | ||||
if not rev: | ||||
rev = repo.changelog.tip() | ||||
else: | ||||
rev = repo.lookup(rev) | ||||
change = repo.changelog.read(rev) | ||||
n = change[0] | ||||
Matt Mackall
|
r2840 | files = repo.manifest.read(n) | ||
Benoit Boissinot
|
r1760 | wlock = repo.wlock() | ||
Matt Mackall
|
r2840 | repo.dirstate.rebuild(rev, files) | ||
Benoit Boissinot
|
r1755 | |||
mpm@selenic.com
|
r596 | def debugcheckstate(ui, repo): | ||
"""validate the correctness of the current dirstate""" | ||||
mpm@selenic.com
|
r460 | parent1, parent2 = repo.dirstate.parents() | ||
mpm@selenic.com
|
r555 | repo.dirstate.read() | ||
dc = repo.dirstate.map | ||||
mpm@selenic.com
|
r460 | keys = dc.keys() | ||
keys.sort() | ||||
m1n = repo.changelog.read(parent1)[0] | ||||
m2n = repo.changelog.read(parent2)[0] | ||||
m1 = repo.manifest.read(m1n) | ||||
m2 = repo.manifest.read(m2n) | ||||
errors = 0 | ||||
for f in dc: | ||||
state = repo.dirstate.state(f) | ||||
if state in "nr" and f not in m1: | ||||
Benoit Boissinot
|
r1402 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) | ||
mpm@selenic.com
|
r460 | errors += 1 | ||
if state in "a" and f in m1: | ||||
Benoit Boissinot
|
r1402 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) | ||
mpm@selenic.com
|
r460 | errors += 1 | ||
if state in "m" and f not in m1 and f not in m2: | ||||
Benoit Boissinot
|
r1402 | ui.warn(_("%s in state %s, but not in either manifest\n") % | ||
mpm@selenic.com
|
r582 | (f, state)) | ||
mpm@selenic.com
|
r460 | errors += 1 | ||
for f in m1: | ||||
state = repo.dirstate.state(f) | ||||
if state not in "nrm": | ||||
Benoit Boissinot
|
r1402 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) | ||
mpm@selenic.com
|
r460 | errors += 1 | ||
if errors: | ||||
Muli Ben-Yehuda
|
r1602 | error = _(".hg/dirstate inconsistent with current parent's manifest") | ||
raise util.Abort(error) | ||||
mpm@selenic.com
|
r460 | |||
Alexis S. L. Carvalho
|
r3553 | def showconfig(ui, repo, *values, **opts): | ||
Vadim Gelfer
|
r2410 | """show combined config settings from all hgrc files | ||
With no args, print names and values of all config items. | ||||
With one arg of the form section.name, print just the value of | ||||
that config item. | ||||
With multiple args, print names and values of all config items | ||||
with matching section names.""" | ||||
Alexis S. L. Carvalho
|
r3553 | untrusted = bool(opts.get('untrusted')) | ||
Vadim Gelfer
|
r2410 | if values: | ||
if len([v for v in values if '.' in v]) > 1: | ||||
raise util.Abort(_('only one config item permitted')) | ||||
Alexis S. L. Carvalho
|
r3553 | for section, name, value in ui.walkconfig(untrusted=untrusted): | ||
Vadim Gelfer
|
r2410 | sectname = section + '.' + name | ||
if values: | ||||
for v in values: | ||||
if v == section: | ||||
ui.write('%s=%s\n' % (sectname, value)) | ||||
elif v == sectname: | ||||
ui.write(value, '\n') | ||||
else: | ||||
ui.write('%s=%s\n' % (sectname, value)) | ||||
Bryan O'Sullivan
|
r1028 | |||
Matt Mackall
|
r1395 | def debugsetparents(ui, repo, rev1, rev2=None): | ||
TK Soh
|
r1470 | """manually set the parents of the current working directory | ||
Matt Mackall
|
r1395 | |||
This is useful for writing repository conversion tools, but should | ||||
be used with care. | ||||
""" | ||||
if not rev2: | ||||
rev2 = hex(nullid) | ||||
repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) | ||||
mpm@selenic.com
|
r596 | def debugstate(ui, repo): | ||
"""show the contents of the current dirstate""" | ||||
mpm@selenic.com
|
r555 | repo.dirstate.read() | ||
dc = repo.dirstate.map | ||||
mpm@selenic.com
|
r460 | keys = dc.keys() | ||
keys.sort() | ||||
Thomas Arendsen Hein
|
r697 | for file_ in keys: | ||
Thomas Arendsen Hein
|
r791 | ui.write("%c %3o %10d %s %s\n" | ||
% (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], | ||||
time.strftime("%x %X", | ||||
time.localtime(dc[file_][3])), file_)) | ||||
Benoit Boissinot
|
r3159 | for f in repo.dirstate.copies(): | ||
ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) | ||||
mpm@selenic.com
|
r460 | |||
mpm@selenic.com
|
r1039 | def debugdata(ui, file_, rev): | ||
"""dump the contents of an data file revision""" | ||||
Thomas Arendsen Hein
|
r1835 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), | ||
mason@suse.com
|
r2072 | file_[:-2] + ".i", file_, 0) | ||
Anupam Kapoor
|
r1313 | try: | ||
ui.write(r.revision(r.lookup(rev))) | ||||
except KeyError: | ||||
Thomas Arendsen Hein
|
r3072 | raise util.Abort(_('invalid revision identifier %s') % rev) | ||
mpm@selenic.com
|
r1039 | |||
Matt Mackall
|
r3812 | def debugdate(ui, date, range=None, **opts): | ||
Matt Mackall
|
r3805 | """parse and display a date""" | ||
Matt Mackall
|
r3812 | if opts["extended"]: | ||
d = util.parsedate(date, util.extendeddateformats) | ||||
else: | ||||
d = util.parsedate(date) | ||||
Matt Mackall
|
r3805 | ui.write("internal: %s %s\n" % d) | ||
ui.write("standard: %s\n" % util.datestr(d)) | ||||
Matt Mackall
|
r3812 | if range: | ||
m = util.matchdate(range) | ||||
ui.write("match: %s\n" % m(d[0])) | ||||
Matt Mackall
|
r3805 | |||
Thomas Arendsen Hein
|
r697 | def debugindex(ui, file_): | ||
mpm@selenic.com
|
r596 | """dump the contents of an index file""" | ||
mason@suse.com
|
r2072 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) | ||
mpm@selenic.com
|
r582 | ui.write(" rev offset length base linkrev" + | ||
mpm@selenic.com
|
r989 | " nodeid p1 p2\n") | ||
Benoit Boissinot
|
r3472 | for i in xrange(r.count()): | ||
mason@suse.com
|
r2072 | node = r.node(i) | ||
pp = r.parents(node) | ||||
mpm@selenic.com
|
r989 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( | ||
mason@suse.com
|
r2072 | i, r.start(i), r.length(i), r.base(i), r.linkrev(node), | ||
short(node), short(pp[0]), short(pp[1]))) | ||||
mpm@selenic.com
|
r248 | |||
Thomas Arendsen Hein
|
r697 | def debugindexdot(ui, file_): | ||
mpm@selenic.com
|
r596 | """dump an index DAG as a .dot file""" | ||
mason@suse.com
|
r2072 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) | ||
mpm@selenic.com
|
r582 | ui.write("digraph G {\n") | ||
Benoit Boissinot
|
r3472 | for i in xrange(r.count()): | ||
Samuel Masham
|
r2287 | node = r.node(i) | ||
pp = r.parents(node) | ||||
ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) | ||||
if pp[1] != nullid: | ||||
ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) | ||||
mpm@selenic.com
|
r582 | ui.write("}\n") | ||
mpm@selenic.com
|
r248 | |||
Matt Mackall
|
r3844 | def debuginstall(ui): | ||
'''test Mercurial installation''' | ||||
Matt Mackall
|
r3846 | def writetemp(contents): | ||
(fd, name) = tempfile.mkstemp() | ||||
f = os.fdopen(fd, "wb") | ||||
f.write(contents) | ||||
f.close() | ||||
return name | ||||
Matt Mackall
|
r3844 | problems = 0 | ||
# encoding | ||||
ui.status(_("Checking encoding (%s)...\n") % util._encoding) | ||||
try: | ||||
util.fromlocal("test") | ||||
except util.Abort, inst: | ||||
ui.write(" %s\n" % inst) | ||||
Matt Mackall
|
r3848 | ui.write(_(" (check that your locale is properly set)\n")) | ||
Matt Mackall
|
r3844 | problems += 1 | ||
# compiled modules | ||||
ui.status(_("Checking extensions...\n")) | ||||
try: | ||||
import bdiff, mpatch, base85 | ||||
except Exception, inst: | ||||
ui.write(" %s\n" % inst) | ||||
Matt Mackall
|
r3848 | ui.write(_(" One or more extensions could not be found")) | ||
ui.write(_(" (check that you compiled the extensions)\n")) | ||||
Matt Mackall
|
r3844 | problems += 1 | ||
# templates | ||||
ui.status(_("Checking templates...\n")) | ||||
try: | ||||
import templater | ||||
t = templater.templater(templater.templatepath("map-cmdline.default")) | ||||
except Exception, inst: | ||||
ui.write(" %s\n" % inst) | ||||
Matt Mackall
|
r3848 | ui.write(_(" (templates seem to have been installed incorrectly)\n")) | ||
Matt Mackall
|
r3844 | problems += 1 | ||
# patch | ||||
ui.status(_("Checking patch...\n")) | ||||
path = os.environ.get('PATH', '') | ||||
patcher = util.find_in_path('gpatch', path, | ||||
util.find_in_path('patch', path, None)) | ||||
if not patcher: | ||||
ui.write(_(" Can't find patch or gpatch in PATH\n")) | ||||
Matt Mackall
|
r3848 | ui.write(_(" (specify a patch utility in your .hgrc file)\n")) | ||
Matt Mackall
|
r3844 | problems += 1 | ||
Matt Mackall
|
r3846 | else: | ||
# actually attempt a patch here | ||||
a = "1\n2\n3\n4\n" | ||||
b = "1\n2\n3\ninsert\n4\n" | ||||
d = mdiff.unidiff(a, None, b, None, "a") | ||||
fa = writetemp(a) | ||||
fd = writetemp(d) | ||||
fp = os.popen('%s %s %s' % (patcher, fa, fd)) | ||||
files = [] | ||||
output = "" | ||||
for line in fp: | ||||
output += line | ||||
if line.startswith('patching file '): | ||||
pf = util.parse_patch_output(line.rstrip()) | ||||
files.append(pf) | ||||
if files != [fa]: | ||||
ui.write(_(" unexpected patch output!")) | ||||
Matt Mackall
|
r3848 | ui.write(_(" (you may have an incompatible version of patch)\n")) | ||
Benoit Boissinot
|
r3858 | ui.write(output) | ||
Matt Mackall
|
r3846 | problems += 1 | ||
a = file(fa).read() | ||||
if a != b: | ||||
ui.write(_(" patch test failed!")) | ||||
Matt Mackall
|
r3848 | ui.write(_(" (you may have an incompatible version of patch)\n")) | ||
Matt Mackall
|
r3846 | problems += 1 | ||
os.unlink(fa) | ||||
os.unlink(fd) | ||||
Matt Mackall
|
r3844 | |||
# merge helper | ||||
ui.status(_("Checking merge helper...\n")) | ||||
cmd = (os.environ.get("HGMERGE") or ui.config("ui", "merge") | ||||
or "hgmerge") | ||||
cmdpath = util.find_in_path(cmd, path) | ||||
if not cmdpath: | ||||
cmdpath = util.find_in_path(cmd.split()[0], path) | ||||
if not cmdpath: | ||||
if cmd == 'hgmerge': | ||||
ui.write(_(" No merge helper set and can't find default" | ||||
" hgmerge script in PATH\n")) | ||||
Matt Mackall
|
r3848 | ui.write(_(" (specify a merge helper in your .hgrc file)\n")) | ||
Matt Mackall
|
r3844 | else: | ||
ui.write(_(" Can't find merge helper '%s' in PATH\n") % cmd) | ||||
Matt Mackall
|
r3848 | ui.write(_(" (specify a merge helper in your .hgrc file)\n")) | ||
Matt Mackall
|
r3844 | problems += 1 | ||
Matt Mackall
|
r3846 | else: | ||
# actually attempt a patch here | ||||
fa = writetemp("1\n2\n3\n4\n") | ||||
fl = writetemp("1\n2\n3\ninsert\n4\n") | ||||
fr = writetemp("begin\n1\n2\n3\n4\n") | ||||
r = os.system('%s %s %s %s' % (cmd, fl, fa, fr)) | ||||
if r: | ||||
ui.write(_(" got unexpected merge error %d!") % r) | ||||
problems += 1 | ||||
m = file(fl).read() | ||||
if m != "begin\n1\n2\n3\ninsert\n4\n": | ||||
ui.write(_(" got unexpected merge results!") % r) | ||||
Matt Mackall
|
r3848 | ui.write(_(" (your merge helper may have the" | ||
" wrong argument order)\n")) | ||||
Matt Mackall
|
r3846 | ui.write(m) | ||
os.unlink(fa) | ||||
os.unlink(fl) | ||||
os.unlink(fr) | ||||
Matt Mackall
|
r3844 | |||
# editor | ||||
ui.status(_("Checking commit editor...\n")) | ||||
editor = (os.environ.get("HGEDITOR") or | ||||
ui.config("ui", "editor") or | ||||
os.environ.get("EDITOR", "vi")) | ||||
cmdpath = util.find_in_path(editor, path) | ||||
if not cmdpath: | ||||
cmdpath = util.find_in_path(editor.split()[0], path) | ||||
if not cmdpath: | ||||
Benoit Boissinot
|
r3855 | if editor == 'vi': | ||
Matt Mackall
|
r3844 | ui.write(_(" No commit editor set and can't find vi in PATH\n")) | ||
Matt Mackall
|
r3848 | ui.write(_(" (specify a commit editor in your .hgrc file)\n")) | ||
Matt Mackall
|
r3844 | else: | ||
ui.write(_(" Can't find editor '%s' in PATH\n") % editor) | ||||
Matt Mackall
|
r3848 | ui.write(_(" (specify a commit editor in your .hgrc file)\n")) | ||
Matt Mackall
|
r3844 | problems += 1 | ||
Matt Mackall
|
r3848 | # check username | ||
ui.status(_("Checking username...\n")) | ||||
user = os.environ.get("HGUSER") | ||||
if user is None: | ||||
user = ui.config("ui", "username") | ||||
if user is None: | ||||
user = os.environ.get("EMAIL") | ||||
if not user: | ||||
ui.warn(" ") | ||||
ui.username() | ||||
ui.write(_(" (specify a username in your .hgrc file)\n")) | ||||
Matt Mackall
|
r3844 | if not problems: | ||
ui.status(_("No problems detected\n")) | ||||
else: | ||||
ui.write(_("%s problems detected," | ||||
" please check your install!\n") % problems) | ||||
return problems | ||||
Matt Mackall
|
r3652 | def debugrename(ui, repo, file1, *pats, **opts): | ||
bos@serpentine.internal.keyresearch.com
|
r1194 | """dump rename information""" | ||
Matt Mackall
|
r3652 | |||
ctx = repo.changectx(opts.get('rev', 'tip')) | ||||
for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts, | ||||
ctx.node()): | ||||
m = ctx.filectx(abs).renamed() | ||||
if m: | ||||
ui.write(_("%s renamed from %s:%s\n") % (rel, m[0], hex(m[1]))) | ||||
else: | ||||
ui.write(_("%s not renamed\n") % rel) | ||||
mpm@selenic.com
|
r1116 | |||
Bryan O'Sullivan
|
r820 | def debugwalk(ui, repo, *pats, **opts): | ||
Thomas Arendsen Hein
|
r1053 | """show how files match on given patterns""" | ||
Vadim Gelfer
|
r2882 | items = list(cmdutil.walk(repo, pats, opts)) | ||
Thomas Arendsen Hein
|
r1065 | if not items: | ||
return | ||||
Thomas Arendsen Hein
|
r1309 | fmt = '%%s %%-%ds %%-%ds %%s' % ( | ||
Bryan O'Sullivan
|
r942 | max([len(abs) for (src, abs, rel, exact) in items]), | ||
max([len(rel) for (src, abs, rel, exact) in items])) | ||||
for src, abs, rel, exact in items: | ||||
Thomas Arendsen Hein
|
r1309 | line = fmt % (src, abs, rel, exact and 'exact' or '') | ||
ui.write("%s\n" % line.rstrip()) | ||||
Bryan O'Sullivan
|
r820 | |||
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. | ||||
Matt Mackall
|
r3822 | NOTE: diff may generate unexpected results for merges, as it will | ||
default to comparing against the working directory's first parent | ||||
changeset if no revisions are specified. | ||||
Benoit Boissinot
|
r1437 | When two revision arguments are given, then changes are shown | ||
between those revisions. If only one revision is specified then | ||||
that revision is compared to the working directory, and, when no | ||||
revisions are specified, the working directory files are compared | ||||
to its parent. | ||||
Without the -a option, diff will avoid generating diffs of files | ||||
it detects as binary. With -a, diff will generate a diff anyway, | ||||
probably with undesirable results. | ||||
""" | ||||
Thomas Arendsen Hein
|
r3707 | node1, node2 = cmdutil.revpair(repo, opts['rev']) | ||
mpm@selenic.com
|
r245 | |||
Vadim Gelfer
|
r2882 | fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) | ||
mpm@selenic.com
|
r1014 | |||
Vadim Gelfer
|
r2874 | patch.diff(repo, node1, node2, fns, match=matchfn, | ||
Matt Mackall
|
r2888 | opts=patch.diffopts(ui, opts)) | ||
Thomas Arendsen Hein
|
r396 | |||
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. | ||||
The information shown in the changeset header is: author, | ||||
Matt Mackall
|
r3822 | changeset hash, parent(s) and commit comment. | ||
NOTE: export may generate unexpected diff output for merge changesets, | ||||
as it will compare the merge changeset against its first parent only. | ||||
Benoit Boissinot
|
r1437 | |||
Output may be to a file, in which case the name of the file is | ||||
given using a format string. The formatting rules are as follows: | ||||
%% literal "%" character | ||||
%H changeset hash (40 bytes of hexadecimal) | ||||
%N number of patches being generated | ||||
%R changeset revision number | ||||
%b basename of the exporting repository | ||||
%h short-form changeset hash (12 bytes of hexadecimal) | ||||
%n zero-padded sequence number, starting at 1 | ||||
%r zero-padded changeset revision number | ||||
Without the -a option, export will avoid generating diffs of files | ||||
it detects as binary. With -a, export will generate a diff anyway, | ||||
probably with undesirable results. | ||||
Benoit Boissinot
|
r1571 | |||
With the --switch-parent option, the diff will be against the second | ||||
parent. It can be useful to review a merge. | ||||
Benoit Boissinot
|
r1437 | """ | ||
shaleh@speakeasy.net
|
r610 | if not changesets: | ||
Benoit Boissinot
|
r1402 | raise util.Abort(_("export requires at least one changeset")) | ||
Thomas Arendsen Hein
|
r3707 | revs = cmdutil.revrange(repo, changesets) | ||
Vadim Gelfer
|
r2874 | if len(revs) > 1: | ||
ui.note(_('exporting patches:\n')) | ||||
else: | ||||
ui.note(_('exporting patch:\n')) | ||||
patch.export(repo, map(repo.lookup, revs), template=opts['output'], | ||||
Matt Mackall
|
r2888 | switch_parent=opts['switch_parent'], | ||
opts=patch.diffopts(ui, opts)) | ||||
mpm@selenic.com
|
r246 | |||
Thomas Arendsen Hein
|
r1108 | def grep(ui, repo, pattern, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """search for a pattern in specified files and revisions | ||
Search revisions of files for a regular expression. | ||||
This command behaves differently than Unix grep. It only accepts | ||||
Python/Perl regexps. It searches repository history, not the | ||||
working directory. It always prints the revision number in which | ||||
a match appears. | ||||
By default, grep only prints output for the first revision of a | ||||
file in which it finds a match. To get it to print every revision | ||||
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. | ||||
""" | ||||
Bryan O'Sullivan
|
r1057 | reflags = 0 | ||
Thomas Arendsen Hein
|
r1065 | if opts['ignore_case']: | ||
reflags |= re.I | ||||
Bryan O'Sullivan
|
r1057 | regexp = re.compile(pattern, reflags) | ||
bos@serpentine.internal.keyresearch.com
|
r1146 | sep, eol = ':', '\n' | ||
Thomas Arendsen Hein
|
r1108 | if opts['print0']: | ||
bos@serpentine.internal.keyresearch.com
|
r1146 | sep = eol = '\0' | ||
Bryan O'Sullivan
|
r1057 | |||
fcache = {} | ||||
def getfile(fn): | ||||
if fn not in fcache: | ||||
fcache[fn] = repo.file(fn) | ||||
return fcache[fn] | ||||
def matchlines(body): | ||||
bos@serpentine.internal.keyresearch.com
|
r1059 | begin = 0 | ||
linenum = 0 | ||||
while True: | ||||
match = regexp.search(body, begin) | ||||
Thomas Arendsen Hein
|
r1065 | if not match: | ||
break | ||||
bos@serpentine.internal.keyresearch.com
|
r1059 | mstart, mend = match.span() | ||
linenum += body.count('\n', begin, mstart) + 1 | ||||
lstart = body.rfind('\n', begin, mstart) + 1 or begin | ||||
lend = body.find('\n', mend) | ||||
yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] | ||||
begin = lend + 1 | ||||
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 | |||
Thomas Arendsen Hein
|
r1065 | def __eq__(self, other): | ||
return self.line == other.line | ||||
Bryan O'Sullivan
|
r1057 | |||
matches = {} | ||||
Brendan Cully
|
r2870 | copies = {} | ||
Bryan O'Sullivan
|
r1057 | def grepbody(fn, rev, body): | ||
Brendan Cully
|
r2869 | matches[rev].setdefault(fn, []) | ||
Bryan O'Sullivan
|
r1057 | m = matches[rev][fn] | ||
for lnum, cstart, cend, line in matchlines(body): | ||||
s = linestate(line, lnum, cstart, cend) | ||||
Brendan Cully
|
r2869 | m.append(s) | ||
def difflinestates(a, b): | ||||
sm = difflib.SequenceMatcher(None, a, b) | ||||
for tag, alo, ahi, blo, bhi in sm.get_opcodes(): | ||||
if tag == 'insert': | ||||
Benoit Boissinot
|
r3472 | for i in xrange(blo, bhi): | ||
Brendan Cully
|
r2869 | yield ('+', b[i]) | ||
elif tag == 'delete': | ||||
Benoit Boissinot
|
r3472 | for i in xrange(alo, ahi): | ||
Brendan Cully
|
r2869 | yield ('-', a[i]) | ||
elif tag == 'replace': | ||||
Benoit Boissinot
|
r3472 | for i in xrange(alo, ahi): | ||
Brendan Cully
|
r2869 | yield ('-', a[i]) | ||
Benoit Boissinot
|
r3472 | for i in xrange(blo, bhi): | ||
Brendan Cully
|
r2869 | yield ('+', b[i]) | ||
Bryan O'Sullivan
|
r1057 | prev = {} | ||
def display(fn, rev, states, prevstates): | ||||
Bryan O'Sullivan
|
r1145 | counts = {'-': 0, '+': 0} | ||
bos@serpentine.internal.keyresearch.com
|
r1146 | filerevmatches = {} | ||
Brendan Cully
|
r2869 | if incrementing or not opts['all']: | ||
Matt Mackall
|
r3523 | a, b, r = prevstates, states, rev | ||
Brendan Cully
|
r2869 | else: | ||
Matt Mackall
|
r3523 | a, b, r = states, prevstates, prev.get(fn, -1) | ||
Brendan Cully
|
r2869 | for change, l in difflinestates(a, b): | ||
cols = [fn, str(r)] | ||||
Thomas Arendsen Hein
|
r1615 | if opts['line_number']: | ||
cols.append(str(l.linenum)) | ||||
if opts['all']: | ||||
cols.append(change) | ||||
if opts['user']: | ||||
Matt Mackall
|
r3650 | cols.append(ui.shortuser(get(r)[1])) | ||
bos@serpentine.internal.keyresearch.com
|
r1146 | if opts['files_with_matches']: | ||
Matt Mackall
|
r3523 | c = (fn, r) | ||
Thomas Arendsen Hein
|
r1615 | if c in filerevmatches: | ||
continue | ||||
bos@serpentine.internal.keyresearch.com
|
r1146 | filerevmatches[c] = 1 | ||
else: | ||||
cols.append(l.line) | ||||
ui.write(sep.join(cols), eol) | ||||
Bryan O'Sullivan
|
r1145 | counts[change] += 1 | ||
return counts['+'], counts['-'] | ||||
Bryan O'Sullivan
|
r1057 | |||
fstate = {} | ||||
Bryan O'Sullivan
|
r1145 | skip = {} | ||
Thomas Arendsen Hein
|
r3673 | get = util.cachefunc(lambda r: repo.changectx(r).changeset()) | ||
Matt Mackall
|
r3650 | changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts) | ||
bos@serpentine.internal.keyresearch.com
|
r1146 | count = 0 | ||
mpm@selenic.com
|
r1337 | incrementing = False | ||
Brendan Cully
|
r2870 | follow = opts.get('follow') | ||
bos@serpentine.internal.keyresearch.com
|
r1146 | for st, rev, fns in changeiter: | ||
Bryan O'Sullivan
|
r1057 | if st == 'window': | ||
incrementing = rev | ||||
matches.clear() | ||||
elif st == 'add': | ||||
Matt Mackall
|
r3530 | mf = repo.changectx(rev).manifest() | ||
Bryan O'Sullivan
|
r1057 | matches[rev] = {} | ||
for fn in fns: | ||||
Thomas Arendsen Hein
|
r1615 | if fn in skip: | ||
continue | ||||
Bryan O'Sullivan
|
r1057 | fstate.setdefault(fn, {}) | ||
try: | ||||
grepbody(fn, rev, getfile(fn).read(mf[fn])) | ||||
Brendan Cully
|
r2870 | if follow: | ||
copied = getfile(fn).renamed(mf[fn]) | ||||
if copied: | ||||
Brendan Cully
|
r2931 | copies.setdefault(rev, {})[fn] = copied[0] | ||
Bryan O'Sullivan
|
r1057 | except KeyError: | ||
pass | ||||
elif st == 'iter': | ||||
states = matches[rev].items() | ||||
states.sort() | ||||
for fn, m in states: | ||||
Brendan Cully
|
r2931 | copy = copies.get(rev, {}).get(fn) | ||
Thomas Arendsen Hein
|
r1615 | if fn in skip: | ||
Brendan Cully
|
r2870 | if copy: | ||
skip[copy] = True | ||||
Thomas Arendsen Hein
|
r1615 | continue | ||
mpm@selenic.com
|
r1212 | if incrementing or not opts['all'] or fstate[fn]: | ||
Bryan O'Sullivan
|
r1145 | pos, neg = display(fn, rev, m, fstate[fn]) | ||
bos@serpentine.internal.keyresearch.com
|
r1146 | count += pos + neg | ||
mpm@selenic.com
|
r1212 | if pos and not opts['all']: | ||
Bryan O'Sullivan
|
r1145 | skip[fn] = True | ||
Brendan Cully
|
r2870 | if copy: | ||
skip[copy] = True | ||||
Bryan O'Sullivan
|
r1057 | fstate[fn] = m | ||
Brendan Cully
|
r2870 | if copy: | ||
fstate[copy] = m | ||||
Bryan O'Sullivan
|
r1057 | prev[fn] = rev | ||
if not incrementing: | ||||
fstate = fstate.items() | ||||
fstate.sort() | ||||
for fn, state in fstate: | ||||
Thomas Arendsen Hein
|
r1615 | if fn in skip: | ||
continue | ||||
Brendan Cully
|
r2931 | if fn not in copies.get(prev[fn], {}): | ||
Brendan Cully
|
r2870 | display(fn, rev, {}, state) | ||
bos@serpentine.internal.keyresearch.com
|
r1146 | return (count == 0 and 1) or 0 | ||
Bryan O'Sullivan
|
r1057 | |||
mason@suse.com
|
r898 | def heads(ui, repo, **opts): | ||
Benoit Boissinot
|
r1437 | """show current repository heads | ||
Show all repository head changesets. | ||||
Repository "heads" are changesets that don't have children | ||||
changesets. They are where development generally takes place and | ||||
are the usual targets for update and merge operations. | ||||
""" | ||||
Benoit Boissinot
|
r1550 | if opts['rev']: | ||
Thomas Arendsen Hein
|
r1551 | heads = repo.heads(repo.lookup(opts['rev'])) | ||
Benoit Boissinot
|
r1550 | else: | ||
heads = repo.heads() | ||||
Matt Mackall
|
r3643 | displayer = cmdutil.show_changeset(ui, repo, opts) | ||
Benoit Boissinot
|
r1550 | for n in heads: | ||
Matt Mackall
|
r3649 | displayer.show(changenode=n) | ||
mpm@selenic.com
|
r221 | |||
Matt Mackall
|
r3655 | def help_(ui, name=None, with_version=False): | ||
"""show help for a command, extension, or list of commands | ||||
With no arguments, print a list of commands and short help. | ||||
Given a command name, print help for that command. | ||||
Given an extension name, print help for that extension, and the | ||||
commands it provides.""" | ||||
option_lists = [] | ||||
def helpcmd(name): | ||||
if with_version: | ||||
version_(ui) | ||||
ui.write('\n') | ||||
aliases, i = findcmd(ui, name) | ||||
# synopsis | ||||
ui.write("%s\n\n" % i[2]) | ||||
# description | ||||
doc = i[0].__doc__ | ||||
if not doc: | ||||
doc = _("(No help text available)") | ||||
if ui.quiet: | ||||
doc = doc.splitlines(0)[0] | ||||
ui.write("%s\n" % doc.rstrip()) | ||||
if not ui.quiet: | ||||
# aliases | ||||
if len(aliases) > 1: | ||||
ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) | ||||
# options | ||||
if i[1]: | ||||
option_lists.append(("options", i[1])) | ||||
def helplist(select=None): | ||||
h = {} | ||||
cmds = {} | ||||
for c, e in table.items(): | ||||
f = c.split("|", 1)[0] | ||||
if select and not select(f): | ||||
continue | ||||
if name == "shortlist" and not f.startswith("^"): | ||||
continue | ||||
f = f.lstrip("^") | ||||
if not ui.debugflag and f.startswith("debug"): | ||||
continue | ||||
doc = e[0].__doc__ | ||||
if not doc: | ||||
doc = _("(No help text available)") | ||||
h[f] = doc.splitlines(0)[0].rstrip() | ||||
cmds[f] = c.lstrip("^") | ||||
fns = h.keys() | ||||
fns.sort() | ||||
m = max(map(len, fns)) | ||||
for f in fns: | ||||
if ui.verbose: | ||||
commands = cmds[f].replace("|",", ") | ||||
ui.write(" %s:\n %s\n"%(commands, h[f])) | ||||
else: | ||||
ui.write(' %-*s %s\n' % (m, f, h[f])) | ||||
Matt Mackall
|
r3795 | def helptopic(name): | ||
v = None | ||||
for i in help.helptable: | ||||
l = i.split('|') | ||||
if name in l: | ||||
v = i | ||||
header = l[-1] | ||||
if not v: | ||||
raise UnknownCommand(name) | ||||
# description | ||||
doc = help.helptable[v] | ||||
if not doc: | ||||
doc = _("(No help text available)") | ||||
Matt Mackall
|
r3796 | if callable(doc): | ||
doc = doc() | ||||
Matt Mackall
|
r3795 | |||
ui.write("%s\n" % header) | ||||
ui.write("%s\n" % doc.rstrip()) | ||||
Matt Mackall
|
r3655 | def helpext(name): | ||
try: | ||||
mod = findext(name) | ||||
except KeyError: | ||||
raise UnknownCommand(name) | ||||
doc = (mod.__doc__ or _('No help text available')).splitlines(0) | ||||
ui.write(_('%s extension - %s\n') % (name.split('.')[-1], doc[0])) | ||||
for d in doc[1:]: | ||||
ui.write(d, '\n') | ||||
ui.status('\n') | ||||
if ui.verbose: | ||||
ui.status(_('list of commands:\n\n')) | ||||
else: | ||||
ui.status(_('list of commands (use "hg help -v %s" ' | ||||
'to show aliases and global options):\n\n') % name) | ||||
modcmds = dict.fromkeys([c.split('|', 1)[0] for c in mod.cmdtable]) | ||||
helplist(modcmds.has_key) | ||||
if name and name != 'shortlist': | ||||
Matt Mackall
|
r3795 | i = None | ||
for f in (helpcmd, helptopic, helpext): | ||||
try: | ||||
f(name) | ||||
i = None | ||||
break | ||||
except UnknownCommand, inst: | ||||
i = inst | ||||
if i: | ||||
raise i | ||||
Matt Mackall
|
r3655 | |||
else: | ||||
# program name | ||||
if ui.verbose or with_version: | ||||
version_(ui) | ||||
else: | ||||
ui.status(_("Mercurial Distributed SCM\n")) | ||||
ui.status('\n') | ||||
# list of commands | ||||
if name == "shortlist": | ||||
ui.status(_('basic commands (use "hg help" ' | ||||
'for the full list or option "-v" for details):\n\n')) | ||||
elif ui.verbose: | ||||
ui.status(_('list of commands:\n\n')) | ||||
else: | ||||
ui.status(_('list of commands (use "hg help -v" ' | ||||
'to show aliases and global options):\n\n')) | ||||
helplist() | ||||
# global options | ||||
if ui.verbose: | ||||
option_lists.append(("global options", globalopts)) | ||||
# list all option lists | ||||
opt_output = [] | ||||
for title, options in option_lists: | ||||
opt_output.append(("\n%s:\n" % title, None)) | ||||
for shortopt, longopt, default, desc in options: | ||||
if "DEPRECATED" in desc and not ui.verbose: continue | ||||
opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, | ||||
longopt and " --%s" % longopt), | ||||
"%s%s" % (desc, | ||||
default | ||||
and _(" (default: %s)") % default | ||||
or ""))) | ||||
if opt_output: | ||||
opts_len = max([len(line[0]) for line in opt_output if line[1]]) | ||||
for first, second in opt_output: | ||||
if second: | ||||
ui.write(" %-*s %s\n" % (opts_len, first, second)) | ||||
else: | ||||
ui.write("%s\n" % first) | ||||
mpm@selenic.com
|
r221 | |||
Thomas Arendsen Hein
|
r339 | def identify(ui, repo): | ||
Benoit Boissinot
|
r1437 | """print information about the working copy | ||
TK Soh
|
r1470 | |||
Benoit Boissinot
|
r1437 | Print a short summary of the current state of the repo. | ||
This summary identifies the repository state using one or two parent | ||||
hash identifiers, followed by a "+" if there are uncommitted changes | ||||
in the working directory, followed by a list of tags for this revision. | ||||
""" | ||||
mpm@selenic.com
|
r1092 | parents = [p for p in repo.dirstate.parents() if p != nullid] | ||
Thomas Arendsen Hein
|
r340 | if not parents: | ||
Benoit Boissinot
|
r1402 | ui.write(_("unknown\n")) | ||
Thomas Arendsen Hein
|
r340 | return | ||
Matt Mackall
|
r2966 | hexfunc = ui.debugflag and hex or short | ||
Vadim Gelfer
|
r2875 | modified, added, removed, deleted = repo.status()[:4] | ||
Thomas Arendsen Hein
|
r1619 | output = ["%s%s" % | ||
('+'.join([hexfunc(parent) for parent in parents]), | ||||
(modified or added or removed or deleted) and "+" or "")] | ||||
Thomas Arendsen Hein
|
r386 | |||
Thomas Arendsen Hein
|
r339 | if not ui.quiet: | ||
Matt Mackall
|
r3415 | |||
Alexis S. L. Carvalho
|
r3862 | branch = util.tolocal(repo.workingctx().branch()) | ||
Matt Mackall
|
r3415 | if branch: | ||
output.append("(%s)" % branch) | ||||
Thomas Arendsen Hein
|
r386 | # multiple tags for a single parent separated by '/' | ||
parenttags = ['/'.join(tags) | ||||
for tags in map(repo.nodetags, parents) if tags] | ||||
# tags for multiple parents separated by ' + ' | ||||
Thomas Arendsen Hein
|
r758 | if parenttags: | ||
output.append(' + '.join(parenttags)) | ||||
Thomas Arendsen Hein
|
r339 | |||
Thomas Arendsen Hein
|
r386 | ui.write("%s\n" % ' '.join(output)) | ||
Thomas Arendsen Hein
|
r339 | |||
mpm@selenic.com
|
r437 | def import_(ui, repo, patch1, *patches, **opts): | ||
Benoit Boissinot
|
r1437 | """import an ordered set of patches | ||
Import a list of patches and commit them individually. | ||||
If there are outstanding changes in the working directory, import | ||||
will abort unless given the -f flag. | ||||
Vadim Gelfer
|
r2504 | You can import a patch straight from a mail message. Even patches | ||
as attachments work (body part must be type text/plain or | ||||
Vadim Gelfer
|
r2515 | text/x-patch to be used). From and Subject headers of email | ||
message are used as default committer and commit message. All | ||||
text/plain body parts before first diff are added to commit | ||||
message. | ||||
Vadim Gelfer
|
r2504 | |||
If imported patch was generated by hg export, user and description | ||||
from patch override values from message headers and body. Values | ||||
given on command line with -m and -u override these. | ||||
Vadim Gelfer
|
r2400 | |||
To read a patch from standard input, use patch name "-". | ||||
Benoit Boissinot
|
r1437 | """ | ||
mpm@selenic.com
|
r437 | patches = (patch1,) + patches | ||
mpm@selenic.com
|
r500 | |||
mpm@selenic.com
|
r966 | if not opts['force']: | ||
Vadim Gelfer
|
r2158 | bail_if_changed(repo) | ||
mpm@selenic.com
|
r966 | |||
mpm@selenic.com
|
r437 | d = opts["base"] | ||
strip = opts["strip"] | ||||
Vadim Gelfer
|
r2854 | wlock = repo.wlock() | ||
lock = repo.lock() | ||||
Brendan Cully
|
r2861 | for p in patches: | ||
pf = os.path.join(d, p) | ||||
mpm@selenic.com
|
r437 | |||
Vadim Gelfer
|
r2400 | if pf == '-': | ||
ui.status(_("applying patch from stdin\n")) | ||||
Vadim Gelfer
|
r2866 | tmpname, message, user, date = patch.extract(ui, sys.stdin) | ||
Vadim Gelfer
|
r2400 | else: | ||
Brendan Cully
|
r2861 | ui.status(_("applying %s\n") % p) | ||
Vadim Gelfer
|
r2866 | tmpname, message, user, date = patch.extract(ui, file(pf)) | ||
if tmpname is None: | ||||
raise util.Abort(_('no diffs found')) | ||||
Vadim Gelfer
|
r2400 | try: | ||
Mathieu Clabaut
|
r3857 | cmdline_message = logmessage(opts) | ||
if cmdline_message: | ||||
Benoit Boissinot
|
r2458 | # pickup the cmdline msg | ||
Mathieu Clabaut
|
r3857 | message = cmdline_message | ||
Benoit Boissinot
|
r2458 | elif message: | ||
# pickup the patch msg | ||||
Vadim Gelfer
|
r2504 | message = message.strip() | ||
Vadim Gelfer
|
r2400 | else: | ||
Benoit Boissinot
|
r2458 | # launch the editor | ||
message = None | ||||
Vadim Gelfer
|
r2400 | ui.debug(_('message:\n%s\n') % message) | ||
Brendan Cully
|
r3465 | files = {} | ||
try: | ||||
fuzz = patch.patch(tmpname, ui, strip=strip, cwd=repo.root, | ||||
files=files) | ||||
finally: | ||||
files = patch.updatedir(ui, repo, files, wlock=wlock) | ||||
Vadim Gelfer
|
r2854 | repo.commit(files, message, user, date, wlock=wlock, lock=lock) | ||
Vadim Gelfer
|
r2400 | finally: | ||
Vadim Gelfer
|
r2504 | os.unlink(tmpname) | ||
mpm@selenic.com
|
r437 | |||
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 | ||
pull location. These are the changesets that would be pulled if a pull | ||||
Benoit Boissinot
|
r1437 | was requested. | ||
Benoit Boissinot
|
r1944 | For remote repository, using --bundle avoids downloading the changesets | ||
twice if the incoming is followed by a pull. | ||||
Thomas Arendsen Hein
|
r1979 | |||
See pull for valid source format details. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Thomas Arendsen Hein
|
r1893 | source = ui.expandpath(source) | ||
Matt Mackall
|
r2731 | setremoteconfig(ui, opts) | ||
Benoit Boissinot
|
r1965 | |||
mpm@selenic.com
|
r927 | other = hg.repository(ui, source) | ||
Vadim Gelfer
|
r1959 | incoming = repo.findincoming(other, force=opts["force"]) | ||
Benoit Boissinot
|
r1944 | if not incoming: | ||
TK Soh
|
r1993 | ui.status(_("no changes found\n")) | ||
mpm@selenic.com
|
r931 | return | ||
Benoit Boissinot
|
r1944 | |||
cleanup = None | ||||
Thomas Arendsen Hein
|
r1974 | try: | ||
fname = opts["bundle"] | ||||
if fname or not other.local(): | ||||
# create a bundle (uncompressed if other repo is not local) | ||||
cg = other.changegroup(incoming, "incoming") | ||||
Thomas Arendsen Hein
|
r3706 | bundletype = other.local() and "HG10BZ" or "HG10UN" | ||
fname = cleanup = changegroup.writebundle(cg, fname, bundletype) | ||||
Thomas Arendsen Hein
|
r1974 | # keep written bundle? | ||
if opts["bundle"]: | ||||
cleanup = None | ||||
if not other.local(): | ||||
# use the created uncompressed bundlerepo | ||||
other = bundlerepo.bundlerepository(ui, repo.root, fname) | ||||
Benoit Boissinot
|
r2521 | revs = None | ||
if opts['rev']: | ||||
revs = [other.lookup(rev) for rev in opts['rev']] | ||||
o = other.changelog.nodesbetween(incoming, revs)[0] | ||||
Thomas Arendsen Hein
|
r1974 | if opts['newest_first']: | ||
o.reverse() | ||||
Matt Mackall
|
r3643 | displayer = cmdutil.show_changeset(ui, other, opts) | ||
Thomas Arendsen Hein
|
r1974 | for n in o: | ||
parents = [p for p in other.changelog.parents(n) if p != nullid] | ||||
if opts['no_merges'] and len(parents) == 2: | ||||
continue | ||||
displayer.show(changenode=n) | ||||
finally: | ||||
if hasattr(other, 'close'): | ||||
other.close() | ||||
if cleanup: | ||||
os.unlink(cleanup) | ||||
Benoit Boissinot
|
r1944 | |||
Thomas Arendsen Hein
|
r2598 | def init(ui, dest=".", **opts): | ||
Benoit Boissinot
|
r1437 | """create a new repository in the given directory | ||
Initialize a new repository in the given directory. If the given | ||||
directory does not exist, it is created. | ||||
If no directory is given, the current directory is used. | ||||
Thomas Arendsen Hein
|
r2590 | |||
It is possible to specify an ssh:// URL as the destination. | ||||
Look at the help text for the pull command for important details | ||||
about ssh:// URLs. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r2731 | setremoteconfig(ui, opts) | ||
Bryan O'Sullivan
|
r907 | hg.repository(ui, dest, create=1) | ||
mpm@selenic.com
|
r338 | |||
Bryan O'Sullivan
|
r627 | def locate(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """locate files matching specific patterns | ||
Print all files under Mercurial control whose names match the | ||||
given patterns. | ||||
This command searches the current directory and its | ||||
subdirectories. To search an entire repository, move to the root | ||||
of the repository. | ||||
If no patterns are given to match, this command prints all file | ||||
names. | ||||
If you want to feed the output of this command into the "xargs" | ||||
command, use the "-0" option to both this command and "xargs". | ||||
This will avoid the problem of "xargs" treating single filenames | ||||
that contain white space as multiple filenames. | ||||
""" | ||||
Thomas Arendsen Hein
|
r1065 | end = opts['print0'] and '\0' or '\n' | ||
Benoit Boissinot
|
r1622 | rev = opts['rev'] | ||
if rev: | ||||
node = repo.lookup(rev) | ||||
else: | ||||
node = None | ||||
mpm@selenic.com
|
r742 | |||
Vadim Gelfer
|
r2882 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node, | ||
head='(?:.*/|)'): | ||||
Benoit Boissinot
|
r1622 | if not node and repo.dirstate.state(abs) == '?': | ||
Thomas Arendsen Hein
|
r1065 | continue | ||
Thomas Arendsen Hein
|
r697 | if opts['fullpath']: | ||
Bryan O'Sullivan
|
r724 | ui.write(os.path.join(repo.root, abs), end) | ||
else: | ||||
Benoit Boissinot
|
r1625 | ui.write(((pats and rel) or abs), end) | ||
Bryan O'Sullivan
|
r627 | |||
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. | ||||
File history is shown without following rename or copy history of | ||||
Brendan Cully
|
r2782 | files. Use -f/--follow with a file name to follow history across | ||
renames and copies. --follow without a file name will only show | ||||
Brendan Cully
|
r2784 | ancestors or descendants of the starting revision. --follow-first | ||
only follows the first parent of merge revisions. | ||||
Benoit Boissinot
|
r1437 | |||
Brendan Cully
|
r2783 | 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. | ||||
Benoit Boissinot
|
r1437 | By default this command outputs: changeset id and hash, tags, | ||
Thomas Arendsen Hein
|
r1557 | 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 is shown. | ||||
Matt Mackall
|
r3822 | |||
NOTE: log -p may generate unexpected diff output for merge | ||||
changesets, as it will compare the merge changeset against its | ||||
first parent only. Also, the files: list will only reflect files | ||||
that are different from BOTH parents. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Vadim Gelfer
|
r1756 | |||
Thomas Arendsen Hein
|
r3673 | get = util.cachefunc(lambda r: repo.changectx(r).changeset()) | ||
Matt Mackall
|
r3650 | changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts) | ||
Matt Mackall
|
r3518 | |||
Vadim Gelfer
|
r1756 | if opts['limit']: | ||
try: | ||||
limit = int(opts['limit']) | ||||
except ValueError: | ||||
raise util.Abort(_('limit must be a positive integer')) | ||||
if limit <= 0: raise util.Abort(_('limit must be positive')) | ||||
else: | ||||
limit = sys.maxint | ||||
count = 0 | ||||
Brendan Cully
|
r3197 | if opts['copies'] and opts['rev']: | ||
Thomas Arendsen Hein
|
r3707 | endrev = max(cmdutil.revrange(repo, opts['rev'])) + 1 | ||
Brendan Cully
|
r3197 | else: | ||
endrev = repo.changelog.count() | ||||
rcache = {} | ||||
ncache = {} | ||||
dcache = [] | ||||
def getrenamed(fn, rev, man): | ||||
'''looks up all renames for a file (up to endrev) the first | ||||
time the file is given. It indexes on the changerev and only | ||||
parses the manifest if linkrev != changerev. | ||||
Returns rename info for fn at changerev rev.''' | ||||
if fn not in rcache: | ||||
rcache[fn] = {} | ||||
ncache[fn] = {} | ||||
fl = repo.file(fn) | ||||
for i in xrange(fl.count()): | ||||
node = fl.node(i) | ||||
lr = fl.linkrev(node) | ||||
renamed = fl.renamed(node) | ||||
rcache[fn][lr] = renamed | ||||
if renamed: | ||||
ncache[fn][node] = renamed | ||||
if lr >= endrev: | ||||
break | ||||
if rev in rcache[fn]: | ||||
return rcache[fn][rev] | ||||
Brendan Cully
|
r3386 | mr = repo.manifest.rev(man) | ||
Thomas Arendsen Hein
|
r3578 | if repo.manifest.parentrevs(mr) != (mr - 1, nullrev): | ||
Brendan Cully
|
r3384 | return ncache[fn].get(repo.manifest.find(man, fn)[0]) | ||
Brendan Cully
|
r3197 | if not dcache or dcache[0] != man: | ||
dcache[:] = [man, repo.manifest.readdelta(man)] | ||||
if fn in dcache[1]: | ||||
return ncache[fn].get(dcache[1][fn]) | ||||
return None | ||||
Matt Mackall
|
r3813 | df = False | ||
if opts["date"]: | ||||
df = util.matchdate(opts["date"]) | ||||
Matt Mackall
|
r3837 | displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn) | ||
bos@serpentine.internal.keyresearch.com
|
r1146 | for st, rev, fns in changeiter: | ||
Matt Mackall
|
r3645 | if st == 'add': | ||
Benoit Boissinot
|
r1435 | changenode = repo.changelog.node(rev) | ||
Thomas Arendsen Hein
|
r3578 | parents = [p for p in repo.changelog.parentrevs(rev) | ||
if p != nullrev] | ||||
Benoit Boissinot
|
r1435 | if opts['no_merges'] and len(parents) == 2: | ||
Thomas Arendsen Hein
|
r1615 | continue | ||
Benoit Boissinot
|
r1436 | if opts['only_merges'] and len(parents) != 2: | ||
Thomas Arendsen Hein
|
r1615 | continue | ||
Benoit Boissinot
|
r1435 | |||
Matt Mackall
|
r3813 | if df: | ||
changes = get(rev) | ||||
if not df(changes[2][0]): | ||||
continue | ||||
Matt Mackall
|
r1373 | if opts['keyword']: | ||
Matt Mackall
|
r3650 | changes = get(rev) | ||
Matt Mackall
|
r1373 | miss = 0 | ||
TK Soh
|
r1404 | for k in [kw.lower() for kw in opts['keyword']]: | ||
Matt Mackall
|
r1373 | if not (k in changes[1].lower() or | ||
k in changes[4].lower() or | ||||
k in " ".join(changes[3][:20]).lower()): | ||||
miss = 1 | ||||
break | ||||
if miss: | ||||
continue | ||||
Brendan Cully
|
r3197 | copies = [] | ||
if opts.get('copies') and rev: | ||||
Matt Mackall
|
r3650 | mf = get(rev)[0] | ||
for fn in get(rev)[3]: | ||||
Brendan Cully
|
r3197 | rename = getrenamed(fn, rev, mf) | ||
if rename: | ||||
copies.append((fn, rename[0])) | ||||
Matt Mackall
|
r3649 | displayer.show(rev, changenode, copies=copies) | ||
Bryan O'Sullivan
|
r1057 | elif st == 'iter': | ||
Vadim Gelfer
|
r1756 | if count == limit: break | ||
Matt Mackall
|
r3645 | if displayer.flush(rev): | ||
Thomas Arendsen Hein
|
r1765 | count += 1 | ||
mpm@selenic.com
|
r255 | |||
Thomas Arendsen Hein
|
r697 | def manifest(ui, repo, rev=None): | ||
Benoit Boissinot
|
r1437 | """output the latest or given revision of the project manifest | ||
Print a list of version controlled files for the given revision. | ||||
The manifest is the list of files being version controlled. If no revision | ||||
Matt Mackall
|
r3736 | is given then the first parent of the working directory is used. | ||
With -v flag, print file permissions. With --debug flag, print | ||||
file revision hashes. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r3736 | |||
m = repo.changectx(rev).manifest() | ||||
mpm@selenic.com
|
r255 | files = m.keys() | ||
files.sort() | ||||
for f in files: | ||||
Matt Mackall
|
r3736 | if ui.debugflag: | ||
ui.write("%40s " % hex(m[f])) | ||||
if ui.verbose: | ||||
ui.write("%3s " % (m.execf(f) and "755" or "644")) | ||||
ui.write("%s\n" % f) | ||||
mpm@selenic.com
|
r255 | |||
Matt Mackall
|
r3815 | def merge(ui, repo, node=None, force=None, branch=None): | ||
Vadim Gelfer
|
r2019 | """Merge working directory with another revision | ||
Merge the contents of the current working directory and the | ||||
requested revision. Files that changed between either parent are | ||||
marked as changed for the next commit and a commit must be | ||||
performed before any further updates are allowed. | ||||
Vadim Gelfer
|
r2915 | |||
If no revision is specified, the working directory's parent is a | ||||
head revision, and the repository contains exactly one other head, | ||||
the other head is merged with by default. Otherwise, an explicit | ||||
revision to merge with must be provided. | ||||
Vadim Gelfer
|
r2019 | """ | ||
Matt Mackall
|
r2806 | |||
Benoit Boissinot
|
r3071 | if node or branch: | ||
Vadim Gelfer
|
r2915 | node = _lookup(repo, node, branch) | ||
else: | ||||
heads = repo.heads() | ||||
if len(heads) > 2: | ||||
raise util.Abort(_('repo has %d heads - ' | ||||
'please merge with an explicit rev') % | ||||
len(heads)) | ||||
if len(heads) == 1: | ||||
raise util.Abort(_('there is nothing to merge - ' | ||||
'use "hg update" instead')) | ||||
parent = repo.dirstate.parents()[0] | ||||
if parent not in heads: | ||||
raise util.Abort(_('working dir not at a head rev - ' | ||||
'use "hg update" or merge with an explicit rev')) | ||||
node = parent == heads[0] and heads[-1] or heads[0] | ||||
Matt Mackall
|
r2808 | return hg.merge(repo, node, force=force) | ||
Vadim Gelfer
|
r2029 | |||
Vadim Gelfer
|
r2494 | def outgoing(ui, repo, dest=None, **opts): | ||
Benoit Boissinot
|
r1437 | """show changesets not found in destination | ||
Thomas Arendsen Hein
|
r1979 | Show changesets not found in the specified destination repository or | ||
the default push location. These are the changesets that would be pushed | ||||
Benoit Boissinot
|
r1437 | if a push was requested. | ||
Benoit Boissinot
|
r1811 | |||
Thomas Arendsen Hein
|
r1979 | See pull for valid destination format details. | ||
Benoit Boissinot
|
r1437 | """ | ||
Vadim Gelfer
|
r2494 | dest = ui.expandpath(dest or 'default-push', dest or 'default') | ||
Matt Mackall
|
r2731 | setremoteconfig(ui, opts) | ||
Benoit Boissinot
|
r2521 | revs = None | ||
if opts['rev']: | ||||
revs = [repo.lookup(rev) for rev in opts['rev']] | ||||
Benoit Boissinot
|
r1965 | |||
mpm@selenic.com
|
r920 | other = hg.repository(ui, dest) | ||
Vadim Gelfer
|
r1959 | o = repo.findoutgoing(other, force=opts['force']) | ||
Thomas Arendsen Hein
|
r1994 | if not o: | ||
ui.status(_("no changes found\n")) | ||||
return | ||||
Benoit Boissinot
|
r2521 | o = repo.changelog.nodesbetween(o, revs)[0] | ||
Michal Kvasnica
|
r1439 | if opts['newest_first']: | ||
o.reverse() | ||||
Matt Mackall
|
r3643 | displayer = cmdutil.show_changeset(ui, repo, opts) | ||
mpm@selenic.com
|
r920 | for n in o: | ||
Benoit Boissinot
|
r1435 | parents = [p for p in repo.changelog.parents(n) if p != nullid] | ||
if opts['no_merges'] and len(parents) == 2: | ||||
continue | ||||
Vadim Gelfer
|
r1907 | displayer.show(changenode=n) | ||
mpm@selenic.com
|
r920 | |||
Matt Mackall
|
r3658 | def parents(ui, repo, file_=None, **opts): | ||
Benoit Boissinot
|
r1437 | """show the parents of the working dir or revision | ||
Print the working directory's parent revisions. | ||||
""" | ||||
Matt Mackall
|
r3658 | rev = opts.get('rev') | ||
Thomas Arendsen Hein
|
r706 | if rev: | ||
Benoit Boissinot
|
r2644 | if file_: | ||
ctx = repo.filectx(file_, changeid=rev) | ||||
else: | ||||
ctx = repo.changectx(rev) | ||||
p = [cp.node() for cp in ctx.parents()] | ||||
mpm@selenic.com
|
r255 | else: | ||
p = repo.dirstate.parents() | ||||
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: | ||
Matt Mackall
|
r3649 | displayer.show(changenode=n) | ||
mpm@selenic.com
|
r255 | |||
Thomas Arendsen Hein
|
r1858 | def paths(ui, repo, search=None): | ||
Benoit Boissinot
|
r1437 | """show definition of symbolic path names | ||
Show definition of symbolic path name NAME. If no name is given, show | ||||
definition of available names. | ||||
Path names are defined in the [paths] section of /etc/mercurial/hgrc | ||||
and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. | ||||
""" | ||||
TK Soh
|
r779 | if search: | ||
for name, path in ui.configitems("paths"): | ||||
if name == search: | ||||
ui.write("%s\n" % path) | ||||
return | ||||
Benoit Boissinot
|
r1402 | ui.warn(_("not found!\n")) | ||
TK Soh
|
r779 | return 1 | ||
else: | ||||
for name, path in ui.configitems("paths"): | ||||
ui.write("%s = %s\n" % (name, path)) | ||||
Vadim Gelfer
|
r2019 | def postincoming(ui, repo, modheads, optupdate): | ||
if modheads == 0: | ||||
return | ||||
if optupdate: | ||||
if modheads == 1: | ||||
Matt Mackall
|
r2806 | return hg.update(repo, repo.changelog.tip()) # update | ||
Vadim Gelfer
|
r2019 | else: | ||
ui.status(_("not updating, since new heads added\n")) | ||||
if modheads > 1: | ||||
ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) | ||||
else: | ||||
ui.status(_("(run 'hg update' to get a working copy)\n")) | ||||
Vadim Gelfer
|
r2029 | |||
mpm@selenic.com
|
r404 | def pull(ui, repo, source="default", **opts): | ||
Benoit Boissinot
|
r1437 | """pull changes from the specified source | ||
Pull changes from a remote repository to a local one. | ||||
This finds all changes from the repository at the specified path | ||||
or URL and adds them to the local repository. By default, this | ||||
does not update the copy of the project in the working directory. | ||||
Valid URLs are of the form: | ||||
Thomas Arendsen Hein
|
r3563 | local/filesystem/path (or file://local/filesystem/path) | ||
"Aurelien Jacobs "
|
r2589 | http://[user@]host[:port]/[path] | ||
https://[user@]host[:port]/[path] | ||||
ssh://[user@]host[:port]/[path] | ||||
Thomas Arendsen Hein
|
r3563 | static-http://host[:port]/[path] | ||
Paths in the local filesystem can either point to Mercurial | ||||
repositories or to bundle files (as created by 'hg bundle' or | ||||
'hg incoming --bundle'). The static-http:// protocol, albeit slow, | ||||
allows access to a Mercurial repository where you simply use a web | ||||
server to publish the .hg directory as static content. | ||||
Benoit Boissinot
|
r1437 | |||
Thomas Arendsen Hein
|
r1979 | Some notes about using SSH with Mercurial: | ||
- SSH requires an accessible shell account on the destination machine | ||||
and a copy of hg in the remote path or specified with as remotecmd. | ||||
"Aurelien Jacobs "
|
r2589 | - path is relative to the remote user's home directory by default. | ||
Thomas Arendsen Hein
|
r2590 | Use an extra slash at the start of a path to specify an absolute path: | ||
ssh://example.com//tmp/repository | ||||
Thomas Arendsen Hein
|
r1979 | - Mercurial doesn't use its own compression via SSH; the right thing | ||
Thomas Arendsen Hein
|
r3471 | to do is to configure it in your ~/.ssh/config, e.g.: | ||
Thomas Arendsen Hein
|
r1979 | Host *.mylocalnetwork.example.com | ||
Thomas Arendsen Hein
|
r3471 | Compression no | ||
Thomas Arendsen Hein
|
r1979 | Host * | ||
Thomas Arendsen Hein
|
r3471 | Compression yes | ||
Thomas Arendsen Hein
|
r1979 | Alternatively specify "ssh -C" as your ssh command in your hgrc or | ||
with the --ssh command line option. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Thomas Arendsen Hein
|
r1893 | source = ui.expandpath(source) | ||
Matt Mackall
|
r2731 | setremoteconfig(ui, opts) | ||
mpm@selenic.com
|
r963 | |||
mpm@selenic.com
|
r246 | other = hg.repository(ui, source) | ||
Vadim Gelfer
|
r2473 | ui.status(_('pulling from %s\n') % (source)) | ||
Eric Hopper
|
r1465 | revs = None | ||
Eric Hopper
|
r3448 | if opts['rev']: | ||
if 'lookup' in other.capabilities: | ||||
revs = [other.lookup(rev) for rev in opts['rev']] | ||||
else: | ||||
error = _("Other repository doesn't support revision lookup, so a rev cannot be specified.") | ||||
raise util.Abort(error) | ||||
Vadim Gelfer
|
r2019 | modheads = repo.pull(other, heads=revs, force=opts['force']) | ||
return postincoming(ui, repo, modheads, opts['update']) | ||||
mpm@selenic.com
|
r246 | |||
Vadim Gelfer
|
r2494 | def push(ui, repo, dest=None, **opts): | ||
Benoit Boissinot
|
r1437 | """push changes to the specified destination | ||
Push changes from the local repository to the given destination. | ||||
This is the symmetrical operation for pull. It helps to move | ||||
changes from the current repository to a different one. If the | ||||
destination is local this is identical to a pull in that directory | ||||
from the current one. | ||||
By default, push will refuse to run if it detects the result would | ||||
increase the number of remote heads. This generally indicates the | ||||
the client has forgotten to sync and merge before pushing. | ||||
Valid URLs are of the form: | ||||
Thomas Arendsen Hein
|
r3563 | local/filesystem/path (or file://local/filesystem/path) | ||
"Aurelien Jacobs "
|
r2589 | ssh://[user@]host[:port]/[path] | ||
Thomas Arendsen Hein
|
r3563 | http://[user@]host[:port]/[path] | ||
https://[user@]host[:port]/[path] | ||||
Benoit Boissinot
|
r1437 | |||
Thomas Arendsen Hein
|
r1979 | Look at the help text for the pull command for important details | ||
about ssh:// URLs. | ||||
Thomas Arendsen Hein
|
r2590 | |||
Thomas Arendsen Hein
|
r3563 | Pushing to http:// and https:// URLs is only possible, if this | ||
feature is explicitly enabled on the remote Mercurial server. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Vadim Gelfer
|
r2494 | dest = ui.expandpath(dest or 'default-push', dest or 'default') | ||
Matt Mackall
|
r2731 | setremoteconfig(ui, opts) | ||
mpm@selenic.com
|
r961 | |||
Matt Mackall
|
r640 | other = hg.repository(ui, dest) | ||
Vadim Gelfer
|
r2473 | ui.status('pushing to %s\n' % (dest)) | ||
Benoit Boissinot
|
r1781 | revs = None | ||
if opts['rev']: | ||||
revs = [repo.lookup(rev) for rev in opts['rev']] | ||||
r = repo.push(other, opts['force'], revs=revs) | ||||
Vadim Gelfer
|
r2019 | return r == 0 | ||
mpm@selenic.com
|
r319 | |||
Matt Mackall
|
r3653 | def rawcommit(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1812 | """raw commit interface (DEPRECATED) | ||
Benoit Boissinot
|
r1811 | |||
(DEPRECATED) | ||||
Benoit Boissinot
|
r1437 | Lowlevel commit, for use in helper scripts. | ||
This command is not intended to be used by normal users, as it is | ||||
primarily useful for importing from other SCMs. | ||||
Matt Mackall
|
r1657 | |||
This command is now deprecated and will be removed in a future | ||||
release, please use debugsetparents and commit instead. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Matt Mackall
|
r1657 | |||
ui.warn(_("(the rawcommit command is deprecated)\n")) | ||||
Matt Mackall
|
r3653 | message = logmessage(opts) | ||
files, match, anypats = cmdutil.matchpats(repo, pats, opts) | ||||
if opts['files']: | ||||
files += open(opts['files']).read().splitlines() | ||||
parents = [repo.lookup(p) for p in opts['parent']] | ||||
mpm@selenic.com
|
r500 | |||
Bryan O'Sullivan
|
r1202 | try: | ||
Matt Mackall
|
r3659 | repo.rawcommit(files, message, opts['user'], opts['date'], *parents) | ||
Bryan O'Sullivan
|
r1202 | except ValueError, inst: | ||
raise util.Abort(str(inst)) | ||||
mpm@selenic.com
|
r500 | |||
mpm@selenic.com
|
r245 | def recover(ui, repo): | ||
Benoit Boissinot
|
r1437 | """roll back an interrupted transaction | ||
Recover from an interrupted commit or pull. | ||||
This command tries to fix the repository status after an interrupted | ||||
operation. It should only be necessary when Mercurial suggests it. | ||||
""" | ||||
Matt Mackall
|
r1516 | if repo.recover(): | ||
Matt Mackall
|
r2778 | return hg.verify(repo) | ||
Thomas Arendsen Hein
|
r2057 | return 1 | ||
mpm@selenic.com
|
r245 | |||
Vadim Gelfer
|
r2179 | def remove(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """remove the specified files on the next commit | ||
Schedule the indicated files for removal from the repository. | ||||
This only removes files from the current branch, not from the | ||||
entire project history. If the files still exist in the working | ||||
Vadim Gelfer
|
r2179 | directory, they will be deleted from it. If invoked with --after, | ||
files that have been manually deleted are marked as removed. | ||||
Vadim Gelfer
|
r2309 | |||
Matt Mackall
|
r3829 | This command schedules the files to be removed at the next commit. | ||
To undo a remove before that, see hg revert. | ||||
Vadim Gelfer
|
r2309 | Modified files and added files are not removed by default. To | ||
remove them, use the -f/--force option. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Bryan O'Sullivan
|
r1188 | names = [] | ||
Vadim Gelfer
|
r2179 | if not opts['after'] and not pats: | ||
raise util.Abort(_('no files specified')) | ||||
Vadim Gelfer
|
r2882 | files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) | ||
Vadim Gelfer
|
r2309 | exact = dict.fromkeys(files) | ||
Vadim Gelfer
|
r2875 | mardu = map(dict.fromkeys, repo.status(files=files, match=matchfn))[:5] | ||
Vadim Gelfer
|
r2309 | modified, added, removed, deleted, unknown = mardu | ||
remove, forget = [], [] | ||||
Vadim Gelfer
|
r2882 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts): | ||
Bryan O'Sullivan
|
r1189 | reason = None | ||
Vadim Gelfer
|
r2309 | if abs not in deleted and opts['after']: | ||
Vadim Gelfer
|
r2179 | reason = _('is still present') | ||
Vadim Gelfer
|
r2309 | elif abs in modified and not opts['force']: | ||
reason = _('is modified (use -f to force removal)') | ||||
elif abs in added: | ||||
if opts['force']: | ||||
forget.append(abs) | ||||
continue | ||||
reason = _('has been marked for add (use -f to force removal)') | ||||
elif abs in unknown: | ||||
Thomas Arendsen Hein
|
r1615 | reason = _('is not managed') | ||
Vadim Gelfer
|
r2309 | elif abs in removed: | ||
continue | ||||
Bryan O'Sullivan
|
r1255 | if reason: | ||
Thomas Arendsen Hein
|
r1615 | if exact: | ||
ui.warn(_('not removing %s: file %s\n') % (rel, reason)) | ||||
Bryan O'Sullivan
|
r1189 | else: | ||
Thomas Arendsen Hein
|
r1615 | if ui.verbose or not exact: | ||
ui.status(_('removing %s\n') % rel) | ||||
Vadim Gelfer
|
r2309 | remove.append(abs) | ||
repo.forget(forget) | ||||
repo.remove(remove, unlink=not opts['after']) | ||||
mpm@selenic.com
|
r245 | |||
Bryan O'Sullivan
|
r1253 | def rename(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """rename files; equivalent of copy + remove | ||
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. | ||||
By default, this command copies the contents of files as they | ||||
stand in the working directory. If invoked with --after, the | ||||
operation is recorded, but no copying is performed. | ||||
Matt Mackall
|
r3829 | This command takes effect in the next commit. To undo a rename | ||
before that, see hg revert. | ||||
Benoit Boissinot
|
r1437 | """ | ||
Vadim Gelfer
|
r2016 | wlock = repo.wlock(0) | ||
errs, copied = docopy(ui, repo, pats, opts, wlock) | ||||
names = [] | ||||
for abs, rel, exact in copied: | ||||
if ui.verbose or not exact: | ||||
ui.status(_('removing %s\n') % rel) | ||||
names.append(abs) | ||||
Thomas Arendsen Hein
|
r2503 | if not opts.get('dry_run'): | ||
Vadim Gelfer
|
r2414 | repo.remove(names, True, wlock) | ||
Bryan O'Sullivan
|
r1253 | return errs | ||
Benoit Boissinot
|
r1472 | def revert(ui, repo, *pats, **opts): | ||
Vadim Gelfer
|
r2227 | """revert files or dirs to their states as of some revision | ||
Vadim Gelfer
|
r2204 | |||
Vadim Gelfer
|
r2212 | With no revision specified, revert the named files or directories | ||
to the contents they had in the parent of the working directory. | ||||
This restores the contents of the affected files to an unmodified | ||||
Matt Mackall
|
r3829 | state and unschedules adds, removes, copies, and renames. If the | ||
working directory has two parents, you must explicitly specify the | ||||
revision to revert to. | ||||
Benoit Boissinot
|
r1811 | |||
Thomas Arendsen Hein
|
r2036 | Modified files are saved with a .orig suffix before reverting. | ||
To disable these backups, use --no-backup. | ||||
Vadim Gelfer
|
r2029 | |||
TK Soh
|
r3016 | Using the -r option, revert the given files or directories to their | ||
contents as of a specific revision. This can be helpful to "roll | ||||
Benoit Boissinot
|
r1811 | back" some or all of a change that should not have been committed. | ||
Revert modifies the working directory. It does not commit any | ||||
Vadim Gelfer
|
r2204 | changes, or change the parent of the working directory. If you | ||
revert to a revision other than the parent of the working | ||||
directory, the reverted files will thus appear modified | ||||
afterwards. | ||||
Benoit Boissinot
|
r1437 | |||
If a file has been deleted, it is recreated. If the executable | ||||
mode of a file was changed, it is reset. | ||||
Benoit Boissinot
|
r1472 | If names are given, all files matching the names are reverted. | ||
Benoit Boissinot
|
r1437 | |||
Vadim Gelfer
|
r2982 | If no arguments are given, no files are reverted. | ||
Benoit Boissinot
|
r1437 | """ | ||
Vadim Gelfer
|
r2982 | |||
Matt Mackall
|
r3814 | if opts["date"]: | ||
if opts["rev"]: | ||||
raise util.Abort(_("you can't specify a revision and a date")) | ||||
opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) | ||||
Vadim Gelfer
|
r2982 | if not pats and not opts['all']: | ||
Benoit Boissinot
|
r3020 | raise util.Abort(_('no files or directories specified; ' | ||
'use --all to revert the whole repo')) | ||||
Vadim Gelfer
|
r2982 | |||
Vadim Gelfer
|
r2212 | parent, p2 = repo.dirstate.parents() | ||
Brendan Cully
|
r3132 | if not opts['rev'] and p2 != nullid: | ||
raise util.Abort(_('uncommitted merge - please provide a ' | ||||
'specific revision')) | ||||
node = repo.changectx(opts['rev']).node() | ||||
Vadim Gelfer
|
r2029 | mf = repo.manifest.read(repo.changelog.read(node)[0]) | ||
Vadim Gelfer
|
r2407 | if node == parent: | ||
pmf = mf | ||||
else: | ||||
pmf = None | ||||
Vadim Gelfer
|
r2029 | |||
wlock = repo.wlock() | ||||
Vadim Gelfer
|
r2042 | # need all matching names in dirstate and manifest of target rev, | ||
# so have to walk both. do not print errors if files exist in one | ||||
# but not other. | ||||
Vadim Gelfer
|
r2029 | names = {} | ||
Vadim Gelfer
|
r2042 | target_only = {} | ||
# walk dirstate. | ||||
Vadim Gelfer
|
r2882 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, | ||
badmatch=mf.has_key): | ||||
Vadim Gelfer
|
r2042 | names[abs] = (rel, exact) | ||
if src == 'b': | ||||
target_only[abs] = True | ||||
# walk target manifest. | ||||
Vadim Gelfer
|
r2882 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node, | ||
badmatch=names.has_key): | ||||
Vadim Gelfer
|
r2042 | if abs in names: continue | ||
names[abs] = (rel, exact) | ||||
target_only[abs] = True | ||||
Vadim Gelfer
|
r2029 | |||
Vadim Gelfer
|
r2875 | changes = repo.status(match=names.has_key, wlock=wlock)[:5] | ||
Vadim Gelfer
|
r2029 | modified, added, removed, deleted, unknown = map(dict.fromkeys, changes) | ||
revert = ([], _('reverting %s\n')) | ||||
add = ([], _('adding %s\n')) | ||||
remove = ([], _('removing %s\n')) | ||||
forget = ([], _('forgetting %s\n')) | ||||
undelete = ([], _('undeleting %s\n')) | ||||
update = {} | ||||
disptable = ( | ||||
# dispatch table: | ||||
# file state | ||||
# action if in target manifest | ||||
# action if not in target manifest | ||||
# make backup if in target manifest | ||||
# make backup if not in target manifest | ||||
(modified, revert, remove, True, True), | ||||
Thomas Arendsen Hein
|
r2043 | (added, revert, forget, True, False), | ||
Vadim Gelfer
|
r2029 | (removed, undelete, None, False, False), | ||
(deleted, revert, remove, False, False), | ||||
(unknown, add, None, True, False), | ||||
Vadim Gelfer
|
r2042 | (target_only, add, None, False, False), | ||
Vadim Gelfer
|
r2029 | ) | ||
Vadim Gelfer
|
r2042 | entries = names.items() | ||
entries.sort() | ||||
for abs, (rel, exact) in entries: | ||||
Vadim Gelfer
|
r2407 | mfentry = mf.get(abs) | ||
Vadim Gelfer
|
r2029 | def handle(xlist, dobackup): | ||
xlist[0].append(abs) | ||||
Vadim Gelfer
|
r2407 | update[abs] = 1 | ||
Thomas Arendsen Hein
|
r2036 | if dobackup and not opts['no_backup'] and os.path.exists(rel): | ||
bakname = "%s.orig" % rel | ||||
ui.note(_('saving current version of %s as %s\n') % | ||||
(rel, bakname)) | ||||
Vadim Gelfer
|
r2415 | if not opts.get('dry_run'): | ||
Matt Mackall
|
r3629 | util.copyfile(rel, bakname) | ||
Vadim Gelfer
|
r2029 | if ui.verbose or not exact: | ||
ui.status(xlist[1] % rel) | ||||
for table, hitlist, misslist, backuphit, backupmiss in disptable: | ||||
if abs not in table: continue | ||||
# file has changed in dirstate | ||||
Vadim Gelfer
|
r2407 | if mfentry: | ||
Vadim Gelfer
|
r2029 | handle(hitlist, backuphit) | ||
elif misslist is not None: | ||||
handle(misslist, backupmiss) | ||||
else: | ||||
Marcos Chaves
|
r3679 | if exact: ui.warn(_('file not managed: %s\n') % rel) | ||
Vadim Gelfer
|
r2029 | break | ||
else: | ||||
# file has not changed in dirstate | ||||
if node == parent: | ||||
Marcos Chaves
|
r3679 | if exact: ui.warn(_('no changes needed to %s\n') % rel) | ||
Vadim Gelfer
|
r2029 | continue | ||
Vadim Gelfer
|
r2407 | if pmf is None: | ||
# only need parent manifest in this unlikely case, | ||||
# so do not read by default | ||||
pmf = repo.manifest.read(repo.changelog.read(parent)[0]) | ||||
if abs in pmf: | ||||
if mfentry: | ||||
# if version of file is same in parent and target | ||||
# manifests, do nothing | ||||
if pmf[abs] != mfentry: | ||||
handle(revert, False) | ||||
else: | ||||
Vadim Gelfer
|
r2272 | handle(remove, False) | ||
Vadim Gelfer
|
r2029 | |||
Vadim Gelfer
|
r2415 | if not opts.get('dry_run'): | ||
repo.dirstate.forget(forget[0]) | ||||
Matt Mackall
|
r2812 | r = hg.revert(repo, node, update.has_key, wlock) | ||
Vadim Gelfer
|
r2415 | repo.dirstate.update(add[0], 'a') | ||
repo.dirstate.update(undelete[0], 'n') | ||||
repo.dirstate.update(remove[0], 'r') | ||||
return r | ||||
mpm@selenic.com
|
r588 | |||
Vadim Gelfer
|
r2227 | def rollback(ui, repo): | ||
"""roll back the last transaction in this repository | ||||
Roll back the last transaction in this repository, restoring the | ||||
project to its state prior to the transaction. | ||||
Transactions are used to encapsulate the effects of all commands | ||||
that create new changesets or propagate existing changesets into a | ||||
repository. For example, the following commands are transactional, | ||||
and their effects can be rolled back: | ||||
commit | ||||
import | ||||
pull | ||||
push (with this repository as destination) | ||||
unbundle | ||||
This command should be used with care. There is only one level of | ||||
rollback, and there is no way to undo a rollback. | ||||
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. | ||||
""" | ||||
Thomas Arendsen Hein
|
r2362 | repo.rollback() | ||
Vadim Gelfer
|
r2227 | |||
mpm@selenic.com
|
r468 | def root(ui, repo): | ||
Benoit Boissinot
|
r1437 | """print the root (top) of the current working dir | ||
Print the root directory of the current repository. | ||||
""" | ||||
mpm@selenic.com
|
r468 | ui.write(repo.root + "\n") | ||
mpm@selenic.com
|
r245 | def serve(ui, repo, **opts): | ||
Benoit Boissinot
|
r1437 | """export the repository via HTTP | ||
Start a local HTTP repository browser and pull server. | ||||
By default, the server logs accesses to stdout and errors to | ||||
stderr. Use the "-A" and "-E" options to log to files. | ||||
""" | ||||
Matt Mackall
|
r624 | |||
if opts["stdio"]: | ||||
Thomas Arendsen Hein
|
r2127 | if repo is None: | ||
Thomas Arendsen Hein
|
r3079 | raise hg.RepoError(_("There is no Mercurial repository here" | ||
" (.hg not found)")) | ||||
Vadim Gelfer
|
r2396 | s = sshserver.sshserver(ui, repo) | ||
s.serve_forever() | ||||
Matt Mackall
|
r2363 | |||
Thomas Arendsen Hein
|
r2125 | optlist = ("name templates style address port ipv6" | ||
" accesslog errorlog webdir_conf") | ||||
mpm@selenic.com
|
r987 | for o in optlist.split(): | ||
if opts[o]: | ||||
Alexis S. L. Carvalho
|
r3344 | ui.setconfig("web", o, str(opts[o])) | ||
mpm@selenic.com
|
r987 | |||
Thomas Arendsen Hein
|
r2127 | if repo is None and not ui.config("web", "webdir_conf"): | ||
Thomas Arendsen Hein
|
r3079 | raise hg.RepoError(_("There is no Mercurial repository here" | ||
" (.hg not found)")) | ||||
Thomas Arendsen Hein
|
r2127 | |||
Vadim Gelfer
|
r1741 | if opts['daemon'] and not opts['daemon_pipefds']: | ||
Vadim Gelfer
|
r1740 | rfd, wfd = os.pipe() | ||
args = sys.argv[:] | ||||
Vadim Gelfer
|
r1741 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) | ||
Vadim Gelfer
|
r1740 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), | ||
args[0], args) | ||||
os.close(wfd) | ||||
os.read(rfd, 1) | ||||
os._exit(0) | ||||
Matt Mackall
|
r3628 | httpd = hgweb.server.create_server(ui, repo) | ||
mpm@selenic.com
|
r987 | |||
mpm@selenic.com
|
r603 | if ui.verbose: | ||
Matt Mackall
|
r3628 | if httpd.port != 80: | ||
ui.status(_('listening at http://%s:%d/\n') % | ||||
(httpd.addr, httpd.port)) | ||||
mpm@selenic.com
|
r603 | else: | ||
Matt Mackall
|
r3628 | ui.status(_('listening at http://%s/\n') % httpd.addr) | ||
Vadim Gelfer
|
r1740 | |||
if opts['pid_file']: | ||||
fp = open(opts['pid_file'], 'w') | ||||
Vadim Gelfer
|
r2571 | fp.write(str(os.getpid()) + '\n') | ||
Vadim Gelfer
|
r1740 | fp.close() | ||
Vadim Gelfer
|
r1741 | if opts['daemon_pipefds']: | ||
rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] | ||||
os.close(rfd) | ||||
Vadim Gelfer
|
r1740 | os.write(wfd, 'y') | ||
os.close(wfd) | ||||
sys.stdout.flush() | ||||
sys.stderr.flush() | ||||
fd = os.open(util.nulldev, os.O_RDWR) | ||||
if fd != 0: os.dup2(fd, 0) | ||||
if fd != 1: os.dup2(fd, 1) | ||||
if fd != 2: os.dup2(fd, 2) | ||||
if fd not in (0, 1, 2): os.close(fd) | ||||
mpm@selenic.com
|
r603 | httpd.serve_forever() | ||
mpm@selenic.com
|
r500 | |||
Bryan O'Sullivan
|
r731 | def status(ui, repo, *pats, **opts): | ||
Benoit Boissinot
|
r1437 | """show changed files in the working directory | ||
mpm@selenic.com
|
r213 | |||
Vadim Gelfer
|
r2661 | Show status of files in the repository. If names are given, only | ||
files that match are shown. Files that are clean or ignored, are | ||||
not listed unless -c (clean), -i (ignored) or -A is given. | ||||
Benoit Boissinot
|
r1437 | |||
Matt Mackall
|
r3822 | NOTE: status may appear to disagree with diff if permissions have | ||
changed or a merge has occurred. The standard diff format does not | ||||
report permission changes and diff only reports changes relative | ||||
to one merge parent. | ||||
Brendan Cully
|
r3467 | If one revision is given, it is used as the base revision. | ||
If two revisions are given, the difference between them is shown. | ||||
Benoit Boissinot
|
r1437 | The codes used to show the status of files are: | ||
mpm@selenic.com
|
r746 | M = modified | ||
mpm@selenic.com
|
r245 | A = added | ||
R = removed | ||||
Vadim Gelfer
|
r2661 | C = clean | ||
Thomas Arendsen Hein
|
r1619 | ! = deleted, but still tracked | ||
Thomas Arendsen Hein
|
r842 | ? = not tracked | ||
Thomas Arendsen Hein
|
r2022 | I = ignored (not shown by default) | ||
Brendan Cully
|
r2639 | = the previous added file was copied from here | ||
Benoit Boissinot
|
r1437 | """ | ||
mpm@selenic.com
|
r312 | |||
Vadim Gelfer
|
r2661 | all = opts['all'] | ||
Thomas Arendsen Hein
|
r3707 | node1, node2 = cmdutil.revpair(repo, opts.get('rev')) | ||
Thomas Arendsen Hein
|
r3223 | |||
Vadim Gelfer
|
r2882 | files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) | ||
Benoit Boissinot
|
r1625 | cwd = (pats and repo.getcwd()) or '' | ||
Vadim Gelfer
|
r2661 | modified, added, removed, deleted, unknown, ignored, clean = [ | ||
Thomas Arendsen Hein
|
r1618 | [util.pathto(cwd, x) for x in n] | ||
Brendan Cully
|
r3467 | for n in repo.status(node1=node1, node2=node2, files=files, | ||
match=matchfn, | ||||
Vadim Gelfer
|
r2661 | list_ignored=all or opts['ignored'], | ||
list_clean=all or opts['clean'])] | ||||
changetypes = (('modified', 'M', modified), | ||||
Thomas Arendsen Hein
|
r1966 | ('added', 'A', added), | ||
('removed', 'R', removed), | ||||
('deleted', '!', deleted), | ||||
Thomas Arendsen Hein
|
r2022 | ('unknown', '?', unknown), | ||
Vadim Gelfer
|
r2661 | ('ignored', 'I', ignored)) | ||
explicit_changetypes = changetypes + (('clean', 'C', clean),) | ||||
Thomas Arendsen Hein
|
r842 | |||
TK Soh
|
r1085 | end = opts['print0'] and '\0' or '\n' | ||
Thomas Arendsen Hein
|
r1106 | |||
Vadim Gelfer
|
r2661 | for opt, char, changes in ([ct for ct in explicit_changetypes | ||
if all or opts[ct[0]]] | ||||
Thomas Arendsen Hein
|
r842 | or changetypes): | ||
Thomas Arendsen Hein
|
r1105 | if opts['no_status']: | ||
TK Soh
|
r1085 | format = "%%s%s" % end | ||
else: | ||||
Thomas Arendsen Hein
|
r1966 | format = "%s %%s%s" % (char, end) | ||
Thomas Arendsen Hein
|
r1106 | |||
Thomas Arendsen Hein
|
r842 | for f in changes: | ||
TK Soh
|
r1085 | ui.write(format % f) | ||
Matt Mackall
|
r3250 | if ((all or opts.get('copies')) and not opts.get('no_status')): | ||
Benoit Boissinot
|
r3159 | copied = repo.dirstate.copied(f) | ||
if copied: | ||||
ui.write(' %s%s' % (copied, end)) | ||||
mpm@selenic.com
|
r213 | |||
Benoit Boissinot
|
r1596 | def tag(ui, repo, name, rev_=None, **opts): | ||
Benoit Boissinot
|
r1437 | """add a tag for the current tip or a given revision | ||
Name a particular revision using <name>. | ||||
Tags are used to name particular revisions of the repository and are | ||||
very useful to compare different revision, to go back to significant | ||||
earlier versions or to mark branch points as releases, etc. | ||||
Benoit Boissinot
|
r2647 | If no revision is given, the parent of the working directory is used. | ||
Benoit Boissinot
|
r1437 | |||
To facilitate version control, distribution, and merging of tags, | ||||
they are stored as a file named ".hgtags" which is managed | ||||
similarly to other project files and can be hand-edited if | ||||
Benoit Boissinot
|
r1654 | necessary. The file '.hg/localtags' is used for local tags (not | ||
shared among repositories). | ||||
Benoit Boissinot
|
r1437 | """ | ||
Brendan Cully
|
r3801 | if name in ['tip', '.', 'null']: | ||
Brendan Cully
|
r2789 | raise util.Abort(_("the name '%s' is reserved") % name) | ||
Benoit Boissinot
|
r1654 | if rev_ is not None: | ||
ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " | ||||
Thomas Arendsen Hein
|
r1661 | "please use 'hg tag [-r REV] NAME' instead\n")) | ||
Benoit Boissinot
|
r1654 | if opts['rev']: | ||
raise util.Abort(_("use only one form to specify the revision")) | ||||
Benoit Boissinot
|
r1596 | if opts['rev']: | ||
rev_ = opts['rev'] | ||||
Brendan Cully
|
r3132 | if not rev_ and repo.dirstate.parents()[1] != nullid: | ||
raise util.Abort(_('uncommitted merge - please provide a ' | ||||
'specific revision')) | ||||
r = repo.changectx(rev_).node() | ||||
Matt Mackall
|
r2967 | |||
message = opts['message'] | ||||
if not message: | ||||
message = _('Added tag %s for changeset %s') % (name, short(r)) | ||||
repo.tag(name, r, message, opts['local'], opts['user'], opts['date']) | ||||
mpm@selenic.com
|
r401 | |||
mpm@selenic.com
|
r248 | def tags(ui, repo): | ||
Benoit Boissinot
|
r1437 | """list repository tags | ||
List the repository tags. | ||||
This lists both regular and local tags. | ||||
""" | ||||
Thomas Arendsen Hein
|
r477 | |||
mpm@selenic.com
|
r343 | l = repo.tagslist() | ||
l.reverse() | ||||
Matt Mackall
|
r2966 | hexfunc = ui.debugflag and hex or short | ||
Thomas Arendsen Hein
|
r477 | for t, n in l: | ||
mpm@selenic.com
|
r248 | try: | ||
Matt Mackall
|
r2966 | r = "%5d:%s" % (repo.changelog.rev(n), hexfunc(n)) | ||
mpm@selenic.com
|
r248 | except KeyError: | ||
Thomas Arendsen Hein
|
r477 | r = " ?:?" | ||
Thomas Arendsen Hein
|
r2035 | if ui.quiet: | ||
ui.write("%s\n" % t) | ||||
else: | ||||
Matt Mackall
|
r3772 | t = util.localsub(t, 30) | ||
t += " " * (30 - util.locallen(t)) | ||||
ui.write("%s %s\n" % (t, r)) | ||||
mpm@selenic.com
|
r248 | |||
Vadim Gelfer
|
r1731 | def tip(ui, repo, **opts): | ||
Benoit Boissinot
|
r1437 | """show the tip revision | ||
Show the tip revision. | ||||
""" | ||||
Thomas Arendsen Hein
|
r3671 | cmdutil.show_changeset(ui, repo, opts).show(nullrev+repo.changelog.count()) | ||
mpm@selenic.com
|
r245 | |||
Muli Ben-Yehuda
|
r1600 | def unbundle(ui, repo, fname, **opts): | ||
Benoit Boissinot
|
r1437 | """apply a changegroup file | ||
Apply a compressed changegroup file generated by the bundle | ||||
command. | ||||
""" | ||||
Benoit Boissinot
|
r3859 | gen = changegroup.readbundle(urllib.urlopen(fname), fname) | ||
Matt Mackall
|
r3660 | modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname) | ||
Vadim Gelfer
|
r2019 | return postincoming(ui, repo, modheads, opts['update']) | ||
mpm@selenic.com
|
r1218 | |||
Matt Mackall
|
r3814 | def update(ui, repo, node=None, clean=False, branch=None, date=None): | ||
Benoit Boissinot
|
r1437 | """update or merge working directory | ||
Update the working directory to the specified revision. | ||||
mpm@selenic.com
|
r254 | |||
If there are no outstanding changes in the working directory and | ||||
there is a linear relationship between the current version and the | ||||
requested version, the result is the requested version. | ||||
Vadim Gelfer
|
r2283 | To merge the working directory with another revision, use the | ||
merge command. | ||||
Benoit Boissinot
|
r1437 | |||
By default, update will refuse to run if doing so would require | ||||
merging or discarding local changes. | ||||
""" | ||||
Matt Mackall
|
r3814 | if date: | ||
if node: | ||||
raise util.Abort(_("you can't specify a revision and a date")) | ||||
node = cmdutil.finddate(ui, repo, date) | ||||
Matt Mackall
|
r2808 | node = _lookup(repo, node, branch) | ||
Matt Mackall
|
r3521 | if clean: | ||
Matt Mackall
|
r2808 | return hg.clean(repo, node) | ||
else: | ||||
return hg.update(repo, node) | ||||
Matt Mackall
|
r2806 | |||
def _lookup(repo, node, branch=None): | ||||
mason@suse.com
|
r898 | if branch: | ||
Matt Mackall
|
r3503 | repo.ui.warn(_("the --branch option is deprecated, " | ||
"please use 'hg branch' instead\n")) | ||||
mason@suse.com
|
r898 | br = repo.branchlookup(branch=branch) | ||
found = [] | ||||
for x in br: | ||||
if branch in br[x]: | ||||
found.append(x) | ||||
if len(found) > 1: | ||||
Matt Mackall
|
r2806 | repo.ui.warn(_("Found multiple heads for %s\n") % branch) | ||
mason@suse.com
|
r898 | for x in found: | ||
Matt Mackall
|
r3649 | cmdutil.show_changeset(ui, repo, {}).show(changenode=x) | ||
Matt Mackall
|
r2806 | raise util.Abort("") | ||
mason@suse.com
|
r898 | if len(found) == 1: | ||
node = found[0] | ||||
Matt Mackall
|
r2806 | repo.ui.warn(_("Using head %s for branch %s\n") | ||
% (short(node), branch)) | ||||
mason@suse.com
|
r898 | else: | ||
Thomas Arendsen Hein
|
r3072 | raise util.Abort(_("branch %s not found") % branch) | ||
mason@suse.com
|
r898 | else: | ||
node = node and repo.lookup(node) or repo.changelog.tip() | ||||
Matt Mackall
|
r2806 | return node | ||
mpm@selenic.com
|
r254 | |||
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
|
r2778 | return hg.verify(repo) | ||
mpm@selenic.com
|
r247 | |||
Matt Mackall
|
r3651 | def version_(ui): | ||
"""output version and copyright information""" | ||||
ui.write(_("Mercurial Distributed SCM (version %s)\n") | ||||
% version.get_version()) | ||||
ui.status(_( | ||||
"\nCopyright (C) 2005, 2006 Matt Mackall <mpm@selenic.com>\n" | ||||
"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" | ||||
)) | ||||
mpm@selenic.com
|
r255 | # Command options and aliases are listed here, alphabetically | ||
Benoit Boissinot
|
r3187 | globalopts = [ | ||
('R', 'repository', '', | ||||
_('repository root directory or symbolic path name')), | ||||
('', 'cwd', '', _('change working directory')), | ||||
('y', 'noninteractive', None, | ||||
_('do not prompt, assume \'yes\' for any required answers')), | ||||
('q', 'quiet', None, _('suppress output')), | ||||
('v', 'verbose', None, _('enable additional output')), | ||||
('', 'config', [], _('set/override config option')), | ||||
('', 'debug', None, _('enable debugging output')), | ||||
('', 'debugger', None, _('start debugger')), | ||||
Matt Mackall
|
r3774 | ('', 'encoding', util._encoding, _('set the charset encoding')), | ||
('', 'encodingmode', util._encodingmode, _('set the charset encoding mode')), | ||||
Benoit Boissinot
|
r3187 | ('', 'lsprof', None, _('print improved command execution profile')), | ||
('', 'traceback', None, _('print 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')), | ||||
] | ||||
Benoit Boissinot
|
r3189 | dryrunopts = [('n', 'dry-run', None, | ||
_('do not perform actions, just print output'))] | ||||
Benoit Boissinot
|
r3190 | remoteopts = [ | ||
('e', 'ssh', '', _('specify ssh command to use')), | ||||
('', 'remotecmd', '', _('specify hg command to run on the remote side')), | ||||
] | ||||
Benoit Boissinot
|
r3188 | walkopts = [ | ||
('I', 'include', [], _('include names matching the given patterns')), | ||||
('X', 'exclude', [], _('exclude names matching the given patterns')), | ||||
] | ||||
Mathieu Clabaut
|
r3857 | commitopts = [ | ||
('m', 'message', '', _('use <text> as commit message')), | ||||
('l', 'logfile', '', _('read commit message from <file>')), | ||||
] | ||||
mpm@selenic.com
|
r209 | table = { | ||
Thomas Arendsen Hein
|
r3824 | "^add": (add, walkopts + dryrunopts, _('hg add [OPTION]... [FILE]...')), | ||
Vadim Gelfer
|
r2955 | "addremove": | ||
Thomas Arendsen Hein
|
r841 | (addremove, | ||
Benoit Boissinot
|
r3188 | [('s', 'similarity', '', | ||
Benoit Boissinot
|
r3189 | _('guess renamed files by similarity (0<=s<=100)')), | ||
] + walkopts + dryrunopts, | ||||
Thomas Arendsen Hein
|
r1615 | _('hg addremove [OPTION]... [FILE]...')), | ||
Thomas Arendsen Hein
|
r697 | "^annotate": | ||
(annotate, | ||||
Benoit Boissinot
|
r1437 | [('r', 'rev', '', _('annotate the specified revision')), | ||
Brendan Cully
|
r3172 | ('f', 'follow', None, _('follow file copies and renames')), | ||
Benoit Boissinot
|
r1402 | ('a', 'text', None, _('treat all files as text')), | ||
Benoit Boissinot
|
r1437 | ('u', 'user', None, _('list the author')), | ||
lupus@debian.org
|
r1522 | ('d', 'date', None, _('list the date')), | ||
Benoit Boissinot
|
r1437 | ('n', 'number', None, _('list the revision number (default)')), | ||
('c', 'changeset', None, _('list the changeset')), | ||||
Benoit Boissinot
|
r3188 | ] + walkopts, | ||
Thomas Arendsen Hein
|
r1816 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), | ||
Thomas Arendsen Hein
|
r2160 | "archive": | ||
Vadim Gelfer
|
r2112 | (archive, | ||
[('', 'no-decode', None, _('do not pass files through decoders')), | ||||
('p', 'prefix', '', _('directory prefix for files in archive')), | ||||
('r', 'rev', '', _('revision to distribute')), | ||||
('t', 'type', '', _('type of distribution to create')), | ||||
Benoit Boissinot
|
r3188 | ] + walkopts, | ||
Vadim Gelfer
|
r2112 | _('hg archive [OPTION]... DEST')), | ||
Thomas Arendsen Hein
|
r2159 | "backout": | ||
Vadim Gelfer
|
r2158 | (backout, | ||
Thomas Arendsen Hein
|
r2159 | [('', 'merge', None, | ||
_('merge with old dirstate parent after backout')), | ||||
Vadim Gelfer
|
r2158 | ('d', 'date', '', _('record datecode as commit date')), | ||
Vadim Gelfer
|
r2614 | ('', 'parent', '', _('parent to choose when backing out merge')), | ||
Vadim Gelfer
|
r2158 | ('u', 'user', '', _('record user as committer')), | ||
Mathieu Clabaut
|
r3857 | ] + walkopts + commitopts, | ||
Thomas Arendsen Hein
|
r2159 | _('hg backout [OPTION]... REV')), | ||
Matt Mackall
|
r3502 | "branch": (branch, [], _('hg branch [NAME]')), | ||
"branches": (branches, [], _('hg branches')), | ||||
mpm@selenic.com
|
r1218 | "bundle": | ||
(bundle, | ||||
Vadim Gelfer
|
r1959 | [('f', 'force', None, | ||
Benoit Boissinot
|
r3191 | _('run even when remote repository is unrelated')), | ||
Benoit Boissinot
|
r3284 | ('r', 'rev', [], | ||
_('a changeset you would like to bundle')), | ||||
('', 'base', [], | ||||
_('a base changeset to specify instead of a destination')), | ||||
Benoit Boissinot
|
r3191 | ] + remoteopts, | ||
Benoit Boissinot
|
r3284 | _('hg bundle [--base REV]... [--rev REV]... FILE [DEST]')), | ||
Thomas Arendsen Hein
|
r697 | "cat": | ||
(cat, | ||||
Thomas Arendsen Hein
|
r1816 | [('o', 'output', '', _('print output to file with formatted name')), | ||
('r', 'rev', '', _('print the given revision')), | ||||
Benoit Boissinot
|
r3188 | ] + walkopts, | ||
Benoit Boissinot
|
r1402 | _('hg cat [OPTION]... FILE...')), | ||
Thomas Arendsen Hein
|
r697 | "^clone": | ||
(clone, | ||||
Benoit Boissinot
|
r1437 | [('U', 'noupdate', None, _('do not update the new working directory')), | ||
Muli Ben-Yehuda
|
r1602 | ('r', 'rev', [], | ||
Vadim Gelfer
|
r2764 | _('a changeset you would like to have after cloning')), | ||
Thomas Arendsen Hein
|
r1816 | ('', 'pull', None, _('use pull protocol to copy metadata')), | ||
Vadim Gelfer
|
r2620 | ('', 'uncompressed', None, | ||
_('use uncompressed transfer (fast over LAN)')), | ||||
Benoit Boissinot
|
r3190 | ] + remoteopts, | ||
Benoit Boissinot
|
r1402 | _('hg clone [OPTION]... SOURCE [DEST]')), | ||
Thomas Arendsen Hein
|
r697 | "^commit|ci": | ||
(commit, | ||||
Thomas Arendsen Hein
|
r2184 | [('A', 'addremove', None, | ||
_('mark new/missing files as added/removed before committing')), | ||||
Thomas Arendsen Hein
|
r1615 | ('d', 'date', '', _('record datecode as commit date')), | ||
Thomas Arendsen Hein
|
r1816 | ('u', 'user', '', _('record user as commiter')), | ||
Mathieu Clabaut
|
r3857 | ] + walkopts + commitopts, | ||
Benoit Boissinot
|
r1402 | _('hg commit [OPTION]... [FILE]...')), | ||
Thomas Arendsen Hein
|
r1615 | "copy|cp": | ||
(copy, | ||||
Thomas Arendsen Hein
|
r1816 | [('A', 'after', None, _('record a copy that has already occurred')), | ||
Thomas Arendsen Hein
|
r1615 | ('f', 'force', None, | ||
Thomas Arendsen Hein
|
r1816 | _('forcibly copy over an existing managed file')), | ||
Benoit Boissinot
|
r3189 | ] + walkopts + dryrunopts, | ||
Thomas Arendsen Hein
|
r1615 | _('hg copy [OPTION]... [SOURCE]... DEST')), | ||
Benoit Boissinot
|
r1402 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), | ||
Alexis S. L. Carvalho
|
r2034 | "debugcomplete": | ||
(debugcomplete, | ||||
[('o', 'options', None, _('show the command options'))], | ||||
_('debugcomplete [-o] CMD')), | ||||
Matt Mackall
|
r3844 | "debuginstall": (debuginstall, [], _('debuginstall')), | ||
Benoit Boissinot
|
r1755 | "debugrebuildstate": | ||
(debugrebuildstate, | ||||
Thomas Arendsen Hein
|
r1816 | [('r', 'rev', '', _('revision to rebuild to'))], | ||
Benoit Boissinot
|
r1755 | _('debugrebuildstate [-r REV] [REV]')), | ||
Benoit Boissinot
|
r1402 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), | ||
"debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), | ||||
"debugstate": (debugstate, [], _('debugstate')), | ||||
Thomas Arendsen Hein
|
r3824 | "debugdate": | ||
(debugdate, | ||||
[('e', 'extended', None, _('try extended date formats'))], | ||||
_('debugdate [-e] DATE [RANGE]')), | ||||
Benoit Boissinot
|
r1402 | "debugdata": (debugdata, [], _('debugdata FILE REV')), | ||
"debugindex": (debugindex, [], _('debugindex FILE')), | ||||
"debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), | ||||
"debugrename": (debugrename, [], _('debugrename FILE [REV]')), | ||||
Thomas Arendsen Hein
|
r3824 | "debugwalk": (debugwalk, walkopts, _('debugwalk [OPTION]... [FILE]...')), | ||
Thomas Arendsen Hein
|
r697 | "^diff": | ||
(diff, | ||||
Benoit Boissinot
|
r1402 | [('r', 'rev', [], _('revision')), | ||
('a', 'text', None, _('treat all files as text')), | ||||
Vadim Gelfer
|
r1728 | ('p', 'show-function', None, | ||
_('show which function each change is in')), | ||||
Brendan Cully
|
r2907 | ('g', 'git', None, _('use git extended diff format')), | ||
Stephen Darnell
|
r3200 | ('', 'nodates', None, _("don't include dates in diff headers")), | ||
Vadim Gelfer
|
r1728 | ('w', 'ignore-all-space', None, | ||
_('ignore white space when comparing lines')), | ||||
Haakon Riiser
|
r2580 | ('b', 'ignore-space-change', None, | ||
_('ignore changes in the amount of white space')), | ||||
('B', 'ignore-blank-lines', None, | ||||
_('ignore changes whose lines are all blank')), | ||||
Benoit Boissinot
|
r3188 | ] + walkopts, | ||
Benoit Boissinot
|
r1402 | _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), | ||
Thomas Arendsen Hein
|
r697 | "^export": | ||
(export, | ||||
Thomas Arendsen Hein
|
r1615 | [('o', 'output', '', _('print output to file with formatted name')), | ||
Benoit Boissinot
|
r1571 | ('a', 'text', None, _('treat all files as text')), | ||
Brendan Cully
|
r3029 | ('g', 'git', None, _('use git extended diff format')), | ||
Stephen Darnell
|
r3200 | ('', 'nodates', None, _("don't include dates in diff headers")), | ||
Benoit Boissinot
|
r1571 | ('', 'switch-parent', None, _('diff against the second parent'))], | ||
Benoit Boissinot
|
r1812 | _('hg export [-a] [-o OUTFILESPEC] REV...')), | ||
Thomas Arendsen Hein
|
r1065 | "grep": | ||
(grep, | ||||
Benoit Boissinot
|
r1402 | [('0', 'print0', None, _('end fields with NUL')), | ||
Benoit Boissinot
|
r1437 | ('', 'all', None, _('print all revisions that match')), | ||
Brendan Cully
|
r2870 | ('f', 'follow', None, | ||
_('follow changeset history, or file history across copies and renames')), | ||||
Benoit Boissinot
|
r1402 | ('i', 'ignore-case', None, _('ignore case when matching')), | ||
Muli Ben-Yehuda
|
r1602 | ('l', 'files-with-matches', None, | ||
_('print only filenames and revs that match')), | ||||
Benoit Boissinot
|
r1437 | ('n', 'line-number', None, _('print matching line numbers')), | ||
('r', 'rev', [], _('search in given revision range')), | ||||
Thomas Arendsen Hein
|
r1816 | ('u', 'user', None, _('print user who committed change')), | ||
Benoit Boissinot
|
r3188 | ] + walkopts, | ||
Thomas Arendsen Hein
|
r1615 | _('hg grep [OPTION]... PATTERN [FILE]...')), | ||
Thomas Arendsen Hein
|
r905 | "heads": | ||
(heads, | ||||
Matt Mackall
|
r3503 | [('b', 'branches', None, _('show branches (DEPRECATED)')), | ||
Vadim Gelfer
|
r1913 | ('', 'style', '', _('display using template map file')), | ||
Vadim Gelfer
|
r1907 | ('r', 'rev', '', _('show only heads which are descendants of rev')), | ||
Vadim Gelfer
|
r1913 | ('', 'template', '', _('display with template'))], | ||
Thomas Arendsen Hein
|
r3510 | _('hg heads [-r REV]')), | ||
Benoit Boissinot
|
r1402 | "help": (help_, [], _('hg help [COMMAND]')), | ||
"identify|id": (identify, [], _('hg identify')), | ||||
Thomas Arendsen Hein
|
r697 | "import|patch": | ||
(import_, | ||||
Muli Ben-Yehuda
|
r1602 | [('p', 'strip', 1, | ||
Thomas Arendsen Hein
|
r2125 | _('directory strip option for patch. This has the same\n' | ||
'meaning as the corresponding patch option')), | ||||
Matt Mackall
|
r3503 | ('b', 'base', '', _('base path (DEPRECATED)')), | ||
Muli Ben-Yehuda
|
r1602 | ('f', 'force', None, | ||
Mathieu Clabaut
|
r3857 | _('skip check for outstanding uncommitted changes'))] + commitopts, | ||
Matt Mackall
|
r3517 | _('hg import [-p NUM] [-m MESSAGE] [-f] PATCH...')), | ||
Bryan O'Sullivan
|
r1253 | "incoming|in": (incoming, | ||
Thomas Arendsen Hein
|
r1615 | [('M', 'no-merges', None, _('do not show merges')), | ||
Vadim Gelfer
|
r1959 | ('f', 'force', None, | ||
_('run even when remote repository is unrelated')), | ||||
Vadim Gelfer
|
r1913 | ('', 'style', '', _('display using template map file')), | ||
Vadim Gelfer
|
r1907 | ('n', 'newest-first', None, _('show newest record first')), | ||
Benoit Boissinot
|
r1944 | ('', 'bundle', '', _('file to store the bundles into')), | ||
Michal Kvasnica
|
r1439 | ('p', 'patch', None, _('show patch')), | ||
Giorgos Keramidas
|
r2878 | ('r', 'rev', [], _('a specific revision up to which you would like to pull')), | ||
Benoit Boissinot
|
r1965 | ('', 'template', '', _('display with template')), | ||
Benoit Boissinot
|
r3190 | ] + remoteopts, | ||
Benoit Boissinot
|
r2521 | _('hg incoming [-p] [-n] [-M] [-r REV]...' | ||
Thomas Arendsen Hein
|
r2544 | ' [--bundle FILENAME] [SOURCE]')), | ||
Thomas Arendsen Hein
|
r2598 | "^init": | ||
Benoit Boissinot
|
r3190 | (init, remoteopts, _('hg init [-e FILE] [--remotecmd FILE] [DEST]')), | ||
Thomas Arendsen Hein
|
r697 | "locate": | ||
(locate, | ||||
Benoit Boissinot
|
r1437 | [('r', 'rev', '', _('search the repository as it stood at rev')), | ||
Muli Ben-Yehuda
|
r1602 | ('0', 'print0', None, | ||
_('end filenames with NUL, for use with xargs')), | ||||
('f', 'fullpath', None, | ||||
_('print complete paths from the filesystem root')), | ||||
Benoit Boissinot
|
r3188 | ] + walkopts, | ||
Benoit Boissinot
|
r1402 | _('hg locate [OPTION]... [PATTERN]...')), | ||
Thomas Arendsen Hein
|
r697 | "^log|history": | ||
(log, | ||||
Matt Mackall
|
r3503 | [('b', 'branches', None, _('show branches (DEPRECATED)')), | ||
Vadim Gelfer
|
r2741 | ('f', 'follow', None, | ||
Brendan Cully
|
r2782 | _('follow changeset history, or file history across copies and renames')), | ||
Brendan Cully
|
r2784 | ('', 'follow-first', None, | ||
_('only follow the first parent of merge changesets')), | ||||
Matt Mackall
|
r3813 | ('d', 'date', '', _('show revs matching date spec')), | ||
Brendan Cully
|
r3197 | ('C', 'copies', None, _('show copied files')), | ||
Benoit Boissinot
|
r1402 | ('k', 'keyword', [], _('search for a keyword')), | ||
Vadim Gelfer
|
r1756 | ('l', 'limit', '', _('limit number of changes displayed')), | ||
Benoit Boissinot
|
r1437 | ('r', 'rev', [], _('show the specified revision or range')), | ||
Matt Mackall
|
r3657 | ('', 'removed', None, _('include revs where files were removed')), | ||
Thomas Arendsen Hein
|
r1615 | ('M', 'no-merges', None, _('do not show merges')), | ||
Vadim Gelfer
|
r1913 | ('', 'style', '', _('display using template map file')), | ||
Thomas Arendsen Hein
|
r1615 | ('m', 'only-merges', None, _('show only merges')), | ||
Thomas Arendsen Hein
|
r1816 | ('p', 'patch', None, _('show patch')), | ||
Brendan Cully
|
r2901 | ('P', 'prune', [], _('do not display revision or any of its ancestors')), | ||
Vadim Gelfer
|
r1920 | ('', 'template', '', _('display with template')), | ||
Benoit Boissinot
|
r3188 | ] + walkopts, | ||
Thomas Arendsen Hein
|
r1816 | _('hg log [OPTION]... [FILE]')), | ||
Benoit Boissinot
|
r1402 | "manifest": (manifest, [], _('hg manifest [REV]')), | ||
Vadim Gelfer
|
r2019 | "merge": | ||
Thomas Arendsen Hein
|
r2044 | (merge, | ||
Matt Mackall
|
r3503 | [('b', 'branch', '', _('merge with head of a specific branch (DEPRECATED)')), | ||
Thomas Arendsen Hein
|
r2044 | ('f', 'force', None, _('force a merge with outstanding changes'))], | ||
Matt Mackall
|
r3504 | _('hg merge [-f] [REV]')), | ||
Bryan O'Sullivan
|
r1253 | "outgoing|out": (outgoing, | ||
Thomas Arendsen Hein
|
r1615 | [('M', 'no-merges', None, _('do not show merges')), | ||
Vadim Gelfer
|
r1959 | ('f', 'force', None, | ||
_('run even when remote repository is unrelated')), | ||||
Michal Kvasnica
|
r1439 | ('p', 'patch', None, _('show patch')), | ||
Vadim Gelfer
|
r1913 | ('', 'style', '', _('display using template map file')), | ||
Benoit Boissinot
|
r2521 | ('r', 'rev', [], _('a specific revision you would like to push')), | ||
Vadim Gelfer
|
r1907 | ('n', 'newest-first', None, _('show newest record first')), | ||
Benoit Boissinot
|
r1965 | ('', 'template', '', _('display with template')), | ||
Benoit Boissinot
|
r3190 | ] + remoteopts, | ||
Benoit Boissinot
|
r2521 | _('hg outgoing [-M] [-p] [-n] [-r REV]... [DEST]')), | ||
Benoit Boissinot
|
r1724 | "^parents": | ||
(parents, | ||||
Matt Mackall
|
r3503 | [('b', 'branches', None, _('show branches (DEPRECATED)')), | ||
Benoit Boissinot
|
r2644 | ('r', 'rev', '', _('show parents from the specified rev')), | ||
Vadim Gelfer
|
r1913 | ('', 'style', '', _('display using template map file')), | ||
('', 'template', '', _('display with template'))], | ||||
Matt Mackall
|
r3504 | _('hg parents [-r REV] [FILE]')), | ||
Benoit Boissinot
|
r1402 | "paths": (paths, [], _('hg paths [NAME]')), | ||
Thomas Arendsen Hein
|
r697 | "^pull": | ||
(pull, | ||||
Muli Ben-Yehuda
|
r1602 | [('u', 'update', None, | ||
Thomas Arendsen Hein
|
r3198 | _('update to new tip if changesets were pulled')), | ||
Vadim Gelfer
|
r1959 | ('f', 'force', None, | ||
_('run even when remote repository is unrelated')), | ||||
Giorgos Keramidas
|
r2878 | ('r', 'rev', [], _('a specific revision up to which you would like to pull')), | ||
Benoit Boissinot
|
r3190 | ] + remoteopts, | ||
Thomas Arendsen Hein
|
r2598 | _('hg pull [-u] [-r REV]... [-e FILE] [--remotecmd FILE] [SOURCE]')), | ||
mpm@selenic.com
|
r818 | "^push": | ||
(push, | ||||
Benoit Boissinot
|
r1402 | [('f', 'force', None, _('force push')), | ||
Benoit Boissinot
|
r1781 | ('r', 'rev', [], _('a specific revision you would like to push')), | ||
Benoit Boissinot
|
r3190 | ] + remoteopts, | ||
Thomas Arendsen Hein
|
r2598 | _('hg push [-f] [-r REV]... [-e FILE] [--remotecmd FILE] [DEST]')), | ||
Thomas Arendsen Hein
|
r1818 | "debugrawcommit|rawcommit": | ||
Thomas Arendsen Hein
|
r697 | (rawcommit, | ||
Benoit Boissinot
|
r1402 | [('p', 'parent', [], _('parent')), | ||
Thomas Arendsen Hein
|
r1615 | ('d', 'date', '', _('date code')), | ||
('u', 'user', '', _('user')), | ||||
Mathieu Clabaut
|
r3857 | ('F', 'files', '', _('file list')) | ||
] + commitopts, | ||||
Thomas Arendsen Hein
|
r1818 | _('hg debugrawcommit [OPTION]... [FILE]...')), | ||
Thomas Arendsen Hein
|
r1615 | "recover": (recover, [], _('hg recover')), | ||
"^remove|rm": | ||||
(remove, | ||||
Thomas Arendsen Hein
|
r2245 | [('A', 'after', None, _('record remove that has already occurred')), | ||
Vadim Gelfer
|
r2179 | ('f', 'force', None, _('remove file even if modified')), | ||
Benoit Boissinot
|
r3188 | ] + walkopts, | ||
Thomas Arendsen Hein
|
r1615 | _('hg remove [OPTION]... FILE...')), | ||
"rename|mv": | ||||
(rename, | ||||
Thomas Arendsen Hein
|
r1816 | [('A', 'after', None, _('record a rename that has already occurred')), | ||
Thomas Arendsen Hein
|
r1615 | ('f', 'force', None, | ||
Thomas Arendsen Hein
|
r1816 | _('forcibly copy over an existing managed file')), | ||
Benoit Boissinot
|
r3189 | ] + walkopts + dryrunopts, | ||
Thomas Arendsen Hein
|
r1869 | _('hg rename [OPTION]... SOURCE... DEST')), | ||
Thomas Arendsen Hein
|
r697 | "^revert": | ||
(revert, | ||||
Vadim Gelfer
|
r2983 | [('a', 'all', None, _('revert all changes when no arguments given')), | ||
Matt Mackall
|
r3814 | ('d', 'date', '', _('tipmost revision matching date')), | ||
Vadim Gelfer
|
r2982 | ('r', 'rev', '', _('revision to revert to')), | ||
Vadim Gelfer
|
r2029 | ('', 'no-backup', None, _('do not save backup copies of files')), | ||
Benoit Boissinot
|
r3189 | ] + walkopts + dryrunopts, | ||
Thomas Arendsen Hein
|
r1816 | _('hg revert [-r REV] [NAME]...')), | ||
Vadim Gelfer
|
r2227 | "rollback": (rollback, [], _('hg rollback')), | ||
Thomas Arendsen Hein
|
r1615 | "root": (root, [], _('hg root')), | ||
Alexis S. L. Carvalho
|
r3553 | "showconfig|debugconfig": | ||
(showconfig, | ||||
[('u', 'untrusted', None, _('show untrusted configuration options'))], | ||||
_('showconfig [-u] [NAME]...')), | ||||
Thomas Arendsen Hein
|
r697 | "^serve": | ||
(serve, | ||||
Benoit Boissinot
|
r1437 | [('A', 'accesslog', '', _('name of access log file to write to')), | ||
Vadim Gelfer
|
r1740 | ('d', 'daemon', None, _('run server in background')), | ||
Thomas Arendsen Hein
|
r1742 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), | ||
Benoit Boissinot
|
r1437 | ('E', 'errorlog', '', _('name of error log file to write to')), | ||
('p', 'port', 0, _('port to use (default: 8000)')), | ||||
('a', 'address', '', _('address to use')), | ||||
Thomas Arendsen Hein
|
r1615 | ('n', 'name', '', | ||
Muli Ben-Yehuda
|
r1602 | _('name to show in web pages (default: working dir)')), | ||
Alexander Schremmer <alex AT alexanderweb DOT de>
|
r2124 | ('', 'webdir-conf', '', _('name of the webdir config file' | ||
' (serve more than one repo)')), | ||||
Vadim Gelfer
|
r1740 | ('', 'pid-file', '', _('name of file to write process ID to')), | ||
Benoit Boissinot
|
r1402 | ('', 'stdio', None, _('for remote clients')), | ||
Thomas Arendsen Hein
|
r1615 | ('t', 'templates', '', _('web templates to use')), | ||
('', 'style', '', _('template style to use')), | ||||
Benoit Boissinot
|
r1402 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], | ||
Thomas Arendsen Hein
|
r1615 | _('hg serve [OPTION]...')), | ||
Matt Mackall
|
r1507 | "^status|st": | ||
tksoh@users.sourceforge.net
|
r840 | (status, | ||
Vadim Gelfer
|
r2661 | [('A', 'all', None, _('show status of all files')), | ||
('m', 'modified', None, _('show only modified files')), | ||||
Benoit Boissinot
|
r1402 | ('a', 'added', None, _('show only added files')), | ||
('r', 'removed', None, _('show only removed files')), | ||||
Thomas Arendsen Hein
|
r1619 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), | ||
Vadim Gelfer
|
r2661 | ('c', 'clean', None, _('show only files without changes')), | ||
Benoit Boissinot
|
r1402 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), | ||
Thomas Arendsen Hein
|
r2022 | ('i', 'ignored', None, _('show ignored files')), | ||
Benoit Boissinot
|
r1402 | ('n', 'no-status', None, _('hide status prefix')), | ||
Brendan Cully
|
r2639 | ('C', 'copies', None, _('show source of copied files')), | ||
Muli Ben-Yehuda
|
r1602 | ('0', 'print0', None, | ||
_('end filenames with NUL, for use with xargs')), | ||||
Brendan Cully
|
r3467 | ('', 'rev', [], _('show difference from revision')), | ||
Benoit Boissinot
|
r3188 | ] + walkopts, | ||
Thomas Arendsen Hein
|
r1615 | _('hg status [OPTION]... [FILE]...')), | ||
Thomas Arendsen Hein
|
r697 | "tag": | ||
(tag, | ||||
Benoit Boissinot
|
r1402 | [('l', 'local', None, _('make the tag local')), | ||
Thomas Arendsen Hein
|
r1615 | ('m', 'message', '', _('message for tag commit log entry')), | ||
('d', 'date', '', _('record datecode as commit date')), | ||||
('u', 'user', '', _('record user as commiter')), | ||||
('r', 'rev', '', _('revision to tag'))], | ||||
Benoit Boissinot
|
r1812 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), | ||
Benoit Boissinot
|
r1402 | "tags": (tags, [], _('hg tags')), | ||
Thomas Arendsen Hein
|
r1762 | "tip": | ||
(tip, | ||||
Matt Mackall
|
r3503 | [('b', 'branches', None, _('show branches (DEPRECATED)')), | ||
Vadim Gelfer
|
r1913 | ('', 'style', '', _('display using template map file')), | ||
Vadim Gelfer
|
r1907 | ('p', 'patch', None, _('show patch')), | ||
Vadim Gelfer
|
r1913 | ('', 'template', '', _('display with template'))], | ||
Matt Mackall
|
r3504 | _('hg tip [-p]')), | ||
mpm@selenic.com
|
r1218 | "unbundle": | ||
(unbundle, | ||||
Matt Mackall
|
r1601 | [('u', 'update', None, | ||
Thomas Arendsen Hein
|
r3198 | _('update to new tip if changesets were unbundled'))], | ||
Muli Ben-Yehuda
|
r1600 | _('hg unbundle [-u] FILE')), | ||
mpm@selenic.com
|
r593 | "^update|up|checkout|co": | ||
Thomas Arendsen Hein
|
r697 | (update, | ||
Matt Mackall
|
r3503 | [('b', 'branch', '', | ||
_('checkout the head of a specific branch (DEPRECATED)')), | ||||
Matt Mackall
|
r3814 | ('C', 'clean', None, _('overwrite locally modified files')), | ||
('d', 'date', '', _('tipmost revision matching date'))], | ||||
Thomas Arendsen Hein
|
r3802 | _('hg update [-C] [REV]')), | ||
Benoit Boissinot
|
r1402 | "verify": (verify, [], _('hg verify')), | ||
Matt Mackall
|
r3651 | "version": (version_, [], _('hg version')), | ||
Thomas Arendsen Hein
|
r1046 | } | ||
mpm@selenic.com
|
r209 | |||
Benoit Boissinot
|
r1887 | norepo = ("clone init version help debugancestor debugcomplete debugdata" | ||
Matt Mackall
|
r3844 | " debugindex debugindexdot debugdate debuginstall") | ||
Thomas Arendsen Hein
|
r3268 | optionalrepo = ("paths serve showconfig") | ||
mpm@selenic.com
|
r209 | |||
Bryan O'Sullivan
|
r2988 | def findpossible(ui, cmd): | ||
Benoit Boissinot
|
r1887 | """ | ||
Return cmd -> (aliases, command table entry) | ||||
Thomas Arendsen Hein
|
r2049 | for each matching command. | ||
Return debug commands (or their aliases) only if no normal command matches. | ||||
Benoit Boissinot
|
r1887 | """ | ||
choice = {} | ||||
debugchoice = {} | ||||
mpm@selenic.com
|
r212 | for e in table.keys(): | ||
Benoit Boissinot
|
r1506 | aliases = e.lstrip("^").split("|") | ||
Thomas Arendsen Hein
|
r2049 | found = None | ||
Benoit Boissinot
|
r1506 | if cmd in aliases: | ||
Thomas Arendsen Hein
|
r2049 | found = cmd | ||
Bryan O'Sullivan
|
r2988 | elif not ui.config("ui", "strict"): | ||
Thomas Arendsen Hein
|
r2049 | for a in aliases: | ||
if a.startswith(cmd): | ||||
found = a | ||||
break | ||||
if found is not None: | ||||
Alexis S. L. Carvalho
|
r3317 | if aliases[0].startswith("debug") or found.startswith("debug"): | ||
Thomas Arendsen Hein
|
r2049 | debugchoice[found] = (aliases, table[e]) | ||
else: | ||||
choice[found] = (aliases, table[e]) | ||||
Alexis S. L. Carvalho
|
r1739 | |||
Thomas Arendsen Hein
|
r1850 | if not choice and debugchoice: | ||
choice = debugchoice | ||||
Benoit Boissinot
|
r1887 | return choice | ||
Bryan O'Sullivan
|
r2988 | def findcmd(ui, cmd): | ||
Benoit Boissinot
|
r1887 | """Return (aliases, command table entry) for command string.""" | ||
Bryan O'Sullivan
|
r2988 | choice = findpossible(ui, cmd) | ||
Benoit Boissinot
|
r1887 | |||
if choice.has_key(cmd): | ||||
return choice[cmd] | ||||
TK Soh
|
r1848 | if len(choice) > 1: | ||
Benoit Boissinot
|
r1887 | clist = choice.keys() | ||
Thomas Arendsen Hein
|
r1849 | clist.sort() | ||
TK Soh
|
r1848 | raise AmbiguousCommand(cmd, clist) | ||
Alexis S. L. Carvalho
|
r1739 | |||
Thomas Arendsen Hein
|
r1517 | if choice: | ||
Benoit Boissinot
|
r1887 | return choice.values()[0] | ||
mpm@selenic.com
|
r212 | |||
raise UnknownCommand(cmd) | ||||
mpm@selenic.com
|
r214 | def catchterm(*args): | ||
Vadim Gelfer
|
r2153 | raise util.SignalInterrupt | ||
mpm@selenic.com
|
r214 | |||
mpm@selenic.com
|
r249 | def run(): | ||
sys.exit(dispatch(sys.argv[1:])) | ||||
Thomas Arendsen Hein
|
r697 | class ParseError(Exception): | ||
"""Exception raised on errors in parsing the command line.""" | ||||
mpm@selenic.com
|
r592 | |||
TK Soh
|
r1453 | def parse(ui, args): | ||
mpm@selenic.com
|
r209 | options = {} | ||
mpm@selenic.com
|
r596 | cmdoptions = {} | ||
mpm@selenic.com
|
r209 | |||
mpm@selenic.com
|
r592 | try: | ||
mpm@selenic.com
|
r596 | args = fancyopts.fancyopts(args, globalopts, options) | ||
mpm@selenic.com
|
r592 | except fancyopts.getopt.GetoptError, inst: | ||
Bryan O'Sullivan
|
r618 | raise ParseError(None, inst) | ||
mpm@selenic.com
|
r209 | |||
Thomas Arendsen Hein
|
r1047 | if args: | ||
cmd, args = args[0], args[1:] | ||||
Bryan O'Sullivan
|
r2988 | aliases, i = findcmd(ui, cmd) | ||
TK Soh
|
r1567 | cmd = aliases[0] | ||
TK Soh
|
r1453 | defaults = ui.config("defaults", cmd) | ||
if defaults: | ||||
TK Soh
|
r3068 | args = shlex.split(defaults) + args | ||
Thomas Arendsen Hein
|
r1047 | c = list(i[1]) | ||
mpm@selenic.com
|
r209 | else: | ||
Thomas Arendsen Hein
|
r1047 | cmd = None | ||
c = [] | ||||
mpm@selenic.com
|
r209 | |||
mpm@selenic.com
|
r592 | # combine global options into local | ||
mpm@selenic.com
|
r596 | for o in globalopts: | ||
mpm@selenic.com
|
r592 | c.append((o[0], o[1], options[o[1]], o[3])) | ||
mpm@selenic.com
|
r214 | |||
mpm@selenic.com
|
r293 | try: | ||
mpm@selenic.com
|
r596 | args = fancyopts.fancyopts(args, c, cmdoptions) | ||
mpm@selenic.com
|
r293 | except fancyopts.getopt.GetoptError, inst: | ||
mpm@selenic.com
|
r596 | raise ParseError(cmd, inst) | ||
mpm@selenic.com
|
r209 | |||
mpm@selenic.com
|
r592 | # separate global options back out | ||
mpm@selenic.com
|
r596 | for o in globalopts: | ||
mpm@selenic.com
|
r592 | n = o[1] | ||
options[n] = cmdoptions[n] | ||||
del cmdoptions[n] | ||||
Thomas Arendsen Hein
|
r1047 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) | ||
mpm@selenic.com
|
r596 | |||
Vadim Gelfer
|
r2553 | external = {} | ||
def findext(name): | ||||
'''return module with given extension name''' | ||||
try: | ||||
Vadim Gelfer
|
r2573 | return sys.modules[external[name]] | ||
Vadim Gelfer
|
r2553 | except KeyError: | ||
for k, v in external.iteritems(): | ||||
Brendan Cully
|
r2755 | if k.endswith('.' + name) or k.endswith('/' + name) or v == name: | ||
Vadim Gelfer
|
r2573 | return sys.modules[v] | ||
Vadim Gelfer
|
r2553 | raise KeyError(name) | ||
Vadim Gelfer
|
r2600 | |||
Vadim Gelfer
|
r2944 | def load_extensions(ui): | ||
added = [] | ||||
for ext_name, load_from_name in ui.extensions(): | ||||
if ext_name in external: | ||||
continue | ||||
Thomas Arendsen Hein
|
r2057 | try: | ||
Vadim Gelfer
|
r2573 | if load_from_name: | ||
Benoit Boissinot
|
r2405 | # the module will be loaded in sys.modules | ||
# choose an unique name so that it doesn't | ||||
# conflicts with other modules | ||||
Vadim Gelfer
|
r2573 | module_name = "hgext_%s" % ext_name.replace('.', '_') | ||
mod = imp.load_source(module_name, load_from_name) | ||||
Thomas Arendsen Hein
|
r2057 | else: | ||
def importh(name): | ||||
mod = __import__(name) | ||||
components = name.split('.') | ||||
for comp in components[1:]: | ||||
mod = getattr(mod, comp) | ||||
return mod | ||||
Thomas Arendsen Hein
|
r1889 | try: | ||
Vadim Gelfer
|
r2573 | mod = importh("hgext.%s" % ext_name) | ||
Thomas Arendsen Hein
|
r1889 | except ImportError: | ||
Vadim Gelfer
|
r2573 | mod = importh(ext_name) | ||
external[ext_name] = mod.__name__ | ||||
Vadim Gelfer
|
r2944 | added.append((mod, ext_name)) | ||
Vadim Gelfer
|
r2428 | except (util.SignalInterrupt, KeyboardInterrupt): | ||
raise | ||||
Thomas Arendsen Hein
|
r2057 | except Exception, inst: | ||
Vadim Gelfer
|
r2943 | ui.warn(_("*** failed to import extension %s: %s\n") % | ||
(ext_name, inst)) | ||||
if ui.print_exc(): | ||||
Thomas Arendsen Hein
|
r2057 | return 1 | ||
Vadim Gelfer
|
r2944 | for mod, name in added: | ||
Vadim Gelfer
|
r2573 | uisetup = getattr(mod, 'uisetup', None) | ||
Vadim Gelfer
|
r2330 | if uisetup: | ||
Vadim Gelfer
|
r2944 | uisetup(ui) | ||
Vadim Gelfer
|
r2573 | cmdtable = getattr(mod, 'cmdtable', {}) | ||
Bryan O'Sullivan
|
r1295 | for t in cmdtable: | ||
mason@suse.com
|
r1071 | if t in table: | ||
Vadim Gelfer
|
r2943 | ui.warn(_("module %s overrides %s\n") % (name, t)) | ||
Bryan O'Sullivan
|
r1295 | table.update(cmdtable) | ||
Thomas Arendsen Hein
|
r3223 | |||
Alexis S. L. Carvalho
|
r3346 | def parseconfig(config): | ||
"""parse the --config options from the command line""" | ||||
parsed = [] | ||||
for cfg in config: | ||||
try: | ||||
name, value = cfg.split('=', 1) | ||||
section, name = name.split('.', 1) | ||||
if not section or not name: | ||||
raise IndexError | ||||
parsed.append((section, name, value)) | ||||
except (IndexError, ValueError): | ||||
raise util.Abort(_('malformed --config option: %s') % cfg) | ||||
return parsed | ||||
Vadim Gelfer
|
r2943 | def dispatch(args): | ||
for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM': | ||||
num = getattr(signal, name, None) | ||||
if num: signal.signal(num, catchterm) | ||||
try: | ||||
Alexis S. L. Carvalho
|
r3014 | u = ui.ui(traceback='--traceback' in sys.argv[1:]) | ||
Vadim Gelfer
|
r2943 | except util.Abort, inst: | ||
sys.stderr.write(_("abort: %s\n") % inst) | ||||
return -1 | ||||
Alexis S. L. Carvalho
|
r3014 | load_extensions(u) | ||
u.addreadhook(load_extensions) | ||||
mpm@selenic.com
|
r596 | try: | ||
TK Soh
|
r1453 | cmd, func, args, options, cmdoptions = parse(u, args) | ||
Matt Mackall
|
r3774 | if options["encoding"]: | ||
util._encoding = options["encoding"] | ||||
if options["encodingmode"]: | ||||
util._encodingmode = options["encodingmode"] | ||||
Thomas Arendsen Hein
|
r1875 | if options["time"]: | ||
def get_times(): | ||||
t = os.times() | ||||
if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() | ||||
t = (t[0], t[1], t[2], t[3], time.clock()) | ||||
return t | ||||
s = get_times() | ||||
def print_time(): | ||||
t = get_times() | ||||
u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % | ||||
(t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) | ||||
atexit.register(print_time) | ||||
# enter the debugger before command execution | ||||
if options['debugger']: | ||||
pdb.set_trace() | ||||
mpm@selenic.com
|
r527 | try: | ||
Thomas Arendsen Hein
|
r1859 | if options['cwd']: | ||
Thomas Arendsen Hein
|
r3840 | os.chdir(options['cwd']) | ||
Thomas Arendsen Hein
|
r1859 | |||
Alexis S. L. Carvalho
|
r3348 | u.updateopts(options["verbose"], options["debug"], options["quiet"], | ||
not options["noninteractive"], options["traceback"], | ||||
parseconfig(options["config"])) | ||||
Thomas Arendsen Hein
|
r1894 | path = u.expandpath(options["repository"]) or "" | ||
Thomas Arendsen Hein
|
r1859 | repo = path and hg.repository(u, path=path) or None | ||
Benoit Boissinot
|
r3278 | if repo and not repo.local(): | ||
raise util.Abort(_("repository '%s' is not local") % path) | ||||
Thomas Arendsen Hein
|
r1857 | |||
Thomas Arendsen Hein
|
r1048 | if options['help']: | ||
Thomas Arendsen Hein
|
r2057 | return help_(u, cmd, options['version']) | ||
Thomas Arendsen Hein
|
r1048 | elif options['version']: | ||
Matt Mackall
|
r3651 | return version_(u) | ||
Thomas Arendsen Hein
|
r1047 | elif not cmd: | ||
Thomas Arendsen Hein
|
r2057 | return help_(u, 'shortlist') | ||
Thomas Arendsen Hein
|
r1047 | |||
mpm@selenic.com
|
r527 | if cmd not in norepo.split(): | ||
Thomas Arendsen Hein
|
r1858 | try: | ||
if not repo: | ||||
repo = hg.repository(u, path=path) | ||||
u = repo.ui | ||||
Vadim Gelfer
|
r2573 | for name in external.itervalues(): | ||
mod = sys.modules[name] | ||||
if hasattr(mod, 'reposetup'): | ||||
mod.reposetup(u, repo) | ||||
Vadim Gelfer
|
r2847 | hg.repo_setup_hooks.append(mod.reposetup) | ||
Thomas Arendsen Hein
|
r1858 | except hg.RepoError: | ||
if cmd not in optionalrepo.split(): | ||||
raise | ||||
mpm@selenic.com
|
r596 | d = lambda: func(u, repo, *args, **cmdoptions) | ||
mpm@selenic.com
|
r527 | else: | ||
mpm@selenic.com
|
r596 | d = lambda: func(u, *args, **cmdoptions) | ||
mpm@selenic.com
|
r209 | |||
Vadim Gelfer
|
r1837 | try: | ||
if options['profile']: | ||||
import hotshot, hotshot.stats | ||||
prof = hotshot.Profile("hg.prof") | ||||
Vadim Gelfer
|
r1832 | try: | ||
try: | ||||
Vadim Gelfer
|
r1837 | return prof.runcall(d) | ||
Vadim Gelfer
|
r1832 | except: | ||
Vadim Gelfer
|
r1837 | try: | ||
u.warn(_('exception raised - generating ' | ||||
'profile anyway\n')) | ||||
except: | ||||
pass | ||||
raise | ||||
finally: | ||||
prof.close() | ||||
stats = hotshot.stats.load("hg.prof") | ||||
stats.strip_dirs() | ||||
stats.sort_stats('time', 'calls') | ||||
stats.print_stats(40) | ||||
Vadim Gelfer
|
r2422 | elif options['lsprof']: | ||
try: | ||||
from mercurial import lsprof | ||||
except ImportError: | ||||
raise util.Abort(_( | ||||
'lsprof not available - install from ' | ||||
'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/')) | ||||
p = lsprof.Profiler() | ||||
p.enable(subcalls=True) | ||||
try: | ||||
return d() | ||||
finally: | ||||
p.disable() | ||||
stats = lsprof.Stats(p.getstats()) | ||||
stats.sort() | ||||
stats.pprint(top=10, file=sys.stderr, climit=5) | ||||
Vadim Gelfer
|
r1837 | else: | ||
return d() | ||||
finally: | ||||
u.flush() | ||||
mpm@selenic.com
|
r527 | except: | ||
mpm@selenic.com
|
r1225 | # enter the debugger when we hit an exception | ||
if options['debugger']: | ||||
pdb.post_mortem(sys.exc_info()[2]) | ||||
Vadim Gelfer
|
r2335 | u.print_exc() | ||
mpm@selenic.com
|
r527 | raise | ||
Thomas Arendsen Hein
|
r1875 | except ParseError, inst: | ||
if inst.args[0]: | ||||
u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) | ||||
help_(u, inst.args[0]) | ||||
else: | ||||
u.warn(_("hg: %s\n") % inst.args[1]) | ||||
help_(u, 'shortlist') | ||||
except AmbiguousCommand, inst: | ||||
Vadim Gelfer
|
r1920 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % | ||
Thomas Arendsen Hein
|
r1875 | (inst.args[0], " ".join(inst.args[1]))) | ||
except UnknownCommand, inst: | ||||
u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | ||||
help_(u, 'shortlist') | ||||
mpm@selenic.com
|
r499 | except hg.RepoError, inst: | ||
Benoit Boissinot
|
r2134 | u.warn(_("abort: %s!\n") % inst) | ||
Vadim Gelfer
|
r2016 | except lock.LockHeld, inst: | ||
if inst.errno == errno.ETIMEDOUT: | ||||
reason = _('timed out waiting for lock held by %s') % inst.locker | ||||
else: | ||||
reason = _('lock held by %s') % inst.locker | ||||
u.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) | ||||
except lock.LockUnavailable, inst: | ||||
u.warn(_("abort: could not lock %s: %s\n") % | ||||
(inst.desc or inst.filename, inst.strerror)) | ||||
mpm@selenic.com
|
r1214 | except revlog.RevlogError, inst: | ||
Thomas Arendsen Hein
|
r3072 | u.warn(_("abort: %s!\n") % inst) | ||
Vadim Gelfer
|
r2153 | except util.SignalInterrupt: | ||
Benoit Boissinot
|
r1402 | u.warn(_("killed!\n")) | ||
mpm@selenic.com
|
r209 | except KeyboardInterrupt: | ||
Thomas Arendsen Hein
|
r832 | try: | ||
Benoit Boissinot
|
r1402 | u.warn(_("interrupted!\n")) | ||
Thomas Arendsen Hein
|
r832 | except IOError, inst: | ||
if inst.errno == errno.EPIPE: | ||||
if u.debugflag: | ||||
Benoit Boissinot
|
r1402 | u.warn(_("\nbroken pipe\n")) | ||
Thomas Arendsen Hein
|
r832 | else: | ||
raise | ||||
mpm@selenic.com
|
r250 | except IOError, inst: | ||
mpm@selenic.com
|
r395 | if hasattr(inst, "code"): | ||
Benoit Boissinot
|
r1402 | u.warn(_("abort: %s\n") % inst) | ||
mpm@selenic.com
|
r395 | elif hasattr(inst, "reason"): | ||
Benoit Boissinot
|
r1402 | u.warn(_("abort: error: %s\n") % inst.reason[1]) | ||
mpm@selenic.com
|
r395 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: | ||
Thomas Arendsen Hein
|
r1065 | if u.debugflag: | ||
Benoit Boissinot
|
r1402 | u.warn(_("broken pipe\n")) | ||
Matt Mackall
|
r1350 | elif getattr(inst, "strerror", None): | ||
Eric Hopper
|
r1354 | if getattr(inst, "filename", None): | ||
Thomas Arendsen Hein
|
r3080 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) | ||
Eric Hopper
|
r1354 | else: | ||
Benoit Boissinot
|
r1402 | u.warn(_("abort: %s\n") % inst.strerror) | ||
mpm@selenic.com
|
r250 | else: | ||
raise | ||||
mpm@selenic.com
|
r549 | except OSError, inst: | ||
Thomas Arendsen Hein
|
r3080 | if getattr(inst, "filename", None): | ||
Benoit Boissinot
|
r1402 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) | ||
mpm@selenic.com
|
r549 | else: | ||
Benoit Boissinot
|
r1402 | u.warn(_("abort: %s\n") % inst.strerror) | ||
Thomas Arendsen Hein
|
r3564 | except util.UnexpectedOutput, inst: | ||
u.warn(_("abort: %s") % inst[0]) | ||||
if not isinstance(inst[1], basestring): | ||||
u.warn(" %r\n" % (inst[1],)) | ||||
elif not inst[1]: | ||||
u.warn(_(" empty string\n")) | ||||
else: | ||||
Thomas Arendsen Hein
|
r3767 | u.warn("\n%r\n" % util.ellipsis(inst[1])) | ||
Bryan O'Sullivan
|
r870 | except util.Abort, inst: | ||
Thomas Arendsen Hein
|
r3072 | u.warn(_("abort: %s\n") % inst) | ||
mpm@selenic.com
|
r212 | except TypeError, inst: | ||
# was this an argument error? | ||||
tb = traceback.extract_tb(sys.exc_info()[2]) | ||||
if len(tb) > 2: # no | ||||
raise | ||||
mpm@selenic.com
|
r293 | u.debug(inst, "\n") | ||
Benoit Boissinot
|
r1402 | u.warn(_("%s: invalid arguments\n") % cmd) | ||
Thomas Arendsen Hein
|
r697 | help_(u, cmd) | ||
Thomas Arendsen Hein
|
r2057 | except SystemExit, inst: | ||
# Commands shouldn't sys.exit directly, but give a return code. | ||||
# Just in case catch this and and pass exit code to caller. | ||||
return inst.code | ||||
mpm@selenic.com
|
r1215 | except: | ||
Benoit Boissinot
|
r1402 | u.warn(_("** unknown exception encountered, details follow\n")) | ||
Benoit Boissinot
|
r2625 | u.warn(_("** report bug details to " | ||
"http://www.selenic.com/mercurial/bts\n")) | ||||
u.warn(_("** or mercurial@selenic.com\n")) | ||||
Thomas Arendsen Hein
|
r1552 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") | ||
% version.get_version()) | ||||
mpm@selenic.com
|
r1215 | raise | ||
mpm@selenic.com
|
r293 | |||
Thomas Arendsen Hein
|
r2057 | return -1 | ||