Details
Details
- Reviewers
yuja - Group Reviewers
hg-reviewers - Commits
- rHG38637dd39cfd: py3: handle keyword arguments in hgext/automv.py
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
yuja |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
from __future__ import absolute_import | from __future__ import absolute_import | ||||
from mercurial.i18n import _ | from mercurial.i18n import _ | ||||
from mercurial import ( | from mercurial import ( | ||||
commands, | commands, | ||||
copies, | copies, | ||||
error, | error, | ||||
extensions, | extensions, | ||||
pycompat, | |||||
registrar, | registrar, | ||||
scmutil, | scmutil, | ||||
similar | similar | ||||
) | ) | ||||
configtable = {} | configtable = {} | ||||
configitem = registrar.configitem(configtable) | configitem = registrar.configitem(configtable) | ||||
configitem('automv', 'similarity', | configitem('automv', 'similarity', | ||||
default=95, | default=95, | ||||
) | ) | ||||
def extsetup(ui): | def extsetup(ui): | ||||
entry = extensions.wrapcommand( | entry = extensions.wrapcommand( | ||||
commands.table, 'commit', mvcheck) | commands.table, 'commit', mvcheck) | ||||
entry[1].append( | entry[1].append( | ||||
('', 'no-automv', None, | ('', 'no-automv', None, | ||||
_('disable automatic file move detection'))) | _('disable automatic file move detection'))) | ||||
def mvcheck(orig, ui, repo, *pats, **opts): | def mvcheck(orig, ui, repo, *pats, **opts): | ||||
"""Hook to check for moves at commit time""" | """Hook to check for moves at commit time""" | ||||
opts = pycompat.byteskwargs(opts) | |||||
renames = None | renames = None | ||||
disabled = opts.pop('no_automv', False) | disabled = opts.pop('no_automv', False) | ||||
if not disabled: | if not disabled: | ||||
threshold = ui.configint('automv', 'similarity') | threshold = ui.configint('automv', 'similarity') | ||||
if not 0 <= threshold <= 100: | if not 0 <= threshold <= 100: | ||||
raise error.Abort(_('automv.similarity must be between 0 and 100')) | raise error.Abort(_('automv.similarity must be between 0 and 100')) | ||||
if threshold > 0: | if threshold > 0: | ||||
match = scmutil.match(repo[None], pats, opts) | match = scmutil.match(repo[None], pats, opts) | ||||
added, removed = _interestingfiles(repo, match) | added, removed = _interestingfiles(repo, match) | ||||
renames = _findrenames(repo, match, added, removed, | renames = _findrenames(repo, match, added, removed, | ||||
threshold / 100.0) | threshold / 100.0) | ||||
with repo.wlock(): | with repo.wlock(): | ||||
if renames is not None: | if renames is not None: | ||||
scmutil._markchanges(repo, (), (), renames) | scmutil._markchanges(repo, (), (), renames) | ||||
return orig(ui, repo, *pats, **opts) | return orig(ui, repo, *pats, **pycompat.strkwargs(opts)) | ||||
def _interestingfiles(repo, matcher): | def _interestingfiles(repo, matcher): | ||||
"""Find what files were added or removed in this commit. | """Find what files were added or removed in this commit. | ||||
Returns a tuple of two lists: (added, removed). Only files not *already* | Returns a tuple of two lists: (added, removed). Only files not *already* | ||||
marked as moved are included in the added list. | marked as moved are included in the added list. | ||||
""" | """ |