Show More
@@ -812,9 +812,11 b' def overridepull(orig, ui, repo, source=' | |||||
812 | ui.status(_("%d largefiles cached\n") % numcached) |
|
812 | ui.status(_("%d largefiles cached\n") % numcached) | |
813 | return result |
|
813 | return result | |
814 |
|
814 | |||
|
815 | revsetpredicate = revset.extpredicate() | |||
|
816 | ||||
|
817 | @revsetpredicate('pulled()') | |||
815 | def pulledrevsetsymbol(repo, subset, x): |
|
818 | def pulledrevsetsymbol(repo, subset, x): | |
816 | """``pulled()`` |
|
819 | """Changesets that just has been pulled. | |
817 | Changesets that just has been pulled. |
|
|||
818 |
|
820 | |||
819 | Only available with largefiles from pull --lfrev expressions. |
|
821 | Only available with largefiles from pull --lfrev expressions. | |
820 |
|
822 |
@@ -9,7 +9,7 b'' | |||||
9 | '''setup for largefiles extension: uisetup''' |
|
9 | '''setup for largefiles extension: uisetup''' | |
10 |
|
10 | |||
11 | from mercurial import archival, cmdutil, commands, extensions, filemerge, hg, \ |
|
11 | from mercurial import archival, cmdutil, commands, extensions, filemerge, hg, \ | |
12 |
httppeer, merge, scmutil, sshpeer, wireproto, |
|
12 | httppeer, merge, scmutil, sshpeer, wireproto, subrepo, copies | |
13 | from mercurial.i18n import _ |
|
13 | from mercurial.i18n import _ | |
14 | from mercurial.hgweb import hgweb_mod, webcommands |
|
14 | from mercurial.hgweb import hgweb_mod, webcommands | |
15 |
|
15 | |||
@@ -83,7 +83,6 b' def uisetup(ui):' | |||||
83 | ('', 'lfrev', [], |
|
83 | ('', 'lfrev', [], | |
84 | _('download largefiles for these revisions'), _('REV'))] |
|
84 | _('download largefiles for these revisions'), _('REV'))] | |
85 | entry[1].extend(pullopt) |
|
85 | entry[1].extend(pullopt) | |
86 | revset.symbols['pulled'] = overrides.pulledrevsetsymbol |
|
|||
87 |
|
86 | |||
88 | entry = extensions.wrapcommand(commands.table, 'clone', |
|
87 | entry = extensions.wrapcommand(commands.table, 'clone', | |
89 | overrides.overrideclone) |
|
88 | overrides.overrideclone) | |
@@ -170,3 +169,5 b' def uisetup(ui):' | |||||
170 | if name == 'transplant': |
|
169 | if name == 'transplant': | |
171 | extensions.wrapcommand(getattr(module, 'cmdtable'), 'transplant', |
|
170 | extensions.wrapcommand(getattr(module, 'cmdtable'), 'transplant', | |
172 | overrides.overridetransplant) |
|
171 | overrides.overridetransplant) | |
|
172 | ||||
|
173 | overrides.revsetpredicate.setup() |
@@ -3558,9 +3558,11 b' def summaryhook(ui, repo):' | |||||
3558 | # i18n: column positioning for "hg summary" |
|
3558 | # i18n: column positioning for "hg summary" | |
3559 | ui.note(_("mq: (empty queue)\n")) |
|
3559 | ui.note(_("mq: (empty queue)\n")) | |
3560 |
|
3560 | |||
|
3561 | revsetpredicate = revset.extpredicate() | |||
|
3562 | ||||
|
3563 | @revsetpredicate('mq()') | |||
3561 | def revsetmq(repo, subset, x): |
|
3564 | def revsetmq(repo, subset, x): | |
3562 | """``mq()`` |
|
3565 | """Changesets managed by MQ. | |
3563 | Changesets managed by MQ. |
|
|||
3564 | """ |
|
3566 | """ | |
3565 | revset.getargs(x, 0, 0, _("mq takes no arguments")) |
|
3567 | revset.getargs(x, 0, 0, _("mq takes no arguments")) | |
3566 | applied = set([repo[r.node].rev() for r in repo.mq.applied]) |
|
3568 | applied = set([repo[r.node].rev() for r in repo.mq.applied]) | |
@@ -3596,7 +3598,7 b' def extsetup(ui):' | |||||
3596 | if extmodule.__file__ != __file__: |
|
3598 | if extmodule.__file__ != __file__: | |
3597 | dotable(getattr(extmodule, 'cmdtable', {})) |
|
3599 | dotable(getattr(extmodule, 'cmdtable', {})) | |
3598 |
|
3600 | |||
3599 | revset.symbols['mq'] = revsetmq |
|
3601 | revsetpredicate.setup() | |
3600 |
|
3602 | |||
3601 | colortable = {'qguard.negative': 'red', |
|
3603 | colortable = {'qguard.negative': 'red', | |
3602 | 'qguard.positive': 'yellow', |
|
3604 | 'qguard.positive': 'yellow', |
@@ -64,6 +64,9 b' def _destrebase(repo):' | |||||
64 | branch = repo[None].branch() |
|
64 | branch = repo[None].branch() | |
65 | return repo[branch].rev() |
|
65 | return repo[branch].rev() | |
66 |
|
66 | |||
|
67 | revsetpredicate = revset.extpredicate() | |||
|
68 | ||||
|
69 | @revsetpredicate('_destrebase') | |||
67 | def _revsetdestrebase(repo, subset, x): |
|
70 | def _revsetdestrebase(repo, subset, x): | |
68 | # ``_rebasedefaultdest()`` |
|
71 | # ``_rebasedefaultdest()`` | |
69 |
|
72 | |||
@@ -1238,4 +1241,4 b' def uisetup(ui):' | |||||
1238 | _("use 'hg rebase --continue' or 'hg rebase --abort'")]) |
|
1241 | _("use 'hg rebase --continue' or 'hg rebase --abort'")]) | |
1239 | # ensure rebased rev are not hidden |
|
1242 | # ensure rebased rev are not hidden | |
1240 | extensions.wrapfunction(repoview, '_getdynamicblockers', _rebasedvisible) |
|
1243 | extensions.wrapfunction(repoview, '_getdynamicblockers', _rebasedvisible) | |
1241 | revset.symbols['_destrebase'] = _revsetdestrebase |
|
1244 | revsetpredicate.setup() |
@@ -693,9 +693,11 b' def _dotransplant(ui, repo, *revs, **opt' | |||||
693 | if cleanupfn: |
|
693 | if cleanupfn: | |
694 | cleanupfn() |
|
694 | cleanupfn() | |
695 |
|
695 | |||
|
696 | revsetpredicate = revset.extpredicate() | |||
|
697 | ||||
|
698 | @revsetpredicate('transplanted([set])') | |||
696 | def revsettransplanted(repo, subset, x): |
|
699 | def revsettransplanted(repo, subset, x): | |
697 | """``transplanted([set])`` |
|
700 | """Transplanted changesets in set, or all transplanted changesets. | |
698 | Transplanted changesets in set, or all transplanted changesets. |
|
|||
699 | """ |
|
701 | """ | |
700 | if x: |
|
702 | if x: | |
701 | s = revset.getset(repo, subset, x) |
|
703 | s = revset.getset(repo, subset, x) | |
@@ -711,7 +713,7 b' def kwtransplanted(repo, ctx, **args):' | |||||
711 | return n and revlog.hex(n) or '' |
|
713 | return n and revlog.hex(n) or '' | |
712 |
|
714 | |||
713 | def extsetup(ui): |
|
715 | def extsetup(ui): | |
714 | revset.symbols['transplanted'] = revsettransplanted |
|
716 | revsetpredicate.setup() | |
715 | templatekw.keywords['transplanted'] = kwtransplanted |
|
717 | templatekw.keywords['transplanted'] = kwtransplanted | |
716 | cmdutil.unfinishedstates.append( |
|
718 | cmdutil.unfinishedstates.append( | |
717 | ['series', True, False, _('transplant in progress'), |
|
719 | ['series', True, False, _('transplant in progress'), |
@@ -487,11 +487,36 b' class predicate(registrar.funcregistrar)' | |||||
487 |
|
487 | |||
488 | The first string argument of the constructor is used also in |
|
488 | The first string argument of the constructor is used also in | |
489 | online help. |
|
489 | online help. | |
|
490 | ||||
|
491 | Use 'extpredicate' instead of this to register revset predicate in | |||
|
492 | extensions. | |||
490 | """ |
|
493 | """ | |
491 | table = symbols |
|
494 | table = symbols | |
492 | formatdoc = "``%s``\n %s" |
|
495 | formatdoc = "``%s``\n %s" | |
493 | getname = registrar.funcregistrar.parsefuncdecl |
|
496 | getname = registrar.funcregistrar.parsefuncdecl | |
494 |
|
497 | |||
|
498 | class extpredicate(registrar.delayregistrar): | |||
|
499 | """Decorator to register revset predicate in extensions | |||
|
500 | ||||
|
501 | Usage:: | |||
|
502 | ||||
|
503 | revsetpredicate = revset.extpredicate() | |||
|
504 | ||||
|
505 | @revsetpredicate('mypredicate(arg1, arg2[, arg3])') | |||
|
506 | def mypredicatefunc(repo, subset, x): | |||
|
507 | '''Explanation of this revset predicate .... | |||
|
508 | ''' | |||
|
509 | pass | |||
|
510 | ||||
|
511 | def uisetup(ui): | |||
|
512 | revsetpredicate.setup() | |||
|
513 | ||||
|
514 | 'revsetpredicate' instance above can be used to decorate multiple | |||
|
515 | functions, and 'setup()' on it registers all such functions at | |||
|
516 | once. | |||
|
517 | """ | |||
|
518 | registrar = predicate | |||
|
519 | ||||
495 | @predicate('_destupdate') |
|
520 | @predicate('_destupdate') | |
496 | def _destupdate(repo, subset, x): |
|
521 | def _destupdate(repo, subset, x): | |
497 | # experimental revset for update destination |
|
522 | # experimental revset for update destination |
@@ -2189,3 +2189,43 b' test error message of bad revset' | |||||
2189 | [255] |
|
2189 | [255] | |
2190 |
|
2190 | |||
2191 | $ cd .. |
|
2191 | $ cd .. | |
|
2192 | ||||
|
2193 | Test registrar.delayregistrar via revset.extpredicate | |||
|
2194 | ||||
|
2195 | 'extpredicate' decorator shouldn't register any functions until | |||
|
2196 | 'setup()' on it. | |||
|
2197 | ||||
|
2198 | $ cd repo | |||
|
2199 | ||||
|
2200 | $ cat <<EOF > $TESTTMP/custompredicate.py | |||
|
2201 | > from mercurial import revset | |||
|
2202 | > | |||
|
2203 | > revsetpredicate = revset.extpredicate() | |||
|
2204 | > | |||
|
2205 | > @revsetpredicate('custom1()') | |||
|
2206 | > def custom1(repo, subset, x): | |||
|
2207 | > return revset.baseset([1]) | |||
|
2208 | > @revsetpredicate('custom2()') | |||
|
2209 | > def custom2(repo, subset, x): | |||
|
2210 | > return revset.baseset([2]) | |||
|
2211 | > | |||
|
2212 | > def uisetup(ui): | |||
|
2213 | > if ui.configbool('custompredicate', 'enabled'): | |||
|
2214 | > revsetpredicate.setup() | |||
|
2215 | > EOF | |||
|
2216 | $ cat <<EOF > .hg/hgrc | |||
|
2217 | > [extensions] | |||
|
2218 | > custompredicate = $TESTTMP/custompredicate.py | |||
|
2219 | > EOF | |||
|
2220 | ||||
|
2221 | $ hg debugrevspec "custom1()" | |||
|
2222 | hg: parse error: unknown identifier: custom1 | |||
|
2223 | [255] | |||
|
2224 | $ hg debugrevspec "custom2()" | |||
|
2225 | hg: parse error: unknown identifier: custom2 | |||
|
2226 | [255] | |||
|
2227 | $ hg debugrevspec "custom1() or custom2()" --config custompredicate.enabled=true | |||
|
2228 | 1 | |||
|
2229 | 2 | |||
|
2230 | ||||
|
2231 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now