
    .Ph`A                     h   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ZTd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   )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)r7   r8   s     M/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/git/index/fun.pyr	   r	   >   s    8GWd+++    pathc                 6    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dS t          j                                        }t          t          |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	   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9R!! 
*//

C'EJ88C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   )ri   s    r>   r   r   z   sT     t}} t}} t33dWn.7%88r?   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_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      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:;;;; !((( r?   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.   rq   zInvalid index file header: %rrr   ru   r#   rp   )readAssertionErrorr2   r/   intr)   )rl   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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      sb     5zzQAh+~66666 +"344 U8S=)511r?   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 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
+

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~###X[^_m[n[nn $## !&K $DSD)NWnk::r?   odbr4   slsir5   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   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|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
   rp   )r$   r'   )r   r   s     r>   _tree_entry_to_baseindexentryr   j  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   r   rO   r
      zCannot handle %i trees at onceNr#   rp   )rz   r   r_   r   
ValueErrorr   )r   r   outr   r   ourstheirss          r>   aggressive_tree_merger   n  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
   )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      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 < < < < < < < <         
 ; : : : : : : : 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f9# 9# 9 9 9 9 *..A	B BeNL89:BuIB $+&B *+	B
 
B B B BJ
 5	 
 eCHo 
  
  
  
 eNHc9: uXs]?S    04;uI4;
3U8S=)<78%FG4; 4; 4; 4;p 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?   