
    g`A                        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. ddl/m0Z0m1Z1 ddl2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; ddl<m=Z= e7rddl>m?Z? ddl@mAZA ddlBmCZC eez  ZD	 e- 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"e6e:e+d#f      d$e4eL   d%e:deLf   d&e9e(   ddf
d'ZMd$e4eL   de8eJeJf   fd(ZNd)e:e+e=eJf   de8e=eJf   fd*ZOd$e4eL   de8eJe3e8e=eJf   d#f   eLeLf   fd+ZP	 d7d"e5e,   d,d-d.eQd/eJde8eLe5d0   f   f
d1ZRd2d0d3eJde+fd4ZSd,d-d5e6eL   de5e+   fd6ZTy)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   )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                 0    t        j                  |d|       S )zK:return: path to the given named hook in the given git repository directoryhooks)ospjoin)r7   r8   s     B/var/www/openai/venv/lib/python3.12/site-packages/git/index/fun.pyr	   r	   >   s    88GWd++    pathc                 2    t        j                  |       d   S )Nr#   )r<   splitext)r@   s    r>   _has_file_extensionrC   C   s    <<a  r?   indexr6   argsc                    t        | |j                  j                        }t        j                  |t        j
                        syt        j                  j                         }t        t        |j                              |d<   d|d<   |g}	 t        j                  dk(  rKt        |      s@t        |      j                  |j                  j                         j#                         }d|g}t%        |t'        |      z   |t(        j*                  t(        j*                  |j                  j                         }g }g }	t-        ||j.                  |	j.                  t0               dj3                  |      }
dj3                  |	      }|j4                  d	k7  r8t7        |
t8              }
t7        |t8              }t;        ||j4                  ||
      y# 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	   repor8   osaccessX_OKenvironcopyr   strr@   sysplatformrC   r   relative_toworking_diras_posixr   list
subprocessPIPEr   appendr"   r=   
returncoder   r   r   	Exception)r7   rD   rE   hprK   cmdrelative_hpprocessstdout_liststderr_listrL   rM   exs                r>   r   r   G   s    
4++	,B99R!
**//
C'EJJ8CC$CM<<7"+>r+B r(..uzz/E/EFOOQK{+C$t*????

&&
 "$!#g{'9'9;;M;MO_`%%"/F/F$R););VVLL #  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  xr dxs 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   )ri   s    r>   r   r   z   sA     t}t}t3dWn.7%88r?   entriesr%   streamextension_dataShaStreamClsc                 8    ||      }|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         . ||j                  |       |j)                          y
)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_bytesrV   r@   r   r   r&   flagsCE_NAMEMASK_INVdevinoderi   uidgidsizebinsha	write_sha)rk   rl   rm   rn   
stream_sharx   ry   versionentrybeginoffsetpath_strr@   plenr}   	real_sizes                  r>   r   r      sr   . f%J??DE G	'N	$ugs7|
,- fe e uzz?!(V<4y;&s4y S"F"SS o56		

				


	
 	dVk)A-3	ei/469:;1 8 !( r?   c           	          | j                  d      }|dk7  rt        d|z        t        t        t        t        f   t        d| j                  d                  }|\  }}|dv sJ ||fS )z>Return tuple(version_long, num_entries) from the given stream.   rq   zInvalid index file header: %rrr   ru   r#   rp   )readAssertionErrorr2   r/   intr)   )rl   type_idunpackedr   num_entriess        r>   read_headerr      sq    kk!nG'<wFGGE#s(OVE6;;u3E%FGH#G[ fKr?   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
        :attr:`index.entries <git.index.base.IndexFile.entries>` dictionary.

    :param entry:
        One instance of type BaseIndexEntry or the path and the stage.
    r#   r
   )	rz   
isinstancer$   r@   stager2   r/   r3   r   )r   entry_firsts     r>   r   r      s[     5zQAh+~666  +"3"344 U8S=)51r?   c                 n   t        |       \  }}d}i }| j                  }| j                  }||k  r |       }t        d |d            d   }t        d |d            d   }	t        d |d            \  }
}}}}}}}|t        z  } ||      j                  t              } |       |z
  dz   dz  } |||z    |       z
         t        ||||||	|
||||f      }||||j                  f<   |dz  }||k  r| j                  d      }t        |      d	kD  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>8sru   rt   .   rv   r#      zNIndex Footer was not at least a sha on content as it was only %i bytes in sizeiN)
r   r   rx   r)   r&   decoder   r%   r   rz   )rl   r   r   countrk   r   rx   r   ctimemtimer   inori   r   r   r   shar}   	path_sizer@   r   r   rm   content_shas                           r>   r   r      s    'v.G[E8:G;;D;;D
+
fud1g&q)ud1g&q)7=mTR`Ma7b4c4c4eK'	I%%f-Vk)A-3	kI%/0D#udE5#sCQTVZ[\',u{{#$
 +
, [[_N~# X[^_m[nn# !&K $DS)NWnk::r?   odbr4   slsir5   c           	      \   g }|j                   }|j                  }||k  r| |   }|j                  dk7  rt        |      |dz  }|j                  j                  d|      }|dk(  r6|j                  |j                  |j                  |j                  |d f       n|j                  || }	|}
|
|k  rD| |
   }|j                  j                  d|      }|dk(  s|j                  || |	k7  rn|
dz  }
|
|k  rDt        | |t        |dz
  |
      |dz         \  }}|j                  |t        |	f       |
}||k  rt               }t        ||j                         |j                  d       |j!                  t#        t$        t'        |j)                               |            }|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   r@   findr_   r   ri   r   slicer   r   r    ry   seekstorer   r   rz   getvalue)rk   r   r   r   
tree_itemsciendr   rboundbasexioentryorboundr   _tree_entry_listsioistreams                    r>   r   r   %  s   . (*J	B
''C
s(;;!&u--
ab)R<u||UZZBCIJ ::b(DBs(  ++**33b=FKK7$;t$Ca s( %:'3bSTfVXHY[ade[e$f!C!sGT23 B; s(D )C:syy)HHQKiis3<<>/BCHIGNNJ''r?   
tree_entryr   c                 @    t        | d   | d   |t        z  | d   f      S )Nr#   r
   rp   )r$   r'   )r   r   s     r>   _tree_entry_to_baseindexentryr   j  s*    :a=*Q--9OQ[\]Q^_``r?   	tree_shasc                 t   g }t        |      dv r2t        | |d   d      D ]  }|j                  t        |d              |S t        |      dkD  rt	        dt        |      z        t        | |d      D ]@  \  }}}||4||d   |d   k7  r|d   |d   k7  r|d   |d   k7  s!|d   |d   k7  rh|d   |d   k7  r]|d   |d   k7  rR|j                  t        |d             |j                  t        |d             |j                  t        |d             |d   |d   k7  s|d   |d   k7  r|j                  t        |d             |j                  t        |d             |d   |d   k7  s|d   |d   k7  s
|j                  t        |d             |j                  t        |d             B|F|d   |d   k7  s|d   |d   k7  s^|j                  t        |d             |j                  t        |d             |!|J |j                  t        |d             ||j                  t        |d             |d   |d   k7  s|d   |d   k7  r8|j                  t        |d             |j                  t        |d             &|j                  t        |d             C |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   r   rO   r
      zCannot handle %i trees at oncer#   rp   )rz   r   r_   r   
ValueErrorr   )r   r   outr   r   ourstheirss          r>   aggressive_tree_merger   n  s    !#C 9~,S)B-DEJJ4UA>? E 
 9~9C	NJKK 7sIrJdF% Q47*tAw&)/CQSYZ[S\H\Q47*tAw&)/CQSYZ[S\H\ 

#@q#IJ

#@q#IJ

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

#@q#IJ 

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

#@q#IJ

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

#@q#IJ

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

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

8qAB 7fQi'47fQi+?JJ<T1EFJJ<VQGH JJ<T1EFC KN Jr?   )r
   )U__doc____all__ior   rQ   os.pathr@   r<   pathlibr   statr   r   r   r   r   r   r   r]   rW   
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'   utilr(   r)   typingr*   r+   r,   r-   r.   r/   r0   r1   r2   	git.typesr3   git.dbr4   git.objects.treer5   r   r6   r   r~   rV   r	   rC   r   r   r   bytesr   r   r   r   r   r   r   r    r?   r>   <module>r      sm  	  	   M M M  
  # 6 C C < 
 ; G G  U T T %-  ,,C ,( ,s ,
!c !c !/M# /Mk /M# /M$ /Mf9# 9# 9 *..A	BeNL89:BuIB $+&B *+	B
 
BJ
 5	 
 eCHo 
 eNHc9: uXs]?S 04;uI4;
3U8S=)<78%FG4;p LMB(*B($4B(:?B(EHB(
5$~&&'B(Jan aS a^ ac/ cHUO cPTUcPd cr?   