##// END OF EJS Templates
match: enable 'subinclude:' syntax...
Durham Goode -
r25283:19d0e5ef default
parent child Browse files
Show More
@@ -42,6 +42,30 b' def _expandsets(kindpats, ctx, listsubre'
42 other.append((kind, pat, source))
42 other.append((kind, pat, source))
43 return fset, other
43 return fset, other
44
44
45 def _expandsubinclude(kindpats, root):
46 '''Returns the list of subinclude matchers and the kindpats without the
47 subincludes in it.'''
48 relmatchers = []
49 other = []
50
51 for kind, pat, source in kindpats:
52 if kind == 'subinclude':
53 sourceroot = pathutil.dirname(source)
54 pat = util.pconvert(pat)
55 path = pathutil.join(sourceroot, pat)
56
57 newroot = pathutil.dirname(path)
58 relmatcher = match(newroot, '', [], ['include:%s' % path])
59
60 prefix = pathutil.canonpath(root, root, newroot)
61 if prefix:
62 prefix += '/'
63 relmatchers.append((prefix, relmatcher))
64 else:
65 other.append((kind, pat, source))
66
67 return relmatchers, other
68
45 def _kindpatsalwaysmatch(kindpats):
69 def _kindpatsalwaysmatch(kindpats):
46 """"Checks whether the kindspats match everything, as e.g.
70 """"Checks whether the kindspats match everything, as e.g.
47 'relpath:.' does.
71 'relpath:.' does.
@@ -76,6 +100,8 b' class match(object):'
76 'relre:<regexp>' - a regexp that needn't match the start of a name
100 'relre:<regexp>' - a regexp that needn't match the start of a name
77 'set:<fileset>' - a fileset expression
101 'set:<fileset>' - a fileset expression
78 'include:<path>' - a file of patterns to read and include
102 'include:<path>' - a file of patterns to read and include
103 'subinclude:<path>' - a file of patterns to match against files under
104 the same directory
79 '<something>' - a pattern of the specified default type
105 '<something>' - a pattern of the specified default type
80 """
106 """
81
107
@@ -375,7 +401,7 b' def _patsplit(pattern, default):'
375 if ':' in pattern:
401 if ':' in pattern:
376 kind, pat = pattern.split(':', 1)
402 kind, pat = pattern.split(':', 1)
377 if kind in ('re', 'glob', 'path', 'relglob', 'relpath', 'relre',
403 if kind in ('re', 'glob', 'path', 'relglob', 'relpath', 'relre',
378 'listfile', 'listfile0', 'set', 'include'):
404 'listfile', 'listfile0', 'set', 'include', 'subinclude'):
379 return kind, pat
405 return kind, pat
380 return default, pattern
406 return default, pattern
381
407
@@ -481,6 +507,15 b' def _buildmatch(ctx, kindpats, globsuffi'
481 globsuffix is appended to the regexp of globs.'''
507 globsuffix is appended to the regexp of globs.'''
482 matchfuncs = []
508 matchfuncs = []
483
509
510 subincludes, kindpats = _expandsubinclude(kindpats, root)
511 if subincludes:
512 def matchsubinclude(f):
513 for prefix, mf in subincludes:
514 if f.startswith(prefix) and mf(f[len(prefix):]):
515 return True
516 return False
517 matchfuncs.append(matchsubinclude)
518
484 fset, kindpats = _expandsets(kindpats, ctx, listsubrepos)
519 fset, kindpats = _expandsets(kindpats, ctx, listsubrepos)
485 if fset:
520 if fset:
486 matchfuncs.append(fset.__contains__)
521 matchfuncs.append(fset.__contains__)
@@ -577,7 +612,7 b' def readpatternfile(filepath, warn):'
577 pattern # pattern of the current default type'''
612 pattern # pattern of the current default type'''
578
613
579 syntaxes = {'re': 'relre:', 'regexp': 'relre:', 'glob': 'relglob:',
614 syntaxes = {'re': 'relre:', 'regexp': 'relre:', 'glob': 'relglob:',
580 'include': 'include'}
615 'include': 'include', 'subinclude': 'subinclude'}
581 syntax = 'relre:'
616 syntax = 'relre:'
582 patterns = []
617 patterns = []
583
618
@@ -190,7 +190,55 b" Check recursive uses of 'include:'"
190 $ hg status
190 $ hg status
191 A dir/b.o
191 A dir/b.o
192
192
193 $ cp otherignore goodignore
193 $ echo "include:badignore" >> otherignore
194 $ echo "include:badignore" >> otherignore
194 $ hg status
195 $ hg status
195 skipping unreadable pattern file 'badignore': No such file or directory
196 skipping unreadable pattern file 'badignore': No such file or directory
196 A dir/b.o
197 A dir/b.o
198
199 $ mv goodignore otherignore
200
201 Check including subincludes
202
203 $ hg revert -q --all
204 $ hg purge --all --config extensions.purge=
205 $ echo ".hgignore" > .hgignore
206 $ mkdir dir1 dir2
207 $ touch dir1/file1 dir1/file2 dir2/file1 dir2/file2
208 $ echo "subinclude:dir2/.hgignore" >> .hgignore
209 $ echo "glob:file*2" > dir2/.hgignore
210 $ hg status
211 ? dir1/file1
212 ? dir1/file2
213 ? dir2/file1
214
215 Check including subincludes with regexs
216
217 $ echo "subinclude:dir1/.hgignore" >> .hgignore
218 $ echo "regexp:f.le1" > dir1/.hgignore
219
220 $ hg status
221 ? dir1/file2
222 ? dir2/file1
223
224 Check multiple levels of sub-ignores
225
226 $ mkdir dir1/subdir
227 $ touch dir1/subdir/subfile1 dir1/subdir/subfile3 dir1/subdir/subfile4
228 $ echo "subinclude:subdir/.hgignore" >> dir1/.hgignore
229 $ echo "glob:subfil*3" >> dir1/subdir/.hgignore
230
231 $ hg status
232 ? dir1/file2
233 ? dir1/subdir/subfile4
234 ? dir2/file1
235
236 Check include subignore at the same level
237
238 $ mv dir1/subdir/.hgignore dir1/.hgignoretwo
239 $ echo "regexp:f.le1" > dir1/.hgignore
240 $ echo "subinclude:.hgignoretwo" >> dir1/.hgignore
241 $ echo "glob:file*2" > dir1/.hgignoretwo
242
243 $ hg status | grep file2
244 [1]
General Comments 0
You need to be logged in to leave comments. Login now