mercurial/match.py
changeset 26587 56b2bcea2529
parent 26014 a5f62af29517
child 26781 1aee2ab0f902
equal deleted inserted replaced
26586:d51c658d3f04 26587:56b2bcea2529
    11 import os
    11 import os
    12 import re
    12 import re
    13 
    13 
    14 from .i18n import _
    14 from .i18n import _
    15 from . import (
    15 from . import (
       
    16     error,
    16     pathutil,
    17     pathutil,
    17     util,
    18     util,
    18 )
    19 )
    19 
    20 
    20 propertycache = util.propertycache
    21 propertycache = util.propertycache
    35     other = []
    36     other = []
    36 
    37 
    37     for kind, pat, source in kindpats:
    38     for kind, pat, source in kindpats:
    38         if kind == 'set':
    39         if kind == 'set':
    39             if not ctx:
    40             if not ctx:
    40                 raise util.Abort("fileset expression with no context")
    41                 raise error.Abort("fileset expression with no context")
    41             s = ctx.getfileset(pat)
    42             s = ctx.getfileset(pat)
    42             fset.update(s)
    43             fset.update(s)
    43 
    44 
    44             if listsubrepos:
    45             if listsubrepos:
    45                 for subpath in ctx.substate:
    46                 for subpath in ctx.substate:
   288                         files = files.split('\0')
   289                         files = files.split('\0')
   289                     else:
   290                     else:
   290                         files = files.splitlines()
   291                         files = files.splitlines()
   291                     files = [f for f in files if f]
   292                     files = [f for f in files if f]
   292                 except EnvironmentError:
   293                 except EnvironmentError:
   293                     raise util.Abort(_("unable to read file list (%s)") % pat)
   294                     raise error.Abort(_("unable to read file list (%s)") % pat)
   294                 for k, p, source in self._normalize(files, default, root, cwd,
   295                 for k, p, source in self._normalize(files, default, root, cwd,
   295                                                     auditor):
   296                                                     auditor):
   296                     kindpats.append((k, p, pat))
   297                     kindpats.append((k, p, pat))
   297                 continue
   298                 continue
   298             elif kind == 'include':
   299             elif kind == 'include':
   300                     fullpath = os.path.join(root, util.localpath(pat))
   301                     fullpath = os.path.join(root, util.localpath(pat))
   301                     includepats = readpatternfile(fullpath, self._warn)
   302                     includepats = readpatternfile(fullpath, self._warn)
   302                     for k, p, source in self._normalize(includepats, default,
   303                     for k, p, source in self._normalize(includepats, default,
   303                                                         root, cwd, auditor):
   304                                                         root, cwd, auditor):
   304                         kindpats.append((k, p, source or pat))
   305                         kindpats.append((k, p, source or pat))
   305                 except util.Abort as inst:
   306                 except error.Abort as inst:
   306                     raise util.Abort('%s: %s' % (pat, inst[0]))
   307                     raise error.Abort('%s: %s' % (pat, inst[0]))
   307                 except IOError as inst:
   308                 except IOError as inst:
   308                     if self._warn:
   309                     if self._warn:
   309                         self._warn(_("skipping unreadable pattern file "
   310                         self._warn(_("skipping unreadable pattern file "
   310                                      "'%s': %s\n") % (pat, inst.strerror))
   311                                      "'%s': %s\n") % (pat, inst.strerror))
   311                 continue
   312                 continue
   585         for k, p, s in kindpats:
   586         for k, p, s in kindpats:
   586             try:
   587             try:
   587                 _rematcher('(?:%s)' % _regex(k, p, globsuffix))
   588                 _rematcher('(?:%s)' % _regex(k, p, globsuffix))
   588             except re.error:
   589             except re.error:
   589                 if s:
   590                 if s:
   590                     raise util.Abort(_("%s: invalid pattern (%s): %s") %
   591                     raise error.Abort(_("%s: invalid pattern (%s): %s") %
   591                                      (s, k, p))
   592                                      (s, k, p))
   592                 else:
   593                 else:
   593                     raise util.Abort(_("invalid pattern (%s): %s") % (k, p))
   594                     raise error.Abort(_("invalid pattern (%s): %s") % (k, p))
   594         raise util.Abort(_("invalid pattern"))
   595         raise error.Abort(_("invalid pattern"))
   595 
   596 
   596 def _roots(kindpats):
   597 def _roots(kindpats):
   597     '''return roots and exact explicitly listed files from patterns
   598     '''return roots and exact explicitly listed files from patterns
   598 
   599 
   599     >>> _roots([('glob', 'g/*', ''), ('glob', 'g', ''), ('glob', 'g*', '')])
   600     >>> _roots([('glob', 'g/*', ''), ('glob', 'g', ''), ('glob', 'g*', '')])