##// END OF EJS Templates
migrate remaining commands...
mpm@selenic.com -
r248:b7645b3c default
parent child Browse files
Show More
@@ -17,105 +17,7 b''
17 # pass
17 # pass
18
18
19 import sys
19 import sys
20 from mercurial import hg, fancyopts, ui, commands
20 from mercurial import commands
21
22 try:
23 sys.exit(commands.dispatch(sys.argv[1:]))
24 except commands.UnknownCommand:
25 # fall through
26 pass
27
28 options = {}
29 opts = [('v', 'verbose', None, 'verbose'),
30 ('d', 'debug', None, 'debug'),
31 ('q', 'quiet', None, 'quiet'),
32 ('y', 'noninteractive', None, 'run non-interactively'),
33 ]
34
35 args = fancyopts.fancyopts(sys.argv[1:], opts, options,
36 'hg [options] <command> [command options] [files]')
37
38 try:
39 cmd = args[0]
40 args = args[1:]
41 except:
42 cmd = "help"
43
44 ui = ui.ui(options["verbose"], options["debug"], options["quiet"],
45 not options["noninteractive"])
46
47 try:
48 repo = hg.repository(ui=ui)
49 except IOError:
50 ui.warn("Unable to open repository\n")
51 sys.exit(0)
52
53 if cmd == "debugchangegroup":
54 newer = repo.newer(map(repo.lookup, args))
55 for chunk in repo.changegroup(newer):
56 sys.stdout.write(chunk)
57
58 elif cmd == "debugaddchangegroup":
59 data = sys.stdin.read()
60 repo.addchangegroup(data)
61
62 elif cmd == "dump":
63 if args:
64 r = repo.file(args[0])
65 n = r.tip()
66 if len(args) > 1: n = r.lookup(args[1])
67 sys.stdout.write(r.read(n))
68 else:
69 print "missing filename"
70
21
71 elif cmd == "dumpmanifest":
22 sys.exit(commands.dispatch(sys.argv[1:]))
72 n = repo.manifest.tip()
73 if len(args) > 0:
74 n = repo.manifest.lookup(args[0])
75 m = repo.manifest.read(n)
76 files = m.keys()
77 files.sort()
78
79 for f in files:
80 print hg.hex(m[f]), f
81
82 elif cmd == "debugindex":
83 if ".hg" not in args[0]:
84 args[0] = ".hg/data/" + repo.file(args[0]).encodepath(args[0]) + "i"
85
86 r = hg.revlog(open, args[0], "")
87 print " rev offset length base linkrev"+\
88 " p1 p2 nodeid"
89 for i in range(r.count()):
90 e = r.index[i]
91 print "% 6d % 9d % 7d % 6d % 7d %s.. %s.. %s.." % (
92 i, e[0], e[1], e[2], e[3],
93 hg.hex(e[4][:5]), hg.hex(e[5][:5]), hg.hex(e[6][:5]))
94
23
95 elif cmd == "debugindexdot":
96 if ".hg" not in args[0]:
97 args[0] = ".hg/data/" + repo.file(args[0]).encodepath(args[0]) + "i"
98
99 r = hg.revlog(open, args[0], "")
100 print "digraph G {"
101 for i in range(r.count()):
102 e = r.index[i]
103 print "\t%d -> %d" % (r.rev(e[4]), i)
104 if e[5] != hg.nullid:
105 print "\t%d -> %d" % (r.rev(e[5]), i)
106 print "}"
107
108 elif cmd == "tags":
109 repo.lookup(0) # prime the cache
110 i = repo.tags.items()
111 i.sort()
112 for k, n in i:
113 try:
114 r = repo.changelog.rev(n)
115 except KeyError:
116 r = "?"
117 print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n))
118
119 else:
120 if cmd: ui.warn("unknown command\n\n")
121 sys.exit(1)
@@ -151,6 +151,12 b' def branch(ui, path):'
151 # this should eventually support remote repos
151 # this should eventually support remote repos
152 os.system("cp -al %s/.hg .hg" % path)
152 os.system("cp -al %s/.hg .hg" % path)
153
153
154 def cat(ui, repo, file, rev = []):
155 r = repo.file(file)
156 n = r.tip()
157 if rev: n = r.lookup(rev)
158 sys.stdout.write(r.read(n))
159
154 def checkout(ui, repo, changeset=None):
160 def checkout(ui, repo, changeset=None):
155 '''checkout a given changeset or the current tip'''
161 '''checkout a given changeset or the current tip'''
156 (c, a, d, u) = repo.diffdir(repo.root)
162 (c, a, d, u) = repo.diffdir(repo.root)
@@ -167,6 +173,35 b' def commit(ui, repo, *files):'
167 """commit the specified files or all outstanding changes"""
173 """commit the specified files or all outstanding changes"""
168 repo.commit(relpath(repo, files))
174 repo.commit(relpath(repo, files))
169
175
176 def debugaddchangegroup(ui, repo):
177 data = sys.stdin.read()
178 repo.addchangegroup(data)
179
180 def debugchangegroup(ui, repo, roots):
181 newer = repo.newer(map(repo.lookup, roots))
182 for chunk in repo.changegroup(newer):
183 sys.stdout.write(chunk)
184
185 def debugindex(ui, file):
186 r = hg.revlog(open, file, "")
187 print " rev offset length base linkrev"+\
188 " p1 p2 nodeid"
189 for i in range(r.count()):
190 e = r.index[i]
191 print "% 6d % 9d % 7d % 6d % 7d %s.. %s.. %s.." % (
192 i, e[0], e[1], e[2], e[3],
193 hg.hex(e[4][:5]), hg.hex(e[5][:5]), hg.hex(e[6][:5]))
194
195 def debugindexdot(ui, file):
196 r = hg.revlog(open, file, "")
197 print "digraph G {"
198 for i in range(r.count()):
199 e = r.index[i]
200 print "\t%d -> %d" % (r.rev(e[4]), i)
201 if e[5] != hg.nullid:
202 print "\t%d -> %d" % (r.rev(e[5]), i)
203 print "}"
204
170 def diff(ui, repo, *files, **opts):
205 def diff(ui, repo, *files, **opts):
171 revs = []
206 revs = []
172 if opts['rev']:
207 if opts['rev']:
@@ -300,6 +335,17 b' def log(ui, repo, f):'
300 print changes[4].rstrip()
335 print changes[4].rstrip()
301 print
336 print
302
337
338 def manifest(ui, repo, rev = []):
339 n = repo.manifest.tip()
340 if rev:
341 n = repo.manifest.lookup(rev)
342 m = repo.manifest.read(n)
343 files = m.keys()
344 files.sort()
345
346 for f in files:
347 print hg.hex(m[f]), f
348
303 def parents(ui, repo, node = None):
349 def parents(ui, repo, node = None):
304 '''show the parents of the current working dir'''
350 '''show the parents of the current working dir'''
305 if node:
351 if node:
@@ -381,6 +427,17 b' def status(ui, repo):'
381 for f in d: print "R", f
427 for f in d: print "R", f
382 for f in u: print "?", f
428 for f in u: print "?", f
383
429
430 def tags(ui, repo):
431 repo.lookup(0) # prime the cache
432 i = repo.tags.items()
433 i.sort()
434 for k, n in i:
435 try:
436 r = repo.changelog.rev(n)
437 except KeyError:
438 r = "?"
439 print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n))
440
384 def tip(ui, repo):
441 def tip(ui, repo):
385 n = repo.changelog.tip()
442 n = repo.changelog.tip()
386 t = repo.changelog.rev(n)
443 t = repo.changelog.rev(n)
@@ -403,8 +460,13 b' table = {'
403 ('c', 'changeset', None, 'show changeset')],
460 ('c', 'changeset', None, 'show changeset')],
404 'hg annotate [-u] [-c] [-n] [-r id] [files]'),
461 'hg annotate [-u] [-c] [-n] [-r id] [files]'),
405 "branch|clone": (branch, [], 'hg branch [path]'),
462 "branch|clone": (branch, [], 'hg branch [path]'),
463 "cat|dump": (cat, [], 'hg cat <file> [rev]'),
406 "checkout|co": (checkout, [], 'hg checkout [changeset]'),
464 "checkout|co": (checkout, [], 'hg checkout [changeset]'),
407 "commit|ci": (commit, [], 'hg commit [files]'),
465 "commit|ci": (commit, [], 'hg commit [files]'),
466 "debugaddchangegroup": (debugaddchangegroup, [], 'debugaddchangegroup'),
467 "debugchangegroup": (debugchangegroup, [], 'debugchangegroup [roots]'),
468 "debugindex": (debugindex, [], 'debugindex <file>'),
469 "debugindexdot": (debugindexdot, [], 'debugindexdot <file>'),
408 "diff": (diff, [('r', 'rev', [], 'revision')],
470 "diff": (diff, [('r', 'rev', [], 'revision')],
409 'hg diff [-r A] [-r B] [files]'),
471 'hg diff [-r A] [-r B] [files]'),
410 "export": (export, [], "hg export <changeset>"),
472 "export": (export, [], "hg export <changeset>"),
@@ -414,6 +476,7 b' table = {'
414 "help": (help, [], 'hg help [command]'),
476 "help": (help, [], 'hg help [command]'),
415 "init": (init, [], 'hg init'),
477 "init": (init, [], 'hg init'),
416 "log": (log, [], 'hg log <file>'),
478 "log": (log, [], 'hg log <file>'),
479 "manifest|dumpmanifest": (manifest, [], 'hg manifest [rev]'),
417 "parents": (parents, [], 'hg parents [node]'),
480 "parents": (parents, [], 'hg parents [node]'),
418 "patch|import": (patch,
481 "patch|import": (patch,
419 [('p', 'strip', 1, 'path strip'),
482 [('p', 'strip', 1, 'path strip'),
@@ -438,12 +501,13 b' table = {'
438 ('t', 'templates', "", 'template map')],
501 ('t', 'templates', "", 'template map')],
439 "hg serve [options]"),
502 "hg serve [options]"),
440 "status": (status, [], 'hg status'),
503 "status": (status, [], 'hg status'),
504 "tags": (tags, [], 'hg tags'),
441 "tip": (tip, [], 'hg tip'),
505 "tip": (tip, [], 'hg tip'),
442 "undo": (undo, [], 'hg undo'),
506 "undo": (undo, [], 'hg undo'),
443 "verify": (verify, [], 'hg verify'),
507 "verify": (verify, [], 'hg verify'),
444 }
508 }
445
509
446 norepo = "init branch help"
510 norepo = "init branch help debugindex debugindexdot"
447
511
448 def find(cmd):
512 def find(cmd):
449 i = None
513 i = None
General Comments 0
You need to be logged in to leave comments. Login now