
    ih                     N    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	y)    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y)	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	repo_path	clone_urlbranchfile_filterc                 <    || _         || _        || _        || _        y)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        f/var/www/html/dev/engine/venv/lib/python3.12/site-packages/langchain_community/document_loaders/git.py__init__zGitLoader.__init__   s!      #"&    returnc              #   l  K   	 ddl m}m} t        j
                  j                  | j                        s%| j                  t        d| j                   d      | j                  rt        j
                  j                  t        j
                  j                  | j                  d            rJ || j                        }|j                  j                  j                  | j                  k7  r1t        d      |j                  | j                  | j                        }|j                   j!                  | j"                         n7 || j                        }|j                   j!                  | j"                         |j%                         j'                         D ].  }t)        ||      st        j
                  j                  | j                  |j
                        }|j+                  |g      }t-        |      rc| j.                  r| j/                  |      st        j
                  j1                  || j                        }	 t3        |d      5 }	|	j5                         }
t        j
                  j7                  |j8                        d	   }	 |
j;                  d
      }|||j8                  |d}t?        ||       d d d        1 y # t        $ r}t        d      |d }~ww xY w# t<        $ r Y d d d        dw xY w# 1 sw Y   BxY w# t@        $ r}tC        d| d|        Y d }~d }~ww xY ww)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    	& ww~~dnn-$..2HuT^^$4ODEE^^ ww}}RWW\\$..&ABDNN+ <<&&**dnn<$P  t~~t~~FHHdkk*'DHHdkk*IIK((* "	>DdD)T^^TYY?I LL)5M=! (8(8(CGGOOIt~~FM>)T* QaffhG " 0 0 ;A >I!'.~~g'>
 #0%2%)YY%.	 H #xPP!Q!"	>5  	B 	b . ! Q Q!Q Q"  >+I;b<==>s   L4K H7L4L=L K( L ?LL4	K%K  K%%L4(	K=1L 2L:L4<K==L  L		L	L1L,&L4,L11L4)NmainN)__name__
__module____qualname____doc__strr   r   boolr   r   r   rC    r   r   r	   r	   	   sf    	 $( &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   