commands.py
3166 lines
| 116.5 KiB
| text/x-python
|
PythonLexer
/ mercurial / commands.py
|
r249 | # commands.py - command processing for mercurial | ||
# | ||||
|
r4635 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | ||
|
r249 | # | ||
# This software may be used and distributed according to the terms | ||||
# of the GNU General Public License, incorporated herein by reference. | ||||
|
r1092 | from node import * | ||
|
r3891 | from i18n import _ | ||
|
r5034 | import os, re, sys, urllib | ||
|
r5178 | import hg, util, revlog, bundlerepo, extensions | ||
|
r3877 | import difflib, patch, time, help, mdiff, tempfile | ||
|
r4549 | import errno, version, socket | ||
|
r3877 | import archival, changegroup, cmdutil, hgweb.server, sshserver | ||
|
r2731 | |||
|
r255 | # Commands start here, listed alphabetically | ||
|
r209 | |||
|
r724 | def add(ui, repo, *pats, **opts): | ||
|
r1437 | """add the specified files on the next commit | ||
Schedule files to be version controlled and added to the repository. | ||||
|
r3829 | The files will be added to the repository at the next commit. To | ||
undo an add before that, see hg revert. | ||||
|
r1437 | |||
|
r1568 | If no names are given, add all files in the repository. | ||
|
r1437 | """ | ||
|
r724 | names = [] | ||
|
r2882 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts): | ||
|
r942 | if exact: | ||
|
r1615 | if ui.verbose: | ||
ui.status(_('adding %s\n') % rel) | ||||
|
r724 | names.append(abs) | ||
|
r4906 | elif abs not in repo.dirstate: | ||
|
r1402 | ui.status(_('adding %s\n') % rel) | ||
|
r724 | names.append(abs) | ||
|
r2503 | if not opts.get('dry_run'): | ||
|
r2411 | repo.add(names) | ||
|
r213 | |||
|
r766 | def addremove(ui, repo, *pats, **opts): | ||
|
r3181 | """add all new files, delete all missing files | ||
|
r2181 | |||
|
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. | ||||
|
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. | ||||
|
r1437 | """ | ||
|
r4966 | try: | ||
sim = float(opts.get('similarity') or 0) | ||||
except ValueError: | ||||
raise util.Abort(_('similarity must be a number')) | ||||
|
r2958 | if sim < 0 or sim > 100: | ||
raise util.Abort(_('similarity must be between 0 and 100')) | ||||
return cmdutil.addremove(repo, pats, opts, similarity=sim/100.) | ||||
|
r219 | |||
|
r733 | def annotate(ui, repo, *pats, **opts): | ||
|
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. | ||||
""" | ||||
|
r4857 | getdate = util.cachefunc(lambda x: util.datestr(x[0].date())) | ||
|
r1522 | |||
|
r744 | if not pats: | ||
|
r1402 | raise util.Abort(_('at least one file name or pattern required')) | ||
|
r744 | |||
|
r4857 | opmap = [('user', lambda x: ui.shortuser(x[0].user())), | ||
('number', lambda x: str(x[0].rev())), | ||||
('changeset', lambda x: short(x[0].node())), | ||||
('date', getdate), | ||||
('follow', lambda x: x[0].path()), | ||||
] | ||||
|
r3172 | if (not opts['user'] and not opts['changeset'] and not opts['date'] | ||
and not opts['follow']): | ||||
|
r714 | opts['number'] = 1 | ||
|
r209 | |||
|
r4857 | linenumber = opts.get('line_number') is not None | ||
if (linenumber and (not opts['changeset']) and (not opts['number'])): | ||||
raise util.Abort(_('at least one of -n/-c is required for -l')) | ||||
funcmap = [func for op, func in opmap if opts.get(op)] | ||||
if linenumber: | ||||
lastfunc = funcmap[-1] | ||||
funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1]) | ||||
|
r3132 | ctx = repo.changectx(opts['rev']) | ||
|
r1016 | |||
|
r2882 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, | ||
node=ctx.node()): | ||||
|
r2566 | fctx = ctx.filectx(abs) | ||
if not opts['text'] and util.binary(fctx.data()): | ||||
|
r1625 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) | ||
|
r1016 | continue | ||
|
r4857 | lines = fctx.annotate(follow=opts.get('follow'), | ||
linenumber=linenumber) | ||||
|
r209 | pieces = [] | ||
|
r4857 | for f in funcmap: | ||
l = [f(n) for n, dummy in lines] | ||||
if l: | ||||
m = max(map(len, l)) | ||||
pieces.append(["%*s" % (m, x) for x in l]) | ||||
|
r209 | |||
|
r771 | if pieces: | ||
for p, l in zip(zip(*pieces), lines): | ||||
ui.write("%s: %s" % (" ".join(p), l[1])) | ||||
|
r209 | |||
|
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. | ||||
''' | ||||
|
r5061 | ctx = repo.changectx(opts['rev']) | ||
if not ctx: | ||||
raise util.Abort(_('repository has no revisions')) | ||||
node = ctx.node() | ||||
|
r2874 | dest = cmdutil.make_filename(repo, dest, node) | ||
|
r2112 | if os.path.realpath(dest) == repo.root: | ||
raise util.Abort(_('repository root cannot be destination')) | ||||
|
r2882 | dummy, matchfn, dummy = cmdutil.matchpats(repo, [], opts) | ||
|
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' | ||||
|
r2874 | prefix = cmdutil.make_filename(repo, prefix, node) | ||
|
r2476 | archival.archive(repo, dest, node, kind, not opts['no_decode'], | ||
matchfn, prefix) | ||||
|
r2112 | |||
|
r4450 | def backout(ui, repo, node=None, rev=None, **opts): | ||
|
r2158 | '''reverse effect of earlier changeset | ||
|
r2254 | Commit the backed out changes as a new changeset. The new | ||
changeset is a child of the backed out changeset. | ||||
|
r2158 | |||
If you back out a changeset other than the tip, a new head is | ||||
|
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.''' | ||||
|
r4450 | if rev and node: | ||
raise util.Abort(_("please specify just one revision")) | ||||
if not rev: | ||||
rev = node | ||||
|
r2158 | |||
|
r4726 | if not rev: | ||
raise util.Abort(_("please specify a revision to backout")) | ||||
|
r4549 | cmdutil.bail_if_changed(repo) | ||
|
r2158 | op1, op2 = repo.dirstate.parents() | ||
if op2 != nullid: | ||||
raise util.Abort(_('outstanding uncommitted merge')) | ||||
node = repo.lookup(rev) | ||||
|
r2614 | p1, p2 = repo.changelog.parents(node) | ||
if p1 == nullid: | ||||
|
r2158 | raise util.Abort(_('cannot back out a change with no parents')) | ||
if p2 != nullid: | ||||
|
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): | ||||
|
r3679 | raise util.Abort(_('%s is not a parent of %s') % | ||
|
r3680 | (short(p), short(node))) | ||
|
r2614 | parent = p | ||
else: | ||||
if opts['parent']: | ||||
raise util.Abort(_('cannot use --parent on non-merge changeset')) | ||||
parent = p1 | ||||
|
r2808 | hg.clean(repo, node, show_stats=False) | ||
|
r2158 | revert_opts = opts.copy() | ||
|
r3814 | revert_opts['date'] = None | ||
|
r2982 | revert_opts['all'] = True | ||
|
r2158 | revert_opts['rev'] = hex(parent) | ||
revert(ui, repo, **revert_opts) | ||||
commit_opts = opts.copy() | ||||
commit_opts['addremove'] = False | ||||
|
r2159 | if not commit_opts['message'] and not commit_opts['logfile']: | ||
|
r4718 | commit_opts['message'] = _("Backed out changeset %s") % (short(node)) | ||
|
r2268 | commit_opts['force_editor'] = True | ||
|
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))) | ||||
|
r2493 | if op1 != node: | ||
if opts['merge']: | ||||
ui.status(_('merging with changeset %s\n') % nice(op1)) | ||||
|
r3876 | hg.merge(repo, hex(op1)) | ||
|
r2493 | else: | ||
ui.status(_('the backout changeset is a new head - ' | ||||
'do not forget to merge\n')) | ||||
|
r2761 | ui.status(_('(use "backout --merge" ' | ||
'if you want to auto-merge)\n')) | ||||
|
r2158 | |||
|
r4202 | def branch(ui, repo, label=None, **opts): | ||
|
r3502 | """set or show the current branch name | ||
|
r4601 | With no argument, show the current branch name. With one argument, | ||
set the working directory branch name (the branch does not exist in | ||||
the repository until the next commit). | ||||
|
r4202 | |||
Unless --force is specified, branch will not let you set a | ||||
branch name that shadows an existing branch. | ||||
|
r3502 | """ | ||
|
r4179 | if label: | ||
|
r4202 | if not opts.get('force') and label in repo.branchtags(): | ||
if label not in [p.branch() for p in repo.workingctx().parents()]: | ||||
raise util.Abort(_('a branch of the same name already exists' | ||||
' (use --force to override)')) | ||||
|
r4179 | repo.dirstate.setbranch(util.fromlocal(label)) | ||
|
r4601 | ui.status(_('marked working directory as branch %s\n') % label) | ||
|
r3502 | else: | ||
|
r4179 | ui.write("%s\n" % util.tolocal(repo.dirstate.branch())) | ||
|
r3502 | |||
|
r4675 | def branches(ui, repo, active=False): | ||
|
r3502 | """list repository named branches | ||
|
r4675 | List the repository's named branches, indicating which ones are | ||
inactive. If active is specified, only show active branches. | ||||
A branch is considered active if it contains unmerged heads. | ||||
|
r3502 | """ | ||
b = repo.branchtags() | ||||
|
r4675 | heads = dict.fromkeys(repo.heads(), 1) | ||
l = [((n in heads), repo.changelog.rev(n), n, t) for t, n in b.items()] | ||||
|
r3502 | l.sort() | ||
|
r4675 | l.reverse() | ||
for ishead, r, n, t in l: | ||||
if active and not ishead: | ||||
# If we're only displaying active branches, abort the loop on | ||||
# encountering the first inactive head | ||||
break | ||||
|
r3502 | else: | ||
|
r4675 | hexfunc = ui.debugflag and hex or short | ||
if ui.quiet: | ||||
ui.write("%s\n" % t) | ||||
else: | ||||
spaces = " " * (30 - util.locallen(t)) | ||||
# The code only gets here if inactive branches are being | ||||
# displayed or the branch is active. | ||||
isinactive = ((not ishead) and " (inactive)") or '' | ||||
ui.write("%s%s %s:%s%s\n" % (t, spaces, r, hexfunc(n), isinactive)) | ||||
|
r3502 | |||
|
r2494 | def bundle(ui, repo, fname, dest=None, **opts): | ||
|
r1437 | """create a changegroup file | ||
|
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. | ||||
|
r1437 | """ | ||
|
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")) | ||||
|
r3318 | base = [repo.lookup(rev) for rev in base] | ||
# create the right base | ||||
# XXX: nodesbetween / changegroup* should be "fixed" instead | ||||
|
r3284 | o = [] | ||
|
r3649 | has = {nullid: None} | ||
|
r3284 | for n in base: | ||
|
r3631 | has.update(repo.changelog.reachable(n)) | ||
|
r3284 | if revs: | ||
|
r3318 | visit = list(revs) | ||
|
r3284 | else: | ||
|
r3318 | visit = repo.changelog.heads() | ||
|
r3631 | seen = {} | ||
|
r3318 | while visit: | ||
n = visit.pop(0) | ||||
|
r3631 | parents = [p for p in repo.changelog.parents(n) if p not in has] | ||
|
r3318 | if len(parents) == 0: | ||
o.insert(0, n) | ||||
else: | ||||
|
r3512 | for p in parents: | ||
if p not in seen: | ||||
|
r3631 | seen[p] = 1 | ||
|
r3512 | visit.append(p) | ||
|
r3284 | else: | ||
|
r4549 | cmdutil.setremoteconfig(ui, opts) | ||
|
r5248 | dest, revs, checkout = hg.parseurl( | ||
|
r4478 | ui.expandpath(dest or 'default-push', dest or 'default'), revs) | ||
|
r3284 | 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') | ||||
|
r3704 | changegroup.writebundle(cg, fname, "HG10BZ") | ||
|
r1218 | |||
|
r1254 | def cat(ui, repo, file1, *pats, **opts): | ||
|
r3914 | """output the current or given revision of files | ||
|
r1437 | |||
Print the specified files as they were at the given revision. | ||||
|
r3915 | If no revision is given, the parent of the working directory is used, | ||
or tip if no revision is checked out. | ||||
|
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 | ||||
""" | ||||
|
r3132 | ctx = repo.changectx(opts['rev']) | ||
|
r4697 | err = 1 | ||
|
r2882 | for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts, | ||
ctx.node()): | ||||
|
r2874 | fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs) | ||
|
r2565 | fp.write(ctx.filectx(abs).data()) | ||
|
r4697 | err = 0 | ||
return err | ||||
|
r248 | |||
|
r698 | def clone(ui, source, dest=None, **opts): | ||
|
r1437 | """make a copy of an existing repository | ||
Create a copy of an existing repository in a new directory. | ||||
If no destination directory name is specified, it defaults to the | ||||
basename of the source. | ||||
The location of the source is added to the new repository's | ||||
.hg/hgrc file, as the default to be used for future pulls. | ||||
For efficiency, hardlinks are used for cloning whenever the source | ||||
|
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). | ||||
|
r1811 | |||
|
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. | ||||
|
r1811 | See pull for valid source format details. | ||
|
r2590 | |||
It is possible to specify an ssh:// URL as the destination, but no | ||||
|
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. | ||||
|
r1437 | """ | ||
|
r4549 | cmdutil.setremoteconfig(ui, opts) | ||
|
r4478 | hg.clone(ui, source, dest, | ||
|
r2597 | pull=opts['pull'], | ||
|
r2620 | stream=opts['uncompressed'], | ||
|
r2597 | rev=opts['rev'], | ||
update=not opts['noupdate']) | ||||
|
r515 | |||
|
r813 | def commit(ui, repo, *pats, **opts): | ||
|
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" | ||||
|
r1995 | will be committed. | ||
|
r1437 | |||
|
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. | ||||
|
r1437 | """ | ||
|
r5034 | def commitfunc(ui, repo, files, message, match, opts): | ||
return repo.commit(files, message, opts['user'], opts['date'], match, | ||||
force_editor=opts.get('force_editor')) | ||||
cmdutil.commit(ui, repo, commitfunc, pats, opts) | ||||
|
r245 | |||
|
r4917 | def docopy(ui, repo, pats, opts): | ||
|
r1822 | # called with the repo lock held | ||
|
r3670 | # | ||
# hgsep => pathname that uses "/" to separate directories | ||||
# ossep => pathname that uses os.sep to separate directories | ||||
|
r1512 | cwd = repo.getcwd() | ||
errors = 0 | ||||
copied = [] | ||||
|
r1514 | targets = {} | ||
|
r1249 | |||
|
r3670 | # abs: hgsep | ||
# rel: ossep | ||||
# return: hgsep | ||||
|
r1249 | def okaytocopy(abs, rel, exact): | ||
|
r1402 | reasons = {'?': _('is not managed'), | ||
|
r1634 | 'r': _('has been marked for remove')} | ||
|
r4906 | state = repo.dirstate[abs] | ||
|
r1747 | reason = reasons.get(state) | ||
|
r1249 | if reason: | ||
|
r4744 | if exact: | ||
ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) | ||||
else: | ||||
|
r1747 | if state == 'a': | ||
origsrc = repo.dirstate.copied(abs) | ||||
if origsrc is not None: | ||||
return origsrc | ||||
return abs | ||||
|
r3670 | # origsrc: hgsep | ||
# abssrc: hgsep | ||||
# relsrc: ossep | ||||
|
r4523 | # otarget: ossep | ||
def copy(origsrc, abssrc, relsrc, otarget, exact): | ||||
abstarget = util.canonpath(repo.root, cwd, otarget) | ||||
|
r4525 | reltarget = repo.pathto(abstarget, cwd) | ||
|
r1514 | prevsrc = targets.get(abstarget) | ||
|
r4523 | src = repo.wjoin(abssrc) | ||
target = repo.wjoin(abstarget) | ||||
|
r1514 | if prevsrc is not None: | ||
ui.warn(_('%s: not overwriting - %s collides with %s\n') % | ||||
|
r4526 | (reltarget, repo.pathto(abssrc, cwd), | ||
repo.pathto(prevsrc, cwd))) | ||||
|
r1514 | return | ||
|
r4523 | if (not opts['after'] and os.path.exists(target) or | ||
|
r4906 | opts['after'] and repo.dirstate[abstarget] in 'mn'): | ||
|
r1565 | if not opts['force']: | ||
|
r1513 | ui.warn(_('%s: not overwriting - file exists\n') % | ||
reltarget) | ||||
return | ||||
|
r2503 | if not opts['after'] and not opts.get('dry_run'): | ||
|
r4523 | os.unlink(target) | ||
|
r1565 | if opts['after']: | ||
|
r4523 | if not os.path.exists(target): | ||
|
r1565 | return | ||
else: | ||||
|
r4523 | targetdir = os.path.dirname(target) or '.' | ||
|
r2503 | if not os.path.isdir(targetdir) and not opts.get('dry_run'): | ||
|
r1512 | os.makedirs(targetdir) | ||
|
r1249 | try: | ||
|
r4906 | restore = repo.dirstate[abstarget] == 'r' | ||
|
r2503 | if restore and not opts.get('dry_run'): | ||
|
r4917 | repo.undelete([abstarget]) | ||
|
r1822 | try: | ||
|
r2503 | if not opts.get('dry_run'): | ||
|
r4523 | util.copyfile(src, target) | ||
|
r1822 | restore = False | ||
finally: | ||||
if restore: | ||||
|
r4917 | repo.remove([abstarget]) | ||
|
r1249 | except IOError, inst: | ||
if inst.errno == errno.ENOENT: | ||||
|
r1512 | ui.warn(_('%s: deleted in working copy\n') % relsrc) | ||
|
r1249 | else: | ||
|
r1512 | ui.warn(_('%s: cannot copy - %s\n') % | ||
(relsrc, inst.strerror)) | ||||
errors += 1 | ||||
return | ||||
|
r1565 | if ui.verbose or not exact: | ||
ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) | ||||
|
r1514 | targets[abstarget] = abssrc | ||
|
r4744 | if abstarget != origsrc: | ||
|
r4906 | if repo.dirstate[origsrc] == 'a': | ||
|
r4833 | if not ui.quiet: | ||
ui.warn(_("%s has not been committed yet, so no copy " | ||||
"data will be stored for %s.\n") | ||||
% (repo.pathto(origsrc, cwd), reltarget)) | ||||
|
r4744 | if abstarget not in repo.dirstate and not opts.get('dry_run'): | ||
|
r4917 | repo.add([abstarget]) | ||
|
r4744 | elif not opts.get('dry_run'): | ||
|
r4917 | repo.copy(origsrc, abstarget) | ||
|
r1512 | copied.append((abssrc, relsrc, exact)) | ||
|
r3670 | # pat: ossep | ||
# dest ossep | ||||
# srcs: list of (hgsep, hgsep, ossep, bool) | ||||
# return: function that takes hgsep and returns ossep | ||||
|
r1565 | def targetpathfn(pat, dest, srcs): | ||
if os.path.isdir(pat): | ||||
|
r1633 | abspfx = util.canonpath(repo.root, cwd, pat) | ||
|
r3670 | abspfx = util.localpath(abspfx) | ||
|
r1565 | if destdirexists: | ||
|
r1633 | striplen = len(os.path.split(abspfx)[0]) | ||
|
r1565 | else: | ||
|
r1633 | striplen = len(abspfx) | ||
|
r1565 | if striplen: | ||
striplen += len(os.sep) | ||||
|
r3670 | res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) | ||
|
r1565 | elif destdirexists: | ||
|
r3670 | res = lambda p: os.path.join(dest, | ||
os.path.basename(util.localpath(p))) | ||||
|
r1565 | else: | ||
res = lambda p: dest | ||||
return res | ||||
|
r3670 | # pat: ossep | ||
# dest ossep | ||||
# srcs: list of (hgsep, hgsep, ossep, bool) | ||||
# return: function that takes hgsep and returns ossep | ||||
|
r1565 | def targetpathafterfn(pat, dest, srcs): | ||
if util.patkind(pat, None)[0]: | ||||
# a mercurial pattern | ||||
|
r3670 | res = lambda p: os.path.join(dest, | ||
os.path.basename(util.localpath(p))) | ||||
|
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: | ||||
|
r3670 | t = os.path.join(dest, util.localpath(s[0])[striplen:]) | ||
|
r1633 | if os.path.exists(t): | ||
score += 1 | ||||
return score | ||||
|
r1565 | |||
|
r3670 | abspfx = util.localpath(abspfx) | ||
|
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 | ||||
|
r3670 | res = lambda p: os.path.join(dest, | ||
util.localpath(p)[striplen:]) | ||||
|
r1565 | else: | ||
|
r1633 | # a file | ||
if destdirexists: | ||||
|
r3670 | res = lambda p: os.path.join(dest, | ||
os.path.basename(util.localpath(p))) | ||||
|
r1633 | else: | ||
res = lambda p: dest | ||||
|
r1565 | return res | ||
|
r4055 | pats = util.expand_glob(pats) | ||
|
r1512 | 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) | ||||
|
r5329 | if not destdirexists: | ||
if len(pats) > 1 or util.patkind(pats[0], None)[0]: | ||||
raise util.Abort(_('with multiple sources, destination must be an ' | ||||
'existing directory')) | ||||
if dest.endswith(os.sep) or os.altsep and dest.endswith(os.altsep): | ||||
raise util.Abort(_('destination %s is not a directory') % dest) | ||||
|
r1565 | if opts['after']: | ||
tfn = targetpathafterfn | ||||
else: | ||||
tfn = targetpathfn | ||||
copylist = [] | ||||
|
r1512 | for pat in pats: | ||
|
r1565 | srcs = [] | ||
|
r4055 | for tag, abssrc, relsrc, exact in cmdutil.walk(repo, [pat], opts, | ||
globbed=True): | ||||
|
r1747 | origsrc = okaytocopy(abssrc, relsrc, exact) | ||
if origsrc: | ||||
srcs.append((origsrc, abssrc, relsrc, exact)) | ||||
|
r1565 | if not srcs: | ||
continue | ||||
copylist.append((tfn(pat, dest, srcs), srcs)) | ||||
if not copylist: | ||||
raise util.Abort(_('no files to copy')) | ||||
|
r2414 | for targetpath, srcs in copylist: | ||
for origsrc, abssrc, relsrc, exact in srcs: | ||||
copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) | ||||
|
r1512 | |||
if errors: | ||||
|
r1402 | ui.warn(_('(consider using --after)\n')) | ||
|
r1512 | return errors, copied | ||
|
r1253 | |||
def copy(ui, repo, *pats, **opts): | ||||
|
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. | ||||
|
r3829 | This command takes effect in the next commit. To undo a copy | ||
before that, see hg revert. | ||||
|
r1437 | """ | ||
|
r4914 | wlock = repo.wlock(False) | ||
|
r4915 | try: | ||
|
r4917 | errs, copied = docopy(ui, repo, pats, opts) | ||
|
r4915 | finally: | ||
del wlock | ||||
|
r1249 | return errs | ||
|
r363 | |||
|
r1262 | def debugancestor(ui, index, rev1, rev2): | ||
"""find the ancestor revision of two revisions in a given index""" | ||||
|
r4258 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index) | ||
|
r1262 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) | ||
ui.write("%d:%s\n" % (r.rev(a), hex(a))) | ||||
|
r2034 | def debugcomplete(ui, cmd='', **opts): | ||
|
r1887 | """returns the completion list associated with the given command""" | ||
|
r2034 | |||
if opts['options']: | ||||
options = [] | ||||
otables = [globalopts] | ||||
if cmd: | ||||
|
r5178 | aliases, entry = cmdutil.findcmd(ui, cmd, table) | ||
|
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 | ||||
|
r5178 | clist = cmdutil.findpossible(ui, cmd, table).keys() | ||
|
r1887 | clist.sort() | ||
|
r2034 | ui.write("%s\n" % "\n".join(clist)) | ||
|
r1887 | |||
|
r3972 | def debugrebuildstate(ui, repo, rev=""): | ||
|
r1755 | """rebuild the dirstate as it would look like for the given revision""" | ||
|
r3972 | if rev == "": | ||
|
r1755 | rev = repo.changelog.tip() | ||
|
r3972 | ctx = repo.changectx(rev) | ||
files = ctx.manifest() | ||||
|
r1760 | wlock = repo.wlock() | ||
|
r4915 | try: | ||
repo.dirstate.rebuild(rev, files) | ||||
finally: | ||||
del wlock | ||||
|
r1755 | |||
|
r596 | def debugcheckstate(ui, repo): | ||
"""validate the correctness of the current dirstate""" | ||||
|
r460 | parent1, parent2 = repo.dirstate.parents() | ||
|
r3972 | m1 = repo.changectx(parent1).manifest() | ||
m2 = repo.changectx(parent2).manifest() | ||||
|
r460 | errors = 0 | ||
|
r4906 | for f in repo.dirstate: | ||
state = repo.dirstate[f] | ||||
|
r460 | if state in "nr" and f not in m1: | ||
|
r1402 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) | ||
|
r460 | errors += 1 | ||
if state in "a" and f in m1: | ||||
|
r1402 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) | ||
|
r460 | errors += 1 | ||
if state in "m" and f not in m1 and f not in m2: | ||||
|
r1402 | ui.warn(_("%s in state %s, but not in either manifest\n") % | ||
|
r582 | (f, state)) | ||
|
r460 | errors += 1 | ||
for f in m1: | ||||
|
r4906 | state = repo.dirstate[f] | ||
|
r460 | if state not in "nrm": | ||
|
r1402 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) | ||
|
r460 | errors += 1 | ||
if errors: | ||||
|
r1602 | error = _(".hg/dirstate inconsistent with current parent's manifest") | ||
raise util.Abort(error) | ||||
|
r460 | |||
|
r3553 | def showconfig(ui, repo, *values, **opts): | ||
|
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.""" | ||||
|
r3553 | untrusted = bool(opts.get('untrusted')) | ||
|
r2410 | if values: | ||
if len([v for v in values if '.' in v]) > 1: | ||||
raise util.Abort(_('only one config item permitted')) | ||||
|
r3553 | for section, name, value in ui.walkconfig(untrusted=untrusted): | ||
|
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)) | ||||
|
r1028 | |||
|
r1395 | def debugsetparents(ui, repo, rev1, rev2=None): | ||
|
r1470 | """manually set the parents of the current working directory | ||
|
r1395 | |||
This is useful for writing repository conversion tools, but should | ||||
be used with care. | ||||
""" | ||||
if not rev2: | ||||
rev2 = hex(nullid) | ||||
|
r4247 | wlock = repo.wlock() | ||
try: | ||||
repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) | ||||
finally: | ||||
|
r4915 | del wlock | ||
|
r1395 | |||
|
r596 | def debugstate(ui, repo): | ||
"""show the contents of the current dirstate""" | ||||
|
r5156 | k = repo.dirstate._map.items() | ||
|
r4906 | k.sort() | ||
|
r5156 | for file_, ent in k: | ||
if ent[3] == -1: | ||||
|
r4053 | # Pad or slice to locale representation | ||
locale_len = len(time.strftime("%x %X", time.localtime(0))) | ||||
timestr = 'unset' | ||||
timestr = timestr[:locale_len] + ' '*(locale_len - len(timestr)) | ||||
else: | ||||
|
r5156 | timestr = time.strftime("%x %X", time.localtime(ent[3])) | ||
if ent[1] & 020000: | ||||
mode = 'lnk' | ||||
else: | ||||
mode = '%3o' % (ent[1] & 0777) | ||||
ui.write("%c %s %10d %s %s\n" % (ent[0], mode, ent[2], timestr, file_)) | ||||
|
r3159 | for f in repo.dirstate.copies(): | ||
ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) | ||||
|
r460 | |||
|
r1039 | def debugdata(ui, file_, rev): | ||
|
r4258 | """dump the contents of a data file revision""" | ||
r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_[:-2] + ".i") | ||||
|
r1313 | try: | ||
ui.write(r.revision(r.lookup(rev))) | ||||
except KeyError: | ||||
|
r3072 | raise util.Abort(_('invalid revision identifier %s') % rev) | ||
|
r1039 | |||
|
r3812 | def debugdate(ui, date, range=None, **opts): | ||
|
r3805 | """parse and display a date""" | ||
|
r3812 | if opts["extended"]: | ||
d = util.parsedate(date, util.extendeddateformats) | ||||
else: | ||||
d = util.parsedate(date) | ||||
|
r3805 | ui.write("internal: %s %s\n" % d) | ||
ui.write("standard: %s\n" % util.datestr(d)) | ||||
|
r3812 | if range: | ||
m = util.matchdate(range) | ||||
ui.write("match: %s\n" % m(d[0])) | ||||
|
r3805 | |||
|
r697 | def debugindex(ui, file_): | ||
|
r596 | """dump the contents of an index file""" | ||
|
r4258 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_) | ||
|
r582 | ui.write(" rev offset length base linkrev" + | ||
|
r989 | " nodeid p1 p2\n") | ||
|
r3472 | for i in xrange(r.count()): | ||
|
r2072 | node = r.node(i) | ||
|
r5311 | try: | ||
pp = r.parents(node) | ||||
except: | ||||
pp = [nullid, nullid] | ||||
|
r989 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( | ||
|
r2072 | i, r.start(i), r.length(i), r.base(i), r.linkrev(node), | ||
short(node), short(pp[0]), short(pp[1]))) | ||||
|
r248 | |||
|
r697 | def debugindexdot(ui, file_): | ||
|
r596 | """dump an index DAG as a .dot file""" | ||
|
r4258 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_) | ||
|
r582 | ui.write("digraph G {\n") | ||
|
r3472 | for i in xrange(r.count()): | ||
|
r2287 | node = r.node(i) | ||
pp = r.parents(node) | ||||
ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) | ||||
if pp[1] != nullid: | ||||
ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) | ||||
|
r582 | ui.write("}\n") | ||
|
r248 | |||
|
r3844 | def debuginstall(ui): | ||
'''test Mercurial installation''' | ||||
|
r3846 | def writetemp(contents): | ||
|
r4849 | (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-") | ||
|
r3846 | f = os.fdopen(fd, "wb") | ||
f.write(contents) | ||||
f.close() | ||||
return name | ||||
|
r3844 | problems = 0 | ||
# encoding | ||||
ui.status(_("Checking encoding (%s)...\n") % util._encoding) | ||||
try: | ||||
util.fromlocal("test") | ||||
except util.Abort, inst: | ||||
ui.write(" %s\n" % inst) | ||||
|
r3848 | ui.write(_(" (check that your locale is properly set)\n")) | ||
|
r3844 | problems += 1 | ||
# compiled modules | ||||
ui.status(_("Checking extensions...\n")) | ||||
try: | ||||
import bdiff, mpatch, base85 | ||||
except Exception, inst: | ||||
ui.write(" %s\n" % inst) | ||||
|
r3848 | ui.write(_(" One or more extensions could not be found")) | ||
ui.write(_(" (check that you compiled the extensions)\n")) | ||||
|
r3844 | problems += 1 | ||
# templates | ||||
ui.status(_("Checking templates...\n")) | ||||
try: | ||||
import templater | ||||
t = templater.templater(templater.templatepath("map-cmdline.default")) | ||||
except Exception, inst: | ||||
ui.write(" %s\n" % inst) | ||||
|
r3848 | ui.write(_(" (templates seem to have been installed incorrectly)\n")) | ||
|
r3844 | problems += 1 | ||
# patch | ||||
ui.status(_("Checking patch...\n")) | ||||
|
r5310 | patchproblems = 0 | ||
a = "1\n2\n3\n4\n" | ||||
b = "1\n2\n3\ninsert\n4\n" | ||||
fa = writetemp(a) | ||||
|
r5482 | d = mdiff.unidiff(a, None, b, None, os.path.basename(fa), | ||
os.path.basename(fa)) | ||||
|
r5310 | fd = writetemp(d) | ||
files = {} | ||||
try: | ||||
patch.patch(fd, ui, cwd=os.path.dirname(fa), files=files) | ||||
except util.Abort, e: | ||||
ui.write(_(" patch call failed:\n")) | ||||
ui.write(" " + str(e) + "\n") | ||||
patchproblems += 1 | ||||
|
r3846 | else: | ||
|
r5310 | if list(files) != [os.path.basename(fa)]: | ||
ui.write(_(" unexpected patch output!\n")) | ||||
patchproblems += 1 | ||||
a = file(fa).read() | ||||
if a != b: | ||||
ui.write(_(" patch test failed!\n")) | ||||
patchproblems += 1 | ||||
if patchproblems: | ||||
if ui.config('ui', 'patch'): | ||||
ui.write(_(" (Current patch tool may be incompatible with patch," | ||||
" or misconfigured. Please check your .hgrc file)\n")) | ||||
|
r4516 | else: | ||
|
r5310 | ui.write(_(" Internal patcher failure, please report this error" | ||
" to http://www.selenic.com/mercurial/bts\n")) | ||||
problems += patchproblems | ||||
os.unlink(fa) | ||||
os.unlink(fd) | ||||
|
r3844 | |||
# merge helper | ||||
ui.status(_("Checking merge helper...\n")) | ||||
cmd = (os.environ.get("HGMERGE") or ui.config("ui", "merge") | ||||
or "hgmerge") | ||||
|
r4488 | cmdpath = util.find_exe(cmd) or util.find_exe(cmd.split()[0]) | ||
|
r3844 | if not cmdpath: | ||
if cmd == 'hgmerge': | ||||
ui.write(_(" No merge helper set and can't find default" | ||||
" hgmerge script in PATH\n")) | ||||
|
r3848 | ui.write(_(" (specify a merge helper in your .hgrc file)\n")) | ||
|
r3844 | else: | ||
ui.write(_(" Can't find merge helper '%s' in PATH\n") % cmd) | ||||
|
r3848 | ui.write(_(" (specify a merge helper in your .hgrc file)\n")) | ||
|
r3844 | problems += 1 | ||
|
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") | ||||
|
r4747 | r = util.system('%s "%s" "%s" "%s"' % (cmd, fl, fa, fr)) | ||
|
r3846 | if r: | ||
|
r4747 | ui.write(_(" Got unexpected merge error %d!\n") % r) | ||
|
r3846 | problems += 1 | ||
m = file(fl).read() | ||||
if m != "begin\n1\n2\n3\ninsert\n4\n": | ||||
|
r4747 | ui.write(_(" Got unexpected merge results!\n")) | ||
|
r3848 | ui.write(_(" (your merge helper may have the" | ||
" wrong argument order)\n")) | ||||
|
r4747 | ui.write(_(" Result: %r\n") % m) | ||
problems += 1 | ||||
|
r3846 | os.unlink(fa) | ||
os.unlink(fl) | ||||
os.unlink(fr) | ||||
|
r3844 | |||
# editor | ||||
ui.status(_("Checking commit editor...\n")) | ||||
editor = (os.environ.get("HGEDITOR") or | ||||
ui.config("ui", "editor") or | ||||
os.environ.get("EDITOR", "vi")) | ||||
|
r4488 | cmdpath = util.find_exe(editor) or util.find_exe(editor.split()[0]) | ||
|
r3844 | if not cmdpath: | ||
|
r3855 | if editor == 'vi': | ||
|
r3844 | ui.write(_(" No commit editor set and can't find vi in PATH\n")) | ||
|
r3848 | ui.write(_(" (specify a commit editor in your .hgrc file)\n")) | ||
|
r3844 | else: | ||
ui.write(_(" Can't find editor '%s' in PATH\n") % editor) | ||||
|
r3848 | ui.write(_(" (specify a commit editor in your .hgrc file)\n")) | ||
|
r3844 | problems += 1 | ||
|
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")) | ||||
|
r3844 | if not problems: | ||
ui.status(_("No problems detected\n")) | ||||
else: | ||||
ui.write(_("%s problems detected," | ||||
" please check your install!\n") % problems) | ||||
return problems | ||||
|
r3652 | def debugrename(ui, repo, file1, *pats, **opts): | ||
|
r1194 | """dump rename information""" | ||
|
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) | ||||
|
r1116 | |||
|
r820 | def debugwalk(ui, repo, *pats, **opts): | ||
|
r1053 | """show how files match on given patterns""" | ||
|
r2882 | items = list(cmdutil.walk(repo, pats, opts)) | ||
|
r1065 | if not items: | ||
return | ||||
|
r1309 | fmt = '%%s %%-%ds %%-%ds %%s' % ( | ||
|
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: | ||||
|
r1309 | line = fmt % (src, abs, rel, exact and 'exact' or '') | ||
ui.write("%s\n" % line.rstrip()) | ||||
|
r820 | |||
|
r732 | def diff(ui, repo, *pats, **opts): | ||
|
r1568 | """diff repository (or selected files) | ||
|
r1437 | |||
Show differences between revisions for the specified files. | ||||
Differences between files are shown using the unified diff format. | ||||
|
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. | ||||
|
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. | ||||
""" | ||||
|
r3707 | node1, node2 = cmdutil.revpair(repo, opts['rev']) | ||
|
r245 | |||
|
r2882 | fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) | ||
|
r1014 | |||
|
r2874 | patch.diff(repo, node1, node2, fns, match=matchfn, | ||
|
r2888 | opts=patch.diffopts(ui, opts)) | ||
|
r396 | |||
|
r580 | def export(ui, repo, *changesets, **opts): | ||
|
r1437 | """dump the header and diffs for one or more changesets | ||
Print the changeset header and diffs for one or more revisions. | ||||
The information shown in the changeset header is: author, | ||||
|
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. | ||||
|
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. | ||||
|
r1571 | |||
With the --switch-parent option, the diff will be against the second | ||||
parent. It can be useful to review a merge. | ||||
|
r1437 | """ | ||
|
r610 | if not changesets: | ||
|
r1402 | raise util.Abort(_("export requires at least one changeset")) | ||
|
r3707 | revs = cmdutil.revrange(repo, changesets) | ||
|
r2874 | if len(revs) > 1: | ||
ui.note(_('exporting patches:\n')) | ||||
else: | ||||
ui.note(_('exporting patch:\n')) | ||||
|
r3900 | patch.export(repo, revs, template=opts['output'], | ||
|
r2888 | switch_parent=opts['switch_parent'], | ||
opts=patch.diffopts(ui, opts)) | ||||
|
r246 | |||
|
r1108 | def grep(ui, repo, pattern, *pats, **opts): | ||
|
r1437 | """search for a pattern in specified files and revisions | ||
Search revisions of files for a regular expression. | ||||
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. | ||||
""" | ||||
|
r1057 | reflags = 0 | ||
|
r1065 | if opts['ignore_case']: | ||
reflags |= re.I | ||||
|
r4877 | try: | ||
regexp = re.compile(pattern, reflags) | ||||
except Exception, inst: | ||||
ui.warn(_("grep: invalid match pattern: %s!\n") % inst) | ||||
return None | ||||
|
r1146 | sep, eol = ':', '\n' | ||
|
r1108 | if opts['print0']: | ||
|
r1146 | sep = eol = '\0' | ||
|
r1057 | |||
fcache = {} | ||||
def getfile(fn): | ||||
if fn not in fcache: | ||||
fcache[fn] = repo.file(fn) | ||||
return fcache[fn] | ||||
def matchlines(body): | ||||
|
r1059 | begin = 0 | ||
linenum = 0 | ||||
while True: | ||||
match = regexp.search(body, begin) | ||||
|
r1065 | if not match: | ||
break | ||||
|
r1059 | mstart, mend = match.span() | ||
linenum += body.count('\n', begin, mstart) + 1 | ||||
lstart = body.rfind('\n', begin, mstart) + 1 or begin | ||||
lend = body.find('\n', mend) | ||||
yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] | ||||
begin = lend + 1 | ||||
|
r1057 | |||
|
r1559 | class linestate(object): | ||
|
r1057 | def __init__(self, line, linenum, colstart, colend): | ||
self.line = line | ||||
self.linenum = linenum | ||||
self.colstart = colstart | ||||
self.colend = colend | ||||
|
r2869 | |||
|
r1065 | def __eq__(self, other): | ||
return self.line == other.line | ||||
|
r1057 | |||
matches = {} | ||||
|
r2870 | copies = {} | ||
|
r1057 | def grepbody(fn, rev, body): | ||
|
r2869 | matches[rev].setdefault(fn, []) | ||
|
r1057 | m = matches[rev][fn] | ||
for lnum, cstart, cend, line in matchlines(body): | ||||
s = linestate(line, lnum, cstart, cend) | ||||
|
r2869 | m.append(s) | ||
def difflinestates(a, b): | ||||
sm = difflib.SequenceMatcher(None, a, b) | ||||
for tag, alo, ahi, blo, bhi in sm.get_opcodes(): | ||||
if tag == 'insert': | ||||
|
r3472 | for i in xrange(blo, bhi): | ||
|
r2869 | yield ('+', b[i]) | ||
elif tag == 'delete': | ||||
|
r3472 | for i in xrange(alo, ahi): | ||
|
r2869 | yield ('-', a[i]) | ||
elif tag == 'replace': | ||||
|
r3472 | for i in xrange(alo, ahi): | ||
|
r2869 | yield ('-', a[i]) | ||
|
r3472 | for i in xrange(blo, bhi): | ||
|
r2869 | yield ('+', b[i]) | ||
|
r1057 | prev = {} | ||
def display(fn, rev, states, prevstates): | ||||
|
r3951 | found = False | ||
|
r1146 | filerevmatches = {} | ||
|
r3951 | r = prev.get(fn, -1) | ||
if opts['all']: | ||||
iter = difflinestates(states, prevstates) | ||||
|
r2869 | else: | ||
|
r3951 | iter = [('', l) for l in prevstates] | ||
for change, l in iter: | ||||
|
r2869 | cols = [fn, str(r)] | ||
|
r1615 | if opts['line_number']: | ||
cols.append(str(l.linenum)) | ||||
if opts['all']: | ||||
cols.append(change) | ||||
if opts['user']: | ||||
|
r3650 | cols.append(ui.shortuser(get(r)[1])) | ||
|
r1146 | if opts['files_with_matches']: | ||
|
r3523 | c = (fn, r) | ||
|
r1615 | if c in filerevmatches: | ||
continue | ||||
|
r1146 | filerevmatches[c] = 1 | ||
else: | ||||
cols.append(l.line) | ||||
ui.write(sep.join(cols), eol) | ||||
|
r3951 | found = True | ||
return found | ||||
|
r1057 | |||
fstate = {} | ||||
|
r1145 | skip = {} | ||
|
r3673 | get = util.cachefunc(lambda r: repo.changectx(r).changeset()) | ||
|
r3650 | changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts) | ||
|
r3951 | found = False | ||
|
r2870 | follow = opts.get('follow') | ||
|
r1146 | for st, rev, fns in changeiter: | ||
|
r1057 | if st == 'window': | ||
matches.clear() | ||||
elif st == 'add': | ||||
|
r3530 | mf = repo.changectx(rev).manifest() | ||
|
r1057 | matches[rev] = {} | ||
for fn in fns: | ||||
|
r1615 | if fn in skip: | ||
continue | ||||
|
r1057 | try: | ||
grepbody(fn, rev, getfile(fn).read(mf[fn])) | ||||
|
r5105 | fstate.setdefault(fn, []) | ||
|
r2870 | if follow: | ||
copied = getfile(fn).renamed(mf[fn]) | ||||
if copied: | ||||
|
r2931 | copies.setdefault(rev, {})[fn] = copied[0] | ||
|
r1057 | except KeyError: | ||
pass | ||||
elif st == 'iter': | ||||
states = matches[rev].items() | ||||
states.sort() | ||||
for fn, m in states: | ||||
|
r2931 | copy = copies.get(rev, {}).get(fn) | ||
|
r1615 | if fn in skip: | ||
|
r2870 | if copy: | ||
skip[copy] = True | ||||
|
r1615 | continue | ||
|
r3951 | if fn in prev or fstate[fn]: | ||
r = display(fn, rev, m, fstate[fn]) | ||||
found = found or r | ||||
if r and not opts['all']: | ||||
|
r1145 | skip[fn] = True | ||
|
r2870 | if copy: | ||
skip[copy] = True | ||||
|
r1057 | fstate[fn] = m | ||
|
r2870 | if copy: | ||
fstate[copy] = m | ||||
|
r1057 | prev[fn] = rev | ||
|
r3950 | fstate = fstate.items() | ||
fstate.sort() | ||||
for fn, state in fstate: | ||||
if fn in skip: | ||||
continue | ||||
if fn not in copies.get(prev[fn], {}): | ||||
|
r3951 | found = display(fn, rev, {}, state) or found | ||
return (not found and 1) or 0 | ||||
|
r1057 | |||
|
r4648 | def heads(ui, repo, *branchrevs, **opts): | ||
"""show current repository heads or show branch heads | ||||
With no arguments, show all repository head changesets. | ||||
If branch or revisions names are given this will show the heads of | ||||
the specified branches or the branches those revisions are tagged | ||||
with. | ||||
Repository "heads" are changesets that don't have child | ||||
|
r1437 | changesets. They are where development generally takes place and | ||
are the usual targets for update and merge operations. | ||||
|
r4648 | |||
Branch heads are changesets that have a given branch tag, but have | ||||
no child changesets with that tag. They are usually where | ||||
development on the given branch takes place. | ||||
|
r1437 | """ | ||
|
r1550 | if opts['rev']: | ||
|
r4648 | start = repo.lookup(opts['rev']) | ||
else: | ||||
start = None | ||||
if not branchrevs: | ||||
# Assume we're looking repo-wide heads if no revs were specified. | ||||
heads = repo.heads(start) | ||||
|
r1550 | else: | ||
|
r4648 | heads = [] | ||
|
r4649 | visitedset = util.set() | ||
|
r4648 | for branchrev in branchrevs: | ||
branch = repo.changectx(branchrev).branch() | ||||
if branch in visitedset: | ||||
continue | ||||
visitedset.add(branch) | ||||
bheads = repo.branchheads(branch, start) | ||||
if not bheads: | ||||
if branch != branchrev: | ||||
ui.warn(_("no changes on branch %s containing %s are " | ||||
"reachable from %s\n") | ||||
% (branch, branchrev, opts['rev'])) | ||||
else: | ||||
ui.warn(_("no changes on branch %s are reachable from %s\n") | ||||
% (branch, opts['rev'])) | ||||
heads.extend(bheads) | ||||
if not heads: | ||||
return 1 | ||||
|
r3643 | displayer = cmdutil.show_changeset(ui, repo, opts) | ||
|
r1550 | for n in heads: | ||
|
r3649 | displayer.show(changenode=n) | ||
|
r221 | |||
|
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 = [] | ||||
|
r4315 | def addglobalopts(aliases): | ||
if ui.verbose: | ||||
option_lists.append((_("global options:"), globalopts)) | ||||
if name == 'shortlist': | ||||
option_lists.append((_('use "hg help" for the full list ' | ||||
'of commands'), ())) | ||||
else: | ||||
if name == 'shortlist': | ||||
msg = _('use "hg help" for the full list of commands ' | ||||
'or "hg -v" for details') | ||||
elif aliases: | ||||
msg = _('use "hg -v help%s" to show aliases and ' | ||||
'global options') % (name and " " + name or "") | ||||
else: | ||||
msg = _('use "hg -v help %s" to show global options') % name | ||||
option_lists.append((msg, ())) | ||||
|
r3655 | def helpcmd(name): | ||
if with_version: | ||||
version_(ui) | ||||
ui.write('\n') | ||||
|
r5178 | aliases, i = cmdutil.findcmd(ui, name, table) | ||
|
r3655 | # 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]: | ||||
|
r4315 | option_lists.append((_("options:\n"), i[1])) | ||
addglobalopts(False) | ||||
|
r3655 | |||
|
r4950 | def helplist(header, select=None): | ||
|
r3655 | 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("^") | ||||
|
r4950 | if not h: | ||
ui.status(_('no commands defined\n')) | ||||
return | ||||
ui.status(header) | ||||
|
r3655 | 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])) | ||||
|
r4315 | if not ui.quiet: | ||
addglobalopts(True) | ||||
|
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: | ||||
|
r4549 | raise cmdutil.UnknownCommand(name) | ||
|
r3795 | |||
# description | ||||
doc = help.helptable[v] | ||||
if not doc: | ||||
doc = _("(No help text available)") | ||||
|
r3796 | if callable(doc): | ||
doc = doc() | ||||
|
r3795 | |||
ui.write("%s\n" % header) | ||||
ui.write("%s\n" % doc.rstrip()) | ||||
|
r3655 | def helpext(name): | ||
try: | ||||
|
r4544 | mod = extensions.find(name) | ||
|
r3655 | except KeyError: | ||
|
r4549 | raise cmdutil.UnknownCommand(name) | ||
|
r3655 | |||
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') | ||||
|
r4009 | |||
try: | ||||
ct = mod.cmdtable | ||||
except AttributeError: | ||||
|
r4950 | ct = {} | ||
|
r4009 | modcmds = dict.fromkeys([c.split('|', 1)[0] for c in ct]) | ||
|
r4950 | helplist(_('list of commands:\n\n'), modcmds.has_key) | ||
|
r3655 | |||
if name and name != 'shortlist': | ||||
|
r3795 | i = None | ||
for f in (helpcmd, helptopic, helpext): | ||||
try: | ||||
f(name) | ||||
i = None | ||||
break | ||||
|
r4549 | except cmdutil.UnknownCommand, inst: | ||
|
r3795 | i = inst | ||
if i: | ||||
raise i | ||||
|
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": | ||||
|
r4950 | header = _('basic commands:\n\n') | ||
|
r4315 | else: | ||
|
r4950 | header = _('list of commands:\n\n') | ||
helplist(header) | ||||
|
r3655 | |||
# list all option lists | ||||
opt_output = [] | ||||
for title, options in option_lists: | ||||
|
r4315 | opt_output.append(("\n%s" % title, None)) | ||
|
r3655 | 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: | ||||
|
r4315 | opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0]) | ||
|
r3655 | for first, second in opt_output: | ||
if second: | ||||
ui.write(" %-*s %s\n" % (opts_len, first, second)) | ||||
else: | ||||
ui.write("%s\n" % first) | ||||
|
r221 | |||
|
r4671 | def identify(ui, repo, source=None, | ||
rev=None, num=None, id=None, branch=None, tags=None): | ||||
|
r4665 | """identify the working copy or specified revision | ||
|
r4671 | With no revision, print a summary of the current state of the repo. | ||
With a path, do a lookup in another repository. | ||||
|
r1437 | |||
This summary identifies the repository state using one or two parent | ||||
hash identifiers, followed by a "+" if there are uncommitted changes | ||||
|
r4665 | in the working directory, a list of tags for this revision and a branch | ||
name for non-default branches. | ||||
|
r1437 | """ | ||
|
r4662 | |||
|
r5330 | if not repo and not source: | ||
raise util.Abort(_("There is no Mercurial repository here " | ||||
"(.hg not found)")) | ||||
|
r2966 | hexfunc = ui.debugflag and hex or short | ||
|
r4666 | default = not (num or id or branch or tags) | ||
output = [] | ||||
|
r4664 | |||
|
r4671 | if source: | ||
|
r5248 | source, revs, checkout = hg.parseurl(ui.expandpath(source), []) | ||
|
r4671 | srepo = hg.repository(ui, source) | ||
if not rev and revs: | ||||
rev = revs[0] | ||||
|
r4667 | if not rev: | ||
rev = "tip" | ||||
if num or branch or tags: | ||||
raise util.Abort( | ||||
"can't query remote revision number, branch, or tags") | ||||
|
r4671 | output = [hexfunc(srepo.lookup(rev))] | ||
|
r4667 | elif not rev: | ||
|
r4665 | ctx = repo.workingctx() | ||
parents = ctx.parents() | ||||
|
r4666 | changed = False | ||
if default or id or num: | ||||
changed = ctx.files() + ctx.deleted() | ||||
if default or id: | ||||
output = ["%s%s" % ('+'.join([hexfunc(p.node()) for p in parents]), | ||||
(changed) and "+" or "")] | ||||
if num: | ||||
output.append("%s%s" % ('+'.join([str(p.rev()) for p in parents]), | ||||
(changed) and "+" or "")) | ||||
|
r4665 | else: | ||
ctx = repo.changectx(rev) | ||||
|
r4666 | if default or id: | ||
output = [hexfunc(ctx.node())] | ||||
if num: | ||||
output.append(str(ctx.rev())) | ||||
|
r4671 | if not source and default and not ui.quiet: | ||
|
r4666 | b = util.tolocal(ctx.branch()) | ||
if b != 'default': | ||||
output.append("(%s)" % b) | ||||
|
r3415 | |||
|
r386 | # multiple tags for a single parent separated by '/' | ||
|
r4666 | t = "/".join(ctx.tags()) | ||
if t: | ||||
output.append(t) | ||||
if branch: | ||||
output.append(util.tolocal(ctx.branch())) | ||||
if tags: | ||||
output.extend(ctx.tags()) | ||||
|
r339 | |||
|
r386 | ui.write("%s\n" % ' '.join(output)) | ||
|
r339 | |||
|
r437 | def import_(ui, repo, patch1, *patches, **opts): | ||
|
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. | ||||
|
r2504 | You can import a patch straight from a mail message. Even patches | ||
as attachments work (body part must be type text/plain or | ||||
|
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. | ||||
|
r2504 | |||
|
r4263 | If the imported patch was generated by hg export, user and description | ||
|
r2504 | from patch override values from message headers and body. Values | ||
given on command line with -m and -u override these. | ||||
|
r2400 | |||
|
r4263 | If --exact is specified, import will set the working directory | ||
to the parent of each patch before applying it, and will abort | ||||
if the resulting changeset has a different ID than the one | ||||
recorded in the patch. This may happen due to character set | ||||
problems or other deficiencies in the text patch format. | ||||
|
r2400 | To read a patch from standard input, use patch name "-". | ||
|
r1437 | """ | ||
|
r437 | patches = (patch1,) + patches | ||
|
r500 | |||
|
r4263 | if opts.get('exact') or not opts['force']: | ||
|
r4549 | cmdutil.bail_if_changed(repo) | ||
|
r966 | |||
|
r437 | d = opts["base"] | ||
strip = opts["strip"] | ||||
|
r4915 | wlock = lock = None | ||
try: | ||||
wlock = repo.wlock() | ||||
lock = repo.lock() | ||||
for p in patches: | ||||
pf = os.path.join(d, p) | ||||
if pf == '-': | ||||
ui.status(_("applying patch from stdin\n")) | ||||
data = patch.extract(ui, sys.stdin) | ||||
|
r2400 | else: | ||
|
r4915 | ui.status(_("applying %s\n") % p) | ||
|
r5205 | if os.path.exists(pf): | ||
data = patch.extract(ui, file(pf, 'rb')) | ||||
else: | ||||
data = patch.extract(ui, urllib.urlopen(pf)) | ||||
|
r4915 | tmpname, message, user, date, branch, nodeid, p1, p2 = data | ||
if tmpname is None: | ||||
raise util.Abort(_('no diffs found')) | ||||
try: | ||||
cmdline_message = cmdutil.logmessage(opts) | ||||
if cmdline_message: | ||||
# pickup the cmdline msg | ||||
message = cmdline_message | ||||
elif message: | ||||
# pickup the patch msg | ||||
message = message.strip() | ||||
else: | ||||
# launch the editor | ||||
message = None | ||||
ui.debug(_('message:\n%s\n') % message) | ||||
wp = repo.workingctx().parents() | ||||
if opts.get('exact'): | ||||
if not nodeid or not p1: | ||||
raise util.Abort(_('not a mercurial patch')) | ||||
|
r4264 | p1 = repo.lookup(p1) | ||
|
r4915 | p2 = repo.lookup(p2 or hex(nullid)) | ||
if p1 != wp[0].node(): | ||||
|
r4917 | hg.clean(repo, p1) | ||
|
r4915 | repo.dirstate.setparents(p1, p2) | ||
elif p2: | ||||
try: | ||||
p1 = repo.lookup(p1) | ||||
p2 = repo.lookup(p2) | ||||
if p1 == wp[0].node(): | ||||
repo.dirstate.setparents(p1, p2) | ||||
except hg.RepoError: | ||||
pass | ||||
if opts.get('exact') or opts.get('import_branch'): | ||||
repo.dirstate.setbranch(branch or 'default') | ||||
files = {} | ||||
try: | ||||
fuzz = patch.patch(tmpname, ui, strip=strip, cwd=repo.root, | ||||
files=files) | ||||
finally: | ||||
|
r4917 | files = patch.updatedir(ui, repo, files) | ||
n = repo.commit(files, message, user, date) | ||||
|
r4915 | if opts.get('exact'): | ||
if hex(n) != nodeid: | ||||
|
r4917 | repo.rollback() | ||
|
r4915 | raise util.Abort(_('patch is damaged' + | ||
' or loses information')) | ||||
|
r3465 | finally: | ||
|
r4915 | os.unlink(tmpname) | ||
finally: | ||||
|
r5053 | del lock, wlock | ||
|
r437 | |||
|
r1192 | def incoming(ui, repo, source="default", **opts): | ||
|
r1437 | """show new changesets found in source | ||
|
r1979 | Show new changesets found in the specified path/URL or the default | ||
pull location. These are the changesets that would be pulled if a pull | ||||
|
r1437 | was requested. | ||
|
r1944 | For remote repository, using --bundle avoids downloading the changesets | ||
twice if the incoming is followed by a pull. | ||||
|
r1979 | |||
See pull for valid source format details. | ||||
|
r1437 | """ | ||
|
r5248 | source, revs, checkout = hg.parseurl(ui.expandpath(source), opts['rev']) | ||
|
r4549 | cmdutil.setremoteconfig(ui, opts) | ||
|
r1965 | |||
|
r927 | other = hg.repository(ui, source) | ||
|
r4162 | ui.status(_('comparing with %s\n') % source) | ||
|
r4478 | if revs: | ||
|
r5259 | revs = [other.lookup(rev) for rev in revs] | ||
|
r4451 | incoming = repo.findincoming(other, heads=revs, force=opts["force"]) | ||
|
r1944 | if not incoming: | ||
|
r3933 | try: | ||
os.unlink(opts["bundle"]) | ||||
except: | ||||
pass | ||||
|
r1993 | ui.status(_("no changes found\n")) | ||
|
r3931 | return 1 | ||
|
r1944 | |||
cleanup = None | ||||
|
r1974 | try: | ||
fname = opts["bundle"] | ||||
if fname or not other.local(): | ||||
# create a bundle (uncompressed if other repo is not local) | ||||
|
r4451 | if revs is None: | ||
cg = other.changegroup(incoming, "incoming") | ||||
else: | ||||
cg = other.changegroupsubset(incoming, revs, 'incoming') | ||||
|
r3706 | bundletype = other.local() and "HG10BZ" or "HG10UN" | ||
fname = cleanup = changegroup.writebundle(cg, fname, bundletype) | ||||
|
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) | ||||
|
r2521 | o = other.changelog.nodesbetween(incoming, revs)[0] | ||
|
r1974 | if opts['newest_first']: | ||
o.reverse() | ||||
|
r3643 | displayer = cmdutil.show_changeset(ui, other, opts) | ||
|
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) | ||||
|
r1944 | |||
|
r2598 | def init(ui, dest=".", **opts): | ||
|
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. | ||||
|
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. | ||||
|
r1437 | """ | ||
|
r4549 | cmdutil.setremoteconfig(ui, opts) | ||
|
r907 | hg.repository(ui, dest, create=1) | ||
|
r338 | |||
|
r627 | def locate(ui, repo, *pats, **opts): | ||
|
r1437 | """locate files matching specific patterns | ||
Print all files under Mercurial control whose names match the | ||||
given patterns. | ||||
|
r4195 | This command searches the entire repository by default. To search | ||
|
r4692 | just the current directory and its subdirectories, use | ||
"--include .". | ||||
|
r1437 | |||
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. | ||||
""" | ||||
|
r1065 | end = opts['print0'] and '\0' or '\n' | ||
|
r1622 | rev = opts['rev'] | ||
if rev: | ||||
node = repo.lookup(rev) | ||||
else: | ||||
node = None | ||||
|
r742 | |||
|
r4196 | ret = 1 | ||
|
r2882 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node, | ||
|
r4308 | badmatch=util.always, | ||
|
r4195 | default='relglob'): | ||
|
r4308 | if src == 'b': | ||
continue | ||||
|
r4906 | if not node and abs not in repo.dirstate: | ||
|
r1065 | continue | ||
|
r697 | if opts['fullpath']: | ||
|
r724 | ui.write(os.path.join(repo.root, abs), end) | ||
else: | ||||
|
r1625 | ui.write(((pats and rel) or abs), end) | ||
|
r4196 | ret = 0 | ||
return ret | ||||
|
r627 | |||
|
r1031 | def log(ui, repo, *pats, **opts): | ||
|
r1437 | """show revision history of entire repository or files | ||
|
r2741 | Print the revision history of the specified files or the entire | ||
project. | ||||
File history is shown without following rename or copy history of | ||||
|
r2782 | files. Use -f/--follow with a file name to follow history across | ||
renames and copies. --follow without a file name will only show | ||||
|
r2784 | ancestors or descendants of the starting revision. --follow-first | ||
only follows the first parent of merge revisions. | ||||
|
r1437 | |||
|
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. | ||||
|
r1437 | By default this command outputs: changeset id and hash, tags, | ||
|
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. | ||||
|
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. | ||||
|
r1437 | """ | ||
|
r1756 | |||
|
r3673 | get = util.cachefunc(lambda r: repo.changectx(r).changeset()) | ||
|
r3650 | changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts) | ||
|
r3518 | |||
|
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 | ||||
|
r3197 | if opts['copies'] and opts['rev']: | ||
|
r3707 | endrev = max(cmdutil.revrange(repo, opts['rev'])) + 1 | ||
|
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] | ||||
|
r3386 | mr = repo.manifest.rev(man) | ||
|
r3578 | if repo.manifest.parentrevs(mr) != (mr - 1, nullrev): | ||
|
r3384 | return ncache[fn].get(repo.manifest.find(man, fn)[0]) | ||
|
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 | ||||
|
r3813 | df = False | ||
if opts["date"]: | ||||
df = util.matchdate(opts["date"]) | ||||
|
r3837 | displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn) | ||
|
r1146 | for st, rev, fns in changeiter: | ||
|
r3645 | if st == 'add': | ||
|
r1435 | changenode = repo.changelog.node(rev) | ||
|
r3578 | parents = [p for p in repo.changelog.parentrevs(rev) | ||
if p != nullrev] | ||||
|
r1435 | if opts['no_merges'] and len(parents) == 2: | ||
|
r1615 | continue | ||
|
r1436 | if opts['only_merges'] and len(parents) != 2: | ||
|
r1615 | continue | ||
|
r1435 | |||
|
r3813 | if df: | ||
changes = get(rev) | ||||
if not df(changes[2][0]): | ||||
continue | ||||
|
r1373 | if opts['keyword']: | ||
|
r3650 | changes = get(rev) | ||
|
r1373 | miss = 0 | ||
|
r1404 | for k in [kw.lower() for kw in opts['keyword']]: | ||
|
r1373 | if not (k in changes[1].lower() or | ||
k in changes[4].lower() or | ||||
|
r4322 | k in " ".join(changes[3]).lower()): | ||
|
r1373 | miss = 1 | ||
break | ||||
if miss: | ||||
continue | ||||
|
r3197 | copies = [] | ||
if opts.get('copies') and rev: | ||||
|
r3650 | mf = get(rev)[0] | ||
for fn in get(rev)[3]: | ||||
|
r3197 | rename = getrenamed(fn, rev, mf) | ||
if rename: | ||||
copies.append((fn, rename[0])) | ||||
|
r3649 | displayer.show(rev, changenode, copies=copies) | ||
|
r1057 | elif st == 'iter': | ||
|
r1756 | if count == limit: break | ||
|
r3645 | if displayer.flush(rev): | ||
|
r1765 | count += 1 | ||
|
r255 | |||
|
r5155 | def manifest(ui, repo, node=None, rev=None): | ||
|
r3914 | """output the current or given revision of the project manifest | ||
|
r1437 | |||
Print a list of version controlled files for the given revision. | ||||
|
r3915 | If no revision is given, the parent of the working directory is used, | ||
or tip if no revision is checked out. | ||||
|
r1437 | |||
The manifest is the list of files being version controlled. If no revision | ||||
|
r3736 | is given then the first parent of the working directory is used. | ||
|
r5405 | With -v flag, print file permissions, symlink and executable bits. With | ||
--debug flag, print file revision hashes. | ||||
|
r1437 | """ | ||
|
r3736 | |||
|
r5155 | if rev and node: | ||
raise util.Abort(_("please specify just one revision")) | ||||
if not node: | ||||
node = rev | ||||
m = repo.changectx(node).manifest() | ||||
|
r255 | files = m.keys() | ||
files.sort() | ||||
for f in files: | ||||
|
r3736 | if ui.debugflag: | ||
ui.write("%40s " % hex(m[f])) | ||||
if ui.verbose: | ||||
|
r5405 | type = m.execf(f) and "*" or m.linkf(f) and "@" or " " | ||
perm = m.execf(f) and "755" or "644" | ||||
ui.write("%3s %1s " % (perm, type)) | ||||
|
r3736 | ui.write("%s\n" % f) | ||
|
r255 | |||
|
r4450 | def merge(ui, repo, node=None, force=None, rev=None): | ||
|
r4014 | """merge working directory with another revision | ||
|
r2019 | |||
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. | ||||
|
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. | ||||
|
r2019 | """ | ||
|
r2806 | |||
|
r4450 | if rev and node: | ||
raise util.Abort(_("please specify just one revision")) | ||||
if not node: | ||||
node = rev | ||||
|
r3876 | if not node: | ||
|
r2915 | heads = repo.heads() | ||
if len(heads) > 2: | ||||
raise util.Abort(_('repo has %d heads - ' | ||||
'please merge with an explicit rev') % | ||||
len(heads)) | ||||
|
r5242 | parent = repo.dirstate.parents()[0] | ||
|
r2915 | if len(heads) == 1: | ||
|
r5242 | msg = _('there is nothing to merge') | ||
if parent != repo.lookup(repo.workingctx().branch()): | ||||
msg = _('%s - use "hg update" instead' % msg) | ||||
raise util.Abort(msg) | ||||
|
r2915 | 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] | ||||
|
r2808 | return hg.merge(repo, node, force=force) | ||
|
r2029 | |||
|
r2494 | def outgoing(ui, repo, dest=None, **opts): | ||
|
r1437 | """show changesets not found in destination | ||
|
r1979 | Show changesets not found in the specified destination repository or | ||
the default push location. These are the changesets that would be pushed | ||||
|
r1437 | if a push was requested. | ||
|
r1811 | |||
|
r1979 | See pull for valid destination format details. | ||
|
r1437 | """ | ||
|
r5248 | dest, revs, checkout = hg.parseurl( | ||
|
r4478 | ui.expandpath(dest or 'default-push', dest or 'default'), opts['rev']) | ||
|
r4549 | cmdutil.setremoteconfig(ui, opts) | ||
|
r4478 | if revs: | ||
revs = [repo.lookup(rev) for rev in revs] | ||||
|
r1965 | |||
|
r920 | other = hg.repository(ui, dest) | ||
|
r4162 | ui.status(_('comparing with %s\n') % dest) | ||
|
r1959 | o = repo.findoutgoing(other, force=opts['force']) | ||
|
r1994 | if not o: | ||
ui.status(_("no changes found\n")) | ||||
|
r3931 | return 1 | ||
|
r2521 | o = repo.changelog.nodesbetween(o, revs)[0] | ||
|
r1439 | if opts['newest_first']: | ||
o.reverse() | ||||
|
r3643 | displayer = cmdutil.show_changeset(ui, repo, opts) | ||
|
r920 | for n in o: | ||
|
r1435 | parents = [p for p in repo.changelog.parents(n) if p != nullid] | ||
if opts['no_merges'] and len(parents) == 2: | ||||
continue | ||||
|
r1907 | displayer.show(changenode=n) | ||
|
r920 | |||
|
r3658 | def parents(ui, repo, file_=None, **opts): | ||
|
r1437 | """show the parents of the working dir or revision | ||
|
r4586 | Print the working directory's parent revisions. If a | ||
revision is given via --rev, the parent of that revision | ||||
will be printed. If a file argument is given, revision in | ||||
which the file was last changed (before the working directory | ||||
revision or the argument to --rev if given) is printed. | ||||
|
r1437 | """ | ||
|
r3658 | rev = opts.get('rev') | ||
|
r5298 | if rev: | ||
ctx = repo.changectx(rev) | ||||
else: | ||||
ctx = repo.workingctx() | ||||
|
r4586 | if file_: | ||
|
r4894 | files, match, anypats = cmdutil.matchpats(repo, (file_,), opts) | ||
if anypats or len(files) != 1: | ||||
raise util.Abort(_('can only specify an explicit file name')) | ||||
|
r5298 | file_ = files[0] | ||
filenodes = [] | ||||
for cp in ctx.parents(): | ||||
if not cp: | ||||
continue | ||||
try: | ||||
filenodes.append(cp.filenode(file_)) | ||||
except revlog.LookupError: | ||||
pass | ||||
if not filenodes: | ||||
raise util.Abort(_("'%s' not found in manifest!") % file_) | ||||
fl = repo.file(file_) | ||||
p = [repo.lookup(fl.linkrev(fn)) for fn in filenodes] | ||||
|
r255 | else: | ||
|
r5298 | p = [cp.node() for cp in ctx.parents()] | ||
|
r255 | |||
|
r3643 | displayer = cmdutil.show_changeset(ui, repo, opts) | ||
|
r255 | for n in p: | ||
|
r1092 | if n != nullid: | ||
|
r3649 | displayer.show(changenode=n) | ||
|
r255 | |||
|
r1858 | def paths(ui, repo, search=None): | ||
|
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. | ||||
""" | ||||
|
r779 | if search: | ||
for name, path in ui.configitems("paths"): | ||||
if name == search: | ||||
ui.write("%s\n" % path) | ||||
return | ||||
|
r1402 | ui.warn(_("not found!\n")) | ||
|
r779 | return 1 | ||
else: | ||||
for name, path in ui.configitems("paths"): | ||||
ui.write("%s = %s\n" % (name, path)) | ||||
|
r5224 | def postincoming(ui, repo, modheads, optupdate, checkout): | ||
|
r2019 | if modheads == 0: | ||
return | ||||
if optupdate: | ||||
|
r5224 | if modheads <= 1 or checkout: | ||
return hg.update(repo, checkout) | ||||
|
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")) | ||||
|
r2029 | |||
|
r404 | def pull(ui, repo, source="default", **opts): | ||
|
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: | ||||
|
r3563 | local/filesystem/path (or file://local/filesystem/path) | ||
|
r2589 | http://[user@]host[:port]/[path] | ||
https://[user@]host[:port]/[path] | ||||
ssh://[user@]host[:port]/[path] | ||||
|
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. | ||||
|
r1437 | |||
|
r4478 | An optional identifier after # indicates a particular branch, tag, | ||
or changeset to pull. | ||||
|
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. | ||||
|
r2589 | - path is relative to the remote user's home directory by default. | ||
|
r2590 | Use an extra slash at the start of a path to specify an absolute path: | ||
ssh://example.com//tmp/repository | ||||
|
r1979 | - Mercurial doesn't use its own compression via SSH; the right thing | ||
|
r3471 | to do is to configure it in your ~/.ssh/config, e.g.: | ||
|
r1979 | Host *.mylocalnetwork.example.com | ||
|
r3471 | Compression no | ||
|
r1979 | Host * | ||
|
r3471 | Compression yes | ||
|
r1979 | Alternatively specify "ssh -C" as your ssh command in your hgrc or | ||
with the --ssh command line option. | ||||
|
r1437 | """ | ||
|
r5248 | source, revs, checkout = hg.parseurl(ui.expandpath(source), opts['rev']) | ||
|
r4549 | cmdutil.setremoteconfig(ui, opts) | ||
|
r963 | |||
|
r246 | other = hg.repository(ui, source) | ||
|
r2473 | ui.status(_('pulling from %s\n') % (source)) | ||
|
r4478 | if revs: | ||
|
r5259 | try: | ||
|
r4478 | revs = [other.lookup(rev) for rev in revs] | ||
|
r5259 | except repo.NoCapability: | ||
error = _("Other repository doesn't support revision lookup, " | ||||
"so a rev cannot be specified.") | ||||
|
r3448 | raise util.Abort(error) | ||
|
r4478 | |||
|
r2019 | modheads = repo.pull(other, heads=revs, force=opts['force']) | ||
|
r5224 | return postincoming(ui, repo, modheads, opts['update'], checkout) | ||
|
r246 | |||
|
r2494 | def push(ui, repo, dest=None, **opts): | ||
|
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: | ||||
|
r3563 | local/filesystem/path (or file://local/filesystem/path) | ||
|
r2589 | ssh://[user@]host[:port]/[path] | ||
|
r3563 | http://[user@]host[:port]/[path] | ||
https://[user@]host[:port]/[path] | ||||
|
r1437 | |||
|
r4478 | An optional identifier after # indicates a particular branch, tag, | ||
or changeset to push. | ||||
|
r1979 | Look at the help text for the pull command for important details | ||
about ssh:// URLs. | ||||
|
r2590 | |||
|
r3563 | Pushing to http:// and https:// URLs is only possible, if this | ||
feature is explicitly enabled on the remote Mercurial server. | ||||
|
r1437 | """ | ||
|
r5248 | dest, revs, checkout = hg.parseurl( | ||
|
r4478 | ui.expandpath(dest or 'default-push', dest or 'default'), opts['rev']) | ||
|
r4549 | cmdutil.setremoteconfig(ui, opts) | ||
|
r961 | |||
|
r640 | other = hg.repository(ui, dest) | ||
|
r2473 | ui.status('pushing to %s\n' % (dest)) | ||
|
r4478 | if revs: | ||
revs = [repo.lookup(rev) for rev in revs] | ||||
|
r1781 | r = repo.push(other, opts['force'], revs=revs) | ||
|
r2019 | return r == 0 | ||
|
r319 | |||
|
r3653 | def rawcommit(ui, repo, *pats, **opts): | ||
|
r1812 | """raw commit interface (DEPRECATED) | ||
|
r1811 | |||
(DEPRECATED) | ||||
|
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. | ||||
|
r1657 | |||
This command is now deprecated and will be removed in a future | ||||
release, please use debugsetparents and commit instead. | ||||
|
r1437 | """ | ||
|
r1657 | |||
ui.warn(_("(the rawcommit command is deprecated)\n")) | ||||
|
r4549 | message = cmdutil.logmessage(opts) | ||
|
r3653 | |||
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']] | ||||
|
r500 | |||
|
r1202 | try: | ||
|
r3659 | repo.rawcommit(files, message, opts['user'], opts['date'], *parents) | ||
|
r1202 | except ValueError, inst: | ||
raise util.Abort(str(inst)) | ||||
|
r500 | |||
|
r245 | def recover(ui, repo): | ||
|
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. | ||||
""" | ||||
|
r1516 | if repo.recover(): | ||
|
r2778 | return hg.verify(repo) | ||
|
r2057 | return 1 | ||
|
r245 | |||
|
r2179 | def remove(ui, repo, *pats, **opts): | ||
|
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 | ||||
|
r2179 | directory, they will be deleted from it. If invoked with --after, | ||
|
r4392 | files are marked as removed, but not actually unlinked unless --force | ||
|
r4394 | is also given. Without exact file names, --after will only mark | ||
|
r4393 | files as removed if they are no longer in the working directory. | ||
|
r2309 | |||
|
r3829 | This command schedules the files to be removed at the next commit. | ||
To undo a remove before that, see hg revert. | ||||
|
r2309 | Modified files and added files are not removed by default. To | ||
remove them, use the -f/--force option. | ||||
|
r1437 | """ | ||
|
r2179 | if not opts['after'] and not pats: | ||
raise util.Abort(_('no files specified')) | ||||
|
r2882 | files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) | ||
|
r2309 | exact = dict.fromkeys(files) | ||
|
r2875 | mardu = map(dict.fromkeys, repo.status(files=files, match=matchfn))[:5] | ||
|
r2309 | modified, added, removed, deleted, unknown = mardu | ||
remove, forget = [], [] | ||||
|
r2882 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts): | ||
|
r1189 | reason = None | ||
|
r4392 | if abs in modified and not opts['force']: | ||
|
r2309 | 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)') | ||||
|
r4906 | elif abs not in repo.dirstate: | ||
|
r1615 | reason = _('is not managed') | ||
|
r4394 | elif opts['after'] and not exact and abs not in deleted: | ||
|
r4393 | continue | ||
|
r2309 | elif abs in removed: | ||
continue | ||||
|
r1255 | if reason: | ||
|
r1615 | if exact: | ||
ui.warn(_('not removing %s: file %s\n') % (rel, reason)) | ||||
|
r1189 | else: | ||
|
r1615 | if ui.verbose or not exact: | ||
ui.status(_('removing %s\n') % rel) | ||||
|
r2309 | remove.append(abs) | ||
repo.forget(forget) | ||||
|
r4392 | repo.remove(remove, unlink=opts['force'] or not opts['after']) | ||
|
r245 | |||
|
r1253 | def rename(ui, repo, *pats, **opts): | ||
|
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. | ||||
|
r3829 | This command takes effect in the next commit. To undo a rename | ||
before that, see hg revert. | ||||
|
r1437 | """ | ||
|
r4914 | wlock = repo.wlock(False) | ||
|
r4915 | try: | ||
|
r4917 | errs, copied = docopy(ui, repo, pats, opts) | ||
|
r4915 | names = [] | ||
for abs, rel, exact in copied: | ||||
if ui.verbose or not exact: | ||||
ui.status(_('removing %s\n') % rel) | ||||
names.append(abs) | ||||
if not opts.get('dry_run'): | ||||
|
r4917 | repo.remove(names, True) | ||
|
r4915 | return errs | ||
finally: | ||||
del wlock | ||||
|
r1253 | |||
|
r1472 | def revert(ui, repo, *pats, **opts): | ||
|
r2227 | """revert files or dirs to their states as of some revision | ||
|
r2204 | |||
|
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 | ||||
|
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. | ||||
|
r1811 | |||
|
r2036 | Modified files are saved with a .orig suffix before reverting. | ||
To disable these backups, use --no-backup. | ||||
|
r2029 | |||
|
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 | ||||
|
r1811 | back" some or all of a change that should not have been committed. | ||
Revert modifies the working directory. It does not commit any | ||||
|
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. | ||||
|
r1437 | |||
|
r4804 | If a file has been deleted, it is restored. If the executable | ||
|
r1437 | mode of a file was changed, it is reset. | ||
|
r1472 | If names are given, all files matching the names are reverted. | ||
|
r1437 | |||
|
r2982 | If no arguments are given, no files are reverted. | ||
|
r1437 | """ | ||
|
r2982 | |||
|
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"]) | ||||
|
r2982 | if not pats and not opts['all']: | ||
|
r3020 | raise util.Abort(_('no files or directories specified; ' | ||
'use --all to revert the whole repo')) | ||||
|
r2982 | |||
|
r2212 | parent, p2 = repo.dirstate.parents() | ||
|
r3132 | if not opts['rev'] and p2 != nullid: | ||
raise util.Abort(_('uncommitted merge - please provide a ' | ||||
'specific revision')) | ||||
|
r3972 | ctx = repo.changectx(opts['rev']) | ||
node = ctx.node() | ||||
mf = ctx.manifest() | ||||
|
r2407 | if node == parent: | ||
pmf = mf | ||||
else: | ||||
pmf = None | ||||
|
r2029 | |||
|
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. | ||||
|
r2029 | names = {} | ||
|
r2042 | target_only = {} | ||
|
r4915 | wlock = repo.wlock() | ||
try: | ||||
# walk dirstate. | ||||
for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, | ||||
badmatch=mf.has_key): | ||||
names[abs] = (rel, exact) | ||||
if src == 'b': | ||||
target_only[abs] = True | ||||
# walk target manifest. | ||||
def badmatch(path): | ||||
if path in names: | ||||
|
r4225 | return True | ||
|
r4915 | path_ = path + '/' | ||
for f in names: | ||||
if f.startswith(path_): | ||||
return True | ||||
return False | ||||
for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node, | ||||
badmatch=badmatch): | ||||
if abs in names or src == 'b': | ||||
continue | ||||
names[abs] = (rel, exact) | ||||
target_only[abs] = True | ||||
|
r4917 | changes = repo.status(match=names.has_key)[:5] | ||
|
r4915 | modified, added, removed, deleted, unknown = map(dict.fromkeys, changes) | ||
|
r5266 | # if f is a rename, also revert the source | ||
cwd = repo.getcwd() | ||||
for f in added: | ||||
src = repo.dirstate.copied(f) | ||||
if src and src not in names and repo.dirstate[src] == 'r': | ||||
removed[src] = None | ||||
names[src] = (repo.pathto(src, cwd), True) | ||||
|
r4915 | 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), | ||||
(added, revert, forget, True, False), | ||||
(removed, undelete, None, False, False), | ||||
(deleted, revert, remove, False, False), | ||||
(unknown, add, None, True, False), | ||||
(target_only, add, None, False, False), | ||||
) | ||||
entries = names.items() | ||||
entries.sort() | ||||
for abs, (rel, exact) in entries: | ||||
mfentry = mf.get(abs) | ||||
target = repo.wjoin(abs) | ||||
def handle(xlist, dobackup): | ||||
xlist[0].append(abs) | ||||
update[abs] = 1 | ||||
if dobackup and not opts['no_backup'] and util.lexists(target): | ||||
bakname = "%s.orig" % rel | ||||
ui.note(_('saving current version of %s as %s\n') % | ||||
(rel, bakname)) | ||||
if not opts.get('dry_run'): | ||||
util.copyfile(target, bakname) | ||||
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 | ||||
if mfentry: | ||||
handle(hitlist, backuphit) | ||||
elif misslist is not None: | ||||
handle(misslist, backupmiss) | ||||
else: | ||||
if exact: ui.warn(_('file not managed: %s\n') % rel) | ||||
break | ||||
|
r2029 | else: | ||
|
r4915 | # file has not changed in dirstate | ||
if node == parent: | ||||
if exact: ui.warn(_('no changes needed to %s\n') % rel) | ||||
continue | ||||
if pmf is None: | ||||
# only need parent manifest in this unlikely case, | ||||
# so do not read by default | ||||
pmf = repo.changectx(parent).manifest() | ||||
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: | ||||
handle(remove, False) | ||||
if not opts.get('dry_run'): | ||||
for f in forget[0]: | ||||
repo.dirstate.forget(f) | ||||
|
r4917 | r = hg.revert(repo, node, update.has_key) | ||
|
r4915 | for f in add[0]: | ||
repo.dirstate.add(f) | ||||
for f in undelete[0]: | ||||
repo.dirstate.normal(f) | ||||
for f in remove[0]: | ||||
repo.dirstate.remove(f) | ||||
return r | ||||
finally: | ||||
del wlock | ||||
|
r588 | |||
|
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 | ||||
|
r4681 | rollback, and there is no way to undo a rollback. It will also | ||
restore the dirstate at the time of the last transaction, which | ||||
may lose subsequent dirstate changes. | ||||
|
r2227 | |||
This command is not intended for use on public repositories. Once | ||||
changes are visible for pull by other users, rolling a transaction | ||||
back locally is ineffective (someone else may already have pulled | ||||
the changes). Furthermore, a race is possible with readers of the | ||||
repository; for example an in-progress pull from the repository | ||||
may fail if a rollback is performed. | ||||
""" | ||||
|
r2362 | repo.rollback() | ||
|
r2227 | |||
|
r468 | def root(ui, repo): | ||
|
r1437 | """print the root (top) of the current working dir | ||
Print the root directory of the current repository. | ||||
""" | ||||
|
r468 | ui.write(repo.root + "\n") | ||
|
r245 | def serve(ui, repo, **opts): | ||
|
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. | ||||
""" | ||||
|
r624 | |||
if opts["stdio"]: | ||||
|
r2127 | if repo is None: | ||
|
r3079 | raise hg.RepoError(_("There is no Mercurial repository here" | ||
" (.hg not found)")) | ||||
|
r2396 | s = sshserver.sshserver(ui, repo) | ||
s.serve_forever() | ||||
|
r2363 | |||
|
r4078 | parentui = ui.parentui or ui | ||
|
r2125 | optlist = ("name templates style address port ipv6" | ||
|
r4860 | " accesslog errorlog webdir_conf certificate") | ||
|
r987 | for o in optlist.split(): | ||
if opts[o]: | ||||
|
r4078 | parentui.setconfig("web", o, str(opts[o])) | ||
|
r5083 | if (repo is not None) and (repo.ui != parentui): | ||
|
r4835 | repo.ui.setconfig("web", o, str(opts[o])) | ||
|
r987 | |||
|
r2127 | if repo is None and not ui.config("web", "webdir_conf"): | ||
|
r3079 | raise hg.RepoError(_("There is no Mercurial repository here" | ||
" (.hg not found)")) | ||||
|
r2127 | |||
|
r4380 | class service: | ||
def init(self): | ||||
|
r4672 | util.set_signal_handler() | ||
|
r4380 | try: | ||
self.httpd = hgweb.server.create_server(parentui, repo) | ||||
except socket.error, inst: | ||||
raise util.Abort(_('cannot start server: ') + inst.args[1]) | ||||
if not ui.verbose: return | ||||
|
r4505 | if self.httpd.port != 80: | ||
|
r4380 | ui.status(_('listening at http://%s:%d/\n') % | ||
|
r4505 | (self.httpd.addr, self.httpd.port)) | ||
|
r4380 | else: | ||
|
r4505 | ui.status(_('listening at http://%s/\n') % self.httpd.addr) | ||
|
r4380 | |||
def run(self): | ||||
self.httpd.serve_forever() | ||||
service = service() | ||||
cmdutil.service(opts, initfn=service.init, runfn=service.run) | ||||
|
r500 | |||
|
r731 | def status(ui, repo, *pats, **opts): | ||
|
r1437 | """show changed files in the working directory | ||
|
r213 | |||
|
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. | ||||
|
r1437 | |||
|
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. | ||||
|
r3467 | If one revision is given, it is used as the base revision. | ||
If two revisions are given, the difference between them is shown. | ||||
|
r1437 | The codes used to show the status of files are: | ||
|
r746 | M = modified | ||
|
r245 | A = added | ||
R = removed | ||||
|
r2661 | C = clean | ||
|
r1619 | ! = deleted, but still tracked | ||
|
r842 | ? = not tracked | ||
|
r2022 | I = ignored (not shown by default) | ||
|
r2639 | = the previous added file was copied from here | ||
|
r1437 | """ | ||
|
r312 | |||
|
r2661 | all = opts['all'] | ||
|
r3707 | node1, node2 = cmdutil.revpair(repo, opts.get('rev')) | ||
|
r3223 | |||
|
r2882 | files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) | ||
|
r1625 | cwd = (pats and repo.getcwd()) or '' | ||
|
r2661 | modified, added, removed, deleted, unknown, ignored, clean = [ | ||
|
r4043 | n for n in repo.status(node1=node1, node2=node2, files=files, | ||
|
r3467 | match=matchfn, | ||
|
r2661 | list_ignored=all or opts['ignored'], | ||
list_clean=all or opts['clean'])] | ||||
changetypes = (('modified', 'M', modified), | ||||
|
r1966 | ('added', 'A', added), | ||
('removed', 'R', removed), | ||||
('deleted', '!', deleted), | ||||
|
r2022 | ('unknown', '?', unknown), | ||
|
r2661 | ('ignored', 'I', ignored)) | ||
explicit_changetypes = changetypes + (('clean', 'C', clean),) | ||||
|
r842 | |||
|
r1085 | end = opts['print0'] and '\0' or '\n' | ||
|
r1106 | |||
|
r2661 | for opt, char, changes in ([ct for ct in explicit_changetypes | ||
if all or opts[ct[0]]] | ||||
|
r842 | or changetypes): | ||
|
r1105 | if opts['no_status']: | ||
|
r1085 | format = "%%s%s" % end | ||
else: | ||||
|
r1966 | format = "%s %%s%s" % (char, end) | ||
|
r1106 | |||
|
r842 | for f in changes: | ||
|
r4525 | ui.write(format % repo.pathto(f, cwd)) | ||
|
r3250 | if ((all or opts.get('copies')) and not opts.get('no_status')): | ||
|
r3159 | copied = repo.dirstate.copied(f) | ||
if copied: | ||||
|
r4525 | ui.write(' %s%s' % (repo.pathto(copied, cwd), end)) | ||
|
r213 | |||
|
r1596 | def tag(ui, repo, name, rev_=None, **opts): | ||
|
r3915 | """add a tag for the current or given revision | ||
|
r1437 | |||
Name a particular revision using <name>. | ||||
Tags are used to name particular revisions of the repository and are | ||||
very useful to compare different revision, to go back to significant | ||||
earlier versions or to mark branch points as releases, etc. | ||||
|
r3915 | If no revision is given, the parent of the working directory is used, | ||
or tip if no revision is checked out. | ||||
|
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 | ||||
|
r1654 | necessary. The file '.hg/localtags' is used for local tags (not | ||
shared among repositories). | ||||
|
r1437 | """ | ||
|
r3801 | if name in ['tip', '.', 'null']: | ||
|
r2789 | raise util.Abort(_("the name '%s' is reserved") % name) | ||
|
r1654 | if rev_ is not None: | ||
ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " | ||||
|
r1661 | "please use 'hg tag [-r REV] NAME' instead\n")) | ||
|
r1654 | if opts['rev']: | ||
raise util.Abort(_("use only one form to specify the revision")) | ||||
|
r4213 | if opts['rev'] and opts['remove']: | ||
raise util.Abort(_("--rev and --remove are incompatible")) | ||||
|
r1596 | if opts['rev']: | ||
rev_ = opts['rev'] | ||||
|
r4213 | message = opts['message'] | ||
if opts['remove']: | ||||
|
r4659 | if not name in repo.tags(): | ||
|
r4650 | raise util.Abort(_('tag %s does not exist') % name) | ||
|
r4213 | rev_ = nullid | ||
if not message: | ||||
message = _('Removed tag %s') % name | ||||
|
r4267 | elif name in repo.tags() and not opts['force']: | ||
raise util.Abort(_('a tag named %s already exists (use -f to force)') | ||||
% name) | ||||
|
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() | ||||
|
r2967 | |||
if not message: | ||||
message = _('Added tag %s for changeset %s') % (name, short(r)) | ||||
repo.tag(name, r, message, opts['local'], opts['user'], opts['date']) | ||||
|
r401 | |||
|
r248 | def tags(ui, repo): | ||
|
r1437 | """list repository tags | ||
List the repository tags. | ||||
This lists both regular and local tags. | ||||
""" | ||||
|
r477 | |||
|
r343 | l = repo.tagslist() | ||
l.reverse() | ||||
|
r2966 | hexfunc = ui.debugflag and hex or short | ||
|
r477 | for t, n in l: | ||
|
r248 | try: | ||
|
r4516 | hn = hexfunc(n) | ||
|
r2966 | r = "%5d:%s" % (repo.changelog.rev(n), hexfunc(n)) | ||
|
r3930 | except revlog.LookupError: | ||
r = " ?:%s" % hn | ||||
|
r2035 | if ui.quiet: | ||
ui.write("%s\n" % t) | ||||
else: | ||||
|
r4143 | spaces = " " * (30 - util.locallen(t)) | ||
ui.write("%s%s %s\n" % (t, spaces, r)) | ||||
|
r248 | |||
|
r1731 | def tip(ui, repo, **opts): | ||
|
r1437 | """show the tip revision | ||
Show the tip revision. | ||||
""" | ||||
|
r3671 | cmdutil.show_changeset(ui, repo, opts).show(nullrev+repo.changelog.count()) | ||
|
r245 | |||
|
r4699 | def unbundle(ui, repo, fname1, *fnames, **opts): | ||
"""apply one or more changegroup files | ||||
Apply one or more compressed changegroup files generated by the | ||||
bundle command. | ||||
|
r1437 | """ | ||
|
r4699 | fnames = (fname1,) + fnames | ||
for fname in fnames: | ||||
if os.path.exists(fname): | ||||
f = open(fname, "rb") | ||||
else: | ||||
f = urllib.urlopen(fname) | ||||
gen = changegroup.readbundle(f, fname) | ||||
modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname) | ||||
|
r5224 | return postincoming(ui, repo, modheads, opts['update'], None) | ||
|
r1218 | |||
|
r4450 | def update(ui, repo, node=None, rev=None, clean=False, date=None): | ||
|
r4014 | """update working directory | ||
|
r1437 | |||
|
r4205 | Update the working directory to the specified revision, or the | ||
tip of the current branch if none is specified. | ||||
|
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. | ||||
|
r2283 | To merge the working directory with another revision, use the | ||
merge command. | ||||
|
r1437 | |||
By default, update will refuse to run if doing so would require | ||||
|
r4014 | discarding local changes. | ||
|
r1437 | """ | ||
|
r4450 | if rev and node: | ||
raise util.Abort(_("please specify just one revision")) | ||||
if not rev: | ||||
rev = node | ||||
|
r3814 | if date: | ||
|
r4450 | if rev: | ||
|
r3814 | raise util.Abort(_("you can't specify a revision and a date")) | ||
|
r4450 | rev = cmdutil.finddate(ui, repo, date) | ||
|
r3814 | |||
|
r3521 | if clean: | ||
|
r4450 | return hg.clean(repo, rev) | ||
|
r2808 | else: | ||
|
r4450 | return hg.update(repo, rev) | ||
|
r254 | |||
|
r247 | def verify(ui, repo): | ||
|
r1437 | """verify the integrity of the repository | ||
Verify the integrity of the current repository. | ||||
This will perform an extensive check of the repository's | ||||
integrity, validating the hashes and checksums of each entry in | ||||
the changelog, manifest, and tracked files, as well as the | ||||
integrity of their crosslinks and indices. | ||||
""" | ||||
|
r2778 | return hg.verify(repo) | ||
|
r247 | |||
|
r3651 | def version_(ui): | ||
"""output version and copyright information""" | ||||
ui.write(_("Mercurial Distributed SCM (version %s)\n") | ||||
% version.get_version()) | ||||
ui.status(_( | ||||
|
r4635 | "\nCopyright (C) 2005-2007 Matt Mackall <mpm@selenic.com> and others\n" | ||
|
r3651 | "This is free software; see the source for copying conditions. " | ||
"There is NO\nwarranty; " | ||||
"not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | ||||
)) | ||||
|
r255 | # Command options and aliases are listed here, alphabetically | ||
|
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')), | ||||
|
r3774 | ('', 'encoding', util._encoding, _('set the charset encoding')), | ||
('', 'encodingmode', util._encodingmode, _('set the charset encoding mode')), | ||||
|
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')), | ||||
] | ||||
|
r3189 | dryrunopts = [('n', 'dry-run', None, | ||
_('do not perform actions, just print output'))] | ||||
|
r3190 | remoteopts = [ | ||
('e', 'ssh', '', _('specify ssh command to use')), | ||||
('', 'remotecmd', '', _('specify hg command to run on the remote side')), | ||||
] | ||||
|
r3188 | walkopts = [ | ||
('I', 'include', [], _('include names matching the given patterns')), | ||||
('X', 'exclude', [], _('exclude names matching the given patterns')), | ||||
] | ||||
|
r3857 | commitopts = [ | ||
('m', 'message', '', _('use <text> as commit message')), | ||||
('l', 'logfile', '', _('read commit message from <file>')), | ||||
] | ||||
|
r5147 | commitopts2 = [ | ||
('d', 'date', '', _('record datecode as commit date')), | ||||
('u', 'user', '', _('record user as committer')), | ||||
] | ||||
|
r209 | table = { | ||
|
r3824 | "^add": (add, walkopts + dryrunopts, _('hg add [OPTION]... [FILE]...')), | ||
|
r2955 | "addremove": | ||
|
r841 | (addremove, | ||
|
r3188 | [('s', 'similarity', '', | ||
|
r3189 | _('guess renamed files by similarity (0<=s<=100)')), | ||
] + walkopts + dryrunopts, | ||||
|
r1615 | _('hg addremove [OPTION]... [FILE]...')), | ||
|
r697 | "^annotate": | ||
(annotate, | ||||
|
r1437 | [('r', 'rev', '', _('annotate the specified revision')), | ||
|
r3172 | ('f', 'follow', None, _('follow file copies and renames')), | ||
|
r1402 | ('a', 'text', None, _('treat all files as text')), | ||
|
r1437 | ('u', 'user', None, _('list the author')), | ||
|
r1522 | ('d', 'date', None, _('list the date')), | ||
|
r1437 | ('n', 'number', None, _('list the revision number (default)')), | ||
('c', 'changeset', None, _('list the changeset')), | ||||
|
r4857 | ('l', 'line-number', None, | ||
_('show line number at the first appearance')) | ||||
|
r3188 | ] + walkopts, | ||
|
r4857 | _('hg annotate [-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...')), | ||
|
r2160 | "archive": | ||
|
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')), | ||||
|
r3188 | ] + walkopts, | ||
|
r2112 | _('hg archive [OPTION]... DEST')), | ||
|
r2159 | "backout": | ||
|
r2158 | (backout, | ||
|
r2159 | [('', 'merge', None, | ||
_('merge with old dirstate parent after backout')), | ||||
|
r2614 | ('', 'parent', '', _('parent to choose when backing out merge')), | ||
|
r4450 | ('r', 'rev', '', _('revision to backout')), | ||
|
r5147 | ] + walkopts + commitopts + commitopts2, | ||
|
r4450 | _('hg backout [OPTION]... [-r] REV')), | ||
|
r4730 | "branch": | ||
(branch, | ||||
[('f', 'force', None, | ||||
_('set branch name even if it shadows an existing branch'))], | ||||
_('hg branch [NAME]')), | ||||
"branches": | ||||
(branches, | ||||
[('a', 'active', False, | ||||
_('show only branches that have unmerged heads'))], | ||||
_('hg branches [-a]')), | ||||
|
r1218 | "bundle": | ||
(bundle, | ||||
|
r1959 | [('f', 'force', None, | ||
|
r3191 | _('run even when remote repository is unrelated')), | ||
|
r3284 | ('r', 'rev', [], | ||
_('a changeset you would like to bundle')), | ||||
('', 'base', [], | ||||
_('a base changeset to specify instead of a destination')), | ||||
|
r3191 | ] + remoteopts, | ||
|
r3885 | _('hg bundle [-f] [-r REV]... [--base REV]... FILE [DEST]')), | ||
|
r697 | "cat": | ||
(cat, | ||||
|
r1816 | [('o', 'output', '', _('print output to file with formatted name')), | ||
('r', 'rev', '', _('print the given revision')), | ||||
|
r3188 | ] + walkopts, | ||
|
r1402 | _('hg cat [OPTION]... FILE...')), | ||
|
r697 | "^clone": | ||
(clone, | ||||
|
r1437 | [('U', 'noupdate', None, _('do not update the new working directory')), | ||
|
r1602 | ('r', 'rev', [], | ||
|
r2764 | _('a changeset you would like to have after cloning')), | ||
|
r1816 | ('', 'pull', None, _('use pull protocol to copy metadata')), | ||
|
r2620 | ('', 'uncompressed', None, | ||
_('use uncompressed transfer (fast over LAN)')), | ||||
|
r3190 | ] + remoteopts, | ||
|
r1402 | _('hg clone [OPTION]... SOURCE [DEST]')), | ||
|
r697 | "^commit|ci": | ||
(commit, | ||||
|
r2184 | [('A', 'addremove', None, | ||
_('mark new/missing files as added/removed before committing')), | ||||
|
r5147 | ] + walkopts + commitopts + commitopts2, | ||
|
r1402 | _('hg commit [OPTION]... [FILE]...')), | ||
|
r1615 | "copy|cp": | ||
(copy, | ||||
|
r1816 | [('A', 'after', None, _('record a copy that has already occurred')), | ||
|
r1615 | ('f', 'force', None, | ||
|
r1816 | _('forcibly copy over an existing managed file')), | ||
|
r3189 | ] + walkopts + dryrunopts, | ||
|
r1615 | _('hg copy [OPTION]... [SOURCE]... DEST')), | ||
|
r1402 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), | ||
|
r2034 | "debugcomplete": | ||
(debugcomplete, | ||||
[('o', 'options', None, _('show the command options'))], | ||||
_('debugcomplete [-o] CMD')), | ||||
|
r3844 | "debuginstall": (debuginstall, [], _('debuginstall')), | ||
|
r1755 | "debugrebuildstate": | ||
(debugrebuildstate, | ||||
|
r1816 | [('r', 'rev', '', _('revision to rebuild to'))], | ||
|
r1755 | _('debugrebuildstate [-r REV] [REV]')), | ||
|
r1402 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), | ||
"debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), | ||||
"debugstate": (debugstate, [], _('debugstate')), | ||||
|
r3824 | "debugdate": | ||
(debugdate, | ||||
[('e', 'extended', None, _('try extended date formats'))], | ||||
_('debugdate [-e] DATE [RANGE]')), | ||||
|
r1402 | "debugdata": (debugdata, [], _('debugdata FILE REV')), | ||
"debugindex": (debugindex, [], _('debugindex FILE')), | ||||
"debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), | ||||
|
r4730 | "debugrename": | ||
(debugrename, | ||||
[('r', 'rev', '', _('revision to debug'))], | ||||
_('debugrename [-r REV] FILE')), | ||||
|
r3824 | "debugwalk": (debugwalk, walkopts, _('debugwalk [OPTION]... [FILE]...')), | ||
|
r697 | "^diff": | ||
(diff, | ||||
|
r1402 | [('r', 'rev', [], _('revision')), | ||
('a', 'text', None, _('treat all files as text')), | ||||
|
r1728 | ('p', 'show-function', None, | ||
_('show which function each change is in')), | ||||
|
r2907 | ('g', 'git', None, _('use git extended diff format')), | ||
|
r3200 | ('', 'nodates', None, _("don't include dates in diff headers")), | ||
|
r1728 | ('w', 'ignore-all-space', None, | ||
_('ignore white space when comparing lines')), | ||||
|
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')), | ||||
|
r3188 | ] + walkopts, | ||
|
r3885 | _('hg diff [OPTION]... [-r REV1 [-r REV2]] [FILE]...')), | ||
|
r697 | "^export": | ||
(export, | ||||
|
r1615 | [('o', 'output', '', _('print output to file with formatted name')), | ||
|
r1571 | ('a', 'text', None, _('treat all files as text')), | ||
|
r3029 | ('g', 'git', None, _('use git extended diff format')), | ||
|
r3200 | ('', 'nodates', None, _("don't include dates in diff headers")), | ||
|
r1571 | ('', 'switch-parent', None, _('diff against the second parent'))], | ||
|
r3885 | _('hg export [OPTION]... [-o OUTFILESPEC] REV...')), | ||
|
r1065 | "grep": | ||
(grep, | ||||
|
r1402 | [('0', 'print0', None, _('end fields with NUL')), | ||
|
r1437 | ('', 'all', None, _('print all revisions that match')), | ||
|
r2870 | ('f', 'follow', None, | ||
_('follow changeset history, or file history across copies and renames')), | ||||
|
r1402 | ('i', 'ignore-case', None, _('ignore case when matching')), | ||
|
r1602 | ('l', 'files-with-matches', None, | ||
_('print only filenames and revs that match')), | ||||
|
r1437 | ('n', 'line-number', None, _('print matching line numbers')), | ||
('r', 'rev', [], _('search in given revision range')), | ||||
|
r1816 | ('u', 'user', None, _('print user who committed change')), | ||
|
r3188 | ] + walkopts, | ||
|
r1615 | _('hg grep [OPTION]... PATTERN [FILE]...')), | ||
|
r905 | "heads": | ||
(heads, | ||||
|
r3876 | [('', 'style', '', _('display using template map file')), | ||
|
r1907 | ('r', 'rev', '', _('show only heads which are descendants of rev')), | ||
|
r1913 | ('', 'template', '', _('display with template'))], | ||
|
r4648 | _('hg heads [-r REV] [REV]...')), | ||
|
r1402 | "help": (help_, [], _('hg help [COMMAND]')), | ||
|
r4665 | "identify|id": | ||
(identify, | ||||
|
r4666 | [('r', 'rev', '', _('identify the specified rev')), | ||
('n', 'num', None, _('show local revision number')), | ||||
('i', 'id', None, _('show global revision id')), | ||||
('b', 'branch', None, _('show branch')), | ||||
('t', 'tags', None, _('show tags'))], | ||||
|
r4671 | _('hg identify [-nibt] [-r REV] [SOURCE]')), | ||
|
r697 | "import|patch": | ||
(import_, | ||||
|
r1602 | [('p', 'strip', 1, | ||
|
r2125 | _('directory strip option for patch. This has the same\n' | ||
'meaning as the corresponding patch option')), | ||||
|
r3876 | ('b', 'base', '', _('base path')), | ||
|
r1602 | ('f', 'force', None, | ||
|
r4263 | _('skip check for outstanding uncommitted changes')), | ||
('', 'exact', None, | ||||
|
r4592 | _('apply patch to the nodes from which it was generated')), | ||
('', 'import-branch', None, | ||||
_('Use any branch information in patch (implied by --exact)'))] + commitopts, | ||||
|
r3517 | _('hg import [-p NUM] [-m MESSAGE] [-f] PATCH...')), | ||
|
r1253 | "incoming|in": (incoming, | ||
|
r1615 | [('M', 'no-merges', None, _('do not show merges')), | ||
|
r1959 | ('f', 'force', None, | ||
_('run even when remote repository is unrelated')), | ||||
|
r1913 | ('', 'style', '', _('display using template map file')), | ||
|
r1907 | ('n', 'newest-first', None, _('show newest record first')), | ||
|
r1944 | ('', 'bundle', '', _('file to store the bundles into')), | ||
|
r1439 | ('p', 'patch', None, _('show patch')), | ||
|
r2878 | ('r', 'rev', [], _('a specific revision up to which you would like to pull')), | ||
|
r1965 | ('', 'template', '', _('display with template')), | ||
|
r3190 | ] + remoteopts, | ||
|
r3885 | _('hg incoming [-p] [-n] [-M] [-f] [-r REV]...' | ||
|
r2544 | ' [--bundle FILENAME] [SOURCE]')), | ||
|
r2598 | "^init": | ||
|
r3885 | (init, | ||
remoteopts, | ||||
_('hg init [-e CMD] [--remotecmd CMD] [DEST]')), | ||||
|
r697 | "locate": | ||
(locate, | ||||
|
r1437 | [('r', 'rev', '', _('search the repository as it stood at rev')), | ||
|
r1602 | ('0', 'print0', None, | ||
_('end filenames with NUL, for use with xargs')), | ||||
('f', 'fullpath', None, | ||||
_('print complete paths from the filesystem root')), | ||||
|
r3188 | ] + walkopts, | ||
|
r1402 | _('hg locate [OPTION]... [PATTERN]...')), | ||
|
r697 | "^log|history": | ||
(log, | ||||
|
r3876 | [('f', 'follow', None, | ||
|
r2782 | _('follow changeset history, or file history across copies and renames')), | ||
|
r2784 | ('', 'follow-first', None, | ||
_('only follow the first parent of merge changesets')), | ||||
|
r3813 | ('d', 'date', '', _('show revs matching date spec')), | ||
|
r3197 | ('C', 'copies', None, _('show copied files')), | ||
|
r4324 | ('k', 'keyword', [], _('do case-insensitive search for a keyword')), | ||
|
r1756 | ('l', 'limit', '', _('limit number of changes displayed')), | ||
|
r1437 | ('r', 'rev', [], _('show the specified revision or range')), | ||
|
r3657 | ('', 'removed', None, _('include revs where files were removed')), | ||
|
r1615 | ('M', 'no-merges', None, _('do not show merges')), | ||
|
r1913 | ('', 'style', '', _('display using template map file')), | ||
|
r1615 | ('m', 'only-merges', None, _('show only merges')), | ||
|
r1816 | ('p', 'patch', None, _('show patch')), | ||
|
r2901 | ('P', 'prune', [], _('do not display revision or any of its ancestors')), | ||
|
r1920 | ('', 'template', '', _('display with template')), | ||
|
r3188 | ] + walkopts, | ||
|
r1816 | _('hg log [OPTION]... [FILE]')), | ||
|
r5155 | "manifest": (manifest, [('r', 'rev', '', _('revision to display'))], | ||
_('hg manifest [-r REV]')), | ||||
|
r4014 | "^merge": | ||
|
r2044 | (merge, | ||
|
r4450 | [('f', 'force', None, _('force a merge with outstanding changes')), | ||
('r', 'rev', '', _('revision to merge')), | ||||
], | ||||
_('hg merge [-f] [[-r] REV]')), | ||||
|
r1253 | "outgoing|out": (outgoing, | ||
|
r1615 | [('M', 'no-merges', None, _('do not show merges')), | ||
|
r1959 | ('f', 'force', None, | ||
_('run even when remote repository is unrelated')), | ||||
|
r1439 | ('p', 'patch', None, _('show patch')), | ||
|
r1913 | ('', 'style', '', _('display using template map file')), | ||
|
r2521 | ('r', 'rev', [], _('a specific revision you would like to push')), | ||
|
r1907 | ('n', 'newest-first', None, _('show newest record first')), | ||
|
r1965 | ('', 'template', '', _('display with template')), | ||
|
r3190 | ] + remoteopts, | ||
|
r3885 | _('hg outgoing [-M] [-p] [-n] [-f] [-r REV]... [DEST]')), | ||
|
r1724 | "^parents": | ||
(parents, | ||||
|
r3876 | [('r', 'rev', '', _('show parents from the specified rev')), | ||
|
r1913 | ('', 'style', '', _('display using template map file')), | ||
('', 'template', '', _('display with template'))], | ||||
|
r3504 | _('hg parents [-r REV] [FILE]')), | ||
|
r1402 | "paths": (paths, [], _('hg paths [NAME]')), | ||
|
r697 | "^pull": | ||
(pull, | ||||
|
r1602 | [('u', 'update', None, | ||
|
r3198 | _('update to new tip if changesets were pulled')), | ||
|
r1959 | ('f', 'force', None, | ||
_('run even when remote repository is unrelated')), | ||||
|
r3885 | ('r', 'rev', [], | ||
_('a specific revision up to which you would like to pull')), | ||||
|
r3190 | ] + remoteopts, | ||
|
r3885 | _('hg pull [-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')), | ||
|
r818 | "^push": | ||
(push, | ||||
|
r1402 | [('f', 'force', None, _('force push')), | ||
|
r1781 | ('r', 'rev', [], _('a specific revision you would like to push')), | ||
|
r3190 | ] + remoteopts, | ||
|
r3885 | _('hg push [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')), | ||
|
r1818 | "debugrawcommit|rawcommit": | ||
|
r697 | (rawcommit, | ||
|
r1402 | [('p', 'parent', [], _('parent')), | ||
|
r3857 | ('F', 'files', '', _('file list')) | ||
|
r5147 | ] + commitopts + commitopts2, | ||
|
r1818 | _('hg debugrawcommit [OPTION]... [FILE]...')), | ||
|
r1615 | "recover": (recover, [], _('hg recover')), | ||
"^remove|rm": | ||||
(remove, | ||||
|
r2245 | [('A', 'after', None, _('record remove that has already occurred')), | ||
|
r2179 | ('f', 'force', None, _('remove file even if modified')), | ||
|
r3188 | ] + walkopts, | ||
|
r1615 | _('hg remove [OPTION]... FILE...')), | ||
"rename|mv": | ||||
(rename, | ||||
|
r1816 | [('A', 'after', None, _('record a rename that has already occurred')), | ||
|
r1615 | ('f', 'force', None, | ||
|
r1816 | _('forcibly copy over an existing managed file')), | ||
|
r3189 | ] + walkopts + dryrunopts, | ||
|
r1869 | _('hg rename [OPTION]... SOURCE... DEST')), | ||
|
r697 | "^revert": | ||
(revert, | ||||
|
r2983 | [('a', 'all', None, _('revert all changes when no arguments given')), | ||
|
r3814 | ('d', 'date', '', _('tipmost revision matching date')), | ||
|
r2982 | ('r', 'rev', '', _('revision to revert to')), | ||
|
r2029 | ('', 'no-backup', None, _('do not save backup copies of files')), | ||
|
r3189 | ] + walkopts + dryrunopts, | ||
|
r3885 | _('hg revert [OPTION]... [-r REV] [NAME]...')), | ||
|
r2227 | "rollback": (rollback, [], _('hg rollback')), | ||
|
r1615 | "root": (root, [], _('hg root')), | ||
|
r3553 | "showconfig|debugconfig": | ||
(showconfig, | ||||
[('u', 'untrusted', None, _('show untrusted configuration options'))], | ||||
_('showconfig [-u] [NAME]...')), | ||||
|
r697 | "^serve": | ||
(serve, | ||||
|
r1437 | [('A', 'accesslog', '', _('name of access log file to write to')), | ||
|
r1740 | ('d', 'daemon', None, _('run server in background')), | ||
|
r1742 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), | ||
|
r1437 | ('E', 'errorlog', '', _('name of error log file to write to')), | ||
('p', 'port', 0, _('port to use (default: 8000)')), | ||||
('a', 'address', '', _('address to use')), | ||||
|
r1615 | ('n', 'name', '', | ||
|
r1602 | _('name to show in web pages (default: working dir)')), | ||
|
r2124 | ('', 'webdir-conf', '', _('name of the webdir config file' | ||
' (serve more than one repo)')), | ||||
|
r1740 | ('', 'pid-file', '', _('name of file to write process ID to')), | ||
|
r1402 | ('', 'stdio', None, _('for remote clients')), | ||
|
r1615 | ('t', 'templates', '', _('web templates to use')), | ||
('', 'style', '', _('template style to use')), | ||||
|
r4860 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')), | ||
('', 'certificate', '', _('SSL certificate file'))], | ||||
|
r1615 | _('hg serve [OPTION]...')), | ||
|
r1507 | "^status|st": | ||
|
r840 | (status, | ||
|
r2661 | [('A', 'all', None, _('show status of all files')), | ||
('m', 'modified', None, _('show only modified files')), | ||||
|
r1402 | ('a', 'added', None, _('show only added files')), | ||
('r', 'removed', None, _('show only removed files')), | ||||
|
r1619 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), | ||
|
r2661 | ('c', 'clean', None, _('show only files without changes')), | ||
|
r1402 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), | ||
|
r4156 | ('i', 'ignored', None, _('show only ignored files')), | ||
|
r1402 | ('n', 'no-status', None, _('hide status prefix')), | ||
|
r2639 | ('C', 'copies', None, _('show source of copied files')), | ||
|
r1602 | ('0', 'print0', None, | ||
_('end filenames with NUL, for use with xargs')), | ||||
|
r3467 | ('', 'rev', [], _('show difference from revision')), | ||
|
r3188 | ] + walkopts, | ||
|
r1615 | _('hg status [OPTION]... [FILE]...')), | ||
|
r697 | "tag": | ||
(tag, | ||||
|
r4267 | [('f', 'force', None, _('replace existing tag')), | ||
('l', 'local', None, _('make the tag local')), | ||||
|
r4213 | ('r', 'rev', '', _('revision to tag')), | ||
|
r5147 | ('', 'remove', None, _('remove a tag')), | ||
# -l/--local is already there, commitopts cannot be used | ||||
('m', 'message', '', _('use <text> as commit message')), | ||||
] + commitopts2, | ||||
|
r1812 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), | ||
|
r1402 | "tags": (tags, [], _('hg tags')), | ||
|
r1762 | "tip": | ||
(tip, | ||||
|
r3876 | [('', 'style', '', _('display using template map file')), | ||
|
r1907 | ('p', 'patch', None, _('show patch')), | ||
|
r1913 | ('', 'template', '', _('display with template'))], | ||
|
r3504 | _('hg tip [-p]')), | ||
|
r1218 | "unbundle": | ||
(unbundle, | ||||
|
r1601 | [('u', 'update', None, | ||
|
r3198 | _('update to new tip if changesets were unbundled'))], | ||
|
r4699 | _('hg unbundle [-u] FILE...')), | ||
|
r593 | "^update|up|checkout|co": | ||
|
r697 | (update, | ||
|
r3876 | [('C', 'clean', None, _('overwrite locally modified files')), | ||
|
r4450 | ('d', 'date', '', _('tipmost revision matching date')), | ||
('r', 'rev', '', _('revision'))], | ||||
_('hg update [-C] [-d DATE] [[-r] REV]')), | ||||
|
r1402 | "verify": (verify, [], _('hg verify')), | ||
|
r3651 | "version": (version_, [], _('hg version')), | ||
|
r1046 | } | ||
|
r209 | |||
|
r1887 | norepo = ("clone init version help debugancestor debugcomplete debugdata" | ||
|
r3844 | " debugindex debugindexdot debugdate debuginstall") | ||
|
r5330 | optionalrepo = ("identify paths serve showconfig") | ||