a +bŸ@sddlmZmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlmZddlmZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z#m$Z$m%Z&m'Z'm(Z(ddl)m*Z*m+Z+m,Z,Gd d d e-Z.d d Z/d dZ0ej1r&ddZ2ddZ3nddZ2ddZ3ddZ4ddZ5ddZ6ddZ7ddZ8dd Z9d!d"Z:Gd#d$d$e-Z;Gd%d&d&e-Zd+d,Z?d-d.Z@d/d0ZAd1d2ZBd3d4ZCdAd5d6ZDd7d8ZEd9d:ZFd;d<ZGd=d>ZHd?d@ZIdS)B)absolute_importprint_functionN)_)getattr)tracing)cmdutilcolorcommands demandimportencodingerror extensions fancyoptshelphghook localrepo profilingpycompatrcutil registrar requirementsscmutiluiutilvfs)procutil stringutilurlutilc@seZdZdddZddZdS)requestNc CsD||_||_||_||_||_||_||_i|_|p6g|_d|_ dSN) argsrrepofinfoutferrfmsg earlyoptions prereposetupscanonical_command) selfr"rr#r$r%r&r'r)r,8/usr/lib64/python3.9/site-packages/mercurial/dispatch.py__init__:s  zrequest.__init__cCsd}|jj}zr|rp|\}}}z||i|Wq|durNtd}|jd|jjddYq0qW|dur|n|dur|0dS)Nrserror in exit handlers: T)force)rZ _exithandlerspopsysexc_infoZ warnnoi18n traceback)r+exchandlersfuncr"kwargsr,r,r-_runexithandlersZs   zrequest._runexithandlers)NNNNNNN)__name__ __module__ __qualname__r.r8r,r,r,r-r 9s r c Csd}t|drf|dusJ|jdus*Jz|jWn,tyd}z|}d}WYd}~n d}~00t|dr|dus~J|jdusJz:|dur|jtjkr|jdt |j |jWntyd}Yn0|S)Nsfoutsferrs abort: %s ) r safehasattrr%flushIOErrorr&errnoEPIPEwriter strtolocalstrerror)rerrstatuser,r,r- _flushstdiols*      rHcCs~zTttd"ttjdd}Wdn1s:0Yt|}tWntyjd}Yn0t |d@dS)zrun the command in sys.argvzparse args into requestrNr<) initstdiorlogr rZsysargvdispatch _silencestdioKeyboardInterruptr1exit)reqrFr,r,r-runs 0   rQcCstjdurVdtjjd}ttjdr2tjj|d<tjtjjtjj tjj fi|t_tj durdtj jd}ttj drtj j|d<tjtj jtj j tj j fi|t_ tj durtjtj jtj j tj j dtj jdt_ dS)N )newlineline_buffering write_through) r1stdoutrTrr=rUio TextIOWrapperbufferr errorsstderrstdin)r7r,r,r-rJsD     rJc CsdtjtjfD]R}|durq z|Wq Wnty<Yn0z |Wq ty\Yq 0q dSr!)r1rVr[r>r?closefpr,r,r-rMs   rMcCs$tjtjtjfD]}t|qdSr!)r1r\rVr[rZ setbinaryr^r,r,r-rJscCsdSr!r,r,r,r,r-rMscCsddd|DS)N css|]}t|VqdSr!r shellquote).0ar,r,r- z_formatargs..)joinr"r,r,r- _formatargssric Cs\d}z t|}Wn.tjy>}z|}d}WYd}~n d}~00t|j|}|rX|sX|}|S)zErun the command specified in req.args; returns an integer status codeNr<) _rundispatchr Z StdioErrorrHr)rPrErFrGretr,r,r-rLs  rLc Cstd||jr|j}n|jr,|jj}ntj}z|jsFtj|_|j t |j|j |jdrx|j dddd|j r|j |j_ |jr|j|j_|jr|j|j_|jr|j|j_WnDtjy}z(||WYd}~WddSd}~00t|j }t}d}zzt|p(d}Wntjy}z@|jtd ||jrt|jtd |jWYd}~nd}~0ty.}zz0t|tjrtd }ntd }|j|WnJtjyYn6ty}z|jtj krWYd}~n d}~00d}WYd}~n d}~00Wt|}|j!|jj"r~|d |jj#d<|jjdit$%|jj#|d@}|jjdd||||||j&dz |'Wn|pd}Yn0|j!nt|}|j!|jj"r |d |jj#d<|jjdit$%|jj#|d@}|jjdd||||||j&dz |'Wn|pbd}Yn0|j!0|WdS1s0YdS)Nzdispatch._rundispatch tracebackuion --tracebackr<rrs** ProgrammingError: %s s** (%s) skilled! s interrupted! iscommand_duration uiblockedui blocked ms rIs commandfinishs!%s exited %d after %0.2f seconds ) return_codedurationr*)rprq)rprq)(rrKr&rrr[uimodloadr(update_earlyparseoptsr" setconfigr$r%r'r AbortrBformatrirtimer _runcatchZProgrammingErrorrhintrN isinstanceSignalInterruptr?r@rAr>ZlogblockedtimesZ _blockedtimesr strkwargsr*r8) rPr&instZ formattedargsZ starttimerkmsgrsrrr,r,r-rjs      $               rjc stdtdd}jz*dD] }tt|d}|r t||q WntyVYn0fdd}t|WdS1s0YdS)Nzdispatch._runcatchcWs tjdSr!)r rrhr,r,r- catchterm\sz_runcatch..catchterm)sSIGBREAKsSIGHUPsSIGTERMc sd}zBtjddtji}|d}t|tjd\}}|d}Wn tjtj t t j fyfYn0|dkrd|vrt jdksjddksjddsjd dksjd dkrttd tjfzd }d tji}d tji}tjjd }jr:|D]"\} } } jjj| | | ddqdd}t} |rZr`d }nXjdrt2z t|} Wnt yYn0Wdn1s0Y| j||<| j||<jdrH!td|d kr|||d kr!td|t||Wdn1s>0Yzt"W#WS#0Wn6jdrt$%||t&'d Yn0dS)NrFsserves--stdios-Rr--s/potentially unsafe serve --stdio invocation: %sspdbconfig--config)sourcermdebuggersAentering debugger - type c to continue starting hg or h for help s3%s debugger specified but its module was not found )(rr"r globaloptsrfindcmdtabler UnknownCommandAmbiguousCommand IndexErrorgetopt GetoptErrorlen startswithryrrZpprintpdbZ set_traceZ post_mortem _parseconfigrr(r#rxconfigplainr Z deactivated __import__ ImportErrorwarn _dispatchr>r3 print_excr1r2) ZrealcmdZcmdargscmdaliasesentryZdebuggerZ debugtraceZ debugmortemZcfgsZsecnamevalZdebugmodrPrr,r- _runcatchfunchs              &    * z _runcatch.._runcatchfunc)rrKrrsignal ValueError _callcatch)rPrrnumrr,rr-r|Ys   nr|c Cs2d}zt||WStjy^}z2d}|td|jd|jfWYd}~nd}~0tj y}z~d}|j r| dt |j}|td|j |ftj||j dd d n"|td |j|td WYd}~n,d}~0tjy}zd}td |j }z,tj|t|j d d}||||Wn~tjtjfyd}|jrt|j|j }|r|||dt|d }|s|||tdYn0WYd}~nHd}~0tyYn,tyYnt|sYn0|ddr*|SdSdS)zlike scmutil.callcatch but handles more high-level exceptions about config parsing and commands. besides, use handlecommandexception to handle uncaught exceptions. r< s&hg: command '%s' is ambiguous: %s r`Nhelps hg %s: %s FT)Zfullcommandshg: %s s0(use 'hg help -v' for a list of global options) shg: unknown command '%s' ) unknowncmds(%s) s'(use 'hg help' for a list of commands) rmsdetailed-exit-code)rZ callcatchr rrrprefixrgmatches CommandErrorrpagerrbytestrmessager help_rrZ formattedhelprBryZ all_commandsZ getsimilarZsimilarity_hintr?rNhandlecommandexception configbool) rr6Zdetailed_exit_coderZmsgbytesZnocmdmsg formattedZ suggestedZsimr,r,r-rsb  $    ( rcszg}t|dst|d|}|rrdttj|}gfdd}td||}fddt Dt |}|S) Ns _origfuncr"r`csBt|dd}||tkr0|SttddS)Nrs#too few arguments for command alias)intgroupappendrr InputErrorr)mr givenargsnumsr,r-replacers   zaliasargs..replacer \$(\d+|\$)csg|]\}}|vr|qSr,r,)rcix)rr,r- 'rfzaliasargs..) rr=rrgmaprrbresub enumerater shlexsplit)fnrr"rrr,rr- aliasargss   rcs|ddt|D|d<dd<d|d<ddd |Dd <d dd }t|}|fd d|S)zXinterpolate args into cmd for shell aliases This also handles $0, $@ and "$@". cSsi|]\}}d|d|qS)s$%drr,)rcrargr,r,r- 3rfz$aliasinterpolate..s$0$s$$r`s$@css|]}t|VqdSr!ra)rcrr,r,r-re;rfz#aliasinterpolate..s"$@"|s\$cs |Sr!)r)rZ replacemapr,r-?rfz"aliasinterpolate..)rrgkeysreplacercompiler)rr"rZregexrr,rr-aliasinterpolate,s rc@s:eZdZddZd ddZeddZdd Zd d ZdS) cmdaliasc sl|__d_|_d_g_g_d_d_d_ |_ zBt j|\}}t |D]\}} | |ur`|_q|q`d_Wntjyd_Yn0jstdj_dSjdr jddd_fdd} | _d_||jdSzt j} WnBty^} z(td jt| f_WYd} ~ dSd} ~ 00t| \} } | rtd jd t j| d f_dS| d _}| _z^t ||dd}t|d kr|\__}n|\__d}d_|||j|WnXtjy>tdj|f_d_ Yn*tj yftdj|f_Yn0dS)NrfFTsno definition for alias '%s'!rcsXddjfi}fdd}td|}tj|}j||djdS)NsHG_ARGSr`cs`|ddkr|St|dtkr8|Sdt|djfdSdS)NrrsLNo argument found for substitution of %i variable in alias '%s' definition. rf)groupsrrrdebugr)r)r"r+rr,r- _checkvardsz0cmdalias.__init__..fn.._checkvarrsalias_%s)environZ blockedtag)rgrrrrsystem)rr"envrrr+Zshdef)r"rr-ras  zcmdalias.__init__..fns&error in definition for alias '%s': %ssLerror in definition for alias '%s': %s may only be given on the command line/rrs+alias '%s' resolves to unknown command '%s's-alias '%s' resolves to ambiguous command '%s')!rrcmdname definitionrroptsrbadaliasrrrrrZ iteritemsshadowsr rrrshellalias _populatehelprrr forcebytestr_earlysplitoptsrgZziplistr0rr)r+rrrcmdtablerrrrrGrr"rZ earlyoptsrZ tableentryZcmdhelpr,rr-r.Cs      zcmdalias.__init__Nc Csi}dD]N}|dd||fd}|dur,qt|sNtd||f|_dS|||<q|d|pdd|_|jr|jd|r|jdt|d|_d |v|_ |d t |} | durt | } | |_ |d tjj|_dS) N)docrcategoryaliass%s:%ss/non-ASCII character in alias definition '%s:%s'rrfshg rrr)rr Z isasciistrrrgetrrrZowndocrZgetdocZsysstr__doc__rrZ CATEGORY_NONEZ helpcategory) r+rrrrZ defaulthelpcfgkvdocr,r,r-rs0    zcmdalias._populatehelpcCsttj|j}t|j|Sr!)rmaplistr expandpathrrr)r+r"r,r,r-r"sz cmdalias.argscCsFdtddd}||vr t||js2t|dr:||St|j|S)NTF)norepointents optionalrepo inferreposhell)setAttributeErrorrrr=rr)r+rZ adefaultsr,r,r- __getattr__szcmdalias.__getattr__cOs|jrdd}|jrTz.t||jdd\}}td||f}WntjyRYn0tj|j|d|j r| d|j |jf| dd|j |j t|dr|j|g|Ri|Sz t|j|g|Ri|WStjyd|jg|j}| d|j |fYn0dS) Nrs"'%s' is provided by '%s' extension)r}s alias '%s' shadows command '%s' s commandaliassalias '%s' expands to '%s' rr`)rrrZ disabledcmdrrr rZ ConfigErrorrrrrKrrr=rchecksignatureSignatureErrorrgr")r+rr"rr}rextr,r,r-__call__s6  zcmdalias.__call__)N) r9r:r;r.rpropertyr"rrr,r,r,r-rBs f   rc@s>eZdZdZddZejddZddZdd Z d d Z d S) lazyaliasentryz.=r.rs?malformed --config option: %r (use --config section.name=value)) splitrrxrrr rrrr)rrZconfigsrrvaluesectionr,r,r-r[s$ rcCs.i}tj|tj||d dddgid|S)Ns strictflagsT repositoryrepo)rZearlyZ optaliases)rr rr)rr"rr,r,r-rwss rwcCs d}gd}tj|||dddS)zCSplit args into a list of possible early options and remainder argssR:)scwd=s repository=srepo=sconfig=T)rZkeepsep)rZ earlygetopt)r"Z shortoptionsZ longoptionsr,r,r-rs  rc Cstj||d|dd|||dz6t||||} tj||d|dd|| ||dWn6tytj||d|dd|||dYn0| S) Nspre-%sTr`)r"patsrspost-%sF)r"resultr!rsfail-%s)rrg _runcommand Exception) luir#rfullargsrrdcmdpatsrrkr,r,r- runcommandsB   r)cCszttj|ddd~}t|}tj|vr>tj |vsPWdWdSt tj|d}t ||}|j }||d|Wdn1s0YWntyYn0dS)a!if the current repository is shared one, this tries to read .hg/hgrc of shared source if we are in share-safe mode Config read is loaded into the ui object passed This should be called before reading .hg/hgrc or the main repo as that overrides config set in shared source.hgsrequiresrbNhgrc)openospathrgrread splitlinesrequirementsmodZSHARESAFE_REQUIREMENTZSHARED_REQUIREMENTrrZ _getsharedvfsbase readconfigr?)rr/r_rZhgvfsZ sharedvfsrootr,r,r-_readsharedsourceconfigs 4 r6c Cs |durTz t}Wn>tyR}z&ttdt|jWYd}~n d}~00t |p`d}|sl|}nJ| }t rt |||tj|dd||tj|dd||rt||d}| }t rt |||tj|dd||tj|dd|||fS)zpReturn (path, local ui object) for the given target path. Takes paths in [cwd]/.hg/hgrc into account." Ns+error getting current working directory: %srfr*r,shgrc-not-sharedr)r getcwdOSErrorr ryrrCrDrfindreporrZ use_repo_hgrcr6r4r.r/rgrZget_clone_path)rrpathZwdrGr/r%r,r,r- _getlocals2     r;c sizttjWntjy.YdS0s8dStj}dz"dd}t||\}}Wnt j t j fyYdS0|d|drt drt\}fddfddSdS) z=Return the function to run the shell alias, if it is requiredNrrmrrcsgddRSNrr,r,)r"rrr,r-rrfz"_checkshellalias..c s tdddgi Sr<)r)r,)r"rr'r%rrr,r-rs)rr rrrrrrrr rrrr=r)r%rr"rstrictrrZ _earlyoptsr,)r"rr'rr%rrr-_checkshellaliass(  r>c s|j|j|jd}|r$t||jd}t|\}}|h}|jrX||jj|jdsv|jdsv|jdrdD]6}t t |j|}|D]}| d||d|qqz|jd r|D]}| d d d d qn.|jd dur| d d r| d d dd| d d } t j|| d} t||j_t|tjt|} | r~|D]}t|qX| WdS|dd} | r| t_} t|\}}}||_|d|jdkrttd|d|jdkrttd|d|jdkrttd|d|jdkr|t?|krd8|g| |_||jd<t@|YWdS|sttd9tAYn0|r&|j|d:r&|B}Cd7|n|rHDtd;tE| }Fdd?}zDtH|||| |||| W|r||jkr|IWdSn|r||jkr|I0Wdn1s0YdS)@Nscwdrverbosedebugquiet)r?r@rArmrsprofiles profilingsenabledstrues --profileFsfalses --no-profile)Zenabledsfallbackencodingrs&option --config may not be abbreviateds#option --cwd may not be abbreviatedsroption -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repors(option --debugger may not be abbreviatedsencodings encodingmodestimecSs:t}|ddkr6|d|d|d|dtf}|S)Nrgrrrr)r.timesrr{tr,r,r- get_timesos "z_dispatch..get_timesc sb}td|dd|dd|dd|dd|ddfdS)Ns4time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f) rrrrr)rrrC)rEsrr,r- print_timexsz_dispatch..print_timerlrnrosnoninteractives interactivesoffs-ysinsecureTscolors--colorspagersinternal-always-sautosversionr)rs shortlist)r/Z presetupfuncsrsrepository '%s' is not localsbundles mainreporootr rs --repositorys+no repository found in '%s' (.hg not found)shiddenswarning: --repository ignored scommands%s cstgRiSr!)rrr,)r"r6 strcmdoptrr,r-rrfz_dispatch..)Jr"rr(r.chdirr;r#addrrboolrxrrprofilerZloadall __class__rr rr>Z populateuirr Zfallbackencodingrr*r rrZ encodingmodeatexitstartrZinsecureconnectionsr ZsetuprZ parseboolrZ disablepagerZversion_rrr$r%r&r'rZ repositoryr)rlocalr5ZRequirementErrorZ RepoErrorrrrrr9countrrr7Z unfilteredinsertrrirKrr)r])rPcwdr:r/r%ZuisoptrZui_rLZprofilerZ shellaliasfnfallbackr&rrrrGZcoloroptr#r(ZreposZguessrr'r,)r"r6rErFrHrr-r sT                      "           rcCsdz:td||WdWS1s.0YWn$tjy^t|tdYn0dS)z8Run a command function, possibly with profiling enabled.zRunning %s commandNsinvalid arguments)rrKr rrr)rrrZcmdfuncr,r,r-r#s *r#c stjdddddf}|dddurtD]\}}tt|dd}t|}t|dtd }| s||d ||f}qt |rq0d d | D}|vrq0fd d |D}t |p|} |ddus| |dkr0|| ||f}q0|ddurR|\}}}}t |ttfs&ddd |D}|p2td} td|| ||t|f} n.|dd} | durptd} td| d} ttjdd} dd| td| tdttddfdd ttD7} | S)z:Produce a warning message for the current active exceptionr)rNrfrmssupportcontact testedwithZbuglinksthe extension author.sunknowncSsg|]}t|dqS)r)r versiontuplercrDr,r,r-r(rfz%_exceptionwarning..csg|]}|kr|qSr,r,rX)ctr,r-r,rfrrrcSsg|]}t|qSr,)rr)rcrr,r,r-r4rfs (version N/A)s** Unknown exception encountered with possibly-broken third-party extension "%s" %s ** which supports versions %s of Mercurial. ** Please disable "%s" and try your action again. ** If that fixes the bug please report it to %s s)https://mercurial-scm.org/wiki/BugTrackers?** unknown exception encountered, please report by visiting **  cSs*|d}t|d}|r&|d|7}|S)Nrrr`)r moduleversion)rrZverr,r,r- ext_with_verLs  z'_exceptionwarning..ext_with_vers ** Python %s s*** Mercurial Distributed SCM (version %s) s** Extensions loaded: %s s, csg|] }|qSr,r,)rcr)r\r,r-rYrf)rrWrrrrrr[rrZismoduleinternalrmaxr~bytesstrrgrsysbytesr1versionrsorted)rZworstrmodrVrareportZtestedlowerZnearestZextverwarningZ bugtrackerZ sysversionr,)rYr\r-_exceptionwarning st             rgc Cs0t|}|dd|tt||dS)zProduce a warning message for broken commands Called when handling an exception; the exception is reraised if this function returns False, ignored otherwise. scommandexceptions%s %s F)rgrKrr`r3 format_excr)rrfr,r,r-r`s  r)N)JZ __future__rrr@rrWr.rrrr1r3Zi18nrrrZhgdemandimportrrr r r r r rrrrrrrrrrr2rrrtrrZutilsrrrobjectr rHrQZispy3rJrMrirLrjr|rrrrrrrrrwrr)r6r;r>rr#rgrr,r,r,r-s^   \3; T<8$-  ' #!u V