
    	D,jB                     l   d Z g dZddlmZ ddl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ZddlZddlmZ ddlmZ dd	lmZmZ dd
lmZmZmZmZ ddl m!Z!m"Z" ddl#m$Z$m%Z%m&Z& ddl'm(Z(m)Z) ddl*m+Z+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z< ddl=m>Z> e8rddl?m@Z@ ddlAmBZB ddlCmDZD eez  ZE	 e. ZFdeGde>deGfdZHdeGdeGfdZIdeGdddeGddfdZJd eKdeKfd!ZLde(fd"e7e;e,d#f                  d$e5eM         d%e;deMf         d&e:e(         ddf
d'ZNd$e5eM         de9eKeKf         fd(ZOd)e;e,e>eKf         de9e>eKf         fd*ZPd$e5eM         de9eKe4e9e>eKf         d#f         eMeMf         fd+ZQ	 d7d"e6e-         d,d-d.eRd/eKde9eMe6d0         f         f
d1ZSd2d0d3eKde,fd4ZTd,d-d5e7eM         de6e,         fd6ZUdS )8zVStandalone functions to accompany the index implementation and make it more
versatile.)write_cache
read_cachewrite_tree_from_cache	entry_keystat_mode_to_index_modeS_IFGITLINKrun_commit_hook	hook_path    )BytesION)Path)S_IFDIRS_IFLNKS_IFMTS_IFREGS_ISDIRS_ISLNKS_IXUSR)IStream)str_tree_type)handle_process_outputsafer_popen)defencforce_bytes
force_textsafe_decode)HookExecutionErrorUnmergedEntriesError)traverse_tree_recursivetraverse_trees_recursivetree_to_stream)IndexFileSHA1Writerfinalize_process   )CE_EXTENDEDBaseIndexEntry
IndexEntryCE_NAMEMASKCE_STAGESHIFT)packunpack)	DictIOListSequenceTYPE_CHECKINGTupleTypeUnioncast)PathLike)GitCmdObjectDB)TreeCacheTup)	IndexFilenamegit_dirreturnc                 .    t          j        |d|           S )zK:return: path to the given named hook in the given git repository directoryhooks)ospjoin)r8   r9   s     \/home/rurouni/.local/share/uv/tools/aider-chat/lib/python3.11/site-packages/git/index/fun.pyr	   r	   >   s    8GWd+++    pathc                 6    t          j        |           d         S )Nr#   )r=   splitext)rA   s    r?   _has_file_extensionrD   C   s    <a  r@   indexr7   argsc                    t          | |j        j                  }t          j        |t          j                  sdS t          j                                        }t          t          j	        |j
                            |d<   d|d<   |g}	 t          j        dk    rQt          |          sBt          |                              |j        j                                                  }d|g}t%          |t'          |          z   |t(          j        t(          j        |j        j                  }g }g }	t-          ||j        |	j        t0                     d                    |          }
d                    |	          }|j        d	k    rAt7          |
t8                    }
t7          |t8                    }t;          ||j        ||
          dS # t<          $ r}t;          ||          |d}~ww xY w)
a:  Run the commit hook of the given name. Silently ignore hooks that do not exist.

    :param name:
        Name of hook, like ``pre-commit``.

    :param index:
        :class:`~git.index.base.IndexFile` instance.

    :param args:
        Arguments passed to hook file.

    :raise git.exc.HookExecutionError:
    NGIT_INDEX_FILE:
GIT_EDITORwin32zbash.exe)envstdoutstderrcwd r
   )r	   repor9   osaccessX_OKenvironcopyr   fspathrA   sysplatformrD   r   relative_toworking_diras_posixr   list
subprocessPIPEr   appendr"   r>   
returncoder   r   r   	Exception)r8   rE   rF   hprL   cmdrelative_hpprocessstdout_liststderr_listrM   rN   exs                r?   r   r   G   s    
4+	,	,B9R!! 
*//

C'	%*(=(=>>CC$CM<7""+>r+B+B" r((..uz/EFFOOQQK{+C$t**??
&
 
 
 "$!#g{'9;;MO_```%%%%""//F//F$R);VVLLL #"  1 1 1 R((b01s   B#G 
G,G''G,modec                     t          |           rt          S t          |           st          |           t          k    rt          S t
          | t          z  rdpdz  S )zZConvert the given mode from a stat call to the corresponding index mode and
    return it.i  i  )r   r   r   r   r   r   r   )rj   s    r?   r   r   z   sT     t}} t}} t33dWn.7%88r@   entriesr&   streamextension_dataShaStreamClsc                     ||          }|j         }|j        }t          d | D                       rdnd} |d            |t          d|t	          |                                | D ]X} |            }	 ||j                    ||j                   t          |j                  }
t          |
t                    }t	          |          t          z  }|t	          |          k    sJ d|j        z              ||j        t          z  z  }|j        r
|t          z  } |t          d|j        |j        |j        |j        |j        |j        |j        |	  	                   |j        r |t          d	|j                              ||            |            |	z
  d
z   dz  } |d|	|z    |            z
  z             Z||                    |           |                                 dS )a  Write the cache represented by entries to a stream.

    :param entries:
        **Sorted** list of entries.

    :param stream:
        Stream to wrap into the AdapterStreamCls - it is used for final output.

    :param ShaStreamCls:
        Type to use when writing to the stream. It produces a sha while writing to it,
        before the data is passed on to the wrapped stream.

    :param extension_data:
        Any kind of data to write as a trailer, it must begin a 4 byte identifier,
        followed by its size (4 bytes).
    c              3   $   K   | ]}|j         V  d S )N)extended_flags).0entrys     r?   	<genexpr>zwrite_cache.<locals>.<genexpr>   s%      AAu+AAAAAAr@            DIRC>LL)encodingz"Path %s too long to fit into index>LLLLLL20sH>H       N)tellwriteanyr)   lenctime_bytesmtime_bytesstrrA   r   r   r'   flagsCE_NAMEMASK_INVrr   r$   devinoderj   uidgidsizebinsha	write_sha)rl   rm   rn   ro   
stream_shar   r   versionrt   beginoffsetpath_strrA   plenr   	real_sizes                  r?   r   r      s/   . f%%J?DE AAAAAAAHaaqG	E'NNN	E$ugs7||
,
,---  < <dffe   e   uz??!(V<<<4yy;&s4yy   "F"S   o56 	![ E	
		

 
	
 	
 	
  	4E$tU122333dTVVk)A-3	ei/44669:;;;; !((( r@   c           	          |                      d          }|dk    rt          d|z            t          t          t          t          f         t          d|                      d                              }|\  }}|dv sJ d|z              ||fS )z>Return tuple(version_long, num_entries) from the given stream.   rx   zInvalid index file header: %rry   r}   )r#   rw   rv   z@Unsupported git index version %i, only 1, 2, and 3 are supported)readAssertionErrorr3   r0   intr*   )rm   type_idunpackedr   num_entriess        r?   read_headerr      s    kk!nnG'<wFGGGE#s(OVE6;;u3E3E%F%FGGH#G[i!cfm!mKr@   rt   c                      t          |           dk    r-| d         }t          |t                    sJ |j        |j        fS t          t          t          t          f         |           } | S )z
    :return:
        Key suitable to be used for the
        :attr:`index.entries <git.index.base.IndexFile.entries>` dictionary.

    :param entry:
        One instance of type BaseIndexEntry or the path and the stage.
    r#   r
   )	r   
isinstancer%   rA   stager3   r0   r4   r   )rt   entry_firsts     r?   r   r      sb     5zzQAh+~66666 +"344 U8S=)511r@   c                 R   t          |           \  }}d}i }| j        }| j        }||k     r! |            }t          d |d                    d         }t          d |d                    d         }	t          d |d                    \  }
}}}}}}}d}|t          z  rt          d |d                    d         }|t
          z  } ||                              t                    } |            |z
  dz   dz  } |||z    |            z
             t          ||||||	|
|||||f          }||||j	        f<   |d	z  }||k     !|                     d
          }t          |          dk    sJ dt          |          z              |dd         }|dd         }||||fS )a  Read a cache file from the given stream.

    :return:
        tuple(version, entries_dict, extension_data, content_sha)

        * *version* is the integer version number.
        * *entries_dict* is a dictionary which maps IndexEntry instances to a path at a
          stage.
        * *extension_data* is ``""`` or 4 bytes of type + 4 bytes of size + size bytes.
        * *content_sha* is a 20 byte sha on all cache file contents.
    r
   z>8sr}   r{   .   r|   rw   r~   r#      zNIndex Footer was not at least a sha on content as it was only %i bytes in sizeiN)r   r   r   r*   r$   r'   decoder   r&   r   r   )rm   r   r   countrl   r   r   r   ctimemtimer   inorj   r   r   r   shar   rr   	path_sizerA   r   rt   rn   content_shas                            r?   r   r      s    'v..G[E8:G;D;D
+

dffudd1gg&&q)udd1gg&&q)7=mTTR`MaMa7b7b4c4c4e; 	6#D$$q''2215NK'	tI%%f--TVVk)A-3	kI%/000D#udE5#sCQTVZ\jkll',u{#$
! +

2 [[__N~###X[^_m[n[nn $## !&K $DSD)NWnk::r@   odbr5   slsir6   c           	         g }|j         }|j        }||k     r&| |         }|j        dk    rt          |          |dz  }|j                            d|          }|dk    r0|                    |j        |j        |j        |d         f           n|j        ||         }	|}
|
|k     rH| |
         }|j                            d|          }|dk    s|j        ||         |	k    rn|
dz  }
|
|k     Ht          | |t          |dz
  |
          |dz             \  }}|                    |t          |	f           |
}||k     &t                      }t          ||j                   |                    d           |                    t#          t$          t'          |                                          |                    }|j        |fS )aN  Create a tree from the given sorted list of entries and put the respective
    trees into the given object database.

    :param entries:
        **Sorted** list of :class:`~git.index.typ.IndexEntry`\s.

    :param odb:
        Object database to store the trees in.

    :param si:
        Start index at which we should start creating subtrees.

    :param sl:
        Slice indicating the range we should process on the entries list.

    :return:
        tuple(binsha, list(tree_entry, ...))

        A tuple of a sha and a list of tree entries being a tuple of hexsha, mode, name.
    r
   r#   /r   N)startstopr   r   rA   findr`   r   rj   r   slicer   r   r    r   seekstorer   r   r   getvalue)rl   r   r   r   
tree_itemsciendrt   rboundbasexioentryorboundr   _tree_entry_listsioistreams                    r?   r   r   +  s   . (*J	B
'C
s((;!&u---
ab))R<<u|UZBCCIJJJJ :bi(DBs((  +**333b==FK7
$;t$C$Ca s(( %:'3bSTfVXHYHY[ade[e$f$f!C!sGT2333 B; s((D ))C:sy)))HHQKKKiis3<<>>/B/BCHHIIGNJ''r@   
tree_entryr   c                 \    t          | d         | d         |t          z  | d         f          S )Nr#   r
   rw   )r%   r(   )r   r   s     r?   _tree_entry_to_baseindexentryr   p  s-    :a=*Q--9OQ[\]Q^_```r@   	tree_shasc                 V   g }t          |          dv r?t          | |d         d          D ]%}|                    t          |d                     &|S t          |          dk    rt	          dt          |          z            t          | |d          D ]\  }}}|&||D|d         |d         k    r$|d         |d         k    r|d         |d         k    s6|d         |d         k    r|d         |d         k    r||d         |d         k    rj|                    t          |d                     |                    t          |d	                     |                    t          |d                     |d         |d         k    s|d         |d         k    r%|                    t          |d                     /|                    t          |d                     T|d         |d         k    s|d         |d         k    rF|                    t          |d                     |                    t          |d	                     ||d         |d         k    s|d         |d         k    rF|                    t          |d                     |                    t          |d                     0|)|J |                    t          |d                     [|%|                    t          |d                     |d         |d         k    s|d         |d         k    rH|                    t          |d	                     |                    t          |d                     |                    t          |d                     |S )
a7  
    :return:
        List of :class:`~git.index.typ.BaseIndexEntry`\s representing the aggressive
        merge of the given trees. All valid entries are on stage 0, whereas the
        conflicting ones are left on stage 1, 2 or 3, whereas stage 1 corresponds to the
        common ancestor tree, 2 to our tree and 3 to 'their' tree.

    :param tree_shas:
        1, 2 or 3 trees as identified by their binary 20 byte shas. If 1 or two, the
        entries will effectively correspond to the last given tree. If 3 are given, a 3
        way merge is performed.
    )r#   rw   r   rP   r
   rv   zCannot handle %i trees at onceNr#   rw   )r   r   r`   r   
ValueErrorr   )r   r   outrt   r   ourstheirss          r?   aggressive_tree_merger   t  s    !#C 9~~,S)B-DD 	@ 	@EJJ4UA>>????
 9~~9C	NNJKKK 7sIrJJ AG AGdF% Q47**tAw&)/C/CQSYZ[S\H\H\Q47**tAw&)/C/CQSYZ[S\H\H\ 

#@q#I#IJJJ

#@q#I#IJJJ

#@#K#KLLLLaDG++tAw$q'/A/A

#@q#I#IJJJJ 

#@#K#KLLLL Aw$q'))T!WQ-?-?

#@q#I#IJJJ

#@q#I#IJJJ >ayDG++vayDG/C/C

#@q#I#IJJJ

#@#K#KLLL |)))

8CCDDDD

8qAABBBB 7fQi''47fQi+?+?JJ<T1EEFFFJJ<VQGGHHHH JJ<T1EEFFFF Jr@   )r
   )V__doc____all__ior   rR   os.pathrA   r=   pathlibr   statr   r   r   r   r   r   r   r^   rX   
gitdb.baser   	gitdb.typr   git.cmdr   r   
git.compatr   r   r   r   git.excr   r   git.objects.funr   r   r    git.utilr!   r"   typr$   r%   r&   r'   r(   utilr)   r*   typingr+   r,   r-   r.   r/   r0   r1   r2   r3   	git.typesr4   git.dbr5   git.objects.treer6   r   r7   r   r   r   r	   rD   r   r   r   bytesr   r   r   r   r   r   r   r    r@   r?   <module>r      s   	 	 	       				             M M M M M M M M M M M M M M M M M M     



       # # # # # # 6 6 6 6 6 6 6 6 C C C C C C C C C C C C < < < < < < < <         
 ; : : : : : : : T T T T T T T T T T T T T T         U T T T T T T T T T T T T T T T T T T T T T        %%%%%%------  ,,C ,( ,s , , , ,
!c !c ! ! ! !/M# /Mk /M# /M$ /M /M /M /Mf9# 9# 9 9 9 9 *..A	F FeNL89:FuIF $+&F *+	F
 
F F F FR	 5	 	 eCHo 	  	  	  	 eNHc9: uXs]?S    07;uI7;
3U8S=)<78%FG7; 7; 7; 7;v LMB( B(*B($4B(:?B(EHB(
5$~&&'B( B( B( B(Jan aS a^ a a a ac/ cHUO cPTUcPd c c c c c cr@   