
    64%e1@                     ^   d dl mZ d dlmZ d dl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mZmZ d dlmZmZ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# d dl$m%Z% d dl&m'Z( ddl)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/m0Z0 d dl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: d dl;m<Z< e6rddl=m>Z> d dl?m@Z@ d dlAmBZB eez  ZCe, ZDdZEdeFde<deFfdZGdeFdeFfdZHdeFdddeFddfdZIdeJdeJfd ZKde fd!e5e9e*d"f                  d#e3eL         d$e9deLf         d%e8e          ddf
d&ZMd#e3eL         de7eJeJf         fd'ZNd(e9e*e<eJf         de7e<eJf         fd)ZOd#e3eL         de7eJe2e7e<eJf         d"f         eLeLf         fd*ZP	 d6d!e4e+         d+d,d-eQd.eJde7eLe4d/         f         f
d0ZRd1d/d2eJde*fd3ZSd+d,d4e5eL         de4e*         fd5ZTdS )7    )BytesIO)PathN)S_IFDIRS_IFLNKS_ISLNKS_ISDIRS_IFMTS_IFREGS_IXUSR)PROC_CREATIONFLAGShandle_process_output)defenc
force_textforce_bytesis_posixis_winsafe_decode)UnmergedEntriesErrorHookExecutionError)tree_to_streamtraverse_tree_recursivetraverse_trees_recursive)IndexFileSHA1Writerfinalize_process)IStream)str_tree_type   )BaseIndexEntry
IndexEntryCE_NAMEMASKCE_STAGESHIFT)packunpack)	DictIOListSequenceTYPE_CHECKINGTupleTypeUnioncast)PathLike)	IndexFile)GitCmdObjectDB)TreeCacheTup)write_cache
read_cachewrite_tree_from_cache	entry_keystat_mode_to_index_modeS_IFGITLINKrun_commit_hook	hook_path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)r9   r:   s     -lib/python3.11/site-packages/git/index/fun.pyr8   r8   J   s    8GWd+++    pathc                 6    t          j        |           d         S )Nr   )r>   splitext)rB   s    r@   _has_file_extensionrE   O   s    <a  rA   indexr.   argsc           	         t          | |j        j                  }t          j        |t          j                  sdS t          j                                        }t          t          |j
                            |d<   d|d<   |g}	 t          rQt          |          sBt          |                              |j        j                                                  }d|g}t#          j        |t'          |          z   |t"          j        t"          j        |j        j        t*          t,                    }g }g }	t/          ||j        |	j        t2                     d                    |          }
d                    |	          }|j        dk    rAt9          |
t:                    }
t9          |t:                    }t=          ||j        ||
          dS # t>          $ r}t=          ||          |d}~ww xY w)	zRun the commit hook of the given name. Silently ignores hooks that do not exist.

    :param name: name of hook, like 'pre-commit'
    :param index: IndexFile instance
    :param args: arguments passed to hook file
    :raises HookExecutionError:NGIT_INDEX_FILE:
GIT_EDITORzbash.exe)envstdoutstderrcwd	close_fdscreationflags r   ) r8   repor:   osaccessX_OKenvironcopyr   strrB   r   rE   r   relative_toworking_diras_posix
subprocessPopenlistPIPEr   r   r   appendr   r?   
returncoder   r   r   	Exception)r9   rF   rG   hprL   cmdrelative_hpprocessstdout_liststderr_listrM   rN   exs                r@   r7   r7   S   s    
4+	,	,B9R!! t
*//

C'EJ88CC$CM 	,-b11 	, 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 )zYConvert the given mode from a stat call to the corresponding index mode
    and return iti  i  )r   r   r   r	   r6   r
   r   )rk   s    r@   r5   r5      sT     t}} t}} t33dWn.7%88rA   entriesr   streamextension_dataShaStreamClsc                 B    ||          }|j         }|j        }d} |d            |t          d|t          |                                | D ]"} |            }	 ||j                    ||j                   t          |j                  }
t          |
t                    }t          |          t          z  }|t          |          k    sJ d|j        z              ||j        t          z  z  } |t          d|j        |j        |j        |j        |j        |j        |j        |	  	                    ||            |            |	z
  dz   dz  } |d	|	|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 )      DIRC>LL)encodingz"Path %s too long to fit into index>LLLLLL20sH       N)tellwriter"   lenctime_bytesmtime_bytesrY   rB   r   r   r    flagsCE_NAMEMASK_INVdevinoderk   uidgidsizebinsha	write_sha)rm   rn   ro   rp   
stream_sharz   r{   versionentrybeginoffsetpath_strrB   plenr   	real_sizes                  r@   r1   r1      s   $ f%%J?DE G	E'NNN	E$ugs7||
,
,---  < <dffe   e   uz??!(V<<<4yy;&s4yy   "F"S   o56	
		

 
	
 	
 	
 	dTVVk)A-3	ei/44669:;;;; !((( rA   c           	      
   |                      d          }|dk    rt          d|z            t          t          t          t          f         t          d|                      d                              }|\  }}|dv sJ ||fS )z=Return tuple(version_long, num_entries) from the given stream   rs   zInvalid index file header: %rrt   rw   r   rr   )readAssertionErrorr,   r)   intr#   )rn   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[ fKrA   r   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 index.entries dictionary
    :param entry: One instance of type BaseIndexEntry or the path and the stager   r   )	r|   
isinstancer   rB   stager,   r)   r-   r   )r   entry_firsts     r@   r4   r4      sb     5zzQAh+~66666 +"344 U8S=)511rA   c                    t          |           \  }}d}i }| j        }| j        }||k     r |            }t          d |d                    d         }t          d |d                    d         }	t          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 contentsr   z>8srw   rv   .   rx   r      zNIndex Footer was not at least a sha on content as it was only %i bytes in sizeiN)
r   r   rz   r#   r    decoder   r   r   r|   )rn   r   r   countrm   r   rz   r   ctimemtimer   inork   r   r   r   shar   	path_sizerB   r   r   ro   content_shas                           r@   r2   r2      s    'v..G[E8:G;D;D
+

dffudd1gg&&q)udd1gg&&q)7=mTTR`MaMa7b7b4c4c4eK'	tI%%f--TVVk)A-3	kI%/000D#udE5#sCQTVZ[\\',u{#$
 +

, [[__NNb   WZ]^lZmZmm 	!   !&K $DSD)NWnk::rA   odbr/   slsir0   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 )a  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 IndexEntries
    :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, namer   r   /r   N)startstopr   r   rB   findra   r   rk   r3   slicer   r   r   r{   seekstorer   r   r|   getvalue)rm   r   r   r   
tree_itemsciendr   rboundbasexioentryorboundr   _tree_entry_listsioistreams                    r@   r3   r3     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''rA   
tree_entryr   c                 \    t          | d         | d         |t          z  | d         f          S )Nr   r   rr   )r   r!   )r   r   s     r@   _tree_entry_to_baseindexentryr   X  s-    :a=*Q--9OQ[\]Q^_```rA   	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 )
a  
    :return: list of BaseIndexEntries 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 performedr   r   rR   r      zCannot handle %i trees at onceNr   rr   )r|   r   ra   r   
ValueErrorr   )r   r   outr   r   ourstheirss          r@   aggressive_tree_merger   \  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 JrA   )r   )Uior   pathlibr   rT   statr   r   r   r   r	   r
   r   r]   git.cmdr   r   
git.compatr   r   r   r   r   r   git.excr   r   git.objects.funr   r   r   git.utilr   r   
gitdb.baser   	gitdb.typr   os.pathrB   r>   typr   r   r    r!   utilr"   r#   typingr$   r%   r&   r'   r(   r)   r*   r+   r,   	git.typesr-   r   r.   git.dbr/   git.objects.treer0   r6   r   __all__rY   r8   rE   r7   r   r5   bytesr1   r   r4   r2   r   r3   r   r    rA   r@   <module>r      s'  
             				                      = = = = = = = =                = < < < < < < <         
 ; : : : : : : :       # # # # # #       G G G G G G G G G G G G         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\9# 9# 9 9 9 9 *..A	= =eNL89:=uI= $+&= *+	=
 
= = = =@
 5	 
 eCHo 
  
  
  
 eNHc9: uXs]?S    $1;uI1;
3U8S=)<78%FG1; 1; 1; 1;j LM7( 7(*7($47(:?7(EH7(
5$~&&'7( 7( 7( 7(tan aS a^ a a a a_/ _HUO _PTUcPd _ _ _ _ _ _rA   