
    wi!                       d dl m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	 d dlm
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ  ej        d          ZddZdZddZ G d d          ZdS )    )annotationsN)Callable)	Generator)Sequence)	clientlib)	file_lock)git)CalledProcessError)clean_path_on_failurecmd_output_b)resource_text
pre_commitreturnstrc                 6   t           j                            d          p[t           j                            t           j                            d          pt           j                            d          d          } t           j                            |           S )a7  Returns the default directory for the Store.  This is intentionally
    underscored to indicate that `Store.get_default_directory` is the intended
    way to get this information.  This is also done so
    `Store.get_default_directory` can be mocked in tests and
    `_get_default_directory` can be tested.
    PRE_COMMIT_HOMEXDG_CACHE_HOMEz~/.cachez
pre-commit)osenvirongetpathjoin
expanduserrealpath)rets    `/root/.openclaw/workspace/chatterbox_venv_py311/lib/python3.11/site-packages/pre_commit/store.py_get_default_directoryr      sq     *..*
+
+ rw||

'((JBG,>,>z,J,J0 0C 7C       )z
Cargo.tomlzmain.gozgo.modzmain.rsz
.npmignorezpackage.jsonz!pre-commit-package-dev-1.rockspecz&pre_commit_placeholder_package.gemspeczsetup.pyzenvironment.ymlzMakefile.PLzpubspec.yamlz	renv.lockzrenv/activate.Rzrenv/LICENSE.renv	directoryNonec                   t           D ]}t          j                            |          \  }}t	          d|           }t          j                            | |          }t          j                            ||          }t          j        |d           t          |d          5 }|                    |           d d d            n# 1 swxY w Y   d S )Nempty_template_Texist_okw)	_LOCAL_RESOURCESr   r   splitr   r   makedirsopenwrite)r    resourceresource_dirnameresource_basenamecontents
target_dirtarget_filefs           r   _make_local_repor3   0   s   $  .0gmmH.E.E++ !F3D!F!FGGW\\)-=>>
gll:/@AA
J....+s## 	qGGH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 s   $CC
	C
	c                      e Zd Z ee          Zd!d"dZej        d#d            Z	ej        	 d!d$d            Z
ed%d            Zd&dZd'dZd'dZd(d)dZd*dZd+dZd,d ZdS )-StoreNr    
str | Noner   r!   c                   |pt                                           | _        t          j                            | j        d          | _        t          j                            | j                  o$t          j        | j        t          j	                   | _
        t          j                            | j                  s{t          j        | j        d           t          t          j                            | j        d          d          5 }|                    d           d d d            n# 1 swxY w Y   t          j                            | j                  rd S |                                 5  t          j                            | j                  r	 d d d            d S t          j        | j                  \  }}t          j        |           |                     |          5 }|                    d	           |                     |           d d d            n# 1 swxY w Y   t          j        || j                   d d d            d S # 1 swxY w Y   d S )
Nzdb.dbTr$   READMEr&   zmThis directory is maintained by the pre-commit project.
Learn more: https://github.com/pre-commit/pre-commit
)dir)db_pathzuCREATE TABLE repos (    repo TEXT NOT NULL,    ref TEXT NOT NULL,    path TEXT NOT NULL,    PRIMARY KEY (repo, ref));)r5   get_default_directoryr    r   r   r   r:   existsaccessW_OKreadonlyr)   r*   r+   exclusive_locktempfilemkstempcloseconnectexecutescript_create_configs_tablereplace)selfr    r2   fdtmpfiledbs         r   __init__zStore.__init__>   s   "Ce&A&A&C&Cw||DNG<<GNN4>** 3	$."'222 	
 w~~dn-- 	K6666bgll4>8<<cBB aM                 7>>$,'' 	F  "" 	. 	.w~~dl++ 	. 	. 	. 	. 	. 	. 	. 	. #*t~>>>KBHRLLLg.. 	/"     **2...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ Jw---+	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.sO   D--D14D12&I%AI,+H#I#H'	'I*H'	+IIIGenerator[None]c              #     K   dd}t          j        t          j                            | j        d          |          5  d V  d d d            d S # 1 swxY w Y   d S )Nr   r!   c                 :    t                               d           d S )NzLocking pre-commit directory)loggerinfo r   r   
blocked_cbz(Store.exclusive_lock.<locals>.blocked_cbi   s    KK677777r   z.lock)r   r!   )r   lockr   r   r   r    )rH   rS   s     r   r@   zStore.exclusive_lockg   s      	8 	8 	8 	8 ^BGLLAA:NN 	 	EEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAr:   Generator[sqlite3.Connection]c              #     K   |p| j         }t          j        t          j        |                    5 }|5  |V  d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S N)r:   
contextlibclosingsqlite3rD   )rH   r:   rK   s      r   rD   zStore.connecto   s      
 )T\  8 899 	R                	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s3   AAAA
	
AA
	AA"%A"repor   depsSequence[str]c                >    |r| dd                     |           S |S )N:,)r   )clsr[   r\   s      r   db_repo_namezStore.db_repo_name}   s-     	--SXXd^^---Kr   refmake_strategyCallable[[str], None]c                ~    }                      |          d	 fd} |            }|r|S                                  5   |            }|r|cd d d            S t                              d d           t	          j        d j                  }t          |          5   ||           d d d            n# 1 swxY w Y                                    5 }	|		                    d|g           d d d            n# 1 swxY w Y   t          j        ||           d d d            n# 1 swxY w Y   |S )
Nr   r6   c                                                      5 } |                     df                                          }|r|d         nd cd d d            S # 1 swxY w Y   d S )Nz1SELECT path FROM repos WHERE repo = ? AND ref = ?r   )rD   executefetchone)rK   resultrc   r[   rH   s     r   _get_resultz$Store._new_repo.<locals>._get_result   s     52G3K  (**  %+4vayy5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5s   6AA AzInitializing environment for .r[   )prefixr9   z4INSERT INTO repos (repo, ref, path) VALUES (?, ?, ?))r   r6   )rb   r@   rP   rQ   rA   mkdtempr    r   rD   rh   r   warn_for_stages_on_repo_init)
rH   r[   rc   r\   rd   original_repork   rj   r    rK   s
   ```       r   	_new_repozStore._new_repo   sm      t,,	5 	5 	5 	5 	5 	5 	5 	5  	M  "" 	M 	M []]F 		M 	M 	M 	M 	M 	M 	M 	M KK????@@@ (DNKKKI&y11 ) )i((() ) ) ) ) ) ) ) ) ) ) ) ) ) )  2

J3	*                 2=)LLL'	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M* sa   D2!AD2)C5D2C	D2C		D2 D:D2D
	
D2D
	D22D69D6git_cmdCallable[..., None]c                T     |ddd            |d|            |dddd           d	S )
z<Perform a complete clone of a repository and its submodules fetchoriginz--tagscheckout	submoduleupdate--init--recursiveNrR   )rH   rc   rr   s      r   _complete_clonezStore._complete_clone   sF     	8,,,
C   Xx?????r   c           	     d    d} |d|dd|d            |dd            |d|dd	d
dd           dS )z;Perform a shallow clone of a repository and its submodules zprotocol.version=2z-cru   rv   z	--depth=1rw   
FETCH_HEADrx   ry   rz   r{   NrR   )rH   rc   rr   
git_configs       r   _shallow_clonezStore._shallow_clone   sc     *
j'8S+FFF
L)))*k8X}	
 	
 	
 	
 	
r   rR   c                H     d fd}                      ||          S )z2Clone the given url and checkout the specific ref.r    r   r   r!   c                     t          j                    t          j                    d fd}	                     |           d S # t          $ r                     |           Y d S w xY w)Nargsr   r   r!   c                 *    t          dg| R d d S )Nr	   )cwdenvr   )r   r    r   s    r   _git_cmdz5Store.clone.<locals>.clone_strategy.<locals>._git_cmd   s)    UBTBBycBBBBBBr   )r   r   r   r!   )r	   	init_repo
no_git_envr   r
   r|   )r    r   r   rc   r[   rH   s   ` @r   clone_strategyz#Store.clone.<locals>.clone_strategy   s    M)T***.""CC C C C C C C4##C22222% 4 4 4$$S(3333334s   A  A0/A0r    r   r   r!   )rq   )rH   r[   rc   r\   r   s   ```  r   clonezStore.clone   sG    
	4 
	4 
	4 
	4 
	4 
	4 
	4 
	4 ~~dC~>>>r   c                P    |                      dt          j        |t                    S )Nlocal)rq   CLOCAL_REPO_VERSIONr3   )rH   r\   s     r   
make_localzStore.make_local   s%    ~~Q)41A
 
 	
r   rK   sqlite3.Connectionc                0    |                     d           d S )NzQCREATE TABLE IF NOT EXISTS configs (   path TEXT NOT NULL,   PRIMARY KEY (path));)rE   )rH   rK   s     r   rF   zStore._create_configs_table   s)    
	
 	
 	
 	
 	
r   r   c                J   | j         rd S t          j                            |          }t          j                            |          sd S |                                 5 }|                     |           |                    d|f           d d d            d S # 1 swxY w Y   d S )Nz(INSERT OR IGNORE INTO configs VALUES (?))r?   r   r   r   r<   rD   rF   rh   )rH   r   rK   s      r   mark_config_usedzStore.mark_config_used   s    = 	Fw%%w~~d## 	F\\^^ 	Lr&&r***JJAD7KKK	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	Ls   -BBBrW   )r    r6   r   r!   )r   rM   )r:   r6   r   rU   )r[   r   r\   r]   r   r   )
r[   r   rc   r   r\   r]   rd   re   r   r   )rc   r   rr   rs   r   r!   )rR   )r[   r   rc   r   r\   r]   r   r   )r\   r]   r   r   )rK   r   r   r!   )r   r   r   r!   )__name__
__module____qualname__staticmethodr   r;   rL   rX   contextmanagerr@   rD   classmethodrb   rq   r|   r   r   r   rF   r   rR   r   r   r5   r5   ;   sM       (L)?@@'. '. '. '. '.R      #'        [+ + + +Z@ @ @ @	
 	
 	
 	
? ? ? ? ?"
 
 
 


 
 
 

L 
L 
L 
L 
L 
Lr   r5   )r   r   r   )
__future__r   rX   loggingos.pathr   rZ   rA   collections.abcr   r   r   pre_commit.constants	constantsr   r   r   r   r	   pre_commit.utilr
   r   r   r   	getLoggerrP   r   r'   r3   r5   rR   r   r   <module>r      s   " " " " " "         $ $ $ $ $ $ % % % % % % $ $ $ $ $ $                                           . . . . . . 1 1 1 1 1 1 ( ( ( ( ( ( ) ) ) ) ) ) 
	<	(	(! ! ! !    pL pL pL pL pL pL pL pL pL pLr   