
    6h                       S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKJrJ	r	J
r
JrJrJr  SSKJr  SSKJr  SSKJrJrJrJrJrJr  SSKJr  SS	KJr  \R<                  " S
SS9rSr Sr!\RD                  r"S r#SIS jr$S r%S r&   SIS jr'          SJS jr(SKS jr)SKS jr*SKS jr+S r,SLS jr- " S S\R\                  5      r/ " S S\/5      r0 " S S\/5      r1 " S  S!\/5      r2S" r3 " S# S$\/5      r4 " S% S&5      r5 " S' S(\/5      r6 " S) S*\/5      r7 " S+ S,\/5      r8S- r9 " S. S/\/5      r: " S0 S1\/5      r; " S2 S3\/5      r< " S4 S5\/5      r=SKS6 jr>S7 r?S8 r@\R                  R                  S95      rBS: rCS; rDS<rES= rFS> rGS? rHS@ rISA rJSB rKSC rLSqM\R                  (       a>  S SDKOJPrP  \        SMSE j5       rQ\        SNSF j5       rQ\ SO       SPSG jj5       rQSOSH jrQg)Q    )annotationsN)AnyCallableListTupleUnionoverload   )_)MatcherT)encodingerrorpathutilpolicypycompatutil)
stringutil)matcherdirstateT)pyo3)   re   glob   path   filepath   relglob   relpath   relre   rootglob   listfile	   listfile0   set   include
   subinclude   rootfilesinr   r   c                    [         R                  R                  U 5      n UR                  $ ! [         a    UR
                  s $ f = f)zVcompile the regexp with the best available regexp engine and return a
matcher function)r   recompile
test_matchAttributeErrormatch)regexms     1/usr/lib/python3/dist-packages/mercurial/match.py
_rematcherr/   C   s=     	A|| wws   - AAc           	     v   / n/ nU H  u  pxn	US:X  a  Uc  [         R                  " S5      eUR                  UR                  XUS95        U(       aM  UR                   H=  n
UR                  U
5      R                  XUS9n[        XUS9nUR                  U5        M?     M  UR                  XxU	45        M     XV4$ )zFReturns the kindpats list with the 'set' patterns expanded to matchersr!   s"   fileset expression with no contextbadfn)r   ProgrammingErrorappendmatchfilesetsubstatesubprefixdirmatcher)cwdkindpatsctxlistsubreposr2   matchersotherkindpatsourcesubpathsmpms                r.   _expandsetsrE   N   s    HE%66>{,,9  OOC,,SU,CD"||G)66su6MB)'UCBOOB'  ,
 d() &  ?    c                   / n/ nU  H  u  pEnUS:X  a  [         R                  " [        R                  " U5      5      n[        R                  " U5      n[         R
                  " Xu5      n[         R                  " U5      n	U	S/ SU-  /4n
[         R                  " XU	5      nU(       a  US-  nUR                  X45        M  UR                  XEU45        M     X#4$ )z[Returns the list of subinclude matcher args and the kindpats without the
subincludes in it.r#   rF   s
   include:%s   /)r   dirnamer   normpathpconvertjoin	canonpathr4   )r:   rootrelmatchersr>   r?   r@   rA   
sourcerootpathnewrootmatcherargsprefixs               r.   _expandsubincluderU   f   s     KE%6= !))$--*?@J--$C==1D&&t,G"Cmd.B-CDK''G<F$45LL$V,- &  rF   c                8    U  H  u  pnUS:w  d  US;  d  M    g   g)zIChecks whether the kindspats match everything, as e.g.
'relpath:.' does.
rF   r%   FT r:   r?   r@   rA   s       r.   _kindpatsalwaysmatchrY      s*     &6#:%:: & rF   c                    / n[        UUUUUS9u  pU(       a  U " XUS9n	UR                  U	5        U(       a  UR                  U5        U(       d	  [        US9$ [	        U5      S:X  a  US   $ [        U5      $ )Nr;   r<   r2   r1   r
   r   )rE   r4   extendnevermatcherlenunionmatcher)

matcherclsrN   r9   r:   r;   r<   r2   r=   fmsr-   s
             r.   _buildkindpatsmatcherrb      s     H!MC tU3
%((
8}{!!rF   c           
       ^^ [         R                  R                  U 5      (       d   e[         R                  R                  U [        R
                  " U5      5      n[        nU(       a-  UR                  5       R                  mTR                  mUU4S jnU(       a:  U" X%XXi5      n[        U5      (       a  [        U
5      nO[        [        U UUUUU
S9nO[        U
5      nU(       a)  U" USXXi5      n[        [        U UUUUSS9n[        X5      nU(       a*  U" USXXi5      n[        [        U UUUUSS9n[!        UU5      nU$ )a  build an object to match a set of file patterns

arguments:
root - the canonical root of the tree you're matching against
cwd - the current working directory, if relevant
patterns - patterns to find
include - patterns to include (unless they are excluded)
exclude - patterns to exclude (even if they are included)
default - if a pattern in patterns has no explicit type, assume this one
auditor - optional path auditor
ctx - optional changecontext
listsubrepos - if True, recurse into subrepositories
warn - optional function used for printing warnings
badfn - optional bad() callback for this matcher instead of the default
icasefs - make a matcher for wdir on case insensitive filesystems, which
    normalizes the given patterns to the case in the filesystem

a pattern is one of:
'glob:<glob>' - a glob relative to cwd
're:<regexp>' - a regular expression
'path:<path>' - a path relative to repository root, which is matched
                recursively
'filepath:<path>' - an exact path to a single file, relative to the
                    repository root
'rootfilesin:<path>' - a path relative to repository root, which is
                matched non-recursively (will not match subdirectories)
'relglob:<glob>' - an unrooted glob (*.c matches C files in all dirs)
'relpath:<path>' - a path relative to cwd
'relre:<regexp>' - a regexp that needn't match the start of a name
'set:<fileset>' - a fileset expression
'include:<path>' - a file of patterns to read and include
'subinclude:<path>' - a file of patterns to match against files under
                      the same directory
'<something>' - a pattern of the specified default type

>>> def _match(root, *args, **kwargs):
...     return match(util.localpath(root), *args, **kwargs)

Usually a patternmatcher is returned:
>>> _match(b'/foo', b'.', [br're:.*\.c$', b'path:foo/a', b'*.py'])
<patternmatcher patterns='[^/]*\\.py$|foo/a(?:/|$)|.*\\.c$'>

Combining 'patterns' with 'include' (resp. 'exclude') gives an
intersectionmatcher (resp. a differencematcher):
>>> type(_match(b'/foo', b'.', [br're:.*\.c$'], include=[b'path:lib']))
<class 'mercurial.match.intersectionmatcher'>
>>> type(_match(b'/foo', b'.', [br're:.*\.c$'], exclude=[b'path:build']))
<class 'mercurial.match.differencematcher'>

Notice that, if 'patterns' is empty, an alwaysmatcher is returned:
>>> _match(b'/foo', b'.', [])
<alwaysmatcher>

The 'default' argument determines which kind of pattern is assumed if a
pattern has no prefix:
>>> _match(b'/foo', b'.', [br'.*\.c$'], default=b're')
<patternmatcher patterns='.*\\.c$'>
>>> _match(b'/foo', b'.', [b'main.py'], default=b'relpath')
<patternmatcher patterns='main\\.py(?:/|$)'>
>>> _match(b'/foo', b'.', [b'main.py'], default=b're')
<patternmatcher patterns='main.py'>

The primary use of matchers is to check whether a value (usually a file
name) matches againset one of the patterns given at initialization. There
are two ways of doing this check.

>>> m = _match(b'/foo', b'', [br're:.*\.c$', b'relpath:a'])

1. Calling the matcher with a file name returns True if any pattern
matches that file name:
>>> m(b'a')
True
>>> m(b'main.c')
True
>>> m(b'test.py')
False

2. Using the exact() method only returns True if the file name matches one
of the exact patterns (i.e. not re: or glob: patterns):
>>> m.exact(b'a')
True
>>> m.exact(b'main.c')
False
c                   > [        XX#XE5      n/ nU HG  u  pn
US;  a(  U	nT" U	5      n	X:w  a  UT;   a  UR                  XU
45        UR                  XU
45        MI     U$ )N)r   r   )_donormalizer4   )patternsdefaultrN   r9   auditorwarnkpr:   r?   patsrA   pr   dsnormalizes               r.   	normalizematch.<locals>.normalize  ss    hGJBH&("F00A&t,D yQ(] &(9:V 45 ') OrF   r[   r   N)osrQ   isabsrL   r   	localpathre   repor   rn   rY   alwaysmatcherrb   patternmatcherincludematcherintersectmatchersdifferencematcher)rN   r9   rf   includeexcluderg   rh   r;   r<   ri   r2   icasefsrn   r:   r-   imemr   rm   s                    @@r.   r+   r+      s;   D 77==
'',,tT^^C0
1CI88:&&((	 X7I))e$A%)A % Wgt'H"%
 a$Wgt'H"%
 a$HrF   c                    [        XS9$ )Nr1   )exactmatcher)filesr2   s     r.   exactr   L  s    ++rF   c                    [        U 5      $ N)rt   r1   s    r.   alwaysr   P  s    rF   c                    [        U 5      $ r   )r]   r1   s    r.   neverr   T  s    rF   c                >    [         R                   " U 5      nXl        U$ )zOMake a copy of the given matcher, replacing its bad method with the given
one.
)copybad)r+   r2   r-   s      r.   badmatchr   X  s     			%AEHrF   c           	        / nSnU  Vs/ s H  n[        X5      PM     sn GH_  u  pU	[        ;   a  [        R                  " X#XS9n
GO%X;   a  [        R
                  " U
5      n
GOU	S;   a   [        R                  " U
5      nU	S:X  a  UR                  S5      nOUR                  5       nU Vs/ s H  o(       d  M  UPM     nn[        XX#XE5       H  u  pnUR                  XU
45        M     M  U	S:X  aw   [        R                   R#                  U[        R$                  " U
5      5      n['        X5      n[        UXX4U5       H"  u  pnUR                  XU=(       d    U
45        M$     GML  UR                  XS45        GMb     U$ s  snf s  snf ! [         a#    [        R                  " [        S5      U
-  5      ef = f! [        R                   a*  n[        R                  " SU
UR(                  4-  5      eS	nAf[         aE  nU(       a4  U" [        S
5      U
[*        R,                  " UR.                  5      4-  5         S	nANS	nAff = f)z}Convert 'kind:pat' from the patterns list to tuples with kind and
normalized and rooted patterns and with listfiles expanded.)r   r   r   r$   r   )rh   )r   r    r        s   unable to read file list (%s)r"   s   %s: %sNs*   skipping unreadable pattern file '%s': %s
rF   )	_patsplitcwdrelativepatternkindsr   rM   r   rJ   readfilesplit
splitlinesOSErrorr   Abortr   re   r4   rp   rQ   rL   rr   readpatternfilemessager   forcebytestrstrerror)rf   rg   rN   r9   rh   ri   r:   kinds_to_normalizerl   r?   r@   r   fkrA   fullpathincludepatsinsts                     r.   re   re   a  s"    H 6>>Xi+X>	**$$TEC'--$C00Mc*<'!KK.E!,,.E$)/EqQE/ !-7!f s,! Z77<<dnnS.AB-h=$0d%LA& OOQ6=S$9:%$ C()Y ?Z O[ ? 0 Mkk!$D"E"KLLM ;; kk   HI
 7 7 FGHsO   F,AF.
F<FF7A3GF-F>I%G::I;IIc                      \ rS rSrSS jrSS jrSS jrS rS rSr	\
S 5       rS	 r\
S
 5       rS rS rS rS rS rS rS rS rSrg)basematcheri  Nc                &    SU l         Ub  Xl        g g NF_was_tampered_withr   )selfr2   s     r.   __init__basematcher.__init__  s    "'H rF   c                    U R                   $ r   )r   r   s    r.   was_tampered_with_nonrec$basematcher.was_tampered_with_nonrec  s     &&&rF   c                "    U R                  5       $ r   )r   r   s    r.   was_tampered_withbasematcher.was_tampered_with  s    ,,..rF   c                $    U R                  U5      $ r   )matchfnr   fns     r.   __call__basematcher.__call__  s    ||BrF   c                    g)zgCallback from dirstate.walk for each explicit file that can't be
found/accessed, with an error message.NrW   r   r   msgs      r.   r   basematcher.bad  s    rF   c                    / $ r   rW   r   s    r.   _filesbasematcher._files  s    	rF   c                    U R                   $ )zExplicitly listed files or patterns or roots:
if no patterns or .always(): empty list,
if exact: list exact files,
if not .anypats(): list all files and dirs,
else: optimal rootsr   r   s    r.   r   basematcher.files  s     {{rF   c                ,    [        U R                  5      $ r   )setr   r   s    r.   _filesetbasematcher._fileset  s    4;;rF   c                    XR                   ;   $ )z!Returns True if f is in .files().)r   r   r   s     r.   r   basematcher.exact  s    MM!!rF   c                    gr   rW   r   s     r.   r   basematcher.matchfn      rF   c                    g)ax  Decides whether a directory should be visited based on whether it
has potential matches in it or one of its subdirectories. This is
based on the match's primary, included, and excluded patterns.

Returns the string 'all' if the given directory and all subdirectories
should be visited. Otherwise returns True or False indicating whether
the given directory should be visited.
TrW   r   dirs     r.   visitdirbasematcher.visitdir  s     rF   c                    g)aM  Decides whether a directory should be visited based on whether it
has potential matches in it or one of its subdirectories, and
potentially lists which subdirectories of that directory should be
visited. This is based on the match's primary, included, and excluded
patterns.

This function is very similar to 'visitdir', and the following mapping
can be applied:

     visitdir | visitchildrenlist
    ----------+-------------------
     False    | set()
     'all'    | 'all'
     True     | 'this' OR non-empty set of subdirs -or files- to visit

Example:
  Assume matchers ['path:foo/bar', 'rootfilesin:qux'], we would return
  the following values (assuming the implementation of visitchildrenset
  is capable of recognizing this; some implementations are not).

  '' -> {'foo', 'qux'}
  'baz' -> set()
  'foo' -> {'bar'}
  # Ideally this would be 'all', but since the prefix nature of matchers
  # is applied to the entire matcher, we have to downgrade this to
  # 'this' due to the non-prefix 'rootfilesin'-kind matcher being mixed
  # in.
  'foo/bar' -> 'this'
  'qux' -> 'this'

Important:
  Most matchers do not know if they're representing files or
  directories. They see ['path:dir/f'] and don't know whether 'f' is a
  file or a directory, so visitchildrenset('dir') for most matchers will
  return {'f'}, but if the matcher knows it's a file (like exactmatcher
  does), it may return 'this'. Do not rely on the return being a set
  indicating that there are no files in this dir to investigate (or
  equivalently that if there are files to investigate in 'dir' that it
  will always return 'this').
   thisrW   r   s     r.   visitchildrensetbasematcher.visitchildrenset  s    R rF   c                    g)z[Matcher will match everything and .files() will be empty --
optimization might be possible.FrW   r   s    r.   r   basematcher.always       rF   c                    g)z[Matcher will match exactly the list of files in .files() --
optimization might be possible.FrW   r   s    r.   isexactbasematcher.isexact
  r   rF   c                    g)zWMatcher will match the paths in .files() recursively --
optimization might be possible.FrW   r   s    r.   rT   basematcher.prefix  r   rF   c                    U R                  5       (       + =(       a1    U R                  5       (       + =(       a    U R                  5       (       + $ )zXNone of .always(), .isexact(), and .prefix() is true --
optimizations will be difficult.)r   r   rT   r   s    r.   anypatsbasematcher.anypats  s/     ;;= M%7M<MMrF   r   r   returnbool)__name__
__module____qualname____firstlineno__r   r   r   r   r   traversedirpropertycacher   r   r   r   r   r   r   r   r   rT   r   __static_attributes__rW   rF   r.   r   r     sw    
'
/ 
2 K     "	)V


NrF   r   c                  N   ^  \ rS rSrSrS
U 4S jjrS rS rS rS r	S r
S	rU =r$ )rt   i  zMatches everything.c                $   > [         TU ]  U5        g r   superr   r   r2   	__class__s     r.   r   alwaysmatcher.__init__      rF   c                    gNTrW   r   s    r.   r   alwaysmatcher.always       rF   c                    gr   rW   r   s     r.   r   alwaysmatcher.matchfn#  r   rF   c                    gN   allrW   r   s     r.   r   alwaysmatcher.visitdir&      rF   c                    gr   rW   r   s     r.   r   alwaysmatcher.visitchildrenset)  r   rF   c                    g)Nz<alwaysmatcher>rW   r   s    r.   __repr__alwaysmatcher.__repr__,  s    !rF   rW   r   )r   r   r   r   __doc__r   r   r   r   r   r   r   __classcell__r   s   @r.   rt   rt     s)     " "rF   rt   c                  N   ^  \ rS rSrSrS
U 4S jjrS rS rS rS r	S r
S	rU =r$ )r]   i0  zMatches nothing.c                $   > [         TU ]  U5        g r   r   r   s     r.   r   nevermatcher.__init__3  r   rF   c                    gr   rW   r   s    r.   r   nevermatcher.isexact;  r   rF   c                    gr   rW   r   s    r.   rT   nevermatcher.prefix>  r   rF   c                    gr   rW   r   s     r.   r   nevermatcher.visitdirA  r   rF   c                    [        5       $ r   )r   r   s     r.   r   nevermatcher.visitchildrensetD  s	    urF   c                    g)Nz<nevermatcher>rW   r   s    r.   r   nevermatcher.__repr__G  s     rF   rW   r   )r   r   r   r   r   r   r   rT   r   r   r   r   r   r   s   @r.   r]   r]   0  s)     ! !rF   r]   c                  T   ^  \ rS rSrSrSU 4S jjr\R                  S 5       rSr	U =r
$ )predicatematcheriK  z/A matcher adapter for a simple boolean functionc                <   > [         TU ]  U5        Xl        X l        g r   )r   r   r   	_predrepr)r   predfnpredreprr2   r   s       r.   r   predicatematcher.__init__N  s    !rF   c                    [         R                  " U R                  5      =(       d     [        R                  " U R
                  5      nSU-  $ )Ns   <predicatenmatcher pred=%s>)r   	buildreprr  r   bytereprr   )r   ss     r.   r   predicatematcher.__repr__S  s<      0 
H4E4ELL5
 .11rF   )r  r   NN)r   r   r   r   r   r   r   	strmethodr   r   r   r   s   @r.   r  r  K  s%    9"
 2 2rF   r  c                   ^ ^^ [        T5      nUS:X  a  gT T;   a  gUS:  a)  [        U4S j[        R                  " T 5       5       5      $ ST;   a  g[	        S5      m[        U U4S jT 5       5      $ )	zDReturns True if `path` (or any parent of `path`) is in `prefix_set`.r   FT   c              3  ,   >#    U  H	  oT;   v   M     g 7fr   rW   ).0	parentdir
prefix_sets     r.   	<genexpr>)path_or_parents_in_set.<locals>.<genexpr>f  s      
5L	#5L   rF   rH   c              3  v   >#    U  H.  nTR                  U5      =(       a    T[        U5         T:H  v   M0     g 7fr   )
startswithr^   )r  pfrQ   sls     r.   r"  r#  s  s/     PZrtr":tCG}'::Zs   69)r^   anyr   finddirsord)rQ   r!  lr(  s   `` @r.   path_or_parents_in_setr-  [  sx    JAAvz 	1u 
5=5F5Ft5L
 
 	
 j	TB PZPPPrF   c                  l   ^  \ rS rSrSrS
U 4S jjrS rS rS rS r	\
R                  S 5       rS	rU =r$ )ru   iv  a  Matches a set of (kind, pat, source) against a 'root' directory.

>>> kindpats = [
...     (b're', br'.*\.c$', b''),
...     (b'path', b'foo/a', b''),
...     (b'relpath', b'b', b''),
...     (b'glob', b'*.h', b''),
... ]
>>> m = patternmatcher(b'foo', kindpats)
>>> m(b'main.c')  # matches re:.*\.c$
True
>>> m(b'b.txt')
False
>>> m(b'foo/a')  # matches path:foo/a
True
>>> m(b'a')  # does not match path:b, since 'root' is 'foo'
False
>>> m(b'b')  # matches relpath:b, since 'root' is 'foo'
True
>>> m(b'lib.h')  # matches glob:*.h
True

>>> m.files()
[b'', b'foo/a', b'', b'b']
>>> m.exact(b'foo/a')
True
>>> m.exact(b'b')
True
>>> m.exact(b'lib.h')  # exact matches are for (rel)path kinds
False
c                  > [         TU ]  U5        UR                  5         [        b  X l        [        U5      u  pEn[        U5      U l        [        U5      U l	        X`l
        [        U5      U l        [        USU5      u  U l        U l        g )N   $)r   r   sortrustmod	_kindpats_rootsdirsandparents_explicitfilesr   r   _dirs_explicit_dirs_prefix_buildmatch_pats_matchfnr   rN   r:   r2   rootsdirsparentsr   s          r.   r   patternmatcher.__init__  su     &N3H=W$X.!$i
x($/$$E!
DMrF   c                D    XR                   ;   a  gU R                  U5      $ r   )r   r;  r   s     r.   r   patternmatcher.matchfn  s    }}R  rF   c                    U R                   (       a  XR                  ;   a  gXR                  ;   =(       d1    [        XR                  5      =(       d    [        XR                  5      $ r   )r8  r   r7  r-  r6  r   s     r.   r   patternmatcher.visitdir  sJ    <<C==0:: @%c==9@%c+>+>?	
rF   c                d    U R                  U5      nUSL a  gU(       d
  [        5       $ US:X  d   eg)NTr   r   )r   r   )r   r   rets      r.   r   patternmatcher.visitchildrenset  s3    mmC $;5Lf}}rF   c                    U R                   $ r   )r8  r   s    r.   rT   patternmatcher.prefix      ||rF   c                H    S[         R                  " U R                  5      -  $ )Ns   <patternmatcher patterns=%r>r   bytestrr:  r   s    r.   r   patternmatcher.__repr__      .1A1A$**1MMMrF   )r7  r6  r   r3  r;  r:  r8  r   )r   r   r   r   r   r   r   r   r   rT   r   r  r   r   r   r   s   @r.   ru   ru   v  s?    @F !

 N NrF   ru   c                  :    \ rS rSrSS jrS r\S 5       rS rSr	g)	_dirchildreni  Nc                l    0 U l         U=(       d    / U l        U R                  nU H  nU" U5        M     g r   )r7  _onlyincludeaddpath)r   pathsonlyincluderT  r   s        r.   r   _dirchildren.__init__  s0    
'-2,,AAJ rF   c                    US:X  a  g U R                   n[        R                  nU" U5       H?  u  pEX@R                  ;  a  M  UR	                  U[        5       5      R                  U5        MA     g NrF   )r7  rQ  _findsplitdirsrS  
setdefaultr   add)r   rQ   r>  findsplitdirsdbs         r.   rT  _dirchildren.addpath  s[    3;zz$33!$'DA)))OOAsu%))!, (rF   c              #     #    [        U 5      nU R                  S5      nUS:w  a+  U S U XS-   U 4v   UnU R                  SSU5      nUS:w  a  M+  SU S U 4v   g 7f)NrH   r
   r   rF   )r^   rfind)rQ   oldposposs      r.   rZ  _dirchildren._findsplitdirs  sr      TjjRit*d7V444F**T1c*C Ri 4=  s   AA
Ac                J    U R                   R                  U[        5       5      $ r   )r7  getr   )r   rQ   s     r.   rh  _dirchildren.get  s    zz~~dCE**rF   )r7  rS  r   )
r   r   r   r   r   rT  staticmethodrZ  rh  r   rW   rF   r.   rQ  rQ    s%    - ! !+rF   rQ  c                  l   ^  \ rS rSrSU 4S jjrS r\S 5       rS r\	R                  S 5       rSrU =r$ )	rv   i  c                   > [         TU ]  U5        [        b  X l        [	        USU5      u  U l        U l        [        U5      U l        [        U5      u  pEn[        U5      U l
        [        U5      U l        X`l        g )N   (?:/|$))r   r   r2  r3  r9  r:  r   r8  r4  r   _rootsr7  _parentsr<  s          r.   r   includematcher.__init__  sl     &N#.xT#J 
DLx(3H=W%jY
  rF   c                    U R                   (       a  XR                  ;   a  gXR                  ;   =(       d*    XR                  ;   =(       d    [	        XR                  5      $ r   )r8  rn  r7  ro  r-  r   s     r.   r   includematcher.visitdir   sD    <<C;;.:: 8mm#8%c;;7	
rF   c                    [        [        R                  " U R                  U R                  U R
                  5      U R
                  S9$ )N)rV  )rQ  	itertoolschainr7  rn  ro  r   s    r.   _allparentschildren"includematcher._allparentschildren	  s4     OODJJT]]C
 	
rF   c                B   U R                   (       a  XR                  ;   a  gSU R                  ;   d)  XR                  ;   d  [        XR                  5      (       a  gXR                  ;   a,  U R
                  R                  U5      =(       d
    [        5       $ [        5       $ )Nr   rF   r   )r8  rn  r7  r-  ro  rv  rh  r   r   s     r.   r   includematcher.visitchildrenset  sn    <<C;;. 4;;jj %c;;77--++//4==urF   c                H    S[         R                  " U R                  5      -  $ )Ns   <includematcher includes=%r>rL  r   s    r.   r   includematcher.__repr__&  rO  rF   )r7  r3  ro  r:  r8  rn  r   r   )r   r   r   r   r   r   r   rv  r   r   r  r   r   r   r   s   @r.   rv   rv     sB     "
 

 

  N NrF   rv   c                     ^  \ rS rSrSrSU 4S jjr\R                  r\	S 5       r
S r\	S 5       r\	S 5       rS rS	 r\R"                  S
 5       rSrU =r$ )r   i+  a  Matches the input files exactly. They are interpreted as paths, not
patterns (so no kind-prefixes).

>>> m = exactmatcher([b'a.txt', br're:.*\.c$'])
>>> m(b'a.txt')
True
>>> m(b'b.txt')
False

Input files that would be matched are exactly those returned by .files()
>>> m.files()
['a.txt', 're:.*\\.c$']

So pattern 're:.*\.c$' is not considered as a regex, but as a file name
>>> m(b'main.c')
False
>>> m(br're:.*\.c$')
True
c                |   > [         TU ]  U5        [        U[        5      (       a  Xl        g [        U5      U l        g r   )r   r   
isinstancelistr   )r   r   r2   r   s      r.   r   exactmatcher.__init__@  s-    eT""Ku+DKrF   c                T    [        [        R                  " U R                  5      5      $ r   )r   r   r>  r   r   s    r.   r7  exactmatcher._dirsJ  s    8==/00rF   c                    XR                   ;   $ r   )r7  r   s     r.   r   exactmatcher.visitdirN  s    jj  rF   c                <    U R                   U R                  S1-
  -  $ )z2A memoized set of candidates for visitchildrenset.rF   )r   r7  r   s    r.   _visitchildrenset_candidates)exactmatcher._visitchildrenset_candidatesQ  s     }}tzzSE111rF   c                ,    [        U R                  5      $ )z:A memoized sorted list of candidates for visitchildrenset.)sortedr  r   s    r.   #_sorted_visitchildrenset_candidates0exactmatcher._sorted_visitchildrenset_candidatesV  s     d7788rF   c                   U R                   (       a  XR                  ;  a
  [        5       $ US:X  a  U R                  nOU R                  nUS-   n[
        R                  " X#5      nU[        R                  " [        [        S5      S-   5      5      -   n[
        R                  " X%US9n[        U5      nX$U  Vs1 s H  oUS  iM	     nnU Vs1 s H  nSU;  d  M  UiM     n	nU	(       d   eU	$ s  snf s  snf )NrF   rH   r
   )lo)r   r7  r   r  r  bisectbisect_leftr   
strtolocalchrr+  r^   )
r   r   
candidatesr^  firstdnextlastdlencrF  s
             r.   r   exactmatcher.visitchildrenset[  s    }}:: 55L#:::JAAJd
A &&z5E
 (--c#d)a-.@AAE%%jEBDq6D,6T,BC,BqDE(,BJC %6*QAq*6 
s
 D 7s   9C.
C3C3c                    gr   rW   r   s    r.   r   exactmatcher.isexact|  r   rF   c                     SU R                   -  $ )Ns   <exactmatcher files=%r>r   r   s    r.   r   exactmatcher.__repr__  s    )DKK77rF   r   r   )r   r   r   r   r   r   r   r   r   r   r7  r   r  r  r   r   r   r  r   r   r   r   s   @r.   r   r   +  s~    (& G1 1! 2 2 9 9B 8 8rF   r   c                     ^  \ rS rSrSrU 4S jrSS jrS r\S 5       r	S r
S rS	 r\R                  S
 5       rSrU =r$ )rx   i  zComposes two matchers by matching if the first matches and the second
does not.

The second matcher's non-matching-attributes (bad, traversedir) are ignored.
c                ~   > [         TU ]  5         Xl        X l        UR                  U l        UR
                  U l        g r   r   r   _m1_m2r   r   r   m1m2r   s      r.   r   differencematcher.__init__  /    66>>rF   c                    U R                  5       =(       d;    U R                  R                  5       =(       d    U R                  R                  5       $ r   r   r  r   r  r   s    r.   r   #differencematcher.was_tampered_with  =    ))+ ,xx))+,xx))+	
rF   c                ^    U R                  U5      =(       a    U R                  U5      (       + $ r   r  r  r   s     r.   r   differencematcher.matchfn  s    xx{.488A;.rF   c                    U R                  5       (       a9  U R                  R                  5        Vs/ s H  o" U5      (       d  M  UPM     sn$ U R                  R                  5       $ s  snf r   )r   r  r   r   s     r.   r   differencematcher._files  sM    <<>>#xx~~/;/!47A/;; xx~~ <s   A)A)c                    U R                   R                  U5      S:X  a  gU R                   R                  U5      (       d  U R                  R                  U5      $ [        U R                  R                  U5      5      $ )Nr   F)r  r   r  r   r   s     r.   r   differencematcher.visitdir  s`    88S!V+""3''88$$S))DHH%%c*++rF   c                    U R                   R                  U5      nUS:X  a
  [        5       $ U R                  R                  U5      nU(       d  U$ US;   a  gU$ )Nr   )r   r   r   )r  r   r   r  )r   r   m2_setm1_sets       r.   r   "differencematcher.visitchildrenset  sX    **3/V5L**3/ M&&  rF   c                6    U R                   R                  5       $ r   )r  r   r   s    r.   r   differencematcher.isexact  s    xx!!rF   c                8    SU R                   U R                  4-  $ )Ns    <differencematcher m1=%r, m2=%r>r  r   s    r.   r   differencematcher.__repr__  s    2dhh5IIIrF   r  r  r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   s   @r.   rx   rx     sV    *
/    ,2" J JrF   rx   c                2   U b  Uc  U =(       d    U$ U R                  5       (       a:  [        R                  " U5      nU R                  Ul        U R                  Ul        U$ UR                  5       (       a  [        R                  " U 5      nU$ [	        X5      $ )zComposes two matchers by matching if both of them match.

The second matcher's non-matching-attributes (bad, traversedir) are ignored.
)r   r   r   r   intersectionmatcher)r  r  r-   s      r.   rw   rw     ss    
 
zRZxR	yy{{IIbM 	yy{{IIbMr&&rF   c                     ^  \ rS rSrU 4S jrSS jr\S 5       rS rS r	S r
S rS	 r\R                  S
 5       rSrU =r$ )r  i  c                ~   > [         TU ]  5         Xl        X l        UR                  U l        UR
                  U l        g r   r  r  s      r.   r   intersectionmatcher.__init__  r  rF   c                    U R                  5       =(       d;    U R                  R                  5       =(       d    U R                  R                  5       $ r   r  r   s    r.   r   %intersectionmatcher.was_tampered_with  r  rF   c                Z   U R                  5       (       a]  U R                  U R                  p!UR                  5       (       d  X!p!UR                  5        Vs/ s H  o2" U5      (       d  M  UPM     sn$ U R                  R                  5       U R                  R                  5       -   $ s  snf r   )r   r  r  r   )r   r  r  r   s       r.   r   intersectionmatcher._files  su    <<>>XXtxx::<<B!xxz3z!RUAz33
 xx~~$((.."222 4s   B(*B(c                T    U R                  U5      =(       a    U R                  U5      $ r   r  r   s     r.   r   intersectionmatcher.matchfn   s    xx{*txx{*rF   c                    U R                   R                  U5      nUS:X  a  U R                  R                  U5      $ [        U=(       a    U R                  R                  U5      5      $ r   )r  r   r  r   )r   r   visit1s      r.   r   intersectionmatcher.visitdir  sR    ""3'V88$$S))F5txx00566rF   c                f   U R                   R                  U5      nU(       d
  [        5       $ U R                  R                  U5      nU(       d
  [        5       $ US:X  a  U$ US:X  a  U$ US:X  d  US:X  a  g[	        U[        5      (       a  [	        U[        5      (       d   eUR                  U5      $ )Nr   r   )r  r   r   r  r~  intersection)r   r   r  r  s       r.   r   $intersectionmatcher.visitchildrenset
  s    **3/5L**3/5LVMvMW' 1&#&&:fc+B+BBB""6**rF   c                x    U R                   R                  5       =(       a    U R                  R                  5       $ r   )r  r   r  r   s    r.   r   intersectionmatcher.always  s#    xx 6TXX__%66rF   c                x    U R                   R                  5       =(       d    U R                  R                  5       $ r   )r  r   r  r   s    r.   r   intersectionmatcher.isexact   s'    xx!7TXX%5%5%77rF   c                8    SU R                   U R                  4-  $ )Ns"   <intersectionmatcher m1=%r, m2=%r>r  r   s    r.   r   intersectionmatcher.__repr__#  s    4$((7KKKrF   r  r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   s   @r.   r  r    sV    *
 
3 
3+7+&78 L LrF   r  c                     ^  \ rS rSrSrSU 4S jjrSS jrS rS rS r	S r
S	 rS
 r\R                  S 5       rSrU =r$ )subdirmatcheri(  aG  Adapt a matcher to work on a subdirectory only.

The paths are remapped to remove/insert the path as needed:

>>> from . import pycompat
>>> m1 = match(util.localpath(b'/root'), b'', [b'a.txt', b'sub/b.txt'], auditor=lambda name: None)
>>> m2 = subdirmatcher(b'sub', m1)
>>> m2(b'a.txt')
False
>>> m2(b'b.txt')
True
>>> m2.matchfn(b'a.txt')
False
>>> m2.matchfn(b'b.txt')
True
>>> m2.files()
['b.txt']
>>> m2.exact(b'b.txt')
True
>>> def bad(f, msg):
...     print(pycompat.sysstr(b"%s: %s" % (f, msg)))
>>> m1.bad = bad
>>> m2.bad(b'x.txt', b'No such file')
sub/x.txt: No such file
c                ~  >^ [         TU ]  5         TU l        X l        UR	                  5       U l        UR                   Vs/ s H/  nUR                  TS-   5      (       d  M  U[        T5      S-   S  PM1     snU l        UR                  5       (       a%  [        U4S jUR                   5       5      U l        g g s  snf )NrH   r
   c              3  ,   >#    U  H	  oT:H  v   M     g 7fr   rW   )r  r   rQ   s     r.   r"  )subdirmatcher.__init__.<locals>.<genexpr>R  s     A.QDy.r$  )r   r   _path_matcherr   _alwaysr   r&  r^   rT   r)  )r   rQ   r   r   r   s    `  r.   r   subdirmatcher.__init__C  s    
~~' ^^
#||D4K( Ac$i!mo#
 >>A'..AADL 
s   B:"B:c                d    U R                  5       =(       d    U R                  R                  5       $ r   )r   r  r   r   s    r.   r   subdirmatcher.was_tampered_withT  s%    ))+Pt}}/N/N/P	
rF   c                \    U R                   R                  U R                  S-   U-   U5        g NrH   )r  r   r  r   s      r.   r   subdirmatcher.badY  s$    $**t+a/5rF   c                X    U R                   R                  U R                  S-   U-   5      $ r  )r  r   r  r   s     r.   r   subdirmatcher.matchfn\  s'    
 }}$$TZZ$%6%:;;rF   c                    US:X  a  U R                   nOU R                   S-   U-   nU R                  R                  U5      $ NrF   rH   )r  r  r   r   s     r.   r   subdirmatcher.visitdirc  s:    #:**C**t#c)C}}%%c**rF   c                    US:X  a  U R                   nOU R                   S-   U-   nU R                  R                  U5      $ r  )r  r  r   r   s     r.   r   subdirmatcher.visitchildrensetj  s:    #:**C**t#c)C}}--c22rF   c                    U R                   $ r   )r  r   s    r.   r   subdirmatcher.alwaysq  rJ  rF   c                f    U R                   R                  5       =(       a    U R                  (       + $ r   )r  rT   r  r   s    r.   rT   subdirmatcher.prefixt  s!    }}##%:dll*::rF   c                8    SU R                   U R                  4-  $ )Ns#   <subdirmatcher path=%r, matcher=%r>)r  r  r   s    r.   r   subdirmatcher.__repr__w  s"    5JJMM9
 
 	
rF   )r  r   r  r  )rQ   bytesr   r   r   Noner   )r   r   r   r   r   r   r   r   r   r   r   r   rT   r   r  r   r   r   r   s   @r.   r  r  (  sK    4B"

6<+3; 
 
rF   r  c                     ^  \ rS rSrSrSU 4S jjr\S 5       rS r\S 5       r	S r
S rS	 rS
 r\R                  S 5       rSrU =r$ )r8   i  a  Adapt a matcher to work on a parent directory.

The matcher's non-matching-attributes (bad, traversedir) are ignored.

The prefix path should usually be the relative path from the root of
this matcher to the root of the wrapped matcher.

>>> m1 = match(util.localpath(b'/root/d/e'), b'f', [b'../a.txt', b'b.txt'], auditor=lambda name: None)
>>> m2 = prefixdirmatcher(b'd/e', m1)
>>> m2(b'a.txt')
False
>>> m2(b'd/e/a.txt')
True
>>> m2(b'd/e/b.txt')
False
>>> m2.files()
['d/e/a.txt', 'd/e/f/b.txt']
>>> m2.exact(b'd/e/a.txt')
True
>>> m2.visitdir(b'd')
True
>>> m2.visitdir(b'd/e')
True
>>> m2.visitdir(b'd/e/f')
True
>>> m2.visitdir(b'd/e/g')
False
>>> m2.visitdir(b'd/ef')
False
c                   > [         TU ]  U5        U(       d  [        R                  " S5      eXl        US-   U l        X l        g )Ns   prefix path must not be emptyrH   )r   r   r   r3   r  _pathprefixr  )r   rQ   r   r2   r   s       r.   r   prefixdirmatcher.__init__  s;    (()IJJ
$;rF   c                r    U R                   R                   Vs/ s H  oR                  U-   PM     sn$ s  snf r   )r  r   r  r   s     r.   r   prefixdirmatcher._files  s/    .2mm.B.BC.B  1$.BCCCs   4c                    UR                  U R                  5      (       d  gU R                  R                  U[	        U R                  5      S  5      $ r   )r&  r  r  r   r^   r   s     r.   r   prefixdirmatcher.matchfn  sB    ||D,,--}}$$Qs4+;+;'<'>%?@@rF   c                T    [        [        R                  " U R                  5      5      $ r   )r   r   r*  r  r   s    r.   	_pathdirsprefixdirmatcher._pathdirs  s    8$$TZZ011rF   c                   XR                   :X  a  U R                  R                  S5      $ UR                  U R                  5      (       a1  U R                  R                  U[        U R                  5      S  5      $ XR                  ;   $ rY  )r  r  r   r&  r  r^   r  r   s     r.   r   prefixdirmatcher.visitdir  sk    **==))#..>>$**++==))#c$2B2B.C.E*FGGnn$$rF   c                ,   XR                   :X  a  U R                  R                  S5      $ UR                  U R                  5      (       a1  U R                  R                  U[        U R                  5      S  5      $ XR                  ;   a  g[        5       $ )NrF   r   )r  r  r   r&  r  r^   r  r   r   s     r.   r   !prefixdirmatcher.visitchildrenset  sr    **==11#66>>$**++==11#c$:J:J6K6M2NOO.. urF   c                6    U R                   R                  5       $ r   )r  r   r   s    r.   r   prefixdirmatcher.isexact  s    }}$$&&rF   c                6    U R                   R                  5       $ r   )r  rT   r   s    r.   rT   prefixdirmatcher.prefix  s    }}##%%rF   c                `    S[         R                  " U R                  5      U R                  4-  $ )Ns&   <prefixdirmatcher path=%r, matcher=%r>)r   rM  r  r  r   s    r.   r   prefixdirmatcher.__repr__  s-    8TZZ(MM<
 
 	
rF   )r  r  r  r   )r   r   r   r   r   r   r   r   r   r  r   r   r   rT   r   r  r   r   r   r   s   @r.   r8   r8     sk    >  D DA
 2 2%'& 
 
rF   r8   c                  l   ^  \ rS rSrSrU 4S jrS
S jrS rS rS r	\
R                  S 5       rS	rU =r$ )r_   i  zA matcher that is the union of several matchers.

The non-matching-attributes (bad, traversedir) are taken from the first
matcher.
c                Z   > US   n[         TU ]  5         UR                  U l        Xl        g )Nr   )r   r   r   	_matchers)r   r=   r  r   s      r.   r   unionmatcher.__init__  s(    a[>>!rF   c                p    U R                  5       =(       d     [        [        S U R                  5      5      $ )Nc                "    U R                  5       $ r   )r   )r-   s    r.   <lambda>0unionmatcher.was_tampered_with.<locals>.<lambda>  s    !--/rF   )r   r)  mapr  r   s    r.   r   unionmatcher.was_tampered_with  s.    ,,. 
#/@3
 	
rF   c                H    U R                    H  nU" U5      (       d  M    g   gNTFr  )r   r   r+   s      r.   r   unionmatcher.matchfn  s!    ^^EQxx $ rF   c                n    SnU R                    H"  nUR                  U5      nUS:X  a  Us  $ X$-  nM$     U$ )NFr   )r  r   )r   r   rr-   vs        r.   r   unionmatcher.visitdir  s<    A

3AF{FA	  
 rF   c                   [        5       nSnU R                   H`  nUR                  U5      nU(       d  M  US:X  a  Us  $ U(       d  US:X  a  SnM8  [        U[         5      (       d   eUR	                  U5      nMb     U(       a  gU$ )NFr   r   T)r   r  r   r~  union)r   r   r  thisr-   r  s         r.   r   unionmatcher.visitchildrenset  s|    EA""3'AF{qG|a%%%%
A   rF   c                     SU R                   -  $ )Ns   <unionmatcher matchers=%r>r  r   s    r.   r   unionmatcher.__repr__  s    ,t~~==rF   )r  r   r   )r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   s   @r.   r_   r_     s;    "

& > >rF   r_   c                    [        X5      S   $ )zIf pattern is 'kind:pat' with a known kind, return kind.

>>> patkind(br're:.*\.c$')
're'
>>> patkind(b'glob:*.c')
'glob'
>>> patkind(b'relpath:test.py')
'relpath'
>>> patkind(b'main.py')
>>> patkind(b'main.py', default=b're')
're'
r   )r   )patternrg   s     r.   patkindr    s     W&q))rF   c                V    SU ;   a!  U R                  SS5      u  p#U[        ;   a  X#4$ X4$ )zLSplit a string into the optional pattern kind prefix and the actual
pattern.   :r
   )r   allpatternkinds)r  rg   r?   r@   s       r.   r   r     s6     wMM$*	?"9rF   c                  ^ ^	^
 S[        T 5      sm	m
SnSn[        R                  R                  R                  nU	U
U 4S jnT	T
:  Gay  T T	T	S-    nT	S-  m	US;  a  X" XU5      -  nGOQUS:X  a5  U" 5       S:X  a#  T	S-  m	U" 5       S:X  a  T	S-  m	US-  nGO$US	-  nGOUS
-  nGOUS:X  a  US-  nGO	US:X  a  T	nUT
:  a  T XfS-    S;   a  US-  nUT
:  a#  T XfS-    S:w  a  US-  nUT
:  a  T XfS-    S:w  a  M  UT
:  a  US-  nOT T	U R                  SS5      nUS-   m	USS S:X  a	  SUSS -   nOUSS S:X  a  SU-   nSX4-  nOuUS:X  a  US-  nUS-  nOdUS:X  a  U(       a  US-  nUS-  nOLUS:X  a  U(       a  US-  nO9US:X  a)  U" 5       nU(       a  T	S-  m	X" X5      -  nOX" XU5      -  nO
X" XU5      -  nT	T
:  a  GMy  U$ )a  Convert an extended glob string to a regexp string.

>>> from . import pycompat
>>> def bprint(s):
...     print(pycompat.sysstr(s))
>>> bprint(_globre(br'?'))
.
>>> bprint(_globre(br'*'))
[^/]*
>>> bprint(_globre(br'**'))
.*
>>> bprint(_globre(br'**/a'))
(?:.*/)?a
>>> bprint(_globre(br'a/**/b'))
a/(?:.*/)?b
>>> bprint(_globre(br'[a*?!^][^b][!c]'))
[a*?!^][\^b][^c]
>>> bprint(_globre(br'{a,b}'))
(?:a|b)
>>> bprint(_globre(br'.\*\?'))
\.\*\?
r   rF   c                 ,   > T T:  =(       a    TT T S-    $ )Nr
   rW   )inr@   s   r.   peek_globre.<locals>.peekA  s    1u'QQ'rF   r
   s   *?[{},\   *rH   s   (?:.*/)?   .*   [^/]*   ?   .   [s   !]   ]s   \[   \s   \\   !   ^Ns   %s[%s]   {s   (?:   }   )   ,   |)r^   r   r   regexbytesescapemaprh  replace)r@   resgroupescaper&  r  jstuffrl   r$  r%  s   `        @@r.   _globrer>  %  s6   . c#hDAq
CE__0044F( a%AEN	QK6!<C$Yv~Q6T>FA;&C5LCx$Y4KC$YA1uQQ50Qa%CENd2Q a%CENd2AvvAa((8E1:% 59,E1QZ4'!EME3,.$YQJE6MC$Y54KCQJE$Y54KC%ZAQva|#va|#6!<Cc a%d JrF   s   ^\(\?([aiLmsux]+)\)(.*)c                   U(       d  U S;   a  gU S:X  a  U$ U S:X  a  [         R                  " S5      eU S;   a)  US:X  a  g[        R                  R	                  U5      S-   $ U S	:X  a4  US:X  a  SnUS-   $ [        R                  R	                  U5      S
-   nUS-   $ U S:X  a=  [        U5      nUR                  S5      (       a  SU[        S5      S -   U-   $ SU-   U-   $ U S:X  aV  Sn[        R                  U5      nU(       a  UR                  5       u  pQUR                  S5      (       d  SU-   nUb  SXQ4-  nU$ U S;   a  [        U5      U-   $ [         R                  " SX4-  5      e)ztConvert a (normalized) pattern of any kind into a
regular expression.
globsuffix is appended to the regexp of globs.)r   r   rF   r   r   z7'filepath:' patterns should not be converted to a regexr   r   r,  rm  r$   rH   s   [^/]+$r   r*  r)  Ns   (?:|.*/)r   r1  s   (?%s:%s)r   r   s   not a regex pattern: %s:%s)r   r3   r   r   reescaper>  r&  r^   FLAG_REr+   groups)r?   r@   
globsuffixescapedglobreflagr-   s          r.   _regexrI  |  s    400u}
{$$E
 	
 $$$;'',z99~$;G
 "" oo..s3d:G""zX&& 6#h-/22Z??V#j00xMM#
ID~~d###+C$,C
%%s|j((

 
 !>$!L
MMrF   c                  ^	^
^^ / m
[        X5      u  mn T(       a  0 mUU4S jnT
R                  U5        SnU (       a  [        S U  5       5      (       a\  U  VVVs1 s H  u  pVoviM	     snnnm	U	4S jnS[        R                  " [        [        T	5      5      5      -  nT
R                  U5        O[        X5      u  pHT
R                  U5        [        T
5      S:X  a  UT
S   4$ UU
4S j4$ s  snnnf )	zhReturn regexp string and a matcher function for kindpats.
globsuffix is appended to the regexp of globs.c                   > T HY  u  pU R                  U5      (       d  M  TR                  U5      nUc  [        U6 nUTU'   U" U [        U5      S  5      (       d  MY    g   gr  )r&  rh  r+   r^   )r   rT   rS   mfsubincludessubmatcherss       r.   matchsubinclude$_buildmatch.<locals>.matchsubinclude  sd    '2#<<''$0Bz"K0.0F+!CKM*++# (3 rF   rF   c              3  0   #    U  H  u  po1S :H  v   M     g7f)r$   NrW   )r  r   rl   r  s       r.   r"  _buildmatch.<locals>.<genexpr>  s     ;(wqQN"(s   c                T   > U R                  S5      nUS:  a
  U S U nUT;   $ SnUT;   $ )NrH   r   r,  )rc  )r   r$  r   r>  s      r.   rL  _buildmatch.<locals>.mf  s?    GGDM6BQ%C d{" Cd{"rF   s   rootfilesin: %sr
   r   c                0   >^  [        U 4S jT 5       5      $ )Nc              3  2   >#    U  H  o" T5      v   M     g 7fr   rW   )r  rL  r   s     r.   r"  0_buildmatch.<locals>.<lambda>.<locals>.<genexpr>  s     #?JbBqEEJ   r)  )r   
matchfuncss   `r.   r
  _buildmatch.<locals>.<lambda>  s    #?J#? ?rF   )	rU   r4   allr   pprintr  r  _buildregexmatchr^   )r:   rE  rN   rO  r,   r   rl   r  rL  r>  rZ  rM  rN  s            @@@@r.   r9  r9    s     J-h=K
	 	/*E;(;;;%-.X'!AX.D# '):):4t;M)NNEb!(>IEb!
:!jm##???' /s   C.i N  c                $    SR                  U 5      $ )z5gather multiple regular expressions into a single oner6  )rL   )regexpss    r.   _joinregexesra    s    99WrF   c           	     ^  ^^^^  / n/ n[        5       mU  H:  u  pEnUS:X  a  TR                  U5        M  UR                  [        XEU5      5        M<     [	        U5      nSnSn	[        U5       Hs  u  p[        U5      nU[        :  a$  [        S5      U-  n[        R                  " U5      eX-   [        :  a"  X8U
 nUR                  [	        U5      5        U
nSn	XS-   -  n	Mu     US:X  a  [        U5      mU4S jmO@X8S nUR                  [	        U5      5        U Vs/ s H  n[        U5      PM     snmU4S jmTnT(       a  U(       d  U4S jnOUU4S	 jnUU4$ s  snf ! [        R                   a    U  H  u  nnnUS:X  a  M   [        [        UUU5      5        M(  ! [        R                   aQ    U(       a%  [        R                  " [        S
5      UUU4-  5      e[        R                  " [        S5      UU4-  5      ef = f   [        R                  " [        S5      5      ef = f)a'  Build a match function from a list of kinds and kindpats,
return regexp string and a matcher function.

Test too large input
>>> _buildregexmatch([
...     (b'relglob', b'?' * MAX_RE_SIZE, b'')
... ], b'$')
Traceback (most recent call last):
...
Abort: matcher pattern is too long (20009 bytes)
r   r   s&   matcher pattern is too long (%d bytes)r
   c                &   > [        T" U 5      5      $ r   )r   )r  r   s    r.   r
  "_buildregexmatch.<locals>.<lambda>
  s    T'!*-rF   Nc                0   >^  [        U 4S jT 5       5      $ )Nc              3  2   >#    U  H  o" T5      v   M     g 7fr   rW   )r  r-   r  s     r.   r"  5_buildregexmatch.<locals>.<lambda>.<locals>.<genexpr>  s      ;{!1{rX  rY  )r  allmatcherss   `r.   r
  rd    s    S ;{ ;;rF   c                   > U T;   $ r   rW   )r  r   s    r.   r
  rd    s	    qEzrF   c                ,   > U T;   =(       d    T" U 5      $ r   rW   )r  r   funcs    r.   r
  rd    s    qEz'<T!W'<rF   s   %s: invalid pattern (%s): %ss   invalid pattern (%s): %ss   invalid pattern)r   r\  r4   rI  ra  	enumerater^   MAX_RE_SIZEr   r   r   r/   r'   )r:   rE  	allgroupsr`  r?   r  _source
fullregexpstartidx	groupsizeidxr  	piecesizer   r:  g
actualfuncr   rl   r  rh  r   rk  r   s                       @@@@r.   r^  r^    s   91	&."D7{"		'"NN6$<=	 '/ "'*
	(FCAI;&ABYNkk#&&';6-  e!45	Q&I ) q= ,G-DI&E\%012;<)Q:a=)<K;D
 1
<
:%% = 88 1GAq!KO6!Q
3488 O++9:aAYF   ++a(C&D1v&MNNO   kk!./001s7   DE$ E4*E$ E$ $%H,
F" H,"A%H%H,c                   / n/ nU  H  u  p4nUS;   ag  / nUR                  S5       H.  nSU;   d  SU;   d  SU;   d  SU;   a    OUR                  U5        M0     UR                  SR                  U5      5        Ms  US;   a  US:X  a  S	nUR                  U5        M  US
;   a  US:X  a  S	nUR                  U5        M  UR                  S	5        M     X4$ )a  Returns roots and directories corresponding to each pattern.

This calculates the roots and directories exactly matching the patterns and
returns a tuple of (roots, dirs) for each. It does not return other
directories which may also need to be considered, like the parent
directories.
rA  rH   r-  r2  r(  r+  )r   r   r   r,  rF   r$   )r   r4   rL   )r:   r  r^  r?   r@   rA   rN   rl   s           r.   _patternrootsanddirsry  *  s     	A
A%6))DYYt_19	TQY$!)A % HHTYYt_%77d{HHSM&&d{HHSMHHSM# &$ 4KrF   c                     [        U 5      u  pU$ )zFReturns root directories to match recursively from the given patterns.)ry  )r:   r=  r>  s      r.   rn  rn  I  s    &x0KELrF   c                    [        U 5      u  p[        5       nUR                  [        R                  " U5      5        UR                  [        R                  " U5      5        XU4$ )ac  Returns roots and exact directories from patterns.

`roots` are directories to match recursively, `dirs` should
be matched non-recursively, and `parents` are the implicitly required
directories to walk to items in either roots or dirs.

Returns a tuple of (roots, dirs, parents).

>>> r = _rootsdirsandparents(
...     [(b'glob', b'g/h/*', b''), (b'glob', b'g/h', b''),
...      (b'glob', b'g*', b'')])
>>> print(r[0:2], sorted(r[2])) # the set has an unstable output
(['g/h', 'g/h', ''], []) ['', 'g']
>>> r = _rootsdirsandparents(
...     [(b'rootfilesin', b'g/h', b''), (b'rootfilesin', b'', b'')])
>>> print(r[0:2], sorted(r[2])) # the set has an unstable output
([], ['g/h', '']) ['', 'g']
>>> r = _rootsdirsandparents(
...     [(b'relpath', b'r', b''), (b'path', b'p/p', b''),
...      (b'path', b'', b'')])
>>> print(r[0:2], sorted(r[2])) # the set has an unstable output
(['r', 'p/p', ''], []) ['', 'p']
>>> r = _rootsdirsandparents(
...     [(b'relglob', b'rg*', b''), (b're', b're/', b''),
...      (b'relre', b'rr', b'')])
>>> print(r[0:2], sorted(r[2])) # the set has an unstable output
(['', '', ''], []) ['']
)ry  r   updater   r>  )r:   r  r^  rl   s       r.   r4  r4  O  sN    :  )DAA HHX]]1HHX]]1 7NrF   c                Z    U  Vs/ s H  oS   S;  d  M  UPM     nn[        U5      $ s  snf )zReturns the potential explicit filenames from the patterns.

>>> _explicitfiles([(b'path', b'foo/bar', b'')])
['foo/bar']
>>> _explicitfiles([(b'rootfilesin', b'foo/bar', b'')])
[]
r   rx  )rn  )r:   rj   filables      r.   r5  r5  {  s2     %GHb15F(FrHGG'? Hs   ((c                ,    U  H  u  pnUS;  d  M    g   g)z:Whether all the patterns match a prefix (i.e. recursively)r@  FTrW   rX   s       r.   r8  r8    s"    %6,, & rF   )Literalc                    g r   rW   filepathri   
sourceinfos      r.   r   r     s     	rF   c                    g r   rW   r  s      r.   r   r          	rF   c                    g r   rW   r  s      r.   r   r     r  rF   c                   SSSSSSS.nSn/ n[        U S5       n[        USS	9 GHd  u  pxS
U;   al  [        (       d  [        R                  R                  S5      q[        R                  U5      n	U	(       a  USU	R                  S5       nUR                  SS
5      nUR                  5       nU(       d  M  UR                  S5      (       a  USS R                  5       n
 X:   nM  UnUR                  5        H[  u  pUR                  U5      (       a  UnU[        U5      S n  O2UR                  U
S-   5      (       d  MH  UnU[        U
5      S-   S n  O   U(       a  UR!                  X-   Xx45        GMQ  UR!                  X-   5        GMg     SSS5        U$ ! [         a    U(       a  U" [        S5      X
4-  5         Nf = f! , (       d  f       U$ = f)a  parse a pattern file, returning a list of
patterns. These patterns should be given to compile()
to be validated and converted into a match function.

trailing white space is dropped.
the escape character is backslash.
comments start with #.
empty lines are skipped.

lines can be of the following formats:

syntax: regexp # defaults following lines to non-rooted regexps
syntax: glob   # defaults following lines to non-rooted globs
re:pattern     # non-rooted regular expression
glob:pattern   # non-rooted glob
rootglob:pat   # rooted glob (same root as ^ in regexps)
pattern        # pattern of the current default type

if sourceinfo is set, returns a list of tuples:
(pattern, lineno, originalline).
This is useful to debug ignore patterns.
s   relre:s   relglob:s	   rootglob:r"   r#   )r   s   regexpr   r   r"   r#   rbr
   )start   #s   ((?:^|[^\\])(?:\\\\)*)#.*Ns   \#s   syntax:   s!   %s: ignoring invalid syntax '%s'
r   )openrl  
_commentrer   r'   r(   searchendr8  rstripr&  stripKeyErrorr   itemsr^   r4   )r  ri   r  syntaxessyntaxrf   fplinenoliner-   r  
linesyntaxrelss                r.   r   r     s   2 !$H FH	h	%b2LFt|!z!%1N!OJ%%d+
!%%(+D||FD1;;=Dz**HNN$%[F J#>>+??4((!%JD	,D__QX..!%JA
-D , !2F AB
 12Q 3 
V O/   CD'm,) 
	V Os8   CG F$AG AG&G>G GG
G)NFN)
NNNr   NNFNNFr   r  )r  r  ri   Callable[[bytes], Any]r  zLiteral[True]r   zList[Tuple[bytes, int, bytes]])r  r  ri   r  r  zLiteral[False]r   zList[bytes])F)r  r  ri   r  r  r   r   z,List[Union[Tuple[bytes, int, bytes], bytes]])R
__future__r   r  r   rt  rp   r'   typingr   r   r   r   r   r	   i18nr   interfaces.typesr    r   r   r   r   r   r   utilsr   
interfacesr   int_matcher
importrustr2  r!  r   r   r/   rE   rU   rY   rb   r+   r   r   r   r   re   IMatcherr   rt   r]   r  r-  ru   rQ  rv   r   rx   rw   r  r  r8   r_   r  r   r>  r(   rC  rI  r9  rm  ra  r^  ry  rn  r4  r5  r8  r  TYPE_CHECKINGtyping_extensionsr  r   rW   rF   r.   <module>r     s   #    	 	      

JT
2  0 ""02 	
"@ 	
cL, 9xzN+&& zNz"K ",!; !62{ 2 Q6MN[ MNf"+ "+J:N[ :NzV8; V8rIJ IJX'(AL+ ALHT
K T
nP
{ P
f6>; 6>r* Qh ''//5
6+N\-@` 
E1P>)X 
	 5CP	' 
 $ # 
	   !$  
6	 NrF   