Mercurial > public > mercurial-scm > hg
comparison mercurial/dispatch.py @ 16609:d36a384bec87 stable
alias: inherit command optionalrepo flag (issue3298)
Commands working without a repository, like "init", are listed in
commands.norepo. Commands optionally using a repository, like "showconfig", are
listed in commands.optionalrepo. Command aliases were inheriting the former but
not the latter.
author | Patrick Mezard <patrick@mezard.eu> |
---|---|
date | Sat, 05 May 2012 12:21:22 +0200 |
parents | 46e9ed223d2c |
children | 525fdb738975 |
comparison
equal
deleted
inserted
replaced
16608:289fdcd4cb47 | 16609:d36a384bec87 |
---|---|
241 self.definition = definition | 241 self.definition = definition |
242 self.args = [] | 242 self.args = [] |
243 self.opts = [] | 243 self.opts = [] |
244 self.help = '' | 244 self.help = '' |
245 self.norepo = True | 245 self.norepo = True |
246 self.optionalrepo = False | |
246 self.badalias = False | 247 self.badalias = False |
247 | 248 |
248 try: | 249 try: |
249 aliases, entry = cmdutil.findcmd(self.name, cmdtable) | 250 aliases, entry = cmdutil.findcmd(self.name, cmdtable) |
250 for alias, e in cmdtable.iteritems(): | 251 for alias, e in cmdtable.iteritems(): |
310 self.fn, self.opts = tableentry | 311 self.fn, self.opts = tableentry |
311 | 312 |
312 self.args = aliasargs(self.fn, args) | 313 self.args = aliasargs(self.fn, args) |
313 if cmd not in commands.norepo.split(' '): | 314 if cmd not in commands.norepo.split(' '): |
314 self.norepo = False | 315 self.norepo = False |
316 if cmd in commands.optionalrepo.split(' '): | |
317 self.optionalrepo = True | |
315 if self.help.startswith("hg " + cmd): | 318 if self.help.startswith("hg " + cmd): |
316 # drop prefix in old-style help lines so hg shows the alias | 319 # drop prefix in old-style help lines so hg shows the alias |
317 self.help = self.help[4 + len(cmd):] | 320 self.help = self.help[4 + len(cmd):] |
318 self.__doc__ = self.fn.__doc__ | 321 self.__doc__ = self.fn.__doc__ |
319 | 322 |
368 pass | 371 pass |
369 | 372 |
370 cmdtable[aliasdef.name] = (aliasdef, aliasdef.opts, aliasdef.help) | 373 cmdtable[aliasdef.name] = (aliasdef, aliasdef.opts, aliasdef.help) |
371 if aliasdef.norepo: | 374 if aliasdef.norepo: |
372 commands.norepo += ' %s' % alias | 375 commands.norepo += ' %s' % alias |
376 if aliasdef.optionalrepo: | |
377 commands.optionalrepo += ' %s' % alias | |
373 | 378 |
374 def _parse(ui, args): | 379 def _parse(ui, args): |
375 options = {} | 380 options = {} |
376 cmdoptions = {} | 381 cmdoptions = {} |
377 | 382 |
493 lui.readconfig(os.path.join(path, ".hg", "hgrc"), path) | 498 lui.readconfig(os.path.join(path, ".hg", "hgrc"), path) |
494 | 499 |
495 return path, lui | 500 return path, lui |
496 | 501 |
497 def _checkshellalias(lui, ui, args): | 502 def _checkshellalias(lui, ui, args): |
498 norepo = commands.norepo | |
499 options = {} | 503 options = {} |
500 | 504 |
501 try: | 505 try: |
502 args = fancyopts.fancyopts(args, commands.globalopts, options) | 506 args = fancyopts.fancyopts(args, commands.globalopts, options) |
503 except fancyopts.getopt.GetoptError: | 507 except fancyopts.getopt.GetoptError: |
504 return | 508 return |
505 | 509 |
506 if not args: | 510 if not args: |
507 return | 511 return |
508 | 512 |
513 norepo = commands.norepo | |
514 optionalrepo = commands.optionalrepo | |
515 def restorecommands(): | |
516 commands.norepo = norepo | |
517 commands.optionalrepo = optionalrepo | |
518 | |
509 cmdtable = commands.table.copy() | 519 cmdtable = commands.table.copy() |
510 addaliases(lui, cmdtable) | 520 addaliases(lui, cmdtable) |
511 | 521 |
512 cmd = args[0] | 522 cmd = args[0] |
513 try: | 523 try: |
514 aliases, entry = cmdutil.findcmd(cmd, cmdtable, | 524 aliases, entry = cmdutil.findcmd(cmd, cmdtable, |
515 lui.configbool("ui", "strict")) | 525 lui.configbool("ui", "strict")) |
516 except (error.AmbiguousCommand, error.UnknownCommand): | 526 except (error.AmbiguousCommand, error.UnknownCommand): |
517 commands.norepo = norepo | 527 restorecommands() |
518 return | 528 return |
519 | 529 |
520 cmd = aliases[0] | 530 cmd = aliases[0] |
521 fn = entry[0] | 531 fn = entry[0] |
522 | 532 |
523 if cmd and util.safehasattr(fn, 'shell'): | 533 if cmd and util.safehasattr(fn, 'shell'): |
524 d = lambda: fn(ui, *args[1:]) | 534 d = lambda: fn(ui, *args[1:]) |
525 return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, [], {}) | 535 return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, [], {}) |
526 | 536 |
527 commands.norepo = norepo | 537 restorecommands() |
528 | 538 |
529 _loaded = set() | 539 _loaded = set() |
530 def _dispatch(req): | 540 def _dispatch(req): |
531 args = req.args | 541 args = req.args |
532 ui = req.ui | 542 ui = req.ui |