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-07-14 18:30:49 +04:00
|
|
|
demandload(globals(), "os re sys signal shutil")
|
2005-08-17 02:53:47 +04:00
|
|
|
demandload(globals(), "fancyopts ui hg util lock")
|
2005-07-06 06:19:01 +04:00
|
|
|
demandload(globals(), "fnmatch hgweb mdiff random signal time traceback")
|
2005-08-26 13:03:35 +04:00
|
|
|
demandload(globals(), "errno socket version struct atexit sets")
|
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-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-08-26 15:06:58 +04:00
|
|
|
def matchpats(repo, cwd, pats=[], opts={}, head=''):
|
2005-08-08 00:43:11 +04:00
|
|
|
return util.matcher(repo, cwd, pats or ['.'], opts.get('include'),
|
2005-07-21 21:21:33 +04:00
|
|
|
opts.get('exclude'), head)
|
|
|
|
|
2005-08-26 15:06:58 +04:00
|
|
|
def makewalk(repo, pats, opts, head=''):
|
2005-07-18 18:54:21 +04:00
|
|
|
cwd = repo.getcwd()
|
2005-08-24 23:39:10 +04:00
|
|
|
files, matchfn, anypats = matchpats(repo, cwd, 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-08-26 15:06:58 +04:00
|
|
|
for src, fn in repo.walk(files=files, match=matchfn):
|
2005-08-19 01:58:32 +04:00
|
|
|
yield src, fn, util.pathto(cwd, fn), fn in exact
|
2005-08-03 21:10:48 +04:00
|
|
|
return files, matchfn, walk()
|
|
|
|
|
2005-08-26 15:06:58 +04:00
|
|
|
def walk(repo, pats, opts, head=''):
|
2005-08-03 21:10:48 +04:00
|
|
|
files, matchfn, results = makewalk(repo, pats, opts, head)
|
2005-08-26 17:19:18 +04:00
|
|
|
for r in results:
|
|
|
|
yield r
|
2005-07-18 18:54:21 +04:00
|
|
|
|
2005-08-25 13:00:03 +04:00
|
|
|
def walkchangerevs(ui, repo, cwd, pats, opts):
|
|
|
|
# This code most commonly needs 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. Walk forwards through a window of revisions,
|
|
|
|
# yielding them in the desired order, and walk the windows
|
|
|
|
# themselves backwards.
|
|
|
|
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']]
|
|
|
|
files, matchfn, anypats = matchpats(repo, (pats and cwd) or '',
|
|
|
|
pats, opts)
|
|
|
|
revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0']))
|
|
|
|
wanted = {}
|
|
|
|
slowpath = anypats
|
|
|
|
window = 300
|
|
|
|
fncache = {}
|
|
|
|
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):
|
|
|
|
for i in xrange(filelog.count() - 1, -1, -window):
|
|
|
|
revs = []
|
|
|
|
for j in xrange(max(0, i - window), i + 1):
|
|
|
|
revs.append(filelog.linkrev(filelog.node(j)))
|
|
|
|
revs.reverse()
|
|
|
|
for rev in revs:
|
|
|
|
yield rev
|
|
|
|
|
|
|
|
minrev, maxrev = min(revs), max(revs)
|
|
|
|
for file in files:
|
|
|
|
filelog = repo.file(file)
|
|
|
|
# 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, [])
|
|
|
|
fncache[rev].append(file)
|
|
|
|
wanted[rev] = 1
|
|
|
|
if slowpath:
|
|
|
|
# The slow path checks files modified in every changeset.
|
|
|
|
def changerevgen():
|
|
|
|
for i in xrange(repo.changelog.count() - 1, -1, -window):
|
|
|
|
for j in xrange(max(0, i - window), i + 1):
|
|
|
|
yield j, repo.changelog.read(repo.lookup(str(j)))[3]
|
|
|
|
|
|
|
|
for rev, changefiles in changerevgen():
|
|
|
|
matches = filter(matchfn, changefiles)
|
|
|
|
if matches:
|
|
|
|
fncache[rev] = matches
|
|
|
|
wanted[rev] = 1
|
|
|
|
|
|
|
|
for i in xrange(0, len(revs), window):
|
|
|
|
yield 'window', revs[0] < revs[-1], revs[-1]
|
2005-08-26 17:19:18 +04:00
|
|
|
nrevs = [rev for rev in revs[i:min(i+window, len(revs))]
|
2005-08-25 13:00:03 +04:00
|
|
|
if rev in wanted]
|
|
|
|
srevs = list(nrevs)
|
|
|
|
srevs.sort()
|
|
|
|
for rev in srevs:
|
|
|
|
fns = fncache.get(rev)
|
|
|
|
if not fns:
|
|
|
|
fns = repo.changelog.read(repo.lookup(str(rev)))[3]
|
|
|
|
fns = filter(matchfn, fns)
|
|
|
|
yield 'add', rev, fns
|
|
|
|
for rev in nrevs:
|
|
|
|
yield 'iter', rev, None
|
|
|
|
|
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
|
|
|
|
if num < 0:
|
|
|
|
num += revcount
|
2005-07-03 06:29:54 +04:00
|
|
|
if not (0 <= num < revcount):
|
|
|
|
raise ValueError
|
|
|
|
except ValueError:
|
|
|
|
try:
|
|
|
|
num = repo.changelog.rev(repo.lookup(val))
|
|
|
|
except KeyError:
|
|
|
|
try:
|
|
|
|
num = revlog.rev(revlog.lookup(val))
|
|
|
|
except KeyError:
|
2005-08-08 00:43:11 +04:00
|
|
|
raise util.Abort('invalid revision identifier %s', val)
|
2005-07-03 06:29:54 +04:00
|
|
|
return num
|
|
|
|
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):
|
2005-07-03 06:29:54 +04:00
|
|
|
yield str(rev)
|
|
|
|
else:
|
2005-08-24 23:39:10 +04:00
|
|
|
yield str(fix(spec, None))
|
2005-07-03 06:29:54 +04:00
|
|
|
|
2005-07-20 16:08:11 +04:00
|
|
|
def make_filename(repo, r, pat, node=None,
|
|
|
|
total=None, seqno=None, revwidth=None):
|
2005-07-06 06:23:56 +04:00
|
|
|
node_expander = {
|
|
|
|
'H': lambda: hg.hex(node),
|
|
|
|
'R': lambda: str(r.rev(node)),
|
|
|
|
'h': lambda: hg.short(node),
|
|
|
|
}
|
|
|
|
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)))
|
|
|
|
|
|
|
|
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-08-08 00:43:11 +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,
|
|
|
|
total=None, seqno=None, revwidth=None, mode='wb'):
|
|
|
|
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
|
|
|
|
return open(make_filename(repo, r, pat, node, total, seqno, revwidth),
|
|
|
|
mode)
|
|
|
|
|
2005-08-24 05:58:26 +04:00
|
|
|
def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always,
|
2005-08-24 06:58:46 +04:00
|
|
|
changes=None, text=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
|
|
|
def date(c):
|
|
|
|
return time.asctime(time.gmtime(float(c[2].split(' ')[0])))
|
|
|
|
|
2005-08-15 08:09:32 +04:00
|
|
|
if not changes:
|
2005-08-26 15:06:58 +04:00
|
|
|
(c, a, d, u) = repo.changes(node1, node2, files, match=match)
|
2005-08-15 08:09:32 +04:00
|
|
|
else:
|
|
|
|
(c, a, d, u) = changes
|
2005-07-01 09:28:18 +04:00
|
|
|
if files:
|
|
|
|
c, a, d = map(lambda x: filterfiles(files, x), (c, a, d))
|
|
|
|
|
|
|
|
if not c and not a and not d:
|
|
|
|
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])
|
|
|
|
date2 = date(change)
|
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:
|
|
|
|
date2 = time.asctime()
|
|
|
|
if not node1:
|
|
|
|
node1 = repo.dirstate.parents()[0]
|
2005-07-14 13:42:28 +04:00
|
|
|
def read(f):
|
|
|
|
return repo.wfile(f).read()
|
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:
|
|
|
|
hexfunc = ui.verbose and hg.hex or hg.short
|
|
|
|
r = [hexfunc(node) for node in [node1, node2] if node]
|
|
|
|
|
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
|
|
|
change = repo.changelog.read(node1)
|
|
|
|
mmap = repo.manifest.read(change[0])
|
|
|
|
date1 = date(change)
|
|
|
|
|
|
|
|
for f in c:
|
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)
|
2005-08-24 06:58:46 +04:00
|
|
|
fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text))
|
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 f in a:
|
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)
|
2005-08-24 06:58:46 +04:00
|
|
|
fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text))
|
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 f in d:
|
|
|
|
to = repo.file(f).read(mmap[f])
|
2005-06-06 22:51:09 +04:00
|
|
|
tn = None
|
2005-08-24 06:58:46 +04:00
|
|
|
fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text))
|
2005-06-13 11:49:21 +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-24 23:39:10 +04:00
|
|
|
ui.write("%d:%s\n" % (rev, hg.short(changenode)))
|
2005-06-13 11:49:21 +04:00
|
|
|
return
|
|
|
|
|
2005-08-24 23:39:10 +04:00
|
|
|
changes = log.read(changenode)
|
2005-06-13 11:49:21 +04:00
|
|
|
|
2005-08-20 11:23:42 +04:00
|
|
|
t, tz = changes[2].split(' ')
|
2005-08-20 22:59:10 +04:00
|
|
|
# a conversion tool was sticking non-integer offsets into repos
|
|
|
|
try:
|
|
|
|
tz = int(tz)
|
|
|
|
except ValueError:
|
|
|
|
tz = 0
|
2005-08-20 11:23:42 +04:00
|
|
|
date = time.asctime(time.localtime(float(t))) + " %+05d" % (int(tz)/-36)
|
|
|
|
|
2005-07-27 20:14:52 +04:00
|
|
|
parents = [(log.rev(p), ui.verbose and hg.hex(p) or hg.short(p))
|
2005-08-24 23:39:10 +04:00
|
|
|
for p in log.parents(changenode)
|
2005-07-27 20:14:52 +04:00
|
|
|
if ui.debugflag or p != hg.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-08-24 23:39:10 +04:00
|
|
|
ui.write("changeset: %d:%s\n" % (rev, hg.hex(changenode)))
|
2005-07-27 20:14:52 +04:00
|
|
|
else:
|
2005-08-24 23:39:10 +04:00
|
|
|
ui.write("changeset: %d:%s\n" % (rev, hg.short(changenode)))
|
2005-07-27 20:14:52 +04:00
|
|
|
|
2005-07-13 08:55:42 +04:00
|
|
|
for tag in repo.nodetags(changenode):
|
|
|
|
ui.status("tag: %s\n" % tag)
|
|
|
|
for parent in parents:
|
|
|
|
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]
|
|
|
|
ui.write("branch: %s\n" % " ".join(br))
|
|
|
|
|
2005-07-27 20:14:52 +04:00
|
|
|
ui.debug("manifest: %d:%s\n" % (repo.manifest.rev(changes[0]),
|
2005-07-13 08:55:42 +04:00
|
|
|
hg.hex(changes[0])))
|
2005-06-13 11:49:21 +04:00
|
|
|
ui.status("user: %s\n" % changes[1])
|
2005-08-20 11:23:42 +04:00
|
|
|
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-06-27 09:17:28 +04:00
|
|
|
for key, value in zip(["files:", "files+:", "files-:"], files):
|
|
|
|
if value:
|
|
|
|
ui.note("%-12s %s\n" % (key, " ".join(value)))
|
2005-06-28 09:50:28 +04:00
|
|
|
else:
|
|
|
|
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:
|
|
|
|
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-06-14 11:01:18 +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-08-06 18:43:12 +04:00
|
|
|
ui.write("Mercurial Distributed SCM (version %s)\n"
|
|
|
|
% version.get_version())
|
2005-06-18 19:32:41 +04:00
|
|
|
ui.status(
|
|
|
|
"\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-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-08-06 18:43:12 +04:00
|
|
|
key, i = find(cmd)
|
|
|
|
# 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__
|
|
|
|
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-08-06 18:43:12 +04:00
|
|
|
aliases = ', '.join(key.split('|')[1:])
|
|
|
|
if aliases:
|
|
|
|
ui.write("\naliases: %s\n" % aliases)
|
|
|
|
|
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-08-06 18:43:12 +04:00
|
|
|
ui.status("Mercurial Distributed SCM\n")
|
|
|
|
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-08-06 18:43:12 +04:00
|
|
|
ui.status('basic commands (use "hg help" '
|
|
|
|
'for the full list or option "-v" for details):\n\n')
|
|
|
|
elif ui.verbose:
|
|
|
|
ui.status('list of commands:\n\n')
|
|
|
|
else:
|
|
|
|
ui.status('list of commands (use "hg help -v" '
|
|
|
|
'to show aliases and global options):\n\n')
|
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
|
2005-06-05 07:09:00 +04:00
|
|
|
d = ""
|
2005-06-25 12:16:39 +04:00
|
|
|
if e[0].__doc__:
|
|
|
|
d = e[0].__doc__.splitlines(0)[0].rstrip()
|
|
|
|
h[f] = d
|
2005-08-06 16:27:31 +04: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("|",", ")
|
|
|
|
ui.write(" %s:\n %s\n"%(commands,h[f]))
|
|
|
|
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,
|
|
|
|
default and " (default: %s)" % default
|
|
|
|
or "")))
|
|
|
|
|
|
|
|
if opt_output:
|
|
|
|
opts_len = max([len(line[0]) for line in opt_output if line[1]])
|
|
|
|
for first, second in opt_output:
|
|
|
|
if second:
|
|
|
|
ui.write(" %-*s %s\n" % (opts_len, first, second))
|
|
|
|
else:
|
|
|
|
ui.write("%s\n" % first)
|
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):
|
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
|
|
|
'''add the specified files on the next commit'''
|
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:
|
2005-07-18 18:54:21 +04:00
|
|
|
names.append(abs)
|
|
|
|
elif repo.dirstate.state(abs) == '?':
|
|
|
|
ui.status('adding %s\n' % rel)
|
|
|
|
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-06-05 07:09:00 +04:00
|
|
|
"""add all new files, delete all missing files"""
|
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-08-26 17:19:18 +04:00
|
|
|
if not exact:
|
|
|
|
ui.status('adding ', rel, '\n')
|
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-08-26 17:19:18 +04:00
|
|
|
if not exact:
|
|
|
|
ui.status('removing ', rel, '\n')
|
2005-07-29 20:42:28 +04:00
|
|
|
repo.add(add)
|
|
|
|
repo.remove(remove)
|
2005-06-01 12:25:42 +04:00
|
|
|
|
2005-07-20 15:23:12 +04:00
|
|
|
def annotate(ui, repo, *pats, **opts):
|
2005-06-05 07:09:00 +04:00
|
|
|
"""show changeset information per file line"""
|
2005-06-01 12:25:42 +04:00
|
|
|
def getnode(rev):
|
|
|
|
return hg.short(repo.changelog.node(rev))
|
|
|
|
|
|
|
|
def getname(rev):
|
|
|
|
try:
|
|
|
|
return bcache[rev]
|
|
|
|
except KeyError:
|
|
|
|
cl = repo.changelog.read(repo.changelog.node(rev))
|
|
|
|
name = cl[1]
|
|
|
|
f = name.find('@')
|
|
|
|
if f >= 0:
|
|
|
|
name = name[:f]
|
2005-06-30 21:22:59 +04:00
|
|
|
f = name.find('<')
|
|
|
|
if f >= 0:
|
|
|
|
name = name[f+1:]
|
2005-06-01 12:25:42 +04:00
|
|
|
bcache[rev] = name
|
|
|
|
return name
|
2005-06-28 12:59:59 +04:00
|
|
|
|
2005-07-21 21:22:54 +04:00
|
|
|
if not pats:
|
2005-08-08 00:43:11 +04:00
|
|
|
raise util.Abort('at least one file name or pattern required')
|
2005-07-21 21:22:54 +04:00
|
|
|
|
2005-06-01 12:25:42 +04:00
|
|
|
bcache = {}
|
|
|
|
opmap = [['user', getname], ['number', str], ['changeset', getnode]]
|
2005-07-16 10:56:39 +04:00
|
|
|
if not opts['user'] and not opts['changeset']:
|
|
|
|
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
|
|
|
|
2005-08-19 01:58:32 +04:00
|
|
|
for src, abs, rel, exact in walk(repo, pats, opts):
|
2005-07-23 23:11:49 +04:00
|
|
|
if abs not in mmap:
|
|
|
|
ui.warn("warning: %s is not in the repository!\n" % rel)
|
|
|
|
continue
|
|
|
|
|
2005-08-24 07:21:52 +04:00
|
|
|
f = repo.file(abs)
|
|
|
|
if not opts['text'] and util.binary(f.read(mmap[abs])):
|
|
|
|
ui.write("%s: binary file\n" % rel)
|
|
|
|
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-07-14 13:42:28 +04:00
|
|
|
def cat(ui, repo, file1, rev=None, **opts):
|
2005-06-05 07:09:00 +04:00
|
|
|
"""output the latest or given revision of a file"""
|
2005-07-14 13:42:28 +04:00
|
|
|
r = repo.file(relpath(repo, [file1])[0])
|
|
|
|
if rev:
|
2005-08-17 03:22:44 +04:00
|
|
|
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, [file1])[0]]
|
|
|
|
except hg.RepoError, KeyError:
|
|
|
|
n = r.lookup(rev)
|
2005-07-14 13:42:28 +04:00
|
|
|
else:
|
|
|
|
n = r.tip()
|
2005-07-20 14:48:16 +04:00
|
|
|
fp = make_file(repo, r, opts['output'], node=n)
|
2005-07-06 06:23:56 +04:00
|
|
|
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-06-27 03:20:46 +04:00
|
|
|
"""make a copy of an existing repository"""
|
|
|
|
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):
|
|
|
|
ui.warn("abort: destination '%s' already exists\n" % dest)
|
|
|
|
return 1
|
2005-06-30 02:04:56 +04:00
|
|
|
|
2005-08-14 02:41:51 +04:00
|
|
|
dest = os.path.realpath(dest)
|
|
|
|
|
2005-07-14 13:42:28 +04:00
|
|
|
class Dircleanup:
|
|
|
|
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-07-14 13:42:28 +04:00
|
|
|
d = Dircleanup(dest)
|
2005-07-07 10:14:10 +04:00
|
|
|
source = ui.expandpath(source)
|
2005-08-20 10:48:43 +04:00
|
|
|
abspath = source
|
2005-07-07 10:14:10 +04:00
|
|
|
other = hg.repository(ui, source)
|
|
|
|
|
2005-07-11 04:15:20 +04:00
|
|
|
if other.dev() != -1:
|
|
|
|
abspath = os.path.abspath(source)
|
2005-07-14 18:30:49 +04:00
|
|
|
copyfile = (os.stat(dest).st_dev == other.dev()
|
|
|
|
and getattr(os, 'link', None) or shutil.copy2)
|
|
|
|
if copyfile is not shutil.copy2:
|
|
|
|
ui.note("cloning by hardlink\n")
|
2005-08-17 02:53:47 +04:00
|
|
|
# we use a lock here because because we're not nicely ordered
|
|
|
|
l = lock.lock(os.path.join(source, ".hg", "lock"))
|
|
|
|
|
2005-07-14 18:30:49 +04:00
|
|
|
util.copytree(os.path.join(source, ".hg"), os.path.join(dest, ".hg"),
|
|
|
|
copyfile)
|
2005-06-30 22:07:50 +04:00
|
|
|
try:
|
2005-07-14 13:42:28 +04:00
|
|
|
os.unlink(os.path.join(dest, ".hg", "dirstate"))
|
2005-07-23 19:14:42 +04:00
|
|
|
except OSError:
|
2005-07-14 13:42:28 +04:00
|
|
|
pass
|
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:
|
|
|
|
repo = hg.repository(ui, dest, create=1)
|
2005-07-06 06:12:57 +04:00
|
|
|
repo.pull(other)
|
2005-06-28 12:59:59 +04:00
|
|
|
|
2005-06-30 22:07:50 +04:00
|
|
|
f = repo.opener("hgrc", "w")
|
|
|
|
f.write("[paths]\n")
|
2005-07-01 23:49:58 +04:00
|
|
|
f.write("default = %s\n" % abspath)
|
2005-06-28 12:59:59 +04:00
|
|
|
|
2005-06-30 22:07:50 +04:00
|
|
|
if not opts['noupdate']:
|
|
|
|
update(ui, repo)
|
|
|
|
|
|
|
|
d.close()
|
2005-06-29 22:42:35 +04:00
|
|
|
|
2005-07-30 03:02:27 +04:00
|
|
|
def commit(ui, repo, *pats, **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
|
|
|
"""commit the specified files or all outstanding changes"""
|
2005-07-22 19:27:30 +04:00
|
|
|
if opts['text']:
|
|
|
|
ui.warn("Warning: -t and --text is deprecated,"
|
|
|
|
" please use -m or --message instead.\n")
|
2005-07-22 19:26:46 +04:00
|
|
|
message = opts['message'] or opts['text']
|
2005-07-14 13:42:28 +04:00
|
|
|
logfile = opts['logfile']
|
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-07-14 13:42:28 +04:00
|
|
|
except IOError, why:
|
2005-07-22 19:26:46 +04:00
|
|
|
ui.warn("Can't read commit message %s: %s\n" % (logfile, why))
|
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)
|
|
|
|
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']]
|
2005-08-24 23:39:10 +04:00
|
|
|
fns, match, anypats = matchpats(repo, (pats and repo.getcwd()) or '',
|
|
|
|
pats, opts)
|
2005-07-30 03:02:27 +04:00
|
|
|
if pats:
|
2005-08-26 15:06:58 +04:00
|
|
|
c, a, d, u = repo.changes(files=fns, match=match)
|
2005-07-30 03:02:27 +04:00
|
|
|
files = c + a + [fn for fn in d if repo.dirstate.state(fn) == 'r']
|
|
|
|
else:
|
|
|
|
files = []
|
|
|
|
repo.commit(files, message, opts['user'], opts['date'], match)
|
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-16 03:57:07 +04:00
|
|
|
def copy(ui, repo, source, dest):
|
|
|
|
"""mark a file as copied or renamed for the next commit"""
|
|
|
|
return repo.copy(*relpath(repo, (source, dest)))
|
|
|
|
|
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-07-03 06:57:59 +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-07-03 06:57:59 +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-07-03 06:57:59 +04:00
|
|
|
ui.warn("%s in state %s, but not in either manifest\n" %
|
|
|
|
(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-07-03 06:57:59 +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-08-08 00:43:11 +04:00
|
|
|
raise util.Abort(".hg/dirstate inconsistent with current parent's manifest")
|
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)
|
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-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-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"""
|
|
|
|
r = hg.revlog(hg.opener(""), file_[:-2] + ".i", file_)
|
|
|
|
ui.write(r.revision(r.lookup(rev)))
|
|
|
|
|
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"""
|
2005-07-14 13:42:28 +04:00
|
|
|
r = hg.revlog(hg.opener(""), 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-22 03:51:50 +04:00
|
|
|
hg.short(e[6]), hg.short(e[4]), hg.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"""
|
2005-07-14 13:42:28 +04:00
|
|
|
r = hg.revlog(hg.opener(""), 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-06-05 01:45:31 +04:00
|
|
|
if e[5] != hg.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
|
|
|
|
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-08-25 21:11:54 +04:00
|
|
|
fmt = '%%s %%-%ds %%-%ds %%s\n' % (
|
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-08-26 17:19:18 +04:00
|
|
|
ui.write(fmt % (src, abs, rel, exact and 'exact' or ''))
|
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-06-05 07:09:00 +04:00
|
|
|
"""diff working directory (or selected files)"""
|
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-08-08 00:43:11 +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
|
|
|
|
2005-07-20 15:16:20 +04:00
|
|
|
files = []
|
2005-08-12 19:10:21 +04:00
|
|
|
match = util.always
|
|
|
|
if pats:
|
|
|
|
roots, match, results = makewalk(repo, pats, opts)
|
2005-08-19 01:58:32 +04:00
|
|
|
for src, abs, rel, exact in results:
|
2005-08-12 19:10:21 +04:00
|
|
|
files.append(abs)
|
2005-08-24 05:58:26 +04:00
|
|
|
|
2005-08-24 06:58:46 +04:00
|
|
|
dodiff(sys.stdout, ui, repo, node1, node2, files, match=match,
|
|
|
|
text=opts['text'])
|
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)
|
|
|
|
prev, other = repo.changelog.parents(node)
|
|
|
|
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])
|
|
|
|
fp.write("# Node ID %s\n" % hg.hex(node))
|
|
|
|
fp.write("# Parent %s\n" % hg.hex(prev))
|
2005-07-03 06:29:54 +04:00
|
|
|
if other != hg.nullid:
|
2005-07-03 06:57:59 +04:00
|
|
|
fp.write("# Parent %s\n" % hg.hex(other))
|
|
|
|
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):
|
|
|
|
"""dump the header and diffs for one or more changesets"""
|
2005-07-04 23:06:01 +04:00
|
|
|
if not changesets:
|
2005-08-08 00:43:11 +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-07-22 10:42:47 +04:00
|
|
|
ui.note(len(revs) > 1 and "Exporting patches:\n" or "Exporting patch:\n")
|
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):
|
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
|
|
|
"""don't add the specified files on 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-08-26 17:19:18 +04:00
|
|
|
if not exact:
|
|
|
|
ui.status('forgetting ', rel, '\n')
|
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-26 15:06:58 +04:00
|
|
|
def grep(ui, repo, pattern=None, *pats, **opts):
|
2005-08-26 12:56:49 +04:00
|
|
|
"""search for a pattern in specified files and revisions"""
|
2005-08-26 17:19:18 +04:00
|
|
|
if pattern is None:
|
|
|
|
pattern = opts['regexp']
|
|
|
|
if not pattern:
|
|
|
|
raise util.Abort('no pattern to search for')
|
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)
|
|
|
|
sep, end = ':', '\n'
|
2005-08-26 17:19:18 +04:00
|
|
|
if opts['null'] or opts['print0']:
|
|
|
|
sep = end = '\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
|
|
|
|
|
|
|
class linestate:
|
|
|
|
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
|
|
|
|
|
|
|
|
prev = {}
|
|
|
|
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))
|
|
|
|
for l in diff:
|
|
|
|
if incrementing:
|
|
|
|
change = ((l in prevstates) and '-') or '+'
|
|
|
|
r = rev
|
|
|
|
else:
|
|
|
|
change = ((l in states) and '-') or '+'
|
|
|
|
r = prev[fn]
|
|
|
|
ui.write('%s:%s:%s:%s%s\n' % (fn, r, l.linenum, change, l.line))
|
|
|
|
|
|
|
|
fstate = {}
|
|
|
|
for st, rev, fns in walkchangerevs(ui, repo, repo.getcwd(), pats, opts):
|
|
|
|
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:
|
|
|
|
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:
|
|
|
|
if incrementing or fstate[fn]:
|
|
|
|
display(fn, rev, m, fstate[fn])
|
|
|
|
fstate[fn] = m
|
|
|
|
prev[fn] = rev
|
|
|
|
|
|
|
|
if not incrementing:
|
|
|
|
fstate = fstate.items()
|
|
|
|
fstate.sort()
|
|
|
|
for fn, state in fstate:
|
|
|
|
display(fn, rev, {}, state)
|
|
|
|
|
2005-08-15 00:23:45 +04:00
|
|
|
def heads(ui, repo, **opts):
|
2005-06-13 11:49:21 +04:00
|
|
|
"""show current repository heads"""
|
2005-08-15 00:23:45 +04:00
|
|
|
heads = repo.changelog.heads()
|
|
|
|
br = None
|
|
|
|
if opts['branches']:
|
|
|
|
br = repo.branchlookup(heads)
|
2005-06-03 06:07:01 +04:00
|
|
|
for n in repo.changelog.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):
|
|
|
|
"""print information about the working copy"""
|
2005-06-15 12:08:03 +04:00
|
|
|
parents = [p for p in repo.dirstate.parents() if p != hg.nullid]
|
2005-06-15 10:07:05 +04:00
|
|
|
if not parents:
|
2005-06-15 12:08:03 +04:00
|
|
|
ui.write("unknown\n")
|
2005-06-15 10:07:05 +04:00
|
|
|
return
|
|
|
|
|
2005-06-17 13:19:43 +04:00
|
|
|
hexfunc = ui.verbose and hg.hex or hg.short
|
2005-07-17 03:13:40 +04:00
|
|
|
(c, a, d, u) = repo.changes()
|
2005-06-17 13:19:43 +04:00
|
|
|
output = ["%s%s" % ('+'.join([hexfunc(parent) for parent in parents]),
|
|
|
|
(c or a or d) and "+" or "")]
|
|
|
|
|
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):
|
|
|
|
"""import an ordered set of patches"""
|
|
|
|
patches = (patch1,) + patches
|
2005-06-28 12:59:59 +04:00
|
|
|
|
2005-08-20 11:07:31 +04:00
|
|
|
if not opts['force']:
|
|
|
|
(c, a, d, u) = repo.changes()
|
|
|
|
if c or a or d:
|
|
|
|
ui.warn("abort: outstanding uncommitted changes!\n")
|
|
|
|
return 1
|
|
|
|
|
2005-06-23 10:31:25 +04:00
|
|
|
d = opts["base"]
|
|
|
|
strip = opts["strip"]
|
|
|
|
|
|
|
|
for patch in patches:
|
|
|
|
ui.status("applying %s\n" % patch)
|
|
|
|
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()
|
|
|
|
if line.startswith("--- ") or line.startswith("diff -r"):
|
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-07-04 09:14:40 +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:
|
|
|
|
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)
|
|
|
|
ui.debug('message:\n%s\n' % message)
|
2005-06-23 10:31:25 +04:00
|
|
|
|
2005-08-05 01:22:36 +04:00
|
|
|
f = os.popen("patch -p%d < '%s'" % (strip, pf))
|
2005-06-23 10:31:25 +04:00
|
|
|
files = []
|
|
|
|
for l in f.read().splitlines():
|
|
|
|
l.rstrip('\r\n');
|
2005-06-26 17:18:23 +04:00
|
|
|
ui.status("%s\n" % l)
|
2005-07-11 04:14:56 +04:00
|
|
|
if l.startswith('patching file '):
|
2005-06-24 01:29:35 +04:00
|
|
|
pf = l[14:]
|
|
|
|
if pf not in files:
|
|
|
|
files.append(pf)
|
|
|
|
patcherr = f.close()
|
|
|
|
if patcherr:
|
2005-08-08 00:43:11 +04:00
|
|
|
raise util.Abort("patch failed")
|
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-08-17 07:17:16 +04:00
|
|
|
def incoming(ui, repo, source="default"):
|
2005-08-17 07:27:46 +04:00
|
|
|
"""show new changesets found in source"""
|
2005-08-17 07:17:16 +04:00
|
|
|
source = ui.expandpath(source)
|
|
|
|
other = hg.repository(ui, source)
|
|
|
|
if not other.local():
|
|
|
|
ui.warn("abort: incoming doesn't work for remote"
|
|
|
|
+ " repositories yet, sorry!\n")
|
|
|
|
return 1
|
|
|
|
o = repo.findincoming(other)
|
2005-08-17 10:47:49 +04:00
|
|
|
if not o:
|
|
|
|
return
|
2005-08-17 07:17:16 +04:00
|
|
|
o = other.newer(o)
|
|
|
|
o.reverse()
|
|
|
|
for n in o:
|
|
|
|
show_changeset(ui, other, changenode=n)
|
|
|
|
|
2005-08-15 09:33:09 +04:00
|
|
|
def init(ui, dest="."):
|
|
|
|
"""create a new repository in the given directory"""
|
|
|
|
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):
|
|
|
|
"""locate files matching specific patterns"""
|
2005-08-26 17:19:18 +04:00
|
|
|
end = opts['print0'] and '\0' or '\n'
|
2005-07-21 21:21:33 +04:00
|
|
|
|
2005-08-19 01:58:32 +04:00
|
|
|
for src, abs, rel, exact in walk(repo, pats, opts, '(?:.*/|)'):
|
2005-08-26 17:19:18 +04:00
|
|
|
if repo.dirstate.state(abs) == '?':
|
|
|
|
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:
|
|
|
|
ui.write(rel, end)
|
2005-07-06 06:19:01 +04:00
|
|
|
|
2005-08-24 23:39:10 +04:00
|
|
|
def log(ui, repo, *pats, **opts):
|
|
|
|
"""show revision history of entire repository or files"""
|
2005-08-25 13:00:03 +04:00
|
|
|
class dui:
|
|
|
|
# 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)
|
|
|
|
def __getattr__(self, key):
|
|
|
|
return getattr(self.ui, key)
|
2005-08-25 01:45:35 +04:00
|
|
|
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']]
|
2005-08-25 13:00:03 +04:00
|
|
|
for st, rev, fns in walkchangerevs(ui, repo, (pats and cwd) or '', pats,
|
|
|
|
opts):
|
|
|
|
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)
|
|
|
|
show_changeset(du, repo, rev)
|
|
|
|
if opts['patch']:
|
|
|
|
changenode = repo.changelog.node(rev)
|
|
|
|
prev, other = repo.changelog.parents(changenode)
|
|
|
|
dodiff(du, du, repo, prev, changenode, fns)
|
|
|
|
du.write("\n\n")
|
|
|
|
elif st == 'iter':
|
|
|
|
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-06-05 07:09:00 +04:00
|
|
|
"""output the latest or given revision of the project manifest"""
|
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-06-08 22:16:33 +04:00
|
|
|
ui.write("%40s %3s %s\n" % (hg.hex(m[f]), mf[f] and "755" or "644", f))
|
2005-06-05 01:45:31 +04:00
|
|
|
|
2005-08-17 03:49:26 +04:00
|
|
|
def outgoing(ui, repo, dest="default-push"):
|
|
|
|
"""show changesets not found in destination"""
|
|
|
|
dest = ui.expandpath(dest)
|
|
|
|
other = hg.repository(ui, dest)
|
|
|
|
o = repo.findoutgoing(other)
|
|
|
|
o = repo.newer(o)
|
|
|
|
o.reverse()
|
|
|
|
for n in o:
|
|
|
|
show_changeset(ui, repo, changenode=n)
|
|
|
|
|
2005-07-15 11:32:45 +04:00
|
|
|
def parents(ui, repo, rev=None):
|
|
|
|
"""show the parents of the working dir or revision"""
|
|
|
|
if rev:
|
|
|
|
p = repo.changelog.parents(repo.lookup(rev))
|
2005-06-04 00:46:38 +04:00
|
|
|
else:
|
|
|
|
p = repo.dirstate.parents()
|
|
|
|
|
|
|
|
for n in p:
|
|
|
|
if n != hg.nullid:
|
2005-06-13 11:49:21 +04:00
|
|
|
show_changeset(ui, repo, changenode=n)
|
2005-06-04 00:46:38 +04:00
|
|
|
|
2005-08-26 15:06:58 +04:00
|
|
|
def paths(ui, search=None):
|
2005-08-17 05:30:41 +04:00
|
|
|
"""show definition of symbolic path names"""
|
2005-08-17 01:52:28 +04:00
|
|
|
try:
|
|
|
|
repo = hg.repository(ui=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
|
|
|
|
ui.warn("not found!\n")
|
|
|
|
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-06-05 00:14:14 +04:00
|
|
|
"""pull changes from the specified source"""
|
2005-06-28 14:30:36 +04:00
|
|
|
source = ui.expandpath(source)
|
2005-06-22 06:04:25 +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-07-06 06:12:57 +04:00
|
|
|
r = repo.pull(other)
|
|
|
|
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-06-22 06:04:25 +04:00
|
|
|
ui.status("(run 'hg update' to get a working copy)\n")
|
|
|
|
|
|
|
|
return r
|
2005-06-05 00:14:14 +04:00
|
|
|
|
2005-08-20 09:36:57 +04:00
|
|
|
def push(ui, repo, dest="default-push", force=False, ssh=None, remotecmd=None):
|
2005-06-13 07:35:41 +04:00
|
|
|
"""push changes to the specified destination"""
|
2005-06-28 14:30:36 +04:00
|
|
|
dest = ui.expandpath(dest)
|
2005-07-07 10:25:40 +04:00
|
|
|
ui.status('pushing to %s\n' % (dest))
|
2005-06-28 12:59:59 +04:00
|
|
|
|
2005-08-20 09:36:57 +04:00
|
|
|
if ssh:
|
|
|
|
ui.setconfig("ui", "ssh", ssh)
|
|
|
|
if remotecmd:
|
|
|
|
ui.setconfig("ui", "remotecmd", remotecmd)
|
|
|
|
|
2005-07-07 10:25:40 +04:00
|
|
|
other = hg.repository(ui, dest)
|
2005-08-02 11:34:23 +04:00
|
|
|
r = repo.push(other, force)
|
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):
|
2005-06-05 00:14:14 +04:00
|
|
|
"raw commit interface"
|
2005-07-22 19:27:30 +04:00
|
|
|
if rc['text']:
|
|
|
|
ui.warn("Warning: -t and --text is deprecated,"
|
|
|
|
" please use -m or --message instead.\n")
|
2005-07-22 19:26:46 +04:00
|
|
|
message = rc['message'] or rc['text']
|
|
|
|
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']:
|
|
|
|
ui.warn("abort: missing commit message\n")
|
2005-06-05 00:14:14 +04:00
|
|
|
return 1
|
|
|
|
|
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-07-22 19:26:46 +04:00
|
|
|
repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent'])
|
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-06-05 07:09:00 +04:00
|
|
|
"""roll back an interrupted transaction"""
|
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
|
|
|
repo.recover()
|
|
|
|
|
2005-07-14 13:42:28 +04:00
|
|
|
def remove(ui, repo, file1, *files):
|
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
|
|
|
"""remove the specified files on the next commit"""
|
2005-07-14 13:42:28 +04:00
|
|
|
repo.remove(relpath(repo, (file1,) + files))
|
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 07:49:46 +04:00
|
|
|
def revert(ui, repo, *names, **opts):
|
|
|
|
"""revert modified files or dirs back to their unmodified states"""
|
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
|
|
|
root = os.path.realpath(repo.root)
|
2005-07-03 08:51:33 +04:00
|
|
|
|
2005-07-03 07:49:46 +04:00
|
|
|
def trimpath(p):
|
|
|
|
p = os.path.realpath(p)
|
|
|
|
if p.startswith(root):
|
|
|
|
rest = p[len(root):]
|
|
|
|
if not rest:
|
|
|
|
return rest
|
|
|
|
if p.startswith(os.sep):
|
|
|
|
return rest[1:]
|
|
|
|
return p
|
2005-07-03 08:51:33 +04:00
|
|
|
|
2005-07-03 07:49:46 +04:00
|
|
|
relnames = map(trimpath, names or [os.getcwd()])
|
|
|
|
chosen = {}
|
2005-07-03 08:51:33 +04:00
|
|
|
|
2005-07-03 07:49:46 +04:00
|
|
|
def choose(name):
|
|
|
|
def body(name):
|
|
|
|
for r in relnames:
|
2005-07-14 13:42:28 +04:00
|
|
|
if not name.startswith(r):
|
|
|
|
continue
|
2005-07-03 07:49:46 +04:00
|
|
|
rest = name[len(r):]
|
2005-07-14 13:42:28 +04:00
|
|
|
if not rest:
|
|
|
|
return r, True
|
2005-07-03 07:49:46 +04:00
|
|
|
depth = rest.count(os.sep)
|
|
|
|
if not r:
|
2005-07-14 13:42:28 +04:00
|
|
|
if depth == 0 or not opts['nonrecursive']:
|
|
|
|
return r, True
|
2005-07-03 07:49:46 +04:00
|
|
|
elif rest[0] == os.sep:
|
2005-07-14 13:42:28 +04:00
|
|
|
if depth == 1 or not opts['nonrecursive']:
|
|
|
|
return r, True
|
2005-07-03 07:49:46 +04:00
|
|
|
return None, False
|
|
|
|
relname, ret = body(name)
|
|
|
|
if ret:
|
|
|
|
chosen[relname] = 1
|
|
|
|
return ret
|
|
|
|
|
|
|
|
r = repo.update(node, False, True, choose, False)
|
|
|
|
for n in relnames:
|
|
|
|
if n not in chosen:
|
|
|
|
ui.warn('error: no matches for %s\n' % n)
|
|
|
|
r = 1
|
|
|
|
sys.stdout.flush()
|
|
|
|
return r
|
|
|
|
|
2005-06-25 11:22:46 +04:00
|
|
|
def root(ui, repo):
|
|
|
|
"""print the root (top) of the current working dir"""
|
|
|
|
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-06-05 07:09:00 +04:00
|
|
|
"""export the repository via HTTP"""
|
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-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()
|
|
|
|
respond(" ".join(map(hg.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()
|
|
|
|
nodes = map(hg.bin, nodes.split(" "))
|
|
|
|
r = []
|
|
|
|
for b in repo.branches(nodes):
|
|
|
|
r.append(" ".join(map(hg.hex, b)) + "\n")
|
|
|
|
respond("".join(r))
|
|
|
|
elif cmd == "between":
|
|
|
|
arg, pairs = getarg()
|
2005-07-14 13:42:28 +04:00
|
|
|
pairs = [map(hg.bin, p.split("-")) for p in pairs.split(" ")]
|
2005-07-06 05:55:22 +04:00
|
|
|
r = []
|
|
|
|
for b in repo.between(pairs):
|
|
|
|
r.append(" ".join(map(hg.hex, b)) + "\n")
|
|
|
|
respond("".join(r))
|
|
|
|
elif cmd == "changegroup":
|
|
|
|
nodes = []
|
|
|
|
arg, roots = getarg()
|
|
|
|
nodes = map(hg.bin, roots.split(" "))
|
|
|
|
|
2005-07-07 10:20:12 +04:00
|
|
|
cg = repo.changegroup(nodes)
|
|
|
|
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])
|
|
|
|
|
|
|
|
httpd = hgweb.create_server(repo)
|
|
|
|
|
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-07-04 08:51:05 +04:00
|
|
|
ui.status('listening at http://%s:%d/\n' % (addr, port))
|
2005-07-04 08:47:29 +04:00
|
|
|
else:
|
2005-07-04 08:51:05 +04:00
|
|
|
ui.status('listening at http://%s/\n' % addr)
|
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-06-01 23:48:34 +04:00
|
|
|
'''show changed files in the working directory
|
|
|
|
|
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
|
2005-08-06 15:05:09 +04:00
|
|
|
? = not tracked
|
|
|
|
'''
|
2005-06-12 20:11:43 +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
|
|
|
cwd = repo.getcwd()
|
2005-08-24 23:39:10 +04:00
|
|
|
files, matchfn, anypats = matchpats(repo, cwd, pats, opts)
|
2005-08-12 23:16:58 +04:00
|
|
|
(c, a, d, u) = [[util.pathto(cwd, x) for x in n]
|
2005-08-01 20:58:13 +04:00
|
|
|
for n in repo.changes(files=files, match=matchfn)]
|
2005-06-01 23:48:34 +04:00
|
|
|
|
2005-08-06 15:05:09 +04:00
|
|
|
changetypes = [('modified', 'M', c),
|
|
|
|
('added', 'A', a),
|
|
|
|
('removed', 'R', d),
|
|
|
|
('unknown', '?', u)]
|
|
|
|
|
|
|
|
for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]]
|
|
|
|
or changetypes):
|
|
|
|
for f in changes:
|
|
|
|
ui.write("%s %s\n" % (char, f))
|
2005-06-01 23:48:34 +04:00
|
|
|
|
2005-07-14 19:23:13 +04:00
|
|
|
def tag(ui, repo, name, rev=None, **opts):
|
2005-06-22 05:47:28 +04:00
|
|
|
"""add a tag for the current tip or a given revision"""
|
2005-07-22 19:27:30 +04:00
|
|
|
if opts['text']:
|
|
|
|
ui.warn("Warning: -t and --text is deprecated,"
|
|
|
|
" please use -m or --message instead.\n")
|
2005-06-22 05:47:28 +04:00
|
|
|
if name == "tip":
|
2005-07-03 06:29:54 +04:00
|
|
|
ui.warn("abort: 'tip' is a reserved name!\n")
|
|
|
|
return -1
|
2005-07-04 23:00:25 +04:00
|
|
|
if rev:
|
|
|
|
r = hg.hex(repo.lookup(rev))
|
|
|
|
else:
|
|
|
|
r = hg.hex(repo.changelog.tip())
|
|
|
|
|
2005-07-03 06:29:54 +04:00
|
|
|
if name.find(revrangesep) >= 0:
|
|
|
|
ui.warn("abort: '%s' cannot be used in a tag name\n" % revrangesep)
|
|
|
|
return -1
|
2005-06-22 05:47:28 +04:00
|
|
|
|
2005-07-04 23:00:25 +04:00
|
|
|
if opts['local']:
|
|
|
|
repo.opener("localtags", "a").write("%s %s\n" % (r, name))
|
|
|
|
return
|
|
|
|
|
2005-07-17 03:13:40 +04:00
|
|
|
(c, a, d, u) = repo.changes()
|
2005-06-22 05:47:28 +04:00
|
|
|
for x in (c, a, d, u):
|
2005-07-03 06:29:54 +04:00
|
|
|
if ".hgtags" in x:
|
|
|
|
ui.warn("abort: working copy of .hgtags is changed!\n")
|
2005-06-22 05:47:28 +04:00
|
|
|
ui.status("(please commit .hgtags manually)\n")
|
2005-07-03 06:29:54 +04:00
|
|
|
return -1
|
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-07-22 19:26:46 +04:00
|
|
|
message = (opts['message'] or opts['text'] or
|
|
|
|
"Added tag %s for changeset %s" % (name, r))
|
|
|
|
repo.commit([".hgtags"], message, opts['user'], opts['date'])
|
2005-06-22 05:47:28 +04:00
|
|
|
|
2005-06-05 01:45:31 +04:00
|
|
|
def tags(ui, repo):
|
2005-06-05 07:09:00 +04:00
|
|
|
"""list repository 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-06-26 16:25:07 +04:00
|
|
|
r = "%5d:%s" % (repo.changelog.rev(n), hg.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
|
|
|
|
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 tip(ui, repo):
|
2005-06-05 07:09:00 +04:00
|
|
|
"""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()
|
2005-06-13 11:49:21 +04:00
|
|
|
show_changeset(ui, repo, changenode=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-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-08-15 00:23:45 +04:00
|
|
|
def update(ui, repo, node=None, merge=False, clean=False, branch=None):
|
2005-06-05 06:34:35 +04:00
|
|
|
'''update or merge working directory
|
|
|
|
|
|
|
|
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-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:
|
|
|
|
ui.warn("Found multiple heads for %s\n" % branch)
|
|
|
|
for x in found:
|
|
|
|
show_changeset(ui, repo, changenode=x, brinfo=br)
|
|
|
|
return 1
|
|
|
|
if len(found) == 1:
|
|
|
|
node = found[0]
|
|
|
|
ui.warn("Using head %s for branch %s\n" % (hg.short(node), branch))
|
|
|
|
else:
|
|
|
|
ui.warn("branch %s not found\n" % (branch))
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
node = node and repo.lookup(node) or repo.changelog.tip()
|
2005-06-08 08:06:05 +04:00
|
|
|
return repo.update(node, allow=merge, force=clean)
|
2005-06-05 06:34:35 +04:00
|
|
|
|
2005-06-05 00:24:23 +04:00
|
|
|
def verify(ui, repo):
|
|
|
|
"""verify the integrity of the repository"""
|
|
|
|
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,
|
|
|
|
[('I', 'include', [], 'include path in search'),
|
|
|
|
('X', 'exclude', [], 'exclude path from search')],
|
2005-08-16 22:42:30 +04:00
|
|
|
"hg add [OPTION]... [FILE]..."),
|
2005-08-06 10:16:37 +04:00
|
|
|
"addremove":
|
|
|
|
(addremove,
|
|
|
|
[('I', 'include', [], 'include path in search'),
|
|
|
|
('X', 'exclude', [], 'exclude path from search')],
|
|
|
|
"hg addremove [OPTION]... [FILE]..."),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^annotate":
|
|
|
|
(annotate,
|
2005-07-22 11:47:35 +04:00
|
|
|
[('r', 'rev', '', 'revision'),
|
2005-08-24 07:21:52 +04:00
|
|
|
('a', 'text', None, 'treat all files as text'),
|
2005-07-14 13:42:28 +04:00
|
|
|
('u', 'user', None, 'show user'),
|
|
|
|
('n', 'number', None, 'show revision number'),
|
2005-07-22 11:47:35 +04:00
|
|
|
('c', 'changeset', None, 'show changeset'),
|
|
|
|
('I', 'include', [], 'include path in search'),
|
|
|
|
('X', 'exclude', [], 'exclude path from search')],
|
2005-08-16 22:42:30 +04:00
|
|
|
'hg annotate [OPTION]... FILE...'),
|
2005-07-14 13:42:28 +04:00
|
|
|
"cat":
|
|
|
|
(cat,
|
|
|
|
[('o', 'output', "", 'output to file')],
|
2005-07-15 12:38:57 +04:00
|
|
|
'hg cat [-o OUTFILE] FILE [REV]'),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^clone":
|
|
|
|
(clone,
|
2005-08-20 10:11:48 +04:00
|
|
|
[('U', 'noupdate', None, 'skip update after cloning'),
|
|
|
|
('e', 'ssh', "", 'ssh command'),
|
|
|
|
('', 'remotecmd', "", 'remote hg command')],
|
2005-08-26 12:39:43 +04:00
|
|
|
'hg clone [OPTION]... SOURCE [DEST]'),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^commit|ci":
|
|
|
|
(commit,
|
2005-07-15 12:38:57 +04:00
|
|
|
[('A', 'addremove', None, 'run add/remove during commit'),
|
2005-07-30 03:02:27 +04:00
|
|
|
('I', 'include', [], 'include path in search'),
|
|
|
|
('X', 'exclude', [], 'exclude path from search'),
|
2005-07-22 18:59:13 +04:00
|
|
|
('m', 'message', "", 'commit message'),
|
2005-07-22 11:47:35 +04:00
|
|
|
('t', 'text', "", 'commit message (deprecated: use -m)'),
|
2005-07-22 19:26:46 +04:00
|
|
|
('l', 'logfile', "", 'commit message file'),
|
2005-07-14 13:42:28 +04:00
|
|
|
('d', 'date', "", 'date code'),
|
|
|
|
('u', 'user', "", 'user')],
|
2005-07-15 12:38:57 +04:00
|
|
|
'hg commit [OPTION]... [FILE]...'),
|
|
|
|
"copy": (copy, [], 'hg copy SOURCE DEST'),
|
2005-07-03 23:47:45 +04:00
|
|
|
"debugcheckstate": (debugcheckstate, [], 'debugcheckstate'),
|
2005-08-24 08:30:12 +04:00
|
|
|
"debugconfig": (debugconfig, [], 'debugconfig'),
|
2005-07-03 23:47:45 +04:00
|
|
|
"debugstate": (debugstate, [], 'debugstate'),
|
2005-08-25 05:40:17 +04:00
|
|
|
"debugdata": (debugdata, [], 'debugdata FILE REV'),
|
2005-07-15 12:38:57 +04:00
|
|
|
"debugindex": (debugindex, [], 'debugindex FILE'),
|
|
|
|
"debugindexdot": (debugindexdot, [], 'debugindexdot FILE'),
|
2005-08-06 10:16:37 +04:00
|
|
|
"debugwalk":
|
|
|
|
(debugwalk,
|
|
|
|
[('I', 'include', [], 'include path in search'),
|
|
|
|
('X', 'exclude', [], 'exclude path from search')],
|
2005-08-16 22:42:30 +04:00
|
|
|
'debugwalk [OPTION]... [FILE]...'),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^diff":
|
|
|
|
(diff,
|
2005-07-22 11:47:35 +04:00
|
|
|
[('r', 'rev', [], 'revision'),
|
2005-08-24 06:58:46 +04:00
|
|
|
('a', 'text', None, 'treat all files as text'),
|
2005-07-22 11:47:35 +04:00
|
|
|
('I', 'include', [], 'include path in search'),
|
|
|
|
('X', 'exclude', [], 'exclude path from search')],
|
2005-08-26 12:39:43 +04:00
|
|
|
'hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...'),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^export":
|
|
|
|
(export,
|
2005-08-24 06:58:46 +04:00
|
|
|
[('o', 'output', "", 'output to file'),
|
|
|
|
('a', 'text', None, 'treat all files as text')],
|
2005-08-26 12:39:43 +04:00
|
|
|
"hg export [-a] [-o OUTFILE] REV..."),
|
2005-08-06 10:16:37 +04:00
|
|
|
"forget":
|
|
|
|
(forget,
|
|
|
|
[('I', 'include', [], 'include path in search'),
|
|
|
|
('X', 'exclude', [], 'exclude path from search')],
|
2005-08-16 22:42:30 +04:00
|
|
|
"hg forget [OPTION]... FILE..."),
|
2005-08-26 17:19:18 +04:00
|
|
|
"grep":
|
|
|
|
(grep,
|
|
|
|
[('0', 'print0', None, 'terminate file names with NUL'),
|
|
|
|
('I', 'include', [], 'include path in search'),
|
|
|
|
('X', 'exclude', [], 'include path in search'),
|
|
|
|
('Z', 'null', None, 'terminate file names with NUL'),
|
|
|
|
('a', 'all-revs', '', 'search all revs'),
|
|
|
|
('e', 'regexp', '', 'pattern to search for'),
|
|
|
|
('f', 'full-path', None, 'print complete paths'),
|
|
|
|
('i', 'ignore-case', None, 'ignore case when matching'),
|
|
|
|
('l', 'files-with-matches', None, 'print names of files with matches'),
|
|
|
|
('n', 'line-number', '', 'print line numbers'),
|
|
|
|
('r', 'rev', [], 'search in revision rev'),
|
|
|
|
('s', 'no-messages', None, 'do not print error messages'),
|
|
|
|
('v', 'invert-match', None, 'select non-matching lines')],
|
2005-08-26 18:47:09 +04:00
|
|
|
"hg grep [OPTION]... [PATTERN] [FILE]..."),
|
2005-08-15 08:22:40 +04:00
|
|
|
"heads":
|
|
|
|
(heads,
|
|
|
|
[('b', 'branches', None, 'find branch info')],
|
2005-08-26 12:39:43 +04:00
|
|
|
'hg heads [-b]'),
|
2005-07-15 12:38:57 +04:00
|
|
|
"help": (help_, [], 'hg help [COMMAND]'),
|
2005-06-15 09:44:43 +04:00
|
|
|
"identify|id": (identify, [], 'hg identify'),
|
2005-07-14 13:42:28 +04:00
|
|
|
"import|patch":
|
|
|
|
(import_,
|
|
|
|
[('p', 'strip', 1, 'path strip'),
|
2005-08-20 11:07:31 +04:00
|
|
|
('f', 'force', None, 'skip check for outstanding changes'),
|
2005-07-14 13:42:28 +04:00
|
|
|
('b', 'base', "", 'base path')],
|
2005-08-26 12:39:43 +04:00
|
|
|
"hg import [-f] [-p NUM] [-b BASE] PATCH..."),
|
2005-08-18 06:52:27 +04:00
|
|
|
"incoming|in": (incoming, [], 'hg incoming [SOURCE]'),
|
2005-08-15 09:33:09 +04:00
|
|
|
"^init": (init, [], 'hg init [DEST]'),
|
2005-07-14 13:42:28 +04:00
|
|
|
"locate":
|
|
|
|
(locate,
|
2005-07-22 11:47:35 +04:00
|
|
|
[('r', 'rev', '', 'revision'),
|
|
|
|
('0', 'print0', None, 'end records with NUL'),
|
2005-07-14 13:42:28 +04:00
|
|
|
('f', 'fullpath', None, 'print complete paths'),
|
2005-07-18 18:54:21 +04:00
|
|
|
('I', 'include', [], 'include path in search'),
|
|
|
|
('X', 'exclude', [], 'exclude path from search')],
|
2005-08-16 22:42:30 +04:00
|
|
|
'hg locate [OPTION]... [PATTERN]...'),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^log|history":
|
|
|
|
(log,
|
2005-08-24 23:39:10 +04:00
|
|
|
[('I', 'include', [], 'include path in search'),
|
|
|
|
('X', 'exclude', [], 'exclude path from search'),
|
|
|
|
('r', 'rev', [], 'revision'),
|
2005-07-14 13:42:28 +04:00
|
|
|
('p', 'patch', None, 'show patch')],
|
2005-08-26 12:39:43 +04:00
|
|
|
'hg log [-I] [-X] [-r REV]... [-p] [FILE]'),
|
2005-07-15 12:38:57 +04:00
|
|
|
"manifest": (manifest, [], 'hg manifest [REV]'),
|
2005-08-18 06:52:27 +04:00
|
|
|
"outgoing|out": (outgoing, [], 'hg outgoing [DEST]'),
|
2005-07-15 12:38:57 +04:00
|
|
|
"parents": (parents, [], 'hg parents [REV]'),
|
2005-08-17 05:30:41 +04:00
|
|
|
"paths": (paths, [], 'hg paths [NAME]'),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^pull":
|
|
|
|
(pull,
|
2005-08-20 10:11:48 +04:00
|
|
|
[('u', 'update', None, 'update working directory'),
|
|
|
|
('e', 'ssh', "", 'ssh command'),
|
|
|
|
('', 'remotecmd', "", 'remote hg command')],
|
2005-08-26 12:39:43 +04:00
|
|
|
'hg pull [-u] [-e FILE] [--remotecmd FILE] [SOURCE]'),
|
2005-08-02 11:34:23 +04:00
|
|
|
"^push":
|
|
|
|
(push,
|
2005-08-20 09:36:57 +04:00
|
|
|
[('f', 'force', None, 'force push'),
|
|
|
|
('e', 'ssh', "", 'ssh command'),
|
|
|
|
('', 'remotecmd', "", 'remote hg command')],
|
2005-08-26 12:39:43 +04:00
|
|
|
'hg push [-f] [-e FILE] [--remotecmd FILE] [DEST]'),
|
2005-07-14 13:42:28 +04:00
|
|
|
"rawcommit":
|
|
|
|
(rawcommit,
|
|
|
|
[('p', 'parent', [], 'parent'),
|
|
|
|
('d', 'date', "", 'date code'),
|
|
|
|
('u', 'user', "", 'user'),
|
|
|
|
('F', 'files', "", 'file list'),
|
2005-07-22 19:26:46 +04:00
|
|
|
('m', 'message', "", 'commit message'),
|
|
|
|
('t', 'text', "", 'commit message (deprecated: use -m)'),
|
|
|
|
('l', 'logfile', "", 'commit message file')],
|
2005-07-15 12:38:57 +04:00
|
|
|
'hg rawcommit [OPTION]... [FILE]...'),
|
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
|
|
|
"recover": (recover, [], "hg recover"),
|
2005-07-15 12:38:57 +04:00
|
|
|
"^remove|rm": (remove, [], "hg remove FILE..."),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^revert":
|
|
|
|
(revert,
|
|
|
|
[("n", "nonrecursive", None, "don't recurse into subdirs"),
|
|
|
|
("r", "rev", "", "revision")],
|
2005-07-22 11:47:35 +04:00
|
|
|
"hg revert [-n] [-r REV] [NAME]..."),
|
2005-06-25 11:22:46 +04:00
|
|
|
"root": (root, [], "hg root"),
|
2005-07-14 13:42:28 +04:00
|
|
|
"^serve":
|
|
|
|
(serve,
|
|
|
|
[('A', 'accesslog', '', 'access log file'),
|
|
|
|
('E', 'errorlog', '', 'error log file'),
|
2005-08-18 05:57:37 +04:00
|
|
|
('p', 'port', 0, 'listen port'),
|
2005-07-14 13:42:28 +04:00
|
|
|
('a', 'address', '', 'interface address'),
|
2005-08-18 05:57:37 +04:00
|
|
|
('n', 'name', "", 'repository name'),
|
2005-07-14 13:42:28 +04:00
|
|
|
('', 'stdio', None, 'for remote clients'),
|
2005-08-22 02:56:14 +04:00
|
|
|
('t', 'templates', "", 'template directory'),
|
|
|
|
('', 'style', "", 'template style'),
|
2005-08-05 01:21:27 +04:00
|
|
|
('6', 'ipv6', None, 'use IPv6 in addition to IPv4')],
|
2005-07-15 12:38:57 +04:00
|
|
|
"hg serve [OPTION]..."),
|
2005-08-06 10:09:10 +04:00
|
|
|
"^status":
|
|
|
|
(status,
|
|
|
|
[('m', 'modified', None, 'show only modified files'),
|
|
|
|
('a', 'added', None, 'show only added files'),
|
|
|
|
('r', 'removed', None, 'show only removed files'),
|
|
|
|
('u', 'unknown', None, 'show only unknown (not tracked) files'),
|
|
|
|
('I', 'include', [], 'include path in search'),
|
|
|
|
('X', 'exclude', [], 'exclude path from search')],
|
2005-08-16 22:42:30 +04:00
|
|
|
"hg status [OPTION]... [FILE]..."),
|
2005-07-14 13:42:28 +04:00
|
|
|
"tag":
|
|
|
|
(tag,
|
|
|
|
[('l', 'local', None, 'make the tag local'),
|
2005-07-22 19:26:46 +04:00
|
|
|
('m', 'message', "", 'commit message'),
|
|
|
|
('t', 'text', "", 'commit message (deprecated: use -m)'),
|
2005-07-14 13:42:28 +04:00
|
|
|
('d', 'date', "", 'date code'),
|
|
|
|
('u', 'user', "", 'user')],
|
2005-07-15 12:38:57 +04:00
|
|
|
'hg tag [OPTION]... NAME [REV]'),
|
2005-06-05 01:45:31 +04:00
|
|
|
"tags": (tags, [], 'hg tags'),
|
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
|
|
|
"tip": (tip, [], 'hg tip'),
|
2005-06-01 22:40:19 +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,
|
2005-08-15 00:23:45 +04:00
|
|
|
[('b', 'branch', "", 'checkout the head of a specific branch'),
|
|
|
|
('m', 'merge', None, 'allow merging of conflicts'),
|
2005-07-14 13:42:28 +04:00
|
|
|
('C', 'clean', None, 'overwrite locally modified files')],
|
2005-08-15 09:18:49 +04:00
|
|
|
'hg update [-b TAG] [-m] [-C] [REV]'),
|
2005-06-05 00:24:23 +04:00
|
|
|
"verify": (verify, [], 'hg verify'),
|
2005-06-25 12:16:39 +04:00
|
|
|
"version": (show_version, [], 'hg version'),
|
2005-08-25 20:35:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
globalopts = [
|
|
|
|
('R', 'repository', "", 'repository root directory'),
|
|
|
|
('', 'cwd', '', 'change working directory'),
|
|
|
|
('y', 'noninteractive', None, 'run non-interactively'),
|
|
|
|
('q', 'quiet', None, 'quiet mode'),
|
|
|
|
('v', 'verbose', None, 'verbose mode'),
|
|
|
|
('', 'debug', None, 'debug mode'),
|
|
|
|
('', 'traceback', None, 'print traceback on exception'),
|
|
|
|
('', 'time', None, 'time how long the command takes'),
|
|
|
|
('', 'profile', None, 'profile'),
|
|
|
|
('', 'version', None, 'output version information and exit'),
|
2005-08-26 10:37:41 +04:00
|
|
|
('h', 'help', None, 'display help and exit'),
|
2005-08-25 20:35:35 +04:00
|
|
|
]
|
2005-07-03 23:47:45 +04:00
|
|
|
|
2005-08-26 17:19:18 +04:00
|
|
|
norepo = ("clone init version help debugconfig debugdata"
|
|
|
|
" debugindex debugindexdot paths")
|
2005-06-01 12:25:42 +04:00
|
|
|
|
2005-06-01 23:11:19 +04:00
|
|
|
def find(cmd):
|
|
|
|
for e in table.keys():
|
2005-06-15 05:06:57 +04:00
|
|
|
if re.match("(%s)$" % e, cmd):
|
2005-08-06 18:43:12 +04:00
|
|
|
return e, table[e]
|
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-07-03 23:47:45 +04:00
|
|
|
def parse(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-08-26 10:26:21 +04:00
|
|
|
i = find(cmd)[1]
|
|
|
|
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
|
|
|
|
|
|
|
try:
|
|
|
|
cmd, func, args, options, cmdoptions = parse(args)
|
|
|
|
except ParseError, inst:
|
|
|
|
u = ui.ui()
|
|
|
|
if inst.args[0]:
|
|
|
|
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:
|
|
|
|
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)
|
|
|
|
except UnknownCommand, inst:
|
|
|
|
u = ui.ui()
|
|
|
|
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()
|
|
|
|
u = ui.ui()
|
|
|
|
u.warn("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n" %
|
|
|
|
(t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
|
|
|
|
atexit.register(print_time)
|
|
|
|
|
2005-07-03 23:47:45 +04:00
|
|
|
u = ui.ui(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-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:
|
|
|
|
u.warn('abort: %s: %s\n' % (options['cwd'], inst.strerror))
|
|
|
|
sys.exit(1)
|
|
|
|
|
2005-06-30 02:20:54 +04:00
|
|
|
if cmd not in norepo.split():
|
|
|
|
path = options["repository"] or ""
|
|
|
|
repo = hg.repository(ui=u, path=path)
|
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
|
|
|
|
|
|
|
if options['profile']:
|
|
|
|
import hotshot, hotshot.stats
|
|
|
|
prof = hotshot.Profile("hg.prof")
|
|
|
|
r = prof.runcall(d)
|
|
|
|
prof.close()
|
|
|
|
stats = hotshot.stats.load("hg.prof")
|
|
|
|
stats.strip_dirs()
|
|
|
|
stats.sort_stats('time', 'calls')
|
|
|
|
stats.print_stats(40)
|
|
|
|
return r
|
|
|
|
else:
|
|
|
|
return d()
|
|
|
|
except:
|
|
|
|
if options['traceback']:
|
|
|
|
traceback.print_exc()
|
|
|
|
raise
|
2005-06-28 12:55:59 +04:00
|
|
|
except hg.RepoError, inst:
|
|
|
|
u.warn("abort: ", inst, "!\n")
|
2005-06-02 01:04:13 +04:00
|
|
|
except SignalInterrupt:
|
|
|
|
u.warn("killed!\n")
|
2005-06-01 12:25:42 +04:00
|
|
|
except KeyboardInterrupt:
|
2005-08-04 21:06:49 +04:00
|
|
|
try:
|
|
|
|
u.warn("interrupted!\n")
|
|
|
|
except IOError, inst:
|
|
|
|
if inst.errno == errno.EPIPE:
|
|
|
|
if u.debugflag:
|
|
|
|
u.warn("\nbroken pipe\n")
|
|
|
|
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"):
|
|
|
|
u.warn("abort: %s\n" % inst)
|
|
|
|
elif hasattr(inst, "reason"):
|
2005-07-27 06:52:40 +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:
|
|
|
|
u.warn("broken pipe\n")
|
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"):
|
|
|
|
u.warn("abort: %s: %s\n" % (inst.strerror, inst.filename))
|
|
|
|
else:
|
|
|
|
u.warn("abort: %s\n" % inst.strerror)
|
2005-08-08 00:43:11 +04:00
|
|
|
except util.Abort, inst:
|
2005-07-19 19:42:36 +04:00
|
|
|
u.warn('abort: ', inst.args[0] % inst.args[1:], '\n')
|
|
|
|
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-07-03 23:47:45 +04:00
|
|
|
u.warn("%s: invalid arguments\n" % cmd)
|
2005-07-14 13:42:28 +04:00
|
|
|
help_(u, cmd)
|
2005-08-06 17:04:59 +04:00
|
|
|
except UnknownCommand, inst:
|
|
|
|
u.warn("hg: unknown command '%s'\n" % inst.args[0])
|
|
|
|
help_(u, 'shortlist')
|
2005-06-28 14:08:14 +04:00
|
|
|
|
|
|
|
sys.exit(-1)
|