
    i                     B    d dl Z d dlZd dlmZ ddlmZ  G d de      Zy)    N)AbstractFileSystem   )
MemoryFilec                   x     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)
     Tc                     t        |   di | t        j                  |xs |xs t	        j
                               | _        |xs d| _        y)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        IC:\Projects\mas-dev\.venv\Lib\site-packages\fsspec/implementations/git.pyr   zGitFileSystem.__init__   sB    ( 	"6"%%b&?D&?BIIK@	?(    c                     t         |   |      j                  d      }d|v r|j                  dd      d   }d|v r|j                  dd      d   }|j                  d      S )N/:r   @)r   _strip_protocollstripsplit)clsr   r   s     r   r   zGitFileSystem._strip_protocol+   sd    w&t,33C8$;::c1%a(D$;::c1%a(D{{3r   c                     | j                   j                  |xs | j                        \  }}|j                  d      }|j                  }|D ]%  }|st        |t        j                        s!||   }' |S )Nr   )r   resolve_refishr   r!   tree
isinstancer   Tree)r   r   r   commpartsr%   parts          r   _path_to_objectzGitFileSystem._path_to_object4   sb    II,,S_DHH=	c

3yyD
45Dz  r   c                     | j                  d      r| dd  } i }d| v r| j                  dd      \  |d<   } d| v r| j                  dd      \  |d<   } |S )Nzgit://   r   r   r   r   r   )
startswithr!   )r   outs     r   _get_kwargs_from_urlsz#GitFileSystem._get_kwargs_from_urls=   sc    ??8$8D$; $

3 2CK$;#zz#q1CJ
r   c           	         | j                  |      }| j                  ||      }t        |t        j                        rg }|D ]  }t        |t        j                        rX|j                  ddj                  ||j                  g      j                  d      |j                  |j                  ddd       u|j                  ddj                  ||j                  g      j                  d      |j                  |j                  d|j                  d        n5|}d|j                  |j                  |j                  d|j                  dg}|r|S |D cg c]  }|d   	 c}S c c}w )N	directoryr   or   )typenamehexmodesizefiler5   )r   r+   r&   r   r'   appendjoinr5   r    r6   filemoder8   )	r   r   detailr   r   r%   r/   objr3   s	            r   lszGitFileSystem.lsH   sH   ##D)##D#.dFKK(Cc6;;/JJ$/$'HHdCHH-=$>$E$Ec$J#&77'*||A&6$% JJ$*$'HHdCHH-=$>$E$Ec$J#&77'*||A&6$'HH , C #HH77"||A.HHC J#&'3a&	3'''s   E'c                 .    | j                  ||      d   S )N)r   r6   )info)r   r   r   s      r   ukeyzGitFileSystem.ukeyq   s    yy3y'..r   c                 n    | j                  ||xs | j                        }t        |j                        S )N)data)r+   r   r   rD   )	r   r   r7   
block_size
autocommitcache_optionsr   r   r>   s	            r   _openzGitFileSystem._opent   s-     ""49sxx((r   )NNN)TN)N)rbNTNN)__name__
__module____qualname____doc__root_markercachabler   classmethodr   r+   staticmethodr0   r?   rB   rH   __classcell__)r   s   @r   r   r   
   sg    
 KH#0      '(R/ )r   r   )r   r   fsspec.specr   memoryr   r   r   r   r   <module>rU      s     	  * u)& u)r   