diff -r 9c3ba42c582a -r 0c134ca37567 hgext/directaccess.py --- a/hgext/directaccess.py Tue Jun 16 10:07:51 2015 -0700 +++ b/hgext/directaccess.py Tue Jun 16 10:08:48 2015 -0700 @@ -12,18 +12,19 @@ from mercurial import revset from mercurial import error from mercurial import commands +from mercurial import hg from mercurial.i18n import _ cmdtable = {} command = cmdutil.command(cmdtable) -# List of commands where no warning is shown for direct access +# By default, all the commands have directaccess with warnings +# List of commands that have no directaccess and directaccess with no warning directaccesslevel = [ - # warning or not, extension (None if core), command name - (False, None, 'update'), - (False, None, 'export'), - (True, 'rebase', 'rebase'), - (False, 'evolve', 'prune'), + # 'nowarning' or 'error', (None if core) or extension name, command name + ('nowarning', None, 'update'), + ('nowarning', None, 'export'), + ('nowarning', 'evolve', 'prune'), ] def reposetup(ui, repo): @@ -49,19 +50,19 @@ for warn, ext, cmd in directaccesslevel: try: cmdtable = extensions.find(ext).cmdtable if ext else commands.table - wrapper = wrapwithwarning if warn else wrapwithoutwarning + wrapper = wrapwitherror if warn == 'error' else wrapwithoutwarning extensions.wrapcommand(cmdtable, cmd, wrapper) except (error.UnknownCommand, KeyError): pass -def wrapwithoutwarning(orig, ui, repo, *args, **kwargs): - if repo and repo.filtername == 'visible': - repo = repo.filtered("visible-directaccess-nowarn") +def wrapwitherror(orig, ui, repo, *args, **kwargs): + if repo and repo.filtername == 'visible-directaccess-warn': + repo = repo.filtered('visible') return orig(ui, repo, *args, **kwargs) -def wrapwithwarning(orig, ui, repo, *args, **kwargs): - if repo and repo.filtername == 'visible': - repo = repo.filtered("visible-directaccess-warn") +def wrapwithoutwarning(orig, ui, repo, *args, **kwargs): + if repo and repo.filtername == 'visible-directaccess-warn': + repo = repo.filtered("visible-directaccess-nowarn") return orig(ui, repo, *args, **kwargs) def uisetup(ui): @@ -85,8 +86,14 @@ order.remove('directaccess') extensions._order = order +def _repository(orig, *args, **kwargs): + """Make visible-directaccess-warn the default filter for new repos""" + repo = orig(*args, **kwargs) + return repo.filtered("visible-directaccess-warn") + def extsetup(ui): extensions.wrapfunction(revset, 'posttreebuilthook', _posttreebuilthook) + extensions.wrapfunction(hg, 'repository', _repository) setupdirectaccess() def gethashsymbols(tree):