
    çg                     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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)
     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        V/var/www/html/ai-engine/env/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 ]9}|r5t          |t          j                  r||vrt          |          ||         }:|S )Nr   )	r   resolve_refishr   r!   tree
isinstancer   TreeFileNotFoundError)r   r   r   commpartsr%   parts          r   _path_to_objectzGitFileSystem._path_to_object4   s    I,,S_DH==	c

3y 	" 	"D "
455 "t##+D111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                  }|rdnd|r1d                    || j        pdg                              d          n| j        t          | j                  | j        dn| j        d|rdn| 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--#)5KKv@DR$B/0077<<<#(sv;; # 4HHS\:M:M-AASX
 
 	
r   c                     |                      |                               |          }fdt          |t          j                  r|n|gD             S )Nc                     g | ]@}rt                               |          n t                               |          d          AS )r8   )r   rB   ).0r@   detailr   s     r   
<listcomp>z$GitFileSystem.ls.<locals>.<listcomp>Z   s^     
 
 
  BM))#t444..sD99&A
 
 
r   )r,   r   r&   r   r'   )r   r   rF   r   r   r%   s    ``   r   lszGitFileSystem.lsX   sp    ##D$8$8$>$>DD
 
 
 
 
 !+4 = =ID6	
 
 
 	
r   c                     |                      |                     |          |          }t                              ||          S N)r,   r   r   rB   )r   r   r   r   r%   s        r   infozGitFileSystem.infoa   s;    ##D$8$8$>$>DD,,T4888r   c                 <    |                      ||          d         S )N)r   r9   )rK   )r   r   r   s      r   ukeyzGitFileSystem.ukeye   s    yy3y''..r   rbc                 f    |                      ||p| j                  }t          |j                  S )N)data)r,   r   r   rP   )	r   r   r:   
block_size
autocommitcache_optionsr   r   r@   s	            r   _openzGitFileSystem._openh   s2     ""499sx((((r   )NNNrJ   )TN)rN   NTNN)__name__
__module____qualname____doc__root_markercachabler   classmethodr   r,   staticmethodr1   rB   rH   rK   rM   rT   __classcell__)r   s   @r   r   r   
   s#        
 KH# # # # # #0         [ 	 	 	   \ 
 
 
 \

 
 
 
9 9 9 9/ / / / ) ) ) ) ) ) ) )r   r   )r   r   fsspec.specr   memoryr   r   r   r   r   <module>r`      sz    				  * * * * * *      i) i) i) i) i)& i) i) i) i) i)r   