comparison hg @ 209:63af1db35611

Beginning of new command parsing interface -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Beginning of new command parsing interface This adds commands.py, with a primary interface dispatch(args) Dispatch searches a table of known commands, handles switches, sets up a repo object if appropriate, and dispatches the command. It also handles KeyboardInterrupt and can handle similar exceptions in the future. If the command is unknown, it falls through to the current command handler. Commands currently handled by the new scheme: help, init, and annotate manifest hash: 134cd032c880985e3f92f82efb8b629dd862ba4c -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCnXEGywK+sNU5EO8RAuDAAJ9q7K4w7qGVWv1NWjCPFGO/UJc6VQCdEhMQ sBBlSRzah9QPy8K94catZyg= =wuRf -----END PGP SIGNATURE-----
author mpm@selenic.com
date Wed, 01 Jun 2005 00:25:42 -0800
parents ec327cf0d3a9
children d2badbd7d1ad
comparison
equal deleted inserted replaced
208:0a37e9c8ad6c 209:63af1db35611
15 # psyco.full() 15 # psyco.full()
16 # except: 16 # except:
17 # pass 17 # pass
18 18
19 import sys, os, time 19 import sys, os, time
20 from mercurial import hg, mdiff, fancyopts, ui 20 from mercurial import hg, mdiff, fancyopts, ui, commands
21 21
22 def help(): 22 def help():
23 ui.status("""\ 23 ui.status("""\
24 commands: 24 commands:
25 25
90 sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) 90 sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f))
91 for f in d: 91 for f in d:
92 to = repo.file(f).read(mmap[f]) 92 to = repo.file(f).read(mmap[f])
93 tn = "" 93 tn = ""
94 sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) 94 sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f))
95
96
97 try:
98 sys.exit(commands.dispatch(sys.argv[1:]))
99 except commands.UnknownCommand:
100 # fall through
101 pass
95 102
96 options = {} 103 options = {}
97 opts = [('v', 'verbose', None, 'verbose'), 104 opts = [('v', 'verbose', None, 'verbose'),
98 ('d', 'debug', None, 'debug'), 105 ('d', 'debug', None, 'debug'),
99 ('q', 'quiet', None, 'quiet'), 106 ('q', 'quiet', None, 'quiet'),
241 if not args: args = [ relpath ] 248 if not args: args = [ relpath ]
242 else: args = [ os.path.join(relpath, x) for x in args ] 249 else: args = [ os.path.join(relpath, x) for x in args ]
243 250
244 diff(args, *revs) 251 diff(args, *revs)
245 252
246 elif cmd == "annotate":
247 bcache = {}
248
249 def getnode(rev):
250 return hg.short(repo.changelog.node(rev))
251
252 def getname(rev):
253 try:
254 return bcache[rev]
255 except KeyError:
256 cl = repo.changelog.read(repo.changelog.node(rev))
257 name = cl[1]
258 f = name.find('@')
259 if f >= 0:
260 name = name[:f]
261 bcache[rev] = name
262 return name
263
264 aoptions = {}
265 opts = [('r', 'revision', '', 'revision'),
266 ('u', 'user', None, 'show user'),
267 ('n', 'number', None, 'show revision number'),
268 ('c', 'changeset', None, 'show changeset')]
269
270 args = fancyopts.fancyopts(args, opts, aoptions,
271 'hg annotate [-u] [-c] [-n] [-r id] [files]')
272
273 opmap = [['user', getname], ['number', str], ['changeset', getnode]]
274 if not aoptions['user'] and not aoptions['changeset']:
275 aoptions['number'] = 1
276
277 if args:
278 if relpath: args = [ os.path.join(relpath, x) for x in args ]
279 node = repo.current
280 if aoptions['revision']:
281 node = repo.changelog.lookup(aoptions['revision'])
282 change = repo.changelog.read(node)
283 mmap = repo.manifest.read(change[0])
284 maxuserlen = 0
285 maxchangelen = 0
286 for f in args:
287 lines = repo.file(f).annotate(mmap[f])
288 pieces = []
289
290 for o, f in opmap:
291 if aoptions[o]:
292 l = [ f(n) for n,t in lines ]
293 m = max(map(len, l))
294 pieces.append([ "%*s" % (m, x) for x in l])
295
296 for p,l in zip(zip(*pieces), lines):
297 sys.stdout.write(" ".join(p) + ": " + l[1])
298
299 elif cmd == "export": 253 elif cmd == "export":
300 node = repo.lookup(args[0]) 254 node = repo.lookup(args[0])
301 prev, other = repo.changelog.parents(node) 255 prev, other = repo.changelog.parents(node)
302 change = repo.changelog.read(node) 256 change = repo.changelog.read(node)
303 print "# HG changeset patch" 257 print "# HG changeset patch"