o ]Lb@@sddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZddlmZddlmZmZddlmZmZmZmZmZmZmZmZmZmZmZm Z ddl!m"Z"m#Z#m$Z$m%Z%m&Z&e j'Z'd (d d e)ej*e+d DZ,d Z-dddddZ.ddZ/ddZ0Gddde1Z2ddZ3e1Z4gZ5Gddde1Z6da7ddZ8dd Z9d!d"Z:d#d$Z;dS)%)absolute_importN)_)hex)getattropen) colorconfig configitemsencodingerror formatter loggingutilprogresspycompatrcutilscmutilutil)dateutilprocutil resourceutil stringutilurlutilccs|] }|s|VqdSN)isalnum.0cr./usr/lib/python3/dist-packages/mercurial/ui.py 7s  r!s [ui] # The rollback command is dangerous. As a rule, don't use it. rollback = False # Make `hg status` report copy information statuscopies = yes # Prefer curses UIs when available. Revert to plain-text with `text`. interface = curses # Make compatible commands emit cwd-relative paths by default. relative-paths = yes [commands] # Grep working directory by default. grep.all-files = True # Refuse to perform an `hg update` that would cause a file content merge update.check = noconflict # Show conflicts information in `hg status` status.verbose = True # Make `hg resolve` with no action (like `-m`) fail instead of re-merging. resolve.explicit-re-merge = True [diff] git = 1 showfunc = 1 word-diff = 1 s# example user config (see 'hg help config' for more info) [ui] # name and email, e.g. # username = Jane Doe username = # We recommend enabling tweakdefaults to get slight improvements to # the UI over time. Make sure to set HGPLAIN in the environment when # writing scripts! # tweakdefaults = True # uncomment to disable color in command output # (see 'hg help color' for details) # color = never # uncomment to disable command output pagination # (see 'hg help pager' for details) # paginate = never [extensions] # uncomment the lines below to enable some popular extensions # (see 'hg help extensions' for more info) # # histedit = # rebase = # uncommit = s# example repository config (see 'hg help config' for more info) [paths] default = %s # path aliases to other clones of this repo in URLs or filesystem paths # (see 'hg help config.paths' for more info) # # default:pushurl = ssh://jdoe@example.net/hg/jdoes-fork # my-fork = ssh://jdoe@example.net/hg/jdoes-fork # my-clone = /home/jdoe/jdoes-clone [ui] # name and email (local to this repository, optional), e.g. # username = Jane Doe s# example repository config (see 'hg help config' for more info) [paths] # path aliases to other clones of this repo in URLs or filesystem paths # (see 'hg help config.paths' for more info) # # default = http://example.com/hg/example-repo # default:pushurl = ssh://jdoe@example.net/hg/jdoes-fork # my-fork = ssh://jdoe@example.net/hg/jdoes-fork # my-clone = /home/jdoe/jdoes-clone [ui] # name and email (local to this repository, optional), e.g. # username = Jane Doe s# example system-wide hg config (see 'hg help config' for more info) [ui] # uncomment to disable color in command output # (see 'hg help color' for details) # color = never # uncomment to disable command output pagination # (see 'hg help pager' for details) # paginate = never [extensions] # uncomment the lines below to enable some popular extensions # (see 'hg help extensions' for more info) # # blackbox = # churn = )susersclonedslocalsglobalcCttj|Sr)rrapplystrurl) maybebytesrrr _maybestrurlr'cCr#r)rr$bytesurl)maybestrrrr _maybebytesurlr(r+c@s0eZdZdZddZddZddZdd Zd S) httppasswordmgrdbproxyz)Delays loading urllib2 until it's needed.cCs d|_dSr)_mgrselfrrr __init__ zhttppasswordmgrdbproxy.__init__cCs|jdur t|_|jSr)r-urlreqhttppasswordmgrwithdefaultrealmr.rrr _get_mgrs  zhttppasswordmgrdbproxy._get_mgrcCs$|t|t|t|t|Sr)r4 add_passwordr')r/realmurisuserpasswdrrr r5s z#httppasswordmgrdbproxy.add_passwordcCs |}t|t|t|Sr)r4r+find_user_passwordr')r/r6urimgrrrr r:sz)httppasswordmgrdbproxy.find_user_passwordN)__name__ __module__ __qualname____doc__r0r4r5r:rrrr r,s  r,cGstjr)r SignalInterrupt)argsrrr _catchtermsrCc@sdeZdZdddZddZeddZdd Zd d Zd d Z e j ddZ e j ddZ ddZddZ dddZ dddZ dddZdddZd d!Zdd"d#Zd$d%Zd&d'Zdd(d)Zd*d+Zdd,d-Zedfd.d/Zedfd0d1Zd2d3Zedfd4d5Zedfd6d7Z edfd8d9Z!eddfd:d;Z"edfdd?Z$edfd@dAZ%edfdBdCZ&dDdEZ'ddFdGZ(ddHdIZ)ddJdKZ*ddLdMZ+dNdOZ,dPdQZ-ddRdSZ.ddTdUZ/dVdWZ0ddXdYZ1e2j3dZd[Z4d\d]Z5e6d^d_Z7e7j8d`d_Z7e6dadbZ9e9j8dcdbZ9e6dddeZ:e:j8dfdeZ:e6dgdhZ;e;j8didhZ;e j ddjdkZdpdqZ?drdsZ@dtduZAdvdwZBdxdyZCdzd{ZDd|d}ZEd~dZFddZGddZHddZIddZJddZKe j ddZLddZMddZNdddZOe6ddZPddZQddZRddZSddZTddZUdddZVdddZWddZXeYddZZdddZ[dddZ\ddZ]ddZ^ddZ_ddZ`ddZae]Zbe`Zce^ZdeBZe     dddZf     dddZgddZhdddZiddZje2j3dd„ZkddĄZldddƄZmddȄZnddʄZodd̄Zpdd΄ZqdddфZrdddԄZsddքZte j ddd؄ZuddڄZvdS)uiNcCsNg|_g|_d|_d|_|_|_|_d|_tj |_ t |_ t |_ t |_t|_t|_d|_i|_d|_d|_d|_i|_i|_d|_d|_|r|j|_|j|_|j|_|j|_|j|_|j |_ |j!|_!|j"#|_"|j$|_$|j%|_%|j&|_&|j #|_ |j#|_|j #|_ |j#|_|j#|_|j'|_'|j|_|j|_|j|_|j|_|j#|_|j#|_|(|j)|_)|j*|_*n4t+j,|_t+j-|_t+j.|_d|_|j/|_|j0|_ d|_!i|_"d|_$d|_%d|_&t1j'|_'t2|_)t34t5|_*|6dd}d|vr|j'|_7dSi|_7|D]}||j'vr#|j'||j7|<qdS)zCreate a fresh new ui object if no src given Use uimod.ui.load() to create a ui which knows global and user configs. In most cases, you should use ui.copy() to create a copy of an existing ui object. NFT experimentalsexportableenviron*)8_buffers _bufferstates_bufferapplylabelsquietverbose debugflag tracebackflag_reportuntrustedr coreitems _knownconfigr _ocfg_tcfg_ucfgset _trustusers _trustgroups callhooks _path_to_rootinsecureconnectionslogblockedtimes _colormode_terminfoparams_styles_uninterruptible showtimestamp_fout_ferr_fin_fmsg_fmsgout_fmsgerr_finoutredirected_loggerscopy pageractive _disablepager_tweakedenviron fixconfighttppasswordmgrdb _blockedtimesrstdoutstderrstdinfoutferrr r, collections defaultdictint configlist_exportableenviron)r/srcallowedkrrr r0s                 z ui.__init__cCs"|j|j|jdSr)rQ new_sourcerRrSr.rrr _new_source3s  zui._new_sourcec Cs|}tD]Y\}}|dkr|j|ddq|dkr#|j|ddq|dkrZ|t}|D]\}}}}|j|||||j||||||q0|D]}|j |dqPqt d|| ||S)z,Create a ui and load global and user configsspathT)trustsresourcesitemssectionsunknown rctype: %s) r rccomponents readconfigread_resource_configr~rTrRrSaddrmr ProgrammingError_maybetweakdefaults) clsutfsectionsrnamevaluesourcerrr load8s( zui.loadcCs||ddsdS|js|drdSd|_t}|dt|D]}||D]\}}|||s:||||dq(q!dS)Nuis tweakdefaultsTs) configboolrkplainr parsetweakrcitems hasconfig setconfig)r/tmpcfgrrrrrr rSs   zui._maybetweakdefaultscCs ||Sr) __class__r.rrr rhgr1zui.copycCs|jr|jt|_dS)z;Clear internal state that shouldn't persist across commandsN)_progbar resetstater,rnr.rrr rjs  z ui.resetstatec cs^t}zdVW|j|dt|d7<dS|j|dt|d7<w)Ns_blocked)rtimerro)r/key starttimerrr timeblockedsectionps   zui.timeblockedsectionc #sdd}|rddr}js|sdVdSfdd}t|z d_dVWd_nd_wWddS1sDwYdS) a/Mark an operation as unsafe. Most operations on a repository are safe to interrupt, but a few are risky (for example repair.strip). This context manager lets you advise Mercurial that something risky is happening so that control-C etc can be blocked if desired. rEs nointerruptsnointerrupt-interactiveonlyNcs tdtddS)Nsshutting down cleanly s4press ^C again to terminate immediately (dangerous) T)warnrrr.rr rs z ui.uninterruptible..warnTF)r interactiver^runinterruptible)r/enabledrrr.r r{s     "zui.uninterruptiblecCst||||Sr)r )r/topicoptsrrr r z ui.formattercCst|}t|r dS|j|j}}d|vsd|vrdSt|j}t|j}||vs7||vs7|tkr9dS|j rH| t d|||fdS)NTrFs6not trusting file %s from untrusted user %s, group %s F) rfstatisownerrUrVusernamest_uid groupnamest_gidrNrr)r/fprsttuserstgroupsr8grouprrr _trusteds&    z ui._trustedFcCsPz t|d|d}Wn ty|sYdSw|d||||||dS)Nrrsresource:%s.%s)r open_resourceIOError _readconfig)r/rrootrrremaprrrr rs zui.read_resource_configcCsBzt|d}Wn ty|sYdSw|||||||dS)Nrb)rrr)r/filenamerrrrrrrr rs z ui.readconfigc Cs|Et}|p|p|||}z |j||||dWn#tjy?} z|r(|td| j| jfWYd} ~ nd} ~ wwWdn1sJwY| |||dS)N)rrsignored %s: %s ) r rreadr ConfigErrorrrlocationmessage _applyconfig) r/rrrrrrcfgtrustedinstrrr rs  zui._readconfigrcCs@t}|D]\\}}}|||||q||d|dS)aAdd configitems from a non-file source. Unlike with ``setconfig()``, they can be overridden by subsequent config file reads. The items are in the same format as ``configoverride()``, namely a dict of the following structures: {(section, name) : value} Typically this is used by extensions that inject themselves into the config file load procedure by monkeypatching ``localrepo.loadhgrc()``. TN)r rrTr)r/r rrrrrrrrr applyconfigs zui.applyconfigcCsV|rAdD] }||dvr|d|=q|dD] \}}|d|=q|dD] \}}|d|=q(|dD] \}}|d|=q7|drU|dD] \}}|d|=qK|dri|dD] \}}|d|=q_|dr}|dD] \}}|d|=qs|r|j||j|j|j||j|j|durtjd }|j |d dS) N) debugsfallbackencodingquietsslashs logtemplatemessage-outputs statuscopiessstyle tracebackverbosersdefaultsscommandsscommand-templatessaliass revsetaliass templatealias~)r) rrrRupdaterQrSospath expanduserrm)r/rrrr|vrrr rs8             zui._applyconfigc Cs|dvrg|p t}|j|j|jfD]T}|dD]L\}}|}|d|p&d}|||f}||jvr6||j|<d|vr;q|s>qd|vrZ|durHd}|t d|||f| dd}||kre| d||qq|d vrt |\|_ |_|d d |_|jp|d d |_|j o|d d |_|jr|jrd|_|_|jp|d d|_|d d|_|d d|_|d d|_|dvr|j|dd|j|dd|dvr|jrt} |ddr| d| rt|j| } | d | dSdSdSdS)N)Npathsrsnone:s%%nones((deprecated '%%' in path %s=%s from %s) %)NrrrrrFsreport_untrustedstimestamp-outputrslogblockedtimes)Ntrustedrsuserssgroups)Ndevelrrsdebug.extensionss extension)!r getcwdrRrSrQr configsourcerXrrreplacealter_selectmsgdestsrdrerrLrKrJrNr_rMrZrUrrxrVrTrrfileobjectloggerra setlogger) r/rrrnpold_psroot_keytrackedloggerrrr rm sf          z ui.fixconfigcCs(|j|||j|||j||fSr)rQbackuprRrS)r/ritemrrr backupconfigXs   zui.backupconfigcCs4|j|d|j|d|j|ddS)Nrr)rQrestorerRrS)r/datarrr restoreconfig_szui.restoreconfigcCs>|j|j|jfD] }|||||q|j|d|dS)Nr)rQrRrSrTrmr)r/rrrrrrrr rds  z ui.setconfigcCs|r|jp|jSr)rSrR)r/ untrustedrrr _datajrzui._datacC||||Sr)rrr/rrrrrr rmzui.configsourcecCs"|j||||d}|turdS|S)z+return the plain string version of a config)defaultrN)_config_unsetr/rrrrrrrr r ps z ui.configcs|}}|j|i|}||fg}|dur+||jt|jr'|}n|j}nd} | ||f;} || dd|tur`|durE|}n<|jtj ur]d}d} | ||f;} || ddn$|}n!|dur|jtj ur||krd} | ||t |f;} || ddg} | ||D]\} } | | d} | dur| | | | fq| rfdd}t| |d d}|jr|s|jr|D]\} } |j| | }|dur||kr|d | | |fq|S) Ns+accessing unregistered config item: '%s.%s'rswarn-config-unknowns7config item requires an explicit default value: '%s.%s'swarn-config-defaultsPspecifying a mismatched default value for a registered config item: '%s.%s' '%s'cs|d|dS)Nrr)level)xr rr rszui._config..level)r3ignoring untrusted configuration option %s.%s = %s )rPgetextendaliascallabler develwarnrr dynamicdefaultrbytestrrappendmaxrLrNrSdebug)r/rrrrr itemdefaultr alternatesmsg candidatesrr candidateruvaluerrr rys`            z ui._configcCs.|j|i|}|durt||f|jS)zreturn the default value for a config option The default is returned "raw", for example if it is a callable, the callable was not called. N)rPrKeyErrorr)r/rrrrrr config_defaults zui.config_defaultc Cs|j||||d}||}i}d|}||D]\} } | |r,| || t|d<q|jr\|s\|jr\|D]"\} } |j|d|| f} | dur[| | kr[| d||| | fq9||fS)aGet a config option and all sub-options. Some config options have sub-options that are declared with the format "key:opt = value". This method is used to return the main option and all its declared sub-options. Returns a 2-tuple of ``(option, sub-options)``, where `sub-options`` is a dict of defined sub-options where keys and values are strings. rs%s:Ns%s:%ss6ignoring untrusted configuration option %s:%s.%s = %s ) r rr startswithlenrLrNrSrr) r/rrrrmainrsubprefixr|rrrrr configsuboptionss&   zui.configsuboptionscCsv|||||}|durdStj|rd|vr9||||}d|vr9tj|dd}tj|tj|}|S)zMget a path config item, expanded relative to repo root or config fileNs://rr) r rrisabsrdirnamersplitjoinr)r/rrrrrrzbaserrr configpathsz ui.configpathcCsr|j||||d}|dur|S|tur|turdS|St|tr"|St|}|dur7ttd|||f|S)a\parse a configuration element as a boolean >>> u = ui(); s = b'foo' >>> u.setconfig(s, b'true', b'yes') >>> u.configbool(s, b'true') True >>> u.setconfig(s, b'false', b'no') >>> u.configbool(s, b'false') False >>> u.configbool(s, b'unknown') False >>> u.configbool(s, b'unknown', True) True >>> u.setconfig(s, b'invalid', b'somevalue') >>> u.configbool(s, b'invalid') Traceback (most recent call last): ... ConfigError: foo.invalid is not a boolean ('somevalue') r NFs%s.%s is not a boolean ('%s')) rr isinstanceboolr parseboolr rr)r/rrrrrbrrr rs  z ui.configboolc Csj|||||}|dur|Sz||WSttjfy4|dur't|j}ttd||||fw)aparse a configuration element with a conversion function >>> u = ui(); s = b'foo' >>> u.setconfig(s, b'float1', b'42') >>> u.configwith(float, s, b'float1') 42.0 >>> u.setconfig(s, b'float2', b'-4.25') >>> u.configwith(float, s, b'float2') -4.25 >>> u.configwith(float, s, b'unknown', 7) 7.0 >>> u.setconfig(s, b'invalid', b'somevalue') >>> u.configwith(float, s, b'invalid') Traceback (most recent call last): ... ConfigError: foo.invalid is not a valid float ('somevalue') >>> u.configwith(float, s, b'invalid', desc=b'womble') Traceback (most recent call last): ... ConfigError: foo.invalid is not a valid womble ('somevalue') Ns%s.%s is not a valid %s ('%s')) r ValueErrorr ParseErrorrsysbytesr=rr)r/convertrrrdescrrrrr configwiths  z ui.configwithcCs|t|||d|S)aparse a configuration element as an integer >>> u = ui(); s = b'foo' >>> u.setconfig(s, b'int1', b'42') >>> u.configint(s, b'int1') 42 >>> u.setconfig(s, b'int2', b'-42') >>> u.configint(s, b'int2') -42 >>> u.configint(s, b'unknown', 7) 7 >>> u.setconfig(s, b'invalid', b'somevalue') >>> u.configint(s, b'invalid') Traceback (most recent call last): ... ConfigError: foo.invalid is not a valid integer ('somevalue') sinteger)r rwr/rrrrrrr configint6s z ui.configintc Csl|||||}|tur|turd}|}t|ts|Szt|WStjy5tt d|||fw)aparse a configuration element as a quantity in bytes Units can be specified as b (bytes), k or kb (kilobytes), m or mb (megabytes), g or gb (gigabytes). >>> u = ui(); s = b'foo' >>> u.setconfig(s, b'val1', b'42') >>> u.configbytes(s, b'val1') 42 >>> u.setconfig(s, b'val2', b'42.5 kb') >>> u.configbytes(s, b'val2') 43520 >>> u.configbytes(s, b'unknown', b'7 MB') 7340032 >>> u.setconfig(s, b'invalid', b'somevalue') >>> u.configbytes(s, b'invalid') Traceback (most recent call last): ... ConfigError: foo.invalid is not a byte quantity ('somevalue') rs#%s.%s is not a byte quantity ('%s')) rrrbytesr sizetointr rrrrrrr configbytesMs   zui.configbytescCs:|tj|||d|}t|trt|S|durgS|S)aparse a configuration element as a list of comma/space separated strings >>> u = ui(); s = b'foo' >>> u.setconfig(s, b'list1', b'this,is "a small" ,test') >>> u.configlist(s, b'list1') ['this', 'is', 'a small', 'test'] >>> u.setconfig(s, b'list2', b'this, is "a small" , test ') >>> u.configlist(s, b'list2') ['this', 'is', 'a small', 'test'] slistN)r r parselistrr#)r/rrrrrrrr rxrs   z ui.configlistcCs6|||||r|tj|||d|S|turdS|S)zparse a configuration element as a tuple of ints >>> u = ui(); s = b'foo' >>> u.setconfig(s, b'date', b'0 0') >>> u.configdate(s, b'date') (0, 0) sdateN)r r r parsedaterr!rrr configdatesz ui.configdatecCs@|j|i|}d}|durt|jr|}|S|j}|S)z,returns the default value of the config itemN)rPrrr)r/rrrrrrr configdefaults zui.configdefaultcCrr)rhasitemrrrr rrz ui.hasconfigcCs|||vS)z&tell whether section exists in config.)r)r/rrrrr has_sectionszui.has_sectioncCsr|||}|rdd|D}|jr7|s7|jr7|j|D]\}}|j|||kr6|d|||fq|S)NcSsg|] }d|dvr|qS)rrr)rirrr sz"ui.configitems..r)rrrLrNrSrRrr)r/rr ignoresubrr|rrrr r szui.configitemsccs ||}|s|D]}|Vq dS|}t|d}t|d}|dus(|dur|dur5|Vt|d}nD|durB|Vt|d}n7|dd|ddkr\|Vt|d}t|d}n|dd|ddkrq|Vt|d}n|Vt|d}|dus(|dus(dSdS)Nrr) _walk_config _walk_knownnext)r/r all_knowndefineddknowncurrent_defined current_knownrrr walkconfigs4         z ui.walkconfigccsvt|jD]0\}}t|D]%\}}|jrqt|jr$|}n |jtjur-d}n|j}||j|fVqqdS)Ns ) sortedrPrgenericrrr rr)r/rrr|r,rrrr r0s   zui._walk_knownccs@||}|D]}|||D] \}}|||fVqq dSr)rrr )r/rrrrrrrr r/s  zui._walk_configcCsfdtjvr dtjvr dStjddd}dtjdddvr)|d|r1|r1||vSdS) auis plain mode active? Plain mode means that all configuration variables which affect the behavior and output of Mercurial should be ignored. Additionally, the output should be stable, reproducible and suitable for use in scripts or applications. The only way to trigger plain mode is by setting either the `HGPLAIN' or `HGPLAINEXCEPT' environment variables. The return value can either be - False if HGPLAIN is not set, or feature is in HGPLAINEXCEPT - False if feature is disabled by default and not included in HGPLAIN - True otherwise sHGPLAINs HGPLAINEXCEPTFr,s +strictflagss strictflagsT)r rlrstripsplitr)r/feature exceptionsrrr rs   zui.plaincCstjd}|dur|dd}|durtj|}|dur$tjd}|dur,|r,|S|dur?|ddr?|jt ddd}|duri| sizd t t tf}|t d |Wn tyhYnw|svtjt d t d d d|vrtt dt||S)aReturn default username to be used in commits. Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL and stop searching if one of these is set. If not found and acceptempty is True, returns None. If not found and ui.askusername is True, ask the user, else use ($LOGNAME or $USER or $LNAME or $USERNAME) + "@full.hostname". If no username could be found, raise an Abort error. HGUSERNrsusernamesEMAILs askusernamesenter a commit username:rs%s@%ss&no username found, using '%s' instead sno username supplieds+use 'hg config --edit' to set your username)hint susername %r contains a newline )r rlrr rr expandvarsrpromptrrrgetuser strtolocalsocketgetfqdnrrr Abortrr)r/ acceptemptyr8rrr rs>       z ui.usernamecCs|jst|}|S)z>Return a short representation of a user name or email address.)rKr shortuser)r/r8rrr rL0s z ui.shortusercCs|d}||dz ||}|r|jWSWn tjyYnw|rj}jr-|ddr#jr#jdfdd|DdSjd|dS|dds7d|}t}zNz*j d krTt j |j |fi|nj dure|dd |}| |Wnty|}zt|d}~wwWjd t|d 7<dSjd t|d 7<w) a:write args to output By default, this method simply writes to the buffer or stdout. Color mode can be set on the UI class to have the output decorated with color modifier before being written to stdout. The color used is controlled by an optional keyword argument, "label". This should be a string containing label names separated by space. Label names take the form of "topic.type". For example, ui.debug() issues a label of "ui.debug". Progress reports via stderr are normally cleared before writing as stdout and stderr go to the same terminal. This can be skipped with the optional keyword argument "keepprogressbar". The progress bar will continue to occupy a partial line on stderr in that case. This functionality is intended when Mercurial acts as data source in a pipe. When labeling output for a specific command, a label of "cmdname.type" is recommended. For example, status issues a label of "status.modified" for modified files. labelrrfc3|] }|VqdSrrmrarmr/rr r!zui.write..NkeepprogressbarFrk stdio_blockedr)r`rGrrIr _progclearrrrr[r win32printwritermrr StdioErrorro)r/rBrrhrrerrrrrr rxs@               zui.writecOs|j|jg|Ri|dSr)_writera)r/rBrrrr write_errz ui.write_errcst|r,|ddr"jr"jdfdd|DdSjd|dSj|g|Ri|dS)Nrmrrfc3rnrrorprrrr r!rszui._write..)rirrIrGr _writenobufr/rhrBrrrrr r{s   $z ui._writec Os|dds |d|}t}zzZ||jur&t|jdds&|jt|ddr6|j |fi|n(|j dkrHt j ||j |fi|n|j durY|dd}| ||}| |||jurmt|ddsm|Wn8ty}z,||jur|jtjtjtjfvrWYd}~W|jdt|d 7<dSt|d}~wwW|jdt|d 7<dS|jdt|d 7<w) NrtFrclosed structuredrkrmrur)rrvrrrrarr`flushrxr[rrwrmrerrnoEPIPEEIOEBADFror ry)r/rhrBrrrrmrzrrr r~sP                zui._writenobufcOsd|jo |ddv}|rdttjf|}t|j|g|Ri||r0| dSdS)Ntype>notererrorstatuswarnings[%s] ) r_rrrdatetimenow isoformat _writemsgwithr{r)r/rhrBr timestamprrr _writemsg&s z ui._writemsgcOst|j|g|Ri|dSr)rr~rrrr _writemsgnobuf7r}zui._writemsgnobufcCsrt}zzUz|jWn"ty/}z|jtjtjtjfvr%t |WYd}~nd}~wwWz|j WnLtyZ}z|jtjtjtjfvrPt |WYd}~nAd}~wwz|j Wwty}z|jtjtjtjfvrzt |WYd}~wd}~wwW|j dt|d7<dSW|j dt|d7<dS|j dt|d7<w)Nrur) rrr`rrrrrrr ryraro)r/rrzrrr r:sP             zui.flushcCs|ddrdSt|S)NrnonttyF)rrisatty)r/fhrrr _isattyNs  z ui._isattycCsD|jr |j|jfSt|j|j\}}||f|j|jfk|_||fS)aDuplicate ui streams and redirect original if they are stdio Returns (fin, fout) which point to the original ui fds, but may be copy of them. The returned streams can be considered "owned" in that print(), exec(), etc. never reach to them. )rfrbr`r protectstdior/r]rsrrr protectfinoutSs  zui.protectfinoutcCs6||f|j|jfkr dSt|j|j||d|_dS)z7Restore ui streams from possibly duplicated (fin, fout)NF)rbr`r restorestdiorfrrrr restorefinoutbs zui.restorefinoutc cs:|\}}z||fVW|||dS|||w)z.Run code block with protected standard streamsN)rrrrrr protectedfinoutks   zui.protectedfinoutcCs d|_dS)NT)rjr.rrr disablepagertr1zui.disablepagercCsf|js|jrdS|ds>||ddvs<|ddr<|dd|drdS| ddtj}|sJdSi}tD] \}}|tjvr_|||<qR|d t|||}ttd rttjt|||rd|_|dd|d|dddd|j}|| dd|krt|dSdS| dS)a Start a pager for subsequent command output. Commands which produce a long stream of output should call this function to activate the user's preferred pagination mechanism (which may be no pager). Calling this function precludes any future use of interactive functionality, such as prompting the user or activating curses. Args: command: The full, non-aliased name of the command. That is, "log" not "history, "summary" not "summ", etc. Nsinternal-always-spagersignorerspaginatesattend-TTERMdumbs --debuggersstarting pager for command %s sSIGPIPE formatted interactiveFscolors pagermode)!rjrir rxrr rlr formattedrrGrsysargvr r fallbackpagerdefaultpagerenvrrrpprintrr safehasattrsignalSIGPIPErC _runpagerrr[rsetupr)r/commandpagercmdpagerenvrr wasformattedcmrrr pagerwsR         zui.pagerc sNdkrdStfdddD}tjr*|s*t}|s(|tddS|ztjt |dtj tj tj tj tt|dWn%tyk}z|jtjkrf|sf|tdWYd }~dSd }~wwttj ttj tjtj |tj rtjtj |jfd d }d S) zActually start the pager and set up file descriptors. This is separate in part so that extensions (like chg) can override how a pager is invoked. scatFc3s|]}|vVqdSrrr)rrr r!zui._runpager..s|&;<>()$`\"' *?[#~=%s+missing pager command '%s', skipping pager rf)shellbufsize close_fdsrrrprqenvNcsVttdrttjtjttj ttj j  dS)NsSIGINT)rrrSIGINTSIG_IGNrdup2rrpfilenorqrrclosewaitr)rstderrfdstdoutfdrr killpagers   zui._runpager..killpagerT)anyr iswindowsrfindexerr subprocessPopen tonativestrclosefdsPIPErprq tonativeenv shellenvironOSErrorrENOENTrduprrrrratexit)r/rrrfullcmderr)rrrrr rsN         z ui._runpagercCstSr)_reqexithandlersr.rrr _exithandlersszui._exithandlerscOs|j|||f|S)zzregister a function to run after dispatching a request Handlers do not stay registered across request boundaries.)rr)r/funcrBrVrrr r sz ui.atexitc Cstddg}ddgddgd}||vrtd|t||}||kr+td||s7tjddkr9dSd}|dd }||vrG|}|}|dd |}||vrW|}|d ury||kry|d urn|t d |fn |t d ||f|d ur||kr|t d|||f|S)aAwhat interface to use for interactive console features? The interface is controlled by the value of `ui.interface` but also by the value of feature-specific configuration. For example: ui.interface.histedit = text ui.interface.chunkselector = curses Here the features are "histedit" and "chunkselector". The configuration above means that the default interfaces for commands is curses, the interface for histedit is text and the interface for selecting chunk is crecord (the best curses interface available). Consider the following example: ui.interface = curses ui.interface.histedit = text Then histedit will use the text interface and chunkselector will use the default curses interface (crecord at the moment). stextscurses)s chunkselectorshisteditsUnknown feature requested %ss1Feature %s does not handle all default interfacesrrrs interfaces interface.%sNs#invalid value for ui.interface: %s s.invalid value for ui.interface: %s (using %s) s1invalid value for ui.interface.%s: %s (using %s) ) frozensetkeysrrr rlrr rr) r/r> alldefaultsfeatureinterfacesavailableinterfacesdefaultinterfacer,choseninterfacerrrr interfacesP    z ui.interfacecCs$|dd}|dur||jS|S)a-is interactive input allowed? An interactive session is a session where input can be reasonably read from `sys.stdin'. If this function returns false, any attempt to read from stdin should fail with an error, unless a sensible default has been specified. Interactiveness is triggered by the value of the `ui.interactive' configuration variable or - if it is unset - when `sys.stdin' points to a terminal device. This function refers to input only; for output, see `ui.formatted()'. rrN)rrrbr/r,rrr r^s  zui.interactivecCs<dtjvrzttjdWStyYnwt|dS)z$how wide is the terminal in columns?sCOLUMNSr)r rlrwrrtermsizer.rrr termwidthts  z ui.termwidthcCs0|rdS|dd}|dur||jS|S)a*should formatted output be used? It is often desirable to format the output to suite the output medium. Examples of this are truncating long lines or colorizing messages. However, this is not often not desirable when piping output into other utilities, e.g. `grep'. Formatted output is triggered by the value of the `ui.formatted' configuration variable or - if it is unset - when `sys.stdout' points to a terminal device. Please note that `ui.formatted' should be considered an implementation detail; it is not intended for use outside Mercurial or its extensions. This function refers to output only; for input, see `ui.interactive()'. This function always returns false when in plain mode, see `ui.plain()'. FrrN)rrrr`rrrr r}s   z ui.formatted cCsn||jo||jot|jot|j}|r/z ddl}|jWn ty.d}Ynw|j dks6|sN|s:i}|j |j |fddi|| d}n| |dd}|dR|r| t|}tt|}tjd kr|d r|dd }n%|jt||j |j}|st|tj}Wd|SWd|S1swY|S) NrFrkrpromptrs ui.promptstdios  rf)rrbr`risstdinisstdoutreadlineread_history_file Exceptionr[rrdrrmrr strfromlocalrGrrawinput oslinesependswithrxrEOFErrorrstrip)r/rE promptopts usereadlinerlinerrr _readlines`             z ui._readlineycCs|j||dS)zhPrompt user with msg, read response. If ui is not interactive, the default is returned. rA)_prompt)r/rrrrr rEsz ui.promptcKs|d}|s$|j|j|dfddi||j|j|pdddd|Sz |j||d }|s0|}|d drB|j|j|p=dddd|WStyOtw) NrrrrrrCs promptecho)r)rErr)rrrdrrrr ResponseExpected)r/rrrrrrr rs&  z ui._promptcsNtd|}|d}dd|ddD}dd|fd d|DfS) a4Extract prompt message and list of choices from specified prompt. This returns tuple "(message, choices)", and "choices" is the list of tuple "(response character, text without &)". >>> ui.extractchoices(b"awake? $$ &Yes $$ &No") ('awake? ', [('y', 'Yes'), ('n', 'No')]) >>> ui.extractchoices(b"line\nbreak? $$ &Yes $$ &No") ('line\nbreak? ', [('y', 'Yes'), ('n', 'No')]) >>> ui.extractchoices(b"want lots of $$money$$?$$Ye&s$$N&o") ('want lots of $$money$$?', [('s', 'Yes'), ('o', 'No')]) s(?s)(.+?)\$\$([^$]*&[^ $].*)rcSsg|]}|dqS)r)r<)rrrrr r-sz%ui.extractchoices..rs$$cSs0|d}||d|d|dddfS)N&rrr)indexlowerr)rampidxrrr choicetuples &z&ui.extractchoices..choicetuplecsg|]}|qSrrrrrrr r-)rematchrr=)rEmrchoicesrrr extractchoicess  zui.extractchoicesrcCs`||\}}dd|D} |j||||d}||vr&||S||jtdq)aePrompt user with a message, read response, and ensure it matches one of the provided choices. The prompt is formatted as follows: "would you like fries with that (Yn)? $$ &Yes $$ &No" The index of the choice is returned. Responses are case insensitive. If ui is not interactive, the default is returned. cSsg|]\}}|qSrr)rrrrrr r-rz#ui.promptchoice..T)rrsunrecognized response )rrrrrrdr)r/rErrrrespsrrrr promptchoices  zui.promptchoicecCs|s|SzG|j|j|ptdddd|d)|ddr7|j}|s*t| dWdWSt WdWS1sFwYWdStyXt w) Ns password: rT)rpasswordrrrrC)rrrerrrrbrrrr get_passwordr r)r/rErlrrr getpasss*    ( z ui.getpasscOs,|js|j|jg|Rddi|dSdS)zqwrite status message to output (if ui.quiet is False) This adds an output label of "ui.status". rrN)rJrrdr/rrrrr status3"z ui.statuscO"|j|jg|Rddi|dS)zewrite warning message to output (stderr) This adds an output label of "ui.warning". rrNrrerrrr r;"zui.warncOr )zawrite error message to output (stderr) This adds an output label of "ui.error". rrNr rrrr r Br zui.errorcOs,|jr|j|jg|Rddi|dSdS)zfwrite note to output (if ui.verbose is True) This adds an output label of "ui.note". rrN)rKrrdrrrr noteIr zui.notecOs@|jr|j|jg|Rddi||ddd|dSdS)zrwrite debug message to output (if ui.debugflag is True) This adds an output label of "ui.debug". rrs%srN)rLrrdlogrrrrr rQszui.debugc Cs|dur |dddd}|dur#|ddur|d|||}|dkr,d} n |r3d |} n|d} d} |d d rA|} tjd |d d| | d\} } zt| d} | t |Wdn1skwYd|i}d|vr|dt |didD]}||vr|d||inq|r|d|i|r|d|i| }|j d|| f|tjtdddt| d} t | }Wdn1swYWt| |SWt| |St| w)NsAaction is None but will soon be a required parameter to ui.edit()editors.txt)prefixsuffixrs>extra.suffix is not None but will soon be ignored by ui.edit()sdiffs.diffs .%s.hg.txtrEs editortmpinhgshg-r-)rsuffixdirwbr@stransplant_sources HGREVISION)sintermediate-sourcessources rebase_sources HGEDITFORMs HG_PENDINGs%s "%s"s edit failed)rlonerr errprefix blockedtagr)rrrrrmkstemprfdopenrxr tonativeeolr geteditorsystemr CanceledErrorrr fromnativeeolrunlink)r/textr8extraeditformpendingrepopathactionextra_defaultsrrdirfdrrrlrmeditorrrrr edit`sx          zui.editc Cs|dur|dtdd}d|}|j}tdd|jDr!|}|||j||||d} Wdn1s:wY| r]|r]dt|dt | f} |rYd || f} || | S) zexecute shell command with appropriate output stream. command output will be redirected if fout is not stdout. if command fails and onerr is None, return status, else raise onerr object as exception. Nisunknown_system_css|]}|dVqdSrNrrrrr r!rzui.system..rlcwdouts%s %srs%s: %s) translate _keepalnumr`rrHr _runsystemr shellsplit explainexit) r/cmdrlr/rrr cmdsuffixr0rcerrmsgrrr rs$   z ui.systemcCstj||||dS)z[actually execute the given shell command (can be overridden by extensions like chg)r.)rr)r/r6rlr/r0rrr r3sz ui._runsystemc Cs|js|rh|dur t}t|ddd}|durPt|d}t|d}t|d|d}|dt d |ddt d |t d |nt |d|d|d}|t d ||jpl|S) zprint exception traceback if traceback printing enabled or forced. only to call in exception handler. returns true if traceback printed.Nrcauserrs#Traceback (most recent call last): rf) rMsysexc_infor traceback format_tbformat_exception_onlyr|r rGrformat_exception)r/excforcer:causetbexctbexconlyoutputrrr r>s"  z ui.tracebackcCs:tjdkrd}ntjrd}nd}tjdp|dd|S)zreturn editor to usesplan9EsvimsvisHGEDITORrr)r sysplatformisdarwinr rlrr )r/r+rrr rs z ui.geteditorcCs.|js|js|ddst|sdSt|S)z,setup the progbar singleton to the ui objectprogresssdisableN)rJrLrr shouldprint getprogbarr.rrr rs z ui._progbarcCs2tsdS|jdur|jjr|jdSdSdS)z:clear progress bar output if any. use it before any outputN) haveprogbarrprintedclearr.rrr rv s z ui._progclearcsJtjddrfdd}njdurjj}ndd}t||||S)z0Create a progress helper for the specified topicrFc sjjdd|||||ddS)NrK)rrposrunittotal)rerxrrQrrRrSr.rr updatebars z"ui.makeprogress..updatebarNcSsdSrrrTrrr rU+s)rrerrr)r/rrRrSrUrr.r makeprogresss  zui.makeprogresscCs |j|S)z=Returns a logger of the given name; or None if not registered)rgr)r/rrrr getlogger0s z ui.getloggercCs||j|<dS)zInstall logger which can be identified later by the given name More than one loggers can be registered. Use extension or module name to uniquely identify the logger instance. N)rg)r/rrrrr r4sz ui.setloggerc sz|jsdSfddt|jD}|sdS||}t|}|j}i|_z|D] }||||q(W||_dS||_w)a2hook for logging facility extensions event should be a readily-identifiable subsystem, which will allow filtering. msgfmt should be a newline-terminated format string to log, and *msgargs are %-formatted into it. **opts currently has no defined meanings. Ncsg|] }|r|qSr)r)rreventrr r-Is  zui.log..)rgr itervalues byteskwargsr) r/rYmsgfmtmsgargsr activeloggersrregisteredloggersrrrXr r<s     zui.logcCs|jdur t|||S|S)aVstyle msg based on supplied label If some color mode is enabled, this will add the necessary control characters to apply such color. In addition, 'debug' color mode adds markup showing which label affects a piece of text. ui.write(s, 'label') is equivalent to ui.write(ui.label(s, 'label')). N)r[r colorlabel)r/rrmrrr rmYs zui.labelrc Cs|dds|dus|d|sdSd|}|d7}|jr9t|||j|j|dd|dt|fdSt }t |d }||dd \}}}t |t |}}|d ||||f|dd ||||~~dS) zissue a developer warning message Use 'stacklevel' to report the offender some layers further up in the stack. r all-warningsNs devel-warn: rs develwarns %s at: %srrs%s at: %s:%d (%s) )rrMrdebugstacktracerar`rrgetstackframesinspect currentframegetouterframesrrr|) r/r stacklevelr curframecalframefnamelinenor^rrr rgs.   z ui.develwarnrcCs<|dds|ddsdS|d|7}|j||dddS)zissue a deprecation warning - msg: message explaining what is deprecated and how to upgrade, - version: last version where the API will be supported, rras deprec-warnNsF (compatibility will be dropped after Mercurial-%s, update your code.))rhr )rr)r/rversionrhrrr rNs  z ui.deprecwarncCrW)zWThe environment variables that are safe to export, e.g. through hgweb. )ryr.rrr exportableenvironr_zui.exportableenvironc csi}z=|D]\\}}}||||||f<|||||qdVW|D] \}}||q)d|vr?|jdddSdS|D] \}}||qEd|vrZ|jddww)zContext manager for temporary config overrides `overrides` must be a dict of the following structure: {(section, name) : value}N)rrrr)rrrrrm) r/ overridesrbackupsrrr__rrrr configoverrides"  zui.configoverridecCsL|dd}|dur"zt|WStjy!ttd|wtS)zProvide an estimate for the available system memory in Bytes. This can be overriden via ui.available-memory. It returns None, if no estimate can be computed. rsavailable-memoryNs+ui.available-memory value is invalid ('%s'))r rr$r rrr_estimatememory)r/rrrr estimatememorys   zui.estimatememoryr)NFNN)rN)NN)r)F)FF)FFF)rN)r)r)NNNNN)NFr-)r)wr=r>r?r0r~ classmethodrrrhr contextlibcontextmanagerrrr rrrrrrrmrrrrrrr rr rrrr r"r%rxr(r)rr+r r8r0r/rrrLrSr propertycacherTrOpropertyrssetterrtr]r^rerbrcrirjrlrxr|r{r~rrrrrrrrrrrrrrrrrrEr staticmethodrrrr rr rr statusnoi18n notenoi18n warnnoi18n writenoi18nr,rr3r>rrrvrVrWrrrmrrNrnrrrtrrrr rDs  _   "    +8   =  & %%     !)             : *  IE N  7     O #       rDcCstdur t|atSr)_progresssingletonrprogbar)rDrrr rMs rMcCstduSr)rrrrr rNsrNcCsh|dd}|dkr|jr|j|jfS|j|jfS|dkr#|j|jfS|dkr-|j|jfStd|)Nrrschannelrsstderrs)invalid ui.message-output destination: %s)r r^rtrsr rJ)rDrrrr rs     rcOsLd|vrt|dds|ddd|d|d<||g|Ri|dS)zWrite ui message with the given ui._write*() function The specified message type is translated to 'ui.' label if the dest isn't a structured channel, so that the message will be colorized. rrFrmrs ui.%sN)rrrg)rxrhrBrrrr rsr)< __future__rrurvrrrerrrrHrr<r>i18nrnoderrrrr;rr r r r r rrrrrutilsrrrrrr2rmapbytechrranger2r samplehgrcsr'r+objectr,rCrrrDrrMrNrrrrrr sp   8 N