Show More
@@ -130,6 +130,7 b' from mercurial.i18n import _' | |||
|
130 | 130 | |
|
131 | 131 | from mercurial import ( |
|
132 | 132 | config, |
|
133 | context, | |
|
133 | 134 | error, |
|
134 | 135 | exchange, |
|
135 | 136 | extensions, |
@@ -329,6 +330,8 b' def _resolverevlogstorevfsoptions(orig, ' | |||
|
329 | 330 | def _extsetup(ui): |
|
330 | 331 | wrapfilelog(filelog.filelog) |
|
331 | 332 | |
|
333 | context.basefilectx.islfs = wrapper.filectxislfs | |
|
334 | ||
|
332 | 335 | scmutil.fileprefetchhooks.add('lfs', wrapper._prefetchfiles) |
|
333 | 336 | |
|
334 | 337 | # Make bundle choose changegroup3 instead of changegroup2. This affects |
@@ -208,7 +208,6 b' def filectxisbinary(orig, self):' | |||
|
208 | 208 | return bool(int(metadata.get('x-is-binary', 1))) |
|
209 | 209 | return orig(self) |
|
210 | 210 | |
|
211 | @eh.addattr(context.basefilectx, 'islfs') | |
|
212 | 211 | def filectxislfs(self): |
|
213 | 212 | return _islfs(self.filelog(), self.filenode()) |
|
214 | 213 |
@@ -82,7 +82,6 b' class exthelper(object):' | |||
|
82 | 82 | self._commandwrappers = [] |
|
83 | 83 | self._extcommandwrappers = [] |
|
84 | 84 | self._functionwrappers = [] |
|
85 | self._duckpunchers = [] | |
|
86 | 85 | self.cmdtable = {} |
|
87 | 86 | self.command = registrar.command(self.cmdtable) |
|
88 | 87 | self.configtable = {} |
@@ -102,7 +101,6 b' class exthelper(object):' | |||
|
102 | 101 | self._commandwrappers.extend(other._commandwrappers) |
|
103 | 102 | self._extcommandwrappers.extend(other._extcommandwrappers) |
|
104 | 103 | self._functionwrappers.extend(other._functionwrappers) |
|
105 | self._duckpunchers.extend(other._duckpunchers) | |
|
106 | 104 | self.cmdtable.update(other.cmdtable) |
|
107 | 105 | for section, items in other.configtable.iteritems(): |
|
108 | 106 | if section in self.configtable: |
@@ -129,8 +127,6 b' class exthelper(object):' | |||
|
129 | 127 | - Setup of pre-* and post-* hooks |
|
130 | 128 | - pushkey setup |
|
131 | 129 | """ |
|
132 | for cont, funcname, func in self._duckpunchers: | |
|
133 | setattr(cont, funcname, func) | |
|
134 | 130 | for command, wrapper, opts in self._commandwrappers: |
|
135 | 131 | entry = extensions.wrapcommand(commands.table, command, wrapper) |
|
136 | 132 | if opts: |
@@ -302,29 +298,3 b' class exthelper(object):' | |||
|
302 | 298 | self._functionwrappers.append((container, funcname, wrapper)) |
|
303 | 299 | return wrapper |
|
304 | 300 | return dec |
|
305 | ||
|
306 | def addattr(self, container, funcname): | |
|
307 | """Decorated function is to be added to the container | |
|
308 | ||
|
309 | This function takes two arguments, the container and the name of the | |
|
310 | function to wrap. The wrapping is performed during `uisetup`. | |
|
311 | ||
|
312 | Adding attributes to a container like this is discouraged, because the | |
|
313 | container modification is visible even in repositories that do not | |
|
314 | have the extension loaded. Therefore, care must be taken that the | |
|
315 | function doesn't make assumptions that the extension was loaded for the | |
|
316 | current repository. For `ui` and `repo` instances, a better option is | |
|
317 | to subclass the instance in `uipopulate` and `reposetup` respectively. | |
|
318 | ||
|
319 | https://www.mercurial-scm.org/wiki/WritingExtensions | |
|
320 | ||
|
321 | example:: | |
|
322 | ||
|
323 | @eh.addattr(context.changectx, 'babar') | |
|
324 | def babar(ctx): | |
|
325 | return 'babar' in ctx.description | |
|
326 | """ | |
|
327 | def dec(func): | |
|
328 | self._duckpunchers.append((container, funcname, func)) | |
|
329 | return func | |
|
330 | return dec |
General Comments 0
You need to be logged in to leave comments.
Login now