
    q&fw&                       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jN                  Z'ejP                  Z(ejR                  Z)ejT                  Z*d Z+d Z, G d	 d
ejZ                        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;y)    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
                  s2t        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   sR     ''(=>LL!A88}}T\\!&&12K    c                 r    t        t        j                  t        |             j	                               dd S )zEget a unique filename for the store hash cache of a remote repositoryr      )r   r   sha1r%   digest)
remotepaths    r$   _getstorehashcachenamer,   B   s,    x}}-j9:AACDQrJJr&   c                       e Zd ZdZd Zy)SubrepoAbortzEException class used to avoid handling a subrepo error more than oncec                     |j                  dd       | _        |j                  dd       | _        t        j                  j
                  | g|i | y )Nsubrepocause)popr0   r1   r
   Abort__init__)selfargskws      r$   r4   zSubrepoAbort.__init__J   sB    vvi.VVGT*
T/D/B/r&   N)__name__
__module____qualname____doc__r4    r&   r$   r.   r.   G   s
    O0r&   r.   c                       fd}|S )Nc                    	  | g|i |}|S # t         $ r}|d }~wt        j                  $ rY}t        |       }|j                  dz   t        d      |z  z   }t        ||j                  |t        j                               d }~ww xY w)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,C 
  	H{{ 	 &G

T!A&@$AG$KK  rww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  }| j                  |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   sb    $

 _eV,- $
 _eV,- ??3""r&   c                    |j                         D ]  \  }}}t        |      D ]  \  }}|j                         |k(  s||=  n |j                  |      j                         dk7  rU|D ]c  }|j                         dk(  s| j	                  t        d      |j                  |      z         |j                  |j                  ||             e  y )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udO 	DAqwwyF"G	 << &&(F2 		4AwwyG#% hhw'	( 

3;;w23		44r&   c                 b   |j                  d      sd|v st        j                  |      |k7  r!t        j                  t        d      |z         t        j                  | j                        |       | j                  j                  |      r!t        j                  t        d      |z        y )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0E0Mkk<=D
 	
 $H#D)yykk!CDtKLL r&   TF)   hg   git   svnc                 ~   | j                  ddd      s)t        j                  t        d      t        d            t        j                  |d      }| j                  dd|z  |      s,t        j                  t        d	      |z  t        d            |t        vr!t        j                  t        d
      |z        y )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kk%&?@
 	

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

 5kk!67$>?? r&   c                     ddl m} |a| j                         }t        ||       | j                  |   }t        |j                  |d          |r|d   | j                  |      |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!LLEtwwa!q3::d+U1X6q?3eBQi==r&   c                     ddl m} |a| j                         }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      sy     	
B88:DdD!LLEtww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'y)+abstractsubrepoc                 ^    |j                         j                  | _        || _        || _        y)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                      y)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                      y)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    
 r&   c                     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                 X    | j                  ||      rt        d      t        |       z  S y)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  s8     ::<:AABZF   Br&   Nc                 \    | j                  |d      }|rt        j                  ||      y)z+raise Abort if subrepository is ``dirty()``Tr   rw   N)r   r
   r3   )r5   r   r@   r   s       r$   bailifchangedzabstractsubrepo.bailifchanged  s0    &&L$&O++k55 r&   c                     t         )zpcurrent working directory base state, disregarding .hgsubstate
        state and working directory modificationsr   r5   s    r$   	basestatezabstractsubrepo.basestate  s
     "!r&   c                      y)z7check if path is a subrepository within this repositoryFr<   r   s     r$   checknestedzabstractsubrepo.checknested  s    r&   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                 V    | j                   j                  d|t        d      fz         y)Ns   %s: %ss   addremove is not supportedr   rN   r[   r   )r5   matcherr   r   r   s        r$   	addremovezabstractsubrepo.addremoveG  s%    Y&!,I*J!KKLr&   c                      yNr   r<   )r5   r   fm
fntemplater   r   s         r$   catzabstractsubrepo.catK      r&   c           	      8    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9r&   c                      y r   r<   )r5   rN   diffoptsnode2r   r   r   s          r$   diffzabstractsubrepo.diffQ  s    r&   c                      yr   r<   )r5   rN   destr   s       r$   outgoingzabstractsubrepo.outgoingT  r   r&   c                      y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                      y)zreturn file flagsr&   r<   )r5   r   s     r$   	fileflagszabstractsubrepo.fileflagsb  s    r&   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                      y)z)handle the files command for this subrepor   r<   )r5   rN   mr   r   fmtsubreposs          r$   
printfileszabstractsubrepo.printfilesj  s    r&   c           
         |'| j                         D cg c]  } ||      s| }}n| j                         }t        |      }t        |       }| j                  j	                  t        d      |z  t        d      |      }	|	j                  d       |D ]Z  }
| j                  |
      }d|v xr dxs d}d|v }|j                  ||
z   ||| j                  |
|             |	j                          \ |	j                          |S c c}w )	N   archiving (%s)   files)unittotalr      xi  i     l)r   lenrA   rN   makeprogressr   updater   addfiler   	incrementcomplete)r5   archiverr   r   r   re   r   r   relpathprogressr   flagsmodesymlinks                 r$   archivezabstractsubrepo.archiven  s    $

91aQ9E9JJLEE
T"77'' 7*8E ( 
 	 	!DNN4(E5=*U3eDemGtWdmmD&.I  	! 	% :s
   DDc                      y)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	                 R    |j                  t        d      | j                  z         y)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  s'     	:;djjH	
 r&   c                 d    | j                   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  s7    ;<{HQK()	
 	r&   c                     |S r   r<   r5   revids     r$   shortidzabstractsubrepo.shortid  s    r&   c                      y)zH
        convert this repository from shared to normal storage.
        Nr<   r   s    r$   unsharezabstractsubrepo.unshare  r  r&   c                      y)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     r&   c                     t        j                  | j                  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     zz$))..*//44TZZ@AAr&   c                     | j                   j                  t        | j                  j	                               | j
                        S zCreturn path to this subrepository as seen from outermost repository)rn   r^   reporelpathr   rp   r   r   s    r$   _relpathzabstractsubrepo._relpath  s/     yy  TYY^^-=!>

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      s    "6"
""""":""+,(
 B B L Lr&   r   c                   2    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d-d       Zd Zd Zed        Zed        Zed        Zd Zed.d       Zed        Zed        Zed        Zed        Z ed        Z!d Z"d Z#ed         Z$ed/d!       Z%d" Z&ed#        Z'ed$        Z(ed%        Z)d& Z*d' Z+ed(        Z,d.d)Z-e	d*        Z.e	d+        Z/ xZ0S )0	hgsubrepoc                    t         t        |   ||       || _        |j	                         }|j                  t        j                  |            }|xr |j                  j                  d|z         }t        j                  j                  |      }t        j                  j                  t        j                  j                  t        j                  |                  }	|	|k7  r!t        j                   t#        d      |z        t$        j'                  |j(                  ||      | _        t        j                  j                  | j*                  j,                        t        j                  j                  |      k7  r.t        j.                  d|| j*                  j,                  fz        ||j1                         u r| j*                  j1                         | _        | j*                  j2                  | _        dD ]B  \  }
}|j2                  j5                  |
|      }|s%| j2                  j7                  |
||d       D | j2                  j7                  ddd	d       | j9                  ||d
   |       y )Ns   %s/.hgrj   creates9   failed to reject unsafe subrepo path: %s (expanded to %s)))   uis   commitsubrepos   subrepor1  s   _usedassubrepos   Truer   )superr-  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   r0  	norm_root	real_rootskv	__class__s                r$   r4   zhgsubrepo.__init__  s   i'T2HHJwwt~~d+,DQVV]]9t3C%D!D GG$$T*	GG$$RWW%5%5dood6K%LM		!++@ADH  ]]188T&]A
77DJJOO,0@0@0FF((-04djjoo/FG  ..0DJ**--0 	7DAqAq!A!!!Q:6	7
 	%!2GZHq%(F+r&   c                 X    t        j                  | j                  t        |       |       y r   )r   r   r=  rA   r   s      r$   r   zhgsubrepo.addwebdirpath  s    djj*T*:GDr&   c                     | j                   j                         5  | j                  |      cd d d        S # 1 sw Y   y xY wr   )r=  lock_storecleanr   s     r$   r   zhgsubrepo.storeclean  s3    ZZ__ 	*##D)	* 	* 	*s   6?c                     d}| j                  |      }| j                  |      D ]  }|t        |d       k7  sd} n |rt        |d       d u }|S )NTF)_calcstorehash_readstorehashcachenext)r5   r!   clean	itercachefilehashs        r$   rM  zhgsubrepo._storeclean  se    ''-	006 	H4	400	  D)T1Er&   c              #      K   d}dt        |      z   | j                  j                  }|D ]F  }t        t	        j
                  |j                  |            j                               }d||fz   H yw)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%   r=  r   r   r   r)   tryreadr*   )r5   r+   filelistr   relnamerT  s         r$   rO  zhgsubrepo._calcstorehash  sp      O*:666jjnn 	5G8==W)=>EEGHH'8!444	5s   A5A7c                 r    t        j                  | j                  j                  j                  d            S )Ns   cache/storehash)r#  r   r=  r\   r   s    r$   _cachestorehashvfszhgsubrepo._cachestorehashvfs  s%    zz$**..--.@ABBr&   c                 P    t        |      }| j                  j                  |d      S )z7read the store hash cache for a given remote repository   r)r,   r[  tryreadlines)r5   r+   	cachefiles      r$   rP  zhgsubrepo._readstorehashcache  s%    *:6	&&33ItDDr&   c                     t        |      }| j                  j                         5  t        | j	                  |            }| j
                  }|j                  ||dd       ddd       y# 1 sw Y   yxY w)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,   r=  rL  listrO  r[  
writelines)r5   r+   r_  	storehashr   s        r$   _cachestorehashzhgsubrepo._cachestorehash  si     +:6	ZZ__ 	NT00<=I))CNN9ieNM	N 	N 	Ns   <A++A4c                     | j                   j                         | j                  d   S | j                  d   }| j                  |   S )zBfetch the context for this subrepo revision, possibly a workingctxNr   )r   revr=  r4  )r5   rg  s     r$   _getctxzhgsubrepo._getctx  s<    99==?"::d##++a.C::c?"r&   c                     | j                   _        | j                   _        |rdg fd}t         j                   d      }t         j                   dd      } |d|       ||k7  r	 |d|        j                   j                  j                  dt        j                  d	j                                     y y )
Ns   [paths]
c                 t    |r5j                  d| |fz         j                  j                  d| |d       y y )NrV  s   pathsr2  )r  rN   rA  )keyvaluelinesr5   s     r$   addpathconfigz*hgsubrepo._initrepo.<locals>.addpathconfig-  s8    LLe!<=GG%%hUJG r&   F)abortTs   defaults   default-pushrV   r&   )	r=  
_subparent
_subsource
_abssourcer   writer   tonativeeolr\   )r5   
parentrepor   r0  rn  defpathdefpushpathrm  s   `      @r$   rB  zhgsubrepo._initrepo%  s     *

 &

!NEH
 !59G$TZZUCK*g.+%o{;JJNN  $*:*:388E?*KL r&   c           
      H   | j                   j                         5  | j                   j                  j                  | j                         5  t	        j
                  || j                   ||||fi |cd d d        cd d d        S # 1 sw Y   nxY wd d d        y # 1 sw Y   y xY wr   )r=  wlockdirstatechanging_filesr   r   r   s          r$   r   zhgsubrepo.add:  s     ZZ 		!4!4!C!CDJJ!O 		;;

 		 		 		 		 		 		 		s#   0B%B0	BB	BB!c           	      x   t        j                   |      }d|d<   | j                  j                         5  | j                  j                  j	                  | j                        5  t        j                  | j                  ||||      cd d d        cd d d        S # 1 sw Y   nxY wd d d        y # 1 sw Y   y xY w)NTrv   )copyr=  ry  rz  r{  r   r   )r5   r   r   r   r   s        r$   r   zhgsubrepo.addremoveK  s    
 yy [
 ZZ 	!4!4!C!CDJJ!O 	$$

	 	 	 	 	 	 	s#   0B0%#B	B0B$	 B00B9c           	          | j                   d   }| j                  |   }t        j                  | j                  | j                  |||||fi |S r   )r4  r=  r   r   rN   )r5   r   r   r   r   r   rg  r   s           r$   r   zhgsubrepo.cat_  sL    kk!njjo{{GGTZZeRV
GK
 	
r&   c           
      t   	 | j                   d   }| j                  |   }| j                  |   } | j                  j                  ||fi |S # t        j                  $ rW}| j
                  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"
)
r4  r=  r   r
   RepoLookupErrorrN   r[   r   rA   r   )r5   r   r   rev1ctx1ctx2insts          r$   r   zhgsubrepo.statusg  s    
	>;;q>D::d#D::d#D$4::$$T48488$$ 	>GGLL@AD)*+ >>"b"b"b"==	>s   A
A B7 AB2,B72B7c                 x   	 t        | j                  d         }|t        |      }t        j                  || j                  || j                  |   | j                  |   |f|dd| y # t
        j                  $ r<}| j                  j                  t        d      |t        |       fz         Y d }~y d }~ww xY w)Nr   T)r   listsubreposr  )r   r4  r   diffordiffstatr=  r
   r  rN   r[   r   rA   )	r5   rN   r   r   r   r   r   node1r  s	            r$   r   zhgsubrepo.diffu  s    	A'E  E
%%



5!

5!
 !
 
 $$ 	GGLL@AD)*+ 	s   A'A* *B9=2B44B9c                 P   | j                  | j                  dz          | j                         }|r|D cg c]  } ||      s| }}| j                  d   }| j                  |   }t	        j
                  | j                  |j                         t	        j                  | j                  |      fg       t        j                  | |||      }	|j                  D ]D  }
t        ||
d      }t        j                  |
|      }||
z   dz   }|	|j                  ||||      z  }	F |	S c c}w )N)rr   r   T   /)_getr4  r   r=  r   prefetchfilesrg  
matchfilesr   r  r   r0   r   subdirmatcher)r5   r   r   r   r   r   re   rg  r   r   subpathrF  submatch	subprefixs                 r$   r  zhgsubrepo.archive  s   		$++()

 %21qQ2E2kk!njjoJJ#'')W%7%7

E%JKL	
  ''hF|| 	FGWd+A--gu=H(4/IQYYxHfEEE		F
  3s   D#D#c                     | j                   d   }|dk(  r|sy| j                  d    }||j                         j                         k7  r|sy|j	                  |      S )Nr   r&   T)r   )r4  r=  p1r   rP   )r5   r   r   rC  ws        r$   rP   zhgsubrepo.dirty  sS    KKN8LJJt

\wwww''r&   c                 <    | j                   d   j                         S N   .)r=  r   r   s    r$   r   zhgsubrepo.basestate  s    zz$##%%r&   c                 j    | j                   j                  | j                   j                  |            S r   )r=  _checknestedr5  r   s     r$   r   zhgsubrepo.checknested  s&    zz&&tzz'7'7'=>>r&   c                 :   | j                  d      s| j                  d   j                         S | j                  j	                  dt        |       z         | j                  j                  |||      }|s| j                  d   j                         S t        |      S )NTr  s   committing subrepo %s
)rP   r=  r   rN   debugrA   r   )r5   r   r   r   ns        r$   r   zhgsubrepo.commit  s     zz$::d#''))0:d3CCDJJdD$/::d#''))1vr&   c                 D    | j                   |xs d   j                         S r  )r=  r   r   s     r$   r   zhgsubrepo.phase  s    zz%-4(..00r&   c                     | j                   j                  t        d      t        |       z         t        j                  | j                  | j                  j                  d       y )N   removing subrepo %s
F)rN   noter   rA   r   rR  r=  nullidr   s    r$   r   zhgsubrepo.remove  sB     	Q/0:d3CCD
TZZ..6r&   c                     |\  }}} j                   j                  }| j                   j                         v r)t         j                         dk7  s|j	                         sy| j                   _        t         j                          fd}t         j                         dk(  rC j                   j                  j                          |j	                         rt        j                        r j                  j                  t        d      t               fz          |       }	 t        j                   j                   j                  j                   | j                   j"                  dd      }|j%                          |j'                          _         n'|j	                         rS j                  j)                  dd      }	|	rt+        j,                  |	      }	|	 j                  j)                  dd	      d
}
ni }
 j                  j                  t        d      t               t/        j0                        fz          |       }	 t        j3                   j                   j                  j                   i | j                   j"                  d|
      \  }}|j%                          |j'                          _          j5                  ||d        j7                         y j                  j                  t        d      t               t/        j0                        fz          j9                        } |       }	 t;        j<                   j                   |       |j%                          |r j7                         y# |j%                          w xY w# |j%                          w xY w# |j%                          w xY w)Nr   Tc                  F    t         j                   j                  i       S r   )r   peerr=  )r5   srcurls   r$   <lambda>z hgsubrepo._get.<locals>.<lambda>  s    "''$**b&9 r&   s   sharing subrepo %s from %s
F)r   	bookmarkss   share   pools
   poolnaming)r  s   mode   cloning subrepo %s from %s
)r   	shareoptsr/     pulling subrepo %s from %s
)r=  rp  r?  r   sharedrq  rr  r   rmtreer   islocalrN   r   r   rA   sharer<  rm   closerQ   r@  r   r   r   hidepasswordclonerB  re  r   r   pull)r5   r   r   revisionr|   ru  getpeerr  r  poolr  otherclonedcleansubr  s   `             @r$   r  zhgsubrepo._get  s    !&$ZZ**
tzz,,..4::!#:+<+<+> &

DJJ' :tzz?aJJNN!!#   "rzz&'956!$'01 y	!XX

--44

$"' & F JJL#\\^
 $$&77>>(G<D#t4 "&!%-!H!I
 !#I56!$')=)=f)EFG y
!$&HH

--44

$"+ %- %ME6 JJL#\\^
NN:vdN;  (  GGNN12d#W%9%9&%ABC v.H9Ddjj$/

$$V,e JJL@ JJL 

s&   ,AN AN# 
 N8 N #N58O
c                    | j                  |      }|\  }}}| j                  }|j                  j                  d| j                  z         |r]|j                         }||   }	|	j                         r8|j                  j                  t        d      |dd | j                  fz         |}|rt        j                  ||          y t        j                  ||          y )Ns   getting subrepo %s
s,   revision %s in subrepository "%s" is hidden
r   r(   )r  r=  rN   r  r   r?  hiddenr[   r   r   clean_updater   )
r5   r   r   inrepor   r  r|   rp   urepor   s
             r$   rz   zhgsubrepo.get$  s    5!!&$zz-

:;OO%E/Czz|FG"~tzz23 tH~.LLh(r&   c                 l     j                          j                  d    j                  d      j                         fd} j                  d    } j                         r=k7  r/t	         j
                   |j                               r |        y  |        y y  |        y )Nr  r   c                      k(  rlj                         j                         k(  rKj                  j                  dt              z         t        j                  j                  d          y  k(  r(j                  j                  dt              z         y j                  j                  dt              z         t        j                  d       y )Ns   updating subrepository "%s"
r   s   skipping subrepository "%s"
s   merging subrepository "%s"
F)remind)branchrN   r  rA   r   r   r=  r   )anccurdstr5   r   s   r$   	mergefuncz"hgsubrepo.merge.<locals>.mergefunc?  s    czcjjlcjjl:4z$7GG 		$**eAh/4z$7GG 3j6FF U+r&   )r  r=  ancestorrP   rT   rN   )r5   r   r  wctxr  r  r  s   ``  @@@r$   r   zhgsubrepo.merge8  s    		%jjjjq"ll3	, 	,  zz$::<cz $

c3GK H
 Kr&   c                    |j                  d      }|j                  d      }|j                  d      }| j                  d   }|j                  }t        |      D ]'  }|j	                  |      j                  |      dk(  s' y t        | j                  d      }|sW| j                  |      rF| j                  j                  t        d      t        |       t        j                  |      fz         y | j                  j                  t        d	      t        |       t        j                  |      fz         t        j                  | j                  d|i|      }		 t!        j
                  | j                  |	||
      }
|	j#                          | j%                  |       |
j&                  S # |	j#                          w xY w)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   r=  r   sortedrO   r   rr  r   rN   r   r   rA   r   r  r   r  r   r  re  cgresult)r5   r   r  r  sshcsubsrF  dsturlr  rF   s              r$   r   zhgsubrepo.pushY  sp   "HH]+	hhv JJtzz 	AuuQx}}T"a'	 DJJ-v&NO!$')=)=f)EFG +,$!5!5f!=>?	
 

VSM6:	--

E5INCKKM 	V$||	 KKMs   #F, ,F>c                 
   d|v sd|v r9t        j                   |      }|j                  dd        |j                  dd        t        j                  | j                        }t
        j                  || j                  |||      S Ns   revs   branch)r  )r}  r2   r   repo_rel_or_abs_sourcer=  r   r   )r5   rN   r   r   r  s        r$   r   zhgsubrepo.outgoing|  sj    T>Y$.99T?DHHVT"HHY%44TZZ@{{2tzz4w{GGr&   c                 
   d|v sd|v r9t        j                   |      }|j                  dd        |j                  dd        t        j                  | j                        }t
        j                  || j                  |||      S r  )r}  r2   r   r  r=  r   r   )r5   rN   r   r   r  s        r$   r   zhgsubrepo.incoming  sj    T>Y$.99T?DHHVT"HHY%44TZZ@{{2tzz64{IIr&   c                 z    | j                   d   }| j                  |   }|j                         j                         S r   )r4  r=  manifestkeys)r5   rg  r   s      r$   r   zhgsubrepo.files  s1    kk!njjo||~""$$r&   c                     | j                   d   }| j                  |   |   j                         }|r| j                  j                  ||      }|S r   )r4  r=  data
wwritedata)r5   r   r   rg  r  s        r$   r   zhgsubrepo.filedata  sH    kk!nzz#t$))+::((t4Dr&   c                 `    | j                   d   }| j                  |   }|j                  |      S r   )r4  r=  r  )r5   r   rg  r   s       r$   r   zhgsubrepo.fileflags  s*    kk!njjoyyr&   c           	          | j                   j                         | j                  d    }n| j                  d   }| j                  |   }t	        j
                  |||||||      S r   )r   rg  r=  r4  r   r   )	r5   rN   r   r   r   r   r   r   rg  s	            r$   r   zhgsubrepo.printfiles  sW     99==?"**T"C++a.C**S/C}}Ra2sHEEr&   c           
         | j                   j                         | j                  d    }n| j                  d   }| j                  |   }|j	                  |||      g}|j
                  D ]Q  }|j                  |      }	 |j	                  |||      }	t        j                  ||	|      }
|j                  |
       S t%        |      dk(  r|d   S t        j&                  |      S # t        j                  $ rM | j                  j                  t        d      | j                  j!                  t#        |       |      z         Y w xY w)Nr   r   s#   skipping missing subrepository: %s
r   )r   rg  r=  r4  r   r   rO   r   prefixdirmatcherr  r
   LookupErrorrN   r   r   rn   r^   r&  r   unionmatcher)r5   r   r   r   r   rg  matchersr  rO   smpms              r$   r   zhgsubrepo.matchfileset  s)   99==?"**T"C++a.C**S/C$$S$e$<=|| 	G'''"C%%c4u%=..w%H#	 x=AA;$$X.. $$ =>ii''D(97CDs   ?=C&&AEEc                 B    | j                   d    }|j                  |      S r   )r=  rW   )r5   r   r   s      r$   rW   zhgsubrepo.walk  s    jjxxr&   c                 `   | j                   j                         5  | j                   j                  j                  | j                         5  t	        j
                  | j                  | j                   |||d||      cd d d        cd d d        S # 1 sw Y   nxY wd d d        y # 1 sw Y   y xY w)NT)r  r  )r=  ry  rz  r{  r   r  rN   r
  s         r$   r  zhgsubrepo.forget  s     ZZ 
	!4!4!C!CDJJ!O 
	>>

'	
	 
	 
	 
	 
	 
	 
	#   0B$1B<	B$B	B$$B-c	                 `   | j                   j                         5  | j                   j                  j                  | j                         5  t	        j
                  | j                  | j                   |||||||	      cd d d        cd d d        S # 1 sw Y   nxY wd d d        y # 1 sw Y   y xY wr   )r=  ry  rz  r{  r   r   rN   r  s	            r$   r  zhgsubrepo.removefiles  s      ZZ 	!4!4!C!CDJJ!O 	>>


	 	 	 	 	 	 	r  c                 "   | j                   j                  t        d      |d   z         |j                  d      s/|j	                         }d |d<   |d   |d<    | j
                  |i | |j                  d      s| j                  |d	       y y )
N   reverting subrepo %s
r   	no_backupr   r   rg  dry_runTr   )rN   r   r   rz   r}  
filerevertr  s       r$   r  zhgsubrepo.revert  s     	q23hqkABxx$ 99;DDL"1+DKDOOT*T* xx	"HHXH. #r&   c                    | j                   |d      }|j                  d      rdg}ng }| j                   j                         5  | j                   j                  j	                  | j                         5  t        j                  | j                  | j                   |g|i | d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nrg  alls   set:modified())r=  rz   ry  rz  r{  r   r  rN   )r5   r  r   r   s       r$   r  zhgsubrepo.filerevert  s    jje%88E?%&DD
 ZZ 	D!4!4!C!CDJJ!O 	DNN477DJJCdCdC	D 	D 	D 	D 	D 	Ds$   0C40B5$C5B>	:CC
c                     |d d S )Nr(   r<   r  s     r$   r  zhgsubrepo.shortid  s    Sbzr&   c                     ddl m} |a| j                  j                         r1| j                  j                  t        d      | j                  z         t        j                  | j                  | j                         y )Nr   r   s   unsharing subrepo '%s'
)	r   r   r=  r  rN   r   r   r'  r  )r5   r   s     r$   r  zhgsubrepo.unshare  sS     	
 ::GGNN189DMMIJ


477DJJ'r&   c                    	 | j                   d   }| j                  j                         |   }|j                         rzt	        d      | j
                  t        | j                  j                               fz  }|rt        j                  |      | j                  j                  j                  d|z         y# t        j                  $ r} t	        d      | j
                  t        | j                  j                               fz  }|rt        j                  |      | j                  j                  j                  d|z         Y yw xY w)Nr   s%   subrepo '%s' is hidden in revision %ss   %s
r   s%   subrepo '%s' not found in revision %s)r4  r=  r?  r  r   r'  r   r   noder
   r3   rN   r[   r  )r5   r   rg  r   rS   s        r$   r!  zhgsubrepo.verify1  s   	++a.C**'')#.Czz| @AMM$))..*+E 
 ++c**JJMM&&w}5$$ 	 <=diinn&'A C
 kk#&&

""7S=1	s   B6B9 9BE	E	c                 .    | j                   j                  S )z.return own wvfs for efficiency and consistency)r=  rn   r   s    r$   rn   zhgsubrepo.wvfsP  s     zzr&   c                 ,    t        | j                        S r%  )r&  r=  r   s    r$   r'  zhgsubrepo._relpathU  s     4::&&r&   r*  r(  r)  r   )1r8   r9   r:   r4   rK   r   r   rM  rO  r+  r[  rP  re  rh  rB  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__rI  s   @r$   r-  r-    s    ,D E E*5 C CE

N# M M(     & 
 
 > >  0  $ ( (&? 	 	 1 1 7 7Yv ) )&  @    D H H J J % %

 F F / /2  "  8 / /*D ( ($>   ' 'r&   r-  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        y )Nrt   s+   'svn' executable not found for subrepo '%s')r3  r  r4   r4  r   findexe_exer
   r3   r   r   r5   r   r!   r   r   rI  s        r$   r4   zsvnsubrepo.__init__]  s\    j$(d3$$V,	yy++@ADJJN  r&   c           
      X   | j                   g}i }| j                  j                         s+t        j                  |d<   |d   dv r|j                  d       t        t        d      rt        t        d      |d<   |j                  |       |Z| j                  j                  | j                  j                         j                  | j                  |      }|j                  |       t        t         j"                        }|j%                  d      }|r||d<   |d= d	|d
<   t        j&                  t)        j*                  t,        j.                  |      fdt,        j0                  t        j                  t        j                  t-        j2                  |      d|}	t5        t6        j8                  |	j;                               \  }
}|j=                         }|sR|	j>                  r&tA        jB                  |xs d|	j>                  z        |r| j                  jE                  |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  hasattrgetattrextendrn   r^   r   rp   origrootr   dictr	   environrz   Popenr   rapplyr   tonativestrclosefdstonativeenvmapr   fromnativeeolcommunicatestrip
returncoder
   r3   r[   )r5   commandsfilenamefailokcmdextrakwr!   r  lc_allpr  r  s               r$   _svncommandzsvnsubrepo._svncommandf  s   yykww""$  *GG
 {AA

/0:12 (/z;M'NGO$

899$$		 ))4::xD JJt8##$#!CLI"NOOH00#6
''????$$S)
 
 T//A||kkC4q||C  Ve^,v~r&   c                    | j                  ddgd       \  }}t        j                  d|      }|st        j                  t        d            t        |j                  d            t        |j                  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._svnversion  ss    &&:& ' 
 II'0++a CDEEAGGAJQWWQZ11r&   c                 :    | j                   j                  d       S )N   .svnrn   r7  r   s    r$   _svnmissingzsvnsubrepo._svnmissing      99##G,,,r&   c                    | j                  ddg      \  }}t        j                  j                  j	                  |      }|j                  d      }d\  }}|rlt        j                  |d   j                  d            xs d}|d   j                  d      }|r+t        j                  |d   j                  d            xs d}||fS )	Ns   info   --xmlentry)   0r<  r   r  r<  r   )	r)  xmldomminidomparseStringgetElementsByTagNamer   bytestrgetAttribute)r5   r1  r2  docentrieslastrevrg  commitss           r$   _wcrevszsvnsubrepo._wcrevs  s     &&':;ggoo))&1**73!""71:#:#::#FGO4Caj55h?G$$WQZ%<%<Z%HI   ~r&   c                 (    | j                         d   S )Nr   )rH  r   s    r$   _wcrevzsvnsubrepo._wcrev  s    ||~a  r&   c                    | j                  ddg      \  }}g g g }}}t        j                  j                  j	                  |      }|j                  d      D ]  }|j                  d      }|s|d   j                  d      }	|d   j                  d      }
|j                  d      j                  d	      }|	d
k(  r|j                  |       n|	dk(  r|j                  |       |	dvs|
dvs|j                  |        |D ]B  }|D ];  }||k(  s#|j                  |t        j                  z         s+ddt        |      fc c S  D t        |      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unversionedrP  )r   nonerQ  TF)r)  r=  r>  r?  r@  rA  rC  encoder  rk   r   ossepbool)r5   r1  r2  	externalschangesr   rD  erF  rM  rN  r!   exts                r$   
_wcchangedzsvnsubrepo._wcchanged  sd    &&	8'<=&("bG7	ggoo))&1))'2 	%A&&{3AQ4$$V,DaD%%g.E>>&)008Dz!  &"t$  66t$+	%,  	5D  53;$//#2F"GtG}445	5 G}eT']22r&   c                     | j                         r| j                  d   dk7  S | j                         }|d   xs	 |xr |d   }|s"| j                  d   | j                         v s|ryy)Nr   r&   r   r   FT)r7  r4  r[  rH  )r5   r   r   	wcchangedchangeds        r$   rP   zsvnsubrepo.dirty  se    ;;q>S((OO%	A,<7#;y|{{1~/<r&   c                     | j                         \  }}||k7  r(	 | j                  dd| j                  d   |fz  g       |S |S # t        j                  $ r Y |S w xY w)N   list   %s@%sr   )rH  r)  r4  r
   r3   )r5   rF  rg  s      r$   r   zsvnsubrepo.basestate  sp    ||~c>
  h$++a.')BBC  
 ;; 
s   &A AAc                    | j                         \  }}}|s| j                         S |rt        j                  t	        d            |rt        j                  t	        d            | j                  dd|g      \  }}| j                  j                  |       t        j                  d|      }	|	sT|j                         st        j                  t	        d            t        j                  |j                         d         |	j                         d   }	| j                  j                  | 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   
commitinfor2  newrevs
             r$   r   zsvnsubrepo.commit  s    (,'8$W>>##++a >?@@ ++a DEFF**Iud+CD
Cz":JG##%
 kk!$C"DEE++j335b9::#t''E6(BCAFGr&   c                    | j                         r2| j                  j                  t        d      | j                  z         y | j                  j                  t        d      | j                  z         | j                  j                  d       	 | j                  j                         j                  }|j                  |j                  | j                               y # t        $ r Y y 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    ::<GGLLCD** Q/04::=>		$'	IINN$))EU]]4::67 		s   AC   	C,+C,c                 |   |r| j                  ddg       dg}| j                  dk\  r|j                  d       |j                  d|d   |d   fz         t        j                  |d          | j                  |d	
      \  }}t        | j                  | j                  d       t        j                  d|      shd|v r:| j                         d d dk(  r$| j                          | j                  |d       y t        j                  |xs |j                         d         | j                  j!                  |       y )Ns   revert   --recursiver  )r         --forcera  r   r   T)r$  r5  s   Checked out revision [0-9]+.s-   is already a working copy for a different URLr   r(  Fr  r	  )r)  r3  r  r   checksafesshrf   rN   rn   r-  r.  r[  r   rz   r
   r3   re  r   )r5   r   r   r6   r   r2  s         r$   rz   zsvnsubrepo.get'  s   i89}v%KK
# 	Ha%(334 	U1X&&&tD&9$''499g.yy8&A?3F!"1%7 %0++v}88:2>??vr&   c                     | j                   d   }|d   }| j                         }||k7  rG||k(  xs | j                         d   }t        | j                  | |||      r| j                  |d       y y y )Nr   r   F)r4  rJ  r[  rT   rN   rz   )r5   r   oldnewwcrevrP   s         r$   r   zsvnsubrepo.mergeB  sp    kk!nAh%<5L8DOO$5a$8ETWWdE5#>& ? r&   c                      yr*  r<   r   s     r$   r   zsvnsubrepo.pushL  s    r&   c                    | j                  g d      d   }t        j                  j                  j	                  |      }g }|j                  d      D ]  }t        j                  |j                  d            }|dk7  r-dj                  d |j                  d      d   j                  D              }|j                  |j                  d	              |S )
N)r`  rq  r:  r   r;  r|   s   filer   c              3   f   K   | ])  }|j                   |j                  k(  r|j                   + y wr   )nodeType	TEXT_NODEr  ).0r  s     r$   	<genexpr>z#svnsubrepo.files.<locals>.<genexpr>Y  s,      ::, s   /1r   rO  )r)  r=  r>  r?  r@  rA  r   rB  rC  r\   
childNodesr  rT  )r5   r1  rD  pathsrY  r|   r   s          r$   r   zsvnsubrepo.filesP  s    !!"EFqIggoo))&1))'2 		.A##ANN6$:;Dw77 //7:EE D
 LLV,-		. r&   c                 .    | j                  dg|      d   S )Ns   catr   )r)  r   s      r$   r   zsvnsubrepo.filedataa  s    $/22r&   )r&   Fr(  r)  )r8   r9   r:   r4   r)  r+  r3  r7  rH  rJ  r[  rK   rP   r   r   r   rz   r   r   r   r   r  r  s   @r$   r  r  \  s    0d 2 2-$!#3J     6     4 ' '   3r&   r  c                   l    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        |   ||       || _        |j	                         j                  |      | _        |j	                         | _        | j                          y r   )	r3  r  r4   r4  rp   r5  _abspathrp  
_ensuregitr  s        r$   r4   zgitsubrepo.__init__f  sJ    j$(d3
((.((*r&   c           	      T   	 d| _         | j                  dg      \  }}| j                  |      }|d	k(  r%| j                  j!                  t        d
             y |dk(  rt        j                  t        d            |dk(  r%| j                  j!                  t        d             y y # t        $ rv}t        d      }t        d      }|j                  t        j
                  k7  rAt        j                  || j                  t        j                  |j                        fz        t        j                  r	 d| _         | j                  dg      \  }}n# t        $ r}|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 }~d }~ww xY w)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	_gitnodirrn  r   errnoENOENTr
   r3   r   r	   
strtolocalstrerrorr   	iswindows_checkversionrN   r[   )r5   outr2  rY  genericerrornotfoundhinte2versionstatuss           r$   r  zgitsubrepo._ensuregitm  s   !	"(D~~|n5HC@ **3/J&GGLL;<=h&++AB  j(GGLLLMN )M  	HILGHLww%,,&kk DJJ0C0CAJJ0O#PP  ##*4D'#~~|n=HC xx5<</#kk!5 #jj	)
 ".  $kk(#zz8+>+>r{{+KLM   kk;<tzzI% # 	s=   B' '
H'1BH"6EH"	G,BG''G,,0H""H'c                 h   t        j                  d|       }|rMt        |j                  d            t        |j                  d            t        |j                  d            fS t        j                  d|       }|r5t        |j                  d            t        |j                  d            dfS y)Ns    ^git version (\d+)\.(\d+)\.(\d+)r   r      s   ^git version (\d+)\.(\d+)r   r	  )r-  r.  r/  r0  )r  r   s     r$   _gitversionzgitsubrepo._gitversion  s    II:C@
OS_c!''!*oFFII3S9
OS_a88r&   c                 R    t         j                  |       }|dk(  ry|dk  ry|dk  ryy)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   rr  r   r  )r      r   r  s   ok)r  r  )r  versions     r$   r  zgitsubrepo._checkversion  s9    0 ((- b=Yy r&   c                 0    | j                  |||      d   S )N)r  streamr   _gitdirr5   r"  r  r  s       r$   _gitcommandzgitsubrepo._gitcommand  s    ||H#f|=a@@r&   c                 @    | j                  |||| j                        S )N)r  r  r   )r  r  r  s       r$   r  zgitsubrepo._gitdir  s%    ~~#f$--  
 	
r&   c           
         | j                   j                  d| j                  dj                  |      fz         |t        j
                  j                         }d|d<   d|vrd|d<   d}| j                   j                  r$t        j                  t        j                  d      }| j                   j                  r%t        |      r|d	   d
k(  r|j                  dd       i }t        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(        j0                  t         j2                  |d|}|r|j4                  dfS |j4                  j7                         j9                         }|j;                          |j<                  d	k7  r^|j<                  dk7  rO|d	   }	|	dv r||j<                  fS t?        j@                  tC        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   openr8  devnull
_colormoder   insertr  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  s    	o		(8K(LLM;""'')CI +)CC%& 77==mmBJJ5G77#h-HQK74J OOAz*:12 (/z;M'NGO$OO$$t':':&;h&F
  4 4c:$$S)''??
 
 88T>!((--/'')	<<1!2qkG88,,++*+ALL$--89 
 $$r&   c                 :    | j                   j                  d       S )N   .gitr6  r   s    r$   _gitmissingzgitsubrepo._gitmissing  r8  r&   c                 (    | j                  ddg      S )Ns	   rev-parse   HEADr  r   s    r$   	_gitstatezgitsubrepo._gitstate  s    w 788r&   c                 :    | j                  g d      \  }}|rd }|S )N)r  r  r,  r  )r5   currentr2  s      r$   _gitcurrentbranchzgitsubrepo._gitcurrentbranch  s"    ||$JKGr&   c                     | j                  ddd|g      }|j                  d      d   }|j                  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  sP    	7E6BCyy"JJx 3x=0ABxr&   c                 :    | j                  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                 4    | j                  d||g      }||k(  S )N
   merge-baser  )r5   r1r2bases       r$   _gitisancestorzgitsubrepo._gitisancestor$  s#    B 78rzr&   c                 .    | j                  g d      dk(  S )N)   configs   --bool	   core.bare   truer  r   s    r$   
_gitisbarezgitsubrepo._gitisbare(  s     DEPPr&   c                 *    | j                  g d       y)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                 d   i }i }| j                  g d      }|j                  d      D ]  }|j                  d      \  }}|j                  d      s|j                  d      s:|j                  d      r|j                  d      r]|||<   |j	                  |g       j                  |        ||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._gitbranchmap1  s     

G
 IIe$ 		<D JJt,MHc>>.1#.. ; ~~./CLL4J&JsO!!(B/66s;		< :%%r&   c           	          i }|D ]u  }|j                  d      r|j                  dd      d   }| j                  dd|z  g      }|sC| j                  dd|z  g      }||d||j                  dd      d   fz  <   w |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._gittrackingG  s      		A||,-GGD!$Q'E%%y2E2M&NOF&&	3E3M'NO  )VSYYtQ5G5J,KK		 r&   c                 l    d|vr|j                  d      }|dk7  r	d|d | vr|S || _        t        |       S )Ns   ://   :r	  r  )findrq  rr  )r5   r   colons      r$   rr  zgitsubrepo._abssourceW  sC    KK%E{t6&5>9 $r&   c                 Z   | j                         rwt        j                  |       | j                  |      }| j                  j                  t        d      | j                  |fz         | j                  d|| j                  g       | j                  |      ry | j                  j                  t        d      | j                  | j                  d      fz         | j                  dg       | j                  |      s-t        j                  t        d      || j                  fz        y )Nr  s   cloner     origins   fetchs1   revision %s does not exist in subrepository "%s"
)r  r   rt  rr  rN   r   r   r'  r  r  r  r  r  r
   r3   )r5   r   r  s      r$   _fetchzgitsubrepo._fetch`  s      (__V,FGGNN12dmmV5LL NNHfdmm<=)-.}}dooi89:	

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

5!S4Z(dggtyy'2r&   c                      j                   j                  t        d      j                  z         j                   j                  t        d               dg       y )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  sR    GGLLGH--  GGLLKL eX&'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.get  s   !&$KKMFH%??@A~~8+  !?@^^)   (G!45  !?@!%!3!3!5
J		3		( :%Mh' 	%A((./0#ALL9I,J#$ 	% &'($$Z__%67!! =F
 !LLq)!,EeUF+,  HV,<!=vF 4#9#9#;;(6*+,h89dggtyy'2 Mr&   c                 N   | j                         r+t        j                  t        d      | j                  z        ddd|g}t
        j                  j                         }|r|d|gz  }|rt        j                  |d      |d<   | j                  ||       | j                         S )	N   subrepo %s is missingr  s   -arc  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    ++a 89DMMIJJ%-##%K&&C '/&6&6/'C"# 	#& ~~r&   c           	         	 \  }	} j                  |	        j                  d	 j                  d   g       j                           j	                  g d      \  }}	 fd} j                         rp j                         	k7  r\ j                          j                  d   k(  xs |dk7  }t         j                   | j                  d   d d 	d d       r |        y y y  |        y )Nr  r   r  c                       k(  rj                         n& j                  d   k7  rj                  ddg       t        j                  j
                  d       y )Nr   r  s   --no-commitr  )rz   r4  r  rf   rN   rn   )r  r  r5   r   s   r$   r  z#gitsubrepo.merge.<locals>.mergefunc  sO    xQ'  (NH!EFdggtyy'2r&   r      )	r  r  r4  r  r  rP   r  rT   rN   )
r5   r   r   r|   r  r  r  rP   r  r  s
   ``      @@r$   r   zgitsubrepo.merge  s    !&$FH%$++a. IJLL!EF	T	3 ::<~~8+(DKKN:Gdai GGT5$++a.!*<hrl K , Kr&   c                 (   |j                  d      }| j                  d   sy| j                         r+t        j                  t        d      | j                  z        | j                         \  }}| j                  d   |v r*|| j                  d      D ]  }|j                  d      s y |j                         D ]8  \  }}|j                  d      s| j                  | j                  d   |      s8 y dg}|r|j                  d       | j                         }|r| j                  | j                  d   |      s2| j                  j                  t        d      | j                  z         y	| j                  j                  t        d
      |j!                  dd      d   | j                  fz         | j#                  |d|gz         }	|	d   dk(  S | j                  j                  t        d      | j                  | j                  d   fz         y	)Nr  r   Tr  s   refs/remotes/origin/s   pushrs  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   r4  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  s   "{{1~++a 89DMMIJJ!%!3!3!5
J;;q>Z'A/  << 78  &++- 	 KAx||34&&t{{1~x@	 
 iJJz"((*&&t{{1~w?3 mm	$ GGNN>?==q)!,dmm<= ,,si%99:Cq6Q;GGLL1 ==$++a.1	2 r&   c                 6   | j                         rg S | j                  d dd      }t               }|j                  |j                  |j
                  |j                  fD ]  }	|j                  |	        |j                  }
|
j                  |j                                g }t        t        |
            D cg c]  } ||      s| }
}|
D ]  }|j                  |      }dg}|r|j                  d       |j                  s|s#|j                  t        d       ||      z         ||v r|r|j                  |       s|j!                  d      r| j#                  ||gz           |D ]%  }|j%                  t        d       ||      z         ' |S c c}w )NT)unknownrR  s   addr  s
   adding %s
r  s   %s already tracked!
)r  r   setmodifiedaddeddeletedrR  r   r  r  r   r  exactr  verboser   rz   r  r[   )r5   rN   r   r   r   r   r   rF  trackedlr   rejectedre   r  r  s                  r$   r   zgitsubrepo.addA  sl   IKKd$K7%**aggqyy!'': 	ANN1	 		U[[]#"3u:.;q%(;; 	0AKKNEhGu%zz		!N+hqk9:G|OOA&88I&  A3/	0  	?AGGA./(1+=>	? ' <s   8FFc                    | j                         ry | j                         r2| j                  j                  t	        d      | j
                  z         y | j                  j                  t	        d      | j
                  z         | j                  g d       | j                  j                         D ]U  \  }}|dk(  r|t        j                  k(  r| j                  j                  |       ;| j                  j                  |       W y )Nrk  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.removeh  s    ::<GGLLCD--   	Q/04==@A;<yy((* 	$GAtG|t||#		  #		  #	$r&   c                 F   d}| j                   \  }}|s|S | j                  ||       | j                  d|gd      }t        j                  |d      }	t        |       }
| j                  j                  t        d      |
z  t        d      	      }|j                  d       |	D ]  }|j                         rt        j                  |j                        }|r	 ||      s>|j                         r|j                  }nL|	j!                  |      }|r|j#                         }n(| j                  j%                  t        d
      |z         |j'                  ||z   |j(                  |j                         |       |dz  }|j+                           |j-                          |S )Nr   s   archiveT)r  zr|)fileobjr  r   r   )r   s   skipping "%s" (unknown type)r   )r4  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.archive~  sm   ;;LFH%
 $$j(%;D$I	ll948T"77'' 7*8 ( 
 	 	!Dzz|%%dii0EU5\zz|}}OOD)668DGGLL#B!Ce!KLVe^TYY

dKQJE #	!$ 	r&   c           	      z   | j                   d   }|j                         ry|j                         sy|j                         D ]w  }| j                  dd||fz  g      }t	        j
                  | j                  || j                  j                  ||            }	|	j                  |       |	j                          y y)Nr   r  s   %s:%s)pathnamer   )r4  anypatsr   r  r   makefileobjr   rn   r^   rs  r  )
r5   r   r   r   r   r   rg  re   r1  fps
             r$   r   zgitsubrepo.cat  s    kk!n==?{{}  	A%%wC80C&DEF$$		:		0A0A&!0LB HHVHHJ	 r&   c           	         | j                   d   }| j                         s|st        j                  g g g g g g g       S g g g }}}| j	                          |rddd||g}ndd|g}| j                  |      }|j                  d      D ]n  }	|	j                  d      }
|
dk(  r|	|
dz
  |
 |	|
dz   d  }}|d	k(  r|j                  |       A|d
k(  r|j                  |       X|dk(  s^|j                  |       p g g g g f\  }}}}g d}|j                  d      r|dgz  }|j                  d      r|dgz  }| j                  |      }t               }|j                  |       |j                  |       |j                  |       |j                  d      D ]  }	|	s|	dd }|	j                  d      dk\  r|	dd  j                  d      \  }}n|	dd  }d }|j                  |       |r|j                  |       |dk(  r|j                  |       y|dk(  s|j                  |        |j                  d      r>| j                  dg      }|j                  d      D ]  }||vs|j                  |        t        j                  |||||||      S )Nr   s	   diff-tree   --no-renamesrd  r  r     	r	     M   A   D)rL  s   --porcelains   -zr  s   --untracked-files=allignoreds	   --ignored    r   r   r  s   ??s   !!rR  s   ls-files)r4  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&  rR  changedfilesst	filename1	filename2s                        r$   r   zgitsubrepo.status  s   {{1~T>>"b"b"b"==#%r2%#_eT4HG$ot<Gw'IIe$ 
	"D))E"CbyS1Ws+T#')_AF~"4Q4q!
	" ,.r2r>('5488I011G88I~%Gw'uH%E"G$IIe$ 	*DaByy1$'+ABx~~e'<$	9 H	 	Y'  +U{y)uy)%	*( 88G""K=1CYYu% $L(LLO$ ~~eWgw
 	
r&   c                    | j                   d   }ddg}|d   r|j                  d       n|j                  d|j                  z         |j                  r|j	                  d|z  d|z  g       n|j	                  d	|z  d
|z  g       |j
                  r|j                  d       |j                  r|j                  d       | j                  | j                  dg            dk\  r|j                  r|j                  d       |j                  |       |r|j                  |       d}	|j                         r|	| j                  |      dz   z  }	nv| j                  |      }
|
j                  |
j                  |
j                  fD cg c]  }|D ]  }|  }}}|D ]'  } ||      s|	| j                  |d|gz         dz   z  }	) |	j                         r|j!                  |	       y y c c}}w )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  s   --)r4  r  contextnoprefixr  ignorewsignorewsamountr  r  ignoreblanklinesalwaysr   r  r  r(  r   rs  )r5   rN   r   r   r   r   r   r  r%  r1  r+  sublistre   r   s                 r$   r   zgitsubrepo.diff  s   A(<JJy! JJw!1!112JJ$v-/BV/KL JJ&/1F1OP JJ,-""JJ/0T--|n=>)K))JJ./

5JJu<<>d&&s+e33FU#B !#RXXrzzB   E 
  I8d..seQZ/?@5HHFI <<>HHV s   G*c                    | j                   j                  t        d      |d   z         |j                  d      s| j                  d       }|j                  }|D ]  }t
        j                  j                  | j                  |      }t        j                  | j                   | j                  |      }| j                   j                  t        d      |t
        j                  j                  |      fz         t        j                  | j                   j                  |      |        |j                  d      s| j                  |d       g S )Nr  r   r  s#   saving current version of %s as %s
r  Tr  )rN   r   r   rz   r  r8  r!   r\   r   r   
backuppathrp  r  r  r   renamern   )	r5   r   r  r   r   rb   r   
parentnamebaknames	            r$   r  zgitsubrepo.revert-  s   q23hqkABxx$[[&FOOE ;  WW\\$**d;
!,,GGT__j =>RWW__W567 DIINN40':; xx	"HHXH.	r&   c                     |d d S )Nr  r<   r  s     r$   r  zgitsubrepo.shortidD  s    Ray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  rr  r  rK   rP   r   rz   r   r   r   r   r   r  r   r   r   r  r  r  r  s   @r$   r  r  e  s|   +OZ 	 	 ! !FA

:%x-9QA&,  0    V Vp    $  0 0 0d $ $L $ $*$L  $ A
 A
F / /b  ,r&   r  )rr   rt   rs   )FT)<r}  r  r8  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   rr  r+  r%   r,   r3   r.   rK   rT   rf   rq   ry   r~   r0   r   r   r-  r  r  r{   r<   r&   r$   <module>rB     s"     	 	   
    
      
%%##
##
""K
05;; 0*#&4(	M  @(>(A0aL aLHV
' V
'rF3 F3R` `H 	r&   