
    	^c                       d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZ	ddl
mZ ddlmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZ  ddl!m"Z"m#Z#m$Z$m%Z% da&ej'        Z'ej(        Z(ej)        Z)ej*        Z*d Z+d Z, G d	 d
ej-                  Z.d Z/d Z0d Z1d Z2ddddZ3d Z4ddZ5d Z6 G d d          Z7 G d de7          Z8 G d de7          Z9 G d de7          Z:e8e9e:dZ;dS )    N   )_)binhexshort)cmdutilencodingerrorexchange
logcmdutilmatchmergepathutilphasespycompatscmutilsubrepoutilutilvfs)dateutilhashutilprocutilurlutilc                     t          j        t          j        |                     }t          j        |          }|j        s+t          j        t          j        |j                            } | S )zU
    get a path or url and if it is a path expand it and return an absolute path
    )	r   urllocalpathr   
expandpathurlschemenormpathabspathpath)r!   expandedpathus      3/usr/lib/python3/dist-packages/mercurial/subrepo.py_expandedabspathr%   7   sW     '(=(=>>LL!!A8 3}T\!&1122K    c                     t          t          j        t          |                                                               dd         S )zEget a unique filename for the store hash cache of a remote repositoryr      )r   r   sha1r%   digest)
remotepaths    r$   _getstorehashcachenamer,   B   s8    x}-j99::AACCDDQrTJJr&   c                       e Zd ZdZd ZdS )SubrepoAbortzEException class used to avoid handling a subrepo error more than oncec                     |                     dd           | _        |                     dd           | _        t          j        j        | g|R i | d S )Nsubrepocause)popr0   r1   r
   Abort__init__)selfargskws      r$   r4   zSubrepoAbort.__init__J   sU    vvi..VVGT**
T/D///B/////r&   N)__name__
__module____qualname____doc__r4    r&   r$   r.   r.   G   s)        OO0 0 0 0 0r&   r.   c                       fd}|S )Nc                    	  | g|R i |}n{# t           $ r}|d }~wt          j        $ rZ}t          |           }|j        dz   t          d          |z  z   }t          ||j        |t          j                              d }~ww xY w|S )N    s   (in subrepository "%s"))hintr0   r1   )	r.   r
   r3   
subrelpathmessager   r@   sysexc_info)r5   r6   kargsresexr0   errormsgfuncs          r$   decoratedmethodz-annotatesubrepoerror.<locals>.decoratedmethodQ   s    	$t,d,,,e,,CC 	 	 	H{ 	 	 	 &&G
T!A&@$A$AG$KK  rws|~~   	 
s    
BBABBr<   )rI   rJ   s   ` r$   annotatesubrepoerrorrK   P   s$        " r&   c                     |r#t          d          t          |          ||fz  }n"t          d          t          |          ||fz  }|                     |d          S )Ns    subrepository sources for %s differ
you can use (l)ocal source (%s) or (r)emote source (%s).
what do you want to do?$$ &Local $$ &Remotes    subrepository sources for %s differ (in checked out version)
you can use (l)ocal source (%s) or (r)emote source (%s).
what do you want to do?$$ &Local $$ &Remoter   )r   rA   promptchoice)uisubdirtylocalremotemsgs         r$   _updatepromptrT   e   sz     -$
 

 __eV,- $
 
 __eV,- ??3"""r&   c                    |                                 D ]\  }}}t          |          D ]"\  }}|                                |k    r||=  n#|                    |                                          dk    rd|D ]{}|                                dk    ra|                     t          d          |                    |          z             |                    |                    ||                     |d S )Ns   .hg   hgrcs5   warning: removing potentially hostile 'hgrc' in '%s'
)	walk	enumeratelowerbasenamewarnr   joinunlinkreljoin)	rN   r   ignoredirnamedirsnamesidfs	            r$   	_sanitizerf   x   s    #

 4 4udOO 	 	DAqwwyyF""G # <<  &&((F22 		4 		4AwwyyG##%  hhw''	(   

3;;w22333		44 4r&   c                 p   |                     d          sd|v st          j        |          |k    r$t          j        t          d          |z             t          j        | j                  |           | j	        
                    |          r$t          j        t          d          |z            d S )N   ~   $+   subrepo path contains illegal component: %ss$   subrepo '%s' traverses symbolic link)
startswithr   r   r
   r3   r   r   pathauditorrootwvfsislink)repor!   s     r$   _auditsubrepopathrq      s    t 
0E0E0M0Mk<==D
 
 	
 $H##D)))y Mk!CDDtKLLLM Mr&   TF)   hg   git   svnc                    |                      ddd          s0t          j        t          d          t          d                    t                              |d          }|                      dd|z  |          s3t          j        t          d	          |z  t          d                    |t          vr$t          j        t          d
          |z            d S )N   subreposs   allowedTs   subrepos not enableds)   see 'hg help config.subrepos' for detailsr@   Fs
   %s:alloweds   %s subrepos not alloweds   unknown subrepo type %s)
configboolr
   r3   r   SUBREPO_ALLOWED_DEFAULTSgettypes)rN   kinddefaults      r$   
_checktyper~      s     ==j$77 
k%&&?@@
 
 
 	

 '**477G==md&:GDD 
k())D0?@@
 
 
 	

 5k!677$>??? r&   c                 B   ddl m} |a|                                 }t          ||           | j        |         }t          |j        |d                    |r$|d         |                     |          |d         f}t          |d                  | ||dd         |          S )z>return instance of the right subrepo class for subrepo in pathr   hg   r   N)	 r   rp   rq   substater~   rN   subrevr{   )ctxr!   	allowwdirallowcreatehrp   states          r$   r0   r0      s     	
B88::DdD!!!LEtwa!!! 7q3::d++U1X6q?3eBQBi===r&   c                    ddl m} |a|                                 }t          ||           | j        |         }t          |j        |d                    d}|d         dk    rd}t          |d                  |||d         |fd          S )	z=return an empty subrepo in pctx for the extant subrepo in ctxr   r   r   r&   rr   s(   0000000000000000000000000000000000000000r   T)r   r   rp   rq   r   r~   rN   r{   )r   r!   pctxr   rp   r   r   s          r$   nullsubrepor      s     	
B88::DdD!!!LEtwa!!!FQx5q?4a&'94@@@r&   c                      e Zd Zd Zd Zd Zd(dZd(dZd)dZd	 Z	d
 Z
d Zd Zd Zd*dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd+dZd Zd,dZd Zd  Zd! Z d" Z!d# Z"d$ Z#d*d%Z$e%d&             Z&e%d'             Z'dS )-abstractsubrepoc                 ^    |                                 j        | _        || _        || _        dS )zInitialize abstractsubrepo part

        ``ctx`` is the context referring this subrepository in the
        parent repository.

        ``path`` is the path to this subrepository as seen from
        innermost repository.
        N)rp   rN   _ctx_path)r5   r   r!   s      r$   r4   zabstractsubrepo.__init__   s'     ((**-	


r&   c                     dS )zAdd the hgwebdir entries for this subrepo, and any of its subrepos.

        ``serverpath`` is the path component of the URL for this repo.

        ``webconf`` is the dictionary of hgwebdir entries.
        Nr<   r5   
serverpathwebconfs      r$   addwebdirpathzabstractsubrepo.addwebdirpath   s	     	r&   c                     dS )z
        returns true if the repository has not changed since it was last
        cloned from or pushed to a given repository.
        Fr<   r5   r!   s     r$   
storecleanzabstractsubrepo.storeclean   s	    
 ur&   Fc                     t           )a  returns true if the dirstate of the subrepo is dirty or does not
        match current stored state. If ignoreupdate is true, only check
        whether the subrepo has uncommitted changes in its dirstate.  If missing
        is true, check for deleted files.
        NotImplementedErrorr5   ignoreupdatemissings      r$   rP   zabstractsubrepo.dirty   s
     "!r&   c                 r    |                      ||          rt          d          t          |           z  S dS )zreturn reason string if it is ``dirty()``

        Returned string should have enough information for the message
        of exception.

        This returns None, otherwise.
        r   r   s)   uncommitted changes in subrepository "%s"N)rP   r   rA   r   s      r$   dirtyreasonzabstractsubrepo.dirtyreason  sM     ::<:AA 	ABBZF F  	 	r&   Nc                 d    |                      |d          }|rt          j        ||          dS )z+raise Abort if subrepository is ``dirty()``Tr   rw   N)r   r
   r3   )r5   r   r@   r   s       r$   bailifchangedzabstractsubrepo.bailifchanged  sA    &&L$&OO 	6+k5555	6 	6r&   c                     t           )zpcurrent working directory base state, disregarding .hgsubstate
        state and working directory modificationsr   r5   s    r$   	basestatezabstractsubrepo.basestate  s
     "!r&   c                     dS )z7check if path is a subrepository within this repositoryFr<   r   s     r$   checknestedzabstractsubrepo.checknested  s    ur&   c                     t           )zcommit the current changes to the subrepo with the given
        log message. Use given user and date if possible. Return the
        new state of the subrepo.
        r   )r5   textuserdates       r$   commitzabstractsubrepo.commit!  
    
 "!r&   c                     t           j        S )z6returns phase of specified state in the subrepository.)r   publicr5   r   s     r$   phasezabstractsubrepo.phase(  s
    }r&   c                     t           )zTremove the subrepo

        (should verify the dirstate is not dirty first)
        r   r   s    r$   removezabstractsubrepo.remove,  r   r&   c                     t           )zTrun whatever commands are needed to put the subrepo into
        this state
        r   )r5   r   	overwrites      r$   rz   zabstractsubrepo.get3  s
     "!r&   c                     t           )z/merge currently-saved state with the new state.r   r   s     r$   r   zabstractsubrepo.merge9      !!r&   c                     t           )zhperform whatever action is analogous to 'hg push'

        This may be a no-op on some systems.
        r   r5   optss     r$   pushzabstractsubrepo.push=  r   r&   c                     g S Nr<   r5   rN   r   prefixuipathfnexplicitonlyr   s          r$   addzabstractsubrepo.addD  s    	r&   c                 ^    | j                             d|t          d          fz             dS )Ns   %s: %ss   addremove is not supportedr   rN   r[   r   )r5   matcherr   r   r   s        r$   	addremovezabstractsubrepo.addremoveG  s.    Y&!,I*J*J!KKLLLqr&   c                     dS Nr   r<   )r5   r   fm
fntemplater   r   s         r$   catzabstractsubrepo.catK      qr&   c           	      6    t          j        g g g g g g g           S r   )r   status)r5   rev2r   s      r$   r   zabstractsubrepo.statusN  s    ~b"b"b"b999r&   c                     d S r   r<   )r5   rN   diffoptsnode2r   r   r   s          r$   diffzabstractsubrepo.diffQ  s    r&   c                     dS r   r<   )r5   rN   destr   s       r$   outgoingzabstractsubrepo.outgoingT  r   r&   c                     dS r   r<   )r5   rN   sourcer   s       r$   incomingzabstractsubrepo.incomingW  r   r&   c                     t           )zreturn filename iteratorr   r   s    r$   fileszabstractsubrepo.filesZ  r   r&   c                     t           )z9return file data, optionally passed through repo decodersr   r5   namedecodes      r$   filedatazabstractsubrepo.filedata^  r   r&   c                     dS )zreturn file flagsr&   r<   )r5   r   s     r$   	fileflagszabstractsubrepo.fileflagsb  s    sr&   c                 ,    t          j        |          S )z,Resolve the fileset expression for this repobadfn)matchmodnever)r5   cwdexprr   s       r$   matchfilesetzabstractsubrepo.matchfilesetf  s    ~E****r&   c                     dS )z)handle the files command for this subrepor   r<   )r5   rN   mr   r   fmtsubreposs          r$   
printfileszabstractsubrepo.printfilesj  s    qr&   Tc           
      J   !fd|                                  D             }n|                                  }t          |          }t          |           }| j                            t          d          |z  t          d          |          }|                    d           |D ]f}	|                     |	          }
d|
v rdpd}d	|
v }|                    ||	z   ||| 	                    |	|                     |
                                 g|                                 |S )
Nc                 *    g | ]} |          |S r<   r<   .0re   r   s     r$   
<listcomp>z+abstractsubrepo.archive.<locals>.<listcomp>p  s&    9991a9Q999r&      archiving (%s)   files)unittotalr      xi  i     l)r   lenrA   rN   makeprogressr   updater   addfiler   	incrementcomplete)r5   archiverr   r   r   r   r   relpathprogressr   flagsmodesymlinks      `         r$   archivezabstractsubrepo.archiven  s9   9999

999EEJJLLEE

T""7''  7*8E ( 
 
 	 	! 	!DNN4((E5=*U3eDemGtWdmmD&.I.I       r&   c                     dS )zv
        walk recursively through the directory tree, finding all files
        matched by the match function
        Nr<   )r5   r   s     r$   rW   zabstractsubrepo.walk        r&   c                 
    g g fS r   r<   r5   r   r   r   dryruninteractives         r$   forgetzabstractsubrepo.forget  s    Bxr&   c	                 Z    |                     t          d          | j        z             dS )zremove the matched files from the subrepository and the filesystem,
        possibly by force and/or after the file has been removed from the
        filesystem.  Return 0 on success, 1 on any warning.
        s)   warning: removefiles not implemented (%s)r   )appendr   r   	r5   r   r   r   afterforcer   r  warningss	            r$   removefileszabstractsubrepo.removefiles  s4     	:;;djH	
 	
 	
 qr&   c                 v    | j                             t          d          |d         |d         fz             g S )Ns)   %s: reverting %s subrepos is unsupported
r   r   r   r5   r   patsr   s       r$   revertzabstractsubrepo.revert  sB    ;<<{HQK()	
 	
 	
 	r&   c                     |S r   r<   r5   revids     r$   shortidzabstractsubrepo.shortid  s    r&   c                     dS )zH
        convert this repository from shared to normal storage.
        Nr<   r   s    r$   unsharezabstractsubrepo.unshare  r  r&   c                     dS )a1  verify the revision of this repository that is held in `_state` is
        present and not hidden.  Return 0 on success or warning, 1 on any
        error.  In the case of ``onpush``, warnings or errors will raise an
        exception if the result of pushing would be a broken remote repository.
        r   r<   )r5   onpushs     r$   verifyzabstractsubrepo.verify  s	     qr&   c                     t          j        | j                                        j                            | j                            S )z@return vfs to access the working directory of this subrepository)vfsmodr   r   rp   rn   r\   r   r   s    r$   rn   zabstractsubrepo.wvfs  s3     z$)..**/44TZ@@AAAr&   c                     | j                             t          | j                                                  | j                  S zCreturn path to this subrepository as seen from outermost repository)rn   r^   reporelpathr   rp   r   r   s    r$   _relpathzabstractsubrepo._relpath  s2     y  TY^^-=-=!>!>
KKKr&   FF)FNFr   NT)(r8   r9   r:   r4   r   r   rP   r   r   r   r   r   r   r   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
  rW   r  r  r  r   r"  r%  propertycachern   r+  r<   r&   r$   r   r      ss             " " " "   6 6 6 6" " "
  " " "  " " "" " " "" " "" " "      : : :      " " "" " "  + + + +     ,      (      
    B B ]B L L ]L L Lr&   r   c                       e Zd Z fdZed             Zd Zd Zd Ze	d             Z
d Zd Zd	 Zed
             Zed             Zed             Zed             Zed             Zed             Zed/d            Zed0d            Zd Zd Zed             Zed             Zed             Zd Zed1d            Zed             Zed             Zed             Zed             Z ed              Z!d! Z"d" Z#ed#             Z$ed2d$            Z%d% Z&ed&             Z'ed'             Z(ed(             Z)d) Z*d* Z+ed+             Z,d1d,Z-e	d-             Z.e	d.             Z/ xZ0S )3	hgsubrepoc                    t          t          |                               ||           || _        |                                }|                    t          j        |                    }|o|j        	                    d|z             }t          j                            |          }t          j                            t          j                            t          j        |                              }	|	|k    r$t          j        t#          d          |z            t$                              |j        ||          | _        t          j                            | j        j                  t          j                            |          k    r#t          j        d|| j        j        fz            ||                                u r| j                                        | _        | j        j        | _        dD ]?\  }
}|j                            |
|          }|r| j                            |
||d           @| j                            ddd	d           |                     ||d
         |           d S )Ns   %s/.hgrj   creates9   failed to reject unsafe subrepo path: %s (expanded to %s)))   uis   commitsubrepos   subrepor5  s   _usedassubrepos   Truer   )superr1  r4   _staterp   wjoinr   	localpathrn   existsosr!   normcaserealpathr   r
   r3   r   r   
repositorybaseui_reporm   ProgrammingError
unfilteredrN   config	setconfig	_initrepo)r5   r   r!   r   r   rrm   r4  	norm_root	real_rootskv	__class__s                r$   r4   zhgsubrepo.__init__  s   i''T222HHJJwwt~d++,,DQV]]9t3C%D%D!D G$$T**	G$$RW%5%5dod6K6K%L%LMM		!!+@AADH   ]]18T&]AA
7DJO,,0@0@0F0FFF(-04djo/FG   ..00DJ*-0 	7 	7DAqAq!!A 7!!!Q:666%!2GZHHHq%(F+++++r&   c                 V    t          j        | j        t          |           |           d S r   )r   r   rA  rA   r   s      r$   r   zhgsubrepo.addwebdirpath  s'    dj*T*:*:GDDDDDr&   c                     | j                                         5  |                     |          cd d d            S # 1 swxY w Y   d S r   )rA  lock_storecleanr   s     r$   r   zhgsubrepo.storeclean  s    Z__ 	* 	*##D))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   <A A c                     d}|                      |          }|                     |          D ]}|t          |d           k    rd} n|rt          |d           d u }|S )NTF)_calcstorehash_readstorehashcachenext)r5   r!   clean	itercachefilehashs        r$   rQ  zhgsubrepo._storeclean  s    ''--	0066 	 	H4	40000 1  	2 D))T1Er&   c              #      K   d}dt          |          z  V  | j        j        }|D ]Q}t          t	          j        |                    |                                                              }d||fz  V  RdS )zcalculate a unique "store hash"

        This method is used to to detect when there are changes that may
        require a push to a given remote path.)s	   bookmarkss   store/phaserootss   store/00changelog.is   # %s
   %s = %s
N)r%   rA  r   r   r   r)   tryreadr*   )r5   r+   filelistr   relnamerX  s         r$   rS  zhgsubrepo._calcstorehash  s       O*:666666jn 	5 	5G8=W)=)=>>EEGGHHH'8!444444	5 	5r&   c                 d    t          j        | j        j                            d                    S )Ns   cache/storehash)r'  r   rA  r\   r   s    r$   _cachestorehashvfszhgsubrepo._cachestorehashvfs  s%    z$*.--.@AABBBr&   c                 V    t          |          }| j                            |d          S )z7read the store hash cache for a given remote repository   r)r,   r_  tryreadlines)r5   r+   	cachefiles      r$   rT  zhgsubrepo._readstorehashcache  s(    *:66	&33ItDDDr&   c                    t          |          }| j                                        5  t          |                     |                    }| j        }|                    ||dd           ddd           dS # 1 swxY w Y   dS )zcache the current store hash

        Each remote repo requires its own store hash cache, because a subrepo
        store may be "clean" versus a given remote repo, but not versus another
        s   wbT)r  
notindexedN)r,   rA  rP  listrS  r_  
writelines)r5   r+   rc  	storehashr   s        r$   _cachestorehashzhgsubrepo._cachestorehash  s     +:66	Z__ 	N 	NT00<<==I)CNN9ieNMMM	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	Ns   AA99A= A=c                     | j                                         | j        d         S | j        d         }| j        |         S )zBfetch the context for this subrepo revision, possibly a workingctxNr   )r   revrA  r8  )r5   rk  s     r$   _getctxzhgsubrepo._getctx  s6    9==??":d##+a.C:c?"r&   c                 t    | j         _        | j         _        |rdg fd}t           j         d          }t           j         dd          } |d|           ||k    r |d|            j         j                            dt          j        d	                                                   d S d S )
Ns   [paths]
c                 ~    |r9                     d| |fz             j                            d| |d           d S d S )NrZ  s   pathsr6  )r  rN   rE  )keyvaluelinesr5   s     r$   addpathconfigz*hgsubrepo._initrepo.<locals>.addpathconfig-  sU     HLLe!<===G%%hUJGGGGGH Hr&   F)abortTs   defaults   default-pushrV   r&   )	rA  
_subparent
_subsource
_abssourcer   writer   tonativeeolr\   )r5   
parentrepor   r4  rr  defpathdefpushpathrq  s   `      @r$   rF  zhgsubrepo._initrepo%  s     *
 &
 	M!NEH H H H H H
 !5999G$TZUCCCKM*g...+%%o{;;;JN  $*:388E??*K*KLLLLL	M 	Mr&   c                 :    t          j        || j        ||||fi |S r   )r   r   rA  r   s          r$   r   zhgsubrepo.add:  s2    {
E68\
 
EI
 
 	
r&   c                 n    t          j         |          }d|d<   t          j        | j        ||||          S )NTrv   )copyr   r   rA  )r5   r   r   r   r   s        r$   r   zhgsubrepo.addremove@  s6    
 y [ Q$GGGr&   c           	      z    | j         d         }| j        |         }t          j        | j        | j        |||||fi |S r   )r8  rA  r   r   rN   )r5   r   r   r   r   r   rk  r   s           r$   r   zhgsubrepo.catI  sL    k!njo{GTZeRV
 
GK
 
 	
r&   c           
      X   	 | j         d         }| j        |         }| j        |         } | j        j        ||fi |S # t          j        $ r]}| j                            t          d          |t          |           fz             t          j        g g g g g g g           cY d }~S d }~ww xY w)Nr   *   warning: error "%s" in subrepository "%s"
)
r8  rA  r   r
   RepoLookupErrorrN   r[   r   rA   r   )r5   r   r   rev1ctx1ctx2insts          r$   r   zhgsubrepo.statusQ  s    
	>;q>D:d#D:d#D$4:$T4884888$ 	> 	> 	>GLL@AAD))*+   >"b"b"b"========	>s   := B)AB$B)$B)c                 t   	 t          | j        d                   }|t          |          }t          j        || j        || j        |         | j        |         |f|dd| d S # t
          j        $ rD}| j                            t          d          |t          |           fz             Y d }~d S d }~ww xY w)Nr   T)r   listsubreposr  )r   r8  r   diffordiffstatrA  r
   r  rN   r[   r   rA   )	r5   rN   r   r   r   r   r   node1r  s	            r$   r   zhgsubrepo.diff_  s   	A''E  E

%

5!
5!
 !
 
 
 
 
 
 
 $ 	 	 	GLL@AAD))*+        	s   A A$ $B739B22B7NTc                 ,   |                      | j        dz              |                                 }rfd|D             }| j        d         }| j        |         }t	          j        | j        |                                t	          j        | j        |          fg           t          	                    | ||          }|j
        D ]K}	t          ||	d          }
t          j        |	          }||	z   dz   }||
	                    ||||          z  }L|S )N)rr   c                 *    g | ]} |          |S r<   r<   r   s     r$   r   z%hgsubrepo.archive.<locals>.<listcomp>}  s&    2221q2Q222r&   r   T   /)_getr8  r   rA  r   prefetchfilesrk  
matchfilesr   r
  r   r0   r   subdirmatcher)r5   r  r   r   r   r   rk  r   r   subpathrJ  submatch	subprefixs      `         r$   r
  zhgsubrepo.archivex  s   		$+()))

 	32222222Ek!njoJ#''))W%7
E%J%JKL	
 	
 	
  ''hFF| 	F 	FGWd++A-gu==H(4/IQYYxHfEEEEEr&   Fc                     | j         d         }|dk    r|sdS | j        d          }||                                                                k    r|sdS |                    |          S )Nr   r&   T)r   )r8  rA  p1r   rP   )r5   r   r   rG  ws        r$   rP   zhgsubrepo.dirty  sd    KN88L84Jt

\4wwww'''r&   c                 @    | j         d                                         S N   .)rA  r   r   s    r$   r   zhgsubrepo.basestate  s    z$##%%%r&   c                 f    | j                             | j                             |                    S r   )rA  _checknestedr9  r   s     r$   r   zhgsubrepo.checknested  s(    z&&tz'7'7'='=>>>r&   c                 V   |                      d          s| j        d                                         S | j                            dt          |           z             | j                            |||          }|s| j        d                                         S t          |          S )NTr  s   committing subrepo %s
)rP   rA  r   rN   debugrA   r   )r5   r   r   r   ns        r$   r   zhgsubrepo.commit  s     zz$ 	*:d#'')))0:d3C3CCDDDJdD$// 	*:d#'')))1vvr&   c                 D    | j         |pd                                         S r  )rA  r   r   s     r$   r   zhgsubrepo.phase  s    z%-4(..000r&   c                     | j                             t          d          t          |           z             t                              | j        | j        j        d           d S )N   removing subrepo %s
F)rN   noter   rA   r   rV  rA  nullidr   s    r$   r   zhgsubrepo.remove  sQ     	Q/00:d3C3CCDDD
TZ.66666r&   c                     |\  }}} j         j        }| j                                         v r.t           j                   dk    s|                                sdS | j         _        t           j                    fd}t           j                   dk    r~ j         j                                         |                                rt          
                              rŉ j                            t          d          t                     fz              |            }	 t                               j         j        j        | j         j        dd          }|                                 n# |                                 w xY w|                                 _         n?|                                rP j                            dd          }	|	rt+          j        |	          }	|	 j                            dd	          d
}
ni }
 j                            t          d          t                     t/          j                  fz              |            }	 t                               j         j        j        i | j         j        d|
          \  }}|                                 n# |                                 w xY w|                                 _                              ||d                                           nʉ j                            t          d          t                     t/          j                  fz                                            } |            }	 t;          j         j         |           |                                 n# |                                 w xY w|r                                dS )Nr   Tc                  F    t                                j        i           S r   )r   peerrA  )r5   srcurls   r$   <lambda>z hgsubrepo._get.<locals>.<lambda>  s    "''$*b&99 r&   s   sharing subrepo %s from %s
F)r   	bookmarkss   share   pools
   poolnaming)r  s   mode   cloning subrepo %s from %s
)r   	shareoptsr3     pulling subrepo %s from %s
)rA  rt  rC  r   sharedru  rv  r   rmtreer   islocalrN   r   r   rA   sharer@  rm   closerQ   rD  r   r   r   hidepasswordclonerF  ri  r   r   pull)r5   r   r   revisionr|   ry  getpeerr  r  poolr  otherclonedcleansubr  s   `             @r$   r  zhgsubrepo._get  s   !&$Z*
tz,,....4:!##:+<+<+>+>#t &
DJ'' :9999tz??aJN!!###   "" 0,rzz&'9'9 0,566!$''01   wyy	!XX
-4
$"' &  F JJLLLLDJJLLLL#\\^^

 $$&& 
#7>>(G<<D 5#t44 "&!%-!H!H! !II
 !#I566!$'')=f)E)EFG   wyy
!$&HH
-4
$"+ %- % %ME6 JJLLLLDJJLLLL#\\^^
NN:vdN;;;  ((((GNN122d##W%9&%A%ABC   v..H799Ddj$///



 -$$V,,,us$   -8E: :F*<J; ;KN5 5Oc                    |                      |          }|\  }}}| j        }|j                            d| j        z             |rk|                                }||         }	|	                                r;|j                            t          d          |dd         | j        fz             |}|rt          j
        ||                    d S t          j        ||                    d S )Ns   getting subrepo %s
s,   revision %s in subrepository "%s" is hidden
r   r(   )r  rA  rN   r  r   rC  hiddenr[   r   r   clean_updater   )
r5   r   r   inrepor   r  r|   rp   urepor   s
             r$   rz   zhgsubrepo.get  s    5!!!&$z-
:;;; 	OO%%E/Czz|| FGG"~tz23    	)tH~.....Lh(((((r&   c                                                       j        d          j        d                                                 fd} j        d          }                                 rJk    r8t	           j         |                                          r |             d S d S  |             d S  |             d S )Nr  r   c                      k    r|                                                                  k    rRj                            dt                    z             t                              j        d                    d S  k    r,j                            dt                    z             d S j                            dt                    z             t                              d           d S )Ns   updating subrepository "%s"
r   s   skipping subrepository "%s"
s   merging subrepository "%s"
F)remind)branchrN   r  rA   r   r   rA  r   )anccurdstr5   r   s   r$   	mergefuncz"hgsubrepo.merge.<locals>.mergefunc)  s    czzcjjllcjjll::4z$7G7GG   		$*eAh/////4z$7G7GG     3j6F6FF   U+++++r&   )r  rA  ancestorrP   rT   rN   )r5   r   r  wctxr  r  r  s   ``  @@@r$   r   zhgsubrepo.merge"  s    		%jjq"ll3	, 	, 	, 	, 	, 	, 	, 	, 	,  z$::<< 	czz $

c3GG  IKKKKK    	IKKKKKr&   c                    |                     d          }|                     d          }|                     d          }| j        d         }|j        }t          |          D ]1}|                    |                              |          dk    r dS 2t          | j        d          }|sb|                     |          rM| j        	                    t          d          t          |           t          j        |          fz             d S | j        	                    t          d	          t          |           t          j        |          fz             t                              | j        d|i|          }		 t!          j        | j        |	||
          }
|	                                 n# |	                                 w xY w|                     |           |
j        S )N   forces
   new_branchs   sshr  r   FTs4   no changes made to subrepo %s since last push to %s
s   pushing subrepo %s to %s
)	newbranch)rz   rA  r   sortedrO   r   rv  r   rN   r   r   rA   r   r  r   r  r   r  ri  cgresult)r5   r   r  r  sshcsubsrJ  dsturlr  rF   s              r$   r   zhgsubrepo.pushC  s   ""HH]++	hhv Jtz 	 	AuuQxx}}T""a''uu ( DJ-- 	v&& NOO!$'')=f)E)EFG   t+,,$!5f!=!=>?	
 	
 	
 
VSM6::	-
E5INNNCKKMMMMEKKMMMM 	V$$$|s   =F/ /Gc                    d|v sd|v r@t          j         |          }|                    dd            |                    dd            t          j        | j                  }t
                              || j        |||          S Ns   revs   branch)r  )r~  r2   r   repo_rel_or_abs_sourcerA  r   r   )r5   rN   r   r   r  s        r$   r   zhgsubrepo.outgoingf  sz    T>>Y$..9T??DHHVT"""HHY%%%4TZ@@{{2tz4w{GGGr&   c                    d|v sd|v r@t          j         |          }|                    dd            |                    dd            t          j        | j                  }t
                              || j        |||          S r  )r~  r2   r   r  rA  r   r   )r5   rN   r   r   r  s        r$   r   zhgsubrepo.incomingo  sz    T>>Y$..9T??DHHVT"""HHY%%%4TZ@@{{2tz64{IIIr&   c                     | j         d         }| j        |         }|                                                                S r   )r8  rA  manifestkeys)r5   rk  r   s      r$   r   zhgsubrepo.filesx  s2    k!njo||~~""$$$r&   c                     | j         d         }| j        |         |                                         }|r| j                            ||          }|S r   )r8  rA  data
wwritedata)r5   r   r   rk  r  s        r$   r   zhgsubrepo.filedata~  sM    k!nz#t$))++ 	5:((t44Dr&   c                 `    | j         d         }| j        |         }|                    |          S r   )r8  rA  r  )r5   r   rk  r   s       r$   r   zhgsubrepo.fileflags  s(    k!njoyyr&   c           	          | j                                         | j        d          }n| j        d         }| j        |         }t	          j        |||||||          S r   )r   rk  rA  r8  r   r   )	r5   rN   r   r   r   r   r   r   rk  s	            r$   r   zhgsubrepo.printfiles  sT     9==??"*T"CC+a.C*S/C}Ra2sHEEEr&   c           
         | j                                         | j        d          }n| j        d         }| j        |         }|                    |||          g}|j        D ]}|                    |          }	 |                    |||          }	t          j        ||	|          }
|	                    |
           ]# t          j        $ rS | j                            t          d          | j                            t#          |           |          z             Y w xY wt%          |          dk    r|d         S t          j        |          S )Nr   r   s#   skipping missing subrepository: %s
r   )r   rk  rA  r8  r   r   rO   r   prefixdirmatcherr  r
   LookupErrorrN   r   r   rn   r^   r*  r   unionmatcher)r5   r   r   r   r   rk  matchersr  rO   smpms              r$   r   zhgsubrepo.matchfileset  s]   9==??"*T"CC+a.C*S/C$$S$e$<<=| 	 	G'''""C%%c4u%==.w%HHH####$   =>>i''D(9(97CCD    
 x==AA;$X...s   :AB??AD! D!c                 F    | j         d          }|                    |          S r   )rA  rW   )r5   r   r   s      r$   rW   zhgsubrepo.walk  s    jxxr&   c           
      N    t          j        | j        | j        |||d||          S )NT)r  r  )r   r  rN   rA  r  s         r$   r  zhgsubrepo.forget  s7    ~GJ#	
 	
 	
 		
r&   c	                 N    t          j        | j        | j        |||||||	  	        S r   )r   r   rN   rA  r  s	            r$   r  zhgsubrepo.removefiles  s7     ~GJ

 

 
	
r&   c                 N   | j                             t          d          |d         z             |                    d          s1|                                }d |d<   |d         |d<    | j        |i | |                    d          s|                     |d	           d S d S )
N   reverting subrepo %s
r   	no_backupr   r   rk  dry_runTr   )rN   r   r   rz   r~  
filerevertr  s       r$   r  zhgsubrepo.revert  s     	q233hqkABBBxx$$ 	+ 99;;DDL"1+DKDOT*T*** xx	"" 	/HHXH.....	/ 	/r&   c                     | j         |d                  }|                    d          rdg}ng }t          j        | j        | j         |g|R i | d S )Nrk  alls   set:modified())rA  rz   r   r  rN   )r5   r  r   r   s       r$   r  zhgsubrepo.filerevert  sa    je%88E?? 	%&DDDtw
C?$???$?????r&   c                     |d d         S )Nr(   r<   r  s     r$   r   zhgsubrepo.shortid  s    SbSzr&   c                     ddl m} |a| j                                        r/| j                            t          d          | j        z             t                              | j        | j                   d S )Nr   r   s   unsharing subrepo '%s'
)	r   r   rA  r  rN   r   r   r+  r"  )r5   r   s     r$   r"  zhgsubrepo.unshare  sv     	
 : 	KGNN1899DMIJJJ


47DJ'''''r&   c                    	 | j         d         }| j                                        |         }|                                rut	          d          | j        t          | j                                                  fz  }|rt          j
        |          | j        j                            d|z             dS # t          j        $ ry t	          d          | j        t          | j                                                  fz  }|rt          j
        |          | j        j                            d|z             Y dS w xY w)Nr   s%   subrepo '%s' is hidden in revision %ss   %s
r   s%   subrepo '%s' not found in revision %s)r8  rA  rC  r  r   r+  r   r   noder
   r3   rN   r[   r  )r5   r$  rk  r   rS   s        r$   r%  zhgsubrepo.verify  s>   	+a.C*''))#.Czz|| 6 @AAM$)..**++E 
  6+c***JM&&w}5551$ 	 	 	 <==dinn&&''A C
  2k#&&&
""7S=11111	s   B5B9 9BE Ec                     | j         j        S )z.return own wvfs for efficiency and consistency)rA  rn   r   s    r$   rn   zhgsubrepo.wvfs+  s     zr&   c                 *    t          | j                  S r)  )r*  rA  r   s    r$   r+  zhgsubrepo._relpath0  s     4:&&&r&   r.  r,  r-  r   )1r8   r9   r:   r4   rK   r   r   rQ  rS  r/  r_  rT  ri  rl  rF  r   r   r   r   r   r
  rP   r   r   r   r   r   r  rz   r   r   r   r   r   r   r   r   r   rW   r  r  r  r  r   r"  r%  rn   r+  __classcell__rM  s   @r$   r1  r1    sH        ,  ,  ,  ,  ,D E E E* * *  5 5 5 C C ]CE E E

N 
N 
N# # # M M M( 
 
 

 H H H 
 
 
 > > >   0    $ ( ( ( (& & &? ? ? 	 	 	 1 1 1 7 7 7Y Y Yv ) ) ) )&   @      D H H H J J J % % %
    
 F F F / / / /2   

 

 

 
 
 
. / / /*@ @ @   ( ( ($   >   ] ' ' ]' ' ' ' 'r&   r1  c                        e Zd Z fdZddZed             Zd Zd Zd Z	d	 Z
edd
            Zd Zed             Zed             Zedd            Zed             Zd Zed             Zd Z xZS )
svnsubrepoc                     t          t          |                               ||           || _        t	          j        d          | _        | j        s)t          j        t          d          | j
        z            d S )Nrt   s+   'svn' executable not found for subrepo '%s')r7  r  r4   r8  r   findexe_exer
   r3   r   r   r5   r   r!   r   r   rM  s        r$   r4   zsvnsubrepo.__init__8  sw    j$((d333$V,,	y 	+@AADJN  	 	r&   r&   Fc           
      8   | j         g}i }| j                                        s.t          j        |d<   |d         dv r|                    d           t          j        t          d          rt          t          d          |d<   |	                    |           |R| j
                            | j                                        j        | j        |          }|                    |           t!          t"          j                  }|                    d          }|r||d<   |d= d	|d
<   t          j        t+          j        t.          j        |          fdt.          j        t          j        t          j        t/          j        |          d|}	t7          t          j        |	                                          \  }
}|                                }|sD|	j        rtA          j!        |p	d|	j        z            |r| j        "                    |dz              |
|fS )Nstdinr   )   update   checkout   commits   --non-interactiveCREATE_NO_WINDOWcreationflags   LC_ALLs   LANG   Cs   LC_MESSAGES)bufsize	close_fdsstdoutstderrenvs   exited with code %d   
)#r  rN   r  
subprocessPIPEr  r   safehasattrgetattrextendrn   r^   r   rp   origrootr   dictr	   environrz   Popenr   rapplyr   tonativestrclosefdstonativeenvmapfromnativeeolcommunicatestrip
returncoder
   r3   r[   )r5   commandsfilenamefailokcmdextrakwr!   r  lc_allpr  r  s               r$   _svncommandzsvnsubrepo._svncommandA  s   ykw""$$ 		1  *GG
 {AAA

/000J(:;; 	O (/z;M'N'NGO$

89$$	  )4:x D JJt8#$$## 	!CLI"NOH0#66
'??$S))
 
 
 
 T/AA 	-| kC4q|C    -Ve^,,,v~r&   c                 2   |                      ddgd           \  }}t          j        d|          }|s!t          j        t          d                    t          |                    d                    t          |                    d                    fS )N	   --version   --quiet)r$  s   ^(\d+)\.(\d+)s    cannot retrieve svn tool versionr   r   )r*  researchr
   r3   r   intgroup)r5   outputerrr   s       r$   _svnversionzsvnsubrepo._svnversions  s    &&:& ' 
 
 I'00 	F+a CDDEEEAGGAJJQWWQZZ11r&   c                 8    | j                             d           S )N   .svnrn   r;  r   s    r$   _svnmissingzsvnsubrepo._svnmissing}      9##G,,,,r&   c                    |                      ddg          \  }}t          j        j                            |          }|                    d          }d\  }}|r{t          j        |d                             d                    pd}|d                             d          }|r/t          j        |d                             d                    pd}||fS )	Ns   info   --xmlentry)   0r=  r   r  r=  r   )	r*  xmldomminidomparseStringgetElementsByTagNamer   bytestrgetAttribute)r5   r2  r3  docentrieslastrevrk  commitss           r$   _wcrevszsvnsubrepo._wcrevs  s     &&':;;go))&11**733! 	"71:#:#::#F#FGGO4Caj55h??G $WQZ%<%<Z%H%HII   ~r&   c                 6    |                                  d         S )Nr   )rI  r   s    r$   _wcrevzsvnsubrepo._wcrev  s    ||~~a  r&   c                    |                      ddg          \  }}g g g }}}t          j        j                            |          }|                    d          D ]}|                    d          }|s|d                             d          }	|d                             d          }
|                    d                              d	          }|	d
k    r|                    |           n|	dk    r|                    |           |	dvs|
dvr|                    |           |D ]E}|D ]@}||k    s"|	                    |t          j        z             rddt          |          fc c S AFt          |          dt          |          fS )zReturn (changes, extchanges, missing) where changes is True
        if the working directory was changed, extchanges is
        True if any of these changes concern an external entry and missing
        is True if any change is a missing entry.
           statusr;  r<  z	wc-statusr   itempropsr!   utf8externalr   )r   normalunversionedrQ  )r   nonerR  TF)r*  r>  r?  r@  rA  rB  rD  encoder  rk   r   ossepbool)r5   r2  r3  	externalschangesr   rE  erJ  rN  rO  r!   exts                r$   
_wcchangedzsvnsubrepo._wcchanged  s    &&	8'<==&("bG7	go))&11))'22 	% 	%A&&{33A Q4$$V,,DaD%%g..E>>&))0088Dz!!  &&&&""t$$$   666t$$$ 	5 	5D  5 53;;$//#2F"G"G;tG}}444444 5 G}}eT']]22r&   c                     |                                  r| j        d         dk    S |                                 }|d         p	|o|d         }|s%| j        d         |                                 v s|rdS dS )Nr   r&   r   r   FT)r8  r8  r\  rI  )r5   r   r   	wcchangedchangeds        r$   rP   zsvnsubrepo.dirty  s}     	);q>S((OO%%	A,<7#;y| 	{1~//</utr&   c                     |                                  \  }}||k    r?	 |                     dd| j        d         |fz  g           |S # t          j        $ r Y nw xY w|S )N   list   %s@%sr   )rI  r*  r8  r
   r3   )r5   rG  rk  s      r$   r   zsvnsubrepo.basestate  s    ||~~c>>
  h$+a.')BBC   ;   
s   (A AAc                    |                                  \  }}}|s|                                 S |r!t          j        t	          d                    |r!t          j        t	          d                    |                     dd|g          \  }}| j                            |           t          j	        d|          }	|	sa|
                                s!t          j        t	          d                    t          j        |                                d                   |	                                d         }	| j                            |                     d	d
|	g          d                    |	S )Ns   cannot commit svn externalss!   cannot commit missing svn entriesr     -ms   Committed revision ([0-9]+).s   failed to commit svn changesr
  r   r     -r)r\  r   r
   r3   r   r*  rN   r   r.  r/  r!  
splitlinesgroups)
r5   r   r   r   r_  
extchangedr   
commitinfor3  newrevs
             r$   r   zsvnsubrepo.commit  sZ    (,'8'8$W 	$>>### 	A+a >??@@@ 	G +a DEEFFF**Iud+CDD
Cz""":JGG 	;##%% F
 k!$C"D"DEEE+j3355b9:::#t''E6(BCCAFGGGr&   c                    |                                  r1| j                            t          d          | j        z             d S | j                            t          d          | j        z             | j                            d           	 | j        	                                j        }|
                    |                    | j                             d S # t          $ r Y d S w xY w)N-   not removing repo %s because it has changes.
r  T)forcibly)rP   rN   r[   r   r   r  rn   r  r   rp   
removedirsr`   OSError)r5   pwvfss     r$   r   zsvnsubrepo.remove  s    ::<< 	GLLCDD*   FQ/004:=>>>	$'''	INN$$)EU]]4:6677777 	 	 	DD	s   AC 
C,+C,c                    |r|                      ddg           dg}| j        dk    r|                    d           |                    d|d         |d         fz             t          j        |d                    |                      |d	
          \  }}t          | j        | j        d           t          j	        d|          sd|v rM| 
                                d d         dk    r-|                                  |                     |d           d S t          j        |p|                                d                   | j                            |           d S )Ns   revert   --recursiver  )r         --forcerb  r   r   T)r%  r6  s   Checked out revision [0-9]+.s-   is already a working copy for a different URLr   r,  Fr  r
  )r*  r4  r  r   checksafesshrf   rN   rn   r.  r/  r\  r   rz   r
   r3   rf  r   )r5   r   r   r6   r   r3  s         r$   rz   zsvnsubrepo.get  sa    	:i8999}v%%KK
### 	Ha%(33444 	U1X&&&&&tD&99$'49g...y8&AA 	@?3FF!!"1"%77 %000+v}88::2>???vr&   c                    | j         d         }|d         }|                                 }||k    rP||k    p|                                 d         }t          | j        | |||          r|                     |d           d S d S d S )Nr   r   F)r8  rK  r\  rT   rN   rz   )r5   r   oldnewwcrevrP   s         r$   r   zsvnsubrepo.merge  s    k!nAh%<<5L8DOO$5$5a$8ETWdE5#>> '&&&&& <' 'r&   c                     dS r.  r<   r   s     r$   r   zsvnsubrepo.push'  s    tr&   c                    |                      g d          d         }t          j        j                            |          }g }|                    d          D ]}t          j        |                    d                    }|dk    r0d	                    d |                    d          d         j
        D                       }|                    |                    d	                     |S )
N)ra  rr  r;  r   r<  r|   s   filer   c              3   D   K   | ]}|j         |j        k    |j        V  d S r   )nodeType	TEXT_NODEr  )r   r  s     r$   	<genexpr>z#svnsubrepo.files.<locals>.<genexpr>4  s?        :,, ,,,, r&   r   rP  )r*  r>  r?  r@  rA  rB  r   rC  rD  r\   
childNodesr  rU  )r5   r2  rE  pathsrZ  r|   r   s          r$   r   zsvnsubrepo.files+  s    !!"E"E"EFFqIgo))&11))'22 		. 		.A#ANN6$:$:;;Dw77  //77:E    D
 LLV,,----r&   c                 <    |                      dg|          d         S )Ns   catr   )r*  r   s      r$   r   zsvnsubrepo.filedata<  s    $//22r&   )r&   Fr,  r-  )r8   r9   r:   r4   r*  r/  r4  r8  rI  rK  r\  rK   rP   r   r   r   rz   r   r   r   r   r  r  s   @r$   r  r  7  s           0 0 0 0d 2 2 ]2- - -  $! ! !#3 #3 #3J          6        4 ' ' '      3 3 3 3 3 3 3r&   r  c                       e Zd Z fdZd Zed             Zed             Zd%dZd%dZ	d&d	Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zed'd            Zd Zed(d            Zed             Zed             Zed             Zed             Zed             Zd)dZ ed              Z!ed!             Z"ed"             Z#ed#             Z$d$ Z% xZ&S )*
gitsubrepoc                    t          t          |                               ||           || _        |                                                    |          | _        |                                | _        |                                  d S r   )	r7  r  r4   r8  rp   r9  _abspathrt  
_ensuregitr   s        r$   r4   zgitsubrepo.__init__A  sl    j$((d333

((..((**r&   c           	      @   	 d| _         |                     dg          \  }}n`# t          $ rR}t          d          }t          d          }|j        t          j        k    r5t          j        || j        t          j
        |j                  fz            t          j        r	 d| _         |                     dg          \  }}n# t          $ rz}|j        t          j        k    r+t          j        t          d          | j        z  |          t          j        || j        t          j
        |j                  fz            d }~ww xY wt          j        t          d          | j        z  |          Y d }~nd }~ww xY w|                     |          }|d	k    r)| j                            t          d
                     d S |dk    r!t          j        t          d                    |dk    r)| j                            t          d                     d S d S )Nrs   r,  s(   error executing git for subrepo '%s': %ss'   check git is installed and in your PATHs   git.cmds1   couldn't find 'git' or 'git.cmd' for subrepo '%s'rw   s"   couldn't find git for subrepo '%s'   unknowns   cannot retrieve git version
   aborts,   git subrepo requires at least 1.6.0 or later   warnings-   git subrepo requires at least 1.6.0 or later
)_gitexecutable	_gitnodirro  r   errnoENOENTr
   r3   r   r	   
strtolocalstrerrorr   	iswindows_checkversionrN   r[   )r5   outr3  rZ  genericerrornotfoundhinte2versionstatuss           r$   r  zgitsubrepo._ensuregitH  sY   !	"(D~~|n55HC 	 	 	HIILGHHLw%,&&k DJ0CAJ0O0O#PP   # *4D'#~~|n==HC   x5<//#k!5  #j	)
 ".    $k(#z8+>r{+K+KLM    k;<<tzI%   # 	> **3//J&&GLL;<<=====h&&+ABB   j((GLLLMMNNNNN )(s:    $ FA4E<$ CE<
E	A5EE		.E<<Fc                    t          j        d|           }|ret          |                    d                    t          |                    d                    t          |                    d                    fS t          j        d|           }|rEt          |                    d                    t          |                    d                    dfS dS )Ns    ^git version (\d+)\.(\d+)\.(\d+)r   r      s   ^git version (\d+)\.(\d+)r   r
  )r.  r/  r0  r1  )r  r   s     r$   _gitversionzgitsubrepo._gitversionu  s    I:C@@ 	G

OOS__c!''!**ooFFI3S99 	9

OOS__a88rr&   c                 j    t                               |           }|dk    rdS |dk     rdS |dk     rdS dS )a  ensure git version is new enough

        >>> _checkversion = gitsubrepo._checkversion
        >>> _checkversion(b'git version 1.6.0')
        'ok'
        >>> _checkversion(b'git version 1.8.5')
        'ok'
        >>> _checkversion(b'git version 1.4.0')
        'abort'
        >>> _checkversion(b'git version 1.5.0')
        'warning'
        >>> _checkversion(b'git version 1.9-rc0')
        'ok'
        >>> _checkversion(b'git version 1.9.0.265.g81cdec2')
        'ok'
        >>> _checkversion(b'git version 1.9.0.GIT')
        'ok'
        >>> _checkversion(b'git version 12345')
        'unknown'
        >>> _checkversion(b'no')
        'unknown'
        r
  r  )r   rs  r   r  )r      r   r  s   ok)r  r  )r  versions     r$   r  zgitsubrepo._checkversion  sL    0 ((-- b==:Y8y  :ur&   NFc                 >    |                      |||          d         S )N)r  streamr   _gitdirr5   r#  r  r  s       r$   _gitcommandzgitsubrepo._gitcommand  s    ||H#f|==a@@r&   c                 >    |                      |||| j                  S )N)r  r  r   )r  r  r  s       r$   r  zgitsubrepo._gitdir  s(    ~~#f$-  
 
 	
r&   c           
      j   | j                             d| j        d                    |          fz             |t          j                                        }d|d<   d|vrd|d<   d}| j         j        rt          j	        t          j        d          }| j         j        r1t          |          r"|d	         d
k    r|                    dd           i }t          j        t"          d          rt%          t"          d          |d<   t#          j        t          j        t*          j        | j        g|z             fdt          j        t*          j        |          t+          j        |          t*          j        t"          j        |d|}|r	|j        dfS |j                                                                        }|                                 |j        d	k    rQ|j        dk    rF|d	         }	|	dv r	||j        fS tA          j!        tE          d          |	|j        | j        fz            ||j        fS )zCalls the git command

        The methods tries to call the git command. versions prior to 1.6.0
        are not supported and very probably fail.
        s   %s: git %s
r?   Nr	  r  s   GIT_ALLOW_PROTOCOLs   file:git:http:https:ssh   wr      diffr   s   --colorr  r  r
  )r  r   r  r  r  r  )   cat-file   symbolic-refs   git %s error %d in %s)#rN   r  r+  r\   r	   r  r~  quietr   openr<  devnull
_colormoder   insertr   r  r  r  r  r  r   r  r  r  r  r  r  readr!  waitr"  r
   r3   r   )
r5   r#  r  r  r   errpiper'  r)  retdatacommands
             r$   r  zgitsubrepo._gitnodir  s5    	o		(8K8K(LLMMM;"''))CI ++)CC%& 7= 	6mBJ55G7 	+#h-- 	+HQK74J4J OOAz***J(:;; 	O (/z;M'N'NGO$O$t':&;h&F 
  4c::$S))'?
 
 
 
  	"8T>!(--//''))	<1!2!2qkG888,,+*++AL$-89  
 $$r&   c                 8    | j                             d           S )N   .gitr7  r   s    r$   _gitmissingzgitsubrepo._gitmissing  r9  r&   c                 0    |                      ddg          S )Ns	   rev-parse   HEADr  r   s    r$   	_gitstatezgitsubrepo._gitstate  s    w 7888r&   c                 B    |                      g d          \  }}|rd }|S )N)r  r  r-  r  )r5   currentr3  s      r$   _gitcurrentbranchzgitsubrepo._gitcurrentbranch  s0    ||$J$J$JKK 	Gr&   c                     |                      ddd|g          }|                    d          d         }|                    d          t          d          z   }||d          S )Ns   remote   shows   -nr  r   s   URL: )r  splitindexr   )r5   rR   r  linerc   s        r$   
_gitremotezgitsubrepo._gitremote  s]    	7E6BCCyy"JJx  3x==0ABBxr&   c                 D    |                      dd|g          \  }}|dk    S )Nr  s   -er   r  )r5   r  r  codes       r$   _githavelocallyzgitsubrepo._githavelocally  s(    LL+uh!?@@	Tqyr&   c                 >    |                      d||g          }||k    S )N
   merge-baser  )r5   r1r2bases       r$   _gitisancestorzgitsubrepo._gitisancestor  s&    B 788rzr&   c                 8    |                      g d          dk    S )N)   configs   --bool	   core.bare   truer  r   s    r$   
_gitisbarezgitsubrepo._gitisbare  s"     D D DEEPPr&   c                 4    |                      g d           dS )zThis must be run before git diff-index.
        diff-index only looks at changes to file stat;
        this command looks at file contents and updates the stat.)s   update-index   -qs	   --refreshNr  r   s    r$   _gitupdatestatzgitsubrepo._gitupdatestat  s%     	???@@@@@r&   c                    i }i }|                      g d          }|                    d          D ]}|                    d          \  }}|                    d          s|                    d          sE|                    d          r|                    d          rp|||<   |                    |g                               |           ||fS )zcreturns 2 things:
        a map from git branch to revision
        a map from revision to branches)s   for-each-refs   --formats   %(objectname) %(refname)r  r?   s   refs/heads/   refs/remotes/s   /HEAD)r  r  rk   endswith
setdefaultr  )r5   
branch2rev
rev2branchr  r  r  refs          r$   _gitbranchmapzgitsubrepo._gitbranchmap  s     

GGG
 
 IIe$$ 		< 		<D JJt,,MHc>>.11 #.. ; ;  ~~.// CLL4J4J &JsO!!(B//66s;;;;:%%r&   c           	      ,   i }|D ]}|                     d          r|                    dd          d         }|                     dd|z  g          }|r>|                     dd|z  g          }||d||                    dd          d         fz  <   |S )z4return map of remote branch to local tracking branchr  r  r   r  s   branch.%s.remotes   branch.%s.merges   refs/remotes/%s/%s)rk   r  r  )r5   branchestrackingbbnamerR   r  s          r$   _gittrackingzgitsubrepo._gittracking"  s      		 		A||,-- GGD!$$Q'E%%y2E2M&NOOF &&	3E3M'NOO  )VSYYtQ5G5G5J,KK r&   c                     d|vr)|                     d          }|dk    rd|d |         vr|S || _        t          |           S )Ns   ://   :r
  r  )findru  rv  )r5   r   colons      r$   rv  zgitsubrepo._abssource2  sS    KK%%E{{t6&5&>99 $r&   c                 ~   |                                  rwt          j        |           |                     |          }| j                            t          d          | j        |fz             |                     d|| j	        g           | 
                    |          rd S | j                            t          d          | j        |                     d          fz             |                     dg           | 
                    |          s+t          j        t          d          || j        fz            d S )Nr  s   cloner     origins   fetchs1   revision %s does not exist in subrepository "%s"
)r  r   ru  rv  rN   r   r   r+  r  r  r  r  r  r
   r3   )r5   r   r  s      r$   _fetchzgitsubrepo._fetch;  sF    	> (((__V,,FGNN122dmV5LL   NNHfdm<===)) 	F-..}dooi889:	
 	
 	

 	($$$##H-- 	+GHHT]+,  	 	r&   c                 .   |                                  r| j        d         dk    S |                                 rdS |s%| j        d         |                                 k    rdS |                                  |                     g d          \  }}|dk    S )Nr   r&   T
   diff-indexr-  r  )r  r8  r  r  r  r  )r5   r   r   r  r  s        r$   rP   zgitsubrepo.dirtyS  s     	);q>S((?? 	4 	A$..2B2B B B4LL!E!E!EFF	Tqyr&   c                 *    |                                  S r   )r  r   s    r$   r   zgitsubrepo.basestatea  s    ~~r&   c                     |\  }}s                                   d S                      |                                            rI                     g d                                            k    r                     g d           d S nJ                                 k    r2r.                     ddg                                g d           d S                                  \  }} fd fd}|vr |             d S |         }d }	|D ]0}
|
dk    r dg            d S |	s|
                    d          s|
}	1|	r |	g           d S                      |                                          }|d	         }||vr|D ]
}
|
|v r|
} n||vr,|	                    d
d          d         } d||g           d S  
                    |||                  |          re||                                          k    r ||         g                                dd|g           t           j         j        d           d S  |             d S )N)r  r  s   false)   resets   --hardr  r  r  c                     dg}r,                     ddg           |                    d                                || z              t          j        j        d           d S )Nr  r  r     -fr  )r  r  rf   rN   rn   )r6   r&  r   r5   s     r$   checkoutz gitsubrepo.get.<locals>.checkout{  ss    -C "   (G!4555

5!!!S4Z(((dgty'22222r&   c                      j                             t          d          j        z             j                             t          d                       dg           d S )Ns1   checking out detached HEAD in subrepository "%s"
s5   check out a git branch if you intend to make changes
r  )rN   r[   r   r+  )r  r  r5   s   r$   rawcheckoutz#gitsubrepo.get.<locals>.rawcheckout  st    GLLGHH-    GLLKLL   HeX&'''''r&   s   refs/heads/masterr  r   r  r  s   -b   merges   --ffr  )r   r  r  r  r  r  rk   r  r  r  r  r  rf   rN   rn   )r5   r   r   r   r|   r  r  r  r  firstlocalbranchr  r  rR   rQ   r  r  s   ` `           @@r$   rz   zgitsubrepo.getd  s:   !&$ 	KKMMMFFH%%%?? 	@@@AAA~~8++  !?!?!?@@@ , ^^)) A   (G!4555  !?!?!?@@@F!%!3!3!5!5
J		3 		3 		3 		3 		3 		3		( 		( 		( 		( 		( 		( 		( :%%KMMMFh' 	% 	%A(((./000# %ALL9I,J,J %#$  	H&'(((F$$Z__%6%677!!!  ==FE ! !!LLq))!,EHeUF+,,,,,  HV,<!=vFF 	 4#9#9#;#;;;(6*+,,,h8999dgty'22222 KMMMMMr&   c                 `   |                                  r)t          j        t          d          | j        z            ddd|g}t
          j                                        }|r|d|gz  }|rt          j	        |d          |d<   | 
                    ||           |                                 S )	N   subrepo %s is missingr  s   -ard  s   --authors   %Y-%m-%dT%H:%M:%S %1%2s   GIT_AUTHOR_DATE)r  )r  r
   r3   r   r+  r	   r  r~  r   datestrr  r  )r5   r   r   r   r&  r  s         r$   r   zgitsubrepo.commit  s     	K+a 899DMIJJJ%-##%% 	'K&&C 	 '/&6/' 'C"# 	#&&& ~~r&   c           	      <   	 \  }	}                      |	                                d	 j        d         g                                                                 g d          \  }}	 fd}                                 r                                 	k    rh                                  j        d         k    p|dk    }t           j         | j        d         d d         	d d                   r |             d S d S d S  |             d S )Nr  r   r  c                       k    r                                n) j        d         k    r                    ddg           t          j        j        d           d S )Nr   r  s   --no-commitr  )rz   r8  r  rf   rN   rn   )r  r  r5   r   s   r$   r  z#gitsubrepo.merge.<locals>.mergefunc  sg    xQ''  (NH!EFFFdgty'22222r&   r      )	r  r  r8  r  r  rP   r  rT   rN   )
r5   r   r   r|   r  r  r  rP   r  r  s
   ``      @@r$   r   zgitsubrepo.merge  sP   !&$FH%%%$+a. IJJLL!E!E!EFF	T	3 	3 	3 	3 	3 	3 	3 	3 ::<< 	~~8++((DKN:Gdai GT5$+a.!*<hrrl    IKKKKK ,+   
 IKKKKKr&   c                 t   |                     d          }| j        d         sdS |                                 r)t          j        t          d          | j        z            |                                 \  }}| j        d         |v r.|| j        d                  D ]}|                    d          r dS |	                                D ]>\  }}|                    d          r$| 
                    | j        d         |          r dS ?dg}|r|                    d           |                                 }|r| 
                    | j        d         |          s1| j                            t          d          | j        z             d	S | j                            t          d
          |                    dd          d         | j        fz             |                     |d|gz             }	|	d         dk    S | j                            t          d          | j        | j        d         fz             d	S )Nr  r   Tr  s   refs/remotes/origin/s   pushrt  s7   unrelated git branch checked out in subrepository "%s"
Fs(   pushing branch %s of subrepository "%s"
r  r   r  r   sD   no branch checked out in subrepository "%s"
cannot push revision %s
)rz   r8  r  r
   r3   r   r+  r  rk   itemsr  r  r  rN   r[   r   r  r  )
r5   r   r  r  r  r  r  r&  r  rets
             r$   r   zgitsubrepo.push  se   ""{1~ 	4 	K+a 899DMIJJJ!%!3!3!5!5
J;q>Z''A/    << 788  44 %++-- 	  	 KAx||344  &&t{1~x@@  44i 	#JJz"""((** 	&&t{1~w?? 3  m	$   uGNN>??==q))!,dm<=   ,,si%99::Cq6Q;GLL1  =$+a.1	2   5r&   c                 d   |                                  rg S |                     d dd          }t                      }|j        |j        |j        |j        fD ]}	|                    |	           |j        }
|
	                    
                                           g }fdt          t          |
                    D             }
|
D ]}                    |          }dg}|r|                    d           |j        s|s.|                    t          d           ||          z             ||v r|r|                    |           |                    d          s|                     ||gz              |D ]0}|                    t          d           ||          z             1|S )	NT)unknownrV  c                 *    g | ]} |          |S r<   r<   r   s     r$   r   z"gitsubrepo.add.<locals>.<listcomp>.  s&    ;;;q%%((;;;;r&   s   addr  s
   adding %s
r  s   %s already tracked!
)r  r   setmodifiedaddeddeletedrV  r   r  r  r   r  exactr  verboser   rz   r  r[   )r5   rN   r   r   r   r   r   rJ  trackedlr   rejectedre   r  r  s     `            r$   r   zgitsubrepo.add  s    	IKKd$K77%%*agqy!': 	 	ANN1 	U[[]]###;;;;F3u::..;;; 	0 	0AKKNNEhG &u%%%z ; ;		!N++hhqkk9:::G|| 'OOA&&&88I&& 0  A3/// 	? 	?AGGA.//((1++=>>>>r&   c                    |                                  rd S |                                 r1| j                            t	          d          | j        z             d S | j                            t	          d          | j        z             |                     g d           | j        	                                D ]Q\  }}|dk    r|t          j        k    r| j                            |           7| j                            |           Rd S )Nrl  r  )r  r  r  r  )r  rP   rN   r[   r   r+  r  r  rn   readdirstatS_IFDIRr  r]   )r5   re   r|   s      r$   r   zgitsubrepo.removeC  s    	F::<< 	GLLCDD-    F 	Q/004=@AAA;;;<<<y((** 	$ 	$GAtG||t|##	  ####	  ####	$ 	$r&   Tc                    d}| j         \  }}|s|S |                     ||           |                     d|gd          }t          j        |d          }	t          |           }
| j                            t          d          |
z  t          d          	          }|	                    d           |	D ]}|
                                rt          j        |j                  }|r ||          s>|                                r|j        }nW|	                    |          }|r|                                }n+| j                            t          d
          |z             |                    ||z   |j        |                                |           |dz  }|                                 |                                 |S )Nr   s   archiveT)r  zr|)fileobjr  r   r   )r   s   skipping "%s" (unknown type)r   )r8  r  r  tarfiler  rA   rN   r   r   r   isdirr   fsencoder   issymlinknameextractfiler  r[   r  r  r  r  )r5   r  r   r   r   r   r   r  	tarstreamtarr  r  infor  r  re   s                   r$   r
  zgitsubrepo.archiveY  s   ; 	LFH%%%
 $$j(%;D$II	l94888T""7''  7*8 ( 
 
 	 	! 	!Dzz|| %di00E UU5\\ zz|| }OOD)) 6688DDGLL#B!C!Ce!KLLLVe^TY

dKKKQJE    r&   c           	         | j         d         }|                                rdS |                                sdS |                                D ]|}|                     dd||fz  g          }t	          j        | j        || j                            ||                    }	|		                    |           |	
                                 }dS )Nr   r  s   %s:%s)pathnamer   )r8  anypatsr   r  r   makefileobjr   rn   r^   rw  r  )
r5   r   r   r   r   r   rk  re   r2  fps
             r$   r   zgitsubrepo.cat  s    k!n==?? 	1{{}} 	1  	 	A%%wC80C&DEEF$	:	0A0A&!0L0L  B HHVHHJJJJqr&   c           	         | j         d         }|                                 s|st          j        g g g g g g g           S g g g }}}|                                  |rddd||g}ndd|g}|                     |          }|                    d          D ]}	|	                    d          }
|
dk    r|	|
dz
  |
         |	|
dz   d          }}|d	k    r|                    |           T|d
k    r|                    |           p|dk    r|                    |           g g g g f\  }}}}g d}|	                    d          r|dgz  }|	                    d          r|dgz  }|                     |          }t                      }|                    |           |                    |           |                    |           |                    d          D ]}	|	s|	dd         }|	                    d          dk    r!|	dd                              d          \  }}n|	dd          }d }|                    |           |r|                    |           |dk    r|                    |           |dk    r|                    |           |	                    d          rG|                     dg          }|                    d          D ]}||vr|                    |           t          j        |||||||          S )Nr   s	   diff-tree   --no-renamesre  r  r     	r
     M   A   D)rM  s   --porcelains   -zr  s   --untracked-files=allignoreds	   --ignored    r   r   r  s   ??s   !!rV  s   ls-files)r8  r  r   r   r  r  r  r  r  rz   r  r   r   )r5   r   r   r  r  r  removedr  r  r  tabr   re   r  r  r'  rV  changedfilesst	filename1	filename2s                        r$   r   zgitsubrepo.status  sm   {1~ 	>T 	>>"b"b"b"===#%r2% 	=#_eT4HGG$ot<Gw''IIe$$ 
	" 
	"D))E""CbyyS1Ws]+T#'))_AF~~""""4Q4q!!!+-r2r>('544488I 	2011G88I 	&~%Gw''uuH%%%E"""G$$$IIe$$ 	* 	*D acByy1$$'+ABBx~~e'<'<$	99 H	 	Y''' ,  +++U{{y))))uy)))88G 	$""K=11CYYu%% $ $L((LLOOO~eWgw
 
 	
r&   c                    | j         d         }ddg}|d         r|                    d           n|                    d|j        z             |j        r|                    d|z  d|z  g           n|                    d	|z  d
|z  g           |j        r|                    d           |j        r|                    d           |                     |                     dg                    dk    r|j	        r|                    d           |                    |           |r|                    |           d}	|
                                r|	|                     |          dz   z  }	nc|                     |          }
d |
j        |
j        |
j        fD             }|D ]-} ||          r |	|                     |d|gz             dz   z  }	.|	                                r|                    |	           d S d S )Nr   r  r"  r  s   --stats   -U%ds   --src-prefix=%s/s   --dst-prefix=%s/s   --src-prefix=a/%s/s   --dst-prefix=b/%s/s   --ignore-all-spaces   --ignore-space-changer,  )r         s   --ignore-blank-linesr&   r  c                     g | ]	}|D ]}|
S r<   r<   )r   sublistre   s      r$   r   z#gitsubrepo.diff.<locals>.<listcomp>  s?              r&   s   --)r8  r  contextnoprefixr  ignorewsignorewsamountr  r  ignoreblanklinesalwaysr   r  r  r)  r!  rw  )r5   rN   r   r   r   r   r   r  r&  r2  r,  r   re   s                r$   r   zgitsubrepo.diff  sZ   A(< 	3JJy!!!! JJw!11222 	JJ$v-/BV/KL    JJ&/1F1OP    	.JJ,---" 	1JJ/000T--|n==>>)KK) L JJ.///

5 	JJu<<>> 	Id&&s++e33FFU##B  "RXrzB  E
  I I588 Id..seQZ/?@@5HHF<<>> 	HHV	 	r&   c                    | j                             t          d          |d         z             |                    d          s|                     d           }|j        }|D ]}t
          j                            | j        |          }t          j
        | j         | j        |          }| j                             t          d          |t
          j                            |          fz             t          j        | j                            |          |           |                    d          s|                     |d           g S )Nr  r   r  s#   saving current version of %s as %s
r  Tr  )rN   r   r   rz   r  r<  r!   r\   r   r   
backuppathrt  r  r  r   renamern   )	r5   r   r  r   r   rb   r   
parentnamebaknames	            r$   r  zgitsubrepo.revert  s.   q233hqkABBBxx$$ 	;[[&&FOE ; ;  W\\$*d;;
!,GT_j  =>>RW__W5567   DINN400'::::xx	"" 	/HHXH...	r&   c                     |d d         S )Nr  r<   r  s     r$   r   zgitsubrepo.shortid  s    RaRyr&   )NF)NFNr,  r-  r.  )'r8   r9   r:   r4   r  staticmethodr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rv  r  rK   rP   r   rz   r   r   r   r   r   r
  r   r   r   r  r   r  r  s   @r$   r  r  @  s           +O +O +OZ 	 	 \	 ! ! \!FA A A A
 
 
 

:% :% :% :%x- - -9 9 9        Q Q QA A A& & &,          0          V V V Vp      $   0 0 0 0d $ $ $L $ $ $*$ $ $ $L   $ A
 A
 A
F / / /b   ,      r&   r  )rr   rt   rs   )FT)<r~  r  r<  r.  r  r  rC   r  xml.dom.minidomr>  i18nr   r  r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r'  utilsr   r   r   r   r   r*  rA   rv  r/  r%   r,   r3   r.   rK   rT   rf   rq   ry   r~   r0   r   r   r1  r  r  r{   r<   r&   r$   <module>rD     sn     				 				      



                    
                                            
%#
#
"  K K K
0 0 0 0 05; 0 0 0  *# # #&4 4 4(	M 	M 	M   @ @ @(> > > >(A A A0aL aL aL aL aL aL aL aLHq	' q	' q	' q	' q	' q	' q	' q	'hF3 F3 F3 F3 F3 F3 F3 F3R` ` ` ` ` ` ` `H 	 	r&   