
    .Ph7                     >   d Z ddlZddlZddlZddlZddlmZmZ ddlm	Z	 ddl
mZ ddlmZmZmZmZmZ ddlmZ dd	lmZ dd
lmZmZmZmZmZmZmZ ddlmZm Z m!Z! dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ) G d de          Z*e	 G d d                      Z+e	 G d d                      Z, G d d          Z- G d de.          Z/de0de1e0e0f         fdZ2d  Z3d! Z4dfd"Z5d#e6de+fd$Z7d%e+d#e6ddfd&Z8 G d' d(e.          Z9d)edee+         fd*Z:de;e0ee,e-f         f         fd+Z<	 dgd)ed,e=e+         d#ee6         ddfd-Z>	 dgd)ed,e;e0ee,e-f         f         d#ee6         ddfd.Z?d/e6de6fd0Z@ G d1 d2          ZAd3ed4ee1e0e0e6f                  de0fd5ZBd3ed6eAde0fd7ZC	 dhd9ee0         d:ee0ge1e0e6f         f         d3ed;ee0         dee1e1ee0         ee0         f         e1ee6         ee6         f         e1ee0         ee0         f         f                  f
d<ZD	 dgd=e0d/ee6         fd>ZEejF        d?k    r G d@ dAeG          ZHdhddBdCZInejI        ZIdDdEddFdGed/e6dHe0fdIZJdJZKdKe0deLfdLZMdKe0deLfdMZNeMfde0deLfdNZOdDeMdfdOeePe0f         dPeePe0f         d3edQe0dReLddfdSZQdidTe0d/e6fdUZRdidTe0fdVZSdeePe0f         dee0         fdWZTdXe0deLfdYZU	 dgd6eAdOeePe0f         fdZZVejW        X                    d[          ZYdOe0dXe0fd\ZZdTeePe0f         de0fd]Z[de0dee,         fd^Z\	 dgde0d3ee         dee,         fd_Z]	 dgd`ee0         dOe0d3ee         dee1e0ee,         f                  fdaZ^	 djd`ee0         dOe0dee1e0ee0         ee6         f                  fdbZ_d6eAdOe0ddfdcZ` G dd de          ZadS )kz%Parser for the git index file format.    N)IterableIterator)	dataclass)Enum)AnyBinaryIOCallableOptionalUnion   )GitFile)iter_tree_contents)S_IFGITLINKS_ISGITLINKBlobObjectIDTree
hex_to_sha
sha_to_hex)ObjectContainer
SHA1Reader
SHA1Writeri 0     i  i   i @  i       c                       e Zd ZdZdZdZdZdS )Stager   r   r      N)__name__
__module____qualname__NORMALMERGE_CONFLICT_ANCESTORMERGE_CONFLICT_THISMERGE_CONFLICT_OTHER     M/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/dulwich/index.pyr   r   H   s'        Fr&   r   c                       e Zd ZU eed<   eeeeeef         f         ed<   eeeeeef         f         ed<   eed<   eed<   eed<   eed<   eed<   eed	<   eed
<   eed<   eed<   de	fdZ
dS )SerializedIndexEntrynamectimemtimedevinomodeuidgidsizeshaflagsextended_flagsreturnc                 J    t          | j        t          z  t          z	            S Nr   r4   FLAG_STAGEMASKFLAG_STAGESHIFTselfs    r'   stagezSerializedIndexEntry.stage^       dj>1oEFFFr&   N)r   r   r    bytes__annotations__r   intfloattupler   r>   r%   r&   r'   r)   r)   O   s         
KKKeU38_,----eU38_,----	HHH	HHH
III	HHH	HHH
III	JJJJJJGu G G G G G Gr&   r)   c                   8   e Zd ZU eeeeeef         f         ed<   eeeeeef         f         ed<   eed<   eed<   eed<   eed<   eed<   eed<   eed	<   d
Z	eed<   d
Z
eed<   ededd fd            ZdededefdZdefdZedefd            ZddeddfdZdS )
IndexEntryr+   r,   r-   r.   r/   r0   r1   r2   r3   r   r4   r5   
serializedr6   c                      | |j         |j        |j        |j        |j        |j        |j        |j        |j        |j	        |j
                  S )Nr+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   rI   )clsrG   s     r'   from_serializedzIndexEntry.from_serializedp   sV    s"""%4
 
 
 	
r&   r*   r>   c                     | j         t           z  }||j        t          z  z  }t	          || j        | j        | j        | j        | j	        | j
        | j        | j        | j        || j                  S )N)r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   )r4   r:   valuer;   r)   r+   r,   r-   r.   r/   r0   r1   r2   r3   r5   )r=   r*   r>   	new_flagss       r'   	serializezIndexEntry.serialize   sq    J.0	U[O33	#**.
 
 
 	
r&   c                 J    t          | j        t          z  t          z	            S r8   r9   r<   s    r'   r>   zIndexEntry.stage   r?   r&   c                 :    t          | j        t          z            S )z>Return True if the skip-worktree bit is set in extended_flags.)boolr5   EXTENDED_FLAG_SKIP_WORKTREEr<   s    r'   skip_worktreezIndexEntry.skip_worktree   s     D'*EEFFFr&   TskipNc                     |r,| xj         t          z  c_         | xj        t          z  c_        dS | xj         t           z  c_         | j         dk    r| xj        t           z  c_        dS dS )zHelper method to set or clear the skip-worktree bit in extended_flags.
        Also sets FLAG_EXTENDED in self.flags if needed.
        r   N)r5   rS   r4   FLAG_EXTENDED)r=   rU   s     r'   set_skip_worktreezIndexEntry.set_skip_worktree   s{      
	-#>>JJ-'JJJJ $?#??"a''

}n,



 ('r&   T)r   r   r    r   rB   rC   rD   rA   r@   r4   r5   classmethodr)   rK   r   rO   r>   propertyrR   rT   rX   r%   r&   r'   rF   rF   b   s|        eU38_,----eU38_,----	HHH	HHH
III	HHH	HHH
III	JJJE3NNNNC
)= 
, 
 
 
 [

e 
E 
6J 
 
 
 
&Gu G G G G Gt G G G XG- -d -d - - - - - -r&   rF   c            	           e Zd ZU dZee         ed<   ee         ed<   ee         ed<   	 	 	 ddee         dee         dee         ddfdZdS )	ConflictedIndexEntryz'Index entry that represents a conflict.ancestorthisotherNr6   c                 0    || _         || _        || _        d S r8   )r^   r_   r`   )r=   r^   r_   r`   s       r'   __init__zConflictedIndexEntry.__init__   s     !	


r&   )NNN)r   r   r    __doc__r
   rF   rA   rb   r%   r&   r'   r]   r]      s         11z""""
:
J *.%)&*	 :& z" 
#	
 
     r&   r]   c                       e Zd ZdZdS )UnmergedEntriesz$Unmerged entries exist in the index.N)r   r   r    rc   r%   r&   r'   re   re      s        ....r&   re   pathr6   c                 f    	 |                      dd          \  }}||fS # t          $ r d| fcY S w xY w)zSplit a /-delimited path into a directory part and a basename.

    Args:
      path: The path to split.

    Returns:
      Tuple with directory name and basename
       /r   r&   )rsplit
ValueError)rf   dirnamebasenames      r'   	pathsplitrm      sY    #"kk$22( ""    T{s    00c                  @    d                     d | D                       S )zJoin a /-delimited path.rh   c                     g | ]}||S r%   r%   ).0ps     r'   
<listcomp>zpathjoin.<locals>.<listcomp>   s    +++A+a+++r&   )join)argss    r'   pathjoinru      s#    99+++++,,,r&   c                 R    t          j        d|                     d                    S )zRead a cache time.

    Args:
      f: File-like object to read from
    Returns:
      Tuple with seconds and nanoseconds
    >LL   )structunpackread)fs    r'   read_cache_timer}      s      =q		***r&   c                 `   t          |t                    r|df}nnt          |t                    r5t          |d          \  }}t          |          t          |dz            f}n$t          |t                    st          |          |                     t          j        dg|R             dS )zWrite a cache time.

    Args:
      f: File-like object to write to
      t: Time to write (as int, float or tuple with secs and nsecs)
    r   g      ?i ʚ;rw   N)	
isinstancerB   rC   divmodrD   	TypeErrorwritery   pack)r|   tsecsnsecss       r'   write_cache_timer      s     !S F	Au		 q#uYYEJ.//05!! llGGFK""""#####r&   versionc                    |                                  }t          |           }t          |           }t          j        d|                     d                    \  }}}}}	}
}}|t
          z  r@|dk     rt          d          t          j        d|                     d                    \  }nd}|                     |t          z            }|dk     rJ|                                  |z
  d	z   d
z  }|                     ||z   |                                  z
             t          ||||||||	|
t          |          |t           z  |          S )zWRead an entry from a cache file.

    Args:
      f: File-like object to read from
    z>LLLLLL20sH.   r   z+extended flag set in index with version < 3z>Hr   r      rx   )
tellr}   ry   rz   r{   rW   AssertionErrorFLAG_NAMEMASKr)   r   )r|   r   beginoffsetr+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r*   	real_sizes                   r'   read_cache_entryr      sQ    &&((KAEAE 	mQVVN%;%;<<	} Q;; !NOOO"M$q		::66%-'((D{{VVXX+a/25		i'1668834443  r&   entryc                 F   |                                  }t          | |j                   t          | |j                   t	          |j                  |j        t           z  z  }|j        r
|t          z  }|t          z  r||dk     rt          d          |                     t          j        d|j        dz  |j        dz  |j        |j        |j        |j        t)          |j                  |	  	                   |t          z  r-|                     t          j        d|j                             |                     |j                   |dk     rO|                                  |z
  dz   d	z  }|                     d
||z   |                                  z
  z             dS dS )zrWrite an index entry to a file.

    Args:
      f: File object
      entry: IndexEntry to write, tuple with:
    Nr   z+unable to use extended flags in version < 3s   >LLLLLL20sHl    s   >Hr   rx   r       )r   r   r+   r,   lenr*   r4   r   r5   rW   r   r   ry   r   r-   r.   r/   r0   r1   r2   r   r3   )r|   r   r   r   r4   r   s         r'   write_cache_entryr   "  s    &&((KQ$$$Q$$$
OOu{m^;<E } L!41JKKKGGI
"I
"JIIJuy!!
	
 
	
   } :	E5#788999GGEJ{{VVXX+a/25		+	1QVVXX=>????? {r&   c                       e Zd ZdZddZdS )UnsupportedIndexFormatz,An unsupported index format was encountered.r6   Nc                     || _         d S r8   )index_format_version)r=   r   s     r'   rb   zUnsupportedIndexFormat.__init__I  s    $+!!!r&   r6   N)r   r   r    rc   rb   r%   r&   r'   r   r   F  s.        66, , , , , ,r&   r   r|   c              #   (  K   |                      d          }|dk    rt          d|          t          j        d|                      d                    \  }}|dvrt	          |          t          |          D ]}t          | |          V  dS )z4Read an index file, yielding the individual entries.r      DIRCzInvalid index file header:    >LLrx   )r   r   r   N)r{   r   ry   rz   r   ranger   )r|   headerr   num_entriesis        r'   
read_indexr   M  s      VVAYYFE6EEFFF#]6166%==AAWki$W---; + +q'******+ +r&   c                    i }t          |           D ]-}|                                }|t          j        k    r#t                              |          ||j        <   J|                    |j        t                                }t          |t                    rt          d|j        d          |t          j        k    r t                              |          |_        |t          j        k    r t                              |          |_        |t          j        k    rt                              |          |_        /|S )zRead an index file and return it as a dictionary.
       Dict Key is tuple of path and stage number, as
            path alone is not unique
    Args:
      f: File object to read fromls.
    zNon-conflicted entry for z exists)r   r>   r   r!   rF   rK   r*   
setdefaultr]   r   r   r"   r^   r#   r_   r$   r`   )r|   retr   r>   existings        r'   read_index_dictr   Y  s    ACCA C CEL  (88??C
OO~~ej2F2H2HIIH(J// X$%V%V%V%VWWW555$.$>$>u$E$E!!%333 * : :5 A A%444!+!;!;E!B!BJr&   entriesc           	      l   |t           }t          d |D                       }|r|dk     rd}|dk     r|D ]}|j        dk    rt          d          |                     d           |                     t          j        d|t          |                               |D ]}t          | ||           dS )	zWrite an index file.

    Args:
      f: File-like object to write to
      version: Version number to write
      entries: Iterable over the entries to write
    Nc              3   ,   K   | ]}|j         d k    V  dS )r   N)r5   )rp   es     r'   	<genexpr>zwrite_index.<locals>.<genexpr>  s*      EEa.!3EEEEEEr&   r   r   z+Attempt to use extended flags in index < v3r   r   r   )	DEFAULT_VERSIONanyr5   r   r   ry   r   r   r   )r|   r   r   uses_extended_flagsr   r   s         r'   write_indexr   r  s     !EEWEEEEE w{{{{ 	T 	TA1$$$%RSSS % GGGGGFKW66777 5 5!UG444445 5r&   c                 r   g }t          |          D ]}||         }t          |t                    r|j        8|                    |j                            |t          j                             |j        8|                    |j                            |t          j	                             |j
        8|                    |j
                            |t          j                             |                    |                    |t          j                             t          | ||           dS )ztWrite an index file based on the contents of a dictionary.
    being careful to sort by path and then by stage.
    Nr   )sortedr   r]   r^   appendrO   r   r"   r_   r#   r`   r$   r!   r   )r|   r   r   entries_listkeyrM   s         r'   write_index_dictr     s.    Lg D De122 	D~)##N,,S%2OPP   z%##J((e.GHH   {&##K))#u/IJJ   U\ B BCCCC<111111r&   r/   c                     t          j        |           rt           j        S t          j        |           rt           j        S t          |           rt          S t           j        dz  }| dz  r|dz  }|S )zCleanup a mode value.

    This will return a mode that can be stored in a tree object.

    Args:
      mode: Mode to clean up.

    Returns:
      mode
    i  @   I   )statS_ISLNKS_IFLNKS_ISDIRS_IFDIRr   r   S_IFREG)r/   r   s     r'   cleanup_moder     st     |D |	d		 |	T		 
,
Ce| uJr&   c                   4   e Zd ZU dZeeeeef         f         e	d<   d%deee
f         ddfdZed             Zde
fd	Zd&d
Zd&dZdefdZdedeeef         fdZdee         fdZdefdZdedefdZdedefdZdeeeeef                  fdZdefdZd&dZdedeeef         ddfdZdeddfdZ deeeeeef         f                  fdZ!deeeeeef         f                  fdZ"deeeeef         f         ddfdZ#d Z$	 d'd!e%d"efd#Z&d$ Z'dS )(IndexzA Git Index file._bynameTfilenamer6   Nc                 z    || _         d| _        |                                  |r|                                  dS dS )zCreate an index object associated with the given filename.

        Args:
          filename: Path to the index file
          read: Whether to initialize the index from the given file, should it exist.
        N)	_filename_versionclearr{   )r=   r   r{   s      r'   rb   zIndex.__init__  sB     "

 	IIKKKKK	 	r&   c                     | j         S r8   )r   r<   s    r'   rf   z
Index.path  s
    ~r&   c                 0    | j         j         d| j        dS )N())	__class__r   r   r<   s    r'   __repr__zIndex.__repr__  s     .)??DN????r&   c                     t          | j        d          }	 t          |          }t          || j        | j                   |                                 dS # |                                 w xY w)z(Write current contents of index to disk.wbr   N)r   r   r   r   r   r   closer=   r|   s     r'   r   zIndex.write  s_    DND))	1AQdmDDDDGGIIIIIAGGIIIIs   +A A.c                    t           j                            | j                  sdS t	          | j        d          }	 t          |          }|                     t          |                     |                    t           j        	                    | j                  |
                                z
  dz
             |                    d           |                                 dS # |                                 w xY w)z)Read current contents of index from disk.Nrb   T)allow_empty)osrf   existsr   r   r   updater   r{   getsizer   	check_shar   r   s     r'   r{   z
Index.read  s    w~~dn-- 	FDND))	1AKK**+++FF27??4>22QVVXX=BCCCKKDK)))GGIIIIIAGGIIIIs   BC) )C?c                 *    t          | j                  S )z%Number of entries in this index file.)r   r   r<   s    r'   __len__zIndex.__len__  s    4<   r&   r   c                     | j         |         S )zRetrieve entry by relative path and stage.

        Returns: Either a IndexEntry or a ConflictedIndexEntry
        Raises KeyError: if the entry does not exist
        r   r=   r   s     r'   __getitem__zIndex.__getitem__  s     |C  r&   c                 *    t          | j                  S )z0Iterate over the paths and stages in this index.)iterr   r<   s    r'   __iter__zIndex.__iter__  s    DL!!!r&   c                     || j         v S r8   r   r   s     r'   __contains__zIndex.__contains__  s    dl""r&   rf   c                 X    | |         }t          |t                    rt          |j        S )z6Return the (git object) SHA1 for the object at a path.)r   r]   re   r3   r=   rf   rM   s      r'   get_sha1zIndex.get_sha1  s,    T
e122 	"!!yr&   c                 X    | |         }t          |t                    rt          |j        S )z4Return the POSIX file mode for the object at a path.)r   r]   re   r/   r   s      r'   get_modezIndex.get_mode  s,    T
e122 	"!!zr&   c              #      K   | D ]D}| |         }t          |t                    rt          ||j        t	          |j                  fV  EdS )z=Iterate over path, sha, mode tuples for use with commit_tree.N)r   r]   re   r3   r   r/   )r=   rf   r   s      r'   iterobjectszIndex.iterobjects  sc       	< 	<DJE%!566 &%%	<
#;#;;;;;;		< 	<r&   c                 n    | j                                         D ]}t          |t                    r dS dS )NTF)r   valuesr   r]   )r=   rM   s     r'   has_conflictszIndex.has_conflicts  sC    \((** 	 	E%!566 ttur&   c                     i | _         dS )z$Remove all contents from this index.Nr   r<   s    r'   r   zIndex.clear$  s    r&   r*   rM   c                 H    t          |t                    sJ || j        |<   d S r8   )r   r@   r   )r=   r*   rM   s      r'   __setitem__zIndex.__setitem__(  s,     $&&&&&"Tr&   c                     | j         |= d S r8   r   )r=   r*   s     r'   __delitem__zIndex.__delitem__.  s    Lr&   c                 N    t          | j                                                  S r8   r   r   itemsr<   s    r'   	iteritemszIndex.iteritems1  s      DL&&(()))r&   c                 N    t          | j                                                  S r8   r   r<   s    r'   r   zIndex.items6  s    DL&&(()))r&   r   c                 D    |                                 D ]
\  }}|| |<   d S r8   )r   )r=   r   r   rM   s       r'   r   zIndex.update9  s4     "--// 	 	JCDII	 	r&   c              #   H   K   | j                                         E d {V  d S r8   )r   keysr<   s    r'   pathszIndex.paths?  s2      <$$&&&&&&&&&&&r&   Ftreewant_unchangedc              #   n    K    fd}t                                           ||||          E d{V  dS )a  Find the differences between the contents of this index and a tree.

        Args:
          object_store: Object store to use for retrieving tree contents
          tree: SHA1 of the root tree
          want_unchanged: Whether unchanged files should be reported
        Returns: Iterator over tuples with (oldpath, newpath), (oldmode,
            newmode), (oldsha, newsha)
        c                 J    |          }|j         t          |j                  fS r8   )r3   r   r/   )rf   r   r=   s     r'   lookup_entryz-Index.changes_from_tree.<locals>.lookup_entryO  s#    JE9l5:6666r&   )r  N)changes_from_treer  )r=   object_storer  r  r  s   `    r'   r  zIndex.changes_from_treeB  sx      	7 	7 	7 	7 	7 %JJLL)
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r&   c                 F    t          ||                                           S )zCreate a new tree from an index.

        Args:
          object_store: Object store to save the tree in
        Returns:
          Root tree SHA
        commit_treer   )r=   r  s     r'   commitzIndex.commit[  s      <)9)9););<<<r&   rY   r   F)(r   r   r    rc   dictr@   r   rF   r]   rA   strrb   r[   rf   r   r   r{   rB   r   r   r   r   rR   r   r   r   r   rD   r   r   r   r   r   r   r   r   r  r   r  r  r%   r&   r'   r   r     s<        %z+??@@AAAA ucz!2 $       X@# @ @ @ @      ! ! ! ! !!u !z;O/O)P ! ! ! !"(5/ " " " "#4 # # # #U u    U s    <XeE5#,=&>? < < < <t       ##"'
4H(H"I#	# # # # $    *	%uZ1E%EFFG	H* * * *
*xeU:?S3S-T&T UV * * * *E55I)I#JJK	   ' ' ' DI
 
"*
<@
 
 
 
2= = = = =r&   r   r  blobsc                     	
 di i

fd|D ]*\  }}}t          |          \  }} |          }||f||<   +	 
fd	 	d          S )zCommit a new tree.

    Args:
      object_store: Object store to add trees to
      blobs: Iterable over blob path, sha, mode entries
    Returns:
      SHA1 of the created tree.
    r&   c                     | v r|          S t          |           \  }} |          }t          |t                    sJ i }|||<   || <   |S r8   )rm   r   r@   )rf   rk   rl   r   newtreeadd_treetreess        r'   r  zcommit_tree.<locals>.add_trees  sg    5==;%dOOHW(E*****(dr&   c                 F   t                      }|                                          D ]\\  }}t          |t                    r&t          j        } t          | |                    }n|\  }}|                    |||           ]                    |           |j	        S r8   )
r   r   r   r  r   r   ru   add
add_objectid)	rf   r  rl   r   r/   r3   
build_treer  r  s	         r'   r  zcommit_tree.<locals>.build_tree  s    vv$T{0022 	* 	*OHe%&& $| j$!9!9::#sHHXtS))))%%%wr&   )rm   )r  r  rf   r3   r/   	tree_pathrl   r  r  r  r  s   `       @@@r'   r  r  f  s      #BiE	 	 	 	 	 	 ! % %c4'oo	8x	""X
 
 
 
 
 
 
 :c??r&   indexc                 F    t          | |                                          S )zCreate a new tree from an index.

    Args:
      object_store: Object store to save the tree in
      index: Index file
    Note: This function is deprecated, use index.commit() instead.
    Returns: Root tree sha.
    r
  )r  r  s     r'   commit_indexr    s      |U%6%6%8%8999r&   Fnamesr  r  c              #   t  K   t          |           }|st          ||          D ]b\  }}}	  ||          \  }	}
|                    |           |s|	|k    s|
|k    r||f||
f||	ffV  F# t          $ r |df|df|dffV  Y _w xY w|D ].}	  ||          \  }	}
d|fd|
fd|	ffV  # t          $ r Y +w xY wdS )a  Find the differences between the contents of a tree and
    a working copy.

    Args:
      names: Iterable of names in the working copy
      lookup_entry: Function to lookup an entry in the working copy
      object_store: Object store to use for retrieving tree contents
      tree: SHA1 of the root tree, or None for an empty tree
      want_unchanged: Whether unchanged files should be reported
    Returns: Iterator over tuples with (oldpath, newpath), (oldmode, newmode),
        (oldsha, newsha)
    N)setr   removeKeyError)r  r  r  r  r  other_namesr*   r/   r3   	other_sha
other_modes              r'   r  r    sp     4 e**K1,EE 		O 		OOD$O*6,t*<*<'J
 ""4(((! OY#%5%5t9K9K $<$
);c9=MNNNN  @ @ @d|dD\C;??????@  H H	H&2l4&8&8#Y
 $<$
!3dI5FGGGGG  	 	 	D	H Hs#   A**BBB((
B54B5hex_shac                     |t          | j                  }t          | j        | j        | j        | j        || j        | j        | j	        |dd          S )zCreate a new index entry from a stat value.

    Args:
      stat_val: POSIX stat_result instance
      hex_sha: Hex sha of the object
    Nr   rI   )
r   st_moderF   st_ctimest_mtimest_devst_inost_uidst_gidst_size)stat_valr'  r/   s      r'   index_entry_from_statr2    sb     |H,--OOOO   r&   win32c                         e Zd Zd fdZ xZS )WindowsSymlinkPermissionErrorr6   Nc                 b    t          t          |                               |d| |           d S )Nz>Unable to create symlink; do you have developer mode enabled? )superPermissionErrorrb   )r=   errnomsgr   r   s       r'   rb   z&WindowsSymlinkPermissionError.__init__  sA    /4((11VQTVV    r&   r   )r   r   r    rb   __classcell__)r   s   @r'   r5  r5    s=        	 	 	 	 	 	 	 	 	 	r&   r5  )dir_fdc                    	 t          j        | |||          S # t          $ r&}t          |j        |j        |j                  |d }~ww xY w)N)target_is_directoryr<  )r   symlinkr8  r5  r9  strerrorr   )srcdstr>  r<  r   s        r'   r?  r?    sk    	X:S.A&     	X 	X 	X/QZPPVWW	Xs    
A
!AA
Tutf-8)honor_filemodetree_encoding
symlink_fnblobtarget_pathc                   	 t          j        |          }n# t          $ r d}Y nw xY w|                                 }t	          j        |          rd|rt          j        |           t          j        dk    r*|	                    |          }|	                    |          } |pt          ||           n|g|j        t          |          k    rOt          |d          5 }|                                |k    r|cddd           S 	 ddd           n# 1 swxY w Y   t          |d          5 }|                    |           ddd           n# 1 swxY w Y   |rt          j        ||           t          j        |          S )a  Build a file or symlink on disk based on a Git object.

    Args:
      blob: The git object
      mode: File mode
      target_path: Path to write to
      honor_filemode: An optional flag to honor core.filemode setting in
        config file, default is core.filemode=True, change executable bit
      symlink: Function to use for creating symlinks
    Returns: stat object for the file
    Nr3  r   r   )r   lstatFileNotFoundErroras_raw_stringr   r   unlinksysplatformdecoder?  r0  r   openr{   r   chmod)	rG  r/   rH  rD  rE  rF  oldstatcontentsr|   s	            r'   build_file_from_blobrU    s   ((;''   !!##H|D ( 	#Ik"""<7""}55H%,,];;K		w+66667?c(mm#C#Ck4(( #A6688x''"# # # # # # # #'# # # # # # # # # # # # # # # +t$$ 	GGH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  	(H[$'''8K   s0    &&DDD.EEE)   .git   .s   ..r&   elementc                 8    |                                  t          vS r8   )lowerINVALID_DOTNAMES)rX  s    r'   validate_path_element_defaultr\  ;  s    ==??"222r&   c                 z    |                      d                                          }|t          v rdS |dk    rdS dS )Ns   . Fs   git~1T)rstriprZ  r[  )rX  strippeds     r'   validate_path_element_ntfsr`  ?  sE    ~~e$$**,,H###u8u4r&   c                 V    |                      d          }|D ]} ||          s dS dS )z2Default path validator that just checks for .git/.rh   FT)split)rf   element_validatorpartsrq   s       r'   validate_pathre  H  sH    JJtE    ## 	55	 tr&   	root_path
index_pathtree_idrD  c                 :   t          |d          }t          | t                    st          j        |           } t          ||          D ]}t          |j        |          st          | |j                  }	t          j        	                    t          j        
                    |	                    s1t          j        t          j        
                    |	                     t          |j                  rHt          j                            |	          st          j        |	           t          j        |	          }
n=||j                 }t          |t$                    sJ t'          ||j        |	||          }
|rt          |j                  rS|j        |
j        |
j        |
j        |
j        |
j        |
j        |
j        |
j        |
j        f
}|
                    |          }
t=          |
|j                  ||j        <   |                                 dS )a  Generate and materialize index from a tree.

    Args:
      tree_id: Tree to materialize
      root_path: Target dir for materialized index files
      index_path: Target path for generated index
      object_store: Non-empty object store holding tree contents
      honor_filemode: An optional flag to honor core.filemode setting in
        config file, default is core.filemode=True, change executable bit
      validate_path_element: Function to validate path elements to check
        out; default just refuses .git and .. directories.

    Note: existing index is wiped and contents are not merged
        in a working dir. Suitable only for fresh clones.
    F)r{   )rD  rF  N) r   r   r@   r   fsencoder   re  rf   _tree_to_fs_pathr   rk   makedirsr   r/   isdirmkdirrJ  r3   r   rU  r-  r,  st_nlinkr.  r/  r0  st_atimer+  r*  r   r2  r   )rf  rg  r  rh  rD  validate_path_elementrF  r  r   	full_pathstobjst_tuples                r'   build_index_from_treerv  R  s   0 *5)))Ei'' +K	**	#L':: -A -AUZ)>?? 	$Y
;;	w~~bgooi8899 	4K	22333 uz"" 	7==++ $###)$$BB uy)Cc4(((((%
-%  B  	(UZ!8!8 	(
 
				
H h''B 2"ei@@ej	KKMMMMMr&   fs_pathc                    t          | t                    sJ t                      }t          j        |          rit
          j        dk    r?t          j        t          j	        |                     
                    |          |_        n[t          j        |           |_        nAt          | d          5 }|                                |_        ddd           n# 1 swxY w Y   |S )zCreate a blob from a path and a stat object.

    Args:
      fs_path: Full file system path to file
      mode: File mode
    Returns: A `Blob` object
    r3  r   N)r   r@   r   r   r   rN  rO  r   readlinkfsdecodeencodedatarQ  r{   )rw  r/   rE  rG  r|   s        r'   blob_from_path_and_moder}    s     gu%%%%%66D|D !<7""BK$8$899@@OODIIG,,DII'4   	!ADI	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!Ks   3CC Cc                 .    t          | |j        |          S )zCreate a blob from a path and a stat object.

    Args:
      fs_path: Full file system path to file
      st: A stat object
    Returns: A `Blob` object
    )r}  r)  )rw  rs  rE  s      r'   blob_from_path_and_statr    s     #7BJFFFr&   c                     ddl m} ddlm} t	          | t
                    st          j        |           } 	  ||           }n# |$ r Y dS w xY w	 |                                S # t          $ r Y dS w xY w)zRead the head commit of a submodule.

    Args:
      path: path to the submodule
    Returns: HEAD sha, None if not a valid head/repository
    r   )NotGitRepository)RepoN)
errorsr  repor  r   r  r   rz  headr#  )rf   r  r  r  s       r'   read_submodule_headr    s     )((((( dC   !{4  tDzz   ttyy{{   tts#   A AAA$ $
A21A2r  c                     t           j                            t           j                            | d                    rt	          |           }|j        |k    rdS ndS dS )a  Check if a directory has changed after getting an error.

    When handling an error trying to create a blob from a path, call this
    function. It will check if the path is a directory. If it's a directory
    and a submodule, check the submodule head to see if it's has changed. If
    not, consider the file as changed as Git tracked a file and not a
    directory.

    Return true if the given path should be considered as changed and False
    otherwise or if the path is not a directory.
    rV  TF)r   rf   r   rs   r  r3   )r  r   r  s      r'   _has_directory_changedr    sZ     
w~~bgll9g6677 "9--94  t5r&   c              #   \  K   t          |t                    st          j        |          }|                                 D ]\  }}t          ||          }t          |t                    r|V  /	 t          j        |          }t          j	        |j
                  rt          ||          r|V  rt          j        |j
                  st          j        |j
                  st          ||          }| |||          }|j        |j        k    r|V  # t"          $ r |V  Y w xY wdS )zWalk through an index and check for differences against working tree.

    Args:
      index: index to check
      root_path: path in which to find files
    Returns: iterator over paths with unstaged changes
    N)r   r@   r   rj  r   rk  r]   rJ  r   r   r)  r  S_ISREGr   r  r  r3   rK  )r  rf  filter_blob_callbackr  r   rr  rs  rG  s           r'   get_unstaged_changesr    s]      i'' +K	**	!OO--    	5$Y	::	e122 	OOO	 )$$B|BJ'' ))U;; $#OOO<
++ DL4L4L *9b99D#/++D)<< w%)## ! 	 	 	 OOOOO	+   s   0AD22D%DD)(D)asciic                     t          |t                    sJ t          dk    r|                    dt                    }n|}t          j                            | |          S )zConvert a git tree path to a file system path.

    Args:
      root_path: Root filesystem path
      tree_path: Git tree path as bytes

    Returns: File system path.
    rh   )r   r@   os_sep_bytesreplacer   rf   rs   )rf  r  sep_corrected_paths      r'   rk  rk  !  s[     i'''''t&..t\BB&7<<	#5666r&   c                     t          | t                    st          j        |           }n| }t          dk    r|                    t          d          }n|}|S )zConvert a file system path to a git tree path.

    Args:
      fs_path: File system path.

    Returns:  Git tree path as bytes
    rh   )r   r@   r   rj  r  r  )rw  fs_path_bytesr  s      r'   _fs_to_tree_pathr  2  sY     gu%%  G,,t!)),==		!	r&   c                     t           j                            t           j                            |d                    r*t	          |          }|d S t          | |t                    S d S )NrV  )r/   )r   rf   r   rs   r  r2  r   )rs  rf   r  s      r'   index_entry_from_directoryr  E  sZ    	w~~bgll41122 A"4((<4$RK@@@@4r&   c                    t          | t                    sJ t          j        |           }t	          j        |j                  rt          ||           S t	          j        |j                  st	          j	        |j                  r<t          | |          }||                    |           t          ||j                  S dS )ag  Create an index from a filesystem path.

    This returns an index value for files, symlinks
    and tree references. for directories and
    non-existent files it returns None

    Args:
      path: Path to create an index entry for
      object_store: Optional object store to
        save new blobs in
    Returns: An index entry; None for directories
    N)r   r@   r   rJ  r   r   r)  r  r  r   r  r  r2  r  )rf   r  rs  rG  s       r'   index_entry_from_pathr  N  s     dE"""""	$B|BJ 4)"d333|BJ 24<
#;#; 2&tR00###D)))$R1114r&   r  c              #      K   | D ]D}t          ||          }	 t          ||          }n# t          t          f$ r d}Y nw xY w||fV  EdS )zIterate over current versions of index entries on disk.

    Args:
      paths: Paths to iterate over
      root_path: Root path to access from
      object_store: Optional store to save new blobs in
    Returns: Iterator over path, index_entry
    r  N)rk  r  rK  IsADirectoryError)r  rf  r  rf   rq   r   s         r'   iter_fresh_entriesr  k  s         Y--	)!,GGGEE!#45 	 	 	EEE	Ek s   *A A c              #      K   t          | ||          D ]/\  }}|
|r|ddfV  ||j        t          |j                  fV  0dS )a8  Iterate over versions of objects on disk referenced by index.

    Args:
      root_path: Root path to access from
      include_deleted: Include deleted entries with sha and
        mode set to None
      object_store: Optional object store to report new items to
    Returns: Iterator over path, sha, mode
    r  N)r  r3   r   r/   )r  rf  include_deletedr  rf   r   s         r'   iter_fresh_objectsr    sw       *%VVV < <e= 'D$&&&&	<
#;#;;;;;;< <r&   c                 @    t          | |          D ]\  }}|r|| |<   dS )zRefresh the contents of an index.

    This is the equivalent to running 'git commit -a'.

    Args:
      index: Index to update
      root_path: Root filesystem path
    N)r  )r  rf  rf   r   s       r'   refresh_indexr    s=     *%;;    e 	 E$K   r&   c                   >    e Zd ZdZdeeef         ddfdZd Zd Z	dS )locked_indexzPLock the index while making modifications.

    Works as a context manager.
    rf   r6   Nc                     || _         d S r8   )_path)r=   rf   s     r'   rb   zlocked_index.__init__  s    


r&   c                 v    t          | j        d          | _        t          | j                  | _        | j        S )Nr   )r   r  _filer   _indexr<   s    r'   	__enter__zlocked_index.__enter__  s.    TZ..
DJ''{r&   c                    || j                                          d S 	 t          | j                   }t          || j        j                   |                                 d S # t          $ r | j                                          Y d S w xY wr8   )r  abortr   r   r  r   r   BaseException)r=   exc_type	exc_value	tracebackr|   s        r'   __exit__zlocked_index.__exit__  s    JF	4:&&AQ 3444 GGIIIII  	 	 	J	s   .A# ##B
	B
)
r   r   r    rc   r   r@   r  rb   r  r  r%   r&   r'   r  r    sg         
U5#:. 4      

 
 
 
 
r&   r  r   r8   r  )rC  )FN)brc   r   r   ry   rN  collections.abcr   r   dataclassesr   enumr   typingr   r   r	   r
   r   filer   r  r   objectsr   r   r   r   r   r   r   r   r   r   r   r:   r;   r   
FLAG_VALIDrW   rS   EXTENDED_FLAG_INTEND_TO_ADDr   r   r)   rF   r]   	Exceptionre   r@   rD   rm   ru   r}   r   rB   r   r   r   r   r  r   listr   r   r   r   r  r  r  r2  rO  r8  r5  r?  rU  r[  rR   r\  r`  re  r  rv  r}  r  r  r  r  sepr{  r  rk  r  r  r  r  r  r  r  r%   r&   r'   <module>r     sb
  , , + 				   



 . . . . . . . . ! ! ! ! ! !                          , , , , , ,                  : 9 9 9 9 9 9 9 9 9  
  %  %     D    G G G G G G G G$ F- F- F- F- F- F- F- F-R       $/ / / / /i / / /#E #eE5L1 # # # #"- - -
+ + +$ $ $ $"+ +)= + + + +\!@ 4 !@s !@t !@ !@ !@ !@H, , , , ,Y , , ,	+( 	+x(<= 	+ 	+ 	+ 	+$ueJ8L,L&MMN    4 PT5 55345?G}5	5 5 5 5B "2 22%z+??@@A2 c]2 
	2 2 2 2:s s    ._= _= _= _= _= _= _= _=D)!)*25s9J3K*L)
) ) ) )X	: 	:u 	: 	: 	: 	: 	:" /H /HE?/HE7E%*$556/H "/H 5/	/H 	huox./hsmXc]*+huox./	1/H /H /H /Hj   3-   : <7       Xt X X X X X X jG .! .! .!
.!
.! .! .! .! .!b / 35 3T 3 3 3 3 $     2O   SW      7K KS%Z Kc5j!K "K 	K
 K 
K K K K\ U #    ,G GU G G G GeCJ/ HUO    0e t    4 FJ)  ) ) "3:.)  )  )  ) X v}}W%%7 7% 7 7 7 7"eCJ/ E    & 8J3G     <@ 
'8j   @ /3 E? ?+ eE8J//01	   . SW< <E?<',<eE8E?HSM9:;< < < <(   5  T                 r&   