
    wg                     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                        e Zd ZdZdZdZd fd	Ze fd       Zd Z	e
d        Ze
dd       Zd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        _/home/mcse/projects/flask/flask-venv/lib/python3.12/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 ]4  }|st        |t        j                        s!||vrt        |      ||   }6 |S )Nr   )	r   resolve_refishr   r!   tree
isinstancer   TreeFileNotFoundError)r   r   r   commpartsr%   parts          r   _path_to_objectzGitFileSystem._path_to_object4   sz    II,,S_DHH=	c

3yy 	"D
45t#+D11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                 @   t        | t        j                        }|rdnd|r0dj                  || j                  xs dg      j                  d      n| j                  t        | j                        | j                  dn| j                  d|rddS | j                  dS )	N	directoryfiler   r   100644or   )typenamehexmodesize)
r&   r   r'   joinr8   r    stridfilemoder;   )objr   is_dirs      r   _object_to_infozGitFileSystem._object_to_infoJ   s     C-#)Kv@D$B/077<#((svv; # 4HS\\!<LA
 	
 &)XX
 	
r   c                    | j                  | j                  |      |      }t        |t        j                        r|n|gD cg c]3  }|rt
        j                  ||      nt
        j                  ||      d   5 c}S c c}w )Nr8   )r,   r   r&   r   r'   r   rB   )r   r   detailr   r   r%   r@   s          r   lszGitFileSystem.lsX   s    ##D$8$8$>D
 !+4 =D6	
   ))#t4..sD9&AB
 	
 
s   8A>c                 p    | j                  | j                  |      |      }t        j                  ||      S N)r,   r   r   rB   )r   r   r   r   r%   s        r   infozGitFileSystem.infoa   s2    ##D$8$8$>D,,T488r   c                 .    | j                  ||      d   S )N)r   r9   )rH   )r   r   r   s      r   ukeyzGitFileSystem.ukeye   s    yy3y'..r   c                 n    | j                  ||xs | j                        }t        |j                        S )N)data)r,   r   r   rL   )	r   r   r:   
block_size
autocommitcache_optionsr   r   r@   s	            r   _openzGitFileSystem._openh   s-     ""49sxx((r   )NNNrG   )TN)rbNTNN)__name__
__module____qualname____doc__root_markercachabler   classmethodr   r,   staticmethodr1   rB   rE   rH   rJ   rP   __classcell__)r   s   @r   r   r   
   s    
 KH#0    	   
 

9/ )r   r   )r   r   fsspec.specr   memoryr   r   r   r   r   <module>r]      s     	  * i)& i)r   