o
    _Zh                     @   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
        ZmasterN )super__init__pygit2Z
Repositoryosgetcwdreporef)selfpathfor   kwargs	__class__r   I/var/www/auris/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   Zresolve_refishr   r   tree
isinstancer
   TreeFileNotFoundError)r   r   r   Zcommpartsr   partr   r   r   _path_to_object4   s   
zGitFileSystem._path_to_objectc                 C   sV   |  dr| dd  } i }d| v r| dd\|d< } d| v r)| dd\|d< } |S )Nzgit://   r   r   r   r   r   )
startswithr   )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   Z100644or   )typenamehexmodesize)
r   r
   r   joinr,   r   stridfilemoder/   )objr   is_dirr   r   r   _object_to_infoJ   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 )r,   )r   r6   ).0r4   detailr   r   r   
<listcomp>Z   s    z$GitFileSystem.ls.<locals>.<listcomp>)r#   r   r   r
   r   )r   r   r9   r   r   r   r   r8   r   lsX   s   zGitFileSystem.lsc                 K   s   |  | ||}t||S N)r#   r   r   r6   )r   r   r   r   r   r   r   r   infoa   s   zGitFileSystem.infoc                 C   s   | j ||dd S )N)r   r-   )r=   )r   r   r   r   r   r   ukeye   s   zGitFileSystem.ukeyrbc           	      K   s   |  ||p| j}t|jdS )N)data)r#   r   r   r@   )	r   r   r.   
block_sizeZ
autocommitZcache_optionsr   r   r4   r   r   r   _openh   s   
zGitFileSystem._open)NNNr<   )TN)r?   NTNN)__name__
__module____qualname____doc__Zroot_markerZcachabler	   classmethodr   r#   staticmethodr'   r6   r;   r=   r>   rB   __classcell__r   r   r   r   r   
   s*    



	
r   )r   r
   Zfsspec.specr   Zmemoryr   r   r   r   r   r   <module>   s
    