
    dv                        d Z ddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZ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   ej!        d	g d
          Z"dZ#dZ$dZ%dZ&dZ'dZ(de)dee)e)f         fdZ*d Z+d Z,d Z-de.dee/e"f         fdZ0de)de"de.ddfdZ1 G d de2          Z3defdZ4de
e)e"f         fdZ5d\ded eee)e"f                  dee.         fd!Z6	 d\ded e
e)e"f         dee.         ddfd"Z7d#e.de.fd$Z8 G d% d&          Z9d'ed(eee)e)e.f                  de)fd)Z:d'ed*e9de)fd+Z;	 d]d-ee)         d.e	e)gee)e.f         f         d'ed/ee)         deeeee)         ee)         f         eee.         ee.         f         eee)         ee)         f         f                  f
d0Z<	 	 d^d1e)d2e.d#ee.         d3ee.         fd4Z=ej>        d5k    r G d6 d7e?          Z@d]dd8d9ZAnejA        ZAd:d;dd<d=ed#e.d>e)fd?ZBd@ZCdAe)deDfdBZEdAe)deDfdCZFeEfde)deDfdDZGd:eEdfdEee/e)f         dFee/e)f         d'edGe)dHeDf
dIZH	 d_dJe)d#e.fdKZId_dJe)fdLZJdee/e)f         dee)         fdMZKdNe)fdOZL	 d\d*e9dEee/e)f         fdPZMejN        O                    dQ          ZPdEe)dNe)fdRZQdJee/e)f         de)fdSZRde)dee"         fdTZS	 d\de)d'ee         dee"         fdUZT	 d\dVee)         dEe)d'ee         deee)ee"         f                  fdWZU	 	 d`dVee)         dEe)deee)ee)         ee.         f                  fdXZVd*e9dEe)fdYZW G dZ d[          ZXdS )az%Parser for the git index file format.    N)
AnyBinaryIOCallableDictIterableIteratorListOptionalTupleUnion   )GitFile)iter_tree_contents)S_IFGITLINKS_ISGITLINKBlobObjectIDTree
hex_to_sha
sha_to_hex)ObjectContainer
SHA1Reader
SHA1Writer
IndexEntry)ctimemtimedevinomodeuidgidsizeshaflagsextended_flagsi 0  i   i @  i       pathreturnc                 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       )rsplit
ValueError)r'   dirnamebasenames      Q/home/feoh/.local/pipx/venvs/poetry/lib/python3.11/site-packages/dulwich/index.py	pathsplitr1   L   sY    #"kk$22( ""    T{s    00c                  @    d                     d | D                       S )zJoin a /-delimited path.r*   c                     g | ]}||S  r4   ).0ps     r0   
<listcomp>zpathjoin.<locals>.<listcomp>^   s    +++A+a+++r+   )join)argss    r0   pathjoinr:   \   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    r0   read_cache_timerB   a   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 ʚ;r<   N)	
isinstanceintfloatdivmodtuple	TypeErrorwriter>   pack)rA   tsecsnsecss       r0   write_cache_timerO   l   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}|                     |dz            }|d	k     rJ|                                  |z
  d
z   dz  }|                     ||z   |                                  z
             |t          |||||||	|
t          |          |dz  |          fS )zRead an entry from a cache file.

    Args:
      f: File-like object to read from
    Returns:
      tuple with: name, IndexEntry
    z>LLLLLL20sH.      z+extended flag set in index with version < 3z>Hr&   r   i     r=    )	tellrB   r>   r?   r@   FLAG_EXTENDEDAssertionErrorr   r   )rA   rP   beginoffsetr   r   r   r   r   r    r!   r"   r#   r$   r%   name	real_sizes                   r0   read_cache_entryr]   }   sX    &&((KAEAE 	mQVVN%;%;<<	} Q;; =? ? ?#]4;;66%&.!!D{{VVXX+a/25		i'166883444sOOGO	
 	
 r+   r[   entryc                 &   |                                  }t          | |j                   t          | |j                   t	          |          |j        d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                             | 	                    |           |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:
    rV   NrS   z+unable to use extended flags in version < 3s   >LLLLLL20sHl    s   >HrT   r=   rU       )rW   rO   r   r   lenr$   r%   rX   rY   rJ   r>   rK   r   r   r   r    r!   r"   r   r#   )rA   r[   r^   rP   rZ   r$   r\   s          r0   write_cache_entryrb      s    &&((KQ$$$Q$$$IIw./E } L!41JKKKGGI
"I
"JIIJuy!!
	
 
	
   } :	E5#788999GGDMMM{{VVXX+a/25		+	1QVVXX=>????? {r+   c                       e Zd ZdZd ZdS )UnsupportedIndexFormatz,An unsupported index format was encountered.c                     || _         d S N)index_format_version)selfrP   s     r0   __init__zUnsupportedIndexFormat.__init__   s    $+!!!r+   N)__name__
__module____qualname____doc__ri   r4   r+   r0   rd   rd      s)        66, , , , ,r+   rd   rA   c              #   (  K   |                      d          }|dk    rt          d|z            t          j        d|                      d                    \  }}|dvrt	          |          t          |          D ]}t          | |          V  dS )z4Read an index file, yielding the individual entries.rT      DIRCzInvalid index file header: %r   >LLr=   )r   r&   rS   N)r@   rY   r>   r?   rd   ranger]   )rA   headerrP   num_entriesis        r0   
read_indexru      s      VVAYYF<vEFFF#]6166%==AAWki$W---; + +q'******+ +r+   c                 >    i }t          |           D ]
\  }}|||<   |S )zcRead an index file and return it as a dictionary.

    Args:
      f: File object to read from
    )ru   )rA   retr[   r^   s       r0   read_index_dictrx      s2     C!!}}  eD		Jr+   entriesc           	          |t           }|                     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
    Nro   rp   )DEFAULT_VERSIONrJ   r>   rK   ra   rb   )rA   ry   rP   r[   r^   s        r0   write_indexr|      sz     !GGGGGFKW66777 3 3e!T5'22223 3r+   c                     g }t          |          D ]}|                    |||         f            t          | ||           dS )z:Write an index file based on the contents of a dictionary.rP   N)sortedappendr|   )rA   ry   rP   entries_listr[   s        r0   write_index_dictr     sY     Lw 3 3T74=12222<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   rw   s     r0   cleanup_moder     st     |D |	d		 |	T		 
,
Ce| uJr+   c                      e Zd ZdZd deeef         fdZed             Z	d Z
d!d	Zd
 ZdefdZdedefdZde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 ZdedefdZdefdZdeeeef                  fdZdeeeef                  fdZdeeef         fdZ	 d"dede fdZ!d Z"dS )#IndexzA Git Index file.Tfilenamec                 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@   )rh   r   r@   s      r0   ri   zIndex.__init__'  sB     "

 	IIKKKKK	 	r+   c                     | j         S rf   )r   rh   s    r0   r'   z
Index.path5  s
    ~r+   c                 L    d                     | j        j        | j                  S )Nz{}({!r}))format	__class__rj   r   r   s    r0   __repr__zIndex.__repr__9  s      !8$.IIIr+   r(   Nc                     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   _bynamer   close)rh   rA   s     r0   rJ   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          |          D ]
\  }}|| |<   |                    t           j                            | j                  |	                                z
  dz
             |
                                 |                                 dS # |                                 w xY w)z)Read current contents of index from disk.Nrb   )osr'   existsr   r   r   ru   r@   getsizerW   	check_shar   )rh   rA   r[   r^   s       r0   r@   z
Index.readE  s    w~~dn-- 	FDND))	1A)!}} # #e"T

FF27??4>22QVVXX=BCCCKKMMMGGIIIIIAGGIIIIs   BC C5c                 *    t          | j                  S )z%Number of entries in this index file.)ra   r   r   s    r0   __len__zIndex.__len__T  s    4<   r+   r[   c                     | j         |         S )zRetrieve entry by relative path.

        Returns: tuple with (ctime, mtime, dev, ino, mode, uid, gid, size, sha,
            flags)
        r   rh   r[   s     r0   __getitem__zIndex.__getitem__X  s     |D!!r+   c                 *    t          | j                  S )z%Iterate over the paths in this index.)iterr   r   s    r0   __iter__zIndex.__iter__`  s    DL!!!r+   r'   c                     | |         j         S )z6Return the (git object) SHA1 for the object at a path.)r#   rh   r'   s     r0   get_sha1zIndex.get_sha1d  s    Dz~r+   c                     | |         j         S )z4Return the POSIX file mode for the object at a path.r   r   s     r0   get_modezIndex.get_modeh  s    Dzr+   c              #   `   K   | D ](}| |         }||j         t          |j                  fV  )dS )z=Iterate over path, sha, mode tuples for use with commit_tree.Nr#   r   r   )rh   r'   r^   s      r0   iterobjectszIndex.iterobjectsl  sJ       	< 	<DJE	<
#;#;;;;;;	< 	<r+   c                     i | _         dS )z$Remove all contents from this index.Nr   r   s    r0   r   zIndex.clearr  s    r+   xc                     t          |t                    sJ t          |          t          t          j                  k    sJ t          | | j        |<   d S rf   )rD   bytesra   r   _fieldsr   )rh   r[   r   s      r0   __setitem__zIndex.__setitem__v  sP    $&&&&&1vvZ/000000'^Tr+   c                 D    t          |t                    sJ | j        |= d S rf   )rD   r   r   r   s     r0   __delitem__zIndex.__delitem__|  s(    $&&&&&Lr+   c                 4    | j                                         S rf   r   itemsr   s    r0   	iteritemszIndex.iteritems      |!!###r+   c                 4    | j                                         S rf   r   r   s    r0   r   zIndex.items  r   r+   ry   c                 D    |                                 D ]
\  }}|| |<   d S rf   )r   )rh   ry   r[   values       r0   updatezIndex.update  s2    "==?? 	 	KD%DJJ	 	r+   Ftreewant_unchangedc              #   x    K    fd}t           j                                        ||||          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 rf   r   )r'   r^   rh   s     r0   lookup_entryz-Index.changes_from_tree.<locals>.lookup_entry  s#    JE9l5:6666r+   )r   N)changes_from_treer   keys)rh   object_storer   r   r   s   `    r0   r   zIndex.changes_from_tree  s~      	7 	7 	7 	7 	7 %L)
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
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   )rh   r   s     r0   commitzIndex.commit  s      <)9)9););<<<r+   )T)r(   NF)#rj   rk   rl   rm   r   r   strri   propertyr'   r   rJ   r@   rE   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   boolr   r   r4   r+   r0   r   r   $  sc        ucz!2       XJ J J     ! ! ! ! !" "* " " " ""(5/ " " " "U u    U s    <XeE5#,=&>? < < < <  , ,* , , , ,    $8E%*;$<= $ $ $ $$xeZ&7 89 $ $ $ $d5*#45    
 HM
 
&.
@D
 
 
 
0= = = = =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 rf   )r1   rD   r   )r'   r.   r/   rL   newtreeadd_treetreess        r0   r   zcommit_tree.<locals>.add_tree  sg    5==;%dOOHW(E*****(dr+   c                 F   t                      }|                                          D ]\\  }}t          |t                    r&t          j        } t          | |                    }n|\  }}|                    |||           ]                    |           |j	        S rf   )
r   r   rD   dictr   r   r:   add
add_objectid)	r'   r   r/   r^   r   r#   
build_treer   r   s	         r0   r   zcommit_tree.<locals>.build_tree  s    vv$T{0022 	* 	*OHe%&& $| j$!9!9::#sHHXtS))))%%%wr+   )r1   )r   r   r'   r#   r   	tree_pathr/   r   r   r   r   s   `       @@@r0   r   r     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     r0   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   r#   	other_sha
other_modes              r0   r   r     sq     4 e**K!3L$!G!G 		O 		OT4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_shar$   r%   c                     |t          | j                  }t          | j        | j        | j        | j        || j        | j        | j	        |||          S )zCreate a new index entry from a stat value.

    Args:
      stat_val: POSIX stat_result instance
      hex_sha: Hex sha of the object
      flags: Index flags
    )
r   st_moder   st_ctimest_mtimest_devst_inost_uidst_gidst_size)stat_valr   r$   r   r%   s        r0   index_entry_from_statr     s]     |H,--  r+   win32c                        e Zd Z fdZ xZS )WindowsSymlinkPermissionErrorc                 b    t          t          |                               |d|z  |           d S )Nz@Unable to create symlink; do you have developer mode enabled? %s)superPermissionErrorri   )rh   errnomsgr   r   s       r0   ri   z&WindowsSymlinkPermissionError.__init__=  sB    /4((11 9;>?    r+   )rj   rk   rl   ri   __classcell__)r   s   @r0   r   r   ;  s8        	 	 	 	 	 	 	 	 	r+   r   )dir_fdc                    	 t          j        | |||          S # t          $ r&}t          |j        |j        |j                  |d }~ww xY w)N)target_is_directoryr  )r   symlinkr  r   r  strerrorr   )srcdstr  r  es        r0   r  r  C  sn    	8:S.A     	8 	8 	8/QZ1 1678	8s    
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
    Nr   r   r   )r   lstatFileNotFoundErroras_raw_stringr   r   unlinksysplatformdecoder  r   ra   openr@   rJ   chmod)	r  r   r  r  r  r  oldstatcontentsrA   s	            r0   build_file_from_blobr  O  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 rf   )lowerINVALID_DOTNAMES)r"  s    r0   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)rstripr$  r%  )r"  strippeds     r0   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/.r*   FT)split)r'   element_validatorpartsr6   s       r0   validate_pathr/    sJ     JJtE    ## 	55	 tr+   	root_path
index_pathtree_idr  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        d          ||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@   )r  r  r   N) r   rD   r   r   fsencoder   r/  r'   _tree_to_fs_pathr   r.   makedirsr   r   isdirmkdirr  r#   r   r  r   r   st_nlinkr   r   r   st_atimer   r   r   r   rJ   )r0  r1  r   r2  r  validate_path_elementr  r   r^   	full_pathstobjst_tuples                r0   build_index_from_treer@    s   0 *5)))Ei'' +K	**	#L':: )D )DUZ)>?? 	$Y
;;	w~~bgooi8899 	4K	22333 uz"" 	7==++ $###)$$BB uy)Cc4(((((%UZ-%  B  	(UZ!8!8 	(
 
				
H h''B1"eiCC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
    r   r   N)rD   r   r   r   r   r  r  r   readlinkfsdecodeencodedatar  r@   )rA  r   r  r  rA   s        r0   blob_from_path_and_moderG    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
    )rG  r   )rA  r=  r  s      r0   blob_from_path_and_statrI    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)
errorsrK  reporL  rD   r   r   rD  headr   )r'   rK  rL  rN  s       r0   read_submodule_headrP    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.
    r   TF)r   r'   r   r8   rP  r#   )r   r^   rO  s      r0   _has_directory_changedrR    sZ     
w~~bgll9g6677 "9--94  t5r+   c              #   (  K   t          |t                    st          j        |          }|                                 D ]\  }}t          ||          }	 t          j        |          }t          j        |j	                  rt          ||          r|V  Xt          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)rD   r   r   r4  r   r5  r  r   r   r   rR  S_ISREGr   rI  r   r#   r  )r   r0  filter_blob_callbackr   r^   r<  r=  r  s           r0   get_unstaged_changesrV  3  s>      i'' +K	**	!OO--    	5$Y	::		 )$$B|BJ'' ))U;; $#OOO<
++ DL4L4L *9b99D#/++D)<< w%)## ! 	 	 	 OOOOO	!   s   AC>2C>C>>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.
    r*   )rD   r   os_sep_bytesreplacer   r'   r8   )r0  r   sep_corrected_paths      r0   r5  r5  ]  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
    r*   )rD   r   r   r4  rY  rZ  )rA  fs_path_bytesr   s      r0   _fs_to_tree_pathr^  n  sY     gu%%  G,,t!)),==		!	r+   c                     t           j                            t           j                            |d                    r+t	          |          }|d S t          | |dt                    S d S )Nr   r   r   )r   r'   r   r8   rP  r   r   )r=  r'   rO  s      r0   index_entry_from_directoryr`    s\    	w~~bgll41122 D"4((<4$Rq{CCCC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        d          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
    Nr   )rD   r   r   r  r   r   r   r`  rT  r   rI  r   r   r   )r'   r   r=  r  s       r0   index_entry_from_pathrb    s     dE"""""	$B|BJ 4)"d333|BJ 54<
#;#; 5&tR00###D)))$R!4444r+   pathsc              #      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)r5  rb  r  IsADirectoryError)rc  r0  r   r'   r6   r^   s         r0   iter_fresh_entriesrg    s         Y--	)!,GGGEE!#45 	 	 	EEE	Ek s   *A A c              #      K   t          | ||          D ]8\  }}|
|r|ddfV  t          | }||j        t          |j                  fV  9d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
    re  N)rg  r   r#   r   r   )rc  r0  include_deletedr   r'   r^   s         r0   iter_fresh_objectsrj    s       *9<9 9 9 < <e= 'D$&&&&&E	<
#;#;;;;;;< <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)rg  )r   r0  r'   r^   s       r0   refresh_indexrl    s=     *%;;    e 	 E$K   r+   c                   :    e Zd ZdZdeeef         fdZd Zd Z	dS )locked_indexzPLock the index while making modifications.

    Works as a context manager.
    r'   c                     || _         d S rf   )_pathr   s     r0   ri   zlocked_index.__init__  s    


r+   c                 v    t          | j        d          | _        t          | j                  | _        | j        S )Nr   )r   rp  _filer   _indexr   s    r0   	__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rf   )rr  abortr   r   rs  r   r   BaseException)rh   exc_type	exc_value	tracebackrA   s        r0   __exit__zlocked_index.__exit__  s    JF	4:&&AQ 3444 GGIIIII  	 	 	J	s   .A# ##B
	B
N)
rj   rk   rl   rm   r   r   r   ri   rt  r{  r4   r+   r0   rn  rn    s`         U5#:.      

 
 
 
 
r+   rn  rf   r   )NN)r  )FN)Yrm   collectionsr   r   r>   r  typingr   r   r   r   r   r   r	   r
   r   r   filer   r   r   objectsr   r   r   r   r   r   r   rK   r   r   r   
namedtupler   FLAG_STAGEMASK
FLAG_VALIDrX   EXTENDED_FLAG_SKIP_WORKTREEEXTENDED_FLAG_INTEND_TO_ADDr{   r   r1   r:   rB   rO   rE   r   r]   rb   	Exceptionrd   ru   rx   r|   r   r   r   r   r   r   r   r  r  r   r  r  r%  r   r&  r*  r/  r@  rG  rI  rP  rR  rV  seprE  rY  r5  r^  r`  rb  rg  rj  rl  rn  r4   r+   r0   <module>r     sh	  * , +     				   



, , , , , , , , , , , , , , , , , , , , , , , ,       , , , , , ,. . . . . . . . . . . . . . . . . . 9 9 9 9 9 9 9 9 9 9 $[#   
&  
  %  %  #E #eE5L1 # # # # - - -
+ + +$ $ $"/ /sJ)? / / / /d!@u !@Z !@# !@$ !@ !@ !@ !@H, , , , ,Y , , ,	+( 	+ 	+ 	+ 	+	$uj01 	 	 	 	3 38 3d5
1B+C&D 3xX[} 3 3 3 3& "	2 	2	2%#$	2 c]	2 
		2 	2 	2 	2s s    ,F= F= F= F= F= F= F= F=R)!)*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f AE$( %(08SM   : <7       8t 8 8 8 8 8 8 jG FJ$)! )! )!)!)!,1)! )! )! )!X / 35 3T 3 3 3 3 $     %B  FJ      7G GS%Z Gc5j!G "G 	G
 G G G GV +2 U #    .G GU G G G GeCJ/ HUO    0e    6 "$  $ $ !&sEz!2$  $  $  $ N v}}W%%7 7% 7 7 7 7"eCJ/ E    & 8J3G     @D #+O#<j   > /3 E?',?+ eE8J//01   , CH< <<+0<&%%(3-78:< < < <.   5                 r+   