commands.py
3281 lines
| 115.4 KiB
| text/x-python
|
PythonLexer
/ mercurial / commands.py
|
r249 | # commands.py - command processing for mercurial | ||
# | ||||
# Copyright 2005 Matt Mackall <mpm@selenic.com> | ||||
# | ||||
# This software may be used and distributed according to the terms | ||||
# of the GNU General Public License, incorporated herein by reference. | ||||
|
r697 | from demandload import demandload | ||
|
r1092 | from node import * | ||
|
r1400 | from i18n import gettext as _ | ||
|
r1225 | demandload(globals(), "os re sys signal shutil imp urllib pdb") | ||
|
r1944 | demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo") | ||
demandload(globals(), "fnmatch hgweb mdiff random signal tempfile time") | ||||
demandload(globals(), "traceback errno socket version struct atexit sets bz2") | ||||
|
r209 | |||
|
r697 | class UnknownCommand(Exception): | ||
"""Exception raised if command is not in the command table.""" | ||||
|
r1518 | class AmbiguousCommand(Exception): | ||
"""Exception raised if command shortcut matches more than one command.""" | ||||
|
r209 | |||
|
r245 | def filterfiles(filters, files): | ||
|
r697 | l = [x for x in files if x in filters] | ||
|
r213 | |||
|
r245 | for t in filters: | ||
|
r697 | if t and t[-1] != "/": | ||
t += "/" | ||||
l += [x for x in files if x.startswith(t)] | ||||
|
r213 | return l | ||
|
r209 | def relpath(repo, args): | ||
|
r628 | cwd = repo.getcwd() | ||
if cwd: | ||||
|
r886 | return [util.normpath(os.path.join(cwd, x)) for x in args] | ||
|
r209 | return args | ||
|
r245 | |||
|
r1568 | def matchpats(repo, pats=[], opts={}, head=''): | ||
cwd = repo.getcwd() | ||||
if not pats and cwd: | ||||
opts['include'] = [os.path.join(cwd, i) for i in opts['include']] | ||||
opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] | ||||
cwd = '' | ||||
|
r1413 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), | ||
|
r1625 | opts.get('exclude'), head) | ||
|
r724 | |||
|
r1582 | def makewalk(repo, pats, opts, node=None, head=''): | ||
|
r1625 | files, matchfn, anypats = matchpats(repo, pats, opts, head) | ||
|
r942 | exact = dict(zip(files, files)) | ||
|
r837 | def walk(): | ||
|
r1582 | for src, fn in repo.walk(node=node, files=files, match=matchfn): | ||
|
r1625 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact | ||
|
r837 | return files, matchfn, walk() | ||
|
r1582 | def walk(repo, pats, opts, node=None, head=''): | ||
files, matchfn, results = makewalk(repo, pats, opts, node, head) | ||||
|
r1065 | for r in results: | ||
yield r | ||||
|
r724 | |||
|
r1568 | def walkchangerevs(ui, repo, pats, opts): | ||
|
r1146 | '''Iterate over files and the revs they changed in. | ||
Callers most commonly need to iterate backwards over the history | ||||
it is interested in. Doing so has awful (quadratic-looking) | ||||
performance, so we use iterators in a "windowed" way. | ||||
We walk a window of revisions in the desired order. Within the | ||||
window, we first walk forwards to gather data, then in the desired | ||||
order (usually backwards) to display it. | ||||
|
r1570 | This function returns an (iterator, getchange, matchfn) tuple. The | ||
|
r1146 | getchange function returns the changelog entry for a numeric | ||
revision. The iterator yields 3-tuples. They will be of one of | ||||
the following forms: | ||||
"window", incrementing, lastrev: stepping through a window, | ||||
positive if walking forwards through revs, last rev in the | ||||
sequence iterated over - use to reset state for the current window | ||||
"add", rev, fns: out-of-order traversal of the given file names | ||||
fns, which changed during revision rev - use to gather data for | ||||
possible display | ||||
"iter", rev, None: in-order traversal of the revs earlier iterated | ||||
over with "add" - use to display data''' | ||||
|
r1337 | |||
|
r1799 | def increasing_windows(start, end, windowsize=8, sizelimit=512): | ||
if start < end: | ||||
while start < end: | ||||
yield start, min(windowsize, end-start) | ||||
start += windowsize | ||||
if windowsize < sizelimit: | ||||
windowsize *= 2 | ||||
else: | ||||
while start > end: | ||||
yield start, min(windowsize, start-end-1) | ||||
start -= windowsize | ||||
if windowsize < sizelimit: | ||||
windowsize *= 2 | ||||
|
r1625 | files, matchfn, anypats = matchpats(repo, pats, opts) | ||
|
r1570 | |||
|
r1337 | if repo.changelog.count() == 0: | ||
|
r1570 | return [], False, matchfn | ||
|
r1337 | |||
|
r1057 | revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) | ||
wanted = {} | ||||
slowpath = anypats | ||||
fncache = {} | ||||
|
r1146 | |||
chcache = {} | ||||
def getchange(rev): | ||||
ch = chcache.get(rev) | ||||
if ch is None: | ||||
chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev))) | ||||
return ch | ||||
|
r1057 | if not slowpath and not files: | ||
# No files, no patterns. Display all revs. | ||||
wanted = dict(zip(revs, revs)) | ||||
if not slowpath: | ||||
# Only files, no patterns. Check the history of each file. | ||||
def filerevgen(filelog): | ||||
|
r1799 | for i, window in increasing_windows(filelog.count()-1, -1): | ||
|
r1057 | revs = [] | ||
|
r1800 | for j in xrange(i - window, i + 1): | ||
|
r1057 | revs.append(filelog.linkrev(filelog.node(j))) | ||
revs.reverse() | ||||
for rev in revs: | ||||
yield rev | ||||
minrev, maxrev = min(revs), max(revs) | ||||
|
r1749 | for file_ in files: | ||
filelog = repo.file(file_) | ||||
|
r1057 | # A zero count may be a directory or deleted file, so | ||
# try to find matching entries on the slow path. | ||||
if filelog.count() == 0: | ||||
slowpath = True | ||||
break | ||||
for rev in filerevgen(filelog): | ||||
if rev <= maxrev: | ||||
|
r1065 | if rev < minrev: | ||
break | ||||
|
r1057 | fncache.setdefault(rev, []) | ||
|
r1749 | fncache[rev].append(file_) | ||
|
r1057 | wanted[rev] = 1 | ||
if slowpath: | ||||
# The slow path checks files modified in every changeset. | ||||
def changerevgen(): | ||||
|
r1799 | for i, window in increasing_windows(repo.changelog.count()-1, -1): | ||
|
r1800 | for j in xrange(i - window, i + 1): | ||
|
r1146 | yield j, getchange(j)[3] | ||
|
r1057 | |||
for rev, changefiles in changerevgen(): | ||||
matches = filter(matchfn, changefiles) | ||||
if matches: | ||||
fncache[rev] = matches | ||||
wanted[rev] = 1 | ||||
|
r1146 | def iterate(): | ||
|
r1799 | for i, window in increasing_windows(0, len(revs)): | ||
|
r1146 | yield 'window', revs[0] < revs[-1], revs[-1] | ||
|
r1800 | nrevs = [rev for rev in revs[i:i+window] | ||
|
r1146 | if rev in wanted] | ||
srevs = list(nrevs) | ||||
srevs.sort() | ||||
for rev in srevs: | ||||
fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) | ||||
yield 'add', rev, fns | ||||
for rev in nrevs: | ||||
yield 'iter', rev, None | ||||
|
r1570 | return iterate(), getchange, matchfn | ||
|
r1057 | |||
|
r580 | revrangesep = ':' | ||
|
r697 | def revrange(ui, repo, revs, revlog=None): | ||
|
r1066 | """Yield revision as strings from a list of revision specifications.""" | ||
|
r580 | if revlog is None: | ||
revlog = repo.changelog | ||||
revcount = revlog.count() | ||||
def fix(val, defval): | ||||
|
r697 | if not val: | ||
return defval | ||||
|
r580 | try: | ||
num = int(val) | ||||
|
r697 | if str(num) != val: | ||
raise ValueError | ||||
|
r1615 | if num < 0: | ||
num += revcount | ||||
if num < 0: | ||||
num = 0 | ||||
|
r1257 | elif num >= revcount: | ||
|
r580 | raise ValueError | ||
except ValueError: | ||||
try: | ||||
num = repo.changelog.rev(repo.lookup(val)) | ||||
except KeyError: | ||||
try: | ||||
num = revlog.rev(revlog.lookup(val)) | ||||
except KeyError: | ||||
|
r1402 | raise util.Abort(_('invalid revision identifier %s'), val) | ||
|
r580 | return num | ||
|
r1146 | seen = {} | ||
|
r580 | for spec in revs: | ||
if spec.find(revrangesep) >= 0: | ||||
start, end = spec.split(revrangesep, 1) | ||||
start = fix(start, 0) | ||||
end = fix(end, revcount - 1) | ||||
|
r1066 | step = start > end and -1 or 1 | ||
for rev in xrange(start, end+step, step): | ||||
|
r1615 | if rev in seen: | ||
continue | ||||
|
r1146 | seen[rev] = 1 | ||
|
r580 | yield str(rev) | ||
else: | ||||
|
r1146 | rev = fix(spec, None) | ||
|
r1615 | if rev in seen: | ||
continue | ||||
|
r1146 | seen[rev] = 1 | ||
yield str(rev) | ||||
|
r580 | |||
|
r739 | def make_filename(repo, r, pat, node=None, | ||
|
r1254 | total=None, seqno=None, revwidth=None, pathname=None): | ||
|
r632 | node_expander = { | ||
|
r1092 | 'H': lambda: hex(node), | ||
|
r632 | 'R': lambda: str(r.rev(node)), | ||
|
r1092 | 'h': lambda: short(node), | ||
|
r632 | } | ||
expander = { | ||||
'%': lambda: '%', | ||||
'b': lambda: os.path.basename(repo.root), | ||||
} | ||||
|
r727 | try: | ||
if node: | ||||
expander.update(node_expander) | ||||
if node and revwidth is not None: | ||||
expander['r'] = lambda: str(r.rev(node)).zfill(revwidth) | ||||
if total is not None: | ||||
expander['N'] = lambda: str(total) | ||||
if seqno is not None: | ||||
expander['n'] = lambda: str(seqno) | ||||
if total is not None and seqno is not None: | ||||
expander['n'] = lambda:str(seqno).zfill(len(str(total))) | ||||
|
r1254 | if pathname is not None: | ||
expander['s'] = lambda: os.path.basename(pathname) | ||||
expander['d'] = lambda: os.path.dirname(pathname) or '.' | ||||
expander['p'] = lambda: pathname | ||||
|
r632 | |||
|
r727 | newname = [] | ||
patlen = len(pat) | ||||
i = 0 | ||||
while i < patlen: | ||||
c = pat[i] | ||||
if c == '%': | ||||
i += 1 | ||||
c = pat[i] | ||||
c = expander[c]() | ||||
newname.append(c) | ||||
|
r632 | i += 1 | ||
|
r739 | return ''.join(newname) | ||
|
r727 | except KeyError, inst: | ||
|
r1402 | raise util.Abort(_("invalid format spec '%%%s' in output file name"), | ||
|
r727 | inst.args[0]) | ||
|
r632 | |||
|
r739 | def make_file(repo, r, pat, node=None, | ||
|
r1254 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): | ||
|
r739 | if not pat or pat == '-': | ||
|
r1065 | return 'w' in mode and sys.stdout or sys.stdin | ||
|
r739 | if hasattr(pat, 'write') and 'w' in mode: | ||
return pat | ||||
if hasattr(pat, 'read') and 'r' in mode: | ||||
return pat | ||||
|
r1254 | return open(make_filename(repo, r, pat, node, total, seqno, revwidth, | ||
pathname), | ||||
|
r739 | mode) | ||
|
r1974 | def write_bundle(cg, filename=None, compress=True): | ||
"""Write a bundle file and return its filename. | ||||
Existing files will not be overwritten. | ||||
If no filename is specified, a temporary file is created. | ||||
bz2 compression can be turned off. | ||||
The bundle file will be deleted in case of errors. | ||||
|
r1972 | """ | ||
|
r1943 | class nocompress(object): | ||
def compress(self, x): | ||||
return x | ||||
def flush(self): | ||||
return "" | ||||
|
r1974 | |||
fh = None | ||||
cleanup = None | ||||
|
r1943 | try: | ||
|
r1974 | if filename: | ||
if os.path.exists(filename): | ||||
raise util.Abort(_("file '%s' already exists"), filename) | ||||
fh = open(filename, "wb") | ||||
else: | ||||
fd, filename = tempfile.mkstemp(suffix=".hg", prefix="hg-bundle-") | ||||
fh = os.fdopen(fd, "wb") | ||||
cleanup = filename | ||||
|
r1943 | if compress: | ||
fh.write("HG10") | ||||
z = bz2.BZ2Compressor(9) | ||||
else: | ||||
fh.write("HG11") | ||||
z = nocompress() | ||||
while 1: | ||||
chunk = cg.read(4096) | ||||
if not chunk: | ||||
break | ||||
fh.write(z.compress(chunk)) | ||||
fh.write(z.flush()) | ||||
|
r1974 | cleanup = None | ||
return filename | ||||
finally: | ||||
if fh is not None: | ||||
fh.close() | ||||
if cleanup is not None: | ||||
os.unlink(cleanup) | ||||
|
r1943 | |||
|
r1014 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, | ||
|
r1728 | changes=None, text=False, opts={}): | ||
|
r1804 | if not node1: | ||
node1 = repo.dirstate.parents()[0] | ||||
# reading the data for node1 early allows it to play nicely | ||||
# with repo.changes and the revlog cache. | ||||
change = repo.changelog.read(node1) | ||||
mmap = repo.manifest.read(change[0]) | ||||
date1 = util.datestr(change[2]) | ||||
|
r1803 | |||
|
r904 | if not changes: | ||
|
r1618 | changes = repo.changes(node1, node2, files, match=match) | ||
|
r1619 | modified, added, removed, deleted, unknown = changes | ||
|
r537 | if files: | ||
|
r1626 | modified, added, removed = map(lambda x: filterfiles(files, x), | ||
|
r1618 | (modified, added, removed)) | ||
|
r537 | |||
|
r1618 | if not modified and not added and not removed: | ||
|
r537 | return | ||
|
r245 | if node2: | ||
change = repo.changelog.read(node2) | ||||
mmap2 = repo.manifest.read(change[0]) | ||||
|
r1321 | date2 = util.datestr(change[2]) | ||
|
r697 | def read(f): | ||
return repo.file(f).read(mmap2[f]) | ||||
|
r245 | else: | ||
|
r1320 | date2 = util.datestr() | ||
|
r697 | def read(f): | ||
|
r1648 | return repo.wread(f) | ||
|
r245 | |||
|
r396 | if ui.quiet: | ||
r = None | ||||
else: | ||||
|
r1092 | hexfunc = ui.verbose and hex or short | ||
|
r396 | r = [hexfunc(node) for node in [node1, node2] if node] | ||
|
r1637 | diffopts = ui.diffopts() | ||
|
r1728 | showfunc = opts.get('show_function') or diffopts['showfunc'] | ||
ignorews = opts.get('ignore_all_space') or diffopts['ignorews'] | ||||
|
r1618 | for f in modified: | ||
|
r275 | to = None | ||
if f in mmap: | ||||
to = repo.file(f).read(mmap[f]) | ||||
|
r245 | tn = read(f) | ||
|
r1637 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | ||
showfunc=showfunc, ignorews=ignorews)) | ||||
|
r1618 | for f in added: | ||
|
r264 | to = None | ||
|
r245 | tn = read(f) | ||
|
r1637 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | ||
showfunc=showfunc, ignorews=ignorews)) | ||||
|
r1618 | for f in removed: | ||
|
r245 | to = repo.file(f).read(mmap[f]) | ||
|
r264 | tn = None | ||
|
r1637 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | ||
showfunc=showfunc, ignorews=ignorews)) | ||||
|
r329 | |||
|
r1147 | def trimuser(ui, name, rev, revcache): | ||
|
r1146 | """trim the name of the user who committed a change""" | ||
|
r1147 | user = revcache.get(rev) | ||
if user is None: | ||||
user = revcache[rev] = ui.shortuser(name) | ||||
return user | ||||
|
r1146 | |||
|
r1907 | class changeset_templater(object): | ||
|
r1909 | '''use templater module to format changeset information.''' | ||
|
r1907 | def __init__(self, ui, repo, mapfile): | ||
|
r1913 | self.t = templater.templater(mapfile, templater.common_filters, | ||
cache={'parent': '{rev}:{node|short} ', | ||||
'manifest': '{rev}:{node|short}'}) | ||||
|
r1907 | self.ui = ui | ||
self.repo = repo | ||||
def use_template(self, t): | ||||
|
r1909 | '''set template string to use''' | ||
|
r1914 | self.t.cache['changeset'] = t | ||
|
r1907 | |||
def write(self, thing): | ||||
|
r1909 | '''write expanded template. | ||
uses in-order recursive traverse of iterators.''' | ||||
|
r1907 | for t in thing: | ||
if hasattr(t, '__iter__'): | ||||
self.write(t) | ||||
else: | ||||
self.ui.write(t) | ||||
def show(self, rev=0, changenode=None, brinfo=None): | ||||
|
r1909 | '''show a single changeset or file revision''' | ||
|
r1907 | log = self.repo.changelog | ||
if changenode is None: | ||||
changenode = log.node(rev) | ||||
elif not rev: | ||||
rev = log.rev(changenode) | ||||
changes = log.read(changenode) | ||||
def showlist(name, values, plural=None, **args): | ||||
|
r1909 | '''expand set of values. | ||
name is name of key in template map. | ||||
values is list of strings or dicts. | ||||
plural is plural of name, if not simply name + 's'. | ||||
expansion works like this, given name 'foo'. | ||||
if values is empty, expand 'no_foos'. | ||||
if 'foo' not in template map, return values as a string, | ||||
joined by space. | ||||
expand 'start_foos'. | ||||
for each value, expand 'foo'. if 'last_foo' in template | ||||
map, expand it instead of 'foo' for last key. | ||||
expand 'end_foos'. | ||||
''' | ||||
|
r1907 | if plural: names = plural | ||
else: names = name + 's' | ||||
if not values: | ||||
noname = 'no_' + names | ||||
if noname in self.t: | ||||
yield self.t(noname, **args) | ||||
return | ||||
if name not in self.t: | ||||
|
r1913 | if isinstance(values[0], str): | ||
yield ' '.join(values) | ||||
else: | ||||
for v in values: | ||||
yield dict(v, **args) | ||||
|
r1907 | return | ||
startname = 'start_' + names | ||||
if startname in self.t: | ||||
yield self.t(startname, **args) | ||||
|
r1909 | vargs = args.copy() | ||
|
r1908 | def one(v, tag=name): | ||
|
r1907 | try: | ||
vargs.update(v) | ||||
|
r1937 | except (AttributeError, ValueError): | ||
try: | ||||
for a, b in v: | ||||
vargs[a] = b | ||||
except ValueError: | ||||
vargs[name] = v | ||||
|
r1908 | return self.t(tag, **vargs) | ||
|
r1907 | lastname = 'last_' + name | ||
if lastname in self.t: | ||||
last = values.pop() | ||||
else: | ||||
last = None | ||||
for v in values: | ||||
yield one(v) | ||||
if last is not None: | ||||
|
r1908 | yield one(last, tag=lastname) | ||
|
r1907 | endname = 'end_' + names | ||
if endname in self.t: | ||||
yield self.t(endname, **args) | ||||
if brinfo: | ||||
def showbranches(**args): | ||||
if changenode in brinfo: | ||||
for x in showlist('branch', brinfo[changenode], | ||||
plural='branches', **args): | ||||
yield x | ||||
else: | ||||
showbranches = '' | ||||
|
r1910 | if self.ui.debugflag: | ||
def showmanifest(**args): | ||||
args = args.copy() | ||||
|
r1937 | args.update(dict(rev=self.repo.manifest.rev(changes[0]), | ||
node=hex(changes[0]))) | ||||
|
r1910 | yield self.t('manifest', **args) | ||
else: | ||||
showmanifest = '' | ||||
|
r1907 | |||
def showparents(**args): | ||||
parents = [[('rev', log.rev(p)), ('node', hex(p))] | ||||
for p in log.parents(changenode) | ||||
if self.ui.debugflag or p != nullid] | ||||
if (not self.ui.debugflag and len(parents) == 1 and | ||||
parents[0][0][1] == rev - 1): | ||||
return | ||||
for x in showlist('parent', parents, **args): | ||||
yield x | ||||
def showtags(**args): | ||||
for x in showlist('tag', self.repo.nodetags(changenode), **args): | ||||
yield x | ||||
if self.ui.debugflag: | ||||
files = self.repo.changes(log.parents(changenode)[0], changenode) | ||||
def showfiles(**args): | ||||
for x in showlist('file', files[0], **args): yield x | ||||
def showadds(**args): | ||||
for x in showlist('file_add', files[1], **args): yield x | ||||
def showdels(**args): | ||||
for x in showlist('file_del', files[2], **args): yield x | ||||
else: | ||||
def showfiles(**args): | ||||
for x in showlist('file', changes[3], **args): yield x | ||||
showadds = '' | ||||
showdels = '' | ||||
props = { | ||||
'author': changes[1], | ||||
'branches': showbranches, | ||||
'date': changes[2], | ||||
'desc': changes[4], | ||||
'file_adds': showadds, | ||||
'file_dels': showdels, | ||||
'files': showfiles, | ||||
'manifest': showmanifest, | ||||
'node': hex(changenode), | ||||
'parents': showparents, | ||||
'rev': rev, | ||||
'tags': showtags, | ||||
} | ||||
try: | ||||
|
r1917 | if self.ui.debugflag and 'changeset_debug' in self.t: | ||
key = 'changeset_debug' | ||||
elif self.ui.quiet and 'changeset_quiet' in self.t: | ||||
key = 'changeset_quiet' | ||||
elif self.ui.verbose and 'changeset_verbose' in self.t: | ||||
|
r1914 | key = 'changeset_verbose' | ||
|
r1913 | else: | ||
|
r1914 | key = 'changeset' | ||
|
r1913 | self.write(self.t(key, **props)) | ||
|
r1907 | except KeyError, inst: | ||
raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile, | ||||
inst.args[0])) | ||||
except SyntaxError, inst: | ||||
raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0])) | ||||
class changeset_printer(object): | ||||
|
r1909 | '''show changeset information when templating not requested.''' | ||
|
r1907 | def __init__(self, ui, repo): | ||
self.ui = ui | ||||
self.repo = repo | ||||
def show(self, rev=0, changenode=None, brinfo=None): | ||||
|
r1909 | '''show a single changeset or file revision''' | ||
|
r1907 | log = self.repo.changelog | ||
if changenode is None: | ||||
changenode = log.node(rev) | ||||
elif not rev: | ||||
rev = log.rev(changenode) | ||||
if self.ui.quiet: | ||||
self.ui.write("%d:%s\n" % (rev, short(changenode))) | ||||
return | ||||
changes = log.read(changenode) | ||||
date = util.datestr(changes[2]) | ||||
parents = [(log.rev(p), self.ui.verbose and hex(p) or short(p)) | ||||
for p in log.parents(changenode) | ||||
if self.ui.debugflag or p != nullid] | ||||
if (not self.ui.debugflag and len(parents) == 1 and | ||||
parents[0][0] == rev-1): | ||||
parents = [] | ||||
if self.ui.verbose: | ||||
self.ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode))) | ||||
else: | ||||
self.ui.write(_("changeset: %d:%s\n") % (rev, short(changenode))) | ||||
for tag in self.repo.nodetags(changenode): | ||||
self.ui.status(_("tag: %s\n") % tag) | ||||
for parent in parents: | ||||
self.ui.write(_("parent: %d:%s\n") % parent) | ||||
if brinfo and changenode in brinfo: | ||||
br = brinfo[changenode] | ||||
self.ui.write(_("branch: %s\n") % " ".join(br)) | ||||
self.ui.debug(_("manifest: %d:%s\n") % | ||||
(self.repo.manifest.rev(changes[0]), hex(changes[0]))) | ||||
self.ui.status(_("user: %s\n") % changes[1]) | ||||
self.ui.status(_("date: %s\n") % date) | ||||
if self.ui.debugflag: | ||||
files = self.repo.changes(log.parents(changenode)[0], changenode) | ||||
for key, value in zip([_("files:"), _("files+:"), _("files-:")], | ||||
files): | ||||
if value: | ||||
self.ui.note("%-12s %s\n" % (key, " ".join(value))) | ||||
else: | ||||
self.ui.note(_("files: %s\n") % " ".join(changes[3])) | ||||
description = changes[4].strip() | ||||
if description: | ||||
if self.ui.verbose: | ||||
self.ui.status(_("description:\n")) | ||||
self.ui.status(description) | ||||
self.ui.status("\n\n") | ||||
else: | ||||
self.ui.status(_("summary: %s\n") % | ||||
description.splitlines()[0]) | ||||
self.ui.status("\n") | ||||
def show_changeset(ui, repo, opts): | ||||
|
r1909 | '''show one changeset. uses template or regular display. caller | ||
|
r1913 | can pass in 'style' and 'template' options in opts.''' | ||
|
r1909 | |||
|
r1907 | tmpl = opts.get('template') | ||
if tmpl: | ||||
tmpl = templater.parsestring(tmpl, quoted=False) | ||||
|
r778 | else: | ||
|
r1907 | tmpl = ui.config('ui', 'logtemplate') | ||
if tmpl: tmpl = templater.parsestring(tmpl) | ||||
|
r1914 | mapfile = opts.get('style') or ui.config('ui', 'style') | ||
|
r1907 | if tmpl or mapfile: | ||
if mapfile: | ||||
if not os.path.isfile(mapfile): | ||||
|
r1914 | mapname = templater.templatepath('map-cmdline.' + mapfile) | ||
if not mapname: mapname = templater.templatepath(mapfile) | ||||
|
r1907 | if mapname: mapfile = mapname | ||
try: | ||||
t = changeset_templater(ui, repo, mapfile) | ||||
except SyntaxError, inst: | ||||
raise util.Abort(inst.args[0]) | ||||
if tmpl: t.use_template(tmpl) | ||||
return t | ||||
return changeset_printer(ui, repo) | ||||
|
r329 | |||
|
r470 | def show_version(ui): | ||
|
r423 | """output version and copyright information""" | ||
|
r1402 | ui.write(_("Mercurial Distributed SCM (version %s)\n") | ||
|
r849 | % version.get_version()) | ||
|
r1402 | ui.status(_( | ||
|
r423 | "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" | ||
"This is free software; see the source for copying conditions. " | ||||
"There is NO\nwarranty; " | ||||
"not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | ||||
|
r1402 | )) | ||
|
r423 | |||
|
r1049 | def help_(ui, cmd=None, with_version=False): | ||
|
r697 | """show help for a given command or all commands""" | ||
|
r1052 | option_lists = [] | ||
|
r846 | if cmd and cmd != 'shortlist': | ||
|
r1049 | if with_version: | ||
show_version(ui) | ||||
ui.write('\n') | ||||
|
r1517 | aliases, i = find(cmd) | ||
|
r849 | # synopsis | ||
|
r848 | ui.write("%s\n\n" % i[2]) | ||
|
r293 | |||
|
r849 | # description | ||
doc = i[0].__doc__ | ||||
|
r1710 | if not doc: | ||
doc = _("(No help text available)") | ||||
|
r849 | if ui.quiet: | ||
doc = doc.splitlines(0)[0] | ||||
ui.write("%s\n" % doc.rstrip()) | ||||
if not ui.quiet: | ||||
|
r1052 | # aliases | ||
|
r1517 | if len(aliases) > 1: | ||
ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) | ||||
|
r849 | |||
|
r1052 | # options | ||
if i[1]: | ||||
option_lists.append(("options", i[1])) | ||||
|
r293 | |||
|
r255 | else: | ||
|
r849 | # program name | ||
|
r1049 | if ui.verbose or with_version: | ||
|
r470 | show_version(ui) | ||
|
r849 | else: | ||
|
r1402 | ui.status(_("Mercurial Distributed SCM\n")) | ||
|
r849 | ui.status('\n') | ||
|
r843 | |||
|
r849 | # list of commands | ||
|
r846 | if cmd == "shortlist": | ||
|
r1402 | ui.status(_('basic commands (use "hg help" ' | ||
'for the full list or option "-v" for details):\n\n')) | ||||
|
r849 | elif ui.verbose: | ||
|
r1402 | ui.status(_('list of commands:\n\n')) | ||
|
r849 | else: | ||
|
r1402 | ui.status(_('list of commands (use "hg help -v" ' | ||
'to show aliases and global options):\n\n')) | ||||
|
r209 | |||
|
r255 | h = {} | ||
|
r844 | cmds = {} | ||
|
r479 | for c, e in table.items(): | ||
f = c.split("|")[0] | ||||
|
r846 | if cmd == "shortlist" and not f.startswith("^"): | ||
|
r479 | continue | ||
|
r849 | f = f.lstrip("^") | ||
|
r593 | if not ui.debugflag and f.startswith("debug"): | ||
continue | ||||
|
r1710 | doc = e[0].__doc__ | ||
if not doc: | ||||
doc = _("(No help text available)") | ||||
h[f] = doc.splitlines(0)[0].rstrip() | ||||
|
r1615 | cmds[f] = c.lstrip("^") | ||
|
r255 | |||
fns = h.keys() | ||||
fns.sort() | ||||
m = max(map(len, fns)) | ||||
for f in fns: | ||||
|
r844 | if ui.verbose: | ||
commands = cmds[f].replace("|",", ") | ||||
|
r1615 | ui.write(" %s:\n %s\n"%(commands, h[f])) | ||
|
r844 | else: | ||
ui.write(' %-*s %s\n' % (m, f, h[f])) | ||||
|
r255 | |||
|
r849 | # global options | ||
if ui.verbose: | ||||
|
r1052 | option_lists.append(("global options", globalopts)) | ||
# list all option lists | ||||
opt_output = [] | ||||
for title, options in option_lists: | ||||
opt_output.append(("\n%s:\n" % title, None)) | ||||
for shortopt, longopt, default, desc in options: | ||||
opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, | ||||
longopt and " --%s" % longopt), | ||||
"%s%s" % (desc, | ||||
|
r1602 | default | ||
and _(" (default: %s)") % default | ||||
|
r1052 | or ""))) | ||
if opt_output: | ||||
opts_len = max([len(line[0]) for line in opt_output if line[1]]) | ||||
for first, second in opt_output: | ||||
if second: | ||||
ui.write(" %-*s %s\n" % (opts_len, first, second)) | ||||
else: | ||||
ui.write("%s\n" % first) | ||||
|
r849 | |||
|
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. | ||||
The files will be added to the repository at the next commit. | ||||
|
r1568 | If no names are given, add all files in the repository. | ||
|
r1437 | """ | ||
|
r724 | names = [] | ||
|
r942 | for src, abs, rel, exact in walk(repo, pats, opts): | ||
if exact: | ||||
|
r1615 | if ui.verbose: | ||
ui.status(_('adding %s\n') % rel) | ||||
|
r724 | names.append(abs) | ||
elif repo.dirstate.state(abs) == '?': | ||||
|
r1402 | ui.status(_('adding %s\n') % rel) | ||
|
r724 | names.append(abs) | ||
repo.add(names) | ||||
|
r213 | |||
|
r766 | def addremove(ui, repo, *pats, **opts): | ||
|
r1437 | """add all new files, delete all missing files | ||
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. | ||||
""" | ||||
|
r1712 | return addremove_lock(ui, repo, pats, opts) | ||
def addremove_lock(ui, repo, pats, opts, wlock=None): | ||||
|
r809 | add, remove = [], [] | ||
|
r942 | for src, abs, rel, exact in walk(repo, pats, opts): | ||
|
r880 | if src == 'f' and repo.dirstate.state(abs) == '?': | ||
add.append(abs) | ||||
|
r1255 | if ui.verbose or not exact: | ||
|
r1625 | ui.status(_('adding %s\n') % ((pats and rel) or abs)) | ||
|
r880 | if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): | ||
|
r809 | remove.append(abs) | ||
|
r1255 | if ui.verbose or not exact: | ||
|
r1625 | ui.status(_('removing %s\n') % ((pats and rel) or abs)) | ||
|
r1712 | repo.add(add, wlock=wlock) | ||
repo.remove(remove, wlock=wlock) | ||||
|
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. | ||||
""" | ||||
|
r209 | def getnode(rev): | ||
|
r1092 | return short(repo.changelog.node(rev)) | ||
|
r209 | |||
|
r1146 | ucache = {} | ||
|
r209 | def getname(rev): | ||
|
r1146 | cl = repo.changelog.read(repo.changelog.node(rev)) | ||
|
r1147 | return trimuser(ui, cl[1], rev, ucache) | ||
|
r500 | |||
|
r1522 | dcache = {} | ||
def getdate(rev): | ||||
|
r1615 | datestr = dcache.get(rev) | ||
|
r1522 | if datestr is None: | ||
cl = repo.changelog.read(repo.changelog.node(rev)) | ||||
datestr = dcache[rev] = util.datestr(cl[2]) | ||||
|
r1615 | return datestr | ||
|
r1522 | |||
|
r744 | if not pats: | ||
|
r1402 | raise util.Abort(_('at least one file name or pattern required')) | ||
|
r744 | |||
|
r1523 | opmap = [['user', getname], ['number', str], ['changeset', getnode], | ||
['date', getdate]] | ||||
|
r1522 | if not opts['user'] and not opts['changeset'] and not opts['date']: | ||
|
r714 | opts['number'] = 1 | ||
|
r209 | |||
|
r715 | if opts['rev']: | ||
node = repo.changelog.lookup(opts['rev']) | ||||
|
r714 | else: | ||
node = repo.dirstate.parents()[0] | ||||
|
r209 | change = repo.changelog.read(node) | ||
mmap = repo.manifest.read(change[0]) | ||||
|
r1016 | |||
|
r1847 | for src, abs, rel, exact in walk(repo, pats, opts, node=node): | ||
|
r1016 | f = repo.file(abs) | ||
if not opts['text'] and util.binary(f.read(mmap[abs])): | ||||
|
r1625 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) | ||
|
r1016 | continue | ||
lines = f.annotate(mmap[abs]) | ||||
|
r209 | pieces = [] | ||
for o, f in opmap: | ||||
|
r714 | if opts[o]: | ||
|
r697 | l = [f(n) for n, dummy in lines] | ||
|
r771 | 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 | |||
|
r1218 | def bundle(ui, repo, fname, dest="default-push", **opts): | ||
|
r1437 | """create a changegroup file | ||
Generate a compressed changegroup file collecting all changesets | ||||
not found in the other repository. | ||||
This file can then be transferred using conventional means and | ||||
applied to another repository with the unbundle command. This is | ||||
useful when native push and pull are not available or when | ||||
exporting an entire repository is undesirable. The standard file | ||||
extension is ".hg". | ||||
Unlike import/export, this exactly preserves all changeset | ||||
contents including permissions, rename data, and revision history. | ||||
""" | ||||
|
r1893 | dest = ui.expandpath(dest) | ||
|
r1218 | other = hg.repository(ui, dest) | ||
|
r1959 | o = repo.findoutgoing(other, force=opts['force']) | ||
|
r1736 | cg = repo.changegroup(o, 'bundle') | ||
|
r1943 | write_bundle(cg, fname) | ||
|
r1218 | |||
|
r1254 | def cat(ui, repo, file1, *pats, **opts): | ||
|
r1437 | """output the latest or given revisions of files | ||
Print the specified files as they were at the given revision. | ||||
If no revision is given then the tip is used. | ||||
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 | ||||
""" | ||||
|
r1254 | mf = {} | ||
|
r1545 | rev = opts['rev'] | ||
if rev: | ||||
|
r1582 | node = repo.lookup(rev) | ||
else: | ||||
node = repo.changelog.tip() | ||||
change = repo.changelog.read(node) | ||||
mf = repo.manifest.read(change[0]) | ||||
for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node): | ||||
|
r1254 | r = repo.file(abs) | ||
|
r1582 | n = mf[abs] | ||
|
r1254 | fp = make_file(repo, r, opts['output'], node=n, pathname=abs) | ||
fp.write(r.read(n)) | ||||
|
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 | ||||
and destination are on the same filesystem. Some filesystems, | ||||
such as AFS, implement hardlinking incorrectly, but do not report | ||||
errors. In these cases, use the --pull option to avoid | ||||
hardlinking. | ||||
|
r1811 | |||
See pull for valid source format details. | ||||
|
r1437 | """ | ||
|
r485 | if dest is None: | ||
|
r528 | dest = os.path.basename(os.path.normpath(source)) | ||
|
r532 | |||
if os.path.exists(dest): | ||||
|
r1402 | raise util.Abort(_("destination '%s' already exists"), dest) | ||
|
r523 | |||
|
r891 | dest = os.path.realpath(dest) | ||
|
r1559 | class Dircleanup(object): | ||
|
r697 | def __init__(self, dir_): | ||
|
r625 | self.rmtree = shutil.rmtree | ||
|
r697 | self.dir_ = dir_ | ||
os.mkdir(dir_) | ||||
|
r535 | def close(self): | ||
|
r697 | self.dir_ = None | ||
|
r535 | def __del__(self): | ||
|
r697 | if self.dir_: | ||
self.rmtree(self.dir_, True) | ||||
|
r485 | |||
|
r963 | if opts['ssh']: | ||
ui.setconfig("ui", "ssh", opts['ssh']) | ||||
if opts['remotecmd']: | ||||
ui.setconfig("ui", "remotecmd", opts['remotecmd']) | ||||
|
r1892 | source = ui.expandpath(source) | ||
|
r1314 | |||
d = Dircleanup(dest) | ||||
|
r562 | abspath = source | ||
|
r634 | other = hg.repository(ui, source) | ||
|
r485 | |||
|
r1244 | copy = False | ||
|
r1315 | if other.dev() != -1: | ||
|
r675 | abspath = os.path.abspath(source) | ||
|
r1461 | if not opts['pull'] and not opts['rev']: | ||
|
r1315 | copy = True | ||
|
r1331 | |||
|
r1244 | if copy: | ||
try: | ||||
# we use a lock here because if we race with commit, we | ||||
# can end up with extra data in the cloned revlogs that's | ||||
# not pointed to by changesets, thus causing verify to | ||||
# fail | ||||
|
r1754 | l1 = other.lock() | ||
except lock.LockException: | ||||
|
r1244 | copy = False | ||
|
r917 | |||
|
r1244 | if copy: | ||
# we lock here to avoid premature writing to the target | ||||
|
r1208 | os.mkdir(os.path.join(dest, ".hg")) | ||
|
r1209 | l2 = lock.lock(os.path.join(dest, ".hg", "lock")) | ||
|
r1114 | |||
|
r1208 | files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i" | ||
for f in files.split(): | ||||
src = os.path.join(source, ".hg", f) | ||||
dst = os.path.join(dest, ".hg", f) | ||||
|
r1444 | try: | ||
util.copyfiles(src, dst) | ||||
except OSError, inst: | ||||
|
r1615 | if inst.errno != errno.ENOENT: | ||
raise | ||||
|
r535 | |||
repo = hg.repository(ui, dest) | ||||
|
r485 | |||
|
r535 | else: | ||
|
r1467 | revs = None | ||
|
r1461 | if opts['rev']: | ||
|
r1465 | if not other.local(): | ||
|
r1607 | error = _("clone -r not supported yet for remote repositories.") | ||
|
r1602 | raise util.Abort(error) | ||
|
r1465 | else: | ||
revs = [other.lookup(rev) for rev in opts['rev']] | ||||
repo = hg.repository(ui, dest, create=1) | ||||
repo.pull(other, heads = revs) | ||||
|
r503 | |||
|
r1331 | f = repo.opener("hgrc", "w", text=True) | ||
|
r1206 | f.write("[paths]\n") | ||
f.write("default = %s\n" % abspath) | ||||
|
r1547 | f.close() | ||
|
r515 | |||
|
r535 | if not opts['noupdate']: | ||
|
r1839 | update(repo.ui, repo) | ||
|
r535 | |||
d.close() | ||||
|
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" | ||||
|
r1568 | will be commited. | ||
|
r1437 | |||
The HGEDITOR or EDITOR environment variables are used to start an | ||||
editor to add a commit comment. | ||||
""" | ||||
|
r1443 | message = opts['message'] | ||
|
r697 | logfile = opts['logfile'] | ||
|
r1319 | |||
if message and logfile: | ||||
|
r1402 | raise util.Abort(_('options --message and --logfile are mutually ' | ||
'exclusive')) | ||||
|
r762 | if not message and logfile: | ||
|
r697 | try: | ||
|
r899 | if logfile == '-': | ||
message = sys.stdin.read() | ||||
else: | ||||
message = open(logfile).read() | ||||
|
r1319 | except IOError, inst: | ||
|
r1402 | raise util.Abort(_("can't read commit message '%s': %s") % | ||
|
r1319 | (logfile, inst.strerror)) | ||
|
r289 | |||
|
r354 | if opts['addremove']: | ||
|
r813 | addremove(ui, repo, *pats, **opts) | ||
|
r1625 | fns, match, anypats = matchpats(repo, pats, opts) | ||
|
r813 | if pats: | ||
|
r1619 | modified, added, removed, deleted, unknown = ( | ||
|
r1618 | repo.changes(files=fns, match=match)) | ||
|
r1619 | files = modified + added + removed | ||
|
r813 | else: | ||
files = [] | ||||
|
r1202 | try: | ||
repo.commit(files, message, opts['user'], opts['date'], match) | ||||
except ValueError, inst: | ||||
raise util.Abort(str(inst)) | ||||
|
r245 | |||
|
r1822 | def docopy(ui, repo, pats, opts, wlock): | ||
# called with the repo lock held | ||||
|
r1512 | cwd = repo.getcwd() | ||
errors = 0 | ||||
copied = [] | ||||
|
r1514 | targets = {} | ||
|
r1249 | |||
def okaytocopy(abs, rel, exact): | ||||
|
r1402 | reasons = {'?': _('is not managed'), | ||
|
r1634 | 'a': _('has been marked for add'), | ||
'r': _('has been marked for remove')} | ||||
|
r1747 | state = repo.dirstate.state(abs) | ||
reason = reasons.get(state) | ||||
|
r1249 | if reason: | ||
|
r1747 | if state == 'a': | ||
origsrc = repo.dirstate.copied(abs) | ||||
if origsrc is not None: | ||||
return origsrc | ||||
|
r1615 | if exact: | ||
ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) | ||||
|
r1249 | else: | ||
|
r1747 | return abs | ||
def copy(origsrc, abssrc, relsrc, target, exact): | ||||
|
r1512 | abstarget = util.canonpath(repo.root, cwd, target) | ||
reltarget = util.pathto(cwd, abstarget) | ||||
|
r1514 | prevsrc = targets.get(abstarget) | ||
if prevsrc is not None: | ||||
ui.warn(_('%s: not overwriting - %s collides with %s\n') % | ||||
(reltarget, abssrc, prevsrc)) | ||||
return | ||||
|
r1565 | if (not opts['after'] and os.path.exists(reltarget) or | ||
opts['after'] and repo.dirstate.state(abstarget) not in '?r'): | ||||
if not opts['force']: | ||||
|
r1513 | ui.warn(_('%s: not overwriting - file exists\n') % | ||
reltarget) | ||||
return | ||||
|
r1565 | if not opts['after']: | ||
os.unlink(reltarget) | ||||
if opts['after']: | ||||
if not os.path.exists(reltarget): | ||||
return | ||||
else: | ||||
|
r1512 | targetdir = os.path.dirname(reltarget) or '.' | ||
if not os.path.isdir(targetdir): | ||||
os.makedirs(targetdir) | ||||
|
r1249 | try: | ||
|
r1822 | restore = repo.dirstate.state(abstarget) == 'r' | ||
if restore: | ||||
repo.undelete([abstarget], wlock) | ||||
try: | ||||
shutil.copyfile(relsrc, reltarget) | ||||
shutil.copymode(relsrc, reltarget) | ||||
restore = False | ||||
finally: | ||||
if restore: | ||||
repo.remove([abstarget], wlock) | ||||
|
r1253 | except shutil.Error, inst: | ||
raise util.Abort(str(inst)) | ||||
|
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 | ||
|
r1822 | if abstarget != origsrc: | ||
repo.copy(origsrc, abstarget, wlock) | ||||
|
r1512 | copied.append((abssrc, relsrc, exact)) | ||
|
r1565 | def targetpathfn(pat, dest, srcs): | ||
if os.path.isdir(pat): | ||||
|
r1633 | abspfx = util.canonpath(repo.root, cwd, pat) | ||
|
r1565 | if destdirexists: | ||
|
r1633 | striplen = len(os.path.split(abspfx)[0]) | ||
|
r1565 | else: | ||
|
r1633 | striplen = len(abspfx) | ||
|
r1565 | if striplen: | ||
striplen += len(os.sep) | ||||
res = lambda p: os.path.join(dest, p[striplen:]) | ||||
elif destdirexists: | ||||
res = lambda p: os.path.join(dest, os.path.basename(p)) | ||||
else: | ||||
res = lambda p: dest | ||||
return res | ||||
def targetpathafterfn(pat, dest, srcs): | ||||
if util.patkind(pat, None)[0]: | ||||
# a mercurial pattern | ||||
res = lambda p: os.path.join(dest, os.path.basename(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: | ||||
t = os.path.join(dest, s[0][striplen:]) | ||||
if os.path.exists(t): | ||||
score += 1 | ||||
return score | ||||
|
r1565 | |||
|
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 | ||||
res = lambda p: os.path.join(dest, p[striplen:]) | ||||
|
r1565 | else: | ||
|
r1633 | # a file | ||
if destdirexists: | ||||
res = lambda p: os.path.join(dest, os.path.basename(p)) | ||||
else: | ||||
res = lambda p: dest | ||||
|
r1565 | return res | ||
|
r1512 | pats = list(pats) | ||
if not pats: | ||||
raise util.Abort(_('no source or destination specified')) | ||||
if len(pats) == 1: | ||||
raise util.Abort(_('no destination specified')) | ||||
dest = pats.pop() | ||||
destdirexists = os.path.isdir(dest) | ||||
|
r1565 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: | ||
|
r1512 | raise util.Abort(_('with multiple sources, destination must be an ' | ||
'existing directory')) | ||||
|
r1565 | if opts['after']: | ||
tfn = targetpathafterfn | ||||
else: | ||||
tfn = targetpathfn | ||||
copylist = [] | ||||
|
r1512 | for pat in pats: | ||
|
r1565 | srcs = [] | ||
|
r1512 | for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): | ||
|
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')) | ||||
for targetpath, srcs in copylist: | ||||
|
r1747 | 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. | ||||
This command takes effect in the next commit. | ||||
NOTE: This command should be treated as experimental. While it | ||||
should properly record copied files, this information is not yet | ||||
fully used by merge, nor fully reported by log. | ||||
""" | ||||
|
r1822 | try: | ||
wlock = repo.wlock(0) | ||||
errs, copied = docopy(ui, repo, pats, opts, wlock) | ||||
except lock.LockHeld, inst: | ||||
ui.warn(_("repository lock held by %s\n") % inst.args[0]) | ||||
errs = 1 | ||||
|
r1249 | return errs | ||
|
r363 | |||
|
r1262 | def debugancestor(ui, index, rev1, rev2): | ||
"""find the ancestor revision of two revisions in a given index""" | ||||
|
r1835 | 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))) | ||||
|
r1887 | def debugcomplete(ui, cmd): | ||
"""returns the completion list associated with the given command""" | ||||
clist = findpossible(cmd).keys() | ||||
clist.sort() | ||||
ui.write("%s\n" % " ".join(clist)) | ||||
|
r1755 | def debugrebuildstate(ui, repo, rev=None): | ||
"""rebuild the dirstate as it would look like for the given revision""" | ||||
if not rev: | ||||
rev = repo.changelog.tip() | ||||
else: | ||||
rev = repo.lookup(rev) | ||||
change = repo.changelog.read(rev) | ||||
n = change[0] | ||||
files = repo.manifest.readflags(n) | ||||
|
r1760 | wlock = repo.wlock() | ||
|
r1755 | repo.dirstate.rebuild(rev, files.iteritems()) | ||
|
r596 | def debugcheckstate(ui, repo): | ||
"""validate the correctness of the current dirstate""" | ||||
|
r460 | parent1, parent2 = repo.dirstate.parents() | ||
|
r555 | repo.dirstate.read() | ||
dc = repo.dirstate.map | ||||
|
r460 | keys = dc.keys() | ||
keys.sort() | ||||
m1n = repo.changelog.read(parent1)[0] | ||||
m2n = repo.changelog.read(parent2)[0] | ||||
m1 = repo.manifest.read(m1n) | ||||
m2 = repo.manifest.read(m2n) | ||||
errors = 0 | ||||
for f in dc: | ||||
state = repo.dirstate.state(f) | ||||
if state in "nr" and f not in m1: | ||||
|
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: | ||||
state = repo.dirstate.state(f) | ||||
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 | |||
|
r1858 | def debugconfig(ui, repo): | ||
|
r1053 | """show combined config settings from all hgrc files""" | ||
|
r1028 | for section, name, value in ui.walkconfig(): | ||
ui.write('%s.%s=%s\n' % (section, name, value)) | ||||
|
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) | ||||
repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) | ||||
|
r596 | def debugstate(ui, repo): | ||
"""show the contents of the current dirstate""" | ||||
|
r555 | repo.dirstate.read() | ||
dc = repo.dirstate.map | ||||
|
r460 | keys = dc.keys() | ||
keys.sort() | ||||
|
r697 | for file_ in keys: | ||
|
r791 | ui.write("%c %3o %10d %s %s\n" | ||
% (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], | ||||
time.strftime("%x %X", | ||||
time.localtime(dc[file_][3])), file_)) | ||||
|
r1116 | for f in repo.dirstate.copies: | ||
|
r1402 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f)) | ||
|
r460 | |||
|
r1039 | def debugdata(ui, file_, rev): | ||
"""dump the contents of an data file revision""" | ||||
|
r1835 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), | ||
file_[:-2] + ".i", file_) | ||||
|
r1313 | try: | ||
ui.write(r.revision(r.lookup(rev))) | ||||
except KeyError: | ||||
|
r1402 | raise util.Abort(_('invalid revision identifier %s'), rev) | ||
|
r1039 | |||
|
r697 | def debugindex(ui, file_): | ||
|
r596 | """dump the contents of an index file""" | ||
|
r1835 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") | ||
|
r582 | ui.write(" rev offset length base linkrev" + | ||
|
r989 | " nodeid p1 p2\n") | ||
|
r248 | for i in range(r.count()): | ||
e = r.index[i] | ||||
|
r989 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( | ||
|
r582 | i, e[0], e[1], e[2], e[3], | ||
|
r1092 | short(e[6]), short(e[4]), short(e[5]))) | ||
|
r248 | |||
|
r697 | def debugindexdot(ui, file_): | ||
|
r596 | """dump an index DAG as a .dot file""" | ||
|
r1835 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") | ||
|
r582 | ui.write("digraph G {\n") | ||
|
r248 | for i in range(r.count()): | ||
e = r.index[i] | ||||
|
r582 | ui.write("\t%d -> %d\n" % (r.rev(e[4]), i)) | ||
|
r1092 | if e[5] != nullid: | ||
|
r582 | ui.write("\t%d -> %d\n" % (r.rev(e[5]), i)) | ||
ui.write("}\n") | ||||
|
r248 | |||
|
r1116 | def debugrename(ui, repo, file, rev=None): | ||
|
r1194 | """dump rename information""" | ||
|
r1116 | r = repo.file(relpath(repo, [file])[0]) | ||
if rev: | ||||
try: | ||||
# assume all revision numbers are for changesets | ||||
n = repo.lookup(rev) | ||||
change = repo.changelog.read(n) | ||||
m = repo.manifest.read(change[0]) | ||||
n = m[relpath(repo, [file])[0]] | ||||
|
r1541 | except (hg.RepoError, KeyError): | ||
|
r1116 | n = r.lookup(rev) | ||
else: | ||||
n = r.tip() | ||||
m = r.renamed(n) | ||||
if m: | ||||
|
r1402 | ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1]))) | ||
|
r1116 | else: | ||
|
r1402 | ui.write(_("not renamed\n")) | ||
|
r1116 | |||
|
r820 | def debugwalk(ui, repo, *pats, **opts): | ||
|
r1053 | """show how files match on given patterns""" | ||
|
r820 | items = list(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. | ||||
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. | ||||
""" | ||||
|
r1015 | node1, node2 = None, None | ||
revs = [repo.lookup(x) for x in opts['rev']] | ||||
|
r396 | |||
|
r1014 | if len(revs) > 0: | ||
node1 = revs[0] | ||||
if len(revs) > 1: | ||||
node2 = revs[1] | ||||
|
r245 | if len(revs) > 2: | ||
|
r1402 | raise util.Abort(_("too many revisions to diff")) | ||
|
r245 | |||
|
r1625 | fns, matchfn, anypats = matchpats(repo, pats, opts) | ||
|
r1014 | |||
|
r1267 | dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, | ||
|
r1728 | text=opts['text'], opts=opts) | ||
|
r245 | |||
|
r580 | def doexport(ui, repo, changeset, seqno, total, revwidth, opts): | ||
|
r246 | node = repo.lookup(changeset) | ||
|
r1571 | parents = [p for p in repo.changelog.parents(node) if p != nullid] | ||
|
r1589 | if opts['switch_parent']: | ||
parents.reverse() | ||||
|
r1571 | prev = (parents and parents[0]) or nullid | ||
|
r246 | change = repo.changelog.read(node) | ||
|
r580 | |||
|
r729 | fp = make_file(repo, repo.changelog, opts['output'], | ||
node=node, total=total, seqno=seqno, | ||||
revwidth=revwidth) | ||||
if fp != sys.stdout: | ||||
|
r755 | ui.note("%s\n" % fp.name) | ||
|
r580 | |||
|
r582 | fp.write("# HG changeset patch\n") | ||
fp.write("# User %s\n" % change[1]) | ||||
|
r1092 | fp.write("# Node ID %s\n" % hex(node)) | ||
fp.write("# Parent %s\n" % hex(prev)) | ||||
|
r1571 | if len(parents) > 1: | ||
fp.write("# Parent %s\n" % hex(parents[1])) | ||||
|
r582 | fp.write(change[4].rstrip()) | ||
fp.write("\n\n") | ||||
|
r580 | |||
|
r1015 | dodiff(fp, ui, repo, prev, node, text=opts['text']) | ||
|
r1065 | if fp != sys.stdout: | ||
fp.close() | ||||
|
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, | ||||
changeset hash, parent and commit comment. | ||||
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")) | ||
|
r580 | seqno = 0 | ||
revs = list(revrange(ui, repo, changesets)) | ||||
total = len(revs) | ||||
|
r1067 | revwidth = max(map(len, revs)) | ||
|
r1602 | msg = len(revs) > 1 and _("Exporting patches:\n") or _("Exporting patch:\n") | ||
ui.note(msg) | ||||
|
r580 | for cset in revs: | ||
seqno += 1 | ||||
doexport(ui, repo, cset, seqno, total, revwidth, opts) | ||||
|
r246 | |||
|
r810 | def forget(ui, repo, *pats, **opts): | ||
|
r1437 | """don't add the specified files on the next commit | ||
Undo an 'hg add' scheduled for the next commit. | ||||
""" | ||||
|
r810 | forget = [] | ||
|
r942 | for src, abs, rel, exact in walk(repo, pats, opts): | ||
|
r810 | if repo.dirstate.state(abs) == 'a': | ||
forget.append(abs) | ||||
|
r1255 | if ui.verbose or not exact: | ||
|
r1625 | ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) | ||
|
r810 | repo.forget(forget) | ||
|
r245 | |||
|
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 | ||||
|
r1057 | regexp = re.compile(pattern, reflags) | ||
|
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 | ||||
|
r1065 | def __eq__(self, other): | ||
return self.line == other.line | ||||
def __hash__(self): | ||||
return hash(self.line) | ||||
|
r1057 | |||
matches = {} | ||||
def grepbody(fn, rev, body): | ||||
matches[rev].setdefault(fn, {}) | ||||
m = matches[rev][fn] | ||||
for lnum, cstart, cend, line in matchlines(body): | ||||
s = linestate(line, lnum, cstart, cend) | ||||
m[s] = s | ||||
|
r1749 | # FIXME: prev isn't used, why ? | ||
|
r1057 | prev = {} | ||
|
r1146 | ucache = {} | ||
|
r1057 | def display(fn, rev, states, prevstates): | ||
|
r1061 | diff = list(sets.Set(states).symmetric_difference(sets.Set(prevstates))) | ||
|
r1057 | diff.sort(lambda x, y: cmp(x.linenum, y.linenum)) | ||
|
r1145 | counts = {'-': 0, '+': 0} | ||
|
r1146 | filerevmatches = {} | ||
|
r1057 | for l in diff: | ||
|
r1212 | if incrementing or not opts['all']: | ||
|
r1057 | change = ((l in prevstates) and '-') or '+' | ||
r = rev | ||||
else: | ||||
change = ((l in states) and '-') or '+' | ||||
r = prev[fn] | ||||
|
r1146 | cols = [fn, str(rev)] | ||
|
r1615 | if opts['line_number']: | ||
cols.append(str(l.linenum)) | ||||
if opts['all']: | ||||
cols.append(change) | ||||
if opts['user']: | ||||
cols.append(trimuser(ui, getchange(rev)[1], rev, | ||||
|
r1146 | ucache)) | ||
if opts['files_with_matches']: | ||||
c = (fn, rev) | ||||
|
r1615 | if c in filerevmatches: | ||
continue | ||||
|
r1146 | filerevmatches[c] = 1 | ||
else: | ||||
cols.append(l.line) | ||||
ui.write(sep.join(cols), eol) | ||||
|
r1145 | counts[change] += 1 | ||
return counts['+'], counts['-'] | ||||
|
r1057 | |||
fstate = {} | ||||
|
r1145 | skip = {} | ||
|
r1570 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) | ||
|
r1146 | count = 0 | ||
|
r1337 | incrementing = False | ||
|
r1146 | for st, rev, fns in changeiter: | ||
|
r1057 | if st == 'window': | ||
incrementing = rev | ||||
matches.clear() | ||||
elif st == 'add': | ||||
change = repo.changelog.read(repo.lookup(str(rev))) | ||||
mf = repo.manifest.read(change[0]) | ||||
matches[rev] = {} | ||||
for fn in fns: | ||||
|
r1615 | if fn in skip: | ||
continue | ||||
|
r1057 | fstate.setdefault(fn, {}) | ||
try: | ||||
grepbody(fn, rev, getfile(fn).read(mf[fn])) | ||||
except KeyError: | ||||
pass | ||||
elif st == 'iter': | ||||
states = matches[rev].items() | ||||
states.sort() | ||||
for fn, m in states: | ||||
|
r1615 | if fn in skip: | ||
continue | ||||
|
r1212 | if incrementing or not opts['all'] or fstate[fn]: | ||
|
r1145 | pos, neg = display(fn, rev, m, fstate[fn]) | ||
|
r1146 | count += pos + neg | ||
|
r1212 | if pos and not opts['all']: | ||
|
r1145 | skip[fn] = True | ||
|
r1057 | fstate[fn] = m | ||
prev[fn] = rev | ||||
if not incrementing: | ||||
fstate = fstate.items() | ||||
fstate.sort() | ||||
for fn, state in fstate: | ||||
|
r1615 | if fn in skip: | ||
continue | ||||
|
r1057 | display(fn, rev, {}, state) | ||
|
r1146 | return (count == 0 and 1) or 0 | ||
|
r1057 | |||
|
r898 | def heads(ui, repo, **opts): | ||
|
r1437 | """show current repository heads | ||
Show all repository head changesets. | ||||
Repository "heads" are changesets that don't have children | ||||
changesets. They are where development generally takes place and | ||||
are the usual targets for update and merge operations. | ||||
""" | ||||
|
r1550 | if opts['rev']: | ||
|
r1551 | heads = repo.heads(repo.lookup(opts['rev'])) | ||
|
r1550 | else: | ||
heads = repo.heads() | ||||
|
r898 | br = None | ||
if opts['branches']: | ||||
|
r1551 | br = repo.branchlookup(heads) | ||
|
r1907 | displayer = show_changeset(ui, repo, opts) | ||
|
r1550 | for n in heads: | ||
|
r1907 | displayer.show(changenode=n, brinfo=br) | ||
|
r221 | |||
|
r339 | def identify(ui, repo): | ||
|
r1437 | """print information about the working copy | ||
|
r1470 | |||
|
r1437 | Print a short summary of the current state of the repo. | ||
This summary identifies the repository state using one or two parent | ||||
hash identifiers, followed by a "+" if there are uncommitted changes | ||||
in the working directory, followed by a list of tags for this revision. | ||||
""" | ||||
|
r1092 | parents = [p for p in repo.dirstate.parents() if p != nullid] | ||
|
r340 | if not parents: | ||
|
r1402 | ui.write(_("unknown\n")) | ||
|
r340 | return | ||
|
r1092 | hexfunc = ui.verbose and hex or short | ||
|
r1619 | modified, added, removed, deleted, unknown = repo.changes() | ||
output = ["%s%s" % | ||||
('+'.join([hexfunc(parent) for parent in parents]), | ||||
(modified or added or removed or deleted) and "+" or "")] | ||||
|
r386 | |||
|
r339 | if not ui.quiet: | ||
|
r386 | # multiple tags for a single parent separated by '/' | ||
parenttags = ['/'.join(tags) | ||||
for tags in map(repo.nodetags, parents) if tags] | ||||
# tags for multiple parents separated by ' + ' | ||||
|
r758 | if parenttags: | ||
output.append(' + '.join(parenttags)) | ||||
|
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. | ||||
If a patch looks like a mail message (its first line starts with | ||||
"From " or looks like an RFC822 header), it will not be applied | ||||
unless the -f option is used. The importer neither parses nor | ||||
discards mail headers, so use -f only to override the "mailness" | ||||
safety check, not to import a real mail message. | ||||
""" | ||||
|
r437 | patches = (patch1,) + patches | ||
|
r500 | |||
|
r966 | if not opts['force']: | ||
|
r1619 | modified, added, removed, deleted, unknown = repo.changes() | ||
if modified or added or removed or deleted: | ||||
|
r1402 | raise util.Abort(_("outstanding uncommitted changes")) | ||
|
r966 | |||
|
r437 | d = opts["base"] | ||
strip = opts["strip"] | ||||
|
r1193 | mailre = re.compile(r'(?:From |[\w-]+:)') | ||
|
r1390 | |||
# attempt to detect the start of a patch | ||||
# (this heuristic is borrowed from quilt) | ||||
diffre = re.compile(r'(?:Index:[ \t]|diff[ \t]|RCS file: |' + | ||||
'retrieving revision [0-9]+(\.[0-9]+)*$|' + | ||||
'(---|\*\*\*)[ \t])') | ||||
|
r1190 | |||
|
r437 | for patch in patches: | ||
|
r1402 | ui.status(_("applying %s\n") % patch) | ||
|
r437 | pf = os.path.join(d, patch) | ||
|
r762 | message = [] | ||
|
r701 | user = None | ||
hgpatch = False | ||||
for line in file(pf): | ||||
line = line.rstrip() | ||||
|
r1220 | if (not message and not hgpatch and | ||
mailre.match(line) and not opts['force']): | ||||
|
r1615 | if len(line) > 35: | ||
line = line[:32] + '...' | ||||
|
r1402 | raise util.Abort(_('first line looks like a ' | ||
'mail header: ') + line) | ||||
|
r1193 | if diffre.match(line): | ||
|
r697 | break | ||
|
r701 | elif hgpatch: | ||
# parse values when importing the result of an hg export | ||||
if line.startswith("# User "): | ||||
user = line[7:] | ||||
|
r1402 | ui.debug(_('User: %s\n') % user) | ||
|
r701 | elif not line.startswith("# ") and line: | ||
|
r762 | message.append(line) | ||
|
r701 | hgpatch = False | ||
elif line == '# HG changeset patch': | ||||
|
r607 | hgpatch = True | ||
|
r852 | message = [] # We may have collected garbage | ||
|
r701 | else: | ||
|
r762 | message.append(line) | ||
|
r607 | |||
|
r762 | # make sure message isn't empty | ||
if not message: | ||||
|
r1402 | message = _("imported patch %s\n") % patch | ||
|
r701 | else: | ||
|
r762 | message = "%s\n" % '\n'.join(message) | ||
|
r1402 | ui.debug(_('message:\n%s\n') % message) | ||
|
r437 | |||
|
r1285 | files = util.patch(strip, pf, ui) | ||
|
r437 | |||
if len(files) > 0: | ||||
addremove(ui, repo, *files) | ||||
|
r762 | repo.commit(files, message, user) | ||
|
r437 | |||
|
r1192 | def incoming(ui, repo, source="default", **opts): | ||
|
r1437 | """show new changesets found in source | ||
Show new changesets found in the specified repo or the default | ||||
pull repo. These are the changesets that would be pulled if a pull | ||||
was requested. | ||||
|
r1944 | For remote repository, using --bundle avoids downloading the changesets | ||
twice if the incoming is followed by a pull. | ||||
|
r1437 | """ | ||
|
r1893 | source = ui.expandpath(source) | ||
|
r1965 | if opts['ssh']: | ||
ui.setconfig("ui", "ssh", opts['ssh']) | ||||
if opts['remotecmd']: | ||||
ui.setconfig("ui", "remotecmd", opts['remotecmd']) | ||||
|
r927 | other = hg.repository(ui, source) | ||
|
r1959 | incoming = repo.findincoming(other, force=opts["force"]) | ||
|
r1944 | if not incoming: | ||
|
r931 | return | ||
|
r1944 | |||
cleanup = None | ||||
|
r1974 | try: | ||
fname = opts["bundle"] | ||||
if fname or not other.local(): | ||||
# create a bundle (uncompressed if other repo is not local) | ||||
cg = other.changegroup(incoming, "incoming") | ||||
fname = cleanup = write_bundle(cg, fname, compress=other.local()) | ||||
# keep written bundle? | ||||
if opts["bundle"]: | ||||
cleanup = None | ||||
if not other.local(): | ||||
# use the created uncompressed bundlerepo | ||||
other = bundlerepo.bundlerepository(ui, repo.root, fname) | ||||
o = other.changelog.nodesbetween(incoming)[0] | ||||
if opts['newest_first']: | ||||
o.reverse() | ||||
displayer = show_changeset(ui, other, opts) | ||||
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) | ||||
if opts['patch']: | ||||
prev = (parents and parents[0]) or nullid | ||||
dodiff(ui, ui, other, prev, n) | ||||
ui.write("\n") | ||||
finally: | ||||
if hasattr(other, 'close'): | ||||
other.close() | ||||
if cleanup: | ||||
os.unlink(cleanup) | ||||
|
r1944 | |||
|
r907 | def init(ui, dest="."): | ||
|
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. | ||||
""" | ||||
|
r907 | if not os.path.exists(dest): | ||
os.mkdir(dest) | ||||
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. | ||||
This command searches the current directory and its | ||||
subdirectories. To search an entire repository, move to the root | ||||
of the repository. | ||||
If no patterns are given to match, this command prints all file | ||||
names. | ||||
If you want to feed the output of this command into the "xargs" | ||||
command, use the "-0" option to both this command and "xargs". | ||||
This will avoid the problem of "xargs" treating single filenames | ||||
that contain white space as multiple filenames. | ||||
""" | ||||
|
r1065 | end = opts['print0'] and '\0' or '\n' | ||
|
r1622 | rev = opts['rev'] | ||
if rev: | ||||
node = repo.lookup(rev) | ||||
else: | ||||
node = None | ||||
|
r742 | |||
|
r1622 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, | ||
head='(?:.*/|)'): | ||||
if not node and repo.dirstate.state(abs) == '?': | ||||
|
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) | ||
|
r627 | |||
|
r1031 | def log(ui, repo, *pats, **opts): | ||
|
r1437 | """show revision history of entire repository or files | ||
Print the revision history of the specified files or the entire project. | ||||
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. | ||||
|
r1437 | """ | ||
|
r1559 | class dui(object): | ||
|
r1057 | # Implement and delegate some ui protocol. Save hunks of | ||
# output for later display in the desired order. | ||||
def __init__(self, ui): | ||||
self.ui = ui | ||||
self.hunk = {} | ||||
def bump(self, rev): | ||||
self.rev = rev | ||||
self.hunk[rev] = [] | ||||
def note(self, *args): | ||||
|
r1065 | if self.verbose: | ||
self.write(*args) | ||||
|
r1057 | def status(self, *args): | ||
|
r1065 | if not self.quiet: | ||
self.write(*args) | ||||
|
r1057 | def write(self, *args): | ||
self.hunk[self.rev].append(args) | ||||
|
r1381 | def debug(self, *args): | ||
if self.debugflag: | ||||
self.write(*args) | ||||
|
r1057 | def __getattr__(self, key): | ||
return getattr(self.ui, key) | ||||
|
r1756 | |||
|
r1570 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) | ||
|
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 | ||||
|
r1907 | displayer = show_changeset(ui, repo, opts) | ||
|
r1146 | for st, rev, fns in changeiter: | ||
|
r1057 | if st == 'window': | ||
|
r1031 | du = dui(ui) | ||
|
r1907 | displayer.ui = du | ||
|
r1057 | elif st == 'add': | ||
du.bump(rev) | ||||
|
r1435 | changenode = repo.changelog.node(rev) | ||
parents = [p for p in repo.changelog.parents(changenode) | ||||
if p != nullid] | ||||
if opts['no_merges'] and len(parents) == 2: | ||||
|
r1615 | continue | ||
|
r1436 | if opts['only_merges'] and len(parents) != 2: | ||
|
r1615 | continue | ||
|
r1435 | |||
|
r1373 | if opts['keyword']: | ||
|
r1570 | changes = getchange(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 | ||||
k in " ".join(changes[3][:20]).lower()): | ||||
miss = 1 | ||||
break | ||||
if miss: | ||||
continue | ||||
|
r1764 | br = None | ||
|
r1763 | if opts['branches']: | ||
|
r1405 | br = repo.branchlookup([repo.changelog.node(rev)]) | ||
|
r1907 | displayer.show(rev, brinfo=br) | ||
|
r1057 | if opts['patch']: | ||
|
r1435 | prev = (parents and parents[0]) or nullid | ||
|
r1570 | dodiff(du, du, repo, prev, changenode, match=matchfn) | ||
|
r1057 | du.write("\n\n") | ||
elif st == 'iter': | ||||
|
r1756 | if count == limit: break | ||
|
r1765 | if du.hunk[rev]: | ||
count += 1 | ||||
for args in du.hunk[rev]: | ||||
ui.write(*args) | ||||
|
r255 | |||
|
r697 | def manifest(ui, repo, rev=None): | ||
|
r1437 | """output the latest or given revision of the project manifest | ||
Print a list of version controlled files for the given revision. | ||||
The manifest is the list of files being version controlled. If no revision | ||||
is given then the tip is used. | ||||
""" | ||||
|
r255 | if rev: | ||
|
r689 | try: | ||
# assume all revision numbers are for changesets | ||||
n = repo.lookup(rev) | ||||
change = repo.changelog.read(n) | ||||
n = change[0] | ||||
|
r697 | except hg.RepoError: | ||
|
r689 | n = repo.manifest.lookup(rev) | ||
|
r697 | else: | ||
n = repo.manifest.tip() | ||||
|
r255 | m = repo.manifest.read(n) | ||
|
r276 | mf = repo.manifest.readflags(n) | ||
|
r255 | files = m.keys() | ||
files.sort() | ||||
for f in files: | ||||
|
r1092 | ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f)) | ||
|
r255 | |||
|
r1192 | def outgoing(ui, repo, dest="default-push", **opts): | ||
|
r1437 | """show changesets not found in destination | ||
Show changesets not found in the specified destination repo or the | ||||
default push repo. These are the changesets that would be pushed | ||||
if a push was requested. | ||||
|
r1811 | |||
See pull for valid source format details. | ||||
|
r1437 | """ | ||
|
r1893 | dest = ui.expandpath(dest) | ||
|
r1965 | if opts['ssh']: | ||
ui.setconfig("ui", "ssh", opts['ssh']) | ||||
if opts['remotecmd']: | ||||
ui.setconfig("ui", "remotecmd", opts['remotecmd']) | ||||
|
r920 | other = hg.repository(ui, dest) | ||
|
r1959 | o = repo.findoutgoing(other, force=opts['force']) | ||
|
r1457 | o = repo.changelog.nodesbetween(o)[0] | ||
|
r1439 | if opts['newest_first']: | ||
o.reverse() | ||||
|
r1907 | displayer = 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) | ||
|
r1192 | if opts['patch']: | ||
|
r1435 | prev = (parents and parents[0]) or nullid | ||
|
r1192 | dodiff(ui, ui, repo, prev, n) | ||
ui.write("\n") | ||||
|
r920 | |||
|
r1907 | def parents(ui, repo, rev=None, branches=None, **opts): | ||
|
r1437 | """show the parents of the working dir or revision | ||
Print the working directory's parent revisions. | ||||
""" | ||||
|
r706 | if rev: | ||
p = repo.changelog.parents(repo.lookup(rev)) | ||||
|
r255 | else: | ||
p = repo.dirstate.parents() | ||||
|
r1724 | br = None | ||
|
r1763 | if branches is not None: | ||
|
r1724 | br = repo.branchlookup(p) | ||
|
r1907 | displayer = show_changeset(ui, repo, opts) | ||
|
r255 | for n in p: | ||
|
r1092 | if n != nullid: | ||
|
r1907 | displayer.show(changenode=n, brinfo=br) | ||
|
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)) | ||||
|
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: | ||||
local/filesystem/path | ||||
http://[user@]host[:port][/path] | ||||
https://[user@]host[:port][/path] | ||||
ssh://[user@]host[:port][/path] | ||||
SSH requires an accessible shell account on the destination machine | ||||
and a copy of hg in the remote path. With SSH, paths are relative | ||||
to the remote user's home directory by default; use two slashes at | ||||
the start of a path to specify it as relative to the filesystem root. | ||||
""" | ||||
|
r1893 | source = ui.expandpath(source) | ||
|
r1402 | ui.status(_('pulling from %s\n') % (source)) | ||
|
r500 | |||
|
r963 | if opts['ssh']: | ||
ui.setconfig("ui", "ssh", opts['ssh']) | ||||
if opts['remotecmd']: | ||||
ui.setconfig("ui", "remotecmd", opts['remotecmd']) | ||||
|
r246 | other = hg.repository(ui, source) | ||
|
r1465 | revs = None | ||
if opts['rev'] and not other.local(): | ||||
|
r1607 | raise util.Abort(_("pull -r doesn't work for remote repositories yet")) | ||
|
r1465 | elif opts['rev']: | ||
revs = [other.lookup(rev) for rev in opts['rev']] | ||||
|
r1959 | r = repo.pull(other, heads=revs, force=opts['force']) | ||
|
r625 | if not r: | ||
|
r404 | if opts['update']: | ||
return update(ui, repo) | ||||
|
r580 | else: | ||
|
r1402 | ui.status(_("(run 'hg update' to get a working copy)\n")) | ||
|
r404 | |||
return r | ||||
|
r246 | |||
|
r1781 | def push(ui, repo, dest="default-push", **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: | ||||
local/filesystem/path | ||||
ssh://[user@]host[:port][/path] | ||||
SSH requires an accessible shell account on the destination | ||||
machine and a copy of hg in the remote path. | ||||
""" | ||||
|
r1893 | dest = ui.expandpath(dest) | ||
|
r640 | ui.status('pushing to %s\n' % (dest)) | ||
|
r319 | |||
|
r1781 | if opts['ssh']: | ||
ui.setconfig("ui", "ssh", opts['ssh']) | ||||
if opts['remotecmd']: | ||||
ui.setconfig("ui", "remotecmd", opts['remotecmd']) | ||||
|
r961 | |||
|
r640 | other = hg.repository(ui, dest) | ||
|
r1781 | revs = None | ||
if opts['rev']: | ||||
revs = [repo.lookup(rev) for rev in opts['rev']] | ||||
r = repo.push(other, opts['force'], revs=revs) | ||||
|
r640 | return r | ||
|
r319 | |||
|
r403 | def rawcommit(ui, repo, *flist, **rc): | ||
|
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")) | ||||
|
r1496 | message = rc['message'] | ||
|
r762 | if not message and rc['logfile']: | ||
|
r697 | try: | ||
|
r762 | message = open(rc['logfile']).read() | ||
|
r697 | except IOError: | ||
pass | ||||
|
r762 | if not message and not rc['logfile']: | ||
|
r1402 | raise util.Abort(_("missing commit message")) | ||
|
r246 | |||
|
r403 | files = relpath(repo, list(flist)) | ||
|
r246 | if rc['files']: | ||
files += open(rc['files']).read().splitlines() | ||||
|
r452 | |||
rc['parent'] = map(repo.lookup, rc['parent']) | ||||
|
r500 | |||
|
r1202 | try: | ||
repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent']) | ||||
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(): | ||
return repo.verify() | ||||
return False | ||||
|
r245 | |||
|
r1188 | def remove(ui, repo, pat, *pats, **opts): | ||
|
r1437 | """remove the specified files on the next commit | ||
Schedule the indicated files for removal from the repository. | ||||
This command schedules the files to be removed at the next commit. | ||||
This only removes files from the current branch, not from the | ||||
entire project history. If the files still exist in the working | ||||
directory, they will be deleted from it. | ||||
""" | ||||
|
r1188 | names = [] | ||
|
r1189 | def okaytoremove(abs, rel, exact): | ||
|
r1619 | modified, added, removed, deleted, unknown = repo.changes(files=[abs]) | ||
|
r1189 | reason = None | ||
|
r1867 | if modified and not opts['force']: | ||
|
r1615 | reason = _('is modified') | ||
|
r1618 | elif added: | ||
|
r1615 | reason = _('has been marked for add') | ||
|
r1618 | elif unknown: | ||
|
r1615 | reason = _('is not managed') | ||
|
r1255 | if reason: | ||
|
r1615 | if exact: | ||
ui.warn(_('not removing %s: file %s\n') % (rel, reason)) | ||||
|
r1189 | else: | ||
return True | ||||
|
r1188 | for src, abs, rel, exact in walk(repo, (pat,) + pats, opts): | ||
|
r1189 | if okaytoremove(abs, rel, exact): | ||
|
r1615 | if ui.verbose or not exact: | ||
ui.status(_('removing %s\n') % rel) | ||||
|
r1188 | names.append(abs) | ||
|
r1415 | repo.remove(names, unlink=True) | ||
|
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. | ||||
This command takes effect in the next commit. | ||||
NOTE: This command should be treated as experimental. While it | ||||
should properly record rename files, this information is not yet | ||||
fully used by merge, nor fully reported by log. | ||||
""" | ||||
|
r1822 | try: | ||
wlock = repo.wlock(0) | ||||
errs, copied = docopy(ui, repo, pats, opts, wlock) | ||||
names = [] | ||||
for abs, rel, exact in copied: | ||||
if ui.verbose or not exact: | ||||
ui.status(_('removing %s\n') % rel) | ||||
names.append(abs) | ||||
repo.remove(names, True, wlock) | ||||
except lock.LockHeld, inst: | ||||
ui.warn(_("repository lock held by %s\n") % inst.args[0]) | ||||
errs = 1 | ||||
|
r1253 | return errs | ||
|
r1472 | def revert(ui, repo, *pats, **opts): | ||
|
r1437 | """revert modified files or dirs back to their unmodified states | ||
|
r1811 | In its default mode, it reverts any uncommitted modifications made | ||
to the named files or directories. This restores the contents of | ||||
the affected files to an unmodified state. | ||||
Using the -r option, it reverts the given files or directories to | ||||
their state as of an earlier revision. This can be helpful to "roll | ||||
back" some or all of a change that should not have been committed. | ||||
Revert modifies the working directory. It does not commit any | ||||
changes, or change the parent of the current working directory. | ||||
|
r1437 | |||
If a file has been deleted, it is recreated. If the executable | ||||
mode of a file was changed, it is reset. | ||||
|
r1472 | If names are given, all files matching the names are reverted. | ||
|
r1437 | |||
|
r1568 | If no arguments are given, all files in the repository are reverted. | ||
|
r1437 | """ | ||
|
r590 | node = opts['rev'] and repo.lookup(opts['rev']) or \ | ||
repo.dirstate.parents()[0] | ||||
|
r1625 | files, choose, anypats = matchpats(repo, pats, opts) | ||
|
r1619 | modified, added, removed, deleted, unknown = repo.changes(match=choose) | ||
|
r1618 | repo.forget(added) | ||
|
r1801 | repo.undelete(removed) | ||
|
r588 | |||
|
r1472 | return repo.update(node, False, True, choose, False) | ||
|
r588 | |||
|
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"]: | ||||
|
r635 | fin, fout = sys.stdin, sys.stdout | ||
sys.stdout = sys.stderr | ||||
|
r1420 | # Prevent insertion/deletion of CRs | ||
util.set_binary(fin) | ||||
util.set_binary(fout) | ||||
|
r624 | def getarg(): | ||
|
r635 | argline = fin.readline()[:-1] | ||
|
r624 | arg, l = argline.split() | ||
|
r635 | val = fin.read(int(l)) | ||
|
r624 | return arg, val | ||
def respond(v): | ||||
|
r635 | fout.write("%d\n" % len(v)) | ||
fout.write(v) | ||||
fout.flush() | ||||
|
r624 | |||
|
r638 | lock = None | ||
|
r624 | while 1: | ||
|
r635 | cmd = fin.readline()[:-1] | ||
|
r624 | if cmd == '': | ||
return | ||||
if cmd == "heads": | ||||
h = repo.heads() | ||||
|
r1092 | respond(" ".join(map(hex, h)) + "\n") | ||
|
r638 | if cmd == "lock": | ||
lock = repo.lock() | ||||
respond("") | ||||
if cmd == "unlock": | ||||
|
r697 | if lock: | ||
lock.release() | ||||
|
r638 | lock = None | ||
respond("") | ||||
|
r624 | elif cmd == "branches": | ||
arg, nodes = getarg() | ||||
|
r1092 | nodes = map(bin, nodes.split(" ")) | ||
|
r624 | r = [] | ||
for b in repo.branches(nodes): | ||||
|
r1092 | r.append(" ".join(map(hex, b)) + "\n") | ||
|
r624 | respond("".join(r)) | ||
elif cmd == "between": | ||||
arg, pairs = getarg() | ||||
|
r1092 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] | ||
|
r624 | r = [] | ||
for b in repo.between(pairs): | ||||
|
r1092 | r.append(" ".join(map(hex, b)) + "\n") | ||
|
r624 | respond("".join(r)) | ||
elif cmd == "changegroup": | ||||
nodes = [] | ||||
arg, roots = getarg() | ||||
|
r1092 | nodes = map(bin, roots.split(" ")) | ||
|
r624 | |||
|
r1736 | cg = repo.changegroup(nodes, 'serve') | ||
|
r635 | while 1: | ||
d = cg.read(4096) | ||||
|
r697 | if not d: | ||
break | ||||
|
r635 | fout.write(d) | ||
|
r624 | |||
|
r667 | fout.flush() | ||
|
r624 | |||
|
r639 | elif cmd == "addchangegroup": | ||
if not lock: | ||||
respond("not locked") | ||||
continue | ||||
respond("") | ||||
r = repo.addchangegroup(fin) | ||||
respond("") | ||||
|
r987 | optlist = "name templates style address port ipv6 accesslog errorlog" | ||
for o in optlist.split(): | ||||
if opts[o]: | ||||
ui.setconfig("web", o, opts[o]) | ||||
|
r1741 | if opts['daemon'] and not opts['daemon_pipefds']: | ||
|
r1740 | rfd, wfd = os.pipe() | ||
args = sys.argv[:] | ||||
|
r1741 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) | ||
|
r1740 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), | ||
args[0], args) | ||||
os.close(wfd) | ||||
os.read(rfd, 1) | ||||
os._exit(0) | ||||
|
r1177 | try: | ||
httpd = hgweb.create_server(repo) | ||||
except socket.error, inst: | ||||
|
r1607 | raise util.Abort(_('cannot start server: ') + inst.args[1]) | ||
|
r987 | |||
|
r603 | if ui.verbose: | ||
addr, port = httpd.socket.getsockname() | ||||
if addr == '0.0.0.0': | ||||
addr = socket.gethostname() | ||||
else: | ||||
try: | ||||
addr = socket.gethostbyaddr(addr)[0] | ||||
|
r697 | except socket.error: | ||
pass | ||||
|
r603 | if port != 80: | ||
|
r1402 | ui.status(_('listening at http://%s:%d/\n') % (addr, port)) | ||
|
r603 | else: | ||
|
r1402 | ui.status(_('listening at http://%s/\n') % addr) | ||
|
r1740 | |||
if opts['pid_file']: | ||||
fp = open(opts['pid_file'], 'w') | ||||
fp.write(str(os.getpid())) | ||||
fp.close() | ||||
|
r1741 | if opts['daemon_pipefds']: | ||
rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] | ||||
os.close(rfd) | ||||
|
r1740 | os.write(wfd, 'y') | ||
os.close(wfd) | ||||
sys.stdout.flush() | ||||
sys.stderr.flush() | ||||
fd = os.open(util.nulldev, os.O_RDWR) | ||||
if fd != 0: os.dup2(fd, 0) | ||||
if fd != 1: os.dup2(fd, 1) | ||||
if fd != 2: os.dup2(fd, 2) | ||||
if fd not in (0, 1, 2): os.close(fd) | ||||
|
r603 | httpd.serve_forever() | ||
|
r500 | |||
|
r731 | def status(ui, repo, *pats, **opts): | ||
|
r1437 | """show changed files in the working directory | ||
|
r213 | |||
|
r1568 | Show changed files in the repository. If names are | ||
given, only files that match are shown. | ||||
|
r1437 | |||
The codes used to show the status of files are: | ||||
|
r746 | M = modified | ||
|
r245 | A = added | ||
R = removed | ||||
|
r1619 | ! = deleted, but still tracked | ||
|
r842 | ? = not tracked | ||
|
r1437 | """ | ||
|
r312 | |||
|
r1625 | files, matchfn, anypats = matchpats(repo, pats, opts) | ||
cwd = (pats and repo.getcwd()) or '' | ||||
|
r1619 | modified, added, removed, deleted, unknown = [ | ||
|
r1618 | [util.pathto(cwd, x) for x in n] | ||
for n in repo.changes(files=files, match=matchfn)] | ||||
|
r213 | |||
|
r1966 | changetypes = [('modified', 'M', modified), | ||
('added', 'A', added), | ||||
('removed', 'R', removed), | ||||
('deleted', '!', deleted), | ||||
('unknown', '?', unknown)] | ||||
|
r842 | |||
|
r1085 | end = opts['print0'] and '\0' or '\n' | ||
|
r1106 | |||
|
r842 | for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]] | ||
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: | ||
|
r1085 | ui.write(format % f) | ||
|
r213 | |||
|
r1596 | def tag(ui, repo, name, rev_=None, **opts): | ||
|
r1437 | """add a tag for the current tip or a given revision | ||
Name a particular revision using <name>. | ||||
Tags are used to name particular revisions of the repository and are | ||||
very useful to compare different revision, to go back to significant | ||||
earlier versions or to mark branch points as releases, etc. | ||||
If no revision is given, the tip is used. | ||||
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 | """ | ||
|
r401 | if name == "tip": | ||
|
r1402 | raise util.Abort(_("the name 'tip' is reserved")) | ||
|
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")) | ||||
|
r1596 | if opts['rev']: | ||
rev_ = opts['rev'] | ||||
if rev_: | ||||
r = hex(repo.lookup(rev_)) | ||||
|
r609 | else: | ||
|
r1092 | r = hex(repo.changelog.tip()) | ||
|
r609 | |||
|
r1561 | disallowed = (revrangesep, '\r', '\n') | ||
for c in disallowed: | ||||
if name.find(c) >= 0: | ||||
raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) | ||||
|
r401 | |||
|
r1720 | repo.hook('pretag', throw=True, node=r, tag=name, | ||
|
r1734 | local=int(not not opts['local'])) | ||
|
r1720 | |||
|
r609 | if opts['local']: | ||
repo.opener("localtags", "a").write("%s %s\n" % (r, name)) | ||||
|
r1720 | repo.hook('tag', node=r, tag=name, local=1) | ||
|
r609 | return | ||
|
r1618 | for x in repo.changes(): | ||
|
r580 | if ".hgtags" in x: | ||
|
r1402 | raise util.Abort(_("working copy of .hgtags is changed " | ||
"(please commit .hgtags manually)")) | ||||
|
r401 | |||
|
r617 | repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name)) | ||
|
r710 | if repo.dirstate.state(".hgtags") == '?': | ||
|
r697 | repo.add([".hgtags"]) | ||
|
r401 | |||
|
r1496 | message = (opts['message'] or | ||
|
r1402 | _("Added tag %s for changeset %s") % (name, r)) | ||
|
r1202 | try: | ||
repo.commit([".hgtags"], message, opts['user'], opts['date']) | ||||
|
r1720 | repo.hook('tag', node=r, tag=name, local=0) | ||
|
r1202 | except ValueError, inst: | ||
raise util.Abort(str(inst)) | ||||
|
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() | ||||
|
r477 | for t, n in l: | ||
|
r248 | try: | ||
|
r1092 | r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) | ||
|
r248 | except KeyError: | ||
|
r477 | r = " ?:?" | ||
ui.write("%-30s %s\n" % (t, r)) | ||||
|
r248 | |||
|
r1731 | def tip(ui, repo, **opts): | ||
|
r1437 | """show the tip revision | ||
Show the tip revision. | ||||
""" | ||||
|
r245 | n = repo.changelog.tip() | ||
|
r1762 | br = None | ||
|
r1763 | if opts['branches']: | ||
|
r1762 | br = repo.branchlookup([n]) | ||
|
r1907 | show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) | ||
|
r1731 | if opts['patch']: | ||
dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n) | ||||
|
r245 | |||
|
r1600 | def unbundle(ui, repo, fname, **opts): | ||
|
r1437 | """apply a changegroup file | ||
Apply a compressed changegroup file generated by the bundle | ||||
command. | ||||
""" | ||||
|
r1218 | f = urllib.urlopen(fname) | ||
|
r1940 | header = f.read(4) | ||
if header == "HG10": | ||||
def generator(f): | ||||
zd = bz2.BZ2Decompressor() | ||||
for chunk in f: | ||||
yield zd.decompress(chunk) | ||||
elif header == "HG11": | ||||
def generator(f): | ||||
for chunk in f: | ||||
yield chunk | ||||
else: | ||||
|
r1402 | raise util.Abort(_("%s: not a Mercurial bundle file") % fname) | ||
|
r1940 | gen = generator(util.filechunkiter(f, 4096)) | ||
if repo.addchangegroup(util.chunkbuffer(gen)): | ||||
|
r1601 | return 1 | ||
|
r1600 | if opts['update']: | ||
return update(ui, repo) | ||||
else: | ||||
ui.status(_("(run 'hg update' to get a working copy)\n")) | ||||
|
r1218 | |||
|
r212 | def undo(ui, repo): | ||
|
r596 | """undo the last commit or pull | ||
Roll back the last pull or commit transaction on the | ||||
repository, restoring the project to its earlier state. | ||||
This command should be used with care. There is only one level of | ||||
undo and there is no redo. | ||||
This command is not intended for use on public repositories. Once | ||||
a change is visible for pull by other users, undoing it locally is | ||||
ineffective. | ||||
""" | ||||
|
r210 | repo.undo() | ||
|
r1581 | def update(ui, repo, node=None, merge=False, clean=False, force=None, | ||
|
r1907 | branch=None, **opts): | ||
|
r1437 | """update or merge working directory | ||
Update the working directory to the specified revision. | ||||
|
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. | ||||
Otherwise the result is a merge between the contents of the | ||||
current working directory and the requested version. 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. | ||||
|
r1437 | |||
By default, update will refuse to run if doing so would require | ||||
merging or discarding local changes. | ||||
""" | ||||
|
r898 | if branch: | ||
br = repo.branchlookup(branch=branch) | ||||
found = [] | ||||
for x in br: | ||||
if branch in br[x]: | ||||
found.append(x) | ||||
if len(found) > 1: | ||||
|
r1402 | ui.warn(_("Found multiple heads for %s\n") % branch) | ||
|
r898 | for x in found: | ||
|
r1907 | show_changeset(ui, repo, opts).show(changenode=x, brinfo=br) | ||
|
r898 | return 1 | ||
if len(found) == 1: | ||||
node = found[0] | ||||
|
r1402 | ui.warn(_("Using head %s for branch %s\n") % (short(node), branch)) | ||
|
r898 | else: | ||
|
r1402 | ui.warn(_("branch %s not found\n") % (branch)) | ||
|
r898 | return 1 | ||
else: | ||||
node = node and repo.lookup(node) or repo.changelog.tip() | ||||
|
r1581 | return repo.update(node, allow=merge, force=clean, forcemerge=force) | ||
|
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. | ||||
""" | ||||
|
r247 | return repo.verify() | ||
|
r255 | # Command options and aliases are listed here, alphabetically | ||
|
r209 | table = { | ||
|
r841 | "^add": | ||
(add, | ||||
|
r1437 | [('I', 'include', [], _('include names matching the given patterns')), | ||
('X', 'exclude', [], _('exclude names matching the given patterns'))], | ||||
|
r1615 | _('hg add [OPTION]... [FILE]...')), | ||
|
r841 | "addremove": | ||
(addremove, | ||||
|
r1437 | [('I', 'include', [], _('include names matching the given patterns')), | ||
('X', 'exclude', [], _('exclude names matching the given patterns'))], | ||||
|
r1615 | _('hg addremove [OPTION]... [FILE]...')), | ||
|
r697 | "^annotate": | ||
(annotate, | ||||
|
r1437 | [('r', 'rev', '', _('annotate the specified revision')), | ||
|
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')), | ||||
('I', 'include', [], _('include names matching the given patterns')), | ||||
('X', 'exclude', [], _('exclude names matching the given patterns'))], | ||||
|
r1816 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), | ||
|
r1218 | "bundle": | ||
(bundle, | ||||
|
r1959 | [('f', 'force', None, | ||
_('run even when remote repository is unrelated'))], | ||||
|
r1402 | _('hg bundle FILE DEST')), | ||
|
r697 | "cat": | ||
(cat, | ||||
|
r1816 | [('o', 'output', '', _('print output to file with formatted name')), | ||
('r', 'rev', '', _('print the given revision')), | ||||
('I', 'include', [], _('include names matching the given patterns')), | ||||
('X', 'exclude', [], _('exclude names matching the given patterns'))], | ||||
|
r1402 | _('hg cat [OPTION]... FILE...')), | ||
|
r697 | "^clone": | ||
(clone, | ||||
|
r1437 | [('U', 'noupdate', None, _('do not update the new working directory')), | ||
|
r1602 | ('r', 'rev', [], | ||
_('a changeset you would like to have after cloning')), | ||||
|
r1816 | ('', 'pull', None, _('use pull protocol to copy metadata')), | ||
('e', 'ssh', '', _('specify ssh command to use')), | ||||
|
r1615 | ('', 'remotecmd', '', | ||
|
r1602 | _('specify hg command to run on the remote side'))], | ||
|
r1402 | _('hg clone [OPTION]... SOURCE [DEST]')), | ||
|
r697 | "^commit|ci": | ||
(commit, | ||||
|
r1437 | [('A', 'addremove', None, _('run addremove during commit')), | ||
|
r1615 | ('m', 'message', '', _('use <text> as commit message')), | ||
('l', 'logfile', '', _('read the commit message from <file>')), | ||||
('d', 'date', '', _('record datecode as commit date')), | ||||
|
r1816 | ('u', 'user', '', _('record user as commiter')), | ||
('I', 'include', [], _('include names matching the given patterns')), | ||||
('X', 'exclude', [], _('exclude names matching the given patterns'))], | ||||
|
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')), | ||
('I', 'include', [], _('include names matching the given patterns')), | ||||
('X', 'exclude', [], _('exclude names matching the given patterns'))], | ||||
|
r1615 | _('hg copy [OPTION]... [SOURCE]... DEST')), | ||
|
r1402 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), | ||
|
r1887 | "debugcomplete": (debugcomplete, [], _('debugcomplete CMD')), | ||
|
r1755 | "debugrebuildstate": | ||
(debugrebuildstate, | ||||
|
r1816 | [('r', 'rev', '', _('revision to rebuild to'))], | ||
|
r1755 | _('debugrebuildstate [-r REV] [REV]')), | ||
|
r1402 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), | ||
"debugconfig": (debugconfig, [], _('debugconfig')), | ||||
"debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), | ||||
"debugstate": (debugstate, [], _('debugstate')), | ||||
"debugdata": (debugdata, [], _('debugdata FILE REV')), | ||||
"debugindex": (debugindex, [], _('debugindex FILE')), | ||||
"debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), | ||||
"debugrename": (debugrename, [], _('debugrename FILE [REV]')), | ||||
|
r841 | "debugwalk": | ||
(debugwalk, | ||||
|
r1437 | [('I', 'include', [], _('include names matching the given patterns')), | ||
('X', 'exclude', [], _('exclude names matching the given patterns'))], | ||||
|
r1402 | _('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')), | ||||
('w', 'ignore-all-space', None, | ||||
_('ignore white space when comparing lines')), | ||||
|
r1816 | ('I', 'include', [], _('include names matching the given patterns')), | ||
('X', 'exclude', [], _('exclude names matching the given patterns'))], | ||||
|
r1402 | _('hg diff [-a] [-I] [-X] [-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')), | ||
('', 'switch-parent', None, _('diff against the second parent'))], | ||||
|
r1812 | _('hg export [-a] [-o OUTFILESPEC] REV...')), | ||
|
r841 | "forget": | ||
(forget, | ||||
|
r1437 | [('I', 'include', [], _('include names matching the given patterns')), | ||
('X', 'exclude', [], _('exclude names matching the given patterns'))], | ||||
|
r1615 | _('hg forget [OPTION]... FILE...')), | ||
|
r1065 | "grep": | ||
(grep, | ||||
|
r1402 | [('0', 'print0', None, _('end fields with NUL')), | ||
|
r1437 | ('', 'all', None, _('print all revisions that match')), | ||
|
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')), | ||
('I', 'include', [], _('include names matching the given patterns')), | ||||
('X', 'exclude', [], _('exclude names matching the given patterns'))], | ||||
|
r1615 | _('hg grep [OPTION]... PATTERN [FILE]...')), | ||
|
r905 | "heads": | ||
(heads, | ||||
|
r1763 | [('b', 'branches', None, _('show branches')), | ||
|
r1913 | ('', 'style', '', _('display using template map file')), | ||
|
r1907 | ('r', 'rev', '', _('show only heads which are descendants of rev')), | ||
|
r1913 | ('', 'template', '', _('display with template'))], | ||
|
r1550 | _('hg heads [-b] [-r <rev>]')), | ||
|
r1402 | "help": (help_, [], _('hg help [COMMAND]')), | ||
"identify|id": (identify, [], _('hg identify')), | ||||
|
r697 | "import|patch": | ||
(import_, | ||||
|
r1602 | [('p', 'strip', 1, | ||
_('directory strip option for patch. This has the same\n') + | ||||
_('meaning as the corresponding patch option')), | ||||
|
r1816 | ('b', 'base', '', _('base path')), | ||
|
r1602 | ('f', 'force', None, | ||
|
r1816 | _('skip check for outstanding uncommitted changes'))], | ||
_('hg import [-p NUM] [-b BASE] [-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')), | ||
|
r1965 | ('', 'template', '', _('display with template')), | ||
('e', 'ssh', '', _('specify ssh command to use')), | ||||
('', 'remotecmd', '', | ||||
_('specify hg command to run on the remote side'))], | ||||
|
r1944 | _('hg incoming [-p] [-n] [-M] [--bundle FILENAME] [SOURCE]')), | ||
|
r1402 | "^init": (init, [], _('hg init [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')), | ||||
|
r1437 | ('I', 'include', [], _('include names matching the given patterns')), | ||
('X', 'exclude', [], _('exclude names matching the given patterns'))], | ||||
|
r1402 | _('hg locate [OPTION]... [PATTERN]...')), | ||
|
r697 | "^log|history": | ||
(log, | ||||
|
r1816 | [('b', 'branches', None, _('show branches')), | ||
|
r1402 | ('k', 'keyword', [], _('search for a keyword')), | ||
|
r1756 | ('l', 'limit', '', _('limit number of changes displayed')), | ||
|
r1437 | ('r', 'rev', [], _('show the specified revision or range')), | ||
|
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')), | ||
|
r1920 | ('', 'template', '', _('display with template')), | ||
|
r1816 | ('I', 'include', [], _('include names matching the given patterns')), | ||
('X', 'exclude', [], _('exclude names matching the given patterns'))], | ||||
_('hg log [OPTION]... [FILE]')), | ||||
|
r1402 | "manifest": (manifest, [], _('hg manifest [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')), | ||
|
r1907 | ('n', 'newest-first', None, _('show newest record first')), | ||
|
r1965 | ('', 'template', '', _('display with template')), | ||
('e', 'ssh', '', _('specify ssh command to use')), | ||||
('', 'remotecmd', '', | ||||
_('specify hg command to run on the remote side'))], | ||||
|
r1816 | _('hg outgoing [-M] [-p] [-n] [DEST]')), | ||
|
r1724 | "^parents": | ||
(parents, | ||||
|
r1907 | [('b', 'branches', None, _('show branches')), | ||
|
r1913 | ('', 'style', '', _('display using template map file')), | ||
('', 'template', '', _('display with template'))], | ||||
|
r1724 | _('hg parents [-b] [REV]')), | ||
|
r1402 | "paths": (paths, [], _('hg paths [NAME]')), | ||
|
r697 | "^pull": | ||
(pull, | ||||
|
r1602 | [('u', 'update', None, | ||
_('update the working directory to tip after pull')), | ||||
|
r1615 | ('e', 'ssh', '', _('specify ssh command to use')), | ||
|
r1959 | ('f', 'force', None, | ||
_('run even when remote repository is unrelated')), | ||||
|
r1469 | ('r', 'rev', [], _('a specific revision you would like to pull')), | ||
|
r1615 | ('', 'remotecmd', '', | ||
|
r1602 | _('specify hg command to run on the remote side'))], | ||
|
r1816 | _('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')), | ||
|
r818 | "^push": | ||
(push, | ||||
|
r1402 | [('f', 'force', None, _('force push')), | ||
|
r1615 | ('e', 'ssh', '', _('specify ssh command to use')), | ||
|
r1781 | ('r', 'rev', [], _('a specific revision you would like to push')), | ||
|
r1615 | ('', 'remotecmd', '', | ||
|
r1602 | _('specify hg command to run on the remote side'))], | ||
|
r1816 | _('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')), | ||
|
r1818 | "debugrawcommit|rawcommit": | ||
|
r697 | (rawcommit, | ||
|
r1402 | [('p', 'parent', [], _('parent')), | ||
|
r1615 | ('d', 'date', '', _('date code')), | ||
('u', 'user', '', _('user')), | ||||
('F', 'files', '', _('file list')), | ||||
('m', 'message', '', _('commit message')), | ||||
('l', 'logfile', '', _('commit message file'))], | ||||
|
r1818 | _('hg debugrawcommit [OPTION]... [FILE]...')), | ||
|
r1615 | "recover": (recover, [], _('hg recover')), | ||
"^remove|rm": | ||||
(remove, | ||||
|
r1869 | [('f', 'force', None, _('remove file even if modified')), | ||
('I', 'include', [], _('include names matching the given patterns')), | ||||
('X', 'exclude', [], _('exclude names matching the given patterns'))], | ||||
|
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')), | ||
('I', 'include', [], _('include names matching the given patterns')), | ||||
('X', 'exclude', [], _('exclude names matching the given patterns'))], | ||||
|
r1869 | _('hg rename [OPTION]... SOURCE... DEST')), | ||
|
r697 | "^revert": | ||
(revert, | ||||
|
r1816 | [('r', 'rev', '', _('revision to revert to')), | ||
('I', 'include', [], _('include names matching the given patterns')), | ||||
('X', 'exclude', [], _('exclude names matching the given patterns'))], | ||||
_('hg revert [-r REV] [NAME]...')), | ||||
|
r1615 | "root": (root, [], _('hg root')), | ||
|
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)')), | ||
|
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')), | ||||
|
r1402 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], | ||
|
r1615 | _('hg serve [OPTION]...')), | ||
|
r1507 | "^status|st": | ||
|
r840 | (status, | ||
|
r1402 | [('m', 'modified', None, _('show only modified files')), | ||
('a', 'added', None, _('show only added files')), | ||||
('r', 'removed', None, _('show only removed files')), | ||||
|
r1619 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), | ||
|
r1402 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), | ||
('n', 'no-status', None, _('hide status prefix')), | ||||
|
r1602 | ('0', 'print0', None, | ||
_('end filenames with NUL, for use with xargs')), | ||||
|
r1437 | ('I', 'include', [], _('include names matching the given patterns')), | ||
('X', 'exclude', [], _('exclude names matching the given patterns'))], | ||||
|
r1615 | _('hg status [OPTION]... [FILE]...')), | ||
|
r697 | "tag": | ||
(tag, | ||||
|
r1402 | [('l', 'local', None, _('make the tag local')), | ||
|
r1615 | ('m', 'message', '', _('message for tag commit log entry')), | ||
('d', 'date', '', _('record datecode as commit date')), | ||||
('u', 'user', '', _('record user as commiter')), | ||||
('r', 'rev', '', _('revision to tag'))], | ||||
|
r1812 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), | ||
|
r1402 | "tags": (tags, [], _('hg tags')), | ||
|
r1762 | "tip": | ||
(tip, | ||||
|
r1763 | [('b', 'branches', None, _('show branches')), | ||
|
r1913 | ('', 'style', '', _('display using template map file')), | ||
|
r1907 | ('p', 'patch', None, _('show patch')), | ||
|
r1913 | ('', 'template', '', _('display with template'))], | ||
|
r1811 | _('hg tip [-b] [-p]')), | ||
|
r1218 | "unbundle": | ||
(unbundle, | ||||
|
r1601 | [('u', 'update', None, | ||
_('update the working directory to tip after unbundle'))], | ||||
|
r1600 | _('hg unbundle [-u] FILE')), | ||
|
r1402 | "undo": (undo, [], _('hg undo')), | ||
|
r593 | "^update|up|checkout|co": | ||
|
r697 | (update, | ||
|
r1615 | [('b', 'branch', '', _('checkout the head of a specific branch')), | ||
|
r1913 | ('', 'style', '', _('display using template map file')), | ||
|
r1437 | ('m', 'merge', None, _('allow merging of branches')), | ||
|
r1581 | ('C', 'clean', None, _('overwrite locally modified files')), | ||
|
r1907 | ('f', 'force', None, _('force a merge with outstanding changes')), | ||
|
r1913 | ('', 'template', '', _('display with template'))], | ||
|
r1581 | _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), | ||
|
r1402 | "verify": (verify, [], _('hg verify')), | ||
"version": (show_version, [], _('hg version')), | ||||
|
r1046 | } | ||
|
r209 | |||
|
r1046 | globalopts = [ | ||
|
r1894 | ('R', 'repository', '', | ||
_('repository root directory or symbolic path name')), | ||||
|
r1615 | ('', 'cwd', '', _('change working directory')), | ||
|
r1602 | ('y', 'noninteractive', None, | ||
|
r1615 | _('do not prompt, assume \'yes\' for any required answers')), | ||
('q', 'quiet', None, _('suppress output')), | ||||
('v', 'verbose', None, _('enable additional output')), | ||||
('', 'debug', None, _('enable debugging output')), | ||||
('', 'debugger', None, _('start debugger')), | ||||
('', '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')), | ||||
|
r1046 | ] | ||
|
r596 | |||
|
r1887 | norepo = ("clone init version help debugancestor debugcomplete debugdata" | ||
|
r1858 | " debugindex debugindexdot") | ||
optionalrepo = ("paths debugconfig") | ||||
|
r209 | |||
|
r1887 | def findpossible(cmd): | ||
""" | ||||
Return cmd -> (aliases, command table entry) | ||||
for each matching command | ||||
""" | ||||
choice = {} | ||||
debugchoice = {} | ||||
|
r212 | for e in table.keys(): | ||
|
r1506 | aliases = e.lstrip("^").split("|") | ||
if cmd in aliases: | ||||
|
r1887 | choice[cmd] = (aliases, table[e]) | ||
continue | ||||
|
r1506 | for a in aliases: | ||
if a.startswith(cmd): | ||||
|
r1850 | if aliases[0].startswith("debug"): | ||
|
r1887 | debugchoice[a] = (aliases, table[e]) | ||
|
r1850 | else: | ||
|
r1887 | choice[a] = (aliases, table[e]) | ||
|
r1739 | break | ||
|
r1850 | if not choice and debugchoice: | ||
choice = debugchoice | ||||
|
r1887 | return choice | ||
def find(cmd): | ||||
"""Return (aliases, command table entry) for command string.""" | ||||
choice = findpossible(cmd) | ||||
if choice.has_key(cmd): | ||||
return choice[cmd] | ||||
|
r1848 | if len(choice) > 1: | ||
|
r1887 | clist = choice.keys() | ||
|
r1849 | clist.sort() | ||
|
r1848 | raise AmbiguousCommand(cmd, clist) | ||
|
r1739 | |||
|
r1517 | if choice: | ||
|
r1887 | return choice.values()[0] | ||
|
r212 | |||
raise UnknownCommand(cmd) | ||||
|
r697 | class SignalInterrupt(Exception): | ||
"""Exception raised on SIGTERM and SIGHUP.""" | ||||
|
r214 | |||
def catchterm(*args): | ||||
raise SignalInterrupt | ||||
|
r249 | def run(): | ||
sys.exit(dispatch(sys.argv[1:])) | ||||
|
r697 | class ParseError(Exception): | ||
"""Exception raised on errors in parsing the command line.""" | ||||
|
r592 | |||
|
r1453 | def parse(ui, args): | ||
|
r209 | options = {} | ||
|
r596 | cmdoptions = {} | ||
|
r209 | |||
|
r592 | try: | ||
|
r596 | args = fancyopts.fancyopts(args, globalopts, options) | ||
|
r592 | except fancyopts.getopt.GetoptError, inst: | ||
|
r618 | raise ParseError(None, inst) | ||
|
r209 | |||
|
r1047 | if args: | ||
cmd, args = args[0], args[1:] | ||||
|
r1567 | aliases, i = find(cmd) | ||
cmd = aliases[0] | ||||
|
r1453 | defaults = ui.config("defaults", cmd) | ||
if defaults: | ||||
|
r1526 | args = defaults.split() + args | ||
|
r1047 | c = list(i[1]) | ||
|
r209 | else: | ||
|
r1047 | cmd = None | ||
c = [] | ||||
|
r209 | |||
|
r592 | # combine global options into local | ||
|
r596 | for o in globalopts: | ||
|
r592 | c.append((o[0], o[1], options[o[1]], o[3])) | ||
|
r214 | |||
|
r293 | try: | ||
|
r596 | args = fancyopts.fancyopts(args, c, cmdoptions) | ||
|
r293 | except fancyopts.getopt.GetoptError, inst: | ||
|
r596 | raise ParseError(cmd, inst) | ||
|
r209 | |||
|
r592 | # separate global options back out | ||
|
r596 | for o in globalopts: | ||
|
r592 | n = o[1] | ||
options[n] = cmdoptions[n] | ||||
del cmdoptions[n] | ||||
|
r1047 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) | ||
|
r596 | |||
def dispatch(args): | ||||
signal.signal(signal.SIGTERM, catchterm) | ||||
|
r697 | try: | ||
signal.signal(signal.SIGHUP, catchterm) | ||||
except AttributeError: | ||||
pass | ||||
|
r596 | |||
|
r1483 | try: | ||
u = ui.ui() | ||||
except util.Abort, inst: | ||||
sys.stderr.write(_("abort: %s\n") % inst) | ||||
sys.exit(1) | ||||
|
r1071 | external = [] | ||
for x in u.extensions(): | ||||
|
r1545 | def on_exception(exc, inst): | ||
|
r1424 | u.warn(_("*** failed to import extension %s\n") % x[1]) | ||
u.warn("%s\n" % inst) | ||||
if "--traceback" in sys.argv[1:]: | ||||
traceback.print_exc() | ||||
|
r1071 | if x[1]: | ||
|
r1342 | try: | ||
mod = imp.load_source(x[0], x[1]) | ||||
|
r1424 | except Exception, inst: | ||
on_exception(Exception, inst) | ||||
|
r1342 | continue | ||
|
r1071 | else: | ||
def importh(name): | ||||
mod = __import__(name) | ||||
components = name.split('.') | ||||
for comp in components[1:]: | ||||
mod = getattr(mod, comp) | ||||
return mod | ||||
|
r1342 | try: | ||
|
r1889 | try: | ||
mod = importh("hgext." + x[0]) | ||||
except ImportError: | ||||
mod = importh(x[0]) | ||||
|
r1424 | except Exception, inst: | ||
on_exception(Exception, inst) | ||||
|
r1342 | continue | ||
|
r1071 | external.append(mod) | ||
for x in external: | ||||
|
r1295 | cmdtable = getattr(x, 'cmdtable', {}) | ||
for t in cmdtable: | ||||
|
r1071 | if t in table: | ||
|
r1402 | u.warn(_("module %s overrides %s\n") % (x.__name__, t)) | ||
|
r1295 | table.update(cmdtable) | ||
|
r1071 | |||
|
r596 | try: | ||
|
r1453 | cmd, func, args, options, cmdoptions = parse(u, args) | ||
|
r1875 | if options["time"]: | ||
def get_times(): | ||||
t = os.times() | ||||
if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() | ||||
t = (t[0], t[1], t[2], t[3], time.clock()) | ||||
return t | ||||
s = get_times() | ||||
def print_time(): | ||||
t = get_times() | ||||
u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % | ||||
(t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) | ||||
atexit.register(print_time) | ||||
u.updateopts(options["verbose"], options["debug"], options["quiet"], | ||||
not options["noninteractive"]) | ||||
# enter the debugger before command execution | ||||
if options['debugger']: | ||||
pdb.set_trace() | ||||
|
r527 | try: | ||
|
r1859 | if options['cwd']: | ||
try: | ||||
os.chdir(options['cwd']) | ||||
except OSError, inst: | ||||
raise util.Abort('%s: %s' % | ||||
(options['cwd'], inst.strerror)) | ||||
|
r1894 | path = u.expandpath(options["repository"]) or "" | ||
|
r1859 | repo = path and hg.repository(u, path=path) or None | ||
|
r1857 | |||
|
r1048 | if options['help']: | ||
|
r1049 | help_(u, cmd, options['version']) | ||
|
r1048 | sys.exit(0) | ||
elif options['version']: | ||||
|
r1047 | show_version(u) | ||
sys.exit(0) | ||||
elif not cmd: | ||||
help_(u, 'shortlist') | ||||
sys.exit(0) | ||||
|
r527 | if cmd not in norepo.split(): | ||
|
r1858 | try: | ||
if not repo: | ||||
repo = hg.repository(u, path=path) | ||||
u = repo.ui | ||||
for x in external: | ||||
if hasattr(x, 'reposetup'): | ||||
x.reposetup(u, repo) | ||||
except hg.RepoError: | ||||
if cmd not in optionalrepo.split(): | ||||
raise | ||||
|
r596 | d = lambda: func(u, repo, *args, **cmdoptions) | ||
|
r527 | else: | ||
|
r596 | d = lambda: func(u, *args, **cmdoptions) | ||
|
r209 | |||
|
r1837 | try: | ||
if options['profile']: | ||||
import hotshot, hotshot.stats | ||||
prof = hotshot.Profile("hg.prof") | ||||
|
r1832 | try: | ||
try: | ||||
|
r1837 | return prof.runcall(d) | ||
|
r1832 | except: | ||
|
r1837 | try: | ||
u.warn(_('exception raised - generating ' | ||||
'profile anyway\n')) | ||||
except: | ||||
pass | ||||
raise | ||||
finally: | ||||
prof.close() | ||||
stats = hotshot.stats.load("hg.prof") | ||||
stats.strip_dirs() | ||||
stats.sort_stats('time', 'calls') | ||||
stats.print_stats(40) | ||||
else: | ||||
return d() | ||||
finally: | ||||
u.flush() | ||||
|
r527 | except: | ||
|
r1225 | # enter the debugger when we hit an exception | ||
if options['debugger']: | ||||
pdb.post_mortem(sys.exc_info()[2]) | ||||
|
r527 | if options['traceback']: | ||
traceback.print_exc() | ||||
raise | ||||
|
r1875 | except ParseError, inst: | ||
if inst.args[0]: | ||||
u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) | ||||
help_(u, inst.args[0]) | ||||
else: | ||||
u.warn(_("hg: %s\n") % inst.args[1]) | ||||
help_(u, 'shortlist') | ||||
sys.exit(-1) | ||||
except AmbiguousCommand, inst: | ||||
|
r1920 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % | ||
|
r1875 | (inst.args[0], " ".join(inst.args[1]))) | ||
sys.exit(1) | ||||
except UnknownCommand, inst: | ||||
u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | ||||
help_(u, 'shortlist') | ||||
sys.exit(1) | ||||
|
r499 | except hg.RepoError, inst: | ||
|
r1402 | u.warn(_("abort: "), inst, "!\n") | ||
|
r1214 | except revlog.RevlogError, inst: | ||
|
r1402 | u.warn(_("abort: "), inst, "!\n") | ||
|
r214 | except SignalInterrupt: | ||
|
r1402 | u.warn(_("killed!\n")) | ||
|
r209 | except KeyboardInterrupt: | ||
|
r832 | try: | ||
|
r1402 | u.warn(_("interrupted!\n")) | ||
|
r832 | except IOError, inst: | ||
if inst.errno == errno.EPIPE: | ||||
if u.debugflag: | ||||
|
r1402 | u.warn(_("\nbroken pipe\n")) | ||
|
r832 | else: | ||
raise | ||||
|
r250 | except IOError, inst: | ||
|
r395 | if hasattr(inst, "code"): | ||
|
r1402 | u.warn(_("abort: %s\n") % inst) | ||
|
r395 | elif hasattr(inst, "reason"): | ||
|
r1402 | u.warn(_("abort: error: %s\n") % inst.reason[1]) | ||
|
r395 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: | ||
|
r1065 | if u.debugflag: | ||
|
r1402 | u.warn(_("broken pipe\n")) | ||
|
r1350 | elif getattr(inst, "strerror", None): | ||
|
r1354 | if getattr(inst, "filename", None): | ||
|
r1402 | u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename)) | ||
|
r1354 | else: | ||
|
r1402 | u.warn(_("abort: %s\n") % inst.strerror) | ||
|
r250 | else: | ||
raise | ||||
|
r549 | except OSError, inst: | ||
if hasattr(inst, "filename"): | ||||
|
r1402 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) | ||
|
r549 | else: | ||
|
r1402 | u.warn(_("abort: %s\n") % inst.strerror) | ||
|
r870 | except util.Abort, inst: | ||
|
r1402 | u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n') | ||
|
r727 | sys.exit(1) | ||
|
r212 | except TypeError, inst: | ||
# was this an argument error? | ||||
tb = traceback.extract_tb(sys.exc_info()[2]) | ||||
if len(tb) > 2: # no | ||||
raise | ||||
|
r293 | u.debug(inst, "\n") | ||
|
r1402 | u.warn(_("%s: invalid arguments\n") % cmd) | ||
|
r697 | help_(u, cmd) | ||
|
r1215 | except SystemExit: | ||
|
r1229 | # don't catch this in the catch-all below | ||
|
r1215 | raise | ||
except: | ||||
|
r1402 | u.warn(_("** unknown exception encountered, details follow\n")) | ||
u.warn(_("** report bug details to mercurial@selenic.com\n")) | ||||
|
r1552 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") | ||
% version.get_version()) | ||||
|
r1215 | raise | ||
|
r293 | |||
|
r503 | sys.exit(-1) | ||