Skip to content

Commit

Permalink
firefoxtree: use kwargs instead of args for pre 4.6 function signatur…
Browse files Browse the repository at this point in the history
…e (Bug 1505162)

Template keywords in Mercurial 4.6+ have a new signature and API.
When upgrading the signature backwards compatibility was required
with versions 4.4 and 4.5, so the arguments were collected in
`*args` and expanded after determining which API version is
required. It appears that the arguments were actually keyword
arguments, so `*args` is actually empty and we need to get
the arguments from `kwargs`. The behaviour in question can
be demonstrated with the following example:

  Python 2.7.13 (default, Nov  6 2018, 15:52:08)
  [GCC 7.3.0] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> def a(test):
  ...     print test
  ...
  >>> r = {'test': 'hello'}
  >>> a(**r)
  hello

Despite `test` being a positional argument in `a`, we can pass a
dict with a "test" key and the function call will execute correctly.

This commit changes the function to resolve it's arguments from
`kwargs` instead of `args` on Mercurial less than 4.6.
  • Loading branch information
cgsheeh committed Nov 6, 2018
1 parent ce64622 commit bc19539
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion hgext/firefoxtree/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,9 @@ def template_fxheads(*args, **kwargs):
ctx = context.resource(mapping, 'ctx')
cache = context.resource(mapping, 'cache')
else:
repo, ctx, templ, cache = args
repo = kwargs['repo']
ctx = kwargs['ctx']
cache = kwargs['cache']

labels = _getcachedlabels(repo, ctx, cache)
if not labels:
Expand Down

0 comments on commit bc19539

Please sign in to comment.