o
    ÖËh“  ã                   @   s<   d dl Z d dlZd dlmZ ddlmZ G dd„ deƒZdS )é    N)ÚAbstractFileSystemé   )Ú
MemoryFilec                       sŽ   e Zd ZdZdZdZd‡ fdd„	Ze‡ fdd„ƒZd	d
„ Z	e
dd„ ƒZe
ddd„ƒZddd„Zddd„Zddd„Z					ddd„Z‡  ZS )ÚGitFileSystemz\Browse the files of a local git repo at any hash/tag/branch

    (experimental backend)
    Ú TNc                    s8   t ƒ jdi |¤Ž t |p|pt ¡ ¡| _|pd| _dS )aM  

        Parameters
        ----------
        path: str (optional)
            Local location of the repo (uses current directory if not given).
            May be deprecated in favour of ``fo``. When used with a higher
            level function such as fsspec.open(), may be of the form
            "git://[path-to-repo[:]][ref@]path/to/file" (but the actual
            file path should not contain "@" or ":").
        fo: str (optional)
            Same as ``path``, but passed as part of a chained URL. This one
            takes precedence if both are given.
        ref: str (optional)
            Reference to work with, could be a hash, tag or branch name. Defaults
            to current working tree. Note that ``ls`` and ``open`` also take hash,
            so this becomes the default for those operations
        kwargs
        ÚmasterN© )ÚsuperÚ__init__Úpygit2Ú
RepositoryÚosÚgetcwdÚrepoÚref)ÚselfÚpathÚfor   Úkwargs©Ú	__class__r   úU/var/www/html/scripts/venv/lib/python3.10/site-packages/fsspec/implementations/git.pyr
      s   zGitFileSystem.__init__c                    sL   t ƒ  |¡ d¡}d|v r| dd¡d }d|v r!| dd¡d }| d¡S )Nú/ú:r   ú@)r	   Ú_strip_protocolÚlstripÚsplit)Úclsr   r   r   r   r   +   s   
zGitFileSystem._strip_protocolc                 C   s\   | j  |p| j¡\}}| d¡}|j}|D ]}|r+t|tjƒr+||vr't|ƒ‚|| }q|S )Nr   )	r   Úresolve_refishr   r   ÚtreeÚ
isinstancer   ÚTreeÚFileNotFoundError)r   r   r   ÚcommÚpartsr    Úpartr   r   r   Ú_path_to_object4   s   
€zGitFileSystem._path_to_objectc                 C   sJ   |   d¡} i }d| v r|  dd¡\|d< } d| v r#|  dd¡\|d< } |S )Nzgit://r   r   r   r   r   )Úremoveprefixr   )r   Úoutr   r   r   Ú_get_kwargs_from_urls?   s   
z#GitFileSystem._get_kwargs_from_urlsc                 C   sl   t | tjƒ}|r
dnd|rd || jpdg¡ d¡n| jt| jƒ| jd u r'dn| jd›|r1ddœS | j	dœS )	NÚ	directoryÚfiler   r   Ú100644Úor   )ÚtypeÚnameÚhexÚmodeÚsize)
r!   r   r"   Újoinr0   r   ÚstrÚidÚfilemoder3   )Úobjr   Úis_dirr   r   r   Ú_object_to_infoI   s   
"ùùzGitFileSystem._object_to_infoc                    s<   |   |  ˆ¡|¡}‡ ‡fdd„t|tjƒr|D ƒS |gD ƒS )Nc                    s,   g | ]}ˆ rt  |ˆ¡nt  |ˆ¡d  ‘qS )r0   )r   r:   )Ú.0r8   ©Údetailr   r   r   Ú
<listcomp>Y   s    þÿýz$GitFileSystem.ls.<locals>.<listcomp>)r'   r   r!   r   r"   )r   r   r=   r   r   r    r   r<   r   ÚlsW   s   üüzGitFileSystem.lsc                 K   s   |   |  |¡|¡}t ||¡S ©N)r'   r   r   r:   )r   r   r   r   r    r   r   r   Úinfo`   s   zGitFileSystem.infoc                 C   s   | j ||dd S )N)r   r1   )rA   )r   r   r   r   r   r   Úukeyd   s   zGitFileSystem.ukeyÚrbc           	      K   s   |   ||p| j¡}t|jdS )N)Údata)r'   r   r   rD   )	r   r   r2   Ú
block_sizeÚ
autocommitÚcache_optionsr   r   r8   r   r   r   Ú_openg   s   
zGitFileSystem._open)NNNr@   )TN)rC   NTNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úroot_markerÚcachabler
   Úclassmethodr   r'   Ústaticmethodr*   r:   r?   rA   rB   rH   Ú__classcell__r   r   r   r   r   
   s*    
	

	
ùr   )r   r   Úfsspec.specr   Úmemoryr   r   r   r   r   r   Ú<module>   s
    