Mercurial > evolve
comparison hgext/directaccess.py @ 1367:0c134ca37567
directaccess: change rule from opt-in to opt-out
Before this patch we would opt-in commands for direct access and the default
filter for new repository was 'visible'.
With this patch, the default filter for new repos is
'visible-directaccess-warn'. It means that by default all the commands have
directaccess with warnings.
author | Laurent Charignon <lcharignon@fb.com> |
---|---|
date | Tue, 16 Jun 2015 10:08:48 -0700 |
parents | 2eaa2943f9f3 |
children | c02cdb97ebfa |
comparison
equal
deleted
inserted
replaced
1366:9c3ba42c582a | 1367:0c134ca37567 |
---|---|
10 from mercurial import repoview | 10 from mercurial import repoview |
11 from mercurial import branchmap | 11 from mercurial import branchmap |
12 from mercurial import revset | 12 from mercurial import revset |
13 from mercurial import error | 13 from mercurial import error |
14 from mercurial import commands | 14 from mercurial import commands |
15 from mercurial import hg | |
15 from mercurial.i18n import _ | 16 from mercurial.i18n import _ |
16 | 17 |
17 cmdtable = {} | 18 cmdtable = {} |
18 command = cmdutil.command(cmdtable) | 19 command = cmdutil.command(cmdtable) |
19 | 20 |
20 # List of commands where no warning is shown for direct access | 21 # By default, all the commands have directaccess with warnings |
22 # List of commands that have no directaccess and directaccess with no warning | |
21 directaccesslevel = [ | 23 directaccesslevel = [ |
22 # warning or not, extension (None if core), command name | 24 # 'nowarning' or 'error', (None if core) or extension name, command name |
23 (False, None, 'update'), | 25 ('nowarning', None, 'update'), |
24 (False, None, 'export'), | 26 ('nowarning', None, 'export'), |
25 (True, 'rebase', 'rebase'), | 27 ('nowarning', 'evolve', 'prune'), |
26 (False, 'evolve', 'prune'), | |
27 ] | 28 ] |
28 | 29 |
29 def reposetup(ui, repo): | 30 def reposetup(ui, repo): |
30 repo._explicitaccess = set() | 31 repo._explicitaccess = set() |
31 | 32 |
47 branchmap.subsettable['visible-directaccess-warn'] = 'visible' | 48 branchmap.subsettable['visible-directaccess-warn'] = 'visible' |
48 | 49 |
49 for warn, ext, cmd in directaccesslevel: | 50 for warn, ext, cmd in directaccesslevel: |
50 try: | 51 try: |
51 cmdtable = extensions.find(ext).cmdtable if ext else commands.table | 52 cmdtable = extensions.find(ext).cmdtable if ext else commands.table |
52 wrapper = wrapwithwarning if warn else wrapwithoutwarning | 53 wrapper = wrapwitherror if warn == 'error' else wrapwithoutwarning |
53 extensions.wrapcommand(cmdtable, cmd, wrapper) | 54 extensions.wrapcommand(cmdtable, cmd, wrapper) |
54 except (error.UnknownCommand, KeyError): | 55 except (error.UnknownCommand, KeyError): |
55 pass | 56 pass |
56 | 57 |
57 def wrapwithoutwarning(orig, ui, repo, *args, **kwargs): | 58 def wrapwitherror(orig, ui, repo, *args, **kwargs): |
58 if repo and repo.filtername == 'visible': | 59 if repo and repo.filtername == 'visible-directaccess-warn': |
59 repo = repo.filtered("visible-directaccess-nowarn") | 60 repo = repo.filtered('visible') |
60 return orig(ui, repo, *args, **kwargs) | 61 return orig(ui, repo, *args, **kwargs) |
61 | 62 |
62 def wrapwithwarning(orig, ui, repo, *args, **kwargs): | 63 def wrapwithoutwarning(orig, ui, repo, *args, **kwargs): |
63 if repo and repo.filtername == 'visible': | 64 if repo and repo.filtername == 'visible-directaccess-warn': |
64 repo = repo.filtered("visible-directaccess-warn") | 65 repo = repo.filtered("visible-directaccess-nowarn") |
65 return orig(ui, repo, *args, **kwargs) | 66 return orig(ui, repo, *args, **kwargs) |
66 | 67 |
67 def uisetup(ui): | 68 def uisetup(ui): |
68 """ Change ordering of extensions to ensure that directaccess extsetup comes | 69 """ Change ordering of extensions to ensure that directaccess extsetup comes |
69 after the one of the extensions in the loadsafter list """ | 70 after the one of the extensions in the loadsafter list """ |
83 if minidxdirectaccess > directaccesidx: | 84 if minidxdirectaccess > directaccesidx: |
84 order.insert(minidxdirectaccess + 1, 'directaccess') | 85 order.insert(minidxdirectaccess + 1, 'directaccess') |
85 order.remove('directaccess') | 86 order.remove('directaccess') |
86 extensions._order = order | 87 extensions._order = order |
87 | 88 |
89 def _repository(orig, *args, **kwargs): | |
90 """Make visible-directaccess-warn the default filter for new repos""" | |
91 repo = orig(*args, **kwargs) | |
92 return repo.filtered("visible-directaccess-warn") | |
93 | |
88 def extsetup(ui): | 94 def extsetup(ui): |
89 extensions.wrapfunction(revset, 'posttreebuilthook', _posttreebuilthook) | 95 extensions.wrapfunction(revset, 'posttreebuilthook', _posttreebuilthook) |
96 extensions.wrapfunction(hg, 'repository', _repository) | |
90 setupdirectaccess() | 97 setupdirectaccess() |
91 | 98 |
92 def gethashsymbols(tree): | 99 def gethashsymbols(tree): |
93 # Returns the list of symbols of the tree that look like hashes | 100 # Returns the list of symbols of the tree that look like hashes |
94 # for example for the revset 3::abe3ff it will return ('abe3ff') | 101 # for example for the revset 3::abe3ff it will return ('abe3ff') |