##// END OF EJS Templates
Add server side of hg:// protocol to hgweb
Add server side of hg:// protocol to hgweb

File last commit:

r56:ad2ea118 default
r61:1215bf60 default
Show More
hg
372 lines | 10.9 KiB | text/plain | TextLexer
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 #!/usr/bin/env python
#
# mercurial - a minimal scalable distributed SCM
mpm@selenic.com
Update version numbers
r16 # v0.4d "oedipa maas"
mpm@selenic.com
Add back links from file revisions to changeset revisions...
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
Add changegroup support
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
Add back links from file revisions to changeset revisions...
r0
mpm@selenic.com
Import time for hg history command
r23 import sys, os, time
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 from mercurial import hg, mdiff, fancyopts
mpm@selenic.com
Give a friendlier message when repo isn't found
r18 def help():
mpm@selenic.com
Import comments from patches
r49 print """\
mpm@selenic.com
Give a friendlier message when repo isn't found
r18 commands:
init create a new repository in this directory
branch <path> create a branch of <path> in this directory
merge <path> merge changes from <path> into local repository
checkout [changeset] checkout the latest or given changeset
status show new, missing, and changed files in working dir
add [files...] add the given files in the next commit
remove [files...] remove the given files in the next commit
addremove add all new files, delete all missing files
commit commit all changes to the repository
history show changeset history
log <file> show revision history of a single file
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
Document diff in help...
r22 diff [files...] diff working directory (or selected files)
mpm@selenic.com
Give a friendlier message when repo isn't found
r18 """
mpm@selenic.com
Support for 0, 1, or 2 diff revs
r33 def filterfiles(list, files):
l = [ x for x in list if x in files ]
mpm@selenic.com
diffdir tidy in preparation for arg handling
r31
mpm@selenic.com
Support for 0, 1, or 2 diff revs
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
diffdir tidy in preparation for arg handling
r31
mpm@selenic.com
Add export command
r34 def diff(files = None, node1 = None, node2 = None):
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])
else:
if not node1:
node1 = repo.current
(c, a, d) = repo.diffdir(repo.root, node1)
def read(f): return file(f).read()
change = repo.changelog.read(node1)
mmap = repo.manifest.read(change[0])
if files:
(c, a, d) = map(lambda x: filterfiles(x, files), (c, a, d))
for f in c:
to = repo.file(f).read(mmap[f])
tn = read(f)
sys.stdout.write(mdiff.unidiff(to, tn, f))
for f in a:
to = ""
tn = read(f)
sys.stdout.write(mdiff.unidiff(to, tn, f))
for f in d:
to = repo.file(f).read(mmap[f])
tn = ""
sys.stdout.write(mdiff.unidiff(to, tn, f))
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 options = {}
opts = [('v', 'verbose', None, 'verbose'),
('d', 'debug', None, 'debug')]
args = fancyopts.fancyopts(sys.argv[1:], opts, options,
'hg [options] <command> [command options] [files]')
try:
cmd = args[0]
args = args[1:]
except:
cmd = ""
ui = hg.ui(options["verbose"], options["debug"])
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
Give a friendlier message when repo isn't found
r18 elif cmd == "help":
help()
sys.exit(0)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 else:
mpm@selenic.com
Give a friendlier message when repo isn't found
r18 try:
repo = hg.repository(ui=ui)
except:
print "Unable to open repository"
sys.exit(0)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
if cmd == "checkout" or cmd == "co":
node = repo.changelog.tip()
mpm@selenic.com
Add lookup smarts everywhere...
r39 if args:
node = repo.changelog.lookup(args[0])
mpm@selenic.com
Add back links from file revisions to changeset revisions...
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
diffdir tidy in preparation for arg handling
r31 repo.commit(repo.current, args)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 else:
mpm@selenic.com
diffdir tidy in preparation for arg handling
r31 repo.commit(repo.current)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
elif cmd == "import" or cmd == "patch":
ioptions = {}
opts = [('p', 'strip', 1, 'path strip'),
mpm@selenic.com
Add -q option to import...
r50 ('b', 'base', "", 'base path'),
('q', 'quiet', "", 'silence diff')
]
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
args = fancyopts.fancyopts(args, opts, ioptions,
'hg import [options] <patch names>')
d = ioptions["base"]
strip = ioptions["strip"]
mpm@selenic.com
Add -q option to import...
r50 quiet = ioptions["quiet"] and "> /dev/null" or ""
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
for patch in args:
ui.status("applying %s\n" % patch)
mpm@selenic.com
Import comments from patches
r49 pf = os.path.join(d, patch)
text = ""
for l in file(pf):
if l[:3] == "---": break
text += l
mpm@selenic.com
Add -q option to import...
r50 if os.system("patch -p%d < %s %s" % (strip, pf, quiet)):
raise "patch failed!"
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 f = os.popen("lsdiff --strip %d %s" % (strip, pf))
mpm@selenic.com
Fix lsdiff filtering
r54 files = filter(None, map(lambda x: x.rstrip(), f.read().splitlines()))
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 f.close()
mpm@selenic.com
Import comments from patches
r49 repo.commit(repo.current, files, text)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
elif cmd == "status":
mpm@selenic.com
Support for 0, 1, or 2 diff revs
r33 (c, a, d) = repo.diffdir(repo.root, repo.current)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
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
Add export command
r34 revs = []
mpm@selenic.com
diffdir tidy in preparation for arg handling
r31
mpm@selenic.com
Support for 0, 1, or 2 diff revs
r33 if args:
mpm@selenic.com
Add improved rev lookup to diff and export
r38 doptions = {}
mpm@selenic.com
Support for 0, 1, or 2 diff revs
r33 opts = [('r', 'revision', [], 'revision')]
args = fancyopts.fancyopts(args, opts, doptions,
'hg diff [options] [files]')
mpm@selenic.com
Add improved rev lookup to diff and export
r38 revs = map(lambda x: repo.changelog.lookup(x), doptions['revision'])
mpm@selenic.com
Support for 0, 1, or 2 diff revs
r33
if len(revs) > 2:
print "too many revisions to diff"
sys.exit(1)
else:
mpm@selenic.com
Add export command
r34 diff(args, *revs)
mpm@selenic.com
Support for 0, 1, or 2 diff revs
r33
mpm@selenic.com
Add export command
r34 elif cmd == "export":
mpm@selenic.com
Add improved rev lookup to diff and export
r38 node = repo.changelog.lookup(args[0])
mpm@selenic.com
Add export command
r34 prev = repo.changelog.parents(node)[0]
diff(None, prev, node)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
mpm@selenic.com
Add changegroup support
r46 elif cmd == "debugchangegroup":
mpm@selenic.com
Add getchangegroup code to efficiently calculate and request a changegroup
r56 newer = repo.newer(map(repo.changelog.lookup, args))
mpm@selenic.com
Add changegroup support
r46 cg = repo.changegroup(newer)
sys.stdout.write(cg)
elif cmd == "debugaddchangegroup":
data = sys.stdin.read()
repo.addchangegroup(data)
mpm@selenic.com
Add getchangegroup code to efficiently calculate and request a changegroup
r56 elif cmd == "debuggetchangegroup":
if args:
other = hg.repository(ui, args[0])
print "building changegroup"
cg = repo.getchangegroup(other)
print "applying changegroup"
repo.addchangegroup(cg)
else:
print "missing source repository"
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 elif cmd == "addremove":
mpm@selenic.com
Make diffdir take a revision argument
r29 (c, a, d) = repo.diffdir(repo.root, repo.current)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
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
Show date in history
r21 print "date:", time.asctime(
time.localtime(float(changes[2].split(' ')[0])))
oxymoron@cinder.waste.org
Allow checkout by number or hash...
r11 print "files:", " ".join(changes[3])
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 print "description:"
print changes[4]
elif cmd == "log":
if args:
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)
else:
print "missing filename"
elif cmd == "dump":
if args:
r = repo.file(args[0])
n = r.tip()
mpm@selenic.com
Add lookup smarts everywhere...
r39 if len(args) > 1: n = r.lookup(args[1])
mpm@selenic.com
Add back links from file revisions to changeset revisions...
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
Add lookup smarts everywhere...
r39 n = repo.manifest.lookup(args[0])
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 m = repo.manifest.read(n)
files = m.keys()
files.sort()
for f in files:
print hg.hex(m[f]), f
mpm@selenic.com
Add debughash and debugindex commands
r24 elif cmd == "debughash":
f = repo.file(args[0])
print f.encodepath(args[0])
elif cmd == "debugindex":
r = hg.revlog(open, args[0], "")
print " rev offset length base linkrev"+\
" p1 p2 nodeid"
for i in range(r.count()):
e = r.index[i]
print "% 6d % 9d % 7d % 5d % 7d %s.. %s.. %s.." % (
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
Add back links from file revisions to changeset revisions...
r0 elif cmd == "merge":
if args:
other = hg.repository(ui, args[0])
repo.merge(other)
else:
print "missing source repository"
elif cmd == "verify":
filelinkrevs = {}
filenodes = {}
manifestchangeset = {}
changesets = revisions = files = 0
print "checking changesets"
for i in range(repo.changelog.count()):
changesets += 1
n = repo.changelog.node(i)
changes = repo.changelog.read(n)
manifestchangeset[changes[0]] = n
for f in changes[3]:
revisions += 1
filelinkrevs.setdefault(f, []).append(i)
print "checking manifests"
for i in range(repo.manifest.count()):
n = repo.manifest.node(i)
ca = repo.changelog.node(repo.manifest.linkrev(n))
cc = manifestchangeset[n]
if ca != cc:
print "manifest %s points to %s, not %s" % \
(hg.hex(n), hg.hex(ca), hg.hex(cc))
m = repo.manifest.read(n)
for f, fn in m.items():
filenodes.setdefault(f, {})[fn] = 1
print "crosschecking files in changesets and manifests"
for f in filenodes:
if f not in filelinkrevs:
print "file %s in manifest but not in changesets"
for f in filelinkrevs:
if f not in filenodes:
print "file %s in changeset but not in manifest"
print "checking files"
for f in filenodes:
files += 1
fl = repo.file(f)
nodes = {"\0"*20: 1}
for i in range(fl.count()):
n = fl.node(i)
mpm@selenic.com
Make hg verify do more thorough cross-checking.
r17
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 if n not in filenodes[f]:
print "%s:%s not in manifests" % (f, hg.hex(n))
mpm@selenic.com
Make hg verify do more thorough cross-checking.
r17 else:
del filenodes[f][n]
flr = fl.linkrev(n)
if flr not in filelinkrevs[f]:
oxymoron@cinder.waste.org
Allow checkout by number or hash...
r11 print "%s:%s points to unexpected changeset rev %d" \
% (f, hg.hex(n), fl.linkrev(n))
mpm@selenic.com
Make hg verify do more thorough cross-checking.
r17 else:
filelinkrevs[f].remove(flr)
# verify contents
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 t = fl.read(n)
mpm@selenic.com
Make hg verify do more thorough cross-checking.
r17
# verify parents
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 (p1, p2) = fl.parents(n)
if p1 not in nodes:
print "%s:%s unknown parent 1 %s" % (f, hg.hex(n), hg.hex(p1))
if p2 not in nodes:
print "file %s:%s unknown parent %s" % (f, hg.hex(n), hg.hex(p1))
mpm@selenic.com
Make hg verify do more thorough cross-checking.
r17 nodes[n] = 1
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
mpm@selenic.com
Make hg verify do more thorough cross-checking.
r17 # cross-check
for flr in filelinkrevs[f]:
print "changeset rev %d not in %s" % (flr, f)
for node in filenodes[f]:
print "node %s in manifests not in %s" % (hg.hex(n), f)
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0
print "%d files, %d changesets, %d total revisions" % (files, changesets,
revisions)
else:
mpm@selenic.com
Give a friendlier message when repo isn't found
r18 print "unknown command\n"
help()
mpm@selenic.com
Add back links from file revisions to changeset revisions...
r0 sys.exit(1)