hg
588 lines
| 17.8 KiB
| text/plain
|
TextLexer
mpm@selenic.com
|
r0 | #!/usr/bin/env python | ||
# | ||||
# mercurial - a minimal scalable distributed SCM | ||||
mpm@selenic.com
|
r188 | # v0.5 "katje" | ||
mpm@selenic.com
|
r0 | # | ||
# 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. | ||||
mpm@selenic.com
|
r46 | # the psyco compiler makes commits a bit faster | ||
# and makes changegroup merge about 20 times slower! | ||||
# try: | ||||
# import psyco | ||||
# psyco.full() | ||||
# except: | ||||
# pass | ||||
mpm@selenic.com
|
r0 | |||
mpm@selenic.com
|
r23 | import sys, os, time | ||
mpm@selenic.com
|
r0 | from mercurial import hg, mdiff, fancyopts | ||
mpm@selenic.com
|
r18 | def help(): | ||
mpm@selenic.com
|
r175 | ui.status("""\ | ||
mpm@selenic.com
|
r18 | commands: | ||
mpm@selenic.com
|
r150 | add [files...] add the given files in the next commit | ||
addremove add all new files, delete all missing files | ||||
annotate [files...] show changeset number per file line | ||||
mpm@selenic.com
|
r18 | branch <path> create a branch of <path> in this directory | ||
checkout [changeset] checkout the latest or given changeset | ||||
commit commit all changes to the repository | ||||
mpm@selenic.com
|
r150 | diff [files...] diff working directory (or selected files) | ||
mpm@selenic.com
|
r18 | dump <file> [rev] dump the latest or given revision of a file | ||
dumpmanifest [rev] dump the latest or given revision of the manifest | ||||
mpm@selenic.com
|
r150 | history show changeset history | ||
init create a new repository in this directory | ||||
log <file> show revision history of a single file | ||||
merge <path> merge changes from <path> into local repository | ||||
mpm@selenic.com
|
r163 | recover rollback an interrupted transaction | ||
mpm@selenic.com
|
r150 | remove [files...] remove the given files in the next commit | ||
mpm@selenic.com
|
r158 | serve export the repository via HTTP | ||
mpm@selenic.com
|
r150 | status show new, missing, and changed files in working dir | ||
mpm@selenic.com
|
r67 | tags show current changeset tags | ||
mpm@selenic.com
|
r163 | undo undo the last transaction | ||
mpm@selenic.com
|
r175 | """) | ||
mpm@selenic.com
|
r18 | |||
mpm@selenic.com
|
r33 | def filterfiles(list, files): | ||
l = [ x for x in list if x in files ] | ||||
mpm@selenic.com
|
r31 | |||
mpm@selenic.com
|
r33 | for f in files: | ||
if f[-1] != os.sep: f += os.sep | ||||
l += [ x for x in list if x.startswith(f) ] | ||||
return l | ||||
mpm@selenic.com
|
r31 | |||
mpm@selenic.com
|
r34 | def diff(files = None, node1 = None, node2 = None): | ||
mpm@selenic.com
|
r64 | def date(c): | ||
return time.asctime(time.gmtime(float(c[2].split(' ')[0]))) | ||||
mpm@selenic.com
|
r34 | |||
if node2: | ||||
change = repo.changelog.read(node2) | ||||
mmap2 = repo.manifest.read(change[0]) | ||||
(c, a, d) = repo.diffrevs(node1, node2) | ||||
def read(f): return repo.file(f).read(mmap2[f]) | ||||
mpm@selenic.com
|
r64 | date2 = date(change) | ||
mpm@selenic.com
|
r34 | else: | ||
mpm@selenic.com
|
r64 | date2 = time.asctime() | ||
mpm@selenic.com
|
r34 | if not node1: | ||
node1 = repo.current | ||||
(c, a, d) = repo.diffdir(repo.root, node1) | ||||
mpm@selenic.com
|
r129 | a = [] # ignore unknown files in repo, by popular request | ||
mpm@selenic.com
|
r64 | def read(f): return file(os.path.join(repo.root, f)).read() | ||
mpm@selenic.com
|
r34 | |||
change = repo.changelog.read(node1) | ||||
mmap = repo.manifest.read(change[0]) | ||||
mpm@selenic.com
|
r64 | date1 = date(change) | ||
mpm@selenic.com
|
r34 | |||
if files: | ||||
mpm@selenic.com
|
r129 | c, a, d = map(lambda x: filterfiles(x, files), (c, a, d)) | ||
mpm@selenic.com
|
r34 | |||
for f in c: | ||||
mpm@selenic.com
|
r130 | to = "" | ||
if mmap.has_key(f): | ||||
to = repo.file(f).read(mmap[f]) | ||||
mpm@selenic.com
|
r34 | tn = read(f) | ||
mpm@selenic.com
|
r64 | sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) | ||
mpm@selenic.com
|
r129 | for f in a: | ||
to = "" | ||||
tn = read(f) | ||||
sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) | ||||
mpm@selenic.com
|
r34 | for f in d: | ||
to = repo.file(f).read(mmap[f]) | ||||
tn = "" | ||||
mpm@selenic.com
|
r64 | sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) | ||
mpm@selenic.com
|
r34 | |||
mpm@selenic.com
|
r0 | options = {} | ||
opts = [('v', 'verbose', None, 'verbose'), | ||||
mpm@selenic.com
|
r83 | ('d', 'debug', None, 'debug'), | ||
mpm@selenic.com
|
r107 | ('q', 'quiet', None, 'quiet'), | ||
('y', 'noninteractive', None, 'run non-interactively'), | ||||
] | ||||
mpm@selenic.com
|
r0 | |||
args = fancyopts.fancyopts(sys.argv[1:], opts, options, | ||||
'hg [options] <command> [command options] [files]') | ||||
try: | ||||
cmd = args[0] | ||||
args = args[1:] | ||||
except: | ||||
cmd = "" | ||||
mpm@selenic.com
|
r107 | ui = hg.ui(options["verbose"], options["debug"], options["quiet"], | ||
not options["noninteractive"]) | ||||
mpm@selenic.com
|
r0 | |||
if cmd == "init": | ||||
repo = hg.repository(ui, ".", create=1) | ||||
sys.exit(0) | ||||
elif cmd == "branch" or cmd == "clone": | ||||
os.system("cp -al %s/.hg .hg" % args[0]) | ||||
sys.exit(0) | ||||
mpm@selenic.com
|
r18 | elif cmd == "help": | ||
help() | ||||
sys.exit(0) | ||||
mpm@selenic.com
|
r0 | else: | ||
mpm@selenic.com
|
r18 | try: | ||
repo = hg.repository(ui=ui) | ||||
mpm@selenic.com
|
r74 | except IOError: | ||
mpm@selenic.com
|
r83 | ui.warn("Unable to open repository\n") | ||
mpm@selenic.com
|
r18 | sys.exit(0) | ||
mpm@selenic.com
|
r0 | |||
jake@edge2.net
|
r103 | relpath = None | ||
if os.getcwd() != repo.root: | ||||
relpath = os.getcwd()[len(repo.root) + 1: ] | ||||
mpm@selenic.com
|
r0 | if cmd == "checkout" or cmd == "co": | ||
node = repo.changelog.tip() | ||||
mpm@selenic.com
|
r39 | if args: | ||
mpm@selenic.com
|
r67 | node = repo.lookup(args[0]) | ||
mpm@selenic.com
|
r0 | repo.checkout(node) | ||
elif cmd == "add": | ||||
repo.add(args) | ||||
elif cmd == "remove" or cmd == "rm" or cmd == "del" or cmd == "delete": | ||||
repo.remove(args) | ||||
elif cmd == "commit" or cmd == "checkin" or cmd == "ci": | ||||
if 1: | ||||
if len(args) > 0: | ||||
mpm@selenic.com
|
r31 | repo.commit(repo.current, args) | ||
mpm@selenic.com
|
r0 | else: | ||
mpm@selenic.com
|
r31 | repo.commit(repo.current) | ||
mpm@selenic.com
|
r0 | |||
elif cmd == "import" or cmd == "patch": | ||||
mpm@selenic.com
|
r69 | try: | ||
import psyco | ||||
psyco.full() | ||||
except: | ||||
pass | ||||
mpm@selenic.com
|
r0 | ioptions = {} | ||
opts = [('p', 'strip', 1, 'path strip'), | ||||
mpm@selenic.com
|
r50 | ('b', 'base', "", 'base path'), | ||
('q', 'quiet', "", 'silence diff') | ||||
] | ||||
mpm@selenic.com
|
r0 | |||
args = fancyopts.fancyopts(args, opts, ioptions, | ||||
'hg import [options] <patch names>') | ||||
d = ioptions["base"] | ||||
strip = ioptions["strip"] | ||||
mpm@selenic.com
|
r50 | quiet = ioptions["quiet"] and "> /dev/null" or "" | ||
mpm@selenic.com
|
r0 | |||
for patch in args: | ||||
ui.status("applying %s\n" % patch) | ||||
mpm@selenic.com
|
r49 | pf = os.path.join(d, patch) | ||
mpm@selenic.com
|
r62 | text = "" | ||
for l in file(pf): | ||||
mpm@selenic.com
|
r69 | if l[:4] == "--- ": break | ||
mpm@selenic.com
|
r62 | text += l | ||
mpm@selenic.com
|
r0 | f = os.popen("lsdiff --strip %d %s" % (strip, pf)) | ||
mpm@selenic.com
|
r54 | files = filter(None, map(lambda x: x.rstrip(), f.read().splitlines())) | ||
mpm@selenic.com
|
r0 | f.close() | ||
mpm@selenic.com
|
r69 | |||
if files: | ||||
if os.system("patch -p%d < %s %s" % (strip, pf, quiet)): | ||||
raise "patch failed!" | ||||
mpm@selenic.com
|
r49 | repo.commit(repo.current, files, text) | ||
mpm@selenic.com
|
r0 | |||
elif cmd == "status": | ||||
mpm@selenic.com
|
r33 | (c, a, d) = repo.diffdir(repo.root, repo.current) | ||
jake@edge2.net
|
r103 | if relpath: | ||
(c, a, d) = map(lambda x: filterfiles(x, [ relpath ]), (c, a, d)) | ||||
mpm@selenic.com
|
r0 | for f in c: print "C", f | ||
for f in a: print "?", f | ||||
for f in d: print "R", f | ||||
elif cmd == "diff": | ||||
mpm@selenic.com
|
r34 | revs = [] | ||
mpm@selenic.com
|
r31 | |||
mpm@selenic.com
|
r33 | if args: | ||
mpm@selenic.com
|
r38 | doptions = {} | ||
mpm@selenic.com
|
r33 | opts = [('r', 'revision', [], 'revision')] | ||
args = fancyopts.fancyopts(args, opts, doptions, | ||||
'hg diff [options] [files]') | ||||
mpm@selenic.com
|
r67 | revs = map(lambda x: repo.lookup(x), doptions['revision']) | ||
mpm@selenic.com
|
r33 | |||
if len(revs) > 2: | ||||
mpm@selenic.com
|
r83 | self.ui.warn("too many revisions to diff\n") | ||
mpm@selenic.com
|
r33 | sys.exit(1) | ||
mpm@selenic.com
|
r64 | |||
jake@edge2.net
|
r103 | if relpath: | ||
mpm@selenic.com
|
r64 | if not args: args = [ relpath ] | ||
else: args = [ os.path.join(relpath, x) for x in args ] | ||||
diff(args, *revs) | ||||
mpm@selenic.com
|
r33 | |||
mpm@selenic.com
|
r79 | elif cmd == "annotate": | ||
mpm@selenic.com
|
r150 | bcache = {} | ||
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] | ||||
bcache[rev] = name | ||||
return name | ||||
mpm@selenic.com
|
r79 | aoptions = {} | ||
mpm@selenic.com
|
r150 | opts = [('r', 'revision', '', 'revision'), | ||
('u', 'user', None, 'show user'), | ||||
('n', 'number', None, 'show revision number'), | ||||
('c', 'changeset', None, 'show changeset')] | ||||
mpm@selenic.com
|
r79 | args = fancyopts.fancyopts(args, opts, aoptions, | ||
mpm@selenic.com
|
r150 | 'hg annotate [-u] [-c] [-n] [-r id] [files]') | ||
opmap = [['user', getname], ['number', str], ['changeset', getnode]] | ||||
if not aoptions['user'] and not aoptions['changeset']: | ||||
aoptions['number'] = 1 | ||||
mpm@selenic.com
|
r122 | |||
mpm@selenic.com
|
r79 | if args: | ||
mpm@selenic.com
|
r122 | if relpath: args = [ os.path.join(relpath, x) for x in args ] | ||
mpm@selenic.com
|
r79 | node = repo.current | ||
if aoptions['revision']: | ||||
node = repo.changelog.lookup(aoptions['revision']) | ||||
change = repo.changelog.read(node) | ||||
mmap = repo.manifest.read(change[0]) | ||||
mpm@selenic.com
|
r150 | maxuserlen = 0 | ||
maxchangelen = 0 | ||||
mpm@selenic.com
|
r79 | for f in args: | ||
mpm@selenic.com
|
r150 | lines = repo.file(f).annotate(mmap[f]) | ||
pieces = [] | ||||
mpm@selenic.com
|
r80 | |||
mpm@selenic.com
|
r150 | for o, f in opmap: | ||
if aoptions[o]: | ||||
l = [ f(n) for n,t in lines ] | ||||
m = max(map(len, l)) | ||||
pieces.append([ "%*s" % (m, x) for x in l]) | ||||
for p,l in zip(zip(*pieces), lines): | ||||
sys.stdout.write(" ".join(p) + ": " + l[1]) | ||||
mpm@selenic.com
|
r79 | |||
mpm@selenic.com
|
r34 | elif cmd == "export": | ||
mpm@selenic.com
|
r67 | node = repo.lookup(args[0]) | ||
mpm@selenic.com
|
r68 | prev, other = repo.changelog.parents(node) | ||
change = repo.changelog.read(node) | ||||
print "# HG changeset patch" | ||||
print "# User %s" % change[1] | ||||
print "# Node ID %s" % hg.hex(node) | ||||
print "# Parent %s" % hg.hex(prev) | ||||
if other != hg.nullid: | ||||
print "# Parent %s" % hg.hex(other) | ||||
print change[4] | ||||
mpm@selenic.com
|
r34 | diff(None, prev, node) | ||
mpm@selenic.com
|
r0 | |||
mpm@selenic.com
|
r46 | elif cmd == "debugchangegroup": | ||
mpm@selenic.com
|
r67 | newer = repo.newer(map(repo.lookup, args)) | ||
mpm@selenic.com
|
r62 | for chunk in repo.changegroup(newer): | ||
sys.stdout.write(chunk) | ||||
mpm@selenic.com
|
r46 | |||
elif cmd == "debugaddchangegroup": | ||||
data = sys.stdin.read() | ||||
repo.addchangegroup(data) | ||||
mpm@selenic.com
|
r0 | elif cmd == "addremove": | ||
mpm@selenic.com
|
r29 | (c, a, d) = repo.diffdir(repo.root, repo.current) | ||
mpm@selenic.com
|
r0 | repo.add(a) | ||
repo.remove(d) | ||||
elif cmd == "history": | ||||
for i in range(repo.changelog.count()): | ||||
n = repo.changelog.node(i) | ||||
changes = repo.changelog.read(n) | ||||
(p1, p2) = repo.changelog.parents(n) | ||||
(h, h1, h2) = map(hg.hex, (n, p1, p2)) | ||||
(i1, i2) = map(repo.changelog.rev, (p1, p2)) | ||||
print "rev: %4d:%s" % (i, h) | ||||
print "parents: %4d:%s" % (i1, h1) | ||||
if i2: print " %4d:%s" % (i2, h2) | ||||
print "manifest: %4d:%s" % (repo.manifest.rev(changes[0]), | ||||
hg.hex(changes[0])) | ||||
print "user:", changes[1] | ||||
mpm@selenic.com
|
r21 | print "date:", time.asctime( | ||
time.localtime(float(changes[2].split(' ')[0]))) | ||||
mpm@selenic.com
|
r123 | if ui.verbose: print "files:", " ".join(changes[3]) | ||
mpm@selenic.com
|
r0 | print "description:" | ||
print changes[4] | ||||
mpm@selenic.com
|
r89 | elif cmd == "tip": | ||
n = repo.changelog.tip() | ||||
t = repo.changelog.rev(n) | ||||
ui.status("%d:%s\n" % (t, hg.hex(n))) | ||||
mpm@selenic.com
|
r0 | elif cmd == "log": | ||
jake@edge2.net
|
r103 | |||
if len(args) == 1: | ||||
if relpath: | ||||
args[0] = os.path.join(relpath, args[0]) | ||||
mpm@selenic.com
|
r0 | r = repo.file(args[0]) | ||
for i in range(r.count()): | ||||
n = r.node(i) | ||||
(p1, p2) = r.parents(n) | ||||
(h, h1, h2) = map(hg.hex, (n, p1, p2)) | ||||
(i1, i2) = map(r.rev, (p1, p2)) | ||||
cr = r.linkrev(n) | ||||
cn = hg.hex(repo.changelog.node(cr)) | ||||
print "rev: %4d:%s" % (i, h) | ||||
print "changeset: %4d:%s" % (cr, cn) | ||||
print "parents: %4d:%s" % (i1, h1) | ||||
if i2: print " %4d:%s" % (i2, h2) | ||||
jake@edge2.net
|
r103 | changes = repo.changelog.read(repo.changelog.node(cr)) | ||
mpm@selenic.com
|
r105 | print "user: %s" % changes[1] | ||
print "date: %s" % time.asctime( | ||||
mpm@selenic.com
|
r106 | time.localtime(float(changes[2].split(' ')[0]))) | ||
jake@edge2.net
|
r103 | print "description:" | ||
print changes[4] | ||||
elif len(args) > 1: | ||||
print "too many args" | ||||
mpm@selenic.com
|
r0 | else: | ||
print "missing filename" | ||||
elif cmd == "dump": | ||||
if args: | ||||
r = repo.file(args[0]) | ||||
n = r.tip() | ||||
mpm@selenic.com
|
r39 | if len(args) > 1: n = r.lookup(args[1]) | ||
mpm@selenic.com
|
r0 | sys.stdout.write(r.read(n)) | ||
else: | ||||
print "missing filename" | ||||
elif cmd == "dumpmanifest": | ||||
n = repo.manifest.tip() | ||||
if len(args) > 0: | ||||
mpm@selenic.com
|
r39 | n = repo.manifest.lookup(args[0]) | ||
mpm@selenic.com
|
r0 | m = repo.manifest.read(n) | ||
files = m.keys() | ||||
files.sort() | ||||
for f in files: | ||||
print hg.hex(m[f]), f | ||||
mpm@selenic.com
|
r24 | elif cmd == "debugindex": | ||
mpm@selenic.com
|
r91 | if ".hg" not in args[0]: | ||
args[0] = ".hg/data/" + repo.file(args[0]).encodepath(args[0]) + "i" | ||||
mpm@selenic.com
|
r24 | r = hg.revlog(open, args[0], "") | ||
mpm@selenic.com
|
r70 | print " rev offset length base linkrev"+\ | ||
mpm@selenic.com
|
r24 | " p1 p2 nodeid" | ||
for i in range(r.count()): | ||||
e = r.index[i] | ||||
mpm@selenic.com
|
r70 | print "% 6d % 9d % 7d % 6d % 7d %s.. %s.. %s.." % ( | ||
mpm@selenic.com
|
r24 | i, e[0], e[1], e[2], e[3], | ||
hg.hex(e[4][:5]), hg.hex(e[5][:5]), hg.hex(e[6][:5])) | ||||
mpm@selenic.com
|
r92 | elif cmd == "debugindexdot": | ||
if ".hg" not in args[0]: | ||||
args[0] = ".hg/data/" + repo.file(args[0]).encodepath(args[0]) + "i" | ||||
r = hg.revlog(open, args[0], "") | ||||
print "digraph G {" | ||||
for i in range(r.count()): | ||||
e = r.index[i] | ||||
print "\t%d -> %d" % (r.rev(e[4]), i) | ||||
if e[5] != hg.nullid: | ||||
print "\t%d -> %d" % (r.rev(e[5]), i) | ||||
print "}" | ||||
mpm@selenic.com
|
r0 | elif cmd == "merge": | ||
mpm@selenic.com
|
r174 | (c, a, d) = repo.diffdir(repo.root, repo.current) | ||
if c: | ||||
ui.warn("aborting (outstanding changes in working directory)\n") | ||||
sys.exit(1) | ||||
mpm@selenic.com
|
r0 | if args: | ||
mpm@selenic.com
|
r175 | paths = {} | ||
try: | ||||
pf = os.path.join(os.environ["HOME"], ".hgpaths") | ||||
for l in file(pf): | ||||
name, path = l.split() | ||||
paths[name] = path | ||||
except: | ||||
pass | ||||
if args[0] in paths: args[0] = paths[args[0]] | ||||
mpm@selenic.com
|
r0 | other = hg.repository(ui, args[0]) | ||
mpm@selenic.com
|
r62 | cg = repo.getchangegroup(other) | ||
repo.addchangegroup(cg) | ||||
else: | ||||
print "missing source repository" | ||||
mpm@selenic.com
|
r67 | elif cmd == "tags": | ||
repo.lookup(0) # prime the cache | ||||
i = repo.tags.items() | ||||
i.sort() | ||||
for k, n in i: | ||||
try: | ||||
r = repo.changelog.rev(n) | ||||
except KeyError: | ||||
r = "?" | ||||
print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n)) | ||||
mpm@selenic.com
|
r162 | elif cmd == "recover": | ||
repo.recover() | ||||
elif cmd == "undo": | ||||
repo.recover("undo") | ||||
mpm@selenic.com
|
r0 | elif cmd == "verify": | ||
filelinkrevs = {} | ||||
filenodes = {} | ||||
manifestchangeset = {} | ||||
changesets = revisions = files = 0 | ||||
mpm@selenic.com
|
r87 | errors = 0 | ||
mpm@selenic.com
|
r0 | |||
mpm@selenic.com
|
r87 | ui.status("checking changesets\n") | ||
mpm@selenic.com
|
r0 | for i in range(repo.changelog.count()): | ||
changesets += 1 | ||||
n = repo.changelog.node(i) | ||||
mpm@selenic.com
|
r87 | for p in repo.changelog.parents(n): | ||
if p not in repo.changelog.nodemap: | ||||
ui.warn("changeset %s has unknown parent %s\n" % | ||||
(hg.short(n), hg.short(p))) | ||||
errors += 1 | ||||
try: | ||||
changes = repo.changelog.read(n) | ||||
mpm@selenic.com
|
r145 | except Exception, inst: | ||
mpm@selenic.com
|
r87 | ui.warn("unpacking changeset %s: %s\n" % (short(n), inst)) | ||
errors += 1 | ||||
mpm@selenic.com
|
r0 | manifestchangeset[changes[0]] = n | ||
for f in changes[3]: | ||||
revisions += 1 | ||||
filelinkrevs.setdefault(f, []).append(i) | ||||
mpm@selenic.com
|
r87 | ui.status("checking manifests\n") | ||
mpm@selenic.com
|
r0 | for i in range(repo.manifest.count()): | ||
n = repo.manifest.node(i) | ||||
mpm@selenic.com
|
r87 | for p in repo.manifest.parents(n): | ||
if p not in repo.manifest.nodemap: | ||||
ui.warn("manifest %s has unknown parent %s\n" % | ||||
(hg.short(n), hg.short(p))) | ||||
errors += 1 | ||||
mpm@selenic.com
|
r0 | ca = repo.changelog.node(repo.manifest.linkrev(n)) | ||
cc = manifestchangeset[n] | ||||
if ca != cc: | ||||
mpm@selenic.com
|
r87 | ui.warn("manifest %s points to %s, not %s\n" % | ||
(hg.hex(n), hg.hex(ca), hg.hex(cc))) | ||||
errors += 1 | ||||
try: | ||||
mpm@selenic.com
|
r121 | delta = mdiff.patchtext(repo.manifest.delta(n)) | ||
except KeyboardInterrupt: | ||||
print "aborted" | ||||
sys.exit(0) | ||||
mpm@selenic.com
|
r93 | except Exception, inst: | ||
mpm@selenic.com
|
r87 | ui.warn("unpacking manifest %s: %s\n" % (hg.short(n), inst)) | ||
errors += 1 | ||||
mpm@selenic.com
|
r142 | |||
mpm@selenic.com
|
r121 | ff = [ l.split('\0') for l in delta.splitlines() ] | ||
for f, fn in ff: | ||||
filenodes.setdefault(f, {})[hg.bin(fn)] = 1 | ||||
mpm@selenic.com
|
r0 | |||
mpm@selenic.com
|
r87 | ui.status("crosschecking files in changesets and manifests\n") | ||
mpm@selenic.com
|
r0 | for f in filenodes: | ||
if f not in filelinkrevs: | ||||
mpm@selenic.com
|
r87 | ui.warn("file %s in manifest but not in changesets\n" % f) | ||
errors += 1 | ||||
mpm@selenic.com
|
r0 | |||
for f in filelinkrevs: | ||||
if f not in filenodes: | ||||
mpm@selenic.com
|
r121 | ui.warn("file %s in changeset but not in manifest\n" % f) | ||
mpm@selenic.com
|
r87 | errors += 1 | ||
mpm@selenic.com
|
r0 | |||
mpm@selenic.com
|
r87 | ui.status("checking files\n") | ||
mpm@selenic.com
|
r121 | ff = filenodes.keys() | ||
ff.sort() | ||||
for f in ff: | ||||
if f == "/dev/null": continue | ||||
mpm@selenic.com
|
r0 | files += 1 | ||
fl = repo.file(f) | ||||
mpm@selenic.com
|
r87 | nodes = { hg.nullid: 1 } | ||
mpm@selenic.com
|
r0 | for i in range(fl.count()): | ||
n = fl.node(i) | ||||
mpm@selenic.com
|
r17 | |||
mpm@selenic.com
|
r0 | if n not in filenodes[f]: | ||
mpm@selenic.com
|
r121 | ui.warn("%s: %d:%s not in manifests\n" % (f, i, hg.short(n))) | ||
print len(filenodes[f].keys()), fl.count(), f | ||||
mpm@selenic.com
|
r87 | errors += 1 | ||
mpm@selenic.com
|
r17 | else: | ||
del filenodes[f][n] | ||||
flr = fl.linkrev(n) | ||||
if flr not in filelinkrevs[f]: | ||||
mpm@selenic.com
|
r87 | ui.warn("%s:%s points to unexpected changeset rev %d\n" | ||
% (f, hg.short(n), fl.linkrev(n))) | ||||
errors += 1 | ||||
mpm@selenic.com
|
r17 | else: | ||
filelinkrevs[f].remove(flr) | ||||
# verify contents | ||||
mpm@selenic.com
|
r87 | try: | ||
t = fl.read(n) | ||||
mpm@selenic.com
|
r145 | except Exception, inst: | ||
ui.warn("unpacking file %s %s: %s\n" % (f, hg.short(n), inst)) | ||||
mpm@selenic.com
|
r87 | errors += 1 | ||
mpm@selenic.com
|
r17 | # verify parents | ||
mpm@selenic.com
|
r0 | (p1, p2) = fl.parents(n) | ||
if p1 not in nodes: | ||||
mpm@selenic.com
|
r87 | ui.warn("file %s:%s unknown parent 1 %s" % | ||
(f, hg.short(n), hg.short(p1))) | ||||
errors += 1 | ||||
mpm@selenic.com
|
r0 | if p2 not in nodes: | ||
mpm@selenic.com
|
r87 | ui.warn("file %s:%s unknown parent 2 %s" % | ||
(f, hg.short(n), hg.short(p1))) | ||||
errors += 1 | ||||
mpm@selenic.com
|
r17 | nodes[n] = 1 | ||
mpm@selenic.com
|
r0 | |||
mpm@selenic.com
|
r17 | # cross-check | ||
for flr in filelinkrevs[f]: | ||||
mpm@selenic.com
|
r87 | ui.warn("changeset rev %d not in %s\n" % (flr, f)) | ||
errors += 1 | ||||
mpm@selenic.com
|
r17 | |||
for node in filenodes[f]: | ||||
mpm@selenic.com
|
r87 | ui.warn("node %s in manifests not in %s\n" % (hg.hex(n), f)) | ||
errors += 1 | ||||
mpm@selenic.com
|
r0 | |||
mpm@selenic.com
|
r87 | ui.status("%d files, %d changesets, %d total revisions\n" % | ||
(files, changesets, revisions)) | ||||
if errors: | ||||
mpm@selenic.com
|
r93 | ui.warn("%d integrity errors encountered!\n" % errors) | ||
mpm@selenic.com
|
r87 | sys.exit(1) | ||
mpm@selenic.com
|
r158 | |||
elif cmd == "serve": | ||||
from mercurial import hgweb | ||||
soptions = {} | ||||
opts = [('p', 'port', 8000, 'listen port'), | ||||
('a', 'address', '', 'interface address'), | ||||
('n', 'name', os.getcwd(), 'repository name'), | ||||
('t', 'templates', "", 'template map') | ||||
] | ||||
args = fancyopts.fancyopts(args, opts, soptions, | ||||
'hg serve [options]') | ||||
hgweb.server(repo.root, soptions["name"], soptions["templates"], | ||||
soptions["address"], soptions["port"]) | ||||
mpm@selenic.com
|
r0 | |||
else: | ||||
mpm@selenic.com
|
r175 | if cmd: ui.warn("unknown command\n\n") | ||
mpm@selenic.com
|
r18 | help() | ||
mpm@selenic.com
|
r0 | sys.exit(1) | ||