
    q&fTc                        d 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 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j2                        Z" G d de"ej                        Z# G d de"ejH                        Z% G d dej$                        Z& G d dejN                        Z( G d dejR                        Z*d Z+ G d d      Z,ddZ-d Z. G d d      Z/	 ddZ0y)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                   p     e Zd Zd Zej
                   fd       Zd Zd Z fdZ	d Z
d Zd Zd	 Z xZS )
bundlerevlogc                 F   t        j                  |      }t        j                  j                  | |||       || _        t        |       }|dz
  | _        t               | _        |j                         D ]  }|\  }}	}
}}}}}t        |      }|j                         |z
  }| j                  j                  |      r5| j                  j                  | j                  j                  |             }||k(  rt        }n ||      }|	|
fD ]G  }| j                  j                  |      rt!        j"                  || j$                  t'        d             | j                  j                  |      s*t!        j"                  || j$                  t'        d            | j                  |      }t)        j*                  |||||| j                  |	      | j                  |
      |      }| j                  j-                  |       | j                  j                  |       |dz  } y )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__8   s    ##F+tVF%H Ia%%#--/ (	IBK?D"b"ixu:DOO%,Ezz""4(##DJJNN4$89Tz!$R."X zz**1-++4??A.?,@  ::&&y1''t2G0H  hhy)G!!!'+ ' !XXb\!XXb\	A JJa OO"FAQ(	    c              #      K   | j                   dk  rd  y t        | 	         5 }| d d d        y # 1 sw Y   y xY ww)Nr   )r.   superreading)r;   x	__class__s     rN   rR   zbundlerevlog.readingp   s;     ??Q" a  s   #A 4	A =A c                    || j                   k  r t        j                  j                  | |      S | j                  j	                  | j                  |             | j                  j                  | j                  |            S N)r.   r   _chunkr,   seekrI   readlength)r;   r6   s     rN   rW   zbundlerevlog._chunkx   s_     $//!==''c22C){{C 011rO   c                 t   || j                   kD  r7|| j                   kD  r(| j                  |   d   }||k(  rP| j                  |      S || j                   k  r0|| j                   k  r!t        j                  j	                  | ||      S t        j                  | j                  |      | j                  |            S )z1return or calculate a delta between two revisions   )r.   r3   rW   r   revdiffr   textdiffrawdata)r;   rev1rev2revbs       rN   r]   zbundlerevlog.revdiff   s    $//!dT__&<::d#A&Dt|{{4((T__$)@==((tT::~~dll40$,,t2DEErO   c                 L   || j                  |      }d}d }g }|}|| j                  kD  r| j                  j                  r6| j                  j                  d   |k(  r| j                  j                  d   }n3|j	                  |       | j
                  |   d   }|| j                  kD  r|t        k(  rd}n+|)t        t        | '  | j                  |      |      }|\  }}}|rd}|r9| j                  |j                               }	t        j                  ||	g      }|r9|||fS )NFr      r\   rO   )r6   r.   _inner_revisioncacher:   r3   r   rQ   r   _rawtextrA   rW   popr   patches)r;   rA   r6   	validatedrawtextchainiterrevr__rF   rT   s             rN   rg   zbundlerevlog._rawtext   s$   ;((4.C	'**KK..q1W<++44Q7LL!jj)!,G ' gG_lD2		'"A &'"BIKK		,EmmGeW5G  GY&&rO   c                     t         rV   NotImplementedErrorr;   argskwargss      rN   addrevisionzbundlerevlog.addrevision       !!rO   c                     t         rV   rq   rs   s      rN   addgroupzbundlerevlog.addgroup   rw   rO   c                     t         rV   rq   rs   s      rN   stripzbundlerevlog.strip   rw   rO   c                     t         rV   rq   r;   s    rN   	checksizezbundlerevlog.checksize   rw   rO   )__name__
__module____qualname__r+   
contextlibcontextmanagerrR   rW   r]   rg   rv   ry   r{   r~   __classcell__rT   s   @rN   r   r   7   sH    6p  2
F'@""""rO   r   c                       e Zd Zd Zy)bundlechangelogc                     t         j                   j                  | |       d }t        j                  | |t        j                  d f| j
                  ||       y )Nc                     | S rV    )rS   s    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__   sL    $$T62 
,,d3JJ	
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 )bundlemanifestc                 F   t         j                  j                  | |||       t        j                  | |t        j
                  |f| j                  j                  ||       |0i }| j                  j                  dk(  rt        | j                        }|| _        || _        y )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..4LL	
 L{{""e+-dkk:)%rO   c                    || j                   v rk| j                  j                  | j                   |          t        | j                  | j
                  | j                  | j                  | j                   |      S t        t        | #  |      S )N)r   )	r   r,   rX   r   r   r<   r   rQ   dirlog)r;   drT   s     rN   r   zbundlemanifest.dirlog   s{    """KKT//23!""  ""  ^T1!44rO   )NrO   )r   r   r   r+   r   r   r   s   @rN   r   r      s     &65 5rO   r   c                       e Zd Zd Zy)bundlefilelogc                     t         j                   j                  | ||       t        |t        j                  |f| j
                  j                  ||      | _        y )N)r   r    r=   r>   )r   r+   r   r   KIND_FILELOGr   r    )r;   r<   pathr=   r>   s        rN   r+   zbundlefilelog.__init__   sH      vt4#$1148,,$$!!
rO   Nr   r   rO   rN   r   r      s    	
rO   r   c                       e Zd Zd Zy)
bundlepeerc                      yNFr   r}   s    rN   canpushzbundlepeer.canpush       rO   N)r   r   r   r   r   rO   rN   r   r      s    rO   r   c                   2     e Zd Z fdZd Zd ZddZ xZS )bundlephasecachec                     t        t        | 
  |i | t        | d      r%t	        j
                  | j                        | _        y y )Nr<   )rQ   r   r+   hasattrr)   r*   r<   )r;   rt   ru   rT   s      rN   r+   zbundlephasecache.__init__  s=    .??4" ,,T[[9DK #rO   c                     t         rV   rq   r}   s    rN   writezbundlephasecache.write
  rw   rO   c                     t         rV   rq   )r;   fps     rN   _writezbundlephasecache._write  rw   rO   c                 T    || j                   |<   |r| j                          d| _        y )NT)_phaseroots
invalidatedirty)r;   repophasenewrootstrr   s         rN   _updaterootszbundlephasecache._updateroots  s&    "*OO
rO   )T)r   r   r   r+   r   r   r   r   r   s   @rN   r   r     s    :
""rO   r   c                      i }t         j                  i       D ].  }|d   } j                         ||<   t         fdi       D ]  } 0 |S )Ns   filenamec                  &     j                  d       S rV   )
deltachunk)r=   s   rN   r   z _getfilestarts.<locals>.<lambda>  s    *"7"7"= rO   )iterfilelogheaderr2   )r=   filespos	chunkdatafnamechunks   `    rN   r   r     s_    H*22B7 	+&$//+=rB 	E	
 OrO   c                   .    e Zd Zd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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   || _         || _        | j                  j                  dddd       i | _        d | _        d | _        d | _        t        j                  |d      }t        j                  | j                  ||      }t        |t        j                        r|| _        d }|j                  d      D ]U  }|j                   dk(  r| j#                  ||       %|j                   d	k(  s5|rt%        d
      |}| j'                  ||       W |st)        j*                  t-        d            |j/                  dt0        j2                         y t        |t4        j6                        r| j9                  ||       y t)        j*                  t-        d      t!        |      z        )N   phasess   publishFs
   bundlerepo   rbT)seekable   phase-heads   changegroups#   can't process multiple changegroupss   No changegroups foundr   s   bundle type %r cannot be read)_tempparent_urlui	setconfig_cgfilespos_bundlefile_cgunpackertempfiler   	posixfiler   
readbundle
isinstancer   
unbundle20	iterpartstype_handle_bundle2_phase_partrr   _handle_bundle2_cg_partr   Abortr   rX   osSEEK_SETr   cg1unpacker_handle_bundle1)r;   
bundlepathurl
tempparentfr,   cgpartparts           rN   r+   zbundlerepository.__init__.  so   %	)ZF NN:u-$$TWWa<fg001%DF(($(7 	?99.33FDAYY.01B  "F00>	? kk!$<"=>> KK2;;' 7 78  4++23d6lB rO   c           
         |j                         rJ| j                  |j                  dd      }t        j                  | j
                  ||| j                        }|| _        || _        | j                  j                  dz   | _        t        j                  | d t        j                  | | j                  d  D cg c]  }|j                          c}       y c c}w )Ns   .hg10un   HG10UN)headerr   )
compressed_writetempbundlerY   r   r   r   r   r   r   r	   r.   firstnewrevr   retractboundarydraftrA   )r;   r,   r   r   ctxs        rN   r   z bundlerepository._handle_bundle1\  s    %%fkk:i%PA((!ZJF!!>>44q8LL#'(8(8(:#;<CSXXZ<		
 =s   8Cc           
      8   |j                   dk(  sJ |}|j                  j                  d      }	 t        |      }|t
        j                  }|t
        j                  vr%t        d      }||z  }t        j                  |      |j                  j                  dd      }t        j                  |       }||vr#t        d      }t        j                  ||z        |j                         r| j                  |j                  d|z        }t        j                   ||d      | _        | j$                  j&                  d	z   | _        t        j*                  | d || | j(                  d  D 	cg c]  }	|	j-                          c}	       y # t        $ r Y Xw xY wc c}	w )
Nr   s   targetphases   unsupported targetphase: %ds   versions   01s#   Unsupported changegroup version: %ss   .cg%suns   UNr   )r   paramsgetint	TypeErrorr   r   	allphasesr   r   r   r   supportedincomingversionsr   r   rY   getunbundlerr   r	   r.   r   r   rA   )
r;   r,   r   cgstreamtargetphasemr   legalcgversmsgr   s
             rN   r   z(bundlerepository._handle_bundle2_cg_partl  sl   yyN***kkoon5	k*K  ,,Kf...01AA++a. ++//*e4!;;DA+%:;C++cGm,,,,TYY
W8LMH&33GXuM>>44q8#'(8(8(:#;<CSXXZ<		
'  		. =s   F (F	FFc                     |j                   dk(  sJ | j                         }t        j                  |      }t        j                  |d |       y )Nr   c                       y rV   r   r   rO   rN   r   z=bundlerepository._handle_bundle2_phase_part.<locals>.<lambda>  s    rO   )r   
unfilteredr   binarydecodeupdatephases)r;   r,   r   unfiheadsbyphases        rN   r   z+bundlerepository._handle_bundle2_phase_part  sB    yyN*** **40D,=rO   c                 T   | j                   j                  d|      \  }}|| _        t        j                  |d      5 }|j                  |       	  |d      }|sn|j                  |       	 ddd       | j                   j                  | j                  d      S # 1 sw Y   0xY w)zWrite a temporary file to disks
   hg-bundle-)prefixsuffixwbi   Nr   )mode)r   mkstempr   r   fdopenr   open)r;   readfnr  r   fdtemptempfptempr   s           rN   r   z!bundlerepository._writetempbundle  s    xx''}V'LYYvt$ 	$LL wU#	  	$ xx}}T]]}77	$ 	$s   0BB'c                 .    t        | | j                        S rV   )r   _phasedefaultsr}   s    rN   _phasecachezbundlerepository._phasecache  s    d&9&9::rO   c                     | j                   j                          t        | j                  | j                         }| j                   j	                         | _        |S rV   )r   changelogheaderr   svfsr2   manstart)r;   cs     rN   r	   zbundlerepository.changelog  sG     	((*DIIt'7'78((--/rO   c                      y rV   r   r}   s    rN   _refreshchangelogz"bundlerepository._refreshchangelog  s     	rO   c                    | j                   j                  | j                         | j                   j                          | j	                         j
                  j                  }t        | j                  | j                  | j                   |      }| j                   j                         | _        t        j                  | j                  | || j                               S rV   )r   rX   r  manifestheaderr  r	   r6   r   r   r  r2   	filestartr   manifestlognarrowmatch)r;   r>   	rootstores      rN   r  zbundlerepository.manifestlog  s    dmm,'')__&0044
"		4+;+;Z
	 ))..0##IItY(8(8(:
 	
rO   c                     | j                   j                  | j                         | j                   j                          | j                   j	                         D ]  } | j                   j                         | _        y)zgConsumes the manifest portion of the bundle, setting filestart so the
        file portion can be read.N)r   rX   r  r  r1   r2   r  )r;   rF   s     rN   _consumemanifestz!bundlerepository._consumemanifest  se     	dmm,'')%%//1 	E	))..0rO   c                 2    | j                    | j                  S rV   )r	   r  r}   s    rN   r  zbundlerepository.manstart  s    }}rO   c                 n    | j                    d| j                  vr| j                          | j                  S )Nr  )r  __dict__r#  r  r}   s    rN   r  zbundlerepository.filestart  s/     dmm+!!#~~rO   c                     | j                   S rV   )r   r}   s    rN   r   zbundlerepository.url  s    yyrO   c                    | j                   s?| j                  j                  | j                         t	        | j                        | _         || j                   v rn| j                  j                  | j                   |          | j                         j                  j                  }t        | j                  || j                  |      S t        t        | 3  |      S rV   )r   r   rX   r  r   r  r	   r6   r   r  rQ   r   file)r;   r   r>   rT   s      rN   r)  zbundlerepository.file  s    !!$..1-d.>.>?D   !!$"2"21"56*4488J At/?/?LL)45a88rO   c                     | j                   j                          | j                  %| j                  j	                  | j                         | j
                  r!t        j                  | j
                  d       yy)z'Close assigned bundle file immediately.NT)r   closer   r   unlinkr   shutilrmtreer}   s    rN   r+  zbundlerepository.close  sT     ==$HHOODMM*MM$**D1 rO   c                      yr   r   r}   s    rN   cancopyzbundlerepository.cancopy  r   rO   c                     t        | ||      S )N)r   remotehidden)r   )r;   r   r2  s      rN   peerzbundlerepository.peer  s    $TEErO   c                 *    t        j                         S rV   )r   getcwdr}   s    rN   r5  zbundlerepository.getcwd  s      rO   c                    || j                   }| j                  j                  |      }| j                  j                  |      }t        d      }| j                  j                  |k  r'| j
                  j                  |t        |      z         | j                  j                  |k  r'| j
                  j                  |t        |      z         t        t        | +  ||      S )Ns9   setting parent to node %s that only exists in the bundle
)nullidr	   r6   r   r.   r   warnr   rQ   r   
setparents)r;   rB   rC   p1revp2revr   rT   s         rN   r9  zbundlerepository.setparents  s    :B""2&""2&MN>>$$u,GGLLs2w'>>$$u,GGLLs2w'%t7B??rO   )rO   r   rV   )r   r   r   __doc__r+   r   r   r   r   r   unfilteredpropertycacher  r	   r  r  r#  r  r  r   r)  r+  r0  r3  r5  r9  r   r   s   @rN   r   r   !  s    
,\
 
@>8 &&; '; && '
 &&
 '
1 && ' &&
 '

92F!
@ 
@rO   r   c                 J   |rt        j                  t        d            | j                  dd      }|s+t	        j
                  t        j                               }|d}|rPt        j                         }||k(  rd}n4t        j                  |      }|j                  |      r|t        |      d  }t        j                  |      }|j                         }|j                  dk(  r.|j!                  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   r5  r   normasprefix
startswithr-   r   r   	localpathschemesplitmakebundlerepository)r   r   createintents
createopts
parentpathcwdusrepopath
bundlenames              rN   instancerQ    s
   kk!BCDD9o6J%%hoo&78
J ooJ'',C$$S)'C
3
DA;;=Dxx9JJtQq6Q;#-qtjH#$ Hj)4*Hj99rO   c                    |rdt        j                  |      |fz  }nd|z  }	 t        j                  | |d      }d} G d dt        |j                        }||_        t        j                  ||||       |S # t        j
                  $ r  t        j                  $ rT t        j                         }	 t        j                  | |d      }n## t        $ r t        j                  |        w xY wY w xY w)	z?Make a bundle repository object based on repo and bundle paths.s   bundle:%s+%ss	   bundle:%sF)rH  NTc                       e Zd Zy)5makebundlerepository.<locals>.derivedbundlerepositoryN)r   r   r   r   rO   rN   derivedbundlerepositoryrT  L  s    rO   rU  )r   
expandpathr   rQ  r   RequirementError	RepoErrorr   mkdtemp	Exceptionr-  r.  r   rT   r+   )r   rO  r   r   r   r   rU  s          rN   rG  rG  -  s    !:J GGZ'!!"hu=
"2DNN  -DNdJZ@K! !! ?? %%'
	%%b*TBD 	MM*%	 s)   A9 9:C34CC3 C--C32C3c                       e Zd Zd Zd Zd Zy)bundletransactionmanagerc                      y rV   r   r}   s    rN   transactionz$bundletransactionmanager.transactionV  s    rO   c                     t         rV   rq   r}   s    rN   r+  zbundletransactionmanager.closeY  rw   rO   c                     t         rV   rq   r}   s    rN   releasez bundletransactionmanager.release\  rw   rO   N)r   r   r   r^  r+  ra  r   rO   rN   r\  r\  U  s    ""rO   r\  c                 r   t        j                  |||      }|\  }}}	|s'	 |rt        j                  |       |g j
                  fS t        |      }
|	D cg c]	  }||
vs| }	}ddj                         }|s|s| j                  dd      }d|vxr d|v }| xr$ j                  d      xr j                  d      }|r|j                         5 }|j                  dd||	t        j                  |d	
      dd      j                         }t        j                   | |j#                         |      x}ddd       nj                  d      r>j                         5 }|j                  dd||	d      j                         }ddd       n|Pj                  d      s?j                         5 }|j                  d|dd      j                         }ddd       d}	n=j                         5 }|j                  d||	dd      j                         }ddd       |rd}nd}t%        j&                  | ||      x}|rd|s3t)        |j*                  |j,                        x}|j/                         }|r |j0                         }|j2                  j5                  ||	      }rj6                  d D cg c]  }|j9                          }}j                         5 }|j                  dddi      j                         }ddd       t        j:                  d|      }t=               |_        t        j@                  |       fd}|||fS # t        $ r Y .w xY wc c}w # 1 sw Y   8xY w# 1 sw Y   fxY w# 1 sw Y   xY w# 1 sw Y   xY wc c}w # 1 sw Y   xY w)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forceNs   devels   legacy.exchanges   bundle2s   bundle1s	   getbundles   incomings   client)roleT)   source   common   headss
   bundlecapss   cg)rf  rg  rh  s   changegroupsubsetr   )s   nodesrf  )s   basesrh  rf  s   HG10BZr   s   listkeyss	   namespacer   )r   rc  c                  x    rj                           rt        j                          j                          y rV   )r+  r   r,  )r,   
bundlerepor3  s   rN   cleanupz!getremotechanges.<locals>.cleanup  s*    IIf

rO   )!r   findcommonincomingr   r,  OSErrorr+  r/   local
configlistcapablecommandexecutorcallcommandr   
caps20to10resultr   writechunks_forwardchunksr   writebundlerG  baseuirootrc  r  r	   findmissingr   rA   pulloperationr\  	trmanager_pullapplyphases)r   r   r3  	onlyheadsrP  rd  tmpcommonincomingrheads	commonsetrS   r   legexcforcebundle1
canbundle2rM   b2r   cg
bundletypecsetsr   	reponodesremotephasespulloprk  r,   rj  s     `                        @@rN   getremotechangesr  `  s    , 
&
&tT%
PC"FHf			*% R##FI6A1I#5a6F6FJ

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

 ZZ\F )I((*	++FF;E+5j6L6L6N+OPCSXXZP	P!!# 	q== )
 fh 	 ''4y
 45!!&,7 ug&&u  		
 7" &   F Q	 	s`   M 	M/%M/A#M4(%N9$N8%NN(*#N-	M,+M,4M>NNN%-N6)NN)NNF)1r<  r   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   rQ  rG  r\  r  r   rO   rN   <module>r     s     	  
     *
@"6== @"F
lI$7$7 
'5\8#:#: '5T

GOO 

$$ 
v(( &g@ g@T:D%P" " <AV'rO   