
    OOId                     J    d dl Z d dlZd dlmZ ddlmZ  G d de          ZdS )    N)AbstractFileSystem   )
MemoryFilec                        e Zd ZdZdZdZd fd	Ze fd            Zd Z	e
d             Zdd	Zdd
Z	 	 	 	 	 ddZ xZS )GitFileSystemz\Browse the files of a local git repo at any hash/tag/branch

    (experimental backend)
     TNc                      t                      j        di | t          j        |p|pt	          j                              | _        |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__s        :lib/python3.11/site-packages/fsspec/implementations/git.pyr   zGitFileSystem.__init__   sS    ( 	""6"""%b&?D&?BIKK@@	?(    c                    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   s     r   r   zGitFileSystem._strip_protocol+   s|    ww&&t,,33C88$;;::c1%%a(D$;;::c1%%a(D{{3r   c                     | j                             |p| j                  \  }}|                    d          }|j        }|D ]&}|r"t          |t          j                  r||         }'|S )Nr   )r   resolve_refishr   r!   tree
isinstancer   Tree)r   r   r   commpartsr%   parts          r   _path_to_objectzGitFileSystem._path_to_object4   sp    I,,S_DH==	c

3y 	" 	"D "
455 "Dzr   c                     |                      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   outs     r   _get_kwargs_from_urlsz#GitFileSystem._get_kwargs_from_urls=   sw    ??8$$ 	8D$;; $

3 2 2CK$;;#zz#q11CJ
r   c           	         |                      |          }|                     ||          }t          |t          j                  rg }|D ]}t          |t          j                  rV|                    dd                    ||j        g                              d          |j	        d|j
        z  dd           r|                    dd                    ||j        g                              d          |j	        d|j
        z  |j        d           n"|}d|j        |j	        d|j
        z  |j        dg}|r|S d |D             S )N	directoryr   z%or   )typenamehexmodesizefilec                     g | ]
}|d          S )r4   r   ).0os     r   
<listcomp>z$GitFileSystem.ls.<locals>.<listcomp>o   s    '''a&	'''r   )r   r+   r&   r   r'   appendjoinr4   r    r5   filemoder7   )r   r   detailr   r   r%   r/   objs           r   lszGitFileSystem.lsH   s   ##D))##D#..dFK(( !	C  c6;// JJ$/$'HHdCH-=$>$>$E$Ec$J$J#&7$(3<$7$%     JJ$*$'HHdCH-=$>$>$E$Ec$J$J#&7$(3<$7$'H    , C #H7 3</H C  	J''3''''r   c                 <    |                      ||          d         S )N)r   r5   )info)r   r   r   s      r   ukeyzGitFileSystem.ukeyq   s    yy3y''..r   rbc                 f    |                      ||p| j                  }t          |j                  S )N)data)r+   r   r   rH   )	r   r   r6   
block_size
autocommitcache_optionsr   r   rA   s	            r   _openzGitFileSystem._opent   s2     ""499sx((((r   )NNN)TN)N)rF   NTNN)__name__
__module____qualname____doc__root_markercachabler   classmethodr   r+   staticmethodr0   rB   rE   rL   __classcell__)r   s   @r   r   r   
   s         
 KH# # # # # #0         [      \'( '( '( '(R/ / / / ) ) ) ) ) ) ) )r   r   )r   r   fsspec.specr   memoryr   r   r   r   r   <module>rX      sz    				  * * * * * *      u) u) u) u) u)& u) u) u) u) u)r   