
    6pj,+                        S r SSKJr  SSKrSSKrSSKJr  SSKJrJ	r	J
r
  SSKJrJrJr  SSKJr  SS	KJr  SS
KJr  \" 5       rSS/rSS jr            SS jr " S S5      r " S S5      rg)u2  Repository — shim delegating to ``modelscope_hub`` for Git operations.

Preserves the legacy :class:`Repository` and :class:`DatasetRepository`
constructors (auto-clone-on-init) and methods (``push``, ``pull``,
``tag``, ``tag_and_push``, ``add_lfs_type``) used by callers that
pre-date the SDK refactor.
    )annotationsN)Optional)GitErrorInvalidParameterNotLoginException)DEFAULT_DATASET_REVISIONDEFAULT_REPOSITORY_REVISIONMASTER_MODEL_BRANCH)
get_logger   )GitCommandWrapper)get_endpoint
RepositoryDatasetRepositoryc                @    U (       a  U $ SSK Jn  UR                  5       $ )Nr   )ModelScopeConfig)modelscope.hub.apir   get_git_token)
auth_tokenr   s     U/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/modelscope/hub/repository.py_resolve_git_tokenr      s    3))++    c                    [         R                  " USS9  [         R                  " U5      (       a*   U R                  U5      nU R	                  U5      nXt:X  a  g U R                  XXBU5        g! [
         a     N f = f)zClone *url* into *repo_dir* unless it's already that working copy.

Returns ``True`` if a clone was performed, ``False`` if skipped.
Texist_okF)osmakedirslistdirget_repo_remote_urlremove_token_from_urlr   clone)git_wrapperbase_dir	repo_namerepo_dirurl	git_tokenrevisionexistings           r   _clone_if_neededr*   "   s~     KK4(	zz(	"66x@H"88BH  h38D  		s   'A/ /
A<;A<c                      \ rS rSrSr\SSSS4             SS jjrSS jrSSS jjrSS jr	\\S4       SS	 jjr
\4     SS
 jjr\4     SS jjrSrg)r   7   zCA local representation of a model Git repository on ModelScope Hub.Nc           	        Ub  Uc  SS K nUR                  " S[        SS9  UnU(       d  [        S5      eX`l        Xl        [        R                  R                  U5      U l	        [        R                  R                  U5      U l        [        U5      U l        [        U5      U l        U R                  R!                  5       (       d  ["        R%                  S5        U R'                  U5      n	[)        U R                  U R                  U R                  U R
                  U	U R                  U5      n
U
(       d  g U R                  R!                  5       (       a%  U R                  R+                  U R
                  5        U R                  R-                  U R                  U R                  5        U R                  (       a1  U R                  R/                  U R
                  U R                  5        g g )Nr   zPRepository(auth_token=...) is deprecated, use Repository(git_token=...) instead.   
stacklevel0a non-default value of revision cannot be empty.z)git lfs is not installed, please install.)warningswarnDeprecationWarningr   	_endpoint	model_dirr   pathdirnamemodel_base_dirbasenamemodel_repo_namer   r'   r   r"   is_lfs_installedloggererror_get_model_id_urlr*   git_lfs_installadd_user_infoconfig_git_token)selfr6   
clone_fromr(   r'   git_pathendpointr   r2   r&   cloneds              r   __init__Repository.__init__:   s    !i&7MM9"	
 #I"BD D "" ggooi8!ww//	:+I6,X60022LLDE$$Z0!$"2"2D4G4G"&"6"6"&..(< ,,..,,T^^<&&t':':'+';';	=>>--dnndnnM r   c                L    U R                   =(       d
    [        5       nU SU S3$ )N/.gitr5   r   )rC   model_idrF   s      r   r?   Repository._get_model_id_urlh   s%    >>3\^1XJd++r   c                L    U R                   R                  U R                  XS9  g)z/Pull *remote*/*branch* into the local checkout.)remotebranchN)r"   pullr6   )rC   rQ   rR   s      r   rS   Repository.pulll   s    dnnVKr   c                    [         R                  R                  U R                  S5      n[	        USSS9 nUR                  SU S35        SSS5        g! , (       d  f       g= f)z3Track an additional file-name pattern with Git LFS.z.gitattributesazutf-8)encoding
z% filter=lfs diff=lfs merge=lfs -text
N)r   r7   joinr6   openwrite)rC   file_name_suffixattrsfs       r   add_lfs_typeRepository.add_lfs_typep   sQ    T^^-=>%w/1GG%&&LMO 0//s   A
A#Fc           	         [         R                  " S[        SS9  [        U[        5      (       a  U(       d  [        S5      e[        U[        5      (       d  [        S5      eU R                  (       d  [        S5      eU R                  R                  U R                  U R                  5        U R                  R                  U R                  U R                  5        U R                  R                  U R                  5      nU R                  R!                  U R                  SS9  U R                  R#                  U R                  U5        U R                  R%                  U R                  U R                  UUUUS	9  g
z2Stage all changes, commit, and push to the remote.zThis function is deprecated and will be removed in future versions. Please use git command directly or use HubApi().upload_folder insteadr.   r/   z commit_message must be provided!zforce must be boolz'Must login to push, please login first.T)	all_files)r%   r'   r&   local_branchremote_branchforceN)r2   r3   r4   
isinstancestrr   boolr'   r   r"   rB   r6   rA   r9   r;   r   addcommitpush)rC   commit_messagerd   re   rf   r&   s         r   rl   Repository.pushw   s-    	- 	 .#..n"#EFF%&&"#788~~#$MNN))$..$..I&&t':':'+';';	=224>>BT^^t<?^^nn%' 	 	r   c                    U(       d  [        S5      eU(       d  [        S5      eU R                  R                  U R                  UUUS9  g)z*Create an annotated tag pointing to *ref*.zFWe use tag-based revision, therefore tag_name cannot be None or empty.z=We use annotated tag, therefore message cannot None or empty.)r%   tag_namemessagerefN)r   r"   tagr6   rC   rp   rq   rr   s       r   rs   Repository.tag   sY    
 "+, , " $; < <^^	 	 	r   c                p    U R                  XU5        U R                  R                  U R                  US9  g)z,Create *tag_name* and push it to the remote.)r%   rp   N)rs   r"   push_tagr6   rt   s       r   tag_and_pushRepository.tag_and_push   s/    
 	C(!!4>>H!Mr   )r5   r'   r"   r9   r6   r;   )r6   rh   rD   rh   r(   Optional[str]r'   rz   rE   rz   rF   rz   r   rz   )rN   rh   returnrh   )originmaster)rQ   rh   rR   rh   )r\   rh   r{   None)rm   rh   rd   rz   re   rz   rf   ri   )rp   rh   rq   rh   rr   rz   )__name__
__module____qualname____firstlineno____doc__r	   rH   r?   rS   r_   rl   r
   rs   rx   __static_attributes__ r   r   r   r   7   s    M
 ,G,0+/+/-1,N,N ,N ),N *	,N
 ),N ),N +,N\,LO ,G,G 	   (  *  	 J "5 * +>N"N!N (N Nr   c                  z    \ rS rSrSr\SSSS4             S
S jjrSS jrSS jr\S4     SS jjr	S	r
g)r      z>A local representation of a dataset (metadata) Git repository.Nc                j   Ub  Uc  SS K nUR                  " S[        SS9  UnU(       a  [        U[        5      (       d  [        S5      eUR                  S5      nU(       d  [        S5      eU(       d  [        S5      eX`l        X l        Xl	        [        R                  R                  U5      U l        [        R                  R                  U5      U l        X0l        [#        U5      U l        ['        U5      U l        [        R*                  " U R                  S	S
9  U R-                  U5      U l        g )Nr   z^DatasetRepository(auth_token=...) is deprecated, use DatasetRepository(git_token=...) instead.r.   r/   z"dataset_work_dir must be provided!rK   z%dataset_work_dir can not be root dir!r1   Tr   )r2   r3   r4   rg   rh   r   rstripr5   
dataset_idrepo_work_dirr   r7   r8   repo_base_dirr:   r$   r(   r   r'   r   r"   r   _get_repo_urlrepo_url)	rC   r   r   r(   r'   rE   rF   r   r2   s	            r   rH   DatasetRepository.__init__   s    !i&7MM@"	
 #IJ}c$B$B"#GHH%,,S1"#JKK"BD D "$*WW__];))-8 +I6,X6
D&&6**:6r   c                L    U R                   =(       d
    [        5       nU SU S3$ )Nz
/datasets/rL   rM   )rC   r   rF   s      r   r   DatasetRepository._get_repo_url   s%    >>3\^:j\66r   c           	         [        U R                  U R                  U R                  U R                  U R
                  U R                  U R                  5      nU(       a  U R                  $ S$ )zAClone the dataset repo if not already cloned, returning its path. )r*   r"   r   r$   r   r   r'   r(   )rC   rG   s     r   r!   DatasetRepository.clone   sT    !$"2"2D4F4F"&..$2D2D"&--P &,t!!33r   Fc           	        [         R                  " S[        SS9  [        U[        5      (       a  U(       d  [        S5      e[        U[        5      (       d  [        S5      eU R                  (       d  [        S5      eU R                  R                  U R                  U R                  5        U R                  R                  U R                  U R                  5         U R                  R                  U R                  5      nU R                  R!                  U5      nU R                  R'                  U R                  5        U R                  R)                  U R                  SS9  U R                  R+                  U R                  U5        U R                  R-                  U R                  U R                  UUUUS	9  g
! ["         a    U R$                  n Nf = frb   )r2   r3   r4   rg   rh   r   ri   r'   r   r"   rB   r   rA   r   r$   r   r    r   r   rS   rj   rk   rl   )rC   rm   rR   rf   
remote_urls        r   rl   DatasetRepository.push   s   
 	- 	 .#..n"#EFF%&&"#788~~#$MNN))$*<*<dnnM&&t'9'94>>J	'))==""$J))??
KJ 	d001T//4@ 2 2NC''nn  	 	  	'J	's   A G GG)	r5   r   r'   r"   r   r$   r   r   r(   )r   rh   r   rh   r(   rz   r'   rz   rE   rz   rF   rz   r   rz   )r   rh   r{   rh   )r{   rh   )rm   rh   rR   rz   rf   ri   )r   r   r   r   r   r   rH   r   r!   rl   r   r   r   r   r   r      s    H
 ,D,0+/+/-1$7 #$7 $7 )$7 *	$7
 )$7 )$7 +$7L74 &> $ $"$ $ $r   )r   rz   r{   rz   )r"   r   r#   rh   r$   rh   r%   rh   r&   rh   r'   rz   r(   rz   r{   ri   )r   
__future__r   r   r2   typingr   modelscope.hub.errorsr   r   r   modelscope.utils.constantr   r	   r
   modelscope.utils.loggerr   gitr   utils.utilsr   r=   __all__r   r*   r   r   r   r   r   <module>r      s    # 	   O O< < / " %	,
-, #/29< -  - 26*zN zNzX Xr   