
    Ng                     V    d dl Z d dlmZmZmZ d dlmZ d dlmZ  G d de          Z	dS )    N)CallableIteratorOptional)Document)
BaseLoaderc                       e Zd ZdZ	 	 	 ddedee         dee         deeegef                  fdZd	e	e
         fd
ZdS )	GitLoadera  Load `Git` repository files.

    The Repository can be local on disk available at `repo_path`,
    or remote at `clone_url` that will be cloned to `repo_path`.
    Currently, supports only text files.

    Each document represents one file in the repository. The `path` points to
    the local Git repository, and the `branch` specifies the branch to load
    files from. By default, it loads from the `main` branch.
    Nmain	repo_path	clone_urlbranchfile_filterc                 >    || _         || _        || _        || _        dS )a  

        Args:
            repo_path: The path to the Git repository.
            clone_url: Optional. The URL to clone the repository from.
            branch: Optional. The branch to load files from. Defaults to `main`.
            file_filter: Optional. A function that takes a file path and returns
              a boolean indicating whether to load the file. Defaults to None.
        N)r   r   r   r   )selfr   r   r   r   s        d/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/document_loaders/git.py__init__zGitLoader.__init__   s'      #"&    returnc              #   4  K   	 ddl m}m} n"# t          $ r}t          d          |d }~ww xY wt          j                            | j                  s| j        t          d| j         d          | j        rt          j        
                    t          j                            | j        d                    r: || j                  }|j        j        j        | j        k    rt          d          n |                    | j        | j                  }|j                             | j                   n/ || j                  }|j                             | j                   |                                                                D ]}t)          ||          st          j                            | j        |j                  }|                    |g          }t-          |          rd| j        r|                     |          st          j                            || j                  }	 t3          |d          5 }	|	                                }
t          j                            |j                  d	         }	 |
                    d
          }n# t<          $ r Y d d d            %w xY w|||j        |d}t?          ||          V  d d d            n# 1 swxY w Y   a# t@          $ r }tC          d| d|            Y d }~d }~ww xY wd S )Nr   )BlobRepozTCould not import git python package. Please install it with `pip install GitPython`.zPath z does not existz.gitz6A different repository is already cloned at this path.rb   zutf-8)source	file_path	file_name	file_type)page_contentmetadatazError reading file z: )"gitr   r   ImportErrorospathexistsr   r   
ValueErrorisdirjoinremotesoriginurl
clone_fromcheckoutr   treetraverse
isinstanceignoredlenr   relpathopenreadsplitextnamedecodeUnicodeDecodeErrorr   	Exceptionprint)r   r   r   exrepoitemr   ignored_filesrel_file_pathfcontentr   text_contentr   es                  r   	lazy_loadzGitLoader.lazy_load*   s     	&&&&&&&&& 	 	 	B  	 w~~dn-- 	+$.2HDT^DDDEEE^ 	+ w}}RW\\$.&AABB 	GtDN++ <&*dn<<$P   =
 t~t~FFHdk****4''DHdk***IIKK((** "	> "	>DdD)) T^TY??I LL)55M=!!   (8(8(C(C GOOIt~FFM>)T** QaffhhG " 0 0 ; ;A >I!'.~~g'>'>- ! ! ! Q Q Q Q Q Q Q! #0%2%)Y%.	   H #xPPPPPP!Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q"  > > ><I<<<<========>C"	> "	>sv    
,',1K+?KJK
J0!K"K+/J00"KK+K"	"K+%K"	&K++
L5LL)Nr
   N)__name__
__module____qualname____doc__strr   r   boolr   r   r   rD    r   r   r	   r	   	   s        	 	 $( &7;' '' C=' 	'
 hud{34' ' ' '*?>8H- ?> ?> ?> ?> ?> ?>r   r	   )
r"   typingr   r   r   langchain_core.documentsr   )langchain_community.document_loaders.baser   r	   rK   r   r   <module>rO      s    				 / / / / / / / / / / - - - - - - @ @ @ @ @ @`> `> `> `> `>
 `> `> `> `> `>r   