
    cX]                        d Z ddlZddlZddlmZ ddl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mZmZmZmZmZ ddlmZ ddlmZ   G d	 d
ej                  Z! G d de!ej                  Z" G d de!ej#                  Z$ G d dej                  Z% G d dej&                  Z' G d dej(                  Z)d Z* G d d          Z+ddZ,d Z- G d d          Z.	 ddZ/dS ) zRepository class for viewing uncompressed bundles.

This provides a read-only repository interface to bundles as if they
were part of the actual repository.
    N   )_)hexnullrev)bundle2changegroup	changelogcmdutil	discoveryencodingerrorexchangefilelog	localrepomanifestmdiffpathutilphasespycompatrevlogrevlogutilsutilvfs)urlutil)	constantsc                   L     e Zd Zd Zd
dZd Zd
 fd	Zd Zd Zd Z	d	 Z
 xZS )bundlerevlogc                 f   t          j        |          }t          j                            | |||           || _        t          |           }|dz
  | _        t                      | _        |	                                D ]}|\  }}	}
}}}}}t          |          }|
                                |z
  }| j                            |          r3| j                            | j                            |                     ||k    rt          }n ||          }|	|
fD ]D}| j                            |          s(t!          j        || j        t'          d                    E| j                            |          s#t#          || j        t'          d                    |                     |          }t)          j        ||||||                     |	          |                     |
          |          }| j                            |           | j                            |           |dz  }d S )N)targetradixr   s   unknown parents   unknown delta base)flagsdata_offsetdata_compressed_lengthdata_delta_baselink_revparent_rev_1parent_rev_2node_id)vfsmodreadonlyvfsr   __init__bundlelen
repotiprevset
bundlerevs	deltaitertellindexhas_nodeaddrevr   r   LookupError
display_idr   r   entryappend)selfopenerr   r    
cgunpacker
linkmappern	deltadatanodep1p2cs	deltabasedeltar!   sidedatasizestartlinkrevpbasereves                         6/usr/lib/python3/dist-packages/mercurial/bundlerepo.pyr+   zbundlerevlog.__init__7   s6    #F++tVF%HHH IIa%%%#--// (	 (	IBK?D"b"ixu::DOO%%,Ez""4(( ##DJNN4$8$8999Tzz!$*R.."X  z**1-- +4?A.?,@,@  
 :&&y11 !t2G0H0H   hhy))G!!'+ ' !XXb\\!XXb\\	 	 	A Ja   O"""FAAQ(	 (	    Nc                    || j         k    r t          j                            | |          S | j                            |                     |                     | j                            |                     |                    S N)r.   r   _chunkr,   seekrI   readlength)r;   r6   dfs      rN   rR   zbundlerevlog._chunko   sk     $/!!=''c222C))){C 0 0111rO   c                 p   || j         k    r:|| j         k    r/| j        |         d         }||k    r|                     |          S n7|| j         k    r,|| j         k    r!t          j                            | ||          S t          j        |                     |          |                     |                    S )z1return or calculate a delta between two revisions   )r.   r3   rR   r   revdiffr   textdiffrawdata)r;   rev1rev2revbs       rN   rY   zbundlerevlog.revdiffx   s    $/!!dT_&<&<:d#A&Dt||{{4((( T_$$)@)@=((tT:::~dll400$,,t2D2DEEErO   c                 F   ||                      |          }d}d }g }|}|| j        k    rY| j        r| j        d         |k    r| j        d         }n3|                    |           | j        |         d         }|| j        k    Y|t
          k    rd}nF|Dt          t          |                               | 	                    |          ||          }|\  }	}}|rd}|r?| 
                    |                                          }
t          j        ||
g          }|?|||fS )NFr      rX   rO   )_df)r6   r.   _revisioncacher:   r3   r   superr   _rawtextrA   rR   popr   patches)r;   rA   r6   ra   	validatedrawtextchainiterrevr__rF   	__class__s              rN   rd   zbundlerevlog._rawtext   sO   ;((4..C	''" t':1'='H'H-a0LL!!!j)!,G '' gGG_lD))22		'""G 3  A &'"B 	I 	6KK		,,EmGeW55G  	6 GY&&rO   c                     t           rQ   NotImplementedErrorr;   argskwargss      rN   addrevisionzbundlerevlog.addrevision       !!rO   c                     t           rQ   ro   rq   s      rN   addgroupzbundlerevlog.addgroup   ru   rO   c                     t           rQ   ro   rq   s      rN   stripzbundlerevlog.strip   ru   rO   c                     t           rQ   ro   r;   s    rN   	checksizezbundlerevlog.checksize   ru   rO   rQ   )__name__
__module____qualname__r+   rR   rY   rd   rt   rw   ry   r|   __classcell__rm   s   @rN   r   r   6   s        6 6 6p2 2 2 2
F 
F 
F' ' ' ' ' '8" " "" " "" " "" " " " " " "rO   r   c                       e Zd Zd ZdS )bundlechangelogc                     t           j                             | |           d }t                              | |t          j        d f| j        ||           d S )Nc                     | S rQ    )xs    rN   <lambda>z*bundlechangelog.__init__.<locals>.<lambda>   s    q rO   )r	   r+   r   revlog_constantsKIND_CHANGELOGr    )r;   r<   r=   r>   s       rN   r+   zbundlechangelog.__init__   s`    $$T6222 [
,d3J	
 	
 	
 	
 	
rO   Nr}   r~   r   r+   r   rO   rN   r   r      s#        

 

 

 

 

rO   r   c                   *     e Zd Z	 	 ddZ fdZ xZS )bundlemanifestNrO   c                 "   t           j                            | |||           t                              | |t          j        |f| j        j        ||           |&i }| j        j	        dk    rt          | j                  }|| _        || _        d S )N)trees   03)r   manifestrevlogr+   r   r   KIND_MANIFESTLOG_revlogr    r,   version_getfilestarts_dirlogstarts_linkmapper)r;   nodeconstantsr<   r=   r>   dirlogstartsdirs          rN   r+   zbundlemanifest.__init__   s     	((}f3(OOO.4L	
 	
 	
 L{"e++-dk::)%rO   c                    || j         v rS| j                            | j         |                    t          | j        | j        | j        | j        | j         |          S t          t          |                               |          S )N)r   )	r   r,   rS   r   r   r<   r   rc   dirlog)r;   drm   s     rN   r   zbundlemanifest.dirlog   s    """KT/2333!" "    ^T**11!444rO   )NrO   )r}   r~   r   r+   r   r   r   s   @rN   r   r      sT         & & & &25 5 5 5 5 5 5 5 5rO   r   c                       e Zd Zd ZdS )bundlefilelogc                     t           j                             | ||           t          |t          j        |f| j        j        ||          | _        d S )N)r   r    r=   r>   )r   r+   r   r   KIND_FILELOGr   r    )r;   r<   pathr=   r>   s        rN   r+   zbundlefilelog.__init__   sR      vt444#$148,$!!
 
 
rO   Nr   r   rO   rN   r   r      s#        	
 	
 	
 	
 	
rO   r   c                       e Zd Zd ZdS )
bundlepeerc                     dS NFr   r{   s    rN   canpushzbundlepeer.canpush       urO   N)r}   r~   r   r   r   rO   rN   r   r      s#            rO   r   c                   0     e Zd Z fdZd Zd Zd Z xZS )bundlephasecachec                      t          t          |           j        |i | t          j        | d          r t          j        | j                  | _        d S d S )Nr<   )rc   r   r+   r   safehasattrr)   r*   r<   )r;   rr   rs   rm   s      rN   r+   zbundlephasecache.__init__   s]    .%%.????D(++ 	: ,T[99DKKK	: 	:rO   c                     t           rQ   ro   r{   s    rN   writezbundlephasecache.write   ru   rO   c                     t           rQ   ro   )r;   fps     rN   _writezbundlephasecache._write   ru   rO   c                 P    || j         |<   |                                  d| _        d S )NT)
phaseroots
invalidatedirty)r;   phasenewrootstrs       rN   _updaterootszbundlephasecache._updateroots  s)    !)


rO   )r}   r~   r   r+   r   r   r   r   r   s   @rN   r   r      se        : : : : :
" " "" " "      rO   r   c                      i }t           j        i           D ]7}|d         }                                 ||<   t           fdi           D ]}8|S )Ns   filenamec                  .                          d           S rQ   )
deltachunk)r=   s   rN   r   z _getfilestarts.<locals>.<lambda>  s    *"7"7"="= rO   )iterfilelogheaderr2   )r=   filespos	chunkdatafnamechunks   `    rN   r   r     sq    H*2B77  	+&$//++====rBB 	 	E	OrO   c                       e Zd ZdZd Zd ZddZej        d             Z	ej        d             Z
d Zej        d	             Zd
 Zej        d             Zej        d             Zd Z fdZd Zd Zd Zd Zd fd	Z xZS )bundlerepositorya%  A repository instance that is a union of a local repo and a bundle.

    Instances represent a read-only repository composed of a local repository
    with the contents of a bundle file applied. The repository instance is
    conceptually similar to the state of a repository after an
    ``hg unbundle`` operation. However, the contents of the bundle are never
    applied to the actual base repository.

    Instances constructed directly are not usable as repository objects.
    Use instance() or makebundlerepository() to create instances.
    c           	      >   || _         || _        | j                            dddd           d | _        t          j        |d          }t          j        | j        ||          }t          |t          j                  r|| _        d | _        d }|                    d          D ]6}|j        dk    r|rt!          d	          |}|                     ||           7|s!t%          j        t)          d
                    |                    dt,          j                   nt          |t0          j                  ra|                                r>|                     |j        dd          }t          j        | j        ||| j                  }|| _        || _        n1t%          j        t)          d          t          |          z            i | _        | j        j         dz   | _!        tE          j#        | d tD          j$        d | | j!        d          D                        d S )N   phasess   publishFs
   bundlerepo   rbT)seekable   changegroups#   can't process multiple changegroupss   No changegroups foundr   s   .hg10un   HG10UN)headers   bundle type %s cannot be readr   c                 6    g | ]}|                                 S r   rA   .0ctxs     rN   
<listcomp>z-bundlerepository.__init__.<locals>.<listcomp>W  s     <<<CSXXZZ<<<rO   )%_tempparent_urlui	setconfigtempfiler   	posixfiler   
readbundle
isinstancer   
unbundle20_bundlefile_cgunpacker	iterpartstyperp   _handlebundle2partr   Abortr   rS   osSEEK_SETr   cg1unpacker
compressed_writetempbundlerT   r   _cgfilesposr	   r.   firstnewrevr   retractboundarydraft)r;   
bundlepathurl
tempparentfr,   cgpartparts           rN   r+   zbundlerepository.__init__  s7   %	)ZFFFN:u--$TWa<<fg011 %	%D#DF(($(77 6 69.. 1B   "F''5555 ?k!$<"="=>>> KK2;'''' 788 	  "" O))KI *   ",TWaTXNN%D%D+233d6llB  
 >4q8L<<4(8(:(:#;<<<		
 	
 	
 	
 	
rO   c                 p   |j         dk    rd S |}|j                            dd          }t          j        |           }||vr&t          d          }t          j        ||z            |                                r| 	                    |j
        d|z            }t          j        ||d          | _        d S )Nr   s   versions   01s#   Unsupported changegroup version: %ss   .cg%suns   UN)r   paramsgetr   supportedincomingversionsr   r   r   r   r   rT   getunbundlerr   )r;   r,   r   cgstreamr   legalcgversmsgs          rN   r   z#bundlerepository._handlebundle2partZ  s    9&&F+//*e44!;DAA+%%:;;C+cGm,,, 	N,,TY
W8LMMH&3GXuMMrO   rO   c                 `   | j                             d|          \  }}|| _        t          j        |d          5 }|                    |           	  |d          }|sn|                    |           $	 ddd           n# 1 swxY w Y   | j                             | j        d          S )	zWrite a temporary file to disks
   hg-bundle-)prefixsuffixwbTi   Nr   )mode)r   mkstempr   r   fdopenr   open)r;   readfnr   r   fdtemptempfptempr   s           rN   r   z!bundlerepository._writetempbundlei  s    x''}V'LLYvt$$ 	$LL   $w U###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ x}}T]}777s   ;BBBc                 ,    t          | | j                  S rQ   )r   _phasedefaultsr{   s    rN   _phasecachezbundlerepository._phasecachex  s    d&9:::rO   c                     | j                                          t          | j        | j                   }| j                                         | _        |S rQ   )r   changelogheaderr   svfsr2   manstart)r;   cs     rN   r	   zbundlerepository.changelog|  sH     	((***DIt'788(--//rO   c                     d S rQ   r   r{   s    rN   _refreshchangelogz"bundlerepository._refreshchangelog  s	     	rO   c                    | j                             | j                   | j                                          |                                 j        j        }t          | j        | j	        | j         |          }| j         
                                | _        t          j        | j	        | ||                                           S rQ   )r   rS   r	  manifestheader
unfilteredr	   r6   r   r   r  r2   	filestartr   manifestlognarrowmatch)r;   r>   	rootstores      rN   r  zbundlerepository.manifestlog  s    dm,,,'')))__&&04
"	4+;Z
 
	 )..00#ItY(8(8(:(:
 
 	
rO   c                     | j                             | j                   | j                                          | j                                         D ]}| j                                         | _        dS )zgConsumes the manifest portion of the bundle, setting filestart so the
        file portion can be read.N)r   rS   r	  r  r1   r2   r  )r;   rF   s     rN   _consumemanifestz!bundlerepository._consumemanifest  sm     	dm,,,'')))%//11 	 	E)..00rO   c                     | j          | j        S rQ   )r	   r	  r{   s    rN   r	  zbundlerepository.manstart  s    }rO   c                 X    | j          d| j        vr|                                  | j        S )Nr  )r  __dict__r  r  r{   s    rN   r  zbundlerepository.filestart  s4     dm++!!###~rO   c                     | j         S rQ   )r   r{   s    rN   r   zbundlerepository.url  s
    yrO   c                    | j         s8| j                            | j                   t	          | j                  | _         || j         v r_| j                            | j         |                    |                                 j        j        }t          | j	        || j        |          S t          t          |                               |          S rQ   )r   r   rS   r  r   r  r	   r6   r   r  rc   r   file)r;   r   r>   rm   s      rN   r  zbundlerepository.file  s     	@!!$.111-d.>??D   !!$"21"5666**48J At/?LLL)40055a888rO   c                     | j                                          | j        | j                            | j                   | j        rt          j        | j        d           dS dS )z'Close assigned bundle file immediately.NT)r   closer   r   unlinkr   shutilrmtreer{   s    rN   r  zbundlerepository.close  se       =$HOODM*** 	2M$*D11111	2 	2rO   c                     dS r   r   r{   s    rN   cancopyzbundlerepository.cancopy  r   rO   c                      t          |           S rQ   )r   r{   s    rN   peerzbundlerepository.peer  s    $rO   c                 (    t          j                    S rQ   )r   getcwdr{   s    rN   r&  zbundlerepository.getcwd  s       rO   Nc                    || j         }| j                            |          }| j                            |          }t          d          }| j        j        |k     r*| j                            |t          |          z             | j        j        |k     r*| j                            |t          |          z             t          t          |           
                    ||          S )Ns9   setting parent to node %s that only exists in the bundle
)nullidr	   r6   r   r.   r   warnr   rc   r   
setparents)r;   rB   rC   p1revp2revr   rm   s         rN   r*  zbundlerepository.setparents  s    :B""2&&""2&&MNN>$u,,GLLs2ww'''>$u,,GLLs2ww'''%t,,77B???rO   )rO   rQ   )r}   r~   r   __doc__r+   r   r   r   unfilteredpropertycacher  r	   r  r  r  r	  r  r   r  r  r"  r$  r&  r*  r   r   s   @rN   r   r     s       
 
:
 :
 :
xN N N8 8 8 8 &; ; '&; &  '&  
 &
 
 '&
1 1 1 &  '& &
 
 '&
  
9 
9 
9 
9 
92 2 2       ! ! !
@ 
@ 
@ 
@ 
@ 
@ 
@ 
@ 
@ 
@rO   r   c                    |r!t          j        t          d                    |                     dd          }|s)t	          j        t          j                              }|d}|r\t          j                    }||k    rd}n@t          j	        |          }|
                    |          r|t          |          d          }t          j        |          }|                                }|j        dk    r:|                    dd          }t          |          dk    r||d         }
}	n
|\  }	}
n||}
}	t#          | |	|
          S )Ns#   cannot create new bundle repositorys   bundles   mainreporootrO      +r   r   )r   r   r   configr
   findrepor   r&  r   normasprefix
startswithr-   r   r   	localpathschemesplitmakebundlerepository)r   r   createintents
createopts
parentpathcwdusrepopath
bundlenames              rN   instancerB    sF    Ek!BCCDDD9o66J %ho&7&788
J 	4 oJJ',,C$$S)) 4'C

3
DA;;==Dx9JJtQq66Q;;#-qtjHH#$ Hjj)4*Hj999rO   c                    |rdt          j        |          |fz  }nd|z  }	 t          j        | |d          }d}ns# t          j        $ r  t          j        $ rR t          j                    }	 t          j        | |d          }n## t          $ r t          j        |            w xY wY nw xY w G d dt          |j                  }||_        t                              ||||           |S )	z?Make a bundle repository object based on repo and bundle paths.s   bundle:%s+%ss	   bundle:%sF)r9  NTc                       e Zd ZdS )5makebundlerepository.<locals>.derivedbundlerepositoryN)r}   r~   r   r   rO   rN   derivedbundlerepositoryrE  "  s        rO   rF  )r   
expandpathr   rB  r   RequirementError	RepoErrorr   mkdtemp	Exceptionr  r   r   rm   r+   )r   r@  r   r   repor   rF  s          rN   r8  r8    s?    (!:!:J GGZ'!"hu===

!   ?   %''
	%b*TBBBDD 	 	 	M*%%%	 D    "2DN    -DNdJZ@@@Ks'   = 1B-/BB- B''B-,B-c                        e Zd Zd Zd Zd ZdS )bundletransactionmanagerc                     d S rQ   r   r{   s    rN   transactionz$bundletransactionmanager.transaction,  s    trO   c                     t           rQ   ro   r{   s    rN   r  zbundletransactionmanager.close/  ru   rO   c                     t           rQ   ro   r{   s    rN   releasez bundletransactionmanager.release2  ru   rO   N)r}   r~   r   rP  r  rS  r   rO   rN   rN  rN  +  sA          " " "" " " " "rO   rN  Fc                    t          j        |||          }|\  }}}	|s2	 |rt          j        |           n# t          $ r Y nw xY w|g j        fS t          |          fd|	D             }	dd                                }
|s|
su|                     dd          }d|vod|v }| o)	                    d          o	                    d          }|r
                                5 }|                    dd	||	t          j        |d
          dd                                          }t          j        | |                                |          x}ddd           n# 1 swxY w Y   nW	                    d          rY
                                5 }|                    dd	||	d                                          }ddd           n# 1 swxY w Y   n|o	                    d          sZ
                                5 }|                    d|d	d                                          }ddd           n# 1 swxY w Y   d}	nX
                                5 }|                    d||	d	d                                          }ddd           n# 1 swxY w Y   |
rd}nd}t%          j        | |||          x}|rd|
s1t)          |j        |j        |          x}
|                                }|
r |
j                    }
|
j                            ||	          }rd j        d         D             }
                                5 }|                    dddi                                          }ddd           n# 1 swxY w Y   t          j        d|          }t;                      |_        t          j        ||           fd}|
||fS )aD  obtains a bundle of changes incoming from peer

    "onlyheads" restricts the returned changes to those reachable from the
      specified heads.
    "bundlename", if given, stores the bundle to this file path permanently;
      otherwise it's stored to a temp file and gets deleted again when you call
      the returned "cleanupfn".
    "force" indicates whether to proceed on unrelated repos.

    Returns a tuple (local, csets, cleanupfn):

    "local" is a local repo from which to obtain the actual incoming
      changesets; it is a bundlerepo for the obtained bundle when the
      original "peer" is remote.
    "csets" lists the incoming changeset node ids.
    "cleanupfn" must be called without arguments when you're done processing
      the changes; it closes both the original "peer" and the one returned
      here.
    )headsforcec                     g | ]}|v|	S r   r   )r   r   	commonsets     rN   r   z$getremotechanges.<locals>.<listcomp>W  s#    666A1I#5#5a#5#5#5rO   Ns   devels   legacy.exchanges   bundle2s   bundle1s	   getbundles   incomings   client)roleT)   source   common   headss
   bundlecapss   cg)rZ  r[  r\  s   changegroupsubsetr   )s   nodesrZ  )s   basesr\  rZ  s   HG10BZr   c                 6    g | ]}|                                 S r   r   r   s     rN   r   z$getremotechanges.<locals>.<listcomp>  s     PPPCSXXZZPPPrO   s   listkeyss	   namespacer   )r   rU  c                      r                                   rt          j                                                      d S rQ   )r  r   r  )r,   
bundlerepor$  s   rN   cleanupz!getremotechanges.<locals>.cleanup  sF     	 	If

rO   ) r   findcommonincomingr   r  OSErrorr  r/   local
configlistcapablecommandexecutorcallcommandr   
caps20to10resultr   writechunks_forwardchunksr   writebundler8  baseuirootrU  r  r	   findmissingr   pulloperationrN  	trmanager_pullapplyphases)r   rL  r$  	onlyheadsrA  rV  tmpcommonincomingrheadsr   legexcforcebundle1
canbundle2rM   b2r   cg
bundletypecsets	reponodesremotephasespullopr`  r,   r_  rX  s     `                     @@@rN   getremotechangesr  6  s   , 
&tT%
P
P
PC"FHf $	 &	*%%% 	 	 	D	R##FI6666666FFJ

I O" O" x);<<!/HJ&4H )\**)Z(( 	
  9	Q%%'' 1]] #.#)"('/': y( ( (  $   &((  "-!8))++Z" "               $ ||L))  ))++ q$'2'-&,   fhh                "4<<8L+M+M" ))++ q&&.'2   fhh                ))++ q,&.&,'2   fhh                 '&

&
$0RZPPPEF 	F 	"%9TY& & I

 ZZ\\F + )I(**	++FF;;E 8PP:j6L6N6N+OPPP	!!## 	q== ) 
 fhh 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 '4y
 
 
 455!&,777       ug&&sj   = 
A
	A
2A-E++E/2E/!-GG!G,I		II+-J$$J(+J(!+NNN)NN)NNF)0r-  r   r  i18nr   rA   r   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   r   r   	localpeerr   
phasecacher   r   r   rB  r8  rN  r  r   rO   rN   <module>r     sD    
			              
                                         *          
t" t" t" t" t"6= t" t" t"n
 
 
 
 
lI$7 
 
 
%5 %5 %5 %5 %5\8#: %5 %5 %5P

 

 

 

 

GO 

 

 

    $   
    v(   $  M@ M@ M@ M@ M@ M@ M@ M@`: : : :D% % %P" " " " " " " " <AV' V' V' V' V' V'rO   