Mercurial > public > mercurial-scm > hg
comparison mercurial/dispatch.py @ 29087:ad1bdea43965
dispatch: defer environment variable resolution in alias commands (BC)
Before this patch, if there are environment variables in an alias command,
they will be expanded immediately when we first see the alias.
This will cause issues with chg, because environment variable updates will
not propagate to expanded arguments.
This patch makes "args" of "cmdalias" a property that will be calculated
every time when accessed.
author | Jun Wu <quark@fb.com> |
---|---|
date | Sat, 07 May 2016 00:16:58 +0100 |
parents | 86db5cb55d46 |
children | b197e2aba703 |
comparison
equal
deleted
inserted
replaced
29086:fe50341de1ff | 29087:ad1bdea43965 |
---|---|
382 def __init__(self, name, definition, cmdtable, source): | 382 def __init__(self, name, definition, cmdtable, source): |
383 self.name = self.cmd = name | 383 self.name = self.cmd = name |
384 self.cmdname = '' | 384 self.cmdname = '' |
385 self.definition = definition | 385 self.definition = definition |
386 self.fn = None | 386 self.fn = None |
387 self.args = [] | 387 self.givenargs = [] |
388 self.opts = [] | 388 self.opts = [] |
389 self.help = '' | 389 self.help = '' |
390 self.badalias = None | 390 self.badalias = None |
391 self.unknowncmd = False | 391 self.unknowncmd = False |
392 self.source = source | 392 self.source = source |
430 except ValueError as inst: | 430 except ValueError as inst: |
431 self.badalias = (_("error in definition for alias '%s': %s") | 431 self.badalias = (_("error in definition for alias '%s': %s") |
432 % (self.name, inst)) | 432 % (self.name, inst)) |
433 return | 433 return |
434 self.cmdname = cmd = args.pop(0) | 434 self.cmdname = cmd = args.pop(0) |
435 args = map(util.expandpath, args) | 435 self.givenargs = args |
436 | 436 |
437 for invalidarg in ("--cwd", "-R", "--repository", "--repo", "--config"): | 437 for invalidarg in ("--cwd", "-R", "--repository", "--repo", "--config"): |
438 if _earlygetopt([invalidarg], args): | 438 if _earlygetopt([invalidarg], args): |
439 self.badalias = (_("error in definition for alias '%s': %s may " | 439 self.badalias = (_("error in definition for alias '%s': %s may " |
440 "only be given on the command line") | 440 "only be given on the command line") |
446 if len(tableentry) > 2: | 446 if len(tableentry) > 2: |
447 self.fn, self.opts, self.help = tableentry | 447 self.fn, self.opts, self.help = tableentry |
448 else: | 448 else: |
449 self.fn, self.opts = tableentry | 449 self.fn, self.opts = tableentry |
450 | 450 |
451 self.args = aliasargs(self.fn, args) | |
452 if self.help.startswith("hg " + cmd): | 451 if self.help.startswith("hg " + cmd): |
453 # drop prefix in old-style help lines so hg shows the alias | 452 # drop prefix in old-style help lines so hg shows the alias |
454 self.help = self.help[4 + len(cmd):] | 453 self.help = self.help[4 + len(cmd):] |
455 self.__doc__ = self.fn.__doc__ | 454 self.__doc__ = self.fn.__doc__ |
456 | 455 |
459 % (self.name, cmd)) | 458 % (self.name, cmd)) |
460 self.unknowncmd = True | 459 self.unknowncmd = True |
461 except error.AmbiguousCommand: | 460 except error.AmbiguousCommand: |
462 self.badalias = (_("alias '%s' resolves to ambiguous command '%s'") | 461 self.badalias = (_("alias '%s' resolves to ambiguous command '%s'") |
463 % (self.name, cmd)) | 462 % (self.name, cmd)) |
463 | |
464 @property | |
465 def args(self): | |
466 args = map(util.expandpath, self.givenargs) | |
467 return aliasargs(self.fn, args) | |
464 | 468 |
465 def __getattr__(self, name): | 469 def __getattr__(self, name): |
466 adefaults = {'norepo': True, 'optionalrepo': False, 'inferrepo': False} | 470 adefaults = {'norepo': True, 'optionalrepo': False, 'inferrepo': False} |
467 if name not in adefaults: | 471 if name not in adefaults: |
468 raise AttributeError(name) | 472 raise AttributeError(name) |