o
    Wi                     @  s   d dl m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 dddZdddZdddZdS )     )annotationsN)Any)output)InvalidConfigError)InvalidManifestError)load_config)load_manifest)LOCAL)META)Store)rmtreestorer   	all_reposdict[tuple[str, str], str]unused_reposset[tuple[str, str]]repodict[str, Any]returnNonec           
      C  s  |d t krd S |d tkr*|d D ]}|d}|| |d |tjf qd S |d |d f}||}|d u r=d S zttj	
|tj}W n
 tyS   Y d S w || dd |D }	|d D ]$}|d |	vrmqd|d|	|d  d }|| |d ||d f qdd S )Nr   hooksadditional_dependenciesrevc                 S  s   i | ]}|d  |qS )id ).0hookr   r   J/home/ubuntu/.local/lib/python3.10/site-packages/pre_commit/commands/gc.py
<dictcomp>.   s    z$_mark_used_repos.<locals>.<dictcomp>r   )r
   r	   getdiscarddb_repo_nameCLOCAL_REPO_VERSIONr   ospathjoinMANIFEST_FILEr   )
r   r   r   r   r   depskeyr%   manifestby_idr   r   r   _mark_used_repos   s@   


r,   intc                 C  sJ  |    |  }| | |d }dd |D }t|}|d }dd |D }g }|D ]%}zt|}	W n tyI   || Y q3w |	d D ]	}
t	| |||
 qNq3dd |D }|
d	| |
d
t| |D ]}t||  qpt|W  d    W  d    S 1 sw   Y  W d    d S 1 sw   Y  d S )Nz!SELECT repo, ref, path FROM reposc                 S  s   i | ]
\}}}||f|qS r   r   )r   r   refr%   r   r   r   r   B   s    z_gc.<locals>.<dictcomp>zSELECT path FROM configsc                 S  s   g | ]\}|qS r   r   r   r%   r   r   r   
<listcomp>F       z_gc.<locals>.<listcomp>reposc                 S  s   g | ]}|fqS r   r   r/   r   r   r   r0   S   r1   z"DELETE FROM configs WHERE path = ?z,DELETE FROM repos WHERE repo = ? and ref = ?)exclusive_lockconnect_create_configs_tableexecutefetchallsetr   r   appendr,   executemanysortedr   len)r   dbr2   r   r   configs_rowsconfigsdead_configsconfig_pathconfigr   pathskr   r   r   _gc=   s8   

RrE   c                 C  s   t t|  d dS )Nz repo(s) removed.r   )r   
write_linerE   )r   r   r   r   gc`   s   rG   )
r   r   r   r   r   r   r   r   r   r   )r   r   r   r-   )
__future__r   os.pathr$   typingr   pre_commit.constants	constantsr"   
pre_commitr   pre_commit.clientlibr   r   r   r   r	   r
   pre_commit.storer   pre_commit.utilr   r,   rE   rG   r   r   r   r   <module>   s     

+#