Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/exthelper.py @ 41069:0358cca1dccf
exthelper: reintroduce the ability to register revsets
I think this is what Yuya and Boris agreed on.[1] This happens *after* the
extsetup phase now (and after the _aftercallback notifications). But this is
trivial, mergeable between exthelper instances, and doesn't need to have the
extension name supplied when registering.
The test needed updating so that extsetup() takes a `ui` argument, as exthelper
isn't trying to be backward compatible with 1.3.1.
[1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2018-December/125888.html
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 27 Dec 2018 21:26:17 -0500 |
parents | 7250cbaabde0 |
children | 70ca0e846d25 |
rev | line source |
---|---|
41047
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
1 # Copyright 2012 Logilab SA <contact@logilab.fr> |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
2 # Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
3 # Octobus <contact@octobus.net> |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
4 # |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
7 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
8 ##################################################################### |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
9 ### Extension helper ### |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
10 ##################################################################### |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
11 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
12 from __future__ import absolute_import |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
13 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
14 from . import ( |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
15 commands, |
41063
7250cbaabde0
exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents:
41060
diff
changeset
|
16 error, |
41047
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
17 extensions, |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
18 registrar, |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
19 ) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
20 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
21 class exthelper(object): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
22 """Helper for modular extension setup |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
23 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
24 A single helper should be instantiated for each extension. Helper |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
25 methods are then used as decorators for various purpose. |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
26 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
27 All decorators return the original function and may be chained. |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
28 """ |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
29 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
30 def __init__(self): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
31 self._uipopulatecallables = [] |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
32 self._uicallables = [] |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
33 self._extcallables = [] |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
34 self._repocallables = [] |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
35 self._commandwrappers = [] |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
36 self._extcommandwrappers = [] |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
37 self._functionwrappers = [] |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
38 self._duckpunchers = [] |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
39 self.cmdtable = {} |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
40 self.command = registrar.command(self.cmdtable) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
41 self.configtable = {} |
41048
c1476d095d57
exthelper: simplify configitem registration
Matt Harbison <matt_harbison@yahoo.com>
parents:
41047
diff
changeset
|
42 self.configitem = registrar.configitem(self.configtable) |
41069
0358cca1dccf
exthelper: reintroduce the ability to register revsets
Matt Harbison <matt_harbison@yahoo.com>
parents:
41063
diff
changeset
|
43 self.revsetpredicate = registrar.revsetpredicate() |
41047
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
44 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
45 def merge(self, other): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
46 self._uicallables.extend(other._uicallables) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
47 self._uipopulatecallables.extend(other._uipopulatecallables) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
48 self._extcallables.extend(other._extcallables) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
49 self._repocallables.extend(other._repocallables) |
41069
0358cca1dccf
exthelper: reintroduce the ability to register revsets
Matt Harbison <matt_harbison@yahoo.com>
parents:
41063
diff
changeset
|
50 self.revsetpredicate._table.update(other.revsetpredicate._table) |
41047
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
51 self._commandwrappers.extend(other._commandwrappers) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
52 self._extcommandwrappers.extend(other._extcommandwrappers) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
53 self._functionwrappers.extend(other._functionwrappers) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
54 self._duckpunchers.extend(other._duckpunchers) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
55 self.cmdtable.update(other.cmdtable) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
56 for section, items in other.configtable.iteritems(): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
57 if section in self.configtable: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
58 self.configtable[section].update(items) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
59 else: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
60 self.configtable[section] = items |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
61 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
62 def finaluisetup(self, ui): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
63 """Method to be used as the extension uisetup |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
64 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
65 The following operations belong here: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
66 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
67 - Changes to ui.__class__ . The ui object that will be used to run the |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
68 command has not yet been created. Changes made here will affect ui |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
69 objects created after this, and in particular the ui that will be |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
70 passed to runcommand |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
71 - Command wraps (extensions.wrapcommand) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
72 - Changes that need to be visible to other extensions: because |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
73 initialization occurs in phases (all extensions run uisetup, then all |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
74 run extsetup), a change made here will be visible to other extensions |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
75 during extsetup |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
76 - Monkeypatch or wrap function (extensions.wrapfunction) of dispatch |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
77 module members |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
78 - Setup of pre-* and post-* hooks |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
79 - pushkey setup |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
80 """ |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
81 for cont, funcname, func in self._duckpunchers: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
82 setattr(cont, funcname, func) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
83 for command, wrapper, opts in self._commandwrappers: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
84 entry = extensions.wrapcommand(commands.table, command, wrapper) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
85 if opts: |
41063
7250cbaabde0
exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents:
41060
diff
changeset
|
86 for opt in opts: |
7250cbaabde0
exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents:
41060
diff
changeset
|
87 entry[1].append(opt) |
41047
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
88 for cont, funcname, wrapper in self._functionwrappers: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
89 extensions.wrapfunction(cont, funcname, wrapper) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
90 for c in self._uicallables: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
91 c(ui) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
92 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
93 def finaluipopulate(self, ui): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
94 """Method to be used as the extension uipopulate |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
95 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
96 This is called once per ui instance to: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
97 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
98 - Set up additional ui members |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
99 - Update configuration by ``ui.setconfig()`` |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
100 - Extend the class dynamically |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
101 """ |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
102 for c in self._uipopulatecallables: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
103 c(ui) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
104 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
105 def finalextsetup(self, ui): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
106 """Method to be used as a the extension extsetup |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
107 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
108 The following operations belong here: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
109 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
110 - Changes depending on the status of other extensions. (if |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
111 extensions.find('mq')) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
112 - Add a global option to all commands |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
113 """ |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
114 knownexts = {} |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
115 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
116 for ext, command, wrapper, opts in self._extcommandwrappers: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
117 if ext not in knownexts: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
118 try: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
119 e = extensions.find(ext) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
120 except KeyError: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
121 # Extension isn't enabled, so don't bother trying to wrap |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
122 # it. |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
123 continue |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
124 knownexts[ext] = e.cmdtable |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
125 entry = extensions.wrapcommand(knownexts[ext], command, wrapper) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
126 if opts: |
41063
7250cbaabde0
exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents:
41060
diff
changeset
|
127 for opt in opts: |
7250cbaabde0
exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents:
41060
diff
changeset
|
128 entry[1].append(opt) |
41047
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
129 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
130 for c in self._extcallables: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
131 c(ui) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
132 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
133 def finalreposetup(self, ui, repo): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
134 """Method to be used as the extension reposetup |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
135 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
136 The following operations belong here: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
137 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
138 - All hooks but pre-* and post-* |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
139 - Modify configuration variables |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
140 - Changes to repo.__class__, repo.dirstate.__class__ |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
141 """ |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
142 for c in self._repocallables: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
143 c(ui, repo) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
144 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
145 def uisetup(self, call): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
146 """Decorated function will be executed during uisetup |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
147 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
148 example:: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
149 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
150 @eh.uisetup |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
151 def setupbabar(ui): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
152 print 'this is uisetup!' |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
153 """ |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
154 self._uicallables.append(call) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
155 return call |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
156 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
157 def uipopulate(self, call): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
158 """Decorated function will be executed during uipopulate |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
159 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
160 example:: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
161 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
162 @eh.uipopulate |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
163 def setupfoo(ui): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
164 print 'this is uipopulate!' |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
165 """ |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
166 self._uipopulatecallables.append(call) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
167 return call |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
168 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
169 def extsetup(self, call): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
170 """Decorated function will be executed during extsetup |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
171 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
172 example:: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
173 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
174 @eh.extsetup |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
175 def setupcelestine(ui): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
176 print 'this is extsetup!' |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
177 """ |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
178 self._extcallables.append(call) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
179 return call |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
180 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
181 def reposetup(self, call): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
182 """Decorated function will be executed during reposetup |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
183 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
184 example:: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
185 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
186 @eh.reposetup |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
187 def setupzephir(ui, repo): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
188 print 'this is reposetup!' |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
189 """ |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
190 self._repocallables.append(call) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
191 return call |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
192 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
193 def wrapcommand(self, command, extension=None, opts=None): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
194 """Decorated function is a command wrapper |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
195 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
196 The name of the command must be given as the decorator argument. |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
197 The wrapping is installed during `uisetup`. |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
198 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
199 If the second option `extension` argument is provided, the wrapping |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
200 will be applied in the extension commandtable. This argument must be a |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
201 string that will be searched using `extension.find` if not found and |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
202 Abort error is raised. If the wrapping applies to an extension, it is |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
203 installed during `extsetup`. |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
204 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
205 example:: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
206 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
207 @eh.wrapcommand('summary') |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
208 def wrapsummary(orig, ui, repo, *args, **kwargs): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
209 ui.note('Barry!') |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
210 return orig(ui, repo, *args, **kwargs) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
211 |
41063
7250cbaabde0
exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents:
41060
diff
changeset
|
212 The `opts` argument allows specifying a list of tuples for additional |
7250cbaabde0
exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents:
41060
diff
changeset
|
213 arguments for the command. See ``mercurial.fancyopts.fancyopts()`` for |
7250cbaabde0
exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents:
41060
diff
changeset
|
214 the format of the tuple. |
41047
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
215 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
216 """ |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
217 if opts is None: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
218 opts = [] |
41063
7250cbaabde0
exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents:
41060
diff
changeset
|
219 else: |
7250cbaabde0
exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents:
41060
diff
changeset
|
220 for opt in opts: |
7250cbaabde0
exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents:
41060
diff
changeset
|
221 if not isinstance(opt, tuple): |
7250cbaabde0
exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents:
41060
diff
changeset
|
222 raise error.ProgrammingError('opts must be list of tuples') |
7250cbaabde0
exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents:
41060
diff
changeset
|
223 if len(opt) not in (4, 5): |
7250cbaabde0
exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents:
41060
diff
changeset
|
224 msg = 'each opt tuple must contain 4 or 5 values' |
7250cbaabde0
exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents:
41060
diff
changeset
|
225 raise error.ProgrammingError(msg) |
7250cbaabde0
exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents:
41060
diff
changeset
|
226 |
41047
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
227 def dec(wrapper): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
228 if extension is None: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
229 self._commandwrappers.append((command, wrapper, opts)) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
230 else: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
231 self._extcommandwrappers.append((extension, command, wrapper, |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
232 opts)) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
233 return wrapper |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
234 return dec |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
235 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
236 def wrapfunction(self, container, funcname): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
237 """Decorated function is a function wrapper |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
238 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
239 This function takes two arguments, the container and the name of the |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
240 function to wrap. The wrapping is performed during `uisetup`. |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
241 (there is no extension support) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
242 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
243 example:: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
244 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
245 @eh.function(discovery, 'checkheads') |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
246 def wrapfunction(orig, *args, **kwargs): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
247 ui.note('His head smashed in and his heart cut out') |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
248 return orig(*args, **kwargs) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
249 """ |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
250 def dec(wrapper): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
251 self._functionwrappers.append((container, funcname, wrapper)) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
252 return wrapper |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
253 return dec |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
254 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
255 def addattr(self, container, funcname): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
256 """Decorated function is to be added to the container |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
257 |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
258 This function takes two arguments, the container and the name of the |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
259 function to wrap. The wrapping is performed during `uisetup`. |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
260 |
41060
f7863606d4ff
exthelper: add a cautionary note about adding attributes to containers
Matt Harbison <matt_harbison@yahoo.com>
parents:
41059
diff
changeset
|
261 Adding attributes to a container like this is discouraged, because the |
f7863606d4ff
exthelper: add a cautionary note about adding attributes to containers
Matt Harbison <matt_harbison@yahoo.com>
parents:
41059
diff
changeset
|
262 container modification is visible even in repositories that do not |
f7863606d4ff
exthelper: add a cautionary note about adding attributes to containers
Matt Harbison <matt_harbison@yahoo.com>
parents:
41059
diff
changeset
|
263 have the extension loaded. Therefore, care must be taken that the |
f7863606d4ff
exthelper: add a cautionary note about adding attributes to containers
Matt Harbison <matt_harbison@yahoo.com>
parents:
41059
diff
changeset
|
264 function doesn't make assumptions that the extension was loaded for the |
f7863606d4ff
exthelper: add a cautionary note about adding attributes to containers
Matt Harbison <matt_harbison@yahoo.com>
parents:
41059
diff
changeset
|
265 current repository. For `ui` and `repo` instances, a better option is |
f7863606d4ff
exthelper: add a cautionary note about adding attributes to containers
Matt Harbison <matt_harbison@yahoo.com>
parents:
41059
diff
changeset
|
266 to subclass the instance in `uipopulate` and `reposetup` respectively. |
f7863606d4ff
exthelper: add a cautionary note about adding attributes to containers
Matt Harbison <matt_harbison@yahoo.com>
parents:
41059
diff
changeset
|
267 |
f7863606d4ff
exthelper: add a cautionary note about adding attributes to containers
Matt Harbison <matt_harbison@yahoo.com>
parents:
41059
diff
changeset
|
268 https://www.mercurial-scm.org/wiki/WritingExtensions |
f7863606d4ff
exthelper: add a cautionary note about adding attributes to containers
Matt Harbison <matt_harbison@yahoo.com>
parents:
41059
diff
changeset
|
269 |
41047
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
270 example:: |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
271 |
41052
021496277392
exthelper: correct a documentation typo
Matt Harbison <matt_harbison@yahoo.com>
parents:
41049
diff
changeset
|
272 @eh.addattr(context.changectx, 'babar') |
41047
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
273 def babar(ctx): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
274 return 'babar' in ctx.description |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
275 """ |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
276 def dec(func): |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
277 self._duckpunchers.append((container, funcname, func)) |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
278 return func |
fe606f2dcae9
extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
279 return dec |