
    d+.              	       8   d Z ddlZddlZddlmZ ddlmZmZm	Z	m
Z
mZmZmZ erddlmZ ddlmZmZ ded	efd
Zded	efdZded	e
e         fdZddededed	efdZ G d d          Z G d d          Z G d d          Zded	efdZ G d d          ZdS )zhParsing of gitignore files.

For details for the matching rules, see https://git-scm.com/docs/gitignore
    N)suppress)TYPE_CHECKINGBinaryIODictIterableListOptionalUnion   )Repo)Configget_xdg_config_home_pathsegmentreturnc                    | dk    rdS d}dt          |           }}||k     rd| ||dz            }|dz   }|dk    r|dz  }n>|dk    r|dz  }n1|d	k    r)|t          j        | ||dz                      z  }|dz  }n|d
k    r|}||k     r| ||dz            dk    r|dz   }||k     r| ||dz            dk    r|dz   }||k     r-| ||dz            dk    r|dz   }||k     r| ||dz            dk    ||k    r|dz  }n| ||                             d	d          }|dz   }|                    d          rd|dd          z   }n|                    d          rd	|z   }|d
|z   dz   z  }n|t          j        |          z  }||k     d|S )N   *s   [^/]+    r   r   s   [^/]*   ?s   [^/]   \   [   !   ]s   \[s   \\   ^)lenreescapereplace
startswith)r   resincjstuffs          R/home/feoh/.local/pipx/venvs/poetry/lib/python3.11/site-packages/dulwich/ignore.py_translate_segmentr&   %   s   $x
Cc'llqA
a%%AAIE998OCC$YY7NCC%ZZ29WQQY/000CFAA$YYA1uuQU+t33E1uuQU+t33Ea%%GAAI.$66E a%%GAAI.$66Avvv!,,UG<<E##D)) * 59,EE%%d++ *!EMEte|d**29Q<<C; a%%< Jr   patc                    d}d| dd         vr|dz  }|                      d          r| dd         } |dz  }|                      d          r
| dd         } t          |                     d                    D ]@\  }}|d	k    r|d
z  }||dk    rt          j        d          ndt          |          z   z  }A|                     d          s|dz  }|dz   S )zTranslate a shell PATTERN to a regular expression.

    There is no way to quote meta-characters.

    Originally copied from fnmatch in Python 2.7, but modified for Dulwich
    to cope with features in Git ignore patterns.
    s   (?ms)   /Ns   (.*/)?s   **/   r   s   **s   (/.*)?r   r   s   /?s   \Z)r   	enumeratesplitr   r   r&   endswith)r'   r   r    r   s       r%   	translater/   K   s    C3ss8y
~~f !""gy
~~d !""g		$00 U U
7e9Cq1uuBIdOOO#9KG9T9TTTCC<< u<r   fc              #     K   | D ]}|                     d          }|                                s,|                    d          rB|                    d          rI|                    d          s4|dd         }|                    d          r|                    d          4|                    dd          }|V  dS )zlRead a git ignore file.

    Args:
      f: File-like object to read from
    Returns: List of patterns
    s   
   #    s   \ Nr*   )rstripstripr   r.   r   )r0   lines     r%   read_ignore_patternsr7   o   s         {{7## zz|| 	??4   	 mmD!! 	$--*?*? 	9D mmD!! 	$--*?*? 	||FD))



! r   Fpathpattern
ignorecasec                 H    t          ||                              |           S )zMatch a gitignore-style pattern against a path.

    Args:
      path: Path to match
      pattern: Pattern to match
      ignorecase: Whether to do case-sensitive matching
    Returns:
      bool indicating whether the pattern matched
    )Patternmatch)r8   r9   r:   s      r%   match_patternr>      s"     7J''--d333r   c                   h    e Zd ZdZddedefdZdefdZdefdZ	d	e
defd
ZdefdZdedefdZdS )r<   zA single ignore pattern.Fr9   r:   c                    || _         || _        |dd         dk    rd| _        |dd          }n|dd         dk    r
|dd          }d| _        d}| j        rt          j        }t          j        t          |          |          | _        d S )Nr   r   r   Fr   T)r9   r:   
is_excluder   
IGNORECASEcompiler/   _re)selfr9   r:   flagss       r%   __init__zPattern.__init__   s    $1Q3<4#DOabbkGGqs|u$$!!""+"DO? 	"ME:i00%88r   r   c                     | j         S N)r9   rE   s    r%   	__bytes__zPattern.__bytes__   s
    |r   c                 4    t          j        | j                  S rI   )osfsdecoder9   rJ   s    r%   __str__zPattern.__str__   s    {4<(((r   otherc                 |    t          |t          |                     o| j        |j        k    o| j        |j        k    S rI   )
isinstancetyper9   r:   )rE   rP   s     r%   __eq__zPattern.__eq__   s=    ud4jj)) 4-45#33	
r   c                 h    d                     t          |           j        | j        | j                  S )Nz{}({!r}, {!r}))formatrS   __name__r9   r:   rJ   s    r%   __repr__zPattern.__repr__   s0    &&JJLO
 
 	
r   r8   c                 P    t          | j                            |                    S )zTry to match a path against this ignore pattern.

        Args:
          path: Path to match (relative to ignore location)
        Returns: boolean
        )boolrD   r=   rE   r8   s     r%   r=   zPattern.match   s      DHNN4(()))r   NF)rW   
__module____qualname____doc__bytesrZ   rG   rK   strrO   objectrT   rX   r=    r   r%   r<   r<      s        ""9 9 94 9 9 9 95    ) ) ) ) )
F 
t 
 
 
 

# 
 
 
 
*% *D * * * * * *r   r<   c                       e Zd Zddee         defdZdeddfdZd	eee	f         dee
         fd
Zd	edee         fdZeddedd fd            Zde	fdZdS )IgnoreFilterFNpatternsr:   c                 d    g | _         || _        || _        |D ]}|                     |           d S rI   )	_patterns_ignorecase_pathappend_pattern)rE   rf   r:   r8   r9   s        r%   rG   zIgnoreFilter.__init__   sH    (*%
 	) 	)G((((	) 	)r   r9   r   c                 `    | j                             t          || j                             dS )zAdd a pattern to the set.N)rh   appendr<   ri   )rE   r9   s     r%   rk   zIgnoreFilter.append_pattern   s+    ggt/?@@AAAAAr   r8   c              #      K   t          |t                    st          j        |          }| j        D ]}|                    |          r|V  dS )zYield all matching patterns for path.

        Args:
          path: Path to match
        Returns:
          Iterator over iterators
        N)rR   r`   rM   fsencoderh   r=   )rE   r8   r9   s      r%   find_matchingzIgnoreFilter.find_matching   sb       $&& 	%;t$$D~ 	 	G}}T"" 	 	r   c                 H    d}|                      |          D ]	}|j        }
|S )zCheck whether a path is ignored.

        For directories, include a trailing slash.

        Returns: status is None if file is not mentioned, True if it is
            included, False if it is explicitly excluded.
        N)rp   rA   )rE   r8   statusr9   s       r%   
is_ignoredzIgnoreFilter.is_ignored   s5     ))$// 	( 	(G'FFr   c                     t          |d          5 } | t          |          ||          cd d d            S # 1 swxY w Y   d S )Nrb)r8   )openr7   )clsr8   r:   r0   s       r%   	from_pathzIgnoreFilter.from_path   s    $ 	G3+A..
FFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs   9= =c                     t          | dd           }|(d                    t          |           j        |          S dt          |           j        z  S )Nrj   z{}.from_path({!r})z<%s>)getattrrV   rS   rW   r[   s     r%   rX   zIgnoreFilter.__repr__   sL    tWd++'..tDzz/BDIIIT$ZZ011r   )FNr\   )rW   r]   r^   r   r`   rZ   rG   rk   r
   ra   r<   rp   r	   rs   classmethodrx   rX   rc   r   r%   re   re      s       ) )% )d ) ) ) )Be B B B B B%s
"3 8I    u $     G G G. G G G [G2# 2 2 2 2 2 2r   re   c                   4    e Zd ZdZd Zdedee         fdZdS )IgnoreFilterStackz,Check for ignore status in multiple filters.c                     || _         d S rI   )_filters)rE   filterss     r%   rG   zIgnoreFilterStack.__init__   s    r   r8   r   c                 T    d}| j         D ]}|                    |          }||c S |S )Check whether a path is explicitly included or excluded in ignores.

        Args:
          path: Path to check
        Returns:
          None if the file is not mentioned, True if it is included,
          False if it is explicitly excluded.
        N)r   rs   )rE   r8   rr   filters       r%   rs   zIgnoreFilterStack.is_ignored  sF     m 	 	F&&t,,F! "r   N)	rW   r]   r^   r_   rG   ra   r	   rZ   rs   rc   r   r%   r}   r}      sO        66     s x~      r   r}   configc                     	 |                      dd          }t          |t                    sJ |                    d          S # t          $ r Y nw xY wt          dd          S )zReturn default user ignore filter path.

    Args:
      config: A Config object
    Returns:
      Path to a global ignore file
    )   cores   excludesFilezutf-8)encodinggitignore)getrR   r`   decodeKeyErrorr   )r   values     r%   default_user_ignore_filter_pathr     sv    

:77%'''''||W|---    $E8444s   AA 
AAc                       e Zd ZdZdedee         defdZdefdZ	dede
e         fd	Zdedee         fd
Zdede
e         fdZedd            ZdS )IgnoreFilterManagerzIgnore file manager.top_pathglobal_filtersr:   c                 >    i | _         || _        || _        || _        d S rI   )_path_filters	_top_path_global_filtersri   )rE   r   r   r:   s       r%   rG   zIgnoreFilterManager.__init__'  s+     AC!-%r   r   c                 t    d                     t          |           j        | j        | j        | j                  S )Nz{}({}, {!r}, {!r}))rV   rS   rW   r   r   ri   rJ   s    r%   rX   zIgnoreFilterManager.__repr__2  s7    #**JJN 	
 
 	
r   r8   c                 ,   	 | j         |         S # t          $ r Y nw xY wt          j                            | j        |d          }	 t                              || j                  | j         |<   n# t          $ r d | j         |<   Y nw xY w| j         |         S )Nz
.gitignore)
r   r   rM   r8   joinr   re   rx   ri   OSError)rE   r8   ps      r%   
_load_pathzIgnoreFilterManager._load_path:  s    	%d++ 	 	 	D	 GLL|<<	,'3'='=aAQ'R'RDt$$ 	, 	, 	,'+Dt$$$	,!$''s    
(A/ /BBc                    t           j                            |          rt          d|z            d | j        D             }t           j        j        dk    r%|                    t           j        j        d          }|                    d          }g }t          t          |          dz             D ]}d
                    |d|                   }|D ]_\  }}d
                    |||                   }	|t          |          k     r|	dz  }	|t          |                    |	                    z  }`|                     |          }
|
|                    d||
f           t          |          S )zFind matching patterns for path.

        Args:
          path: Path to check
        Returns:
          Iterator over Pattern instances
        z%s is an absolute pathc                     g | ]}d |fS )r   rc   ).0r0   s     r%   
<listcomp>z5IgnoreFilterManager.find_matching.<locals>.<listcomp>Q  s    888aAq6888r   /r   Nr   )rM   r8   isabs
ValueErrorr   sepr   r-   ranger   r   listrp   r   insertiter)rE   r8   r   partsmatchesr    dirnamesr0   relpathignore_filters              r%   rp   z!IgnoreFilterManager.find_matchingG  s[    7== 	>5<===884#78887;#<<S11D

3s5zzA~&& 	6 	6AhhuRaRy))G : :1((51:..s5zz>> sNG4 8 8999 OOG44M(q1m"4555G}}r   c                 h    t          |                     |                    }|r|d         j        S dS )r   r*   N)r   rp   rA   )rE   r8   r   s      r%   rs   zIgnoreFilterManager.is_ignoredd  s9     t))$//00 	*2;))tr   repor   c           	         g }t           j                            |                                dd          t	          |                                          fD ]x}t          t                    5  |                    t          
                    t           j                            |                               ddd           n# 1 swxY w Y   y|                                }|                    ddd          } | |j        ||          S )zCreate a IgnoreFilterManager from a repository.

        Args:
          repo: Repository object
        Returns:
          A `IgnoreFilterManager` object
        infoexcludeNr   s
   ignorecaseF)rM   r8   r   
controldirr   get_config_stackr   r   rm   re   rx   
expanduserget_boolean)rw   r   r   r   r   r:   s         r%   	from_repozIgnoreFilterManager.from_repor  s:    GLL**FI>>+D,A,A,C,CDD
 	U 	UA '"" U U%%l&<&<RW=O=OPQ=R=R&S&STTTU U U U U U U U U U U U U U U&&((''MEJJ
s49nj999s   -ACC	C	N)r   r   r   r   )rW   r]   r^   r_   ra   r   re   rZ   rG   rX   r	   r   r   r<   rp   rs   r{   r   rc   r   r%   r   r   $  s        	&	& \*	& 		& 	& 	& 	&
# 
 
 
 
(s (x'= ( ( ( (# (7*;    :s x~     : : : [: : :r   r   r\   )r_   os.pathrM   r   
contextlibr   typingr   r   r   r   r   r	   r
   r   r   r   r   r   r`   r&   r/   r7   rZ   r>   r<   re   r}   ra   r   r   rc   r   r%   <module>r      s<  ( 
  				                          4 4 4 4 4 4 4 4# #% # # # #L!5 !U ! ! ! !HH %    6
4 
4 
4 
44 
4D 
4 
4 
4 
4-* -* -* -* -* -* -* -*`12 12 12 12 12 12 12 12h       .5F 5s 5 5 5 5$`: `: `: `: `: `: `: `: `: `:r   