comparison hgext/fix.py @ 43227:f02d3c0eed18

fix: match patterns relative to root I was surprised fixer patterns (used to determine which fixers to run) are applies to the parent directory, not the repo root directory. Danny Hooper (the author of the extension) seemed to agree that it's better to apply them to the repo root, so that's what this patch does. Differential Revision: https://phab.mercurial-scm.org/D7101
author Martin von Zweigbergk <martinvonz@google.com>
date Sat, 12 Oct 2019 11:30:25 -0700
parents 0e2a2fab4b2e
children 579672b347d2
comparison
equal deleted inserted replaced
43226:5272bd7e7517 43227:f02d3c0eed18
44 formatter in such a way that it unexpectedly reformats the whole file. If such a 44 formatter in such a way that it unexpectedly reformats the whole file. If such a
45 tool needs to operate on unchanged files, it should set the :skipclean suboption 45 tool needs to operate on unchanged files, it should set the :skipclean suboption
46 to false. 46 to false.
47 47
48 The :pattern suboption determines which files will be passed through each 48 The :pattern suboption determines which files will be passed through each
49 configured tool. See :hg:`help patterns` for possible values. If there are file 49 configured tool. See :hg:`help patterns` for possible values. However, all
50 arguments to :hg:`fix`, the intersection of these patterns is used. 50 patterns are relative to the repo root, even if that text says they are relative
51 to the current working directory. If there are file arguments to :hg:`fix`, the
52 intersection of these patterns is used.
51 53
52 There is also a configurable limit for the maximum size of file that will be 54 There is also a configurable limit for the maximum size of file that will be
53 processed by :hg:`fix`:: 55 processed by :hg:`fix`::
54 56
55 [fix] 57 [fix]
138 from mercurial import ( 140 from mercurial import (
139 cmdutil, 141 cmdutil,
140 context, 142 context,
141 copies, 143 copies,
142 error, 144 error,
145 match as matchmod,
143 mdiff, 146 mdiff,
144 merge, 147 merge,
145 obsolete, 148 obsolete,
146 pycompat, 149 pycompat,
147 registrar, 150 registrar,
841 self._metadata = metadata 844 self._metadata = metadata
842 self._skipclean = skipclean 845 self._skipclean = skipclean
843 846
844 def affects(self, opts, fixctx, path): 847 def affects(self, opts, fixctx, path):
845 """Should this fixer run on the file at the given path and context?""" 848 """Should this fixer run on the file at the given path and context?"""
846 return scmutil.match(fixctx, [self._pattern], opts)(path) 849 repo = fixctx.repo()
850 matcher = matchmod.match(
851 repo.root, repo.root, [self._pattern], ctx=fixctx
852 )
853 return matcher(path)
847 854
848 def shouldoutputmetadata(self): 855 def shouldoutputmetadata(self):
849 """Should the stdout of this fixer start with JSON and a null byte?""" 856 """Should the stdout of this fixer start with JSON and a null byte?"""
850 return self._metadata 857 return self._metadata
851 858