o ]LbŸ@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 dZ0ej1rddZ2ddZ3nddZ2ddZ3ddZ4ddZ5ddZ6ddZ7ddZ8dd 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@s,eZdZ       dddZddZdS)requestNc CsD||_||_||_||_||_||_||_i|_|pg|_d|_ dSN) argsrrepofinfoutferrfmsg earlyoptions prereposetupscanonical_command) selfr"rr#r$r%r&r'r)r,4/usr/lib/python3/dist-packages/mercurial/dispatch.py__init__:s   zrequest.__init__cCsd}|jj}z9|r7|\}}}z ||i|Wn|dur'td}|jd|jjddY|s W|dur>|dS|durF|w)Nrserror in exit handlers: T)force)r _exithandlerspopsysexc_info warnnoi18n traceback)r+exchandlersfuncr"kwargsr,r,r-_runexithandlersZs$    zrequest._runexithandlers)NNNNNNN)__name__ __module__ __qualname__r.r:r,r,r,r-r 9s r c Csd}t|dr3|dusJ|jdusJz|jWnty2}z |}d}WYd}~nd}~wwt|drq|dus?J|jdusFJz|dur]|jtjkr]|jdt |j |jW|Stypd}Y|Sw|S)Nsfoutsferrs abort: %s ) r safehasattrr%flushIOErrorr&errnoEPIPEwriter strtolocalstrerror)rerrstatuser,r,r- _flushstdiols4      rJcCs~z*ttdttjdd}Wdn1swYt|}tWn ty5d}Ynwt |d@dS)zrun the command in sys.argvzparse args into requestrNr>) initstdiorlogr rsysargvdispatch _silencestdioKeyboardInterruptr2exit)reqrHr,r,r-runs   rTcCstjdur+dtjjd}ttjdrtjj|d<tjtjjtjj tjj fi|t_tj durVdtj jd}ttj drDtj j|d<tjtj jtj j tj j fi|t_ tj durptjtj jtj j tj j dtj jdt_ dSdS)N )newlineline_buffering write_through) r2stdoutrWrr?rXio TextIOWrapperbufferr errorsstderrstdin)r9r,r,r-rLsF      rLc Cs^tjtjfD]&}|dur qz|WqtyYnwz|Wqty,YqwdSr!)r2rYr^r@rAclosefpr,r,r-rPs   rPcCs$tjtjtjfD]}t|qdSr!)r2r_rYr^r setbinaryrar,r,r-rLs cCsdSr!r,r,r,r,r-rPcCsddd|DS)N cs|]}t|VqdSr!r shellquote).0ar,r,r- z_formatargs..)joinr"r,r,r- _formatargssroc Cs\d}zt|}Wntjy}z |}d}WYd}~nd}~wwt|j|}|r,|s,|}|S)zErun the command specified in req.args; returns an integer status codeNr>) _rundispatchr StdioErrorrJr)rSrGrHrIretr,r,r-rOs  rOc Cs~td|jr|j}n |jr|jj}ntj}zD|js#tj|_|j t |j|j |jdr<|j dddd|j rD|j |j_ |jrL|j|j_|jrT|j|j_|jr\|j|j_Wn!tjy~}z||WYd}~WddSd}~wwt|j }t}d}zzt|pd}Wnttjy}z|jtd ||jr|jtd |jd}~wty}zBzt|tjrtd }ntd }|j|Wn"tjyYnty}z |jtj krWYd}~nd}~wwd}WYd}~nd}~wwWt|}|j!|jj"r1|d |jj#d<|jj  dit$%|jj#|d@}|jjdd||||||j&dz|'Wn |pRd}Y|j!nQt|}|j!|jj"r|d |jj#d<|jj  dit$%|jj#|d@}|jjdd||||||j&dz|'Wn |pd}Y|j!w|WdS1swYdS)Nzdispatch._rundispatch tracebackuion --tracebackr>rrs** ProgrammingError: %s s** (%s) skilled! s interrupted! iscommand_duration uiblockedui blocked ms rKs commandfinishs!%s exited %d after %0.2f seconds ) return_codedurationr*)rwrx)(rrMr&rrr^uimodloadr(update_earlyparseoptsr" setconfigr$r%r'r AbortrDformatrortimer _runcatchProgrammingErrorrhintrQ isinstanceSignalInterruptrArBrCr@logblockedtimes _blockedtimesr strkwargsr*r:) rSr&inst formattedargs starttimerrmsgrzryr,r,r-rps                          &rpc std:dd}jzdD]}tt|d}|r t||qWn ty+Ynwfdd}t|WdS1sBwYdS)Nzdispatch._runcatchcWstjr!)r rrnr,r,r- catchterm\sz_runcatch..catchterm)sSIGBREAKsSIGHUPsSIGTERMc sd}z!tjddtji}|d}t|tjd\}}|d}Wntjtj t t j fy3Ynw|dkrnd|vrnt jdks`jddks`jdds`jd dks`jd dkrnttd tjfzd }d tji}d tji}tjjd }jr|D]\} } } jjj| | | ddqdd}t} |rrd }n)jdrtzt|} Wn t yYnwWdn1swY| j||<| j||<jdr!td|d kr|||d kr!td|t ||Wdn 1swYz t"W#WS#wjdrCt$%||t&'d )NrFsserves--stdios-Rr--s/potentially unsafe serve --stdio invocation: %sspdbconfig--config)sourcertdebuggersAentering 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 startswithrrrpprintpdb set_trace post_mortem _parseconfigrr(r#rconfigplainr deactivated __import__ ImportErrorwarn _dispatchr@r5 print_excr2r3) realcmdcmdargscmdaliasesentrydebugger debugtrace debugmortemcfgssecnamevaldebugmodrSrr,r- _runcatchfunchs                     z _runcatch.._runcatchfunc)rrMrrsignal ValueError _callcatch)rSrrnumrr,rr-rYs    n$rc Csd}zt||WStjy.}zd}|td|jd|jfWYd}~nd}~wtj yx}z>d}|j r]| dt |j}|td|j |ftj||j dd d n|td |j|td WYd}~nd}~wtjy}zad}td |j }ztj|t|j d d}||||Wn;tjtjfyd}|jrt|j|j }|r|||dt|d }|s|||tdYnwWYd}~nd}~wtytyt|sY|ddr|SdS)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 reNhelps hg %s: %s FT)fullcommandshg: %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) rtsdetailed-exit-code)r callcatchr rrrprefixrmmatches CommandErrorrpagerrbytestrmessager help_rr formattedhelprDr all_commands getsimilarsimilarity_hintrArQhandlecommandexception configbool) rr8detailed_exit_codermsgbytesnocmdmsg formatted suggestedsimr,r,r-rsn        rcszg}t|dst|d|}|r9dttj|}gfdd}td||}fddt Dt |}|S) Ns _origfuncr"recs>t|dd}||tkr|Sttd)Nrs#too few arguments for command alias)intgroupappendrr InputErrorr)mr givenargsnumsr,r-replacers   zaliasargs..replacer \$(\d+|\$)csg|] \}}|vr|qSr,r,)riix)rr,r- 'zaliasargs..) rr?rrmmaprrhresub 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,)rirargr,r,r- 3sz$aliasinterpolate..s$0$s$$res$@csrfr!rg)rirr,r,r-rk;rlz#aliasinterpolate..s"$@"|s\$cs |Sr!)r)r replacemapr,r-?s z"aliasinterpolate..)rrmkeysreplacercompiler)rr"rregexrr,rr-aliasinterpolate,s rc@s:eZdZddZd ddZeddZdd Zd d ZdS) cmdaliasc sf|__d_|_d_g_g_d_d_d_ |_ z!t j|\}}t |D] \}} | |ur=|_nq0d_Wn tjyOd_Ynwjs]tdj_dSjdrjddd_fdd} | _d_||jdSzt j} Wn ty} ztd jt| f_WYd} ~ dSd} ~ wwt| \} } | rtd jd t j| d f_dS| d _}| _z/t ||dd}t|d kr|\__}n|\__d}d_|||j|WdStjytdj|f_d_ YdStj y2tdj|f_YdSw)NFTsno definition for alias '%s'!rcsXddjfi}fdd}td|}tj|}j||djdS)NsHG_ARGSrecs\|ddkr |St|dtkr|Sdt|djfdS)NrrsLNo argument found for substitution of %i variable in alias '%s' definition. r)groupsrrrdebugr)r)r"r+rr,r- _checkvardsz0cmdalias.__init__..fn.._checkvarrsalias_%s)environ blockedtag)rmrrrrsystem)rr"envrrr+shdef)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 definitionrroptsrbadaliasrrrrr iteritemsshadowsr rrrshellalias _populatehelprrr forcebytestr_earlysplitoptsrmziplistr1rr)r+rrr cmdtablerrrrrIrr"r earlyoptsr tableentrycmdhelpr,rr-r.Cs         zcmdalias.__init__Nc Csi}dD]'}|dd||fd}|durqt|s'td||f|_dS|||<q|d|p2d|_|jrL|jd|rL|jdt|d|_d |v|_ |d t |} | durct | } | |_ |d tjj|_dS) N)docrcategoryaliass%s:%ss/non-ASCII character in alias definition '%s:%s'rrshg rrr)rr isasciistrrr getrrrowndocrgetdocsysstr__doc__rr CATEGORY_NONE helpcategory) r+rrrr defaulthelpcfgkvdocr,r,r-rs0     zcmdalias._populatehelpcCsttj|j}t|j|Sr!)rmaplistr expandpathrrr)r+r"r,r,r-r"s z cmdalias.argscCsFdtddd}||vrt||jst|dr||St|j|S)NTF)norepointents optionalrepo inferreposhell)setAttributeErrorr rr?rr)r+r adefaultsr,r,r- __getattr__s zcmdalias.__getattr__cOs|jr2d}|jr*zt||jdd\}}td||f}Wn tjy)Ynwtj|j|d|j r@| d|j |jf| dd|j |j t|dr\|j|g|Ri|Szt|j|g|Ri|WStjyd|jg|j}| d|j |fw) Nrs"'%s' is provided by '%s' extension)rs alias '%s' shadows command '%s' s commandaliassalias '%s' expands to '%s' r0re)r rr disabledcmdr rr r ConfigErrorrrrrMr rr?rchecksignatureSignatureErrorrmr")r+rr"r rrextr,r,r-__call__s:  zcmdalias.__call__r!) r;r<r=r.rpropertyr"r4r:r,r,r,r-rBs f  rc@s>eZdZdZddZejddZddZdd Z d d Z d S) lazyaliasentryzr,r,r-__len__rdzlazyaliasentry.__len__N) r;r<r=r"r.r propertycacher?rBrErFr,r,r,r-r<s  r<c Csn|jdddD]-\}}z ||j|krWqWn ttfy!Ynw|d|}t|||||}|||<qdS)NrT) ignoresub) configitemsr KeyErrorr2 configsourcer<)rrrr rrr,r,r- addaliasess  rLc Csi}i}z t|tj|}Wntjy$}z tdt|d}~ww|rf|d|dd}}t |tj | dd\}}|d}t |d|}|d|}|r_ttjt||}t|d} nd}g} tjD]} | | d| d|| d| dfqmz tj|| |dd}Wntjy}z t|t|d}~wwtjD]} | d} || || <|| =q||r|dpd|||fS) NrrrtstrictsdefaultsrT)gnu)rr rrrr rrrrrrrrrrr*rr+rlistr) rr"options cmdoptionsrrrrdefaultscor@r,r,r-_parse.sJ  (  rUc Csg}|D]D}z-dd|ddD\}}|dd\}}|r |s"t||||d||||fWqttfyHttdt |w|S)z0parse the --config options from the command linecSsg|]}|qSr,)strip)ricfgelemr,r,r-raz _parseconfig..=r.rs?malformed --config option: %r (use --config section.name=value)) splitrrrrr rrrr)rrconfigsr&rvaluesectionr,r,r-r[s& rcCs.i}tj|tj||d dddgid|S)Ns strictflagsT repositoryrepo)rNearly optaliases)rr rr)rr"rPr,r,r-r~ss r~cCs d}gd}tj|||dddS)zCSplit args into a list of possible early options and remainder argssR:)scwd=s repository=srepo=sconfig=T)rNkeepsep)r earlygetopt)r" shortoptions longoptionsr,r,r-rs  rc Cstj||d|dd|||dzt||||} tj||d|dd|| ||dW| StyFtj||d|dd|||dw) Nspre-%sTre)r"patsr spost-%sF)r"resultrgr sfail-%s)rrm _runcommand Exception) luir#rfullargsrrPdcmdpatsrQrrr,r,r- runcommandsD   rocCszXttj|dddB}t|}tj|vrtj |vs) WdWdSt tj|d}t ||}|j }||d|WdWdS1sQwYWdStybYdSw)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)openospathrmr1read splitlinesrequirementsmodSHARESAFE_REQUIREMENTSHARED_REQUIREMENTrr _getsharedvfsbase readconfigrA)rrurbrhgvfs sharedvfsrootr,r,r-_readsharedsourceconfigs   & rc Cs|dur$zt}Wnty#}z ttdt|jd}~wwt |p*d}|s0|}n%| }t rUt |||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: %srrprrshgrc-not-sharedr)r getcwdOSErrorr rrrErFrfindrepor=r use_repo_hgrcrr}rtrurmrget_clone_path)rrpathwdrIrurkr,r,r- _getlocals6    rc siz ttjWn tjyYdSwsdStj}dzdd}t||\}}Wnt j t j fyBYdSw|d|drlt drnt\}fddfddSdSdS) z=Return the function to run the shell alias, if it is requiredNrrtrMr0csgddRSNrr,r,)r"rrr,r-rz"_checkshellalias..c s tdddgi Sr)ror,)r"rrmrkrPrr,r-rs)rr rrrrrrrr rrrr?r)rkrr"rstrictrr _earlyoptsr,)r"rrmrrkrPrr-_checkshellaliass.  rc s|j|j|jd}|rt||jd}t|\}}|h}|jr,||jj|jds;|jds;|jdrYdD]}t t |j|}|D] }| d||d|qKq=|jd rl|D] }| d d d d q`n|jd dur| d d r| d d dd| d d } t j|| d} t||j_t|tjt|} | r|D]}t|q| WdS|dd} | r| t_} t|\}}}||_|d|jdkrttd|d|jdkrttd|d|jdkrttd|d|jdkrttd|dr!|dt_|dr+|dt_|drDddfdd} ||d rM| !|ds\|ds\|drdD](}|||j|krlq^t t ||}|D] }| d||d|qwq^|d r|D] }| dd d!d"q|d#r|D] }| dd$d%d&q|"d'dr|D]}d(|_#q|d)}|D]}|r| dd)|d*t$%|qt&'|d+r(d,|n|d+d-kr|D]}|)q|D]}t|q|d.rt*WdS|d/r*tj+||dud0WdS|s:t+d1WdSd}dd}dusIJj,s|sV|sV|j}|rnj-|j_-j.|j_.j/|j_/j0|j_0nz%t1j2||j3j4d2}|5sttd3||j d4d5|j6d6Wnftj7ytj8y|rj9sj:rr|st;t|t?|krd8|g| |_||jd<t@|YWdS|sttd9tAYnw|r |j|d:r |B}Cd7|n |rDtd;tE| }Fdd?}z!tH|||| |||| W|rM||jkrM|IWdS|rc||jkrd|Iwww1siwYdS)@Nscwdr_verbosedebugquiet)rrrrtrsprofiles profilingsenabledstrues --profileFsfalses --no-profile)enabledsfallbackencodingrs&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}|ddkr|d|d|d|dtf}|S)Nrgrrrr)rttimesrrtr,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)rrr)rsrr,r- print_timexsz_dispatch..print_timersrurvsnoninteractives interactivesoffs-ysinsecureTscolors--colorspagersinternal-always-sautosversionr)rs shortlist)ru presetupfuncsr-srepository '%s' is not localsbundles mainreporootr`rs --repositorys+no repository found in '%s' (.hg not found)shiddenswarning: --repository ignored scommands%s cstgRiSr!)rr7r,)r"r8 strcmdoptrr,r-rrz_dispatch..)Jr"rr(rtchdirrr#addrrboolrrrprofilerloadall __class__rLr rr populateuirr fallbackencodingrUr*r rr encodingmodeatexitstartrinsecureconnectionsr setupr parseboolr disablepagerversion_rr,r$r%r&r'r repositoryr)r-localrRequirementError RepoErrorr.r/r*rrcountrrr unfilteredinsertrrorMrror`)rScwdrrurkuisoptrui_rprofiler shellaliasfnfallbackrlrrPrQrcoloroptr#rnreposguessrrmr,)r"r8rrrrr-r st                       |~            -  G rcCs^ztd| |WdWS1swYWdStjy.t|tdw)z8Run a command function, possibly with profiling enabled.zRunning %s commandNsinvalid arguments)rrMr r8rr)rrPrcmdfuncr,r,r-ris(ric stjdddddf}|dddurttD][\}}tt|dd}t|}t|dtd }| s>|d ||f}n6t |rDqd d | D}|vrRqfd d |D}t |p_|} |ddusm| |dkrs|| ||f}q|ddur|\}}}}t |ttfsddd |D}|ptd} td|| ||t|f} n|dd} | durtd} td| d} ttjdd} dd| td| tdttddfdd ttD7} | S)z:Produce a warning message for the current active exceptionr)r@Nrrtssupportcontact testedwithbuglinksthe extension author.sunknowncSsg|]}t|dqS)r)r versiontuplerirr,r,r-r(rz%_exceptionwarning..csg|]}|kr|qSr,r,r)ctr,r-r,rrrrZcSsg|]}t|qSr,)rr)rirSr,r,r-r4ss (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)Nrrre)r moduleversion)rr9verr,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,)rir)rr,r-rYrX)rrrrrrrrrrVismoduleinternalr[maxrbytesstrrmrsysbytesr2versionrsorted)rworstrmodrrreporttestedlowernearestextverwarning bugtracker sysversionr,)rrr-_exceptionwarning sv              rc 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)rrMrrr5 format_excr)rrr,r,r-r`s  rr!)J __future__rrrBrrZrtrrrr2r5i18nrrrhgdemandimportrrr r r r r rrrrrrrrrrrxrrr{rrutilsrrrobjectr rJrTispy3rLrProrOrprrrrrr<rLrUrr~rrorrrrrirrr,r,r,r-s`   \3 ;T<8$-  ' #!u V