2005-06-05 02:16:32 +04:00
|
|
|
# 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.
|
|
|
|
|
2005-07-14 13:42:28 +04:00
|
|
|
from demandload import demandload
|
2005-08-28 01:55:07 +04:00
|
|
|
from node import *
|
2005-10-19 05:37:48 +04:00
|
|
|
from i18n import gettext as _
|
2005-09-09 04:09:31 +04:00
|
|
|
demandload(globals(), "os re sys signal shutil imp urllib pdb")
|
2005-08-28 01:56:58 +04:00
|
|
|
demandload(globals(), "fancyopts ui hg util lock revlog")
|
2005-07-06 06:19:01 +04:00
|
|
|
demandload(globals(), "fnmatch hgweb mdiff random signal time traceback")
|
2005-09-08 12:27:25 +04:00
|
|
|
demandload(globals(), "errno socket version struct atexit sets bz2")
|
2005-06-01 12:25:42 +04:00
|
|
|
|
2005-07-14 13:42:28 +04:00
|
|
|
class UnknownCommand(Exception):
|
|
|
|
"""Exception raised if command is not in the command table."""
|
2005-11-07 21:00:51 +03:00
|
|
|
class AmbiguousCommand(Exception):
|
|
|
|
"""Exception raised if command shortcut matches more than one command."""
|
2005-06-01 12:25:42 +04:00
|
|
|
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
def filterfiles(filters, files):
|
2005-07-14 13:42:28 +04:00
|
|
|
l = [x for x in files if x in filters]
|
2005-06-01 23:48:34 +04:00
|
|
|
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
for t in filters:
|
2005-07-14 13:42:28 +04:00
|
|
|
if t and t[-1] != "/":
|
|
|
|
t += "/"
|
|
|
|
l += [x for x in files if x.startswith(t)]
|
2005-06-01 23:48:34 +04:00
|
|
|
return l
|
|
|
|
|
2005-06-01 12:25:42 +04:00
|
|
|
def relpath(repo, args):
|
2005-07-06 06:19:22 +04:00
|
|
|
cwd = repo.getcwd()
|
|
|
|
if cwd:
|
2005-08-13 03:06:52 +04:00
|
|
|
return [util.normpath(os.path.join(cwd, x)) for x in args]
|
2005-06-01 12:25:42 +04:00
|
|
|
return args
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
|
2005-12-01 19:51:45 +03:00
|
|
|
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 = ''
|
2005-10-19 11:02:41 +04:00
|
|
|
return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'),
|
2006-01-17 18:10:22 +03:00
|
|
|
opts.get('exclude'), head)
|
2005-07-21 21:21:33 +04:00
|
|
|
|
2005-12-06 16:10:38 +03:00
|
|
|
def makewalk(repo, pats, opts, node=None, head=''):
|
2006-01-17 18:10:22 +03:00
|
|
|
files, matchfn, anypats = matchpats(repo, pats, opts, head)
|
2005-08-19 01:58:32 +04:00
|
|
|
exact = dict(zip(files, files))
|
2005-08-03 21:10:48 +04:00
|
|
|
def walk():
|
2005-12-06 16:10:38 +03:00
|
|
|
for src, fn in repo.walk(node=node, files=files, match=matchfn):
|
2006-01-17 18:10:22 +03:00
|
|
|
yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact
|
2005-08-03 21:10:48 +04:00
|
|
|
return files, matchfn, walk()
|
|
|
|
|
2005-12-06 16:10:38 +03:00
|
|
|
def walk(repo, pats, opts, node=None, head=''):
|
|
|
|
files, matchfn, results = makewalk(repo, pats, opts, node, head)
|
2005-08-26 17:19:18 +04:00
|
|
|
for r in results:
|
|
|
|
yield r
|
2005-07-18 18:54:21 +04:00
|
|
|
|
2005-12-01 19:51:45 +03:00
|
|
|
def walkchangerevs(ui, repo, pats, opts):
|
2005-08-29 21:05:49 +04:00
|
|
|
'''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.
|
|
|
|
|
2005-12-15 05:53:45 +03:00
|
|
|
This function returns an (iterator, getchange, matchfn) tuple. The
|
2005-08-29 21:05:49 +04:00
|
|
|
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'''
|
2005-09-24 04:50:03 +04:00
|
|
|
|
2006-02-24 00:37:29 +03:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2006-01-17 18:10:22 +03:00
|
|
|
files, matchfn, anypats = matchpats(repo, pats, opts)
|
2005-12-15 05:53:45 +03:00
|
|
|
|
2005-09-24 04:50:03 +04:00
|
|
|
if repo.changelog.count() == 0:
|
2005-12-15 05:53:45 +03:00
|
|
|
return [], False, matchfn
|
2005-09-24 04:50:03 +04:00
|
|
|
|
2005-08-25 13:00:03 +04:00
|
|
|
revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0']))
|
|
|
|
wanted = {}
|
|
|
|
slowpath = anypats
|
|
|
|
fncache = {}
|
2005-08-29 21:05:49 +04:00
|
|
|
|
|
|
|
chcache = {}
|
|
|
|
def getchange(rev):
|
|
|
|
ch = chcache.get(rev)
|
|
|
|
if ch is None:
|
|
|
|
chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev)))
|
|
|
|
return ch
|
|
|
|
|
2005-08-25 13:00:03 +04:00
|
|
|
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):
|
2006-02-24 00:37:29 +03:00
|
|
|
for i, window in increasing_windows(filelog.count()-1, -1):
|
2005-08-25 13:00:03 +04:00
|
|
|
revs = []
|
2006-02-24 00:47:40 +03:00
|
|
|
for j in xrange(i - window, i + 1):
|
2005-08-25 13:00:03 +04:00
|
|
|
revs.append(filelog.linkrev(filelog.node(j)))
|
|
|
|
revs.reverse()
|
|
|
|
for rev in revs:
|
|
|
|
yield rev
|
|
|
|
|
|
|
|
minrev, maxrev = min(revs), max(revs)
|
2006-02-19 21:43:03 +03:00
|
|
|
for file_ in files:
|
|
|
|
filelog = repo.file(file_)
|
2005-08-25 13:00:03 +04:00
|
|
|
# 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:
|
2005-08-26 17:19:18 +04:00
|
|
|
if rev < minrev:
|
|
|
|
break
|
2005-08-25 13:00:03 +04:00
|
|
|
fncache.setdefault(rev, [])
|
2006-02-19 21:43:03 +03:00
|
|
|
fncache[rev].append(file_)
|
2005-08-25 13:00:03 +04:00
|
|
|
wanted[rev] = 1
|
|
|
|
if slowpath:
|
|
|
|
# The slow path checks files modified in every changeset.
|
|
|
|
def changerevgen():
|
2006-02-24 00:37:29 +03:00
|
|
|
for i, window in increasing_windows(repo.changelog.count()-1, -1):
|
2006-02-24 00:47:40 +03:00
|
|
|
for j in xrange(i - window, i + 1):
|
2005-08-29 21:05:49 +04:00
|
|
|
yield j, getchange(j)[3]
|
2005-08-25 13:00:03 +04:00
|
|
|
|
|
|
|
for rev, changefiles in changerevgen():
|
|
|
|
matches = filter(matchfn, changefiles)
|
|
|
|
if matches:
|
|
|
|
fncache[rev] = matches
|
|
|
|
wanted[rev] = 1
|
|
|
|
|
2005-08-29 21:05:49 +04:00
|
|
|
def iterate():
|
2006-02-24 00:37:29 +03:00
|
|
|
for i, window in increasing_windows(0, len(revs)):
|
2005-08-29 21:05:49 +04:00
|
|
|
yield 'window', revs[0] < revs[-1], revs[-1]
|
2006-02-24 00:47:40 +03:00
|
|
|
nrevs = [rev for rev in revs[i:i+window]
|
2005-08-29 21:05:49 +04:00
|
|
|
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
|
2005-12-15 05:53:45 +03:00
|
|
|
return iterate(), getchange, matchfn
|
2005-08-25 13:00:03 +04:00
|
|
|
|
2005-07-03 06:29:54 +04:00
|
|
|
revrangesep = ':'
|
|
|
|
|
2005-07-14 13:42:28 +04:00
|
|
|
def revrange(ui, repo, revs, revlog=None):
|
2005-08-26 17:26:44 +04:00
|
|
|
"""Yield revision as strings from a list of revision specifications."""
|
2005-07-03 06:29:54 +04:00
|
|
|
if revlog is None:
|
|
|
|
revlog = repo.changelog
|
|
|
|
revcount = revlog.count()
|
|
|
|
def fix(val, defval):
|
2005-07-14 13:42:28 +04:00
|
|
|
if not val:
|
|
|
|
return defval
|
2005-07-03 06:29:54 +04:00
|
|
|
try:
|
|
|
|
num = int(val)
|
2005-07-14 13:42:28 +04:00
|
|
|
if str(num) != val:
|
|
|
|
raise ValueError
|
2006-01-12 09:57:58 +03:00
|
|
|
if num < 0:
|
|
|
|
num += revcount
|
|
|
|
if num < 0:
|
|
|
|
num = 0
|
2005-09-15 11:04:29 +04:00
|
|
|
elif num >= revcount:
|
2005-07-03 06:29:54 +04:00
|
|
|
raise ValueError
|
|
|
|
except ValueError:
|
|
|
|
try:
|
|
|
|
num = repo.changelog.rev(repo.lookup(val))
|
|
|
|
except KeyError:
|
|
|
|
try:
|
|
|
|
num = revlog.rev(revlog.lookup(val))
|
|
|
|
except KeyError:
|
2005-10-19 05:38:39 +04:00
|
|
|
raise util.Abort(_('invalid revision identifier %s'), val)
|
2005-07-03 06:29:54 +04:00
|
|
|
return num
|
2005-08-29 21:05:49 +04:00
|
|
|
seen = {}
|
2005-07-03 06:29:54 +04:00
|
|
|
for spec in revs:
|
|
|
|
if spec.find(revrangesep) >= 0:
|
|
|
|
start, end = spec.split(revrangesep, 1)
|
|
|
|
start = fix(start, 0)
|
|
|
|
end = fix(end, revcount - 1)
|
2005-08-26 17:26:44 +04:00
|
|
|
step = start > end and -1 or 1
|
|
|
|
for rev in xrange(start, end+step, step):
|
2006-01-12 09:57:58 +03:00
|
|
|
if rev in seen:
|
|
|
|
continue
|
2005-08-29 21:05:49 +04:00
|
|
|
seen[rev] = 1
|
2005-07-03 06:29:54 +04:00
|
|
|
yield str(rev)
|
|
|
|
else:
|
2005-08-29 21:05:49 +04:00
|
|
|
rev = fix(spec, None)
|
2006-01-12 09:57:58 +03:00
|
|
|
if rev in seen:
|
|
|
|
continue
|
2005-08-29 21:05:49 +04:00
|
|
|
seen[rev] = 1
|
|
|
|
yield str(rev)
|
2005-07-03 06:29:54 +04:00
|
|
|
|
2005-07-20 16:08:11 +04:00
|
|
|
def make_filename(repo, r, pat, node=None,
|
2005-09-15 08:57:41 +04:00
|
|
|
total=None, seqno=None, revwidth=None, pathname=None):
|
2005-07-06 06:23:56 +04:00
|
|
|
node_expander = {
|
2005-08-28 01:55:07 +04:00
|
|
|
'H': lambda: hex(node),
|
2005-07-06 06:23:56 +04:00
|
|
|
'R': lambda: str(r.rev(node)),
|
2005-08-28 01:55:07 +04:00
|
|
|
'h': lambda: short(node),
|
2005-07-06 06:23:56 +04:00
|
|
|
}
|
|
|
|
expander = {
|
|
|
|
'%': lambda: '%',
|
|
|
|
'b': lambda: os.path.basename(repo.root),
|
|
|
|
}
|
|
|
|
|
2005-07-19 19:42:36 +04:00
|
|
|
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)))
|
2005-09-15 08:57:41 +04:00
|
|
|
if pathname is not None:
|
|
|
|
expander['s'] = lambda: os.path.basename(pathname)
|
|
|
|
expander['d'] = lambda: os.path.dirname(pathname) or '.'
|
|
|
|
expander['p'] = lambda: pathname
|
2005-07-19 19:42:36 +04:00
|
|
|
|
|
|
|
newname = []
|
|
|
|
patlen = len(pat)
|
|
|
|
i = 0
|
|
|
|
while i < patlen:
|
2005-07-06 06:23:56 +04:00
|
|
|
c = pat[i]
|
2005-07-19 19:42:36 +04:00
|
|
|
if c == '%':
|
|
|
|
i += 1
|
|
|
|
c = pat[i]
|
|
|
|
c = expander[c]()
|
|
|
|
newname.append(c)
|
|
|
|
i += 1
|
2005-07-20 16:08:11 +04:00
|
|
|
return ''.join(newname)
|
2005-07-19 19:42:36 +04:00
|
|
|
except KeyError, inst:
|
2005-10-19 05:38:39 +04:00
|
|
|
raise util.Abort(_("invalid format spec '%%%s' in output file name"),
|
2005-07-19 19:42:36 +04:00
|
|
|
inst.args[0])
|
2005-07-06 06:23:56 +04:00
|
|
|
|
2005-07-20 16:08:11 +04:00
|
|
|
def make_file(repo, r, pat, node=None,
|
2005-09-15 08:57:41 +04:00
|
|
|
total=None, seqno=None, revwidth=None, mode='wb', pathname=None):
|
2005-07-20 16:08:11 +04:00
|
|
|
if not pat or pat == '-':
|
2005-08-26 17:19:18 +04:00
|
|
|
return 'w' in mode and sys.stdout or sys.stdin
|
2005-07-20 16:08:11 +04:00
|
|
|
if hasattr(pat, 'write') and 'w' in mode:
|
|
|
|
return pat
|
|
|
|
if hasattr(pat, 'read') and 'r' in mode:
|
|
|
|
return pat
|
2005-09-15 08:57:41 +04:00
|
|
|
return open(make_filename(repo, r, pat, node, total, seqno, revwidth,
|
|
|
|
pathname),
|
2005-07-20 16:08:11 +04:00
|
|
|
mode)
|
|
|
|
|
2005-08-24 05:58:26 +04:00
|
|
|
def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always,
|
2006-02-15 21:39:47 +03:00
|
|
|
changes=None, text=False, opts={}):
|
2006-02-26 18:23:14 +03:00
|
|
|
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])
|
2006-02-26 04:26:17 +03:00
|
|
|
|
2005-08-15 08:09:32 +04:00
|
|
|
if not changes:
|
2006-01-12 15:35:09 +03:00
|
|
|
changes = repo.changes(node1, node2, files, match=match)
|
2006-01-12 15:58:36 +03:00
|
|
|
modified, added, removed, deleted, unknown = changes
|
2005-07-01 09:28:18 +04:00
|
|
|
if files:
|
2006-01-18 18:55:05 +03:00
|
|
|
modified, added, removed = map(lambda x: filterfiles(files, x),
|
2006-01-12 15:35:09 +03:00
|
|
|
(modified, added, removed))
|
2005-07-01 09:28:18 +04:00
|
|
|
|
2006-01-12 15:35:09 +03:00
|
|
|
if not modified and not added and not removed:
|
2005-07-01 09:28:18 +04:00
|
|
|
return
|
|
|
|
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
if node2:
|
|
|
|
change = repo.changelog.read(node2)
|
|
|
|
mmap2 = repo.manifest.read(change[0])
|
2005-09-23 10:19:47 +04:00
|
|
|
date2 = util.datestr(change[2])
|
2005-07-14 13:42:28 +04:00
|
|
|
def read(f):
|
|
|
|
return repo.file(f).read(mmap2[f])
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
else:
|
2005-09-23 09:46:50 +04:00
|
|
|
date2 = util.datestr()
|
2005-07-14 13:42:28 +04:00
|
|
|
def read(f):
|
2006-01-29 00:10:16 +03:00
|
|
|
return repo.wread(f)
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
|
2005-06-17 23:37:23 +04:00
|
|
|
if ui.quiet:
|
|
|
|
r = None
|
|
|
|
else:
|
2005-08-28 01:55:07 +04:00
|
|
|
hexfunc = ui.verbose and hex or short
|
2005-06-17 23:37:23 +04:00
|
|
|
r = [hexfunc(node) for node in [node1, node2] if node]
|
|
|
|
|
2006-01-24 05:02:10 +03:00
|
|
|
diffopts = ui.diffopts()
|
2006-02-15 21:39:47 +03:00
|
|
|
showfunc = opts.get('show_function') or diffopts['showfunc']
|
|
|
|
ignorews = opts.get('ignore_all_space') or diffopts['ignorews']
|
2006-01-12 15:35:09 +03:00
|
|
|
for f in modified:
|
2005-06-08 08:06:05 +04:00
|
|
|
to = None
|
|
|
|
if f in mmap:
|
|
|
|
to = repo.file(f).read(mmap[f])
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
tn = read(f)
|
2006-01-24 05:02:10 +03:00
|
|
|
fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text,
|
|
|
|
showfunc=showfunc, ignorews=ignorews))
|
2006-01-12 15:35:09 +03:00
|
|
|
for f in added:
|
2005-06-06 22:51:09 +04:00
|
|
|
to = None
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
tn = read(f)
|
2006-01-24 05:02:10 +03:00
|
|
|
fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text,
|
|
|
|
showfunc=showfunc, ignorews=ignorews))
|
2006-01-12 15:35:09 +03:00
|
|
|
for f in removed:
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
to = repo.file(f).read(mmap[f])
|
2005-06-06 22:51:09 +04:00
|
|
|
tn = None
|
2006-01-24 05:02:10 +03:00
|
|
|
fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text,
|
|
|
|
showfunc=showfunc, ignorews=ignorews))
|
2005-06-13 11:49:21 +04:00
|
|
|
|
2005-08-29 21:31:41 +04:00
|
|
|
def trimuser(ui, name, rev, revcache):
|
2005-08-29 21:05:49 +04:00
|
|
|
"""trim the name of the user who committed a change"""
|
2005-08-29 21:31:41 +04:00
|
|
|
user = revcache.get(rev)
|
|
|
|
if user is None:
|
|
|
|
user = revcache[rev] = ui.shortuser(name)
|
|
|
|
return user
|
2005-08-29 21:05:49 +04:00
|
|
|
|
2005-08-24 23:39:10 +04:00
|
|
|
def show_changeset(ui, repo, rev=0, changenode=None, brinfo=None):
|
2005-06-13 11:49:21 +04:00
|
|
|
"""show a single changeset or file revision"""
|
2005-08-24 23:39:10 +04:00
|
|
|
log = repo.changelog
|
|
|
|
if changenode is None:
|
|
|
|
changenode = log.node(rev)
|
|
|
|
elif not rev:
|
|
|
|
rev = log.rev(changenode)
|
2005-06-13 11:49:21 +04:00
|
|
|
|
|
|
|
if ui.quiet:
|
2005-08-28 01:55:07 +04:00
|
|
|
ui.write("%d:%s\n" % (rev, short(changenode)))
|
2005-06-13 11:49:21 +04:00
|
|
|
return
|
|
|
|
|
2005-08-24 23:39:10 +04:00
|
|
|
changes = log.read(changenode)
|
2005-09-23 10:19:47 +04:00
|
|
|
date = util.datestr(changes[2])
|
2005-08-20 11:23:42 +04:00
|
|
|
|
2005-08-28 01:55:07 +04:00
|
|
|
parents = [(log.rev(p), ui.verbose and hex(p) or short(p))
|
2005-08-24 23:39:10 +04:00
|
|
|
for p in log.parents(changenode)
|
2005-08-28 01:55:07 +04:00
|
|
|
if ui.debugflag or p != nullid]
|
2005-06-13 11:49:21 +04:00
|
|
|
if not ui.debugflag and len(parents) == 1 and parents[0][0] == rev-1:
|
|
|
|
parents = []
|
|
|
|
|
2005-07-27 20:14:52 +04:00
|
|
|
if ui.verbose:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode)))
|
2005-07-27 20:14:52 +04:00
|
|
|
else:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.write(_("changeset: %d:%s\n") % (rev, short(changenode)))
|
2005-07-27 20:14:52 +04:00
|
|
|
|
2005-07-13 08:55:42 +04:00
|
|
|
for tag in repo.nodetags(changenode):
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.status(_("tag: %s\n") % tag)
|
2005-07-13 08:55:42 +04:00
|
|
|
for parent in parents:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.write(_("parent: %d:%s\n") % parent)
|
2005-07-27 20:14:52 +04:00
|
|
|
|
2005-08-15 00:23:45 +04:00
|
|
|
if brinfo and changenode in brinfo:
|
|
|
|
br = brinfo[changenode]
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.write(_("branch: %s\n") % " ".join(br))
|
2005-08-15 00:23:45 +04:00
|
|
|
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.debug(_("manifest: %d:%s\n") % (repo.manifest.rev(changes[0]),
|
2005-08-28 01:55:07 +04:00
|
|
|
hex(changes[0])))
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.status(_("user: %s\n") % changes[1])
|
|
|
|
ui.status(_("date: %s\n") % date)
|
2005-07-27 20:14:52 +04:00
|
|
|
|
2005-06-28 09:50:28 +04:00
|
|
|
if ui.debugflag:
|
2005-08-24 23:39:10 +04:00
|
|
|
files = repo.changes(log.parents(changenode)[0], changenode)
|
2005-10-19 05:38:39 +04:00
|
|
|
for key, value in zip([_("files:"), _("files+:"), _("files-:")], files):
|
2005-06-27 09:17:28 +04:00
|
|
|
if value:
|
|
|
|
ui.note("%-12s %s\n" % (key, " ".join(value)))
|
2005-06-28 09:50:28 +04:00
|
|
|
else:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.note(_("files: %s\n") % " ".join(changes[3]))
|
2005-07-27 20:14:52 +04:00
|
|
|
|
2005-06-14 11:01:18 +04:00
|
|
|
description = changes[4].strip()
|
2005-06-13 11:49:21 +04:00
|
|
|
if description:
|
2005-06-14 06:36:40 +04:00
|
|
|
if ui.verbose:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.status(_("description:\n"))
|
2005-06-14 11:01:18 +04:00
|
|
|
ui.status(description)
|
2005-07-01 10:40:32 +04:00
|
|
|
ui.status("\n\n")
|
2005-06-14 06:36:40 +04:00
|
|
|
else:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.status(_("summary: %s\n") % description.splitlines()[0])
|
2005-06-13 11:49:21 +04:00
|
|
|
ui.status("\n")
|
|
|
|
|
2005-06-25 12:16:39 +04:00
|
|
|
def show_version(ui):
|
2005-06-18 19:32:41 +04:00
|
|
|
"""output version and copyright information"""
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.write(_("Mercurial Distributed SCM (version %s)\n")
|
2005-08-06 18:43:12 +04:00
|
|
|
% version.get_version())
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.status(_(
|
2005-06-18 19:32:41 +04:00
|
|
|
"\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"
|
2005-10-19 05:38:39 +04:00
|
|
|
))
|
2005-06-18 19:32:41 +04:00
|
|
|
|
2005-08-26 10:42:56 +04:00
|
|
|
def help_(ui, cmd=None, with_version=False):
|
2005-07-14 13:42:28 +04:00
|
|
|
"""show help for a given command or all commands"""
|
2005-08-26 11:56:33 +04:00
|
|
|
option_lists = []
|
2005-08-06 16:27:31 +04:00
|
|
|
if cmd and cmd != 'shortlist':
|
2005-08-26 10:42:56 +04:00
|
|
|
if with_version:
|
|
|
|
show_version(ui)
|
|
|
|
ui.write('\n')
|
2005-11-07 20:39:25 +03:00
|
|
|
aliases, i = find(cmd)
|
2005-08-06 18:43:12 +04:00
|
|
|
# synopsis
|
2005-08-06 17:04:59 +04:00
|
|
|
ui.write("%s\n\n" % i[2])
|
|
|
|
|
2005-08-06 18:43:12 +04:00
|
|
|
# description
|
|
|
|
doc = i[0].__doc__
|
2006-02-09 11:07:19 +03:00
|
|
|
if not doc:
|
|
|
|
doc = _("(No help text available)")
|
2005-08-06 18:43:12 +04:00
|
|
|
if ui.quiet:
|
|
|
|
doc = doc.splitlines(0)[0]
|
|
|
|
ui.write("%s\n" % doc.rstrip())
|
|
|
|
|
|
|
|
if not ui.quiet:
|
2005-08-26 11:56:33 +04:00
|
|
|
# aliases
|
2005-11-07 20:39:25 +03:00
|
|
|
if len(aliases) > 1:
|
|
|
|
ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:]))
|
2005-08-06 18:43:12 +04:00
|
|
|
|
2005-08-26 11:56:33 +04:00
|
|
|
# options
|
|
|
|
if i[1]:
|
|
|
|
option_lists.append(("options", i[1]))
|
2005-08-06 17:04:59 +04:00
|
|
|
|
2005-06-05 07:09:00 +04:00
|
|
|
else:
|
2005-08-06 18:43:12 +04:00
|
|
|
# program name
|
2005-08-26 10:42:56 +04:00
|
|
|
if ui.verbose or with_version:
|
2005-06-25 12:16:39 +04:00
|
|
|
show_version(ui)
|
2005-07-03 15:58:05 +04:00
|
|
|
else:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.status(_("Mercurial Distributed SCM\n"))
|
2005-08-06 18:43:12 +04:00
|
|
|
ui.status('\n')
|
2005-08-06 16:27:31 +04:00
|
|
|
|
2005-08-06 18:43:12 +04:00
|
|
|
# list of commands
|
2005-08-06 16:27:31 +04:00
|
|
|
if cmd == "shortlist":
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.status(_('basic commands (use "hg help" '
|
|
|
|
'for the full list or option "-v" for details):\n\n'))
|
2005-08-06 18:43:12 +04:00
|
|
|
elif ui.verbose:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.status(_('list of commands:\n\n'))
|
2005-08-06 18:43:12 +04:00
|
|
|
else:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.status(_('list of commands (use "hg help -v" '
|
|
|
|
'to show aliases and global options):\n\n'))
|
2005-06-05 07:09:00 +04:00
|
|
|
|
|
|
|
h = {}
|
2005-08-06 16:27:31 +04:00
|
|
|
cmds = {}
|
2005-06-26 17:14:04 +04:00
|
|
|
for c, e in table.items():
|
|
|
|
f = c.split("|")[0]
|
2005-08-06 16:27:31 +04:00
|
|
|
if cmd == "shortlist" and not f.startswith("^"):
|
2005-07-03 15:58:05 +04:00
|
|
|
continue
|
2005-08-06 18:43:12 +04:00
|
|
|
f = f.lstrip("^")
|
2005-07-03 15:58:05 +04:00
|
|
|
if not ui.debugflag and f.startswith("debug"):
|
2005-06-26 17:14:04 +04:00
|
|
|
continue
|
2006-02-09 11:07:19 +03:00
|
|
|
doc = e[0].__doc__
|
|
|
|
if not doc:
|
|
|
|
doc = _("(No help text available)")
|
|
|
|
h[f] = doc.splitlines(0)[0].rstrip()
|
2006-01-12 09:57:58 +03:00
|
|
|
cmds[f] = c.lstrip("^")
|
2005-06-05 07:09:00 +04:00
|
|
|
|
|
|
|
fns = h.keys()
|
|
|
|
fns.sort()
|
|
|
|
m = max(map(len, fns))
|
|
|
|
for f in fns:
|
2005-08-06 16:27:31 +04:00
|
|
|
if ui.verbose:
|
|
|
|
commands = cmds[f].replace("|",", ")
|
2006-01-12 09:57:58 +03:00
|
|
|
ui.write(" %s:\n %s\n"%(commands, h[f]))
|
2005-08-06 16:27:31 +04:00
|
|
|
else:
|
|
|
|
ui.write(' %-*s %s\n' % (m, f, h[f]))
|
2005-06-05 07:09:00 +04:00
|
|
|
|
2005-08-06 18:43:12 +04:00
|
|
|
# global options
|
|
|
|
if ui.verbose:
|
2005-08-26 11:56:33 +04:00
|
|
|
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,
|
2005-12-28 09:27:05 +03:00
|
|
|
default
|
|
|
|
and _(" (default: %s)") % default
|
2005-08-26 11:56:33 +04:00
|
|
|
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)
|
2005-06-05 07:09:00 +04:00
|
|
|
|
|
|
|
# Commands start here, listed alphabetically
|
2005-06-01 12:25:42 +04:00
|
|
|
|
2005-07-18 18:54:21 +04:00
|
|
|
def add(ui, repo, *pats, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
|
2005-12-01 19:51:45 +03:00
|
|
|
If no names are given, add all files in the repository.
|
2005-10-25 02:52:28 +04:00
|
|
|
"""
|
|
|
|
|
2005-07-18 18:54:21 +04:00
|
|
|
names = []
|
2005-08-19 01:58:32 +04:00
|
|
|
for src, abs, rel, exact in walk(repo, pats, opts):
|
|
|
|
if exact:
|
2006-01-12 09:57:58 +03:00
|
|
|
if ui.verbose:
|
|
|
|
ui.status(_('adding %s\n') % rel)
|
2005-07-18 18:54:21 +04:00
|
|
|
names.append(abs)
|
|
|
|
elif repo.dirstate.state(abs) == '?':
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.status(_('adding %s\n') % rel)
|
2005-07-18 18:54:21 +04:00
|
|
|
names.append(abs)
|
|
|
|
repo.add(names)
|
2005-06-01 12:25:42 +04:00
|
|
|
|
2005-07-23 07:45:48 +04:00
|
|
|
def addremove(ui, repo, *pats, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2006-02-10 02:18:43 +03:00
|
|
|
return addremove_lock(ui, repo, pats, opts)
|
|
|
|
|
|
|
|
def addremove_lock(ui, repo, pats, opts, wlock=None):
|
2005-07-29 20:42:28 +04:00
|
|
|
add, remove = [], []
|
2005-08-19 01:58:32 +04:00
|
|
|
for src, abs, rel, exact in walk(repo, pats, opts):
|
2005-08-12 19:12:08 +04:00
|
|
|
if src == 'f' and repo.dirstate.state(abs) == '?':
|
|
|
|
add.append(abs)
|
2005-09-15 09:32:12 +04:00
|
|
|
if ui.verbose or not exact:
|
2006-01-17 18:10:22 +03:00
|
|
|
ui.status(_('adding %s\n') % ((pats and rel) or abs))
|
2005-08-12 19:12:08 +04:00
|
|
|
if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel):
|
2005-07-29 20:42:28 +04:00
|
|
|
remove.append(abs)
|
2005-09-15 09:32:12 +04:00
|
|
|
if ui.verbose or not exact:
|
2006-01-17 18:10:22 +03:00
|
|
|
ui.status(_('removing %s\n') % ((pats and rel) or abs))
|
2006-02-10 02:18:43 +03:00
|
|
|
repo.add(add, wlock=wlock)
|
|
|
|
repo.remove(remove, wlock=wlock)
|
2005-06-01 12:25:42 +04:00
|
|
|
|
2005-07-20 15:23:12 +04:00
|
|
|
def annotate(ui, repo, *pats, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2005-06-01 12:25:42 +04:00
|
|
|
def getnode(rev):
|
2005-08-28 01:55:07 +04:00
|
|
|
return short(repo.changelog.node(rev))
|
2005-06-01 12:25:42 +04:00
|
|
|
|
2005-08-29 21:05:49 +04:00
|
|
|
ucache = {}
|
2005-06-01 12:25:42 +04:00
|
|
|
def getname(rev):
|
2005-08-29 21:05:49 +04:00
|
|
|
cl = repo.changelog.read(repo.changelog.node(rev))
|
2005-08-29 21:31:41 +04:00
|
|
|
return trimuser(ui, cl[1], rev, ucache)
|
2005-06-28 12:59:59 +04:00
|
|
|
|
2005-11-10 00:39:24 +03:00
|
|
|
dcache = {}
|
|
|
|
def getdate(rev):
|
2006-01-12 09:57:58 +03:00
|
|
|
datestr = dcache.get(rev)
|
2005-11-10 00:39:24 +03:00
|
|
|
if datestr is None:
|
|
|
|
cl = repo.changelog.read(repo.changelog.node(rev))
|
|
|
|
datestr = dcache[rev] = util.datestr(cl[2])
|
2006-01-12 09:57:58 +03:00
|
|
|
return datestr
|
2005-11-10 00:39:24 +03:00
|
|
|
|
2005-07-21 21:22:54 +04:00
|
|
|
if not pats:
|
2005-10-19 05:38:39 +04:00
|
|
|
raise util.Abort(_('at least one file name or pattern required'))
|
2005-07-21 21:22:54 +04:00
|
|
|
|
2005-11-10 00:39:56 +03:00
|
|
|
opmap = [['user', getname], ['number', str], ['changeset', getnode],
|
|
|
|
['date', getdate]]
|
2005-11-10 00:39:24 +03:00
|
|
|
if not opts['user'] and not opts['changeset'] and not opts['date']:
|
2005-07-16 10:56:39 +04:00
|
|
|
opts['number'] = 1
|
2005-06-01 12:25:42 +04:00
|
|
|
|
2005-07-16 10:58:56 +04:00
|
|
|
if opts['rev']:
|
|
|
|
node = repo.changelog.lookup(opts['rev'])
|
2005-07-16 10:56:39 +04:00
|
|
|
else:
|
|
|
|
node = repo.dirstate.parents()[0]
|
2005-06-01 12:25:42 +04:00
|
|
|
change = repo.changelog.read(node)
|
|
|
|
mmap = repo.manifest.read(change[0])
|
2005-08-24 07:21:52 +04:00
|
|
|
|
2006-03-07 22:37:27 +03:00
|
|
|
for src, abs, rel, exact in walk(repo, pats, opts, node=node):
|
2005-08-24 07:21:52 +04:00
|
|
|
f = repo.file(abs)
|
|
|
|
if not opts['text'] and util.binary(f.read(mmap[abs])):
|
2006-01-17 18:10:22 +03:00
|
|
|
ui.write(_("%s: binary file\n") % ((pats and rel) or abs))
|
2005-08-24 07:21:52 +04:00
|
|
|
continue
|
|
|
|
|
|
|
|
lines = f.annotate(mmap[abs])
|
2005-06-01 12:25:42 +04:00
|
|
|
pieces = []
|
|
|
|
|
|
|
|
for o, f in opmap:
|
2005-07-16 10:56:39 +04:00
|
|
|
if opts[o]:
|
2005-07-14 13:42:28 +04:00
|
|
|
l = [f(n) for n, dummy in lines]
|
2005-07-23 23:11:49 +04:00
|
|
|
if l:
|
|
|
|
m = max(map(len, l))
|
|
|
|
pieces.append(["%*s" % (m, x) for x in l])
|
2005-06-01 12:25:42 +04:00
|
|
|
|
2005-07-23 23:11:49 +04:00
|
|
|
if pieces:
|
|
|
|
for p, l in zip(zip(*pieces), lines):
|
|
|
|
ui.write("%s: %s" % (" ".join(p), l[1]))
|
2005-06-01 12:25:42 +04:00
|
|
|
|
2005-09-08 12:27:25 +04:00
|
|
|
def bundle(ui, repo, fname, dest="default-push", **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2005-09-08 12:27:25 +04:00
|
|
|
f = open(fname, "wb")
|
2005-10-25 04:41:45 +04:00
|
|
|
dest = ui.expandpath(dest, repo.root)
|
2005-09-08 12:27:25 +04:00
|
|
|
other = hg.repository(ui, dest)
|
|
|
|
o = repo.findoutgoing(other)
|
2006-02-17 19:26:21 +03:00
|
|
|
cg = repo.changegroup(o, 'bundle')
|
2005-09-08 12:27:25 +04:00
|
|
|
|
|
|
|
try:
|
|
|
|
f.write("HG10")
|
|
|
|
z = bz2.BZ2Compressor(9)
|
|
|
|
while 1:
|
|
|
|
chunk = cg.read(4096)
|
|
|
|
if not chunk:
|
|
|
|
break
|
|
|
|
f.write(z.compress(chunk))
|
|
|
|
f.write(z.flush())
|
|
|
|
except:
|
|
|
|
os.unlink(fname)
|
2005-09-30 22:06:19 +04:00
|
|
|
raise
|
2005-09-08 12:27:25 +04:00
|
|
|
|
2005-09-15 08:57:41 +04:00
|
|
|
def cat(ui, repo, file1, *pats, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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
|
|
|
|
"""
|
2005-09-15 08:57:41 +04:00
|
|
|
mf = {}
|
2005-11-14 18:10:59 +03:00
|
|
|
rev = opts['rev']
|
|
|
|
if rev:
|
2005-12-06 16:10:38 +03:00
|
|
|
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):
|
2005-09-15 08:57:41 +04:00
|
|
|
r = repo.file(abs)
|
2005-12-06 16:10:38 +03:00
|
|
|
n = mf[abs]
|
2005-09-15 08:57:41 +04:00
|
|
|
fp = make_file(repo, r, opts['output'], node=n, pathname=abs)
|
|
|
|
fp.write(r.read(n))
|
2005-06-05 01:45:31 +04:00
|
|
|
|
2005-07-14 18:30:49 +04:00
|
|
|
def clone(ui, source, dest=None, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
2006-02-28 02:46:06 +03:00
|
|
|
|
|
|
|
See pull for valid source format details.
|
2005-10-25 02:52:28 +04:00
|
|
|
"""
|
2005-06-27 03:20:46 +04:00
|
|
|
if dest is None:
|
2005-06-30 09:55:25 +04:00
|
|
|
dest = os.path.basename(os.path.normpath(source))
|
2005-06-30 20:47:31 +04:00
|
|
|
|
|
|
|
if os.path.exists(dest):
|
2005-10-19 05:38:39 +04:00
|
|
|
raise util.Abort(_("destination '%s' already exists"), dest)
|
2005-06-30 02:04:56 +04:00
|
|
|
|
2005-08-14 02:41:51 +04:00
|
|
|
dest = os.path.realpath(dest)
|
|
|
|
|
2005-11-19 09:48:47 +03:00
|
|
|
class Dircleanup(object):
|
2005-07-14 13:42:28 +04:00
|
|
|
def __init__(self, dir_):
|
2005-07-06 06:12:57 +04:00
|
|
|
self.rmtree = shutil.rmtree
|
2005-07-14 13:42:28 +04:00
|
|
|
self.dir_ = dir_
|
|
|
|
os.mkdir(dir_)
|
2005-06-30 22:07:50 +04:00
|
|
|
def close(self):
|
2005-07-14 13:42:28 +04:00
|
|
|
self.dir_ = None
|
2005-06-30 22:07:50 +04:00
|
|
|
def __del__(self):
|
2005-07-14 13:42:28 +04:00
|
|
|
if self.dir_:
|
|
|
|
self.rmtree(self.dir_, True)
|
2005-06-30 22:07:50 +04:00
|
|
|
|
2005-08-20 10:11:48 +04:00
|
|
|
if opts['ssh']:
|
|
|
|
ui.setconfig("ui", "ssh", opts['ssh'])
|
|
|
|
if opts['remotecmd']:
|
|
|
|
ui.setconfig("ui", "remotecmd", opts['remotecmd'])
|
|
|
|
|
2005-09-08 23:10:59 +04:00
|
|
|
if not os.path.exists(source):
|
|
|
|
source = ui.expandpath(source)
|
2005-09-22 20:47:03 +04:00
|
|
|
|
|
|
|
d = Dircleanup(dest)
|
2005-08-20 10:48:43 +04:00
|
|
|
abspath = source
|
2005-07-07 10:14:10 +04:00
|
|
|
other = hg.repository(ui, source)
|
|
|
|
|
2005-09-15 00:48:34 +04:00
|
|
|
copy = False
|
2005-09-22 20:47:27 +04:00
|
|
|
if other.dev() != -1:
|
2005-07-11 04:15:20 +04:00
|
|
|
abspath = os.path.abspath(source)
|
2005-10-08 06:51:09 +04:00
|
|
|
if not opts['pull'] and not opts['rev']:
|
2005-09-22 20:47:27 +04:00
|
|
|
copy = True
|
2005-09-23 21:31:00 +04:00
|
|
|
|
2005-09-15 00:48:34 +04:00
|
|
|
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
|
2006-02-20 03:12:03 +03:00
|
|
|
l1 = other.lock()
|
|
|
|
except lock.LockException:
|
2005-09-15 00:48:34 +04:00
|
|
|
copy = False
|
|
|
|
|
|
|
|
if copy:
|
|
|
|
# we lock here to avoid premature writing to the target
|
2005-09-08 06:30:23 +04:00
|
|
|
os.mkdir(os.path.join(dest, ".hg"))
|
2005-09-08 06:37:11 +04:00
|
|
|
l2 = lock.lock(os.path.join(dest, ".hg", "lock"))
|
2005-08-28 06:15:02 +04:00
|
|
|
|
2005-09-08 06:30:23 +04:00
|
|
|
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)
|
2005-10-26 01:55:39 +04:00
|
|
|
try:
|
|
|
|
util.copyfiles(src, dst)
|
|
|
|
except OSError, inst:
|
2006-01-12 09:57:58 +03:00
|
|
|
if inst.errno != errno.ENOENT:
|
|
|
|
raise
|
2005-06-27 03:20:46 +04:00
|
|
|
|
2005-06-30 22:07:50 +04:00
|
|
|
repo = hg.repository(ui, dest)
|
2005-06-27 03:20:46 +04:00
|
|
|
|
2005-06-30 22:07:50 +04:00
|
|
|
else:
|
2005-10-12 22:32:51 +04:00
|
|
|
revs = None
|
2005-10-08 06:51:09 +04:00
|
|
|
if opts['rev']:
|
2005-10-11 19:39:21 +04:00
|
|
|
if not other.local():
|
2005-12-29 23:59:19 +03:00
|
|
|
error = _("clone -r not supported yet for remote repositories.")
|
2005-12-28 09:27:05 +03:00
|
|
|
raise util.Abort(error)
|
2005-10-11 19:39:21 +04:00
|
|
|
else:
|
|
|
|
revs = [other.lookup(rev) for rev in opts['rev']]
|
2005-06-30 22:07:50 +04:00
|
|
|
repo = hg.repository(ui, dest, create=1)
|
2005-10-11 19:39:21 +04:00
|
|
|
repo.pull(other, heads = revs)
|
2005-06-28 12:59:59 +04:00
|
|
|
|
2005-09-23 21:31:00 +04:00
|
|
|
f = repo.opener("hgrc", "w", text=True)
|
2005-09-08 06:16:36 +04:00
|
|
|
f.write("[paths]\n")
|
|
|
|
f.write("default = %s\n" % abspath)
|
2005-11-15 22:35:10 +03:00
|
|
|
f.close()
|
2005-06-28 12:59:59 +04:00
|
|
|
|
2005-06-30 22:07:50 +04:00
|
|
|
if not opts['noupdate']:
|
2006-03-06 19:47:41 +03:00
|
|
|
update(repo.ui, repo)
|
2005-06-30 22:07:50 +04:00
|
|
|
|
|
|
|
d.close()
|
2005-06-29 22:42:35 +04:00
|
|
|
|
2005-07-30 03:02:27 +04:00
|
|
|
def commit(ui, repo, *pats, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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"
|
2005-12-01 19:51:45 +03:00
|
|
|
will be commited.
|
2005-10-25 02:52:28 +04:00
|
|
|
|
|
|
|
The HGEDITOR or EDITOR environment variables are used to start an
|
|
|
|
editor to add a commit comment.
|
|
|
|
"""
|
2005-10-25 07:42:20 +04:00
|
|
|
message = opts['message']
|
2005-07-14 13:42:28 +04:00
|
|
|
logfile = opts['logfile']
|
2005-09-23 08:42:33 +04:00
|
|
|
|
|
|
|
if message and logfile:
|
2005-10-19 05:38:39 +04:00
|
|
|
raise util.Abort(_('options --message and --logfile are mutually '
|
|
|
|
'exclusive'))
|
2005-07-22 19:26:46 +04:00
|
|
|
if not message and logfile:
|
2005-07-14 13:42:28 +04:00
|
|
|
try:
|
2005-08-15 00:30:01 +04:00
|
|
|
if logfile == '-':
|
|
|
|
message = sys.stdin.read()
|
|
|
|
else:
|
|
|
|
message = open(logfile).read()
|
2005-09-23 08:42:33 +04:00
|
|
|
except IOError, inst:
|
2005-10-19 05:38:39 +04:00
|
|
|
raise util.Abort(_("can't read commit message '%s': %s") %
|
2005-09-23 08:42:33 +04:00
|
|
|
(logfile, inst.strerror))
|
2005-06-09 04:28:34 +04:00
|
|
|
|
2005-06-15 22:01:15 +04:00
|
|
|
if opts['addremove']:
|
2005-07-30 03:02:27 +04:00
|
|
|
addremove(ui, repo, *pats, **opts)
|
2006-01-17 18:10:22 +03:00
|
|
|
fns, match, anypats = matchpats(repo, pats, opts)
|
2005-07-30 03:02:27 +04:00
|
|
|
if pats:
|
2006-01-12 15:58:36 +03:00
|
|
|
modified, added, removed, deleted, unknown = (
|
2006-01-12 15:35:09 +03:00
|
|
|
repo.changes(files=fns, match=match))
|
2006-01-12 15:58:36 +03:00
|
|
|
files = modified + added + removed
|
2005-07-30 03:02:27 +04:00
|
|
|
else:
|
|
|
|
files = []
|
2005-09-05 01:47:02 +04:00
|
|
|
try:
|
|
|
|
repo.commit(files, message, opts['user'], opts['date'], match)
|
|
|
|
except ValueError, inst:
|
|
|
|
raise util.Abort(str(inst))
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
|
2006-03-01 10:47:40 +03:00
|
|
|
def docopy(ui, repo, pats, opts, wlock):
|
|
|
|
# called with the repo lock held
|
2005-11-08 21:35:05 +03:00
|
|
|
cwd = repo.getcwd()
|
|
|
|
errors = 0
|
|
|
|
copied = []
|
2005-11-08 21:35:13 +03:00
|
|
|
targets = {}
|
2005-09-15 01:29:02 +04:00
|
|
|
|
|
|
|
def okaytocopy(abs, rel, exact):
|
2005-10-19 05:38:39 +04:00
|
|
|
reasons = {'?': _('is not managed'),
|
2006-01-24 03:59:01 +03:00
|
|
|
'a': _('has been marked for add'),
|
|
|
|
'r': _('has been marked for remove')}
|
2006-02-18 18:37:59 +03:00
|
|
|
state = repo.dirstate.state(abs)
|
|
|
|
reason = reasons.get(state)
|
2005-09-15 01:29:02 +04:00
|
|
|
if reason:
|
2006-02-18 18:37:59 +03:00
|
|
|
if state == 'a':
|
|
|
|
origsrc = repo.dirstate.copied(abs)
|
|
|
|
if origsrc is not None:
|
|
|
|
return origsrc
|
2006-01-12 09:57:58 +03:00
|
|
|
if exact:
|
|
|
|
ui.warn(_('%s: not copying - file %s\n') % (rel, reason))
|
2005-09-15 01:29:02 +04:00
|
|
|
else:
|
2006-02-18 18:37:59 +03:00
|
|
|
return abs
|
2005-09-15 01:29:02 +04:00
|
|
|
|
2006-02-18 18:37:59 +03:00
|
|
|
def copy(origsrc, abssrc, relsrc, target, exact):
|
2005-11-08 21:35:05 +03:00
|
|
|
abstarget = util.canonpath(repo.root, cwd, target)
|
|
|
|
reltarget = util.pathto(cwd, abstarget)
|
2005-11-08 21:35:13 +03:00
|
|
|
prevsrc = targets.get(abstarget)
|
|
|
|
if prevsrc is not None:
|
|
|
|
ui.warn(_('%s: not overwriting - %s collides with %s\n') %
|
|
|
|
(reltarget, abssrc, prevsrc))
|
|
|
|
return
|
2005-12-01 19:48:35 +03:00
|
|
|
if (not opts['after'] and os.path.exists(reltarget) or
|
|
|
|
opts['after'] and repo.dirstate.state(abstarget) not in '?r'):
|
|
|
|
if not opts['force']:
|
2005-11-08 21:35:09 +03:00
|
|
|
ui.warn(_('%s: not overwriting - file exists\n') %
|
|
|
|
reltarget)
|
|
|
|
return
|
2005-12-01 19:48:35 +03:00
|
|
|
if not opts['after']:
|
|
|
|
os.unlink(reltarget)
|
|
|
|
if opts['after']:
|
|
|
|
if not os.path.exists(reltarget):
|
|
|
|
return
|
|
|
|
else:
|
2005-11-08 21:35:05 +03:00
|
|
|
targetdir = os.path.dirname(reltarget) or '.'
|
|
|
|
if not os.path.isdir(targetdir):
|
|
|
|
os.makedirs(targetdir)
|
2005-09-15 01:29:02 +04:00
|
|
|
try:
|
2006-03-01 10:47:40 +03:00
|
|
|
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)
|
2005-09-15 03:34:22 +04:00
|
|
|
except shutil.Error, inst:
|
|
|
|
raise util.Abort(str(inst))
|
2005-09-15 01:29:02 +04:00
|
|
|
except IOError, inst:
|
|
|
|
if inst.errno == errno.ENOENT:
|
2005-11-08 21:35:05 +03:00
|
|
|
ui.warn(_('%s: deleted in working copy\n') % relsrc)
|
2005-09-15 01:29:02 +04:00
|
|
|
else:
|
2005-11-08 21:35:05 +03:00
|
|
|
ui.warn(_('%s: cannot copy - %s\n') %
|
|
|
|
(relsrc, inst.strerror))
|
|
|
|
errors += 1
|
|
|
|
return
|
2005-12-01 19:48:35 +03:00
|
|
|
if ui.verbose or not exact:
|
|
|
|
ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
|
2005-11-08 21:35:13 +03:00
|
|
|
targets[abstarget] = abssrc
|
2006-03-01 10:47:40 +03:00
|
|
|
if abstarget != origsrc:
|
|
|
|
repo.copy(origsrc, abstarget, wlock)
|
2005-11-08 21:35:05 +03:00
|
|
|
copied.append((abssrc, relsrc, exact))
|
|
|
|
|
2005-12-01 19:48:35 +03:00
|
|
|
def targetpathfn(pat, dest, srcs):
|
|
|
|
if os.path.isdir(pat):
|
2006-01-24 03:57:09 +03:00
|
|
|
abspfx = util.canonpath(repo.root, cwd, pat)
|
2005-12-01 19:48:35 +03:00
|
|
|
if destdirexists:
|
2006-01-24 03:57:09 +03:00
|
|
|
striplen = len(os.path.split(abspfx)[0])
|
2005-12-01 19:48:35 +03:00
|
|
|
else:
|
2006-01-24 03:57:09 +03:00
|
|
|
striplen = len(abspfx)
|
2005-12-01 19:48:35 +03:00
|
|
|
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))
|
|
|
|
else:
|
2006-01-24 03:57:09 +03:00
|
|
|
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
|
|
|
|
|
|
|
|
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:])
|
2005-12-01 19:48:35 +03:00
|
|
|
else:
|
2006-01-24 03:57:09 +03:00
|
|
|
# a file
|
|
|
|
if destdirexists:
|
|
|
|
res = lambda p: os.path.join(dest, os.path.basename(p))
|
|
|
|
else:
|
|
|
|
res = lambda p: dest
|
2005-12-01 19:48:35 +03:00
|
|
|
return res
|
|
|
|
|
|
|
|
|
2005-11-08 21:35:05 +03:00
|
|
|
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)
|
2005-12-01 19:48:35 +03:00
|
|
|
if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists:
|
2005-11-08 21:35:05 +03:00
|
|
|
raise util.Abort(_('with multiple sources, destination must be an '
|
|
|
|
'existing directory'))
|
2005-12-01 19:48:35 +03:00
|
|
|
if opts['after']:
|
|
|
|
tfn = targetpathafterfn
|
|
|
|
else:
|
|
|
|
tfn = targetpathfn
|
|
|
|
copylist = []
|
2005-11-08 21:35:05 +03:00
|
|
|
for pat in pats:
|
2005-12-01 19:48:35 +03:00
|
|
|
srcs = []
|
2005-11-08 21:35:05 +03:00
|
|
|
for tag, abssrc, relsrc, exact in walk(repo, [pat], opts):
|
2006-02-18 18:37:59 +03:00
|
|
|
origsrc = okaytocopy(abssrc, relsrc, exact)
|
|
|
|
if origsrc:
|
|
|
|
srcs.append((origsrc, abssrc, relsrc, exact))
|
2005-12-01 19:48:35 +03:00
|
|
|
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:
|
2006-02-18 18:37:59 +03:00
|
|
|
for origsrc, abssrc, relsrc, exact in srcs:
|
|
|
|
copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact)
|
2005-11-08 21:35:05 +03:00
|
|
|
|
|
|
|
if errors:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.warn(_('(consider using --after)\n'))
|
2005-11-08 21:35:05 +03:00
|
|
|
return errors, copied
|
2005-09-15 03:34:22 +04:00
|
|
|
|
|
|
|
def copy(ui, repo, *pats, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2006-03-01 10:47:40 +03:00
|
|
|
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
|
2005-09-15 01:29:02 +04:00
|
|
|
return errs
|
2005-06-16 03:57:07 +04:00
|
|
|
|
2005-09-16 21:42:20 +04:00
|
|
|
def debugancestor(ui, index, rev1, rev2):
|
|
|
|
"""find the ancestor revision of two revisions in a given index"""
|
2006-03-04 21:01:45 +03:00
|
|
|
r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "")
|
2005-09-16 21:42:20 +04:00
|
|
|
a = r.ancestor(r.lookup(rev1), r.lookup(rev2))
|
|
|
|
ui.write("%d:%s\n" % (r.rev(a), hex(a)))
|
|
|
|
|
2006-02-20 21:04:56 +03:00
|
|
|
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)
|
2006-02-21 02:45:02 +03:00
|
|
|
wlock = repo.wlock()
|
2006-02-20 21:04:56 +03:00
|
|
|
repo.dirstate.rebuild(rev, files.iteritems())
|
|
|
|
|
2005-07-03 23:47:45 +04:00
|
|
|
def debugcheckstate(ui, repo):
|
|
|
|
"""validate the correctness of the current dirstate"""
|
2005-06-25 10:51:39 +04:00
|
|
|
parent1, parent2 = repo.dirstate.parents()
|
2005-07-01 12:34:17 +04:00
|
|
|
repo.dirstate.read()
|
|
|
|
dc = repo.dirstate.map
|
2005-06-25 10:51:39 +04:00
|
|
|
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:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state))
|
2005-06-25 10:51:39 +04:00
|
|
|
errors += 1
|
|
|
|
if state in "a" and f in m1:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state))
|
2005-06-25 10:51:39 +04:00
|
|
|
errors += 1
|
|
|
|
if state in "m" and f not in m1 and f not in m2:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.warn(_("%s in state %s, but not in either manifest\n") %
|
2005-07-03 06:57:59 +04:00
|
|
|
(f, state))
|
2005-06-25 10:51:39 +04:00
|
|
|
errors += 1
|
|
|
|
for f in m1:
|
|
|
|
state = repo.dirstate.state(f)
|
|
|
|
if state not in "nrm":
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.warn(_("%s in manifest1, but listed as state %s") % (f, state))
|
2005-06-25 10:51:39 +04:00
|
|
|
errors += 1
|
|
|
|
if errors:
|
2005-12-28 09:27:05 +03:00
|
|
|
error = _(".hg/dirstate inconsistent with current parent's manifest")
|
|
|
|
raise util.Abort(error)
|
2005-06-25 10:51:39 +04:00
|
|
|
|
2005-08-24 08:30:12 +04:00
|
|
|
def debugconfig(ui):
|
2005-08-26 12:01:55 +04:00
|
|
|
"""show combined config settings from all hgrc files"""
|
2005-08-24 08:30:12 +04:00
|
|
|
try:
|
|
|
|
repo = hg.repository(ui)
|
2006-03-06 19:47:41 +03:00
|
|
|
ui = repo.ui
|
2005-08-26 17:19:18 +04:00
|
|
|
except hg.RepoError:
|
|
|
|
pass
|
2005-08-24 08:30:12 +04:00
|
|
|
for section, name, value in ui.walkconfig():
|
|
|
|
ui.write('%s.%s=%s\n' % (section, name, value))
|
|
|
|
|
2005-10-18 11:43:33 +04:00
|
|
|
def debugsetparents(ui, repo, rev1, rev2=None):
|
2005-10-28 00:29:28 +04:00
|
|
|
"""manually set the parents of the current working directory
|
2005-10-18 11:43:33 +04:00
|
|
|
|
|
|
|
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))
|
|
|
|
|
2005-07-03 23:47:45 +04:00
|
|
|
def debugstate(ui, repo):
|
|
|
|
"""show the contents of the current dirstate"""
|
2005-07-01 12:34:17 +04:00
|
|
|
repo.dirstate.read()
|
|
|
|
dc = repo.dirstate.map
|
2005-06-25 10:51:39 +04:00
|
|
|
keys = dc.keys()
|
|
|
|
keys.sort()
|
2005-07-14 13:42:28 +04:00
|
|
|
for file_ in keys:
|
2005-07-23 20:11:29 +04:00
|
|
|
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_))
|
2005-08-28 07:58:53 +04:00
|
|
|
for f in repo.dirstate.copies:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f))
|
2005-06-25 10:51:39 +04:00
|
|
|
|
2005-08-25 05:40:17 +04:00
|
|
|
def debugdata(ui, file_, rev):
|
|
|
|
"""dump the contents of an data file revision"""
|
2006-03-04 21:01:45 +03:00
|
|
|
r = revlog.revlog(util.opener(os.getcwd(), audit=False),
|
|
|
|
file_[:-2] + ".i", file_)
|
2005-09-22 20:42:15 +04:00
|
|
|
try:
|
|
|
|
ui.write(r.revision(r.lookup(rev)))
|
|
|
|
except KeyError:
|
2005-10-19 05:38:39 +04:00
|
|
|
raise util.Abort(_('invalid revision identifier %s'), rev)
|
2005-08-25 05:40:17 +04:00
|
|
|
|
2005-07-14 13:42:28 +04:00
|
|
|
def debugindex(ui, file_):
|
2005-07-03 23:47:45 +04:00
|
|
|
"""dump the contents of an index file"""
|
2006-03-04 21:01:45 +03:00
|
|
|
r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "")
|
2005-07-03 06:57:59 +04:00
|
|
|
ui.write(" rev offset length base linkrev" +
|
2005-08-22 03:51:50 +04:00
|
|
|
" nodeid p1 p2\n")
|
2005-06-05 01:45:31 +04:00
|
|
|
for i in range(r.count()):
|
|
|
|
e = r.index[i]
|
2005-08-22 03:51:50 +04:00
|
|
|
ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % (
|
2005-07-03 06:57:59 +04:00
|
|
|
i, e[0], e[1], e[2], e[3],
|
2005-08-28 01:55:07 +04:00
|
|
|
short(e[6]), short(e[4]), short(e[5])))
|
2005-06-05 01:45:31 +04:00
|
|
|
|
2005-07-14 13:42:28 +04:00
|
|
|
def debugindexdot(ui, file_):
|
2005-07-03 23:47:45 +04:00
|
|
|
"""dump an index DAG as a .dot file"""
|
2006-03-04 21:01:45 +03:00
|
|
|
r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "")
|
2005-07-03 06:57:59 +04:00
|
|
|
ui.write("digraph G {\n")
|
2005-06-05 01:45:31 +04:00
|
|
|
for i in range(r.count()):
|
|
|
|
e = r.index[i]
|
2005-07-03 06:57:59 +04:00
|
|
|
ui.write("\t%d -> %d\n" % (r.rev(e[4]), i))
|
2005-08-28 01:55:07 +04:00
|
|
|
if e[5] != nullid:
|
2005-07-03 06:57:59 +04:00
|
|
|
ui.write("\t%d -> %d\n" % (r.rev(e[5]), i))
|
|
|
|
ui.write("}\n")
|
2005-06-05 01:45:31 +04:00
|
|
|
|
2005-08-28 07:58:53 +04:00
|
|
|
def debugrename(ui, repo, file, rev=None):
|
2005-09-01 23:13:56 +04:00
|
|
|
"""dump rename information"""
|
2005-08-28 07:58:53 +04:00
|
|
|
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]]
|
2005-11-14 04:59:35 +03:00
|
|
|
except (hg.RepoError, KeyError):
|
2005-08-28 07:58:53 +04:00
|
|
|
n = r.lookup(rev)
|
|
|
|
else:
|
|
|
|
n = r.tip()
|
|
|
|
m = r.renamed(n)
|
|
|
|
if m:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1])))
|
2005-08-28 07:58:53 +04:00
|
|
|
else:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.write(_("not renamed\n"))
|
2005-08-28 07:58:53 +04:00
|
|
|
|
Clean up walk and changes code to use normalised names properly.
New function: commands.pathto returns the relative path from one path
to another. For example, given foo/bar and baz/quux, it will return
../../baz/quux. This new function is used by the walk and status code
to print relative paths correctly.
New command: debugwalk exercises the walk code without doing anything
more.
hg.dirstate.walk now yields normalised names. For example, if you're
in the baz directory and you ask it to walk ../foo/bar/.., it will yield
names starting with foo/.
As a result of this change, all of the other walk and changes methods
in this module also return normalised names.
The util.matcher function now normalises globs and path names, so that
it will match normalised names properly.
Finally, util.matcher uses the non-glob prefix of a glob to tell walk
which directories to scan. Perviously, a glob like foo/* would scan
everything, but only return matches for foo/*. Now, foo/* only scans
under foo (using the globprefix function), which is much faster.
2005-08-01 05:42:46 +04:00
|
|
|
def debugwalk(ui, repo, *pats, **opts):
|
2005-08-26 12:01:55 +04:00
|
|
|
"""show how files match on given patterns"""
|
Clean up walk and changes code to use normalised names properly.
New function: commands.pathto returns the relative path from one path
to another. For example, given foo/bar and baz/quux, it will return
../../baz/quux. This new function is used by the walk and status code
to print relative paths correctly.
New command: debugwalk exercises the walk code without doing anything
more.
hg.dirstate.walk now yields normalised names. For example, if you're
in the baz directory and you ask it to walk ../foo/bar/.., it will yield
names starting with foo/.
As a result of this change, all of the other walk and changes methods
in this module also return normalised names.
The util.matcher function now normalises globs and path names, so that
it will match normalised names properly.
Finally, util.matcher uses the non-glob prefix of a glob to tell walk
which directories to scan. Perviously, a glob like foo/* would scan
everything, but only return matches for foo/*. Now, foo/* only scans
under foo (using the globprefix function), which is much faster.
2005-08-01 05:42:46 +04:00
|
|
|
items = list(walk(repo, pats, opts))
|
2005-08-26 17:19:18 +04:00
|
|
|
if not items:
|
|
|
|
return
|
2005-09-21 10:07:38 +04:00
|
|
|
fmt = '%%s %%-%ds %%-%ds %%s' % (
|
2005-08-19 01:58:32 +04:00
|
|
|
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:
|
2005-09-21 10:07:38 +04:00
|
|
|
line = fmt % (src, abs, rel, exact and 'exact' or '')
|
|
|
|
ui.write("%s\n" % line.rstrip())
|
Clean up walk and changes code to use normalised names properly.
New function: commands.pathto returns the relative path from one path
to another. For example, given foo/bar and baz/quux, it will return
../../baz/quux. This new function is used by the walk and status code
to print relative paths correctly.
New command: debugwalk exercises the walk code without doing anything
more.
hg.dirstate.walk now yields normalised names. For example, if you're
in the baz directory and you ask it to walk ../foo/bar/.., it will yield
names starting with foo/.
As a result of this change, all of the other walk and changes methods
in this module also return normalised names.
The util.matcher function now normalises globs and path names, so that
it will match normalised names properly.
Finally, util.matcher uses the non-glob prefix of a glob to tell walk
which directories to scan. Perviously, a glob like foo/* would scan
everything, but only return matches for foo/*. Now, foo/* only scans
under foo (using the globprefix function), which is much faster.
2005-08-01 05:42:46 +04:00
|
|
|
|
2005-07-20 15:16:20 +04:00
|
|
|
def diff(ui, repo, *pats, **opts):
|
2005-12-01 19:51:45 +03:00
|
|
|
"""diff repository (or selected files)
|
2005-10-25 02:52:28 +04:00
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
2005-08-24 05:58:26 +04:00
|
|
|
node1, node2 = None, None
|
2005-08-24 06:58:46 +04:00
|
|
|
revs = [repo.lookup(x) for x in opts['rev']]
|
2005-06-17 23:37:23 +04:00
|
|
|
|
2005-08-24 05:58:26 +04:00
|
|
|
if len(revs) > 0:
|
|
|
|
node1 = revs[0]
|
|
|
|
if len(revs) > 1:
|
|
|
|
node2 = revs[1]
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
if len(revs) > 2:
|
2005-10-19 05:38:39 +04:00
|
|
|
raise util.Abort(_("too many revisions to diff"))
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
|
2006-01-17 18:10:22 +03:00
|
|
|
fns, matchfn, anypats = matchpats(repo, pats, opts)
|
2005-08-24 05:58:26 +04:00
|
|
|
|
2005-09-17 01:50:06 +04:00
|
|
|
dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn,
|
2006-02-15 21:39:47 +03:00
|
|
|
text=opts['text'], opts=opts)
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
|
2005-07-03 06:29:54 +04:00
|
|
|
def doexport(ui, repo, changeset, seqno, total, revwidth, opts):
|
2005-06-05 00:14:14 +04:00
|
|
|
node = repo.lookup(changeset)
|
2005-12-15 06:01:57 +03:00
|
|
|
parents = [p for p in repo.changelog.parents(node) if p != nullid]
|
2005-12-16 09:12:00 +03:00
|
|
|
if opts['switch_parent']:
|
|
|
|
parents.reverse()
|
2005-12-15 06:01:57 +03:00
|
|
|
prev = (parents and parents[0]) or nullid
|
2005-06-05 00:14:14 +04:00
|
|
|
change = repo.changelog.read(node)
|
2005-06-17 23:37:23 +04:00
|
|
|
|
2005-07-20 14:48:16 +04:00
|
|
|
fp = make_file(repo, repo.changelog, opts['output'],
|
|
|
|
node=node, total=total, seqno=seqno,
|
|
|
|
revwidth=revwidth)
|
|
|
|
if fp != sys.stdout:
|
2005-07-22 10:42:47 +04:00
|
|
|
ui.note("%s\n" % fp.name)
|
2005-07-03 06:29:54 +04:00
|
|
|
|
2005-07-03 06:57:59 +04:00
|
|
|
fp.write("# HG changeset patch\n")
|
|
|
|
fp.write("# User %s\n" % change[1])
|
2005-08-28 01:55:07 +04:00
|
|
|
fp.write("# Node ID %s\n" % hex(node))
|
|
|
|
fp.write("# Parent %s\n" % hex(prev))
|
2005-12-15 06:01:57 +03:00
|
|
|
if len(parents) > 1:
|
|
|
|
fp.write("# Parent %s\n" % hex(parents[1]))
|
2005-07-03 06:57:59 +04:00
|
|
|
fp.write(change[4].rstrip())
|
|
|
|
fp.write("\n\n")
|
2005-07-03 06:29:54 +04:00
|
|
|
|
2005-08-24 06:58:46 +04:00
|
|
|
dodiff(fp, ui, repo, prev, node, text=opts['text'])
|
2005-08-26 17:19:18 +04:00
|
|
|
if fp != sys.stdout:
|
|
|
|
fp.close()
|
2005-07-03 06:29:54 +04:00
|
|
|
|
|
|
|
def export(ui, repo, *changesets, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
2005-12-15 06:01:57 +03:00
|
|
|
|
|
|
|
With the --switch-parent option, the diff will be against the second
|
|
|
|
parent. It can be useful to review a merge.
|
2005-10-25 02:52:28 +04:00
|
|
|
"""
|
2005-07-04 23:06:01 +04:00
|
|
|
if not changesets:
|
2005-10-19 05:38:39 +04:00
|
|
|
raise util.Abort(_("export requires at least one changeset"))
|
2005-07-03 06:29:54 +04:00
|
|
|
seqno = 0
|
|
|
|
revs = list(revrange(ui, repo, changesets))
|
|
|
|
total = len(revs)
|
2005-08-26 18:37:28 +04:00
|
|
|
revwidth = max(map(len, revs))
|
2005-12-28 09:27:05 +03:00
|
|
|
msg = len(revs) > 1 and _("Exporting patches:\n") or _("Exporting patch:\n")
|
|
|
|
ui.note(msg)
|
2005-07-03 06:29:54 +04:00
|
|
|
for cset in revs:
|
|
|
|
seqno += 1
|
|
|
|
doexport(ui, repo, cset, seqno, total, revwidth, opts)
|
2005-06-05 00:14:14 +04:00
|
|
|
|
2005-07-29 20:49:01 +04:00
|
|
|
def forget(ui, repo, *pats, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""don't add the specified files on the next commit
|
|
|
|
|
|
|
|
Undo an 'hg add' scheduled for the next commit.
|
|
|
|
"""
|
2005-07-29 20:49:01 +04:00
|
|
|
forget = []
|
2005-08-19 01:58:32 +04:00
|
|
|
for src, abs, rel, exact in walk(repo, pats, opts):
|
2005-07-29 20:49:01 +04:00
|
|
|
if repo.dirstate.state(abs) == 'a':
|
|
|
|
forget.append(abs)
|
2005-09-15 09:32:12 +04:00
|
|
|
if ui.verbose or not exact:
|
2006-01-17 18:10:22 +03:00
|
|
|
ui.status(_('forgetting %s\n') % ((pats and rel) or abs))
|
2005-07-29 20:49:01 +04:00
|
|
|
repo.forget(forget)
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
|
2005-08-28 01:36:25 +04:00
|
|
|
def grep(ui, repo, pattern, *pats, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2005-08-25 13:00:03 +04:00
|
|
|
reflags = 0
|
2005-08-26 17:19:18 +04:00
|
|
|
if opts['ignore_case']:
|
|
|
|
reflags |= re.I
|
2005-08-25 13:00:03 +04:00
|
|
|
regexp = re.compile(pattern, reflags)
|
2005-08-29 21:05:49 +04:00
|
|
|
sep, eol = ':', '\n'
|
2005-08-28 01:36:25 +04:00
|
|
|
if opts['print0']:
|
2005-08-29 21:05:49 +04:00
|
|
|
sep = eol = '\0'
|
2005-08-25 13:00:03 +04:00
|
|
|
|
|
|
|
fcache = {}
|
|
|
|
def getfile(fn):
|
|
|
|
if fn not in fcache:
|
|
|
|
fcache[fn] = repo.file(fn)
|
|
|
|
return fcache[fn]
|
|
|
|
|
|
|
|
def matchlines(body):
|
2005-08-26 04:13:48 +04:00
|
|
|
begin = 0
|
|
|
|
linenum = 0
|
|
|
|
while True:
|
|
|
|
match = regexp.search(body, begin)
|
2005-08-26 17:19:18 +04:00
|
|
|
if not match:
|
|
|
|
break
|
2005-08-26 04:13:48 +04:00
|
|
|
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
|
2005-08-25 13:00:03 +04:00
|
|
|
|
2005-11-19 09:48:47 +03:00
|
|
|
class linestate(object):
|
2005-08-25 13:00:03 +04:00
|
|
|
def __init__(self, line, linenum, colstart, colend):
|
|
|
|
self.line = line
|
|
|
|
self.linenum = linenum
|
|
|
|
self.colstart = colstart
|
|
|
|
self.colend = colend
|
2005-08-26 17:19:18 +04:00
|
|
|
def __eq__(self, other):
|
|
|
|
return self.line == other.line
|
|
|
|
def __hash__(self):
|
|
|
|
return hash(self.line)
|
2005-08-25 13:00:03 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2006-02-19 21:43:03 +03:00
|
|
|
# FIXME: prev isn't used, why ?
|
2005-08-25 13:00:03 +04:00
|
|
|
prev = {}
|
2005-08-29 21:05:49 +04:00
|
|
|
ucache = {}
|
2005-08-25 13:00:03 +04:00
|
|
|
def display(fn, rev, states, prevstates):
|
2005-08-26 13:03:35 +04:00
|
|
|
diff = list(sets.Set(states).symmetric_difference(sets.Set(prevstates)))
|
2005-08-25 13:00:03 +04:00
|
|
|
diff.sort(lambda x, y: cmp(x.linenum, y.linenum))
|
2005-08-29 19:24:06 +04:00
|
|
|
counts = {'-': 0, '+': 0}
|
2005-08-29 21:05:49 +04:00
|
|
|
filerevmatches = {}
|
2005-08-25 13:00:03 +04:00
|
|
|
for l in diff:
|
2005-09-08 07:50:23 +04:00
|
|
|
if incrementing or not opts['all']:
|
2005-08-25 13:00:03 +04:00
|
|
|
change = ((l in prevstates) and '-') or '+'
|
|
|
|
r = rev
|
|
|
|
else:
|
|
|
|
change = ((l in states) and '-') or '+'
|
|
|
|
r = prev[fn]
|
2005-08-29 21:05:49 +04:00
|
|
|
cols = [fn, str(rev)]
|
2006-01-12 09:57:58 +03:00
|
|
|
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,
|
2005-08-29 21:05:49 +04:00
|
|
|
ucache))
|
|
|
|
if opts['files_with_matches']:
|
|
|
|
c = (fn, rev)
|
2006-01-12 09:57:58 +03:00
|
|
|
if c in filerevmatches:
|
|
|
|
continue
|
2005-08-29 21:05:49 +04:00
|
|
|
filerevmatches[c] = 1
|
|
|
|
else:
|
|
|
|
cols.append(l.line)
|
|
|
|
ui.write(sep.join(cols), eol)
|
2005-08-29 19:24:06 +04:00
|
|
|
counts[change] += 1
|
|
|
|
return counts['+'], counts['-']
|
2005-08-25 13:00:03 +04:00
|
|
|
|
|
|
|
fstate = {}
|
2005-08-29 19:24:06 +04:00
|
|
|
skip = {}
|
2005-12-15 05:53:45 +03:00
|
|
|
changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts)
|
2005-08-29 21:05:49 +04:00
|
|
|
count = 0
|
2005-09-24 04:50:03 +04:00
|
|
|
incrementing = False
|
2005-08-29 21:05:49 +04:00
|
|
|
for st, rev, fns in changeiter:
|
2005-08-25 13:00:03 +04:00
|
|
|
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:
|
2006-01-12 09:57:58 +03:00
|
|
|
if fn in skip:
|
|
|
|
continue
|
2005-08-25 13:00:03 +04:00
|
|
|
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:
|
2006-01-12 09:57:58 +03:00
|
|
|
if fn in skip:
|
|
|
|
continue
|
2005-09-08 07:50:23 +04:00
|
|
|
if incrementing or not opts['all'] or fstate[fn]:
|
2005-08-29 19:24:06 +04:00
|
|
|
pos, neg = display(fn, rev, m, fstate[fn])
|
2005-08-29 21:05:49 +04:00
|
|
|
count += pos + neg
|
2005-09-08 07:50:23 +04:00
|
|
|
if pos and not opts['all']:
|
2005-08-29 19:24:06 +04:00
|
|
|
skip[fn] = True
|
2005-08-25 13:00:03 +04:00
|
|
|
fstate[fn] = m
|
|
|
|
prev[fn] = rev
|
|
|
|
|
|
|
|
if not incrementing:
|
|
|
|
fstate = fstate.items()
|
|
|
|
fstate.sort()
|
|
|
|
for fn, state in fstate:
|
2006-01-12 09:57:58 +03:00
|
|
|
if fn in skip:
|
|
|
|
continue
|
2005-08-25 13:00:03 +04:00
|
|
|
display(fn, rev, {}, state)
|
2005-08-29 21:05:49 +04:00
|
|
|
return (count == 0 and 1) or 0
|
2005-08-25 13:00:03 +04:00
|
|
|
|
2005-08-15 00:23:45 +04:00
|
|
|
def heads(ui, repo, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2005-11-16 14:08:25 +03:00
|
|
|
if opts['rev']:
|
2005-11-16 14:56:19 +03:00
|
|
|
heads = repo.heads(repo.lookup(opts['rev']))
|
2005-11-16 14:08:25 +03:00
|
|
|
else:
|
|
|
|
heads = repo.heads()
|
2005-08-15 00:23:45 +04:00
|
|
|
br = None
|
|
|
|
if opts['branches']:
|
2005-11-16 14:56:19 +03:00
|
|
|
br = repo.branchlookup(heads)
|
2005-11-16 14:08:25 +03:00
|
|
|
for n in heads:
|
2005-08-15 00:23:45 +04:00
|
|
|
show_changeset(ui, repo, changenode=n, brinfo=br)
|
2005-06-03 06:07:01 +04:00
|
|
|
|
2005-06-15 09:44:43 +04:00
|
|
|
def identify(ui, repo):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""print information about the working copy
|
2005-10-28 00:29:28 +04:00
|
|
|
|
2005-10-25 02:52:28 +04:00
|
|
|
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.
|
|
|
|
"""
|
2005-08-28 01:55:07 +04:00
|
|
|
parents = [p for p in repo.dirstate.parents() if p != nullid]
|
2005-06-15 10:07:05 +04:00
|
|
|
if not parents:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.write(_("unknown\n"))
|
2005-06-15 10:07:05 +04:00
|
|
|
return
|
|
|
|
|
2005-08-28 01:55:07 +04:00
|
|
|
hexfunc = ui.verbose and hex or short
|
2006-01-12 15:58:36 +03:00
|
|
|
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 "")]
|
2005-06-17 13:19:43 +04:00
|
|
|
|
2005-06-15 09:44:43 +04:00
|
|
|
if not ui.quiet:
|
2005-06-17 13:19:43 +04:00
|
|
|
# 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 ' + '
|
2005-07-22 11:58:16 +04:00
|
|
|
if parenttags:
|
|
|
|
output.append(' + '.join(parenttags))
|
2005-06-15 09:44:43 +04:00
|
|
|
|
2005-06-17 13:19:43 +04:00
|
|
|
ui.write("%s\n" % ' '.join(output))
|
2005-06-15 09:44:43 +04:00
|
|
|
|
2005-06-23 10:31:25 +04:00
|
|
|
def import_(ui, repo, patch1, *patches, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2005-06-23 10:31:25 +04:00
|
|
|
patches = (patch1,) + patches
|
2005-06-28 12:59:59 +04:00
|
|
|
|
2005-08-20 11:07:31 +04:00
|
|
|
if not opts['force']:
|
2006-01-12 15:58:36 +03:00
|
|
|
modified, added, removed, deleted, unknown = repo.changes()
|
|
|
|
if modified or added or removed or deleted:
|
2005-10-19 05:38:39 +04:00
|
|
|
raise util.Abort(_("outstanding uncommitted changes"))
|
2005-08-20 11:07:31 +04:00
|
|
|
|
2005-06-23 10:31:25 +04:00
|
|
|
d = opts["base"]
|
|
|
|
strip = opts["strip"]
|
|
|
|
|
2005-09-01 20:35:42 +04:00
|
|
|
mailre = re.compile(r'(?:From |[\w-]+:)')
|
2005-10-16 02:04:22 +04:00
|
|
|
|
|
|
|
# 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])')
|
2005-09-01 20:04:18 +04:00
|
|
|
|
2005-06-23 10:31:25 +04:00
|
|
|
for patch in patches:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.status(_("applying %s\n") % patch)
|
2005-06-23 10:31:25 +04:00
|
|
|
pf = os.path.join(d, patch)
|
|
|
|
|
2005-07-22 19:26:46 +04:00
|
|
|
message = []
|
2005-07-14 19:57:01 +04:00
|
|
|
user = None
|
|
|
|
hgpatch = False
|
|
|
|
for line in file(pf):
|
|
|
|
line = line.rstrip()
|
2005-09-08 23:10:43 +04:00
|
|
|
if (not message and not hgpatch and
|
|
|
|
mailre.match(line) and not opts['force']):
|
2006-01-12 09:57:58 +03:00
|
|
|
if len(line) > 35:
|
|
|
|
line = line[:32] + '...'
|
2005-10-19 05:38:39 +04:00
|
|
|
raise util.Abort(_('first line looks like a '
|
|
|
|
'mail header: ') + line)
|
2005-09-01 20:35:42 +04:00
|
|
|
if diffre.match(line):
|
2005-07-14 13:42:28 +04:00
|
|
|
break
|
2005-07-14 19:57:01 +04:00
|
|
|
elif hgpatch:
|
|
|
|
# parse values when importing the result of an hg export
|
|
|
|
if line.startswith("# User "):
|
|
|
|
user = line[7:]
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.debug(_('User: %s\n') % user)
|
2005-07-14 19:57:01 +04:00
|
|
|
elif not line.startswith("# ") and line:
|
2005-07-22 19:26:46 +04:00
|
|
|
message.append(line)
|
2005-07-14 19:57:01 +04:00
|
|
|
hgpatch = False
|
|
|
|
elif line == '# HG changeset patch':
|
|
|
|
hgpatch = True
|
2005-08-07 00:23:38 +04:00
|
|
|
message = [] # We may have collected garbage
|
2005-07-14 19:57:01 +04:00
|
|
|
else:
|
2005-07-22 19:26:46 +04:00
|
|
|
message.append(line)
|
2005-07-04 09:14:40 +04:00
|
|
|
|
2005-07-22 19:26:46 +04:00
|
|
|
# make sure message isn't empty
|
|
|
|
if not message:
|
2005-10-19 05:38:39 +04:00
|
|
|
message = _("imported patch %s\n") % patch
|
2005-07-14 19:57:01 +04:00
|
|
|
else:
|
2005-07-22 19:26:46 +04:00
|
|
|
message = "%s\n" % '\n'.join(message)
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.debug(_('message:\n%s\n') % message)
|
2005-06-23 10:31:25 +04:00
|
|
|
|
2005-09-21 08:35:51 +04:00
|
|
|
files = util.patch(strip, pf, ui)
|
2005-06-23 10:31:25 +04:00
|
|
|
|
|
|
|
if len(files) > 0:
|
|
|
|
addremove(ui, repo, *files)
|
2005-07-22 19:26:46 +04:00
|
|
|
repo.commit(files, message, user)
|
2005-06-23 10:31:25 +04:00
|
|
|
|
2005-09-01 20:11:25 +04:00
|
|
|
def incoming(ui, repo, source="default", **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
|
|
|
|
Currently only local repositories are supported.
|
|
|
|
"""
|
2005-10-25 04:41:45 +04:00
|
|
|
source = ui.expandpath(source, repo.root)
|
2005-08-17 07:17:16 +04:00
|
|
|
other = hg.repository(ui, source)
|
|
|
|
if not other.local():
|
2005-10-19 05:38:39 +04:00
|
|
|
raise util.Abort(_("incoming doesn't work for remote repositories yet"))
|
2005-08-17 07:17:16 +04:00
|
|
|
o = repo.findincoming(other)
|
2005-08-17 10:47:49 +04:00
|
|
|
if not o:
|
|
|
|
return
|
2005-10-07 21:48:27 +04:00
|
|
|
o = other.changelog.nodesbetween(o)[0]
|
2005-10-25 03:59:31 +04:00
|
|
|
if opts['newest_first']:
|
|
|
|
o.reverse()
|
2005-08-17 07:17:16 +04:00
|
|
|
for n in o:
|
2005-10-25 02:37:20 +04:00
|
|
|
parents = [p for p in other.changelog.parents(n) if p != nullid]
|
|
|
|
if opts['no_merges'] and len(parents) == 2:
|
|
|
|
continue
|
2005-08-17 07:17:16 +04:00
|
|
|
show_changeset(ui, other, changenode=n)
|
2005-09-01 20:11:25 +04:00
|
|
|
if opts['patch']:
|
2005-10-25 02:37:20 +04:00
|
|
|
prev = (parents and parents[0]) or nullid
|
2005-09-01 20:11:25 +04:00
|
|
|
dodiff(ui, ui, other, prev, n)
|
|
|
|
ui.write("\n")
|
2005-08-17 07:17:16 +04:00
|
|
|
|
2005-08-15 09:33:09 +04:00
|
|
|
def init(ui, dest="."):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2005-08-15 09:33:09 +04:00
|
|
|
if not os.path.exists(dest):
|
|
|
|
os.mkdir(dest)
|
|
|
|
hg.repository(ui, dest, create=1)
|
2005-06-15 06:37:53 +04:00
|
|
|
|
2005-07-06 06:19:01 +04:00
|
|
|
def locate(ui, repo, *pats, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2005-08-26 17:19:18 +04:00
|
|
|
end = opts['print0'] and '\0' or '\n'
|
2006-01-16 17:51:09 +03:00
|
|
|
rev = opts['rev']
|
|
|
|
if rev:
|
|
|
|
node = repo.lookup(rev)
|
|
|
|
else:
|
|
|
|
node = None
|
2005-07-21 21:21:33 +04:00
|
|
|
|
2006-01-16 17:51:09 +03:00
|
|
|
for src, abs, rel, exact in walk(repo, pats, opts, node=node,
|
|
|
|
head='(?:.*/|)'):
|
|
|
|
if not node and repo.dirstate.state(abs) == '?':
|
2005-08-26 17:19:18 +04:00
|
|
|
continue
|
2005-07-14 13:42:28 +04:00
|
|
|
if opts['fullpath']:
|
2005-07-18 18:54:21 +04:00
|
|
|
ui.write(os.path.join(repo.root, abs), end)
|
|
|
|
else:
|
2006-01-17 18:10:22 +03:00
|
|
|
ui.write(((pats and rel) or abs), end)
|
2005-07-06 06:19:01 +04:00
|
|
|
|
2005-08-24 23:39:10 +04:00
|
|
|
def log(ui, repo, *pats, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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,
|
2005-11-23 20:36:44 +03:00
|
|
|
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.
|
2005-10-25 02:52:28 +04:00
|
|
|
"""
|
2005-11-19 09:48:47 +03:00
|
|
|
class dui(object):
|
2005-08-25 13:00:03 +04:00
|
|
|
# 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):
|
2005-08-26 17:19:18 +04:00
|
|
|
if self.verbose:
|
|
|
|
self.write(*args)
|
2005-08-25 13:00:03 +04:00
|
|
|
def status(self, *args):
|
2005-08-26 17:19:18 +04:00
|
|
|
if not self.quiet:
|
|
|
|
self.write(*args)
|
2005-08-25 13:00:03 +04:00
|
|
|
def write(self, *args):
|
|
|
|
self.hunk[self.rev].append(args)
|
2005-10-05 04:34:02 +04:00
|
|
|
def debug(self, *args):
|
|
|
|
if self.debugflag:
|
|
|
|
self.write(*args)
|
2005-08-25 13:00:03 +04:00
|
|
|
def __getattr__(self, key):
|
|
|
|
return getattr(self.ui, key)
|
2006-02-20 22:06:41 +03:00
|
|
|
|
2005-12-15 05:53:45 +03:00
|
|
|
changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts)
|
2006-02-20 22:06:41 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2005-08-29 21:05:49 +04:00
|
|
|
for st, rev, fns in changeiter:
|
2005-08-25 13:00:03 +04:00
|
|
|
if st == 'window':
|
2005-08-24 23:39:10 +04:00
|
|
|
du = dui(ui)
|
2005-08-25 13:00:03 +04:00
|
|
|
elif st == 'add':
|
|
|
|
du.bump(rev)
|
2005-10-25 02:37:20 +04:00
|
|
|
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:
|
2006-01-12 09:57:58 +03:00
|
|
|
continue
|
2005-10-25 02:37:45 +04:00
|
|
|
if opts['only_merges'] and len(parents) != 2:
|
2006-01-12 09:57:58 +03:00
|
|
|
continue
|
2005-10-25 02:37:20 +04:00
|
|
|
|
2005-10-04 00:45:59 +04:00
|
|
|
if opts['keyword']:
|
2005-12-15 05:53:45 +03:00
|
|
|
changes = getchange(rev)
|
2005-10-04 00:45:59 +04:00
|
|
|
miss = 0
|
2005-10-19 07:06:05 +04:00
|
|
|
for k in [kw.lower() for kw in opts['keyword']]:
|
2005-10-04 00:45:59 +04:00
|
|
|
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
|
|
|
|
|
2006-02-21 17:37:23 +03:00
|
|
|
br = None
|
2006-02-21 15:14:03 +03:00
|
|
|
if opts['branches']:
|
2005-10-19 07:06:13 +04:00
|
|
|
br = repo.branchlookup([repo.changelog.node(rev)])
|
|
|
|
|
Add log -b to show the branch a specific revision lives in
This can be somewhat slow on very large repositories, so I didn't want
to include it in -v
--- hg.orig/mercurial/commands.py 2005-09-13 14:21:57.000000000 -0500
+++ hg/mercurial/commands.py 2005-09-13 18:55:52.000000000 -0500
@@ -1161,7 +1161,10 @@ def log(ui, repo, *pats, **opts):
du = dui(ui)
elif st == 'add':
du.bump(rev)
- show_changeset(du, repo, rev)
+ br = None
+ if opts['branch']:
+ br = repo.branchlookup([repo.changelog.node(rev)])
+ show_changeset(du, repo, rev, brinfo=br)
if opts['patch']:
changenode = repo.changelog.node(rev)
prev, other = repo.changelog.parents(changenode)
@@ -1743,6 +1746,7 @@ table = {
(log,
[('I', 'include', [], 'include path in search'),
('X', 'exclude', [], 'exclude path from search'),
+ ('b', 'branch', None, 'show branches'),
('r', 'rev', [], 'revision'),
('p', 'patch', None, 'show patch')],
'hg log [-I] [-X] [-r REV]... [-p] [FILE]'),
2005-09-14 04:32:53 +04:00
|
|
|
show_changeset(du, repo, rev, brinfo=br)
|
2005-08-25 13:00:03 +04:00
|
|
|
if opts['patch']:
|
2005-10-25 02:37:20 +04:00
|
|
|
prev = (parents and parents[0]) or nullid
|
2005-12-15 05:53:45 +03:00
|
|
|
dodiff(du, du, repo, prev, changenode, match=matchfn)
|
2005-08-25 13:00:03 +04:00
|
|
|
du.write("\n\n")
|
|
|
|
elif st == 'iter':
|
2006-02-20 22:06:41 +03:00
|
|
|
if count == limit: break
|
2006-02-21 17:54:50 +03:00
|
|
|
if du.hunk[rev]:
|
|
|
|
count += 1
|
|
|
|
for args in du.hunk[rev]:
|
|
|
|
ui.write(*args)
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
|
2005-07-14 13:42:28 +04:00
|
|
|
def manifest(ui, repo, rev=None):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2005-06-05 01:45:31 +04:00
|
|
|
if rev:
|
2005-07-13 13:42:48 +04:00
|
|
|
try:
|
|
|
|
# assume all revision numbers are for changesets
|
|
|
|
n = repo.lookup(rev)
|
|
|
|
change = repo.changelog.read(n)
|
|
|
|
n = change[0]
|
2005-07-14 13:42:28 +04:00
|
|
|
except hg.RepoError:
|
2005-07-13 13:42:48 +04:00
|
|
|
n = repo.manifest.lookup(rev)
|
2005-07-14 13:42:28 +04:00
|
|
|
else:
|
|
|
|
n = repo.manifest.tip()
|
2005-06-05 01:45:31 +04:00
|
|
|
m = repo.manifest.read(n)
|
2005-06-08 22:16:33 +04:00
|
|
|
mf = repo.manifest.readflags(n)
|
2005-06-05 01:45:31 +04:00
|
|
|
files = m.keys()
|
|
|
|
files.sort()
|
|
|
|
|
|
|
|
for f in files:
|
2005-08-28 01:55:07 +04:00
|
|
|
ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f))
|
2005-06-05 01:45:31 +04:00
|
|
|
|
2005-09-01 20:11:25 +04:00
|
|
|
def outgoing(ui, repo, dest="default-push", **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
2006-02-28 02:46:06 +03:00
|
|
|
|
|
|
|
See pull for valid source format details.
|
2005-10-25 02:52:28 +04:00
|
|
|
"""
|
2005-10-25 04:41:45 +04:00
|
|
|
dest = ui.expandpath(dest, repo.root)
|
2005-08-17 03:49:26 +04:00
|
|
|
other = hg.repository(ui, dest)
|
|
|
|
o = repo.findoutgoing(other)
|
2005-10-07 21:48:27 +04:00
|
|
|
o = repo.changelog.nodesbetween(o)[0]
|
2005-10-25 03:59:31 +04:00
|
|
|
if opts['newest_first']:
|
|
|
|
o.reverse()
|
2005-08-17 03:49:26 +04:00
|
|
|
for n in o:
|
2005-10-25 02:37:20 +04:00
|
|
|
parents = [p for p in repo.changelog.parents(n) if p != nullid]
|
|
|
|
if opts['no_merges'] and len(parents) == 2:
|
|
|
|
continue
|
2005-08-17 03:49:26 +04:00
|
|
|
show_changeset(ui, repo, changenode=n)
|
2005-09-01 20:11:25 +04:00
|
|
|
if opts['patch']:
|
2005-10-25 02:37:20 +04:00
|
|
|
prev = (parents and parents[0]) or nullid
|
2005-09-01 20:11:25 +04:00
|
|
|
dodiff(ui, ui, repo, prev, n)
|
|
|
|
ui.write("\n")
|
2005-08-17 03:49:26 +04:00
|
|
|
|
2006-02-21 15:14:03 +03:00
|
|
|
def parents(ui, repo, rev=None, branches=None):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""show the parents of the working dir or revision
|
|
|
|
|
|
|
|
Print the working directory's parent revisions.
|
|
|
|
"""
|
2005-07-15 11:32:45 +04:00
|
|
|
if rev:
|
|
|
|
p = repo.changelog.parents(repo.lookup(rev))
|
2005-06-04 00:46:38 +04:00
|
|
|
else:
|
|
|
|
p = repo.dirstate.parents()
|
|
|
|
|
2006-02-16 00:21:20 +03:00
|
|
|
br = None
|
2006-02-21 15:14:03 +03:00
|
|
|
if branches is not None:
|
2006-02-16 00:21:20 +03:00
|
|
|
br = repo.branchlookup(p)
|
2005-06-04 00:46:38 +04:00
|
|
|
for n in p:
|
2005-08-28 01:55:07 +04:00
|
|
|
if n != nullid:
|
2006-02-16 00:21:20 +03:00
|
|
|
show_changeset(ui, repo, changenode=n, brinfo=br)
|
2005-06-04 00:46:38 +04:00
|
|
|
|
2005-08-26 15:06:58 +04:00
|
|
|
def paths(ui, search=None):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2005-08-17 01:52:28 +04:00
|
|
|
try:
|
2006-03-06 19:47:41 +03:00
|
|
|
repo = hg.repository(ui)
|
|
|
|
ui = repo.ui
|
2005-08-26 17:19:18 +04:00
|
|
|
except hg.RepoError:
|
2005-08-17 01:52:28 +04:00
|
|
|
pass
|
|
|
|
|
2005-07-27 20:19:59 +04:00
|
|
|
if search:
|
|
|
|
for name, path in ui.configitems("paths"):
|
|
|
|
if name == search:
|
|
|
|
ui.write("%s\n" % path)
|
|
|
|
return
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.warn(_("not found!\n"))
|
2005-07-27 20:19:59 +04:00
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
for name, path in ui.configitems("paths"):
|
|
|
|
ui.write("%s = %s\n" % (name, path))
|
|
|
|
|
2005-06-22 06:04:25 +04:00
|
|
|
def pull(ui, repo, source="default", **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2005-10-25 04:41:45 +04:00
|
|
|
source = ui.expandpath(source, repo.root)
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.status(_('pulling from %s\n') % (source))
|
2005-06-28 12:59:59 +04:00
|
|
|
|
2005-08-20 10:11:48 +04:00
|
|
|
if opts['ssh']:
|
|
|
|
ui.setconfig("ui", "ssh", opts['ssh'])
|
|
|
|
if opts['remotecmd']:
|
|
|
|
ui.setconfig("ui", "remotecmd", opts['remotecmd'])
|
|
|
|
|
2005-06-05 00:14:14 +04:00
|
|
|
other = hg.repository(ui, source)
|
2005-10-11 19:39:21 +04:00
|
|
|
revs = None
|
|
|
|
if opts['rev'] and not other.local():
|
2005-12-29 23:59:19 +03:00
|
|
|
raise util.Abort(_("pull -r doesn't work for remote repositories yet"))
|
2005-10-11 19:39:21 +04:00
|
|
|
elif opts['rev']:
|
|
|
|
revs = [other.lookup(rev) for rev in opts['rev']]
|
|
|
|
r = repo.pull(other, heads=revs)
|
2005-07-06 06:12:57 +04:00
|
|
|
if not r:
|
2005-06-22 06:04:25 +04:00
|
|
|
if opts['update']:
|
|
|
|
return update(ui, repo)
|
2005-07-03 06:29:54 +04:00
|
|
|
else:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.status(_("(run 'hg update' to get a working copy)\n"))
|
2005-06-22 06:04:25 +04:00
|
|
|
|
|
|
|
return r
|
2005-06-05 00:14:14 +04:00
|
|
|
|
2006-02-14 23:11:57 +03:00
|
|
|
def push(ui, repo, dest="default-push", **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2005-10-25 04:41:45 +04:00
|
|
|
dest = ui.expandpath(dest, repo.root)
|
2005-07-07 10:25:40 +04:00
|
|
|
ui.status('pushing to %s\n' % (dest))
|
2005-06-28 12:59:59 +04:00
|
|
|
|
2006-02-14 23:11:57 +03:00
|
|
|
if opts['ssh']:
|
|
|
|
ui.setconfig("ui", "ssh", opts['ssh'])
|
|
|
|
if opts['remotecmd']:
|
|
|
|
ui.setconfig("ui", "remotecmd", opts['remotecmd'])
|
2005-08-20 09:36:57 +04:00
|
|
|
|
2005-07-07 10:25:40 +04:00
|
|
|
other = hg.repository(ui, dest)
|
2006-02-14 23:11:57 +03:00
|
|
|
revs = None
|
|
|
|
if opts['rev']:
|
|
|
|
revs = [repo.lookup(rev) for rev in opts['rev']]
|
|
|
|
r = repo.push(other, opts['force'], revs=revs)
|
2005-07-07 10:25:40 +04:00
|
|
|
return r
|
2005-06-13 07:35:41 +04:00
|
|
|
|
2005-06-22 05:53:01 +04:00
|
|
|
def rawcommit(ui, repo, *flist, **rc):
|
2006-03-01 00:50:49 +03:00
|
|
|
"""raw commit interface (DEPRECATED)
|
2005-10-25 02:52:28 +04:00
|
|
|
|
2006-02-28 02:46:06 +03:00
|
|
|
(DEPRECATED)
|
2005-10-25 02:52:28 +04:00
|
|
|
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.
|
2006-01-29 09:06:42 +03:00
|
|
|
|
|
|
|
This command is now deprecated and will be removed in a future
|
|
|
|
release, please use debugsetparents and commit instead.
|
2005-10-25 02:52:28 +04:00
|
|
|
"""
|
2006-01-29 09:06:42 +03:00
|
|
|
|
|
|
|
ui.warn(_("(the rawcommit command is deprecated)\n"))
|
|
|
|
|
2005-11-03 11:43:05 +03:00
|
|
|
message = rc['message']
|
2005-07-22 19:26:46 +04:00
|
|
|
if not message and rc['logfile']:
|
2005-07-14 13:42:28 +04:00
|
|
|
try:
|
2005-07-22 19:26:46 +04:00
|
|
|
message = open(rc['logfile']).read()
|
2005-07-14 13:42:28 +04:00
|
|
|
except IOError:
|
|
|
|
pass
|
2005-07-22 19:26:46 +04:00
|
|
|
if not message and not rc['logfile']:
|
2005-10-19 05:38:39 +04:00
|
|
|
raise util.Abort(_("missing commit message"))
|
2005-06-05 00:14:14 +04:00
|
|
|
|
2005-06-22 05:53:01 +04:00
|
|
|
files = relpath(repo, list(flist))
|
2005-06-05 00:14:14 +04:00
|
|
|
if rc['files']:
|
|
|
|
files += open(rc['files']).read().splitlines()
|
2005-06-24 05:43:04 +04:00
|
|
|
|
|
|
|
rc['parent'] = map(repo.lookup, rc['parent'])
|
2005-06-28 12:59:59 +04:00
|
|
|
|
2005-09-05 01:47:02 +04:00
|
|
|
try:
|
|
|
|
repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent'])
|
|
|
|
except ValueError, inst:
|
|
|
|
raise util.Abort(str(inst))
|
2005-06-28 12:59:59 +04:00
|
|
|
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
def recover(ui, repo):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2005-11-09 01:22:03 +03:00
|
|
|
if repo.recover():
|
|
|
|
return repo.verify()
|
|
|
|
return False
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
|
2005-09-01 18:48:14 +04:00
|
|
|
def remove(ui, repo, pat, *pats, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2005-09-01 18:48:14 +04:00
|
|
|
names = []
|
2005-09-01 19:01:10 +04:00
|
|
|
def okaytoremove(abs, rel, exact):
|
2006-01-12 15:58:36 +03:00
|
|
|
modified, added, removed, deleted, unknown = repo.changes(files=[abs])
|
2005-09-01 19:01:10 +04:00
|
|
|
reason = None
|
2006-01-12 15:35:09 +03:00
|
|
|
if modified:
|
2006-01-12 09:57:58 +03:00
|
|
|
reason = _('is modified')
|
2006-01-12 15:35:09 +03:00
|
|
|
elif added:
|
2006-01-12 09:57:58 +03:00
|
|
|
reason = _('has been marked for add')
|
2006-01-12 15:35:09 +03:00
|
|
|
elif unknown:
|
2006-01-12 09:57:58 +03:00
|
|
|
reason = _('is not managed')
|
2005-09-15 09:32:12 +04:00
|
|
|
if reason:
|
2006-01-12 09:57:58 +03:00
|
|
|
if exact:
|
|
|
|
ui.warn(_('not removing %s: file %s\n') % (rel, reason))
|
2005-09-01 19:01:10 +04:00
|
|
|
else:
|
|
|
|
return True
|
2005-09-01 18:48:14 +04:00
|
|
|
for src, abs, rel, exact in walk(repo, (pat,) + pats, opts):
|
2005-09-01 19:01:10 +04:00
|
|
|
if okaytoremove(abs, rel, exact):
|
2006-01-12 09:57:58 +03:00
|
|
|
if ui.verbose or not exact:
|
|
|
|
ui.status(_('removing %s\n') % rel)
|
2005-09-01 18:48:14 +04:00
|
|
|
names.append(abs)
|
2005-10-19 11:10:52 +04:00
|
|
|
repo.remove(names, unlink=True)
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
|
2005-09-15 03:34:22 +04:00
|
|
|
def rename(ui, repo, *pats, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2006-03-01 10:47:40 +03:00
|
|
|
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
|
2005-09-15 03:34:22 +04:00
|
|
|
return errs
|
|
|
|
|
2005-10-28 00:31:12 +04:00
|
|
|
def revert(ui, repo, *pats, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""revert modified files or dirs back to their unmodified states
|
|
|
|
|
2006-02-28 02:46:06 +03:00
|
|
|
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.
|
2005-10-25 02:52:28 +04:00
|
|
|
|
|
|
|
If a file has been deleted, it is recreated. If the executable
|
|
|
|
mode of a file was changed, it is reset.
|
|
|
|
|
2005-10-28 00:31:12 +04:00
|
|
|
If names are given, all files matching the names are reverted.
|
2005-10-25 02:52:28 +04:00
|
|
|
|
2005-12-01 19:51:45 +03:00
|
|
|
If no arguments are given, all files in the repository are reverted.
|
2005-10-25 02:52:28 +04:00
|
|
|
"""
|
2005-07-03 08:51:33 +04:00
|
|
|
node = opts['rev'] and repo.lookup(opts['rev']) or \
|
|
|
|
repo.dirstate.parents()[0]
|
2005-07-03 07:49:46 +04:00
|
|
|
|
2006-01-17 18:10:22 +03:00
|
|
|
files, choose, anypats = matchpats(repo, pats, opts)
|
2006-01-12 15:58:36 +03:00
|
|
|
modified, added, removed, deleted, unknown = repo.changes(match=choose)
|
2006-01-12 15:35:09 +03:00
|
|
|
repo.forget(added)
|
2006-02-24 22:25:18 +03:00
|
|
|
repo.undelete(removed)
|
2005-10-28 00:31:12 +04:00
|
|
|
|
|
|
|
return repo.update(node, False, True, choose, False)
|
2005-07-03 07:49:46 +04:00
|
|
|
|
2005-06-25 11:22:46 +04:00
|
|
|
def root(ui, repo):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""print the root (top) of the current working dir
|
|
|
|
|
|
|
|
Print the root directory of the current repository.
|
|
|
|
"""
|
2005-06-25 11:22:46 +04:00
|
|
|
ui.write(repo.root + "\n")
|
|
|
|
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
def serve(ui, repo, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2005-07-06 05:55:22 +04:00
|
|
|
|
|
|
|
if opts["stdio"]:
|
2005-07-07 10:20:12 +04:00
|
|
|
fin, fout = sys.stdin, sys.stdout
|
|
|
|
sys.stdout = sys.stderr
|
|
|
|
|
2005-10-25 01:34:48 +04:00
|
|
|
# Prevent insertion/deletion of CRs
|
|
|
|
util.set_binary(fin)
|
|
|
|
util.set_binary(fout)
|
|
|
|
|
2005-07-06 05:55:22 +04:00
|
|
|
def getarg():
|
2005-07-07 10:20:12 +04:00
|
|
|
argline = fin.readline()[:-1]
|
2005-07-06 05:55:22 +04:00
|
|
|
arg, l = argline.split()
|
2005-07-07 10:20:12 +04:00
|
|
|
val = fin.read(int(l))
|
2005-07-06 05:55:22 +04:00
|
|
|
return arg, val
|
|
|
|
def respond(v):
|
2005-07-07 10:20:12 +04:00
|
|
|
fout.write("%d\n" % len(v))
|
|
|
|
fout.write(v)
|
|
|
|
fout.flush()
|
2005-07-06 05:55:22 +04:00
|
|
|
|
2005-07-07 10:23:27 +04:00
|
|
|
lock = None
|
|
|
|
|
2005-07-06 05:55:22 +04:00
|
|
|
while 1:
|
2005-07-07 10:20:12 +04:00
|
|
|
cmd = fin.readline()[:-1]
|
2005-07-06 05:55:22 +04:00
|
|
|
if cmd == '':
|
|
|
|
return
|
|
|
|
if cmd == "heads":
|
|
|
|
h = repo.heads()
|
2005-08-28 01:55:07 +04:00
|
|
|
respond(" ".join(map(hex, h)) + "\n")
|
2005-07-07 10:23:27 +04:00
|
|
|
if cmd == "lock":
|
|
|
|
lock = repo.lock()
|
|
|
|
respond("")
|
|
|
|
if cmd == "unlock":
|
2005-07-14 13:42:28 +04:00
|
|
|
if lock:
|
|
|
|
lock.release()
|
2005-07-07 10:23:27 +04:00
|
|
|
lock = None
|
|
|
|
respond("")
|
2005-07-06 05:55:22 +04:00
|
|
|
elif cmd == "branches":
|
|
|
|
arg, nodes = getarg()
|
2005-08-28 01:55:07 +04:00
|
|
|
nodes = map(bin, nodes.split(" "))
|
2005-07-06 05:55:22 +04:00
|
|
|
r = []
|
|
|
|
for b in repo.branches(nodes):
|
2005-08-28 01:55:07 +04:00
|
|
|
r.append(" ".join(map(hex, b)) + "\n")
|
2005-07-06 05:55:22 +04:00
|
|
|
respond("".join(r))
|
|
|
|
elif cmd == "between":
|
|
|
|
arg, pairs = getarg()
|
2005-08-28 01:55:07 +04:00
|
|
|
pairs = [map(bin, p.split("-")) for p in pairs.split(" ")]
|
2005-07-06 05:55:22 +04:00
|
|
|
r = []
|
|
|
|
for b in repo.between(pairs):
|
2005-08-28 01:55:07 +04:00
|
|
|
r.append(" ".join(map(hex, b)) + "\n")
|
2005-07-06 05:55:22 +04:00
|
|
|
respond("".join(r))
|
|
|
|
elif cmd == "changegroup":
|
|
|
|
nodes = []
|
|
|
|
arg, roots = getarg()
|
2005-08-28 01:55:07 +04:00
|
|
|
nodes = map(bin, roots.split(" "))
|
2005-07-06 05:55:22 +04:00
|
|
|
|
2006-02-17 19:26:21 +03:00
|
|
|
cg = repo.changegroup(nodes, 'serve')
|
2005-07-07 10:20:12 +04:00
|
|
|
while 1:
|
|
|
|
d = cg.read(4096)
|
2005-07-14 13:42:28 +04:00
|
|
|
if not d:
|
|
|
|
break
|
2005-07-07 10:20:12 +04:00
|
|
|
fout.write(d)
|
|
|
|
|
2005-07-11 04:01:11 +04:00
|
|
|
fout.flush()
|
2005-07-06 05:55:22 +04:00
|
|
|
|
2005-07-07 10:23:57 +04:00
|
|
|
elif cmd == "addchangegroup":
|
|
|
|
if not lock:
|
|
|
|
respond("not locked")
|
|
|
|
continue
|
|
|
|
respond("")
|
|
|
|
|
|
|
|
r = repo.addchangegroup(fin)
|
|
|
|
respond("")
|
|
|
|
|
2005-08-22 02:56:14 +04:00
|
|
|
optlist = "name templates style address port ipv6 accesslog errorlog"
|
|
|
|
for o in optlist.split():
|
|
|
|
if opts[o]:
|
|
|
|
ui.setconfig("web", o, opts[o])
|
|
|
|
|
2006-02-18 03:32:07 +03:00
|
|
|
if opts['daemon'] and not opts['daemon_pipefds']:
|
2006-02-18 03:29:30 +03:00
|
|
|
rfd, wfd = os.pipe()
|
|
|
|
args = sys.argv[:]
|
2006-02-18 03:32:07 +03:00
|
|
|
args.append('--daemon-pipefds=%d,%d' % (rfd, wfd))
|
2006-02-18 03:29:30 +03:00
|
|
|
pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0),
|
|
|
|
args[0], args)
|
|
|
|
os.close(wfd)
|
|
|
|
os.read(rfd, 1)
|
|
|
|
os._exit(0)
|
|
|
|
|
2005-08-31 22:19:20 +04:00
|
|
|
try:
|
|
|
|
httpd = hgweb.create_server(repo)
|
|
|
|
except socket.error, inst:
|
2005-12-29 23:59:19 +03:00
|
|
|
raise util.Abort(_('cannot start server: ') + inst.args[1])
|
2005-08-22 02:56:14 +04:00
|
|
|
|
2005-07-04 08:47:29 +04:00
|
|
|
if ui.verbose:
|
|
|
|
addr, port = httpd.socket.getsockname()
|
|
|
|
if addr == '0.0.0.0':
|
|
|
|
addr = socket.gethostname()
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
addr = socket.gethostbyaddr(addr)[0]
|
2005-07-14 13:42:28 +04:00
|
|
|
except socket.error:
|
|
|
|
pass
|
2005-07-04 08:47:29 +04:00
|
|
|
if port != 80:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.status(_('listening at http://%s:%d/\n') % (addr, port))
|
2005-07-04 08:47:29 +04:00
|
|
|
else:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.status(_('listening at http://%s/\n') % addr)
|
2006-02-18 03:29:30 +03:00
|
|
|
|
|
|
|
if opts['pid_file']:
|
|
|
|
fp = open(opts['pid_file'], 'w')
|
|
|
|
fp.write(str(os.getpid()))
|
|
|
|
fp.close()
|
|
|
|
|
2006-02-18 03:32:07 +03:00
|
|
|
if opts['daemon_pipefds']:
|
|
|
|
rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')]
|
|
|
|
os.close(rfd)
|
2006-02-18 03:29:30 +03:00
|
|
|
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)
|
|
|
|
|
2005-07-04 08:47:29 +04:00
|
|
|
httpd.serve_forever()
|
2005-06-28 12:59:59 +04:00
|
|
|
|
2005-07-20 15:01:23 +04:00
|
|
|
def status(ui, repo, *pats, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""show changed files in the working directory
|
2005-06-01 23:48:34 +04:00
|
|
|
|
2005-12-01 19:51:45 +03:00
|
|
|
Show changed files in the repository. If names are
|
|
|
|
given, only files that match are shown.
|
2005-10-25 02:52:28 +04:00
|
|
|
|
|
|
|
The codes used to show the status of files are:
|
2005-07-21 21:24:42 +04:00
|
|
|
M = modified
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
A = added
|
|
|
|
R = removed
|
2006-01-12 15:58:36 +03:00
|
|
|
! = deleted, but still tracked
|
2005-08-06 15:05:09 +04:00
|
|
|
? = not tracked
|
2005-10-25 02:52:28 +04:00
|
|
|
"""
|
2005-06-12 20:11:43 +04:00
|
|
|
|
2006-01-17 18:10:22 +03:00
|
|
|
files, matchfn, anypats = matchpats(repo, pats, opts)
|
|
|
|
cwd = (pats and repo.getcwd()) or ''
|
2006-01-12 15:58:36 +03:00
|
|
|
modified, added, removed, deleted, unknown = [
|
2006-01-12 15:35:09 +03:00
|
|
|
[util.pathto(cwd, x) for x in n]
|
|
|
|
for n in repo.changes(files=files, match=matchfn)]
|
2005-06-01 23:48:34 +04:00
|
|
|
|
2006-01-12 15:35:09 +03:00
|
|
|
changetypes = [(_('modified'), 'M', modified),
|
|
|
|
(_('added'), 'A', added),
|
|
|
|
(_('removed'), 'R', removed),
|
2006-01-12 15:58:36 +03:00
|
|
|
(_('deleted'), '!', deleted),
|
2006-01-12 15:35:09 +03:00
|
|
|
(_('unknown'), '?', unknown)]
|
2005-08-06 15:05:09 +04:00
|
|
|
|
2005-08-27 12:49:41 +04:00
|
|
|
end = opts['print0'] and '\0' or '\n'
|
2005-08-28 01:25:55 +04:00
|
|
|
|
2005-08-06 15:05:09 +04:00
|
|
|
for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]]
|
|
|
|
or changetypes):
|
2005-08-28 01:23:32 +04:00
|
|
|
if opts['no_status']:
|
2005-08-27 12:49:41 +04:00
|
|
|
format = "%%s%s" % end
|
|
|
|
else:
|
|
|
|
format = "%s %%s%s" % (char, end);
|
2005-08-28 01:25:55 +04:00
|
|
|
|
2005-08-06 15:05:09 +04:00
|
|
|
for f in changes:
|
2005-08-27 12:49:41 +04:00
|
|
|
ui.write(format % f)
|
2005-06-01 23:48:34 +04:00
|
|
|
|
2005-12-27 21:52:10 +03:00
|
|
|
def tag(ui, repo, name, rev_=None, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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
|
2006-01-29 07:12:31 +03:00
|
|
|
necessary. The file '.hg/localtags' is used for local tags (not
|
|
|
|
shared among repositories).
|
2005-10-25 02:52:28 +04:00
|
|
|
"""
|
2005-06-22 05:47:28 +04:00
|
|
|
if name == "tip":
|
2005-10-19 05:38:39 +04:00
|
|
|
raise util.Abort(_("the name 'tip' is reserved"))
|
2006-01-29 07:12:31 +03:00
|
|
|
if rev_ is not None:
|
|
|
|
ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, "
|
2006-01-29 16:33:12 +03:00
|
|
|
"please use 'hg tag [-r REV] NAME' instead\n"))
|
2006-01-29 07:12:31 +03:00
|
|
|
if opts['rev']:
|
|
|
|
raise util.Abort(_("use only one form to specify the revision"))
|
2005-12-27 21:52:10 +03:00
|
|
|
if opts['rev']:
|
|
|
|
rev_ = opts['rev']
|
|
|
|
if rev_:
|
|
|
|
r = hex(repo.lookup(rev_))
|
2005-07-04 23:00:25 +04:00
|
|
|
else:
|
2005-08-28 01:55:07 +04:00
|
|
|
r = hex(repo.changelog.tip())
|
2005-07-04 23:00:25 +04:00
|
|
|
|
2005-11-30 00:29:14 +03:00
|
|
|
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))
|
2005-06-22 05:47:28 +04:00
|
|
|
|
2006-02-15 02:47:25 +03:00
|
|
|
repo.hook('pretag', throw=True, node=r, tag=name,
|
2006-02-16 20:56:31 +03:00
|
|
|
local=int(not not opts['local']))
|
2006-02-15 02:47:25 +03:00
|
|
|
|
2005-07-04 23:00:25 +04:00
|
|
|
if opts['local']:
|
|
|
|
repo.opener("localtags", "a").write("%s %s\n" % (r, name))
|
2006-02-15 02:47:25 +03:00
|
|
|
repo.hook('tag', node=r, tag=name, local=1)
|
2005-07-04 23:00:25 +04:00
|
|
|
return
|
|
|
|
|
2006-01-12 15:35:09 +03:00
|
|
|
for x in repo.changes():
|
2005-07-03 06:29:54 +04:00
|
|
|
if ".hgtags" in x:
|
2005-10-19 05:38:39 +04:00
|
|
|
raise util.Abort(_("working copy of .hgtags is changed "
|
|
|
|
"(please commit .hgtags manually)"))
|
2005-06-22 05:47:28 +04:00
|
|
|
|
2005-07-05 00:39:21 +04:00
|
|
|
repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name))
|
2005-07-15 15:06:29 +04:00
|
|
|
if repo.dirstate.state(".hgtags") == '?':
|
2005-07-14 13:42:28 +04:00
|
|
|
repo.add([".hgtags"])
|
2005-06-22 05:47:28 +04:00
|
|
|
|
2005-11-03 11:43:05 +03:00
|
|
|
message = (opts['message'] or
|
2005-10-19 05:38:39 +04:00
|
|
|
_("Added tag %s for changeset %s") % (name, r))
|
2005-09-05 01:47:02 +04:00
|
|
|
try:
|
|
|
|
repo.commit([".hgtags"], message, opts['user'], opts['date'])
|
2006-02-15 02:47:25 +03:00
|
|
|
repo.hook('tag', node=r, tag=name, local=0)
|
2005-09-05 01:47:02 +04:00
|
|
|
except ValueError, inst:
|
|
|
|
raise util.Abort(str(inst))
|
2005-06-22 05:47:28 +04:00
|
|
|
|
2005-06-05 01:45:31 +04:00
|
|
|
def tags(ui, repo):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""list repository tags
|
|
|
|
|
|
|
|
List the repository tags.
|
|
|
|
|
|
|
|
This lists both regular and local tags.
|
|
|
|
"""
|
2005-06-26 16:25:07 +04:00
|
|
|
|
2005-06-15 12:08:03 +04:00
|
|
|
l = repo.tagslist()
|
|
|
|
l.reverse()
|
2005-06-26 16:25:07 +04:00
|
|
|
for t, n in l:
|
2005-06-05 01:45:31 +04:00
|
|
|
try:
|
2005-08-28 01:55:07 +04:00
|
|
|
r = "%5d:%s" % (repo.changelog.rev(n), hex(n))
|
2005-06-05 01:45:31 +04:00
|
|
|
except KeyError:
|
2005-06-26 16:25:07 +04:00
|
|
|
r = " ?:?"
|
|
|
|
ui.write("%-30s %s\n" % (t, r))
|
2005-06-05 01:45:31 +04:00
|
|
|
|
2006-02-15 22:05:43 +03:00
|
|
|
def tip(ui, repo, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""show the tip revision
|
|
|
|
|
|
|
|
Show the tip revision.
|
|
|
|
"""
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
n = repo.changelog.tip()
|
2006-02-21 14:59:16 +03:00
|
|
|
br = None
|
2006-02-21 15:14:03 +03:00
|
|
|
if opts['branches']:
|
2006-02-21 14:59:16 +03:00
|
|
|
br = repo.branchlookup([n])
|
|
|
|
show_changeset(ui, repo, changenode=n, brinfo=br)
|
2006-02-15 22:05:43 +03:00
|
|
|
if opts['patch']:
|
|
|
|
dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n)
|
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
2005-06-04 23:18:56 +04:00
|
|
|
|
2005-12-28 01:16:06 +03:00
|
|
|
def unbundle(ui, repo, fname, **opts):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""apply a changegroup file
|
|
|
|
|
|
|
|
Apply a compressed changegroup file generated by the bundle
|
|
|
|
command.
|
|
|
|
"""
|
2005-09-08 12:27:25 +04:00
|
|
|
f = urllib.urlopen(fname)
|
|
|
|
|
|
|
|
if f.read(4) != "HG10":
|
2005-10-19 05:38:39 +04:00
|
|
|
raise util.Abort(_("%s: not a Mercurial bundle file") % fname)
|
2005-09-08 12:27:25 +04:00
|
|
|
|
2005-10-04 01:43:11 +04:00
|
|
|
def bzgenerator(f):
|
|
|
|
zd = bz2.BZ2Decompressor()
|
|
|
|
for chunk in f:
|
|
|
|
yield zd.decompress(chunk)
|
|
|
|
|
|
|
|
bzgen = bzgenerator(util.filechunkiter(f, 4096))
|
2005-12-28 01:18:00 +03:00
|
|
|
if repo.addchangegroup(util.chunkbuffer(bzgen)):
|
|
|
|
return 1
|
|
|
|
|
2005-12-28 01:16:06 +03:00
|
|
|
if opts['update']:
|
|
|
|
return update(ui, repo)
|
|
|
|
else:
|
|
|
|
ui.status(_("(run 'hg update' to get a working copy)\n"))
|
2005-09-08 12:27:25 +04:00
|
|
|
|
2005-06-01 23:11:19 +04:00
|
|
|
def undo(ui, repo):
|
2005-07-03 23:47:45 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2005-06-01 22:40:19 +04:00
|
|
|
repo.undo()
|
|
|
|
|
2005-12-15 07:19:03 +03:00
|
|
|
def update(ui, repo, node=None, merge=False, clean=False, force=None,
|
|
|
|
branch=None):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""update or merge working directory
|
|
|
|
|
|
|
|
Update the working directory to the specified revision.
|
2005-06-05 06:34:35 +04:00
|
|
|
|
|
|
|
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.
|
2005-10-25 02:52:28 +04:00
|
|
|
|
|
|
|
By default, update will refuse to run if doing so would require
|
|
|
|
merging or discarding local changes.
|
|
|
|
"""
|
2005-08-15 00:23:45 +04:00
|
|
|
if branch:
|
|
|
|
br = repo.branchlookup(branch=branch)
|
|
|
|
found = []
|
|
|
|
for x in br:
|
|
|
|
if branch in br[x]:
|
|
|
|
found.append(x)
|
|
|
|
if len(found) > 1:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.warn(_("Found multiple heads for %s\n") % branch)
|
2005-08-15 00:23:45 +04:00
|
|
|
for x in found:
|
|
|
|
show_changeset(ui, repo, changenode=x, brinfo=br)
|
|
|
|
return 1
|
|
|
|
if len(found) == 1:
|
|
|
|
node = found[0]
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.warn(_("Using head %s for branch %s\n") % (short(node), branch))
|
2005-08-15 00:23:45 +04:00
|
|
|
else:
|
2005-10-19 05:38:39 +04:00
|
|
|
ui.warn(_("branch %s not found\n") % (branch))
|
2005-08-15 00:23:45 +04:00
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
node = node and repo.lookup(node) or repo.changelog.tip()
|
2005-12-15 07:19:03 +03:00
|
|
|
return repo.update(node, allow=merge, force=clean, forcemerge=force)
|
2005-06-05 06:34:35 +04:00
|
|
|
|
2005-06-05 00:24:23 +04:00
|
|
|
def verify(ui, repo):
|
2005-10-25 02:52:28 +04:00
|
|
|
"""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.
|
|
|
|
"""
|
2005-06-05 00:24:23 +04:00
|
|
|
return repo.verify()
|
|
|
|
|
2005-06-05 07:09:00 +04:00
|
|
|
# Command options and aliases are listed here, alphabetically
|
|
|
|
|
2005-06-01 12:25:42 +04:00
|
|
|
table = {
|
2005-08-06 10:16:37 +04:00
|
|
|
"^add":
|
|
|
|
(add,
|
2005-10-25 02:52:28 +04:00
|
|
|
[('I', 'include', [], _('include names matching the given patterns')),
|
|
|
|
('X', 'exclude', [], _('exclude names matching the given patterns'))],
|
2006-01-12 09:57:58 +03:00
|
|
|
_('hg add [OPTION]... [FILE]...')),
|
2005-08-06 10:16:37 +04:00
|
|
|
"addremove":
|
|
|
|
(addremove,
|
2005-10-25 02:52:28 +04:00
|
|
|
[('I', 'include', [], _('include names matching the given patterns')),
|
|
|
|
('X', 'exclude', [], _('exclude names matching the given patterns'))],
|
2006-01-12 09:57:58 +03:00
|
|
|
_('hg addremove [OPTION]... [FILE]...')),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^annotate":
|
|
|
|
(annotate,
|
2005-10-25 02:52:28 +04:00
|
|
|
[('r', 'rev', '', _('annotate the specified revision')),
|
2005-10-19 05:38:39 +04:00
|
|
|
('a', 'text', None, _('treat all files as text')),
|
2005-10-25 02:52:28 +04:00
|
|
|
('u', 'user', None, _('list the author')),
|
2005-11-10 00:39:24 +03:00
|
|
|
('d', 'date', None, _('list the date')),
|
2005-10-25 02:52:28 +04:00
|
|
|
('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'))],
|
2006-03-01 11:08:56 +03:00
|
|
|
_('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')),
|
2005-09-08 12:27:25 +04:00
|
|
|
"bundle":
|
|
|
|
(bundle,
|
|
|
|
[],
|
2005-10-19 05:38:39 +04:00
|
|
|
_('hg bundle FILE DEST')),
|
2005-07-14 13:42:28 +04:00
|
|
|
"cat":
|
|
|
|
(cat,
|
2006-03-01 11:08:56 +03:00
|
|
|
[('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'))],
|
2005-10-19 05:38:39 +04:00
|
|
|
_('hg cat [OPTION]... FILE...')),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^clone":
|
|
|
|
(clone,
|
2005-10-25 02:52:28 +04:00
|
|
|
[('U', 'noupdate', None, _('do not update the new working directory')),
|
2005-12-28 09:27:05 +03:00
|
|
|
('r', 'rev', [],
|
|
|
|
_('a changeset you would like to have after cloning')),
|
2006-03-01 11:08:56 +03:00
|
|
|
('', 'pull', None, _('use pull protocol to copy metadata')),
|
|
|
|
('e', 'ssh', '', _('specify ssh command to use')),
|
2006-01-12 09:57:58 +03:00
|
|
|
('', 'remotecmd', '',
|
2005-12-28 09:27:05 +03:00
|
|
|
_('specify hg command to run on the remote side'))],
|
2005-10-19 05:38:39 +04:00
|
|
|
_('hg clone [OPTION]... SOURCE [DEST]')),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^commit|ci":
|
|
|
|
(commit,
|
2005-10-25 02:52:28 +04:00
|
|
|
[('A', 'addremove', None, _('run addremove during commit')),
|
2006-01-12 09:57:58 +03:00
|
|
|
('m', 'message', '', _('use <text> as commit message')),
|
|
|
|
('l', 'logfile', '', _('read the commit message from <file>')),
|
|
|
|
('d', 'date', '', _('record datecode as commit date')),
|
2006-03-01 11:08:56 +03:00
|
|
|
('u', 'user', '', _('record user as commiter')),
|
|
|
|
('I', 'include', [], _('include names matching the given patterns')),
|
|
|
|
('X', 'exclude', [], _('exclude names matching the given patterns'))],
|
2005-10-19 05:38:39 +04:00
|
|
|
_('hg commit [OPTION]... [FILE]...')),
|
2006-01-12 09:57:58 +03:00
|
|
|
"copy|cp":
|
|
|
|
(copy,
|
2006-03-01 11:08:56 +03:00
|
|
|
[('A', 'after', None, _('record a copy that has already occurred')),
|
2006-01-12 09:57:58 +03:00
|
|
|
('f', 'force', None,
|
2006-03-01 11:08:56 +03:00
|
|
|
_('forcibly copy over an existing managed file')),
|
|
|
|
('I', 'include', [], _('include names matching the given patterns')),
|
|
|
|
('X', 'exclude', [], _('exclude names matching the given patterns'))],
|
2006-01-12 09:57:58 +03:00
|
|
|
_('hg copy [OPTION]... [SOURCE]... DEST')),
|
2005-10-19 05:38:39 +04:00
|
|
|
"debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')),
|
2006-02-20 21:04:56 +03:00
|
|
|
"debugrebuildstate":
|
|
|
|
(debugrebuildstate,
|
2006-03-01 11:08:56 +03:00
|
|
|
[('r', 'rev', '', _('revision to rebuild to'))],
|
2006-02-20 21:04:56 +03:00
|
|
|
_('debugrebuildstate [-r REV] [REV]')),
|
2005-10-19 05:38:39 +04:00
|
|
|
"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]')),
|
2005-08-06 10:16:37 +04:00
|
|
|
"debugwalk":
|
|
|
|
(debugwalk,
|
2005-10-25 02:52:28 +04:00
|
|
|
[('I', 'include', [], _('include names matching the given patterns')),
|
|
|
|
('X', 'exclude', [], _('exclude names matching the given patterns'))],
|
2005-10-19 05:38:39 +04:00
|
|
|
_('debugwalk [OPTION]... [FILE]...')),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^diff":
|
|
|
|
(diff,
|
2005-10-19 05:38:39 +04:00
|
|
|
[('r', 'rev', [], _('revision')),
|
|
|
|
('a', 'text', None, _('treat all files as text')),
|
2006-02-15 21:39:47 +03:00
|
|
|
('p', 'show-function', None,
|
|
|
|
_('show which function each change is in')),
|
|
|
|
('w', 'ignore-all-space', None,
|
|
|
|
_('ignore white space when comparing lines')),
|
2006-03-01 11:08:56 +03:00
|
|
|
('I', 'include', [], _('include names matching the given patterns')),
|
|
|
|
('X', 'exclude', [], _('exclude names matching the given patterns'))],
|
2005-10-19 05:38:39 +04:00
|
|
|
_('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^export":
|
|
|
|
(export,
|
2006-01-12 09:57:58 +03:00
|
|
|
[('o', 'output', '', _('print output to file with formatted name')),
|
2005-12-15 06:01:57 +03:00
|
|
|
('a', 'text', None, _('treat all files as text')),
|
|
|
|
('', 'switch-parent', None, _('diff against the second parent'))],
|
2006-03-01 00:50:49 +03:00
|
|
|
_('hg export [-a] [-o OUTFILESPEC] REV...')),
|
2005-08-06 10:16:37 +04:00
|
|
|
"forget":
|
|
|
|
(forget,
|
2005-10-25 02:52:28 +04:00
|
|
|
[('I', 'include', [], _('include names matching the given patterns')),
|
|
|
|
('X', 'exclude', [], _('exclude names matching the given patterns'))],
|
2006-01-12 09:57:58 +03:00
|
|
|
_('hg forget [OPTION]... FILE...')),
|
2005-08-26 17:19:18 +04:00
|
|
|
"grep":
|
|
|
|
(grep,
|
2005-10-19 05:38:39 +04:00
|
|
|
[('0', 'print0', None, _('end fields with NUL')),
|
2005-10-25 02:52:28 +04:00
|
|
|
('', 'all', None, _('print all revisions that match')),
|
2005-10-19 05:38:39 +04:00
|
|
|
('i', 'ignore-case', None, _('ignore case when matching')),
|
2005-12-28 09:27:05 +03:00
|
|
|
('l', 'files-with-matches', None,
|
|
|
|
_('print only filenames and revs that match')),
|
2005-10-25 02:52:28 +04:00
|
|
|
('n', 'line-number', None, _('print matching line numbers')),
|
|
|
|
('r', 'rev', [], _('search in given revision range')),
|
2006-03-01 11:08:56 +03:00
|
|
|
('u', 'user', None, _('print user who committed change')),
|
|
|
|
('I', 'include', [], _('include names matching the given patterns')),
|
|
|
|
('X', 'exclude', [], _('exclude names matching the given patterns'))],
|
2006-01-12 09:57:58 +03:00
|
|
|
_('hg grep [OPTION]... PATTERN [FILE]...')),
|
2005-08-15 08:22:40 +04:00
|
|
|
"heads":
|
|
|
|
(heads,
|
2006-02-21 15:14:03 +03:00
|
|
|
[('b', 'branches', None, _('show branches')),
|
2006-01-12 09:57:58 +03:00
|
|
|
('r', 'rev', '', _('show only heads which are descendants of rev'))],
|
2005-11-16 14:08:25 +03:00
|
|
|
_('hg heads [-b] [-r <rev>]')),
|
2005-10-19 05:38:39 +04:00
|
|
|
"help": (help_, [], _('hg help [COMMAND]')),
|
|
|
|
"identify|id": (identify, [], _('hg identify')),
|
2005-07-14 13:42:28 +04:00
|
|
|
"import|patch":
|
|
|
|
(import_,
|
2005-12-28 09:27:05 +03:00
|
|
|
[('p', 'strip', 1,
|
|
|
|
_('directory strip option for patch. This has the same\n') +
|
|
|
|
_('meaning as the corresponding patch option')),
|
2006-03-01 11:08:56 +03:00
|
|
|
('b', 'base', '', _('base path')),
|
2005-12-28 09:27:05 +03:00
|
|
|
('f', 'force', None,
|
2006-03-01 11:08:56 +03:00
|
|
|
_('skip check for outstanding uncommitted changes'))],
|
|
|
|
_('hg import [-p NUM] [-b BASE] [-f] PATCH...')),
|
2005-09-15 03:34:22 +04:00
|
|
|
"incoming|in": (incoming,
|
2006-01-12 09:57:58 +03:00
|
|
|
[('M', 'no-merges', None, _('do not show merges')),
|
2005-10-25 03:59:31 +04:00
|
|
|
('p', 'patch', None, _('show patch')),
|
|
|
|
('n', 'newest-first', None, _('show newest record first'))],
|
|
|
|
_('hg incoming [-p] [-n] [-M] [SOURCE]')),
|
2005-10-19 05:38:39 +04:00
|
|
|
"^init": (init, [], _('hg init [DEST]')),
|
2005-07-14 13:42:28 +04:00
|
|
|
"locate":
|
|
|
|
(locate,
|
2005-10-25 02:52:28 +04:00
|
|
|
[('r', 'rev', '', _('search the repository as it stood at rev')),
|
2005-12-28 09:27:05 +03:00
|
|
|
('0', 'print0', None,
|
|
|
|
_('end filenames with NUL, for use with xargs')),
|
|
|
|
('f', 'fullpath', None,
|
|
|
|
_('print complete paths from the filesystem root')),
|
2005-10-25 02:52:28 +04:00
|
|
|
('I', 'include', [], _('include names matching the given patterns')),
|
|
|
|
('X', 'exclude', [], _('exclude names matching the given patterns'))],
|
2005-10-19 05:38:39 +04:00
|
|
|
_('hg locate [OPTION]... [PATTERN]...')),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^log|history":
|
|
|
|
(log,
|
2006-03-01 11:08:56 +03:00
|
|
|
[('b', 'branches', None, _('show branches')),
|
2005-10-19 05:38:39 +04:00
|
|
|
('k', 'keyword', [], _('search for a keyword')),
|
2006-02-20 22:06:41 +03:00
|
|
|
('l', 'limit', '', _('limit number of changes displayed')),
|
2005-10-25 02:52:28 +04:00
|
|
|
('r', 'rev', [], _('show the specified revision or range')),
|
2006-01-12 09:57:58 +03:00
|
|
|
('M', 'no-merges', None, _('do not show merges')),
|
|
|
|
('m', 'only-merges', None, _('show only merges')),
|
2006-03-01 11:08:56 +03:00
|
|
|
('p', 'patch', None, _('show patch')),
|
|
|
|
('I', 'include', [], _('include names matching the given patterns')),
|
|
|
|
('X', 'exclude', [], _('exclude names matching the given patterns'))],
|
|
|
|
_('hg log [OPTION]... [FILE]')),
|
2005-10-19 05:38:39 +04:00
|
|
|
"manifest": (manifest, [], _('hg manifest [REV]')),
|
2005-09-15 03:34:22 +04:00
|
|
|
"outgoing|out": (outgoing,
|
2006-01-12 09:57:58 +03:00
|
|
|
[('M', 'no-merges', None, _('do not show merges')),
|
2005-10-25 03:59:31 +04:00
|
|
|
('p', 'patch', None, _('show patch')),
|
|
|
|
('n', 'newest-first', None, _('show newest record first'))],
|
2006-03-01 11:08:56 +03:00
|
|
|
_('hg outgoing [-M] [-p] [-n] [DEST]')),
|
2006-02-16 00:21:20 +03:00
|
|
|
"^parents":
|
|
|
|
(parents,
|
2006-02-21 15:14:03 +03:00
|
|
|
[('b', 'branches', None, _('show branches'))],
|
2006-02-16 00:21:20 +03:00
|
|
|
_('hg parents [-b] [REV]')),
|
2005-10-19 05:38:39 +04:00
|
|
|
"paths": (paths, [], _('hg paths [NAME]')),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^pull":
|
|
|
|
(pull,
|
2005-12-28 09:27:05 +03:00
|
|
|
[('u', 'update', None,
|
|
|
|
_('update the working directory to tip after pull')),
|
2006-01-12 09:57:58 +03:00
|
|
|
('e', 'ssh', '', _('specify ssh command to use')),
|
2005-10-27 23:26:16 +04:00
|
|
|
('r', 'rev', [], _('a specific revision you would like to pull')),
|
2006-01-12 09:57:58 +03:00
|
|
|
('', 'remotecmd', '',
|
2005-12-28 09:27:05 +03:00
|
|
|
_('specify hg command to run on the remote side'))],
|
2006-03-01 11:08:56 +03:00
|
|
|
_('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')),
|
2005-08-02 11:34:23 +04:00
|
|
|
"^push":
|
|
|
|
(push,
|
2005-10-19 05:38:39 +04:00
|
|
|
[('f', 'force', None, _('force push')),
|
2006-01-12 09:57:58 +03:00
|
|
|
('e', 'ssh', '', _('specify ssh command to use')),
|
2006-02-14 23:11:57 +03:00
|
|
|
('r', 'rev', [], _('a specific revision you would like to push')),
|
2006-01-12 09:57:58 +03:00
|
|
|
('', 'remotecmd', '',
|
2005-12-28 09:27:05 +03:00
|
|
|
_('specify hg command to run on the remote side'))],
|
2006-03-01 11:08:56 +03:00
|
|
|
_('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')),
|
2006-03-01 11:14:25 +03:00
|
|
|
"debugrawcommit|rawcommit":
|
2005-07-14 13:42:28 +04:00
|
|
|
(rawcommit,
|
2005-10-19 05:38:39 +04:00
|
|
|
[('p', 'parent', [], _('parent')),
|
2006-01-12 09:57:58 +03:00
|
|
|
('d', 'date', '', _('date code')),
|
|
|
|
('u', 'user', '', _('user')),
|
|
|
|
('F', 'files', '', _('file list')),
|
|
|
|
('m', 'message', '', _('commit message')),
|
|
|
|
('l', 'logfile', '', _('commit message file'))],
|
2006-03-01 11:14:25 +03:00
|
|
|
_('hg debugrawcommit [OPTION]... [FILE]...')),
|
2006-01-12 09:57:58 +03:00
|
|
|
"recover": (recover, [], _('hg recover')),
|
|
|
|
"^remove|rm":
|
|
|
|
(remove,
|
|
|
|
[('I', 'include', [], _('include names matching the given patterns')),
|
|
|
|
('X', 'exclude', [], _('exclude names matching the given patterns'))],
|
|
|
|
_('hg remove [OPTION]... FILE...')),
|
|
|
|
"rename|mv":
|
|
|
|
(rename,
|
2006-03-01 11:08:56 +03:00
|
|
|
[('A', 'after', None, _('record a rename that has already occurred')),
|
2006-01-12 09:57:58 +03:00
|
|
|
('f', 'force', None,
|
2006-03-01 11:08:56 +03:00
|
|
|
_('forcibly copy over an existing managed file')),
|
|
|
|
('I', 'include', [], _('include names matching the given patterns')),
|
|
|
|
('X', 'exclude', [], _('exclude names matching the given patterns'))],
|
2006-01-12 09:57:58 +03:00
|
|
|
_('hg rename [OPTION]... [SOURCE]... DEST')),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^revert":
|
|
|
|
(revert,
|
2006-03-01 11:08:56 +03:00
|
|
|
[('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]...')),
|
2006-01-12 09:57:58 +03:00
|
|
|
"root": (root, [], _('hg root')),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^serve":
|
|
|
|
(serve,
|
2005-10-25 02:52:28 +04:00
|
|
|
[('A', 'accesslog', '', _('name of access log file to write to')),
|
2006-02-18 03:29:30 +03:00
|
|
|
('d', 'daemon', None, _('run server in background')),
|
2006-02-18 07:40:08 +03:00
|
|
|
('', 'daemon-pipefds', '', _('used internally by daemon mode')),
|
2005-10-25 02:52:28 +04:00
|
|
|
('E', 'errorlog', '', _('name of error log file to write to')),
|
|
|
|
('p', 'port', 0, _('port to use (default: 8000)')),
|
|
|
|
('a', 'address', '', _('address to use')),
|
2006-01-12 09:57:58 +03:00
|
|
|
('n', 'name', '',
|
2005-12-28 09:27:05 +03:00
|
|
|
_('name to show in web pages (default: working dir)')),
|
2006-02-18 03:29:30 +03:00
|
|
|
('', 'pid-file', '', _('name of file to write process ID to')),
|
2005-10-19 05:38:39 +04:00
|
|
|
('', 'stdio', None, _('for remote clients')),
|
2006-01-12 09:57:58 +03:00
|
|
|
('t', 'templates', '', _('web templates to use')),
|
|
|
|
('', 'style', '', _('template style to use')),
|
2005-10-19 05:38:39 +04:00
|
|
|
('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))],
|
2006-01-12 09:57:58 +03:00
|
|
|
_('hg serve [OPTION]...')),
|
2005-11-04 21:24:05 +03:00
|
|
|
"^status|st":
|
2005-08-06 10:09:10 +04:00
|
|
|
(status,
|
2005-10-19 05:38:39 +04:00
|
|
|
[('m', 'modified', None, _('show only modified files')),
|
|
|
|
('a', 'added', None, _('show only added files')),
|
|
|
|
('r', 'removed', None, _('show only removed files')),
|
2006-01-12 15:58:36 +03:00
|
|
|
('d', 'deleted', None, _('show only deleted (but tracked) files')),
|
2005-10-19 05:38:39 +04:00
|
|
|
('u', 'unknown', None, _('show only unknown (not tracked) files')),
|
|
|
|
('n', 'no-status', None, _('hide status prefix')),
|
2005-12-28 09:27:05 +03:00
|
|
|
('0', 'print0', None,
|
|
|
|
_('end filenames with NUL, for use with xargs')),
|
2005-10-25 02:52:28 +04:00
|
|
|
('I', 'include', [], _('include names matching the given patterns')),
|
|
|
|
('X', 'exclude', [], _('exclude names matching the given patterns'))],
|
2006-01-12 09:57:58 +03:00
|
|
|
_('hg status [OPTION]... [FILE]...')),
|
2005-07-14 13:42:28 +04:00
|
|
|
"tag":
|
|
|
|
(tag,
|
2005-10-19 05:38:39 +04:00
|
|
|
[('l', 'local', None, _('make the tag local')),
|
2006-01-12 09:57:58 +03:00
|
|
|
('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'))],
|
2006-03-01 00:50:49 +03:00
|
|
|
_('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')),
|
2005-10-19 05:38:39 +04:00
|
|
|
"tags": (tags, [], _('hg tags')),
|
2006-02-21 14:59:16 +03:00
|
|
|
"tip":
|
|
|
|
(tip,
|
2006-02-21 15:14:03 +03:00
|
|
|
[('b', 'branches', None, _('show branches')),
|
2006-02-21 14:59:16 +03:00
|
|
|
('p', 'patch', None, _('show patch'))],
|
2006-02-28 02:46:06 +03:00
|
|
|
_('hg tip [-b] [-p]')),
|
2005-09-08 12:27:25 +04:00
|
|
|
"unbundle":
|
|
|
|
(unbundle,
|
2005-12-28 01:18:00 +03:00
|
|
|
[('u', 'update', None,
|
|
|
|
_('update the working directory to tip after unbundle'))],
|
2005-12-28 01:16:06 +03:00
|
|
|
_('hg unbundle [-u] FILE')),
|
2005-10-19 05:38:39 +04:00
|
|
|
"undo": (undo, [], _('hg undo')),
|
2005-07-03 15:58:05 +04:00
|
|
|
"^update|up|checkout|co":
|
2005-07-14 13:42:28 +04:00
|
|
|
(update,
|
2006-01-12 09:57:58 +03:00
|
|
|
[('b', 'branch', '', _('checkout the head of a specific branch')),
|
2005-10-25 02:52:28 +04:00
|
|
|
('m', 'merge', None, _('allow merging of branches')),
|
2005-12-15 07:19:03 +03:00
|
|
|
('C', 'clean', None, _('overwrite locally modified files')),
|
|
|
|
('f', 'force', None, _('force a merge with outstanding changes'))],
|
|
|
|
_('hg update [-b TAG] [-m] [-C] [-f] [REV]')),
|
2005-10-19 05:38:39 +04:00
|
|
|
"verify": (verify, [], _('hg verify')),
|
|
|
|
"version": (show_version, [], _('hg version')),
|
2005-08-25 20:35:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
globalopts = [
|
2006-01-12 09:57:58 +03:00
|
|
|
('R', 'repository', '', _('repository root directory')),
|
|
|
|
('', 'cwd', '', _('change working directory')),
|
2005-12-28 09:27:05 +03:00
|
|
|
('y', 'noninteractive', None,
|
2006-01-12 09:57:58 +03:00
|
|
|
_('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')),
|
2005-08-25 20:35:35 +04:00
|
|
|
]
|
2005-07-03 23:47:45 +04:00
|
|
|
|
2005-09-16 21:42:20 +04:00
|
|
|
norepo = ("clone init version help debugancestor debugconfig debugdata"
|
2005-08-26 17:19:18 +04:00
|
|
|
" debugindex debugindexdot paths")
|
2005-06-01 12:25:42 +04:00
|
|
|
|
2005-06-01 23:11:19 +04:00
|
|
|
def find(cmd):
|
2005-11-07 20:39:25 +03:00
|
|
|
"""Return (aliases, command table entry) for command string."""
|
2006-03-07 10:05:17 +03:00
|
|
|
choice = []
|
2006-03-07 10:46:19 +03:00
|
|
|
debugchoice = []
|
2005-06-01 23:11:19 +04:00
|
|
|
for e in table.keys():
|
2005-11-04 21:22:03 +03:00
|
|
|
aliases = e.lstrip("^").split("|")
|
|
|
|
if cmd in aliases:
|
2005-11-07 20:39:25 +03:00
|
|
|
return aliases, table[e]
|
2005-11-04 21:22:03 +03:00
|
|
|
for a in aliases:
|
|
|
|
if a.startswith(cmd):
|
2006-03-07 10:46:19 +03:00
|
|
|
if aliases[0].startswith("debug"):
|
|
|
|
debugchoice.append([aliases, table[e]])
|
|
|
|
else:
|
|
|
|
choice.append([aliases, table[e]])
|
2006-02-18 02:41:23 +03:00
|
|
|
break
|
|
|
|
|
2006-03-07 10:46:19 +03:00
|
|
|
if not choice and debugchoice:
|
|
|
|
choice = debugchoice
|
|
|
|
|
2006-03-07 10:05:17 +03:00
|
|
|
if len(choice) > 1:
|
2006-03-07 10:41:13 +03:00
|
|
|
clist = []
|
|
|
|
for aliases, table_e in choice:
|
|
|
|
if aliases[0].startswith(cmd):
|
|
|
|
clist.append(aliases[0])
|
|
|
|
for a in aliases[1:]:
|
|
|
|
if a.startswith(cmd) and not aliases[0].startswith(a):
|
|
|
|
clist.append(a)
|
|
|
|
clist.sort()
|
2006-03-07 10:05:17 +03:00
|
|
|
raise AmbiguousCommand(cmd, clist)
|
2006-02-18 02:41:23 +03:00
|
|
|
|
2005-11-07 20:39:25 +03:00
|
|
|
if choice:
|
2006-03-07 10:05:17 +03:00
|
|
|
return choice[0]
|
2005-06-01 23:11:19 +04:00
|
|
|
|
|
|
|
raise UnknownCommand(cmd)
|
|
|
|
|
2005-07-14 13:42:28 +04:00
|
|
|
class SignalInterrupt(Exception):
|
|
|
|
"""Exception raised on SIGTERM and SIGHUP."""
|
2005-06-02 01:04:13 +04:00
|
|
|
|
|
|
|
def catchterm(*args):
|
|
|
|
raise SignalInterrupt
|
|
|
|
|
2005-06-05 02:16:32 +04:00
|
|
|
def run():
|
|
|
|
sys.exit(dispatch(sys.argv[1:]))
|
|
|
|
|
2005-07-14 13:42:28 +04:00
|
|
|
class ParseError(Exception):
|
|
|
|
"""Exception raised on errors in parsing the command line."""
|
2005-07-03 15:33:48 +04:00
|
|
|
|
2005-10-27 03:10:36 +04:00
|
|
|
def parse(ui, args):
|
2005-06-01 12:25:42 +04:00
|
|
|
options = {}
|
2005-07-03 23:47:45 +04:00
|
|
|
cmdoptions = {}
|
2005-06-01 12:25:42 +04:00
|
|
|
|
2005-07-03 15:33:48 +04:00
|
|
|
try:
|
2005-07-03 23:47:45 +04:00
|
|
|
args = fancyopts.fancyopts(args, globalopts, options)
|
2005-07-03 15:33:48 +04:00
|
|
|
except fancyopts.getopt.GetoptError, inst:
|
2005-07-05 00:39:35 +04:00
|
|
|
raise ParseError(None, inst)
|
2005-06-01 12:25:42 +04:00
|
|
|
|
2005-08-26 10:26:21 +04:00
|
|
|
if args:
|
2005-06-01 12:25:42 +04:00
|
|
|
cmd, args = args[0], args[1:]
|
2005-12-01 19:51:33 +03:00
|
|
|
aliases, i = find(cmd)
|
|
|
|
cmd = aliases[0]
|
2005-10-27 03:10:36 +04:00
|
|
|
defaults = ui.config("defaults", cmd)
|
|
|
|
if defaults:
|
2005-11-12 02:32:28 +03:00
|
|
|
args = defaults.split() + args
|
2005-08-26 10:26:21 +04:00
|
|
|
c = list(i[1])
|
|
|
|
else:
|
|
|
|
cmd = None
|
|
|
|
c = []
|
2005-06-01 12:25:42 +04:00
|
|
|
|
2005-07-03 15:33:48 +04:00
|
|
|
# combine global options into local
|
2005-07-03 23:47:45 +04:00
|
|
|
for o in globalopts:
|
2005-07-03 15:33:48 +04:00
|
|
|
c.append((o[0], o[1], options[o[1]], o[3]))
|
2005-06-02 01:04:13 +04:00
|
|
|
|
2005-06-09 08:11:57 +04:00
|
|
|
try:
|
2005-07-03 23:47:45 +04:00
|
|
|
args = fancyopts.fancyopts(args, c, cmdoptions)
|
2005-06-09 08:11:57 +04:00
|
|
|
except fancyopts.getopt.GetoptError, inst:
|
2005-07-03 23:47:45 +04:00
|
|
|
raise ParseError(cmd, inst)
|
2005-06-01 12:25:42 +04:00
|
|
|
|
2005-07-03 15:33:48 +04:00
|
|
|
# separate global options back out
|
2005-07-03 23:47:45 +04:00
|
|
|
for o in globalopts:
|
2005-07-03 15:33:48 +04:00
|
|
|
n = o[1]
|
|
|
|
options[n] = cmdoptions[n]
|
|
|
|
del cmdoptions[n]
|
|
|
|
|
2005-08-26 10:26:21 +04:00
|
|
|
return (cmd, cmd and i[0] or None, args, options, cmdoptions)
|
2005-07-03 23:47:45 +04:00
|
|
|
|
|
|
|
def dispatch(args):
|
|
|
|
signal.signal(signal.SIGTERM, catchterm)
|
2005-07-14 13:42:28 +04:00
|
|
|
try:
|
|
|
|
signal.signal(signal.SIGHUP, catchterm)
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2005-07-03 23:47:45 +04:00
|
|
|
|
2005-10-31 20:57:54 +03:00
|
|
|
try:
|
|
|
|
u = ui.ui()
|
|
|
|
except util.Abort, inst:
|
|
|
|
sys.stderr.write(_("abort: %s\n") % inst)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2005-08-27 01:05:52 +04:00
|
|
|
external = []
|
|
|
|
for x in u.extensions():
|
2005-11-14 18:10:59 +03:00
|
|
|
def on_exception(exc, inst):
|
2005-10-25 01:53:12 +04:00
|
|
|
u.warn(_("*** failed to import extension %s\n") % x[1])
|
|
|
|
u.warn("%s\n" % inst)
|
|
|
|
if "--traceback" in sys.argv[1:]:
|
|
|
|
traceback.print_exc()
|
2005-08-27 01:05:52 +04:00
|
|
|
if x[1]:
|
2005-09-24 06:04:19 +04:00
|
|
|
try:
|
|
|
|
mod = imp.load_source(x[0], x[1])
|
2005-10-25 01:53:12 +04:00
|
|
|
except Exception, inst:
|
|
|
|
on_exception(Exception, inst)
|
2005-09-24 06:04:19 +04:00
|
|
|
continue
|
2005-08-27 01:05:52 +04:00
|
|
|
else:
|
|
|
|
def importh(name):
|
|
|
|
mod = __import__(name)
|
|
|
|
components = name.split('.')
|
|
|
|
for comp in components[1:]:
|
|
|
|
mod = getattr(mod, comp)
|
|
|
|
return mod
|
2005-09-24 06:04:19 +04:00
|
|
|
try:
|
|
|
|
mod = importh(x[0])
|
2005-10-25 01:53:12 +04:00
|
|
|
except Exception, inst:
|
|
|
|
on_exception(Exception, inst)
|
2005-09-24 06:04:19 +04:00
|
|
|
continue
|
|
|
|
|
2005-08-27 01:05:52 +04:00
|
|
|
external.append(mod)
|
|
|
|
for x in external:
|
2005-09-22 01:22:16 +04:00
|
|
|
cmdtable = getattr(x, 'cmdtable', {})
|
|
|
|
for t in cmdtable:
|
2005-08-27 01:05:52 +04:00
|
|
|
if t in table:
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("module %s overrides %s\n") % (x.__name__, t))
|
2005-09-22 01:22:16 +04:00
|
|
|
table.update(cmdtable)
|
2005-08-27 01:05:52 +04:00
|
|
|
|
2005-07-03 23:47:45 +04:00
|
|
|
try:
|
2005-10-27 03:10:36 +04:00
|
|
|
cmd, func, args, options, cmdoptions = parse(u, args)
|
2005-07-03 23:47:45 +04:00
|
|
|
except ParseError, inst:
|
|
|
|
if inst.args[0]:
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1]))
|
2005-07-14 13:42:28 +04:00
|
|
|
help_(u, inst.args[0])
|
2005-07-03 23:47:45 +04:00
|
|
|
else:
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("hg: %s\n") % inst.args[1])
|
2005-08-06 17:04:59 +04:00
|
|
|
help_(u, 'shortlist')
|
2005-07-03 23:47:45 +04:00
|
|
|
sys.exit(-1)
|
2005-11-07 21:00:51 +03:00
|
|
|
except AmbiguousCommand, inst:
|
2006-03-07 10:05:17 +03:00
|
|
|
u.warn(_("hg: command '%s' is ambiguous:\n %s\n") %
|
|
|
|
(inst.args[0], " ".join(inst.args[1])))
|
2005-11-07 21:00:51 +03:00
|
|
|
sys.exit(1)
|
2005-07-03 23:47:45 +04:00
|
|
|
except UnknownCommand, inst:
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("hg: unknown command '%s'\n") % inst.args[0])
|
2005-08-06 17:04:59 +04:00
|
|
|
help_(u, 'shortlist')
|
2005-07-03 23:47:45 +04:00
|
|
|
sys.exit(1)
|
|
|
|
|
2005-07-27 22:18:44 +04:00
|
|
|
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()
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") %
|
2005-07-27 22:18:44 +04:00
|
|
|
(t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
|
|
|
|
atexit.register(print_time)
|
|
|
|
|
2005-08-27 01:05:52 +04:00
|
|
|
u.updateopts(options["verbose"], options["debug"], options["quiet"],
|
2005-07-14 13:42:28 +04:00
|
|
|
not options["noninteractive"])
|
2005-07-03 15:33:48 +04:00
|
|
|
|
2005-09-09 04:09:31 +04:00
|
|
|
# enter the debugger before command execution
|
|
|
|
if options['debugger']:
|
|
|
|
pdb.set_trace()
|
|
|
|
|
2005-06-01 12:25:42 +04:00
|
|
|
try:
|
2005-06-30 02:20:54 +04:00
|
|
|
try:
|
2005-08-26 10:37:41 +04:00
|
|
|
if options['help']:
|
2005-08-26 10:42:56 +04:00
|
|
|
help_(u, cmd, options['version'])
|
2005-08-26 10:37:41 +04:00
|
|
|
sys.exit(0)
|
|
|
|
elif options['version']:
|
2005-08-26 10:26:21 +04:00
|
|
|
show_version(u)
|
|
|
|
sys.exit(0)
|
|
|
|
elif not cmd:
|
|
|
|
help_(u, 'shortlist')
|
|
|
|
sys.exit(0)
|
|
|
|
|
2005-08-26 10:47:43 +04:00
|
|
|
if options['cwd']:
|
|
|
|
try:
|
|
|
|
os.chdir(options['cwd'])
|
|
|
|
except OSError, inst:
|
2005-09-09 22:34:34 +04:00
|
|
|
raise util.Abort('%s: %s' %
|
|
|
|
(options['cwd'], inst.strerror))
|
2005-08-26 10:47:43 +04:00
|
|
|
|
2005-06-30 02:20:54 +04:00
|
|
|
if cmd not in norepo.split():
|
|
|
|
path = options["repository"] or ""
|
2006-03-06 19:47:41 +03:00
|
|
|
repo = hg.repository(u, path=path)
|
|
|
|
u = repo.ui
|
2005-08-27 01:05:52 +04:00
|
|
|
for x in external:
|
2006-01-12 09:57:58 +03:00
|
|
|
if hasattr(x, 'reposetup'):
|
|
|
|
x.reposetup(u, repo)
|
2005-07-03 23:47:45 +04:00
|
|
|
d = lambda: func(u, repo, *args, **cmdoptions)
|
2005-06-30 02:20:54 +04:00
|
|
|
else:
|
2005-07-03 23:47:45 +04:00
|
|
|
d = lambda: func(u, *args, **cmdoptions)
|
2005-06-30 02:20:54 +04:00
|
|
|
|
2006-03-06 19:35:15 +03:00
|
|
|
try:
|
|
|
|
if options['profile']:
|
|
|
|
import hotshot, hotshot.stats
|
|
|
|
prof = hotshot.Profile("hg.prof")
|
2006-03-04 00:11:25 +03:00
|
|
|
try:
|
|
|
|
try:
|
2006-03-06 19:35:15 +03:00
|
|
|
return prof.runcall(d)
|
2006-03-04 00:11:25 +03:00
|
|
|
except:
|
2006-03-06 19:35:15 +03:00
|
|
|
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()
|
2005-06-30 02:20:54 +04:00
|
|
|
except:
|
2005-09-09 04:09:31 +04:00
|
|
|
# enter the debugger when we hit an exception
|
|
|
|
if options['debugger']:
|
|
|
|
pdb.post_mortem(sys.exc_info()[2])
|
2005-06-30 02:20:54 +04:00
|
|
|
if options['traceback']:
|
|
|
|
traceback.print_exc()
|
|
|
|
raise
|
2005-06-28 12:55:59 +04:00
|
|
|
except hg.RepoError, inst:
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("abort: "), inst, "!\n")
|
2005-09-08 10:38:28 +04:00
|
|
|
except revlog.RevlogError, inst:
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("abort: "), inst, "!\n")
|
2005-06-02 01:04:13 +04:00
|
|
|
except SignalInterrupt:
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("killed!\n"))
|
2005-06-01 12:25:42 +04:00
|
|
|
except KeyboardInterrupt:
|
2005-08-04 21:06:49 +04:00
|
|
|
try:
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("interrupted!\n"))
|
2005-08-04 21:06:49 +04:00
|
|
|
except IOError, inst:
|
|
|
|
if inst.errno == errno.EPIPE:
|
|
|
|
if u.debugflag:
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("\nbroken pipe\n"))
|
2005-08-04 21:06:49 +04:00
|
|
|
else:
|
|
|
|
raise
|
2005-06-05 02:25:08 +04:00
|
|
|
except IOError, inst:
|
2005-06-17 23:03:44 +04:00
|
|
|
if hasattr(inst, "code"):
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("abort: %s\n") % inst)
|
2005-06-17 23:03:44 +04:00
|
|
|
elif hasattr(inst, "reason"):
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("abort: error: %s\n") % inst.reason[1])
|
2005-06-17 23:03:44 +04:00
|
|
|
elif hasattr(inst, "args") and inst[0] == errno.EPIPE:
|
2005-08-26 17:19:18 +04:00
|
|
|
if u.debugflag:
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("broken pipe\n"))
|
2005-09-27 01:01:18 +04:00
|
|
|
elif getattr(inst, "strerror", None):
|
2005-09-28 01:58:48 +04:00
|
|
|
if getattr(inst, "filename", None):
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename))
|
2005-09-28 01:58:48 +04:00
|
|
|
else:
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("abort: %s\n") % inst.strerror)
|
2005-06-05 02:25:08 +04:00
|
|
|
else:
|
|
|
|
raise
|
2005-07-01 11:45:43 +04:00
|
|
|
except OSError, inst:
|
|
|
|
if hasattr(inst, "filename"):
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
|
2005-07-01 11:45:43 +04:00
|
|
|
else:
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("abort: %s\n") % inst.strerror)
|
2005-08-08 00:43:11 +04:00
|
|
|
except util.Abort, inst:
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n')
|
2005-07-19 19:42:36 +04:00
|
|
|
sys.exit(1)
|
2005-06-01 23:11:19 +04:00
|
|
|
except TypeError, inst:
|
|
|
|
# was this an argument error?
|
|
|
|
tb = traceback.extract_tb(sys.exc_info()[2])
|
|
|
|
if len(tb) > 2: # no
|
|
|
|
raise
|
2005-06-09 08:11:57 +04:00
|
|
|
u.debug(inst, "\n")
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("%s: invalid arguments\n") % cmd)
|
2005-07-14 13:42:28 +04:00
|
|
|
help_(u, cmd)
|
2005-11-10 18:16:28 +03:00
|
|
|
except AmbiguousCommand, inst:
|
2006-03-07 10:05:17 +03:00
|
|
|
u.warn(_("hg: command '%s' is ambiguous:\n %s\n") %
|
|
|
|
(inst.args[0], " ".join(inst.args[1])))
|
2005-11-10 18:16:28 +03:00
|
|
|
help_(u, 'shortlist')
|
2005-08-06 17:04:59 +04:00
|
|
|
except UnknownCommand, inst:
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("hg: unknown command '%s'\n") % inst.args[0])
|
2005-08-06 17:04:59 +04:00
|
|
|
help_(u, 'shortlist')
|
2005-09-08 10:57:59 +04:00
|
|
|
except SystemExit:
|
2005-09-09 22:47:13 +04:00
|
|
|
# don't catch this in the catch-all below
|
2005-09-08 10:57:59 +04:00
|
|
|
raise
|
|
|
|
except:
|
2005-10-19 05:38:39 +04:00
|
|
|
u.warn(_("** unknown exception encountered, details follow\n"))
|
|
|
|
u.warn(_("** report bug details to mercurial@selenic.com\n"))
|
2005-11-16 21:19:39 +03:00
|
|
|
u.warn(_("** Mercurial Distributed SCM (version %s)\n")
|
|
|
|
% version.get_version())
|
2005-09-08 10:57:59 +04:00
|
|
|
raise
|
2005-06-28 14:08:14 +04:00
|
|
|
|
|
|
|
sys.exit(-1)
|