o ]Lbkz@sddlmZddlZddlZddlZddlZddlZddlZddlm Z m Z ddl m Z m Z mZddlmZmZmZm Z mZddlmZiZiZiZgZhdZdVd d Zd d Zd dZddZdWddZddZ ddZ!dZ"ddZ#ddZ$dVddZ%ddZ&d d!Z'dVd"d#Z(d$d%Z)d&d'Z*d(d)Z+d*d+Z,d,d-Z-dWd.d/Z.d0d1Z/Gd2d3d3e0Z1d4d5Z2dVd6d7Z3d8d9Z4d:d;Z5dd?Z7d@dAZ8dBdCZ9dDdEZ:dFdGZ;dHdIZdPdQZ?dRdSZ@dTdUZAdS)Z)absolute_importN)_gettext)getattropensetattr)cmdutil configitemserrorpycompatutil) stringutil> colorhgciashelvehbisectinotifyinterhgprogress bookmarks parentrevspecc#sHr fdd}ndd}tD]}t|}|r!||r!||fVqdS)Ncs6dD]}d||}|dur|dsdSqdS)N)s%shgext.%s extensions!T)config startswith)nameformatconfui6/usr/lib/python3/dist-packages/mercurial/extensions.pyenabled9s zextensions..enabledcSsdS)NTr")rr"r"r#@szextensions..)_order _extensions)r!r$rmoduler"r r# extensions6s  r)cCsld}zt|}Wn%ty-ttD]\}}|d|s&|d|r*|}nqYnw|s4t||S)z'return module with given extension nameN./)r'KeyErrorr iteritemsendswith)rmodkvr"r"r#findGs  r2c Cs|dd}tt|}t|}t|}tj|r8tj |\}}t ||g\}}}t ||||Szt ||WStyR}z|jsM||_d}~ww)Nr*_)replacer normpath expandpathr fsdecodeospathisdirsplitimp find_module load_module load_sourceIOErrorfilename)r9 module_namedffdfpathdescexcr"r"r#loadpathVs$    rIcCs8tt|}|d}|ddD]}t||}q|S)z#import and return the moduler*rN) __import__r sysstrr;r)rr/ componentscompr"r"r#_importhms   rNc Cs|r t|d|}|Sz td|}W|Styc}zC|r(||d|d|ztd|}Wn tyP}z|rB||d||t|}WYd}~n d}~wwWYd}~|SWYd}~|Sd}~ww)Nrs hgext3rd.%s)rIrN ImportError)rr9 reportfuncr/errr"r"r# _importextvs.    rRcCs>|dd|t|||jr|ddr|dSdSdS)N extensions* - could not import %s (%s): trying %s sdevelsdebug.extensions)logr forcebytestr debugflag configbool traceback)r!rQfailednextr"r"r#_reportimporterrors r[cCst|tttfr|D]}t||q dSt|tr5|D]\}}t||td|t|f|qdSt|t drGt j d||fdddS)Ns%s.%ssunicode %r found in %ssuse b'' to make it byte stringhint) isinstancelistsettuple_rejectunicodedictitemsrrUtyper ProgrammingError)rxsxr0r1r"r"r#rcs    rc)snorepos optionalrepos inferrepocsRt|D]!\}}|dfddtD}|sqtjdd|d|ddS) z4Check if extension commands have required attributesrcsg|] }t|s|qSr")r safehasattr).0arDr"r# sz%_validatecmdtable..smissing attributes: %ss, s'use @command decorator to register '%s'r]N)r r- _cmdfuncattrsr rgjoin)r!cmdtablecemissingr"rmr#_validatecmdtables rucCsXdD] }t|t||iqdD]}t||d}|r t||jqt|t|didS)z=Sanity check for loadable tables provided by extension module)cmdtable colortable configtable)filesetpredicate internalmergerevsetpredicatetemplatefilter templatefunctemplatekeywordNrq)rcr_tableru)r!r/tor"r"r#_validatetabless  rc Cs|ds |dr|dd}n|}|tvrdS|tvr!t|S|dd|dt|<td|}t||tt|}Wdn1sFwY|dd|||dur`|||j 7<t |dd}|rtj d d }t t |d } d| vr| d pd | d pd f} d|vs| |krtd } || ||tfdS|dd|t|||t|<t||dd|td|}t|gD]} | ddqWdn1swY|dd||S)Nshgext.shgext/rSs - loading extension: %s zload extension %ss > %s extension loaded in %s minimumhgversion)nrrs^(third party extension %s requires version %s or newer of Mercurial (current: %s); disabling) s& - validating extension tables: %s s( - invoking registered callbacks: %s zcallbacks extension %sTloadeds > callbacks completed in %s )r_builtinr'rTr timedcmrRbindr[elapsedr versiontuplerrUrwarnversionrr&append_aftercallbacksget) r!rr9 loadingtime shortnamestatsr/minvercurverextminmsgfnr"r"r#loadsR     rc Cztt|dd}|r;z||WdSty:}z|jddt|}|td||fWYd}~dSd}~wwdS)NuisetupTforce&*** failed to set up extension %s: %s Frr' ExceptionrXrrUrr)rr!rinstrr"r"r# _runuisetup   rc Cr)NextsetupTrrFr)rr!rrrr"r"r# _runextsetup rrc stt}|d}durfdd|D}dd|D}tt}|dd|r*dnd|dd t|td }| dd d }|D]\}}|rh|d d dkrh|t vr_|dd||d dt |<qFz t ||||WqFt y} zxt | } |rtd} | ||| f;} n td} | || f;} |} | d|d } | | t | ddrd}t| tjr| jr| j}|durtd}tj| |d|d| t| tjr| jr|td| j|WYd} ~ qFd} ~ wwWdn 1swY|ddtt||dtdfg}|ddt|||t}|ddtdS}t|dD]D}|dd|td|}t||s[|dd |||Wdn 1sfwY|dd!|||||j7<q9Wdn 1swY|dd"||dd#td$Z}t|dD]K}||vrq|dd%|td&|}t ||s|dd'|||Wdn 1swY|dd(|||||j7<qWdn 1swY|dd)||D]}|dd*|dt!|<q |dd+td,)}t"D]}|t!vr2q)t"|D]}|dd-||d.d/q6q)Wdn 1sSwY|dd0|t"#d d1l$m%}m&}m'}m(}m)}m*}m+}m,}|dd2d3|d4fd5|d6fd7|d8fd9|d:fd;|d8fd<|d=fd>|d?fd@|dAfg}tdB}t|||Wdn 1swY|ddC|t-|D]}|ddD|t.||q|ddEdS)FNrcs g|] \}}|vr||fqSr"r"rkr0r1 whitelistr"r#rn zloadall..cSs g|] \}}d|vr||fqS):r"rr"r"r#rnrrSsloading %sextensions s additional s- processing %d entries zload all extensions*rrrs$ - skipping disabled extension: %s s+failed to import extension "%s" from %s: %ss#failed to import extension "%s": %ssrequiredsnosSloading of this extension was required, see `hg help config.extensions` for detailsr]s*** %s s *** (%s) s&> loaded %d extensions, total time %s rxsloadconfigtables!- loading configtable attributes s- executing uisetup hooks z all uisetups - running uisetup for %s z uisetup %ss& - the %s extension uisetup failed s > uisetup for %s took %s s> all uisetup took %s s- executing extsetup hooks z all extsetups - running extsetup for %s z extsetup %ss' - the %s extension extsetup failed s > extsetup for %s took %s s> all extsetup took %s s$ - disabling broken %s extension s%- executing remaining aftercallbacks aftercallbackss. - extension %s not loaded, notify callbacks Frs+> remaining aftercallbacks completed in %s )colorcommands filemergefilesetrevsettemplatefilters templatefuncs templatekws)- loading extension registration objects rvs loadcmdtablerwsloadcolortablerys loadpredicaterzsloadinternalmerger{r|s loadfilterr}s loadfunctionr~s loadkeywordzload registration objectss0> extension registration object loading took %s s*> extension %s take a total of %s to load sextension loading complete )/ collections defaultdictintr lenr&rTr rconfigsuboptions_disabledextensionsrrrrUrcopyupdate parseboolrr_r Hintr^AbortrrX _loadextrararaddrrr'rclearr\rrrrrrrrsorted timecount)r!rrresultnewindexrdefault_sub_optionsrr9rr error_msgoptions ext_optionsr^earlyextraloadersbrokenalluisetupstatsallextetupstatsrrrrrrrrrr extraloadersr"rr#loadalls4        .                  (    rc CsZt|dD]$}t|}|sq|D]\}}}t||d}|dur)t|||||qqdSN)r&r'r) r!rrrr(objname loadermod loadernameextraobjr"r"r#rs rcCs8|tvrt|du}||ddSt|g|dS)aRun the specified function after a named extension is loaded. If the named extension is already loaded, the callback will be called immediately. If the named extension never loads, the callback will be called after all extensions have been loaded. The callback receives the named argument ``loaded``, which is a boolean indicating whether the dependent extension actually loaded. Nr)r'r setdefaultr) extensioncallbackrr"r"r# afterloadeds rc Cst|D]9\}}t|dd}|sqz||Wqty=}z|jdd|td|t|fWYd}~qd}~wwdS)aMRun extension hooks on the given ui to populate additional members, extend the class dynamically, etc. This will be called after the configuration is loaded, and/or extensions are loaded. In general, it's once per ui instance, but in command-server and hgweb, this may be called more than once with the same ui. uipopulateNTrs.*** failed to populate ui by extension %s: %s )r)rrrXrrrrU)r!rr/hookrr"r"r# populateuis     rcstsJfdd}|S)zPartial function application Returns a new function that is the partial application of args and kwargs to func. For example, f(1, 2, bar=3) === bind(f, 1)(2, bar=3)cs|i|Srr")rlkwargsfuncr"r#closureszbind..closure)callable)rrrr"rr#r s rcCs\z|j|_Wn tyYnwt|d|_t|d|_|jt|di||_||_dS)z.Copy and add some useful attributes to wrapper __module____doc____dict__N) __name__AttributeErrorrrrrr _origfunc_unboundwrapper)wraporigfnunboundwrapperr"r"r#_updatewrappers     rc Cst|sJt||\}}t|D] \}}||ur|} nq|d} tt|t| } t | | ||durA| j |7_ t |} | | d<|durU| d|7<t | || <|S)a.Wrap the command named `command' in table Replace command in the command table with wrapper. The wrapped command will be inserted into the command table specified by the table argument. The wrapper will be called like wrapper(orig, *args, **kwargs) where orig is the original (wrapped) function, and *args, **kwargs are the arguments passed to it. Optionally append to the command synopsis and docstring, used for help. For example, if your extension wraps the ``bookmarks`` command to add the flags ``--remote`` and ``--all`` you might call this function like so: synopsis = ' [-a] [--remote]' docstring = """ The ``remotenames`` extension adds the ``--remote`` and ``--all`` (``-a``) flags to the bookmarks command. Either flag will show the remote bookmarks known to the repository; ``--remote`` will also suppress the output of the local bookmarks. """ extensions.wrapcommand(commands.table, 'bookmarks', exbookmarks, synopsis, docstring) rNr) rr findcmdr r- functoolspartialr checksignaturerrr`rb) tablecommandwrappersynopsis docstringaliasesentryaliasrskeyrrnewentryr"r"r# wrapcommand's(   rcs~t|}ts J|jD]"}||jvr0|j|jts!Jfdd}||j|_nq|tur=td||fdS)z[Wraps a filecache property. These can't be wrapped using the normal wrapfunction. csg|Ri|Srr")rkwargsrrr"r#rgzwrapfilecache..wrapztype '%s' has no property '%s'N)r rKr__mro__rrobjectr)clspropnamercurrclsrr"rr# wrapfilecache[s        rc@s(eZdZdZddZddZddZdS) wrappedfunctionz3context manager for temporarily wrapping a functioncCs"t|sJ||_||_||_dSr)r _container _funcname_wrapper)self containerfuncnamerr"r"r#__init__ts  zwrappedfunction.__init__cCt|j|j|jdSr) wrapfunctionr r r )r r"r"r# __enter__zrzwrappedfunction.__enter__cCrr)unwrapfunctionr r r )r exctypeexcvaluerXr"r"r#__exit__}rzwrappedfunction.__exit__N)rr __qualname__rrrrr"r"r"r#r qs  r cCs`t|sJt||}t|sJt|rt||}nt||}t|||t||||S)aWrap the function named funcname in container Replace the funcname member in the given container with the specified wrapper. The container is typically a module, class, or instance. The wrapper will be called like wrapper(orig, *args, **kwargs) where orig is the original (wrapped) function, and *args, **kwargs are the arguments passed to it. Wrapping methods of the repository object is not recommended since it conflicts with extensions that extend the repository by subclassing. All extensions that need to extend methods of localrepository should use this subclassing trick: namely, reposetup() should look like def reposetup(ui, repo): class myrepo(repo.__class__): def whatever(self, *args, **kwargs): [...extension stuff...] super(myrepo, self).whatever(*args, **kwargs) [...extension stuff...] repo.__class__ = myrepo In general, combining wrapfunction() with subclassing does not work. Since you cannot control what other extensions are loaded by your end users, you should play nicely with others by using the subclass trick. ) rrinspectismodulerrrrr)rrrrrr"r"r#rs !      rcCsVt||}|}|dur|d}||t|||t|D]}t|||q |S)a/undo wrapfunction If wrappers is None, undo the last wrap. Otherwise removes the wrapper from the chain of wrappers. Return the removed wrapper. Raise IndexError if wrapper is None and nothing to unwrap; ValueError if wrapper is not None but is not found in the wrapper chain. Nr)getwrapperchainpopremoverreversedr)rrrchainrwr"r"r#rs    rcCsDg}t||}|r t|sJ|t|d|t|dd}|s |S)zget a chain of wrappers of a function Return a list of functions: [newest wrapper, ..., oldest wrapper, origfunc] The wrapper functions are the ones passed to wrapfunction, whose first argument is origfunc. rrN)rrr)rrrrr"r"r#rs   rcCsddl}t|dr*tjtt|j }zt |}Wn t y)iYSwiSi}|D]9}| drG| ddd}tj||}n|}tj||d}tj|sXq0||vsd|tvsd|dkreq0|||<q0ttD] \}}|ry|||<qo|S) zAfind paths of disabled extensions. returns a dict of {name: path}rN__file__s.pyr*rs __init__.pys__init__)hgextr rjr8r9dirnameabspathr fsencoder!listdirOSErrorr.rsplitrpexistsr&r-r)r"extpathfilesextsrsrr9r"r"r#_disabledpathss8     r-cCsg}|}|dddks|s%|}|sn |dddks|r|dd}|dks3|dkra|dd}|r`||rQ||d}|rP||n|sUdS|||}|s;ndSd|S) zreturn the top-level python documentation for the given file Loosely inspired by pydoc.source_synopsis(), but rewritten to handle triple quotes and to return the whole text instead of just the synopsisNr#s"""s'''rr)readlinestriprstripr.r;rrp)filerlinestartr"r"r# _moduledocs0     r6cCs`zt|d }t|}Wdn1swYWn ty%YdSw|r,t|StdS)zBretrieve help synopsis of a disabled extension (without importing)rbN(no help text available))rr6r@rr)r9srcdocr"r"r# _disabledhelp s   r;c Cszddlm}ddt|jDWSttfyYnwt}|s%iSi}t|D]\}}t|}|rB|dkrB| d||<q,|S)zCfind disabled extensions from hgext. returns a dict of {name: desc}r) __index__cSs"i|] \}}|tvr|t|qSr")r&r)rkrrGr"r"r# 3s zdisabled..s __index__) r"r<r r-docsrOrr-r; splitlines)r<pathsr,rr9r:r"r"r#disabled.s$   rAcCst}||vr t||SdS)z.)r r-r'r"r"r"r# notloadedsrccCst|drt|jrz|}Wntyd}Yn wt|dr'|j}nd}t|ttfrsz moduleversion..) r rjr getversionr __version__r_r`rbrprrU)r(rr"r"r# moduleversions    rhcCst|dd}|dkS)N testedwithsships-with-hg-core)r)r( exttestedwithr"r"r#ismoduleinternals rkr)NN)F)T)B __future__rrErrr<rr8i18nrrr rrrr\r r r r utilsrr'rrr&rr)r2rIrNrRr[rcrorurrrrrrrrrrrrrr rrrr-r6r;rArBrOrXr^r`r$rcrhrkr"r"r"r#sn     3 =  4 2&!