
    	^c                        d 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	Z	ddl
Z
ddlmZmZ ddlmZ ddlmZ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%m&Z&m'Z'm(Z(m)Z) dd	l*m+Z+m,Z, d
Z-i Z. e%j/        e.          Z/ e/ddd            e/ddd            e/ddd            e/ddd            e/ddd            e/ddd            e/ddd            e/ddd            e/ddd            e/ddd            e/ddd           dZ0dZ1dZ2e+j3        Z3 e%j4                    Z4 e%j5                    Z5d a6 ej7        d          j8        Z9d Z:d Z;d  Z<d! Z= G d" d#          Z>d$ Z?d% Z@d& ZAd' ZBd( ZCd) ZDd* ZEd+ ZFdMd,ZGe(jH        d-             ZId. ZJd/ ZKd0 ZLd1 ZMd2 ZNd3 ZOdNd4ZPd5 ZQdOd7ZRd8 ZSd9 ZTd: ZUd; ZVd< ZWd= ZXe"jY        fd>ZZ ej[        e3          d?             Z\d@ej]        e+j3        <   dA Z^ej_        dB             Z`dC ZadD ZbdE ZcdF Zd eje        e3dG          dH             ZfdI ZgdJ ZhdK ZidL ZjdS )Pax
   store some pushes in a remote blob store on the server (EXPERIMENTAL)

IMPORTANT: if you use this extension, please contact
mercurial-devel@mercurial-scm.org ASAP. This extension is believed to
be unused and barring learning of users of this functionality, we will
delete this code at the end of 2020.

    [infinitepush]
    # Server-side and client-side option. Pattern of the infinitepush bookmark
    branchpattern = PATTERN

    # Server or client
    server = False

    # Server-side option. Possible values: 'disk' or 'sql'. Fails if not set
    indextype = disk

    # Server-side option. Used only if indextype=sql.
    # Format: 'IP:PORT:DB_NAME:USER:PASSWORD'
    sqlhost = IP:PORT:DB_NAME:USER:PASSWORD

    # Server-side option. Used only if indextype=disk.
    # Filesystem path to the index store
    indexpath = PATH

    # Server-side option. Possible values: 'disk' or 'external'
    # Fails if not set
    storetype = disk

    # Server-side option.
    # Path to the binary that will save bundle to the bundlestore
    # Formatted cmd line will be passed to it (see `put_args`)
    put_binary = put

    # Serser-side option. Used only if storetype=external.
    # Format cmd-line string for put binary. Placeholder: {filename}
    put_args = {filename}

    # Server-side option.
    # Path to the binary that get bundle from the bundlestore.
    # Formatted cmd line will be passed to it (see `get_args`)
    get_binary = get

    # Serser-side option. Used only if storetype=external.
    # Format cmd-line string for get binary. Placeholders: {filename} {handle}
    get_args = {filename} {handle}

    # Server-side option
    logfile = FIlE

    # Server-side option
    loglevel = DEBUG

    # Server-side option. Used only if indextype=sql.
    # Sets mysql wait_timeout option.
    waittimeout = 300

    # Server-side option. Used only if indextype=sql.
    # Sets mysql innodb_lock_wait_timeout option.
    locktimeout = 120

    # Server-side option. Used only if indextype=sql.
    # Name of the repository
    reponame = ''

    # Client-side option. Used by --list-remote option. List of remote scratch
    # patterns to list if no patterns are specified.
    defaultremotepatterns = ['*']

    # Instructs infinitepush to forward all received bundle2 parts to the
    # bundle for storage. Defaults to False.
    storeallparts = True

    # routes each incoming push to the bundlestore. defaults to False
    pushtobundlestore = True

    [remotenames]
    # Client-side option
    # This option should be set only if remotenames extension is enabled.
    # Whether remote bookmarks are tracked by remotenames extension.
    bookmarks = True
    N)binhex)_)getattropen)procutil
stringutilurlutil)bundle2changegroupcommands	discoveryencodingerrorexchange
extensionshg	localrepophasespushkeypycompat	registrarutilwireprototypeswireprotov1peerwireprotov1server   )bundlepartscommons   ships-with-hg-core   infinitepush   serverF)default	   storetype    	   indextypes	   indexpath   storeallparts   reponames   scratchbranchs	   storepath   branchpattern   pushtobundlestores   experimentals   server-bundlestore-bookmarks   infinitepush-scratchpushc                     dS NF )xs    =/usr/lib/python3/dist-packages/hgext/infinitepush/__init__.py<lambda>r/      s    % r$   z^[a-f0-9]+$c                 J   |                      ddg           }|                     dd          }|st          j        d          |                      ddg           }|                     dd          }|st          j        d          dd	lm} |                    ||||          S )
Nr    s   put_argss
   put_binarys   put binary is not specifieds   get_argss
   get_binarys   get binary is not specifiedr   store)
configlistconfigr   Abort r2   externalbundlestore)uiput_args
put_binaryget_args
get_binaryr2   s         r.   _buildexternalbundlestorer=      s    }}_k2>>H?M::J :k8999}}_k2>>H?M::J :k8999$$Z:xPPPr$   c                 
   |                      dd          }|s!t          j        t          d                    |                    d          \  }}}}}|                      dd          }|s!t          j        t          d                    |                      ddd          }|                     dd	d
          }	|                     ddd          }
ddlm} |                    |||||||t          |           |	|

  
        S )Nr    s   sqlhosts   please set infinitepush.sqlhost   :r'   s    please set infinitepush.reponames   logfiler$   s   waittimeouti,  s   locktimeoutx   r   )sqlindexapi)waittimeoutlocktimeout)	r4   r   r5   r   split	configintr6   rA   _getloglevel)r8   sqlhosthostportdbuserpasswordreponamelogfilerB   rC   rA   s               r.   _buildsqlindexrO      s   ii44G Ak!>??@@@%,]]4%8%8"D$D(yy+66H Bk!?@@AAAiiS99G,,DDK,,DDK""
R #   r$   c                     |                      ddd          }t          t          |                                d           }t	          |t
                    s$t          j        t          d          |z            |S )Nr    s   loglevels   DEBUGs   invalid log level %s)	r4   r   loggingupper
isinstanceintr   r5   r   )r8   loglevelnumeric_loglevels      r.   rF   rF     sk    yy+x@@Hw(8(8$??&,, Ak!344x?@@@r$   c                     t          j        |           rE|                     dd          dz   }|                    |          r|t	          |          d         S |S )a)  returns a bookmarks with hoisted part removed

    Remotenames extension has a 'hoist' config that allows to use remote
    bookmarks without specifying remote path. For example, 'hg update master'
    works as well as 'hg update remote/master'. We want to allow the same in
    infinitepush.
       remotenamess   hoistedpeer   /N)r   isremotebooksenabledr4   
startswithlen)r8   remotebookmarkhoists      r.   	_tryhoistr_     s`     "2&& 0		..99D@$$U++ 	0!#e**,,//r$   c                       e Zd Zd ZdS )bundlestorec                 ~   || _         | j         j                            dd          }|dk    r1ddlm} |                    | j         j        | j                   | _        nI|dk    rt          | j         j                  | _        n$t          j        t          d          |z            | j         j                            dd          }|dk    r'dd	lm
} |
                    | j                   | _        d S |d
k    r t          | j         j                  | _        d S t          j        t          d          |z            )Nr    r#   s   diskr   r1   s   externals,   unknown infinitepush store type specified %sr%   )fileindexapis   sqls,   unknown infinitepush index type specified %s)_repor8   r4   r6   r2   filebundlestorer=   r   r5   r   rc   indexrO   )selfrepo	storetyper2   	indextyperc   s         r.   __init__zbundlestore.__init__!  s=   
JM((,GG	..tz}djIIDJJ+%%24:=AADJJ+ABBYN   JM((,GG	&&&&&&%224:>>DJJJ&  '
66DJJJ+ABBYN  r$   N)__name__
__module____qualname__rk   r,   r$   r.   ra   ra      s#            r$   ra   c                 .    |                      dd          S )Nr    r!   )
configboolr8   s    r.   	_isserverrr   <  s    ==)444r$   c                 |    t          |           r*|                                rt          |          |_        d S d S d S N)rr   localra   )r8   rh   s     r.   	reposetuprv   @  sI    }} - -&t,,- - - -r$   c                     t          |            t          |           rt          |            d S t          |            d S rt   )commonsetuprr   serverextsetupclientextsetuprq   s    r.   extsetupr{   E  sC    OOO}} rrr$   c                     t           dft          j        d<   |                     dd          }|rt	          j        |          \  }}ad S d S )Ns   namespace patternss   listkeyspatternsr    r(   )wireprotolistkeyspatternsr   r   r4   r	   stringmatcher_scratchbranchmatcher)r8   scratchbranchpatkindpats       r.   rx   rx   M  se    !723 yy2BCC 
+5+C,
 ,
(c(((
 
r$   c                    t           j        d         fd}j        |_        |t           j        d<   t           j        d         fd}j        |_        |t           j        d<   t          j        t
          j        dt                     t          t          j
        d         d                   dft          j
        d<   t          j        t          d	t                     t          j        t           d
t                     d S )N   pushkeyc                  (    t          g| R i | d S rt   )bundle2pushkey)argskwargsorigpushkeyhandlers     r.   newpushkeyhandlerz)serverextsetup.<locals>.newpushkeyhandler]  s(    );D;;;F;;;;;r$   s   phase-headsc                  $    t          g| R i |S rt   )bundle2handlephases)r   r   orighandlephasehandlers     r.   r/   z serverextsetup.<locals>.<lambda>d  s/    3F4!%4 4 4)/4 4 r$      listkeyss   lookupr      keys   getbundlechunkss   processparts)r   parthandlermappingparamsr   wrapfunctionr   localrepositorylocalrepolistkeys_lookupwrapr   r   r   getbundlechunksprocessparts)r8   r   newphaseheadshandlerr   r   s      @@r.   ry   ry   Z  s    3J?< < < < <  28->Gz*$7G    #9"?1EG~.!;0A   	%.y9!<==-y) H&8/JJJG_lCCCCCr$   c                 "   t          j        t          j        dt                    }|d                             ddd t          d          f           t          j        t          j        dt                     t          j        t          dt                     t          t          j        _        t          j        }|                    d          }|                    ||                    |                    t&                                         d S )	Ns   pushr   r$   s   bundle-stores/   force push to go to bundle store (EXPERIMENTAL)   pulls
   checkheadss	   changeset)r   wrapcommandr   table_pushappendr   _pullr   r   _checkheadslistkeyspatternsr   wirepeerr   b2partsgenorderrf   insertpopscratchbranchparttype)r8   entry	partorderrf   s       r.   rz   rz   v  s    "8>7EBBE	!HOO@AA		
   8>7E:::I}kBBB0@O-(IOOL))Ey}}Y__-BCCDD    r$   c                 h    |j                             t          t          d          rd S  | |          S r+   )r8   rp   experimentalconfigscratchpush)origpushops     r.   r   r     s2    yL*;UCC 4<<r$   c                     t          j        |          }|                     t          j        |          |                                          }t          j        |          S rt   )r   
decodelistlistkeysr   tolocalitemsr   
encodekeys)rh   proto	namespacepatternsds        r.   r}   r}     sM    (22Hh&y118<<BBDDAa   r$   c                    |dk    r|r|j         j        }i } | ||          }|D ]}|                    |                    |                     |                    d          rd|d d         z   dz   }t          j        |          \  }}	}
|                                D ]\  }} |
|          r|||<   |S  | ||          S )N	   bookmarks   *s   re:^s   .*)ra   rf   updategetbookmarksendswithr	   r~   r   )r   rg   r   r   rf   results	bookmarkspatternr   r   matcherbookmarknodes                r.   r   r     s    L  X  &Dy))	 	- 	-GNN5--g66777%% 9!GCRCL058!+!9'!B!BD#w"+//"3"3 - -$78$$ -(,GH%- tD)$$$r$   c                                            d          si d fS  j                            dz              fd}t          j                  t          j        |          d|fS )Nr   s   preparing listkeys for "%s"
c                     j                             dt          |           fz             t          j        |           S )Ns$   received listkey for "%s": %i bytes
)r8   debugr\   r   
decodekeys)r   r   rg   s    r.   decodez listkeyspatterns.<locals>.decode  sA    4	3q667JJ	
 	
 	
 !!$$$r$   )	   namespaces   patterns)capabler8   r   r   	fromlocalr   
encodelist)rg   r   r   r   s   ``  r.   r   r     s    <<
## 4xGMM2Y>???% % % % % % (33#.x88   r$   c                 F    t          |                     d                    S )Ns   bundle())listrevs)
bundlerepos    r.   _readbundlerevsr     s    
,,---r$   c                    t                      }|j        }|D ]0}|                    |                    |          d                    1|s| S d                    |          }g }d}| pg D ]Y}	|	                    d          r-|                    d                    |	|f                     d}D|                    |	           Z|s|                    d|z              |S )zTells remotefilelog to include all changed files to the changegroup

    By default remotefilelog doesn't include file content to the changegroup.
    But we need to include it if we are fetching from bundlestore.
           Fs   excludepattern=T)set	changelogr   readjoinr[   r   )

bundlecapsr   
bundlerevsr8   changedfilesclrnewcapsappendedcaps
             r.   _includefilelogstobundler     s     55L		B + +BGGAJJqM**** ::l++LGHR    >>,-- 	 NN5::sL&9::;;;HHNN3 :)L8999Nr$   c                 :   g }d}t          j        | ||g          }t          j        | ||d          }t	          j        |                                          }t          j        d|          }|	                    d|           |
                    |           |S )z
    Bundle may include more revision then user requested. For example,
    if user asks for revision but bundle also consists its descendants.
    This function will filter out all revision that user is not requested.
    s   02)commonheadsancestorsofr      changegroupdata   version)r   outgoingr   
makestreamr   chunkbufferr   r   
bundlepartaddparamr   )r   bundlerootsunknownheadpartsversionr   cgstreamcgparts           r.   	_rebundler     s     EG!+  H %j(GWMMH))..00HX>>>F
OOJ(((	LLLr$   c                     |j         }g }|D ]J}|                    |          }|                    |          }|D ]}|| v r|                    |           K|S rt   )r   r   parentsr   )	oldrepor   r   r   r   revr   r   parents	            r.   _getbundlerootsr     s|    		BK + +wws||**T"" 	+ 	+F   ""6***		+
 r$   c                     t          |                    d                    }t          |          dk    o#||d                                                  | k     S )N   heads(bundle())r   r   )r   r   r\   r   )headr   bundleheadss      r.   _needsrebundlingr     sU    z'9::;;KKAK*[^"<"A"A"C"Ct"K r$   c                    g }t          | |          st          j        |d          5 }t          j        |j        ||          }t          |t          j                  rYt          j
        d|j                                                  }|                    dd           |                    |           nt          |t          j                  rd}|                                D ]}|j        dk    rd}t          j
        |j        |                                          }	|j                                        D ]\  }
}|	                    |
|           |                    |	           |s)t)          j        dd	t-          |           z  z   d
          nt)          j        d          ddd           n# 1 swxY w Y   nt/          |||           }|S )zmgenerates bundle that will be send to the user

    returns tuple with raw bundle string and bundle type
       rbr   r   r      01FTs,   unexpected bundle without changegroup part, s   head: %ss   report to administrator)hints   unknown bundle typeN)r   r   	posixfiler   
readbundler8   rS   r   cg1unpackerr   r   _streamr   r   r   
unbundle20	iterpartstyper   r   r   r5   r   r   )r   r   r   
bundlefiler   f	unbundlerparthaschangegroupnewpartkeyvalues               r.   _generateoutputpartsr    s    
 ED*-- 9^J.. 	:! +JM1jIII)[%<== :)"):)?)?)A)A   j%000T""""Iw'9:: :!&%//11 * *DyN22)-%0MMMG&*k&7&7&9&9 5 5
U((e4444LL))))% +G%D		127    k"89993	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:6 *k488Ls   FF;;F?F?c                 Z   |pg }i g g }g }i }g }		 |D ]_}
|j         j                            |
          s<|
|vrt          j        ||
          }d|j        |fz  }t          j        |j        |          }|		                    ||f           t          t          |                    }t          ||||j                  }|j         }t          |||          }|D ]H}|                    |          }t          t           j                  t%          |          <   |||f||<   I	                    t'          |
g||
         R             |                    |           |	                    |
           a	 |	D ]E\  }}|                                 	 t-          j        |           /# t0          t2          f$ r Y Bw xY wnM# |	D ]E\  }}|                                 	 t-          j        |           /# t0          t2          f$ r Y Bw xY ww xY wt5                    d}d}t6          j        d         	 fd}|t6          j        d<   d}fd}t;          j        t>          j         d|           d}tC          t          |          t          |          z  t          |          z
            } | ||f||d|}|rt6          j        d<   |r t;          j"        t>          j         d|           n9# |rt6          j        d<   |r!t;          j"        t>          j         d|           w w xY w|S )	N   bundle:%s+%sFr   c                 ^     | g|R i |}D ]}|D ]}|                      |           |S rt   )addpart)bundlerr   r   resultbundler  oldchangegrouppartscratchbundless         r.   _changegrouppartz)getbundlechunks.<locals>._changegroupparth  sb     ('A$AAA&AAF( * *" * *DOOD))))*Mr$   Tc                      | ||          }|dk    r3r1|                     d          dk    r|d= |                               |S )Ns   phasess
   publishing   True)getr   )r   rg   r   
origvalues	newphasespullfrombundlestores       r.   	_listkeysz"getbundlechunks.<locals>._listkeysu  s^    dI..JI%%*=%>>-00G;;"=1!!),,,r$   r   )headsr   )#r   rf   has_noder   downloadbundlerootr   
repositoryr8   r   r   r   r   r   r   strr   draftr   r  extendcloseosunlinkIOErrorOSErrorboolr   getbundle2partsmappingr   r   r   r   r   unwrapfunction)r   rh   sourcer&  r   r   newheadsscratchheadsnodestobundleallbundlestocleanupr   newbundlefile
bundlepathr   r   r   r   r   r   r  wrappedchangegrouppartwrappedlistkeysr  r%  r  r#  r  r$  r  s                            @@@@r.   r   r   2  s   KREINHLM% 	* 	*D>'0066 *},,$*$9$$E$EM!0DI}3M!MJ!#tw
!C!CJ'..
M/JKKK!$_Z%@%@!A!AJ!9"J
DG" "J $-B"1$
J"O"OK)  !wws||/26</@/@	#d)),&')/d++ %%(Dd0CDDD   ,,,##D)))7	*: ': 	 	"J
	*%%%%W%    		&9 	 	"J
	*%%%%W%    		 ~.."O!8H&	 	 	 	 	 	 ;K'7!%	 	 	 	 	 	 	%{I	
 	
 	
 c(mmc%jj0C4E4EEFF&
 %*
 
@F
 
 " 	Q>PH+N; 	%);	   " 	Q>PH+N; 	%);	   	 MsO   E#G F++F?>F?H G54H5H		HH			H6BK2 26L(c                     d }|S )Nc                    t          j        |          }t          |t                    rAt	          |          r2| j        j                            |          }|rdd|fz  S ddd|z  fz  S 	 t          | 	                    |                    }dd|fz  S # t          $ rP}| j        j                            |          rdd|fz  cY d }~S t          j        |          }dd|fz  cY d }~S d }~ww xY w)Ns   %d %s
r   r   s   scratch branch %s not found)r   r   rS   r+  r   ra   rf   getnoder   lookup	Exception	getbundler	   forcebytestr)rh   r   r  localkeyscratchnoder   insts          r.   _lookupz_lookupwrap.<locals>._lookup  s6   #C((h$$ 	/)>x)H)H 	/*088BBK !Q$444!2X=%  
/H--..!QF** / / /#)33H== /%H5555555"/55A%A......./s*   ,(B 
C/%C*C/
C*$C/*C/r,   )r   rI  s     r.   r   r     s    / / /. Nr$      defaultc           	         t          j        |          }t          j        d||||                    d                    \  }}i }|                                }g }|                    dg           D ]}	|	|vr|                    |	           |                    d          r
g }
|                    d          pg }|                    d          D ],}t          |          rd||<   |
                    |           -|rt          j	        |||          }	 |
                    d|          }|D ]C}||vrt          j        d	|z            ||         ||<   |                    ||                    D	 |                                 n# |                                 w xY w|
|d<   ||d<   |s|r t          j        t           d
t"                     	 t%          |||          } | |||fi t          j        |          }t)          j        |          r'|                    |           t/          |||           nt1          ||           ||rt          j        t           d
           S S # |rt          j        t           d
           w w xY w)Ns   infinite-push's pulls   branch)default_branchess   rev   bookmarks
   REVTOFETCHr   r   s   remote bookmark %s not found!s   findcommonincoming)r   byteskwargsr
   get_unique_pull_pathr!  
unfilteredr   r   r   peerr   r   r5   r.  r   r   r   _findcommonincoming_readscratchremotebookmarks	strkwargsr   rZ   r   _saveremotebookmarks_savelocalbookmarksr5  )r   r8   rh   r6  optsbranchesscratchbookmarksunfiunknownnodesr   r   r   r   otherfetchedbookmarksremotescratchbookmarksr  s                    r.   r   r     s   %%D3
),,  FH ??DLxx## % %d??$$$xx 	xx%2-- 	+ 	+H$X.. + .; **  **** 	GD$//E#(#9#9 +; $: $ $  !1 < <H'777#k<xG   2B(1K$X.KK 0 :;;;;< %[V 
< 
,.A	
 	
 	
H "=Rv!N!Nb$CC(*<T*B*BCC &r** 	8"))*:;;; '=vFFFF&6777 	H%i1FGGGG	H 	H%i1FGGGG	Hs   AF F!A:I+ +J
c                    t          j        |           rt          j        d          }|                    |j        |          }i }|j                                         |j        d         	                    |          D ]j}|
                    |          \  }}||k    rJt          |          r;|j        d                             ||          }	|	rt          |	d                   ||<   k|S i S )NrX   s   remotebookmarksr   )r   rZ   r   find
activepathr8   _remotenames
clearnamesnames	listnamessplitremotenamer   nodesr   )
r8   rh   r]  remotenamesext
remotepathr  r]   pathbooknamerh  s
             r.   rT  rT    s    "2&& #88#..tw>>

 	$$&&&"j);<FFtLL 	5 	5N+;;NKKND(z!!&;H&E&E!
#56<<.   5'*58}}F8$	r$   c                    t          j        d          }|                    | j        |          }t	          j        t                    }i }|                    |           }|D ]O\  }}	}}
||k    r|	dk    r|
|v r||
= |||
<   !|	dk    r(||
                             t          |                     P|
                                D ]
\  }}|||<   |                    | |||           d S )NrX   r      branches)r   ra  rb  r8   collectionsdefaultdictr   readremotenamesr   r   r   saveremotenames)rh   newbookmarksremoteri  rj  rY  r   remotenameshexnodenametypernamer   s               r.   rV  rV    s   _^44N**47F;;J&t,,HI 0066K,7 1 1(65Z|##$$ !'&Ie$$UO""3w<<000)//11 & &'%	(""4XyIIIIIr$   c           	         |sd S |                                  5  |                                 5  |                     d          5 }g }|                                D ]6\  }}| |         }|                    ||                                f           7| j                            | ||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NrM  )wlocklocktransactionr   r   r   
_bookmarksapplychanges)rh   r   trchangesscratchbookr   	changectxs          r.   rW  rW  !  s    	 8 8tyy{{ 8 8D$4$4[$A$A 8R!*!2!2 	< 	<KT
INNK)9)9:;;;;$$T2w7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8sY   C)CA*B:.C:B>>CB>CC)C	C)C	C))C-0C-c                 $     | |i |\  }}}|d|fS )NTr,   )r   r   r   r   incremoteheadss         r.   rS  rS  ,  s*    #tT4V44FC4$$r$   c                    t          j        |          }|                    d          }t          |          dk    r	|d         }nd}d }t          t
          f|i}|                    |d          5  |                    d          }t          |          rd}|                    t          dd           |rFg |d<   |                    t          t          d           t          j        t          d	t                    }t          t          j        |||                    }	t          |	          dk    r#t#          d
          }
t%          j        |
          |	d         }|j        p|j        }t-          |||          } | ||g|R i t          j        |          }t1          j        |          r|rt|rrt5          j        |||          }	 |                    d|g          }|                    |           |                                 n# |                                 w xY wt?          |||           d d d            n# 1 swxY w Y   |r|t          _         |S )NrM  r   r   r$   r    s   bundle_storeTs   bundle2.pushbacks   _localphasemoves.   cannot push to multiple path with infinitepushr   rN  )!r   rO  r!  r\   r   configbookmarkconfigoverrider   	setconfigr   r   r   r   
_phasemover   r
   get_push_pathsr   r   r5   pushloclocrT  rU  r   rZ   r   rR  r   r   r.  rV  _localphasemove)r   r8   rh   destsrX  r   oldphasemove	overridesscratchpushpathsmsgrk  destpathr_  r  r]  r^  s                    r.   r   r   1  s   %%Dxx$$H
8}}A;L/:I			9o	6	6 &I &Ihh// ** 	BK LL':DAAA 	 !#DLL'8$???%2,j L W+D"e<<==u::>>EFFC+c"""Qx<+48 "=Rx!P!Pb$CCCC(*<T*B*BCC&r** 
	I "K "dH55"','='=$z (> ( ($ +112BCCCKKMMMMEKKMMMM '=xHHHM&I &I &I &I &I &I &I &I &I &I &I &I &I &I &IN  0#/ Ms+   0EI	-H6IH!!IIIc                    t          j        d          }dddfd|                    |          D             }fd|D             }|D ];}||vr5t          j        t          d                              |                    <i }t          j        t                    }	|D ]E\  }
}}}|dk    r
||vr|
||<   |d	k    r(|	|         
                    t          |
                     F|                    ||	|           d
S )zqPrune remote names by removing the bookmarks we don't want anymore,
    then writing the result back to disk
    rX   r      r   c                 ,    g | ]}|         k    |S r,   r,   ).0
remotenamerk  
remote_idxs     r.   
<listcomp>z0_deleteinfinitepushbookmarks.<locals>.<listcomp>t  s3       j!T)) 	)))r$   c                 8    g | ]}|         d k    |         S )r   r,   )r  r  name_idxnametype_idxs     r.   r  z0_deleteinfinitepushbookmarks.<locals>.<listcomp>y  s8       l#|33 	8333r$   s6   infinitepush bookmark '{}' does not exist in path '{}'r   rn  N)r   ra  rq  r   r5   r   formatro  rp  r   r   r   rr  )r8   rh   rk  re  ri  ru  remote_bm_namesnamer   rY  r   rw  rt  r  r  r  s     `          @@@r.   _deleteinfinitepushbookmarksr  i  s     _^44N LJH    (88>>  K
    %  O   &&+$  &t$$	   ' I&t,,H(3 - -$h|##E(9(9"IdOO$$TN!!#d)),,,""4xCCCCCr$   c                 D    |t           j        k    r | |||           dS dS )zprevent commits from being marked public

    Since these are going to a scratch branch, they aren't really being
    published.N)r   public)r   r   rh  phases       r.   r  r    s3     VUE""""" r$   c                 h     j                             t          t                    } j                             t          t
                    }d j        v s|sd S t          t          j	         j
                  vrd S  j                            d            j        j        s0 j                             t          d                     d _        d S |                    dd           t%          j         j         j
         j         j         |          }|D ]}|                    |            fd}|S )Ns
   changesetss   no changes found
r   r    r   c                     d_         d S )Nr   )cgresult)opr   s    r.   handlereplyzpartgen.<locals>.handlereply  s    r$   )r8   r4   r   r  rp   r   	stepsdoner   r   bundle2capsrt  addr   missingstatusr   r  r   r   getscratchbranchpartsrh   r  )r   r  r   r  scratchpartsscratchpartr  s   `      r.   partgenr    s:   yn==H)&&|5FGGK((((G$7$F$FFF
'''?" 	011222
 _g...4V]FOVY L $ % %$$$$     r$   r,   c                      	  fd                      d          D             }||S | v r%t                               d|                    r|S |S )Nc                      g | ]
}|         S r,   r,   )r  r   r  s     r.   r  z_getrevs.<locals>.<listcomp>  s    >>>!F1I>>>r$   s   sort(bundle())s   bundle() & %s::)r   r   r   )r  oldnodeforcer   r   s   `    r.   _getrevsr    sk    5>>>>v{{+<==>>>D  &T&**-?"I"IJJKr$   c           	   +   (  K   t          j                     } | |fddi| 	 d V   | |fdt          j                     |z
  dz  d| d S # t          $ r<} | |fdt          j                     |z
  dz  t          j        |          d|  d }~ww xY w)N	eventtype   start   success  r  	elapsedms   failurer  r  errormsg)timerC  r	   rE  )loggerservicer   startes        r.   logservicecallr    s      IKKE
F711h1&111	
 y{{U*d2	
 	
 		
 	
 	
 	
 	
    	
 y{{U*d2,Q//		
 	

 	
 	
 	
 	s   'A 
B7BBc                    | j         d         }|s| j        j        }	 t          j                    }n# t
          $ r d}Y nw xY wt          j                     t          j        dd          }t          j
                    }t          j        |j        d||||                    dd                    }| j                             d|           n|d         }|S )Ns   infinitepushloggers   unknownr   i 5wr    r'   )rK   	requestidhostnamerM   )recordsrh   r8   r   getuserrC  randomseedrandintsocketgethostname	functoolspartiallogr4   r  )r  r  r8   usernamer  r  s         r.   _getorcreateinfinitepushloggerr    s    Z-.F WZ	"'))HH 	" 	" 	"!HHH	" 	N1j11	%''"FYY<<
 
 
 	
,f5555Ms   1 A A c                 T   |j                             t          d                     t          j        |j                   }t          j        |||          5 }|D ]+}d}|j        dk    rt          j        ||           nt          j        |j        |	                                          }|j
                                        D ]\  }}	|                    ||	           |j        dv ra|j        Z|j                            d|j        z            }
|
                    dd|j        z  d	
           |
                    ddd	
           |j                            |j        ddi           |r|                    |           -	 ddd           n# 1 swxY w Y   t'          j        |                                          }t-          j                    \  }}	 	 t1          j        |d          }|                    |	                                           |                                 n# |                                 w xY wt9          |i |           	 t1          j        |           dS # t<          $ r Y dS w xY w# 	 t1          j        |           w # t<          $ r Y w w xY wxY w)zmstores the incoming bundle coming from push command to the bundlestore
    instead of applying on the revlogss&   storing changesets on the bundlestore
N	   replycapsr   )r   r   s   reply:%s   in-reply-tos   %dF	mandatory   return   1r   wb)r8   r  r   r   bundle20partiteratorr  _processpartr   r   r   r   r   replyr  idr  r  r  r   r   	getchunksr   mkstempr/  fdopenwriter.  storebundler0  rC  )r   rh   r  r  r  r   r  r   r  r  rpartbuffdr  fps                  r.   storetobundlestorer    s    	GNN1?@@AAAtw''G 
	dB		2	2 ,e 	, 	,DJyL(($R....$/			LLL
"&+"3"3"5"5 4 4JC''U3333 9 <<<x+ " 0 0ty1H I I*EDGOu '    y$%HHHJNN	q    ,
+++5	,, , , , , , , , , , , , , , ,< 
7,,..
/
/C%''NB
	2t$$BHHSXXZZ   HHJJJJBHHJJJJBJ'''	Ij!!!!! 	 	 	DD		Ij!!!! 	 	 	D	sg   D0FFF<H. J  .IJ  I/ /
I=<I= J'JJ'
J$!J'#J$$J'c                    |j         dk    r | |||          S |j                            dd          rt          | |||          S |j                            d          dk    r | |||          S |j                            dd          }t          j        |j                  }d }t          j        |||          5 }|D ]}d }	|j	        dk    rt          j
        ||           n|j	        t          j        k    r|j                            dd          }
t          j        d	|                                
          }	|	                    d|
           |j        }|sF|j                            t          dz   d           |j                            t          dz   d           n|rt          j        |j	        |                                
          }	|j                                        D ]\  }}|	                    ||           |j	        dk    rc|j        \|j                            d          }|                    dt+          |j                  d           |                    ddd           nt          j
        ||           |r"|j                            |j	        ddi           |	r|                    |	           
	 d d d            n# 1 swxY w Y   |rt1          j        |                                          }t7          j                    \  }}	 	 t;          j        |d          }|                    |                                           |                                  n# |                                  w xY wtC          |||           	 t;          j"        |           d S # tF          $ r Y d S w xY w# 	 t;          j"        |           w # tF          $ r Y w w xY wxY wd S )Ns   unbundler    r)   r   r&   r  	   cgversionr  r   r   r      _skippushkeyT   _skipphaseheadsr      reply:pushkeyr  Fr  r  r  r   r  )$r6  r8   rp   r  r   r!  r   r  r  r  r  r   r   r   r   r   r  r  r   r  r  r+  r  r  r   r   r  r   r  r/  r  r  r.  r  r0  rC  )r   rh   r  r  handleallpartsr  cgparamsr   r  r   	cgversionr  r  r  r  r  r  r  s                     r.   r   r   >  so    
yKtD"i((( w/+?@@ =!$b)<<<O,,77tD"i(((W''9IJJNtw''GH		dB		2	2 :,e 9	, 9	,DJyL(($R....k??? !KOOL%@@	$/"  
 ##J	:::;
 & JNN-?   JNN-0BBD   " 3
 ")!3DIDIIKK!P!P!PJ&*k&7&7&9&9 8 8
U"++C7777 yJ..8/$&H$4$45E$F$FE!NN .DG +    "NN9deNLLL(T222 
I!1    ,
+++s9	,:, :, :, :, :, :, :, :, :, :, :, :, :, :, :,z  w002233!)++J	Yr4(($$$







Hj111	*%%%%%   	*%%%%    sg   =HKKK#<M4 O 4N

O N5 5
OOO-OO-
O*'O-)O**O-c           	      
   t          |           }t          j                    } |t          d           | j        j        j        | j        j        j        }| j                            t          dz   d           d 	 d| j        j	        |fz  }t          j        | j        j        |          |                    d          }|                    dd          }|                    d	          }	|r                    |          }
nd }
                    d
          }|r4t!          |          dk    r!t#          j        t'          d                    t)          |
|	|          }t!          |          dk    rdnd}| j        j                            t'          d          t!          |          |fz             d}t-          dt/          t!          |          |                    D ]m}||                                                                      d          d         d d         }| j        j                            d||         |fz             nt!          |          |dz   k    r| j        j                            d           |d                                                                      d          d         d d         }| j        j                            d|d         |fz             fd|D             }fd|rt5          fd|D                       }nd}|r|d                                         nd }d }|rt9          |d          5 }|                                }t=          |dt!          |                    5  d}t!          |          |k    r'd}t#          j        |t!          |          fz            |                    |          }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t=          |d|          5  5  |r                     ||           |r)!                    ||           tE          | ||||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y    |t          d t          j                    |z
  d!z  "           nP# tF          $ rC} |t          d#t          j                    |z
  d!z  tI          j%        |          $            d }~ww xY w	 r&                                 d S d S # r&                                 w w xY w)%Nr  )r  r  Tr  rM     bookprevnoder$      forcer   r   s2   cannot push more than one head to a scratch branch   ss   pushing %d commit%s:

   r      
2   s       %s  %s
s       ...
r   c                      g | ]
}|         S r,   r,   )r  r   r  s     r.   r  zstorebundle.<locals>.<listcomp>  s    000CF3K000r$   c                 x    t                              |                                                              S rt   )r3  rD  r   )r   r  rf   s    r.   r/   zstorebundle.<locals>.<lambda>  s)    d5??6#;??3D3D#E#EFF r$   c              3   0   K   | ]} |           V  d S rt   r,   )r  r   inindexs     r.   	<genexpr>zstorebundle.<locals>.<genexpr>  s.      HHSGGCLL 0HHHHHHr$   r  s   bundlestore)
bundlesizei  @s7   bundle is too big: %d bytes. max allowed size is 100 MBs   index)newheadscountr  r  r  r  r  )'r  r  r   rh   ra   rf   r2   r  r  r)  r   r*  r8   r!  rA  r   r\   r   r5   r   r  warnrangemindescriptionrD   sumr   r   r   r  r  	addbundleaddbookmark_maybeaddpushbackpartrC  r	   rE  r.  )r  r   r  r  parthandlerstartr2   r<  r   bookprevnoder  r  r   r   plural	maxoutputi	firstlinenodesctxr  bookmarknoder  r  
bundledatabundlesizelimit	error_msgr  r  rf   r  s                             @@@r.   r  r    su   
(
,
,Cy{{C2222G%EG%EJNN(?:DAAAFT$j'AA
rwz:66::k**zz/377

8$$ 	mmH--GGGkk"455 	K((1,,+GHH   99 TQC

344D		67JJKKK	q#c$ii3344 	D 	DAtAw3355;;EBB1EcrcJIGJOOOtAw	.BBCCCCt99y1}$$GJOOL)))tBx(4466<<UCCAFssKIGJOOOtBx.CCDDD00004000FFFFF 	HHHHKHHHHHMMM
 .6?x|'')))4 	2j%(( 2AVVXX
#C
OO   
2 
2 '8O:88< " $k)s:6H*HIII++j11C
2 
2 
2 
2 
2 
2 
2 
2 
2 
2 
2 
2 
2 
2 
22 2 2 2 2 2 2 2 2 2 2 2 2 2 2 CGGG 	 	 	 	 /X... !!(L999%,f  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	! y{{%55=	
 	
 	
 	
 	
    ! y{{%55=,Q//		
 	
 	
 	
 		
  	LLNNNNN	 	6 	LLNNNN	s    KS 4PAO/#P/O3	3P6O3	7P:S P

S P
S #R&AQ6*R6Q:	:R=Q:	>RS RS R-S T. 
T>TTT. .U)rM  r  r     pushbackbookmarksr  c                 :   t          j        | j        j                  }|j                            dd          }t          j        d|                                          }|                    d|           |	                    |           t          j        |                                          }t          j                    \  }}	 	 t          j        |d          }|                    |                                           |                                 n# |                                 w xY wt'          | |j        |           	 t          j        |           n:# t*          $ r Y n.w xY w# 	 t          j        |           w # t*          $ r Y w w xY wxY wdS )z9unbundle a bundle2 part containing a changegroup to storer  r  r   r   r   r  r   )r   r  rh   r8   r   r!  r   r   r   r  r   r   r  r   r  r/  r  r  r.  r  r0  FileNotFoundError)	r  r  r  r  r   r  r  r  r  s	            r.   bundle2scratchbranchr    s    rwz**Ge44ITYY[[AAAF
OOJ	***OOF

7,,..
/
/C%''NB
	2t$$BHHSXXZZ   HHJJJJBHHJJJJBZ000	Ij!!!!  	 	 	D		Ij!!!!  	 	 	D	 1sT   <D E1 D22E1 E! !
E.-E.1F3FF
FFFFc                     |                     d          rL| j        rGd| j        j        v r;d|||d}| j                            d|                                           d S d S d S d S )Nr  s   pushbackr   )r   r   s   news   oldr   )mandatoryparams)r!  r  capabilitiesr  r   )r  r   newnoder  r   s        r.   r  r  #  s    zz&'' I8 	Irx'<<<* 	 F HZHHHHHI I	I 	I<<r$   c                    |j         t          dz            re|j        \|j                            d          }|                    dt          |j                  d           |                    ddd           d	S  | ||          S )
zWrapper of bundle2.handlepushkey()

    The only goal is to skip calling the original function if flag is set.
    It's set if infinitepush push is happening.
    r  Nr  r  Fr  r  r  r   )r  r   r  r  r   r+  r  )r   r  r  r  s       r.   r   r   /  s     
z'/9: 8H$$%566ENN>3tw<<5NIIINN9deN<<<q4D>>r$   c                 H    |j         t          dz            rdS  | ||          S )zWrapper of bundle2.handlephases()

    The only goal is to skip calling the original function if flag is set.
    It's set if infinitepush push is happening.
    r  N)r  r   )r   r  r  s      r.   r   r   ?  s/     
z'*<<= 4D>>r$   c           	         d}t          |          |k    rdS g }|D ],}|                    d           |                    |           -t          t          j        d          5 }t          j                    dd| g|z   }t          j        t          j
        t          j        |          dd|||	           ddd           dS # 1 swxY w Y   dS )
zstarts a separate process that fills metadata for the nodes

    This function creates a separate process and doesn't wait for it's
    completion. This was done to avoid slowing down pushes
    r  Ns   --nodes   w+bs   debugfillinfinitepushmetadatas   -RTF)	close_fdsshellstdinstdoutstderr)r\   r   r   r/  devnullr   hgexecutable
subprocessPopenr   rapplyr   tonativestr)r)  rh  maxnodes	nodesargsr   r)  cmdlines          r.   _asyncsavemetadatar2  L  s4    H
5zzHI  ###	bj&	!	! 
W,	

  	OH0'::	
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   #ACC	Crt   )NN)rJ  )k__doc__ro  
contextlibr  rQ   r/  r  rer  r+  r  mercurial.noder   r   mercurial.i18nr   mercurial.pycompatr   r   mercurial.utilsr   r	   r
   	mercurialr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r6   r   r   
testedwithconfigtable
configitemr   r  r   r   revsetpredicatetemplatekeywordr   compilesearch
_maybehashr=   rO   rF   r_   ra   rr   rv   r{   rx   ry   rz   r   r}   r   	batchabler   r   r   r   r   r   r  r   r   r   rT  rV  rW  rS  r   r  r  r  b2partsgeneratorr  r  r  contextmanagerr  r  r  r   r  parthandlerr  r  r   r   r2  r,   r$   r.   <module>rG     s_  Q Qh              				  				             
             
                                                *        #
!Y!+..
 

   
 
   
 
   
 
   
 
   
 
   
 
   
 
   
 
   
 
"   
 
    // #9 +)+--+)+--' RZ&&-
Q Q Q  8            85 5 5- - -
  

 

 

D D D8  2  ! ! !% % % %$   ". . .  <  *    $ $ $N[ [ [ [|  6CH CH CH CHL  .J J J28 8 8% % %
5 5 5p(D (D (DV +1- # # # # 011  21D ;= [6 7     ,  :4 4 4n] ] ]@] ] ]@ 	 	 	 	6	I 	I 	I   
 
 

 
 
 
 
r$   