o ]Lbx@sddlmZddlZddlmZddlmZddlmZm Z m Z m Z m Z m Z mZmZmZmZmZmZmZmZmZmZddlmZmZejZejZejZejZej Z ej!Z!ej"Z"ej#Z#iZ$e%e$Z%e%dd d Z&e%d d d ddZ'e%dddhdddZ(e%ddddhdddZ)e%ddhdddZ*e%dd d!Z+e%d"d#d$Z,e%d%dhdd&d'Z-e%d(d)dhdd*d+Z.e%d,d-d d.d/Z/e%d0d1d2Z0e%d3d4d5Z1e%d6dhdd7d8Z2e%d9dhdd:d;Z3e%dZ4d?d@Z5e%dAdBdCZ6e%dDdEdFZ7e%dGdHdIZ8e%dJdKdLZ9e%dMdhddNdOZ:e%dPdQdRZ;e%dSdTdUZe%d\d]d^Z?e%d_d`daZ@e%dbdcddZAe%dedfdgZBe%dhdidjZCe%dkd)hddldmZDe%dnd)dhddodpZe%dqdrdsZEe%dtdudvZFe%dwdxd dydzZGe%d{d)dhdd|d}ZHe%d~ddZIe%dddZJe%dddZKe%ddd)dhdddZLe%dddZMddZNe$OZPdS))absolute_importN)_)bin)colordagopdiffutilencodingerrorminirstobsutilpycompat registrarrevset revsetlangscmutiltemplatefilters templatekw templateutilutil)dateutil stringutilsdate(date[, fmt])cCs|dt|kr dksnttdt|||dtd}d}t|dkr/t|||d}|dur8t|St||S)zFormat a date. See :hg:`help dates` for formatting strings. The default is a Unix date format, including the timezone: "Mon Sep 04 15:13:13 2006 0700".rs!date expects one or two argumentsrsdate expects a date informationN)lenr ParseErrorrevaldate evalstringrdatestr)contextmappingargsdatefmtr#9/usr/lib/python3/dist-packages/mercurial/templatefuncs.pyr!3s   r!sdict([[key=]value...])s*args **kwargs)argspeccst}|dD]+}t|}|sttd||vs"||dvr+ttd|t|||<q|fddt |dDt |S)zvConstruct a dict from key-value pairs. A key may be omitted if a value expression can provide an unambiguous name.argssdict key cannot be inferredskwargss!duplicated dict key '%s' inferredc3s$|] \}}|t|fVqdSN evalfuncarg).0kvrrr#r$ Zs  zdict_..) rsortdictrfindsymbolicnamer rrr)updater iteritems hybriddict)rrr datar,r+r#r-r$dict_Ls    r5s)diff([includepattern [, excludepattern]])ctxui)requirescsvtdkr ttdfdd}d}d}t|}|j|g|d|d|d }d |S) zCShow a diff, optionally specifying files to include or exclude.rs(diff expects zero, one, or two argumentscs.|tkrt|}|r|gSgSr')rrstrip)isr rrr#r$ getpatternsks zdiff..getpatternsr6r7rr)matchopts) rr rrresourcer diffalloptsdiffr>join)rrr r=ctxuidiffoptschunksr#r<r$rCas     rCsextdata(source)sourcecache)r%r8cCsd|vr ttdt|||d}|s2t|d}|r+tjtdtd|dttd||ddi}||d}||vrK||}n t | |}||<| | d S) zBShow a text read from the specified extdata source. (EXPERIMENTAL)rIsextdata expects one argumentsempty data source specifiedsdid you mean extdata('%s')?hintrJsextdatar6r@) r rrrrr0rA setdefaultr extdatasourcerepogetrev)rrr sourcesymcacherEr4r#r#r$extdata|s"   rUsfiles(pattern)cCs`t|dks ttdt|||d}||d}||g}t||}t ||d|S)zUAll files of the current changeset matching the pattern. See :hg:`help patterns`.rsfiles expects one argumentrr6sfile) rr rrrrAr>listmatchesrcompatfileslist)rrr rawrEmfilesr#r#r$r[s   r[s1fill(text[, width[, initialident[, hangindent]]])cCsdt|kr dksnttdt|||d}d}d}d}dt|kr.dkrWnn't|||dtd}zt|||d}t|||d }Wn tyVYnwt||||S) zJFill many paragraphs with optional indentation. See the "fill" filter.rs"fill expects one to four argumentsrLr@rsfill expects an integer width) rr rrr evalinteger IndexErrorrfill)rrr textwidth initindent hangindentr#r#r$ras( rasfilter(iterable[, expr])csrdtkr dksnttdtd}tdkr*fdd}nfdd}||S)zsRemove empty elements from a list or a dict. If expr specified, it's applied to each element to test emptiness.rrs#filter expects one or two argumentsrcs |Sr')tobool)wr-r#r$selects zfilter_..selectcs<t|tjs ttd|}t|dS)Nsnot filterable by expressionr) isinstancermappabler rr overlaymaptomap evalboolean)rglmr<r#r$rhs )rr rr evalwrappedfilter)rrr iterablerhr#r<r$filter_s rrsformatnode(node)cCsJt|dkr ttd||d}t|||d}|jr |St|S)z;Obtain the preferred form of a changeset hash. (DEPRECATED)rsformatnode expects one argumentr7r) rr rrrAr debugflagrshort)rrr rFnoder#r#r$ formatnodes   rvsmailmap(author)repocCstt|dkr ttdt|||d}||d}||d}d|vr2|jd}t ||d<t |d|S)zNReturn the author, updated according to the value set in the .mailmap filersmailmap expects one argumentrrJrwsmailmaps.mailmap) rr rrrrAwvfstryreadr parsemailmapmapname)rrr authorrTrOr4r#r#r$mailmaps    r}s@pad(text, width[, fillchar=' '[, left=False[, truncate=False]]])s!text width fillchar left truncatec Csd|vsd|vrttdt|||dtd}t|||d}d}d}d}d|vrDt|||d}tt|dkrDttd d |vrPt|||d }d |vr\t|||d }|t t|}|d krw|rwt j t|||d S|d kr}|S|r|||S|||S)z#Pad text with a fill character.stextswidths#pad() expects two to four argumentsspad() expects an integer widthF sfillcharrs%pad() expects a single fill charactersleftstruncater)leftside) r rrr_rrr stripeffectsrmr colwidthtrim) rrr rcrbtruncateleftfillchar fillwidthr#r#r$pads8   rs&indent(text, indentchars[, firstline])cCsxdt|kr dksnttdt|||d}t|||d}|}t|dkr4t|||d}tj|||dS)zIndents all non-empty lines with the characters given in the indentchars string. An optional third parameter will override the indent for the first line only if present.rr^s'indent() expects two or three argumentsrr) firstline)rr rrrrindent)rrr rbrrr#r#r$r*s rsget(dict, key)c Cst|dkr ttdt|||d}t|||d}z||||WStjy?}z td}tjt||dd}~ww)zGet an attribute/key from an object. Some keywords are complex types. This function allows you to obtain the value of an attribute on these types.rsget() expects two argumentsrrs&get() expects a dict as first argumentrKN)rr rrro evalrawexp getmemberbytes)rrr dictargkeyerrrLr#r#r$rP>s rPs config(section, name[, default])cC||dj}t||||tS)z5Returns the requested hgrc config option as a string.r7)rAconfig_configrrrr fnr#r#r$rQrs$configbool(section, name[, default])cCr)z6Returns the requested hgrc config option as a boolean.r7)rA configboolrrmrr#r#r$rXrrs#configint(section, name[, default])cCr)z7Returns the requested hgrc config option as an integer.r7)rA configintrr_rr#r#r$r_rrcCszdt|kr dksnttdt|||d}t|||d}t|dkr8||||d}||||S|||S)Nrr^s%config expects two or three argumentsrr)rr rrevalstringliteral)rrr configfn defaultfnsectionnamedefaultr#r#r$rfs   rsif(expr, then[, else])cCsldt|kr dksnttdt|||d}|r&t|||dSt|dkr4t|||dSdS)z?Conditionally execute based on the result of an expression.rr^s!if expects two or three argumentsrrN)rr rrrmr)rrr testr#r#r$if_vs rs*ifcontains(needle, haystack, then[, else])cCsdt|kr dksnttdt|||d}zt|||d}||||}Wn tjy9d}Ynw|rDt|||dSt|dkrRt|||dSdS) zNConditionally execute based on whether the item "needle" is in "haystack".r^r\s*ifcontains expects three or four argumentsrrFrN)rr rrrorcontains)rrr haystackneedlefoundr#r#r$ ifcontainss rs ifeq(expr1, expr2, then[, else])cCsdt|kr dksnttdt|||d}t|||d}||kr0t|||dSt|dkr>t|||dSdS)zBConditionally execute based on whether 2 items are equivalent.r^r\s$ifeq expects three or four argumentsrrrN)rr rrrr)rrr rr>r#r#r$ifeqs rsjoin(list, sep)cCsfdt|kr dksnttdt|||d}d}t|dkr,t|||d}||||S)z&Join items in a list with a delimiter.rrs!join expects one or two argumentsrr~)rr rrrorrD)rrr joinsetjoinerr#r#r$rDs rDslabel(label, expr)cCsRt|dkr ttd||d}t|||d}t|||d}|||S)zApply a label to generated content. Content with a label applied can result in additional post-processing, such as automatic colorization.rslabel expects two argumentsr7rr)rr rrrArrlabel)rrr rFthingrr#r#r$rs   rslatesttag([pattern])cCsHt|dkr ttdd}t|dkrt|||d}t|||S)aThe global tags matching the given pattern on the most recent globally tagged ancestor of this changeset. If no such tags exist, the "{tag}" template resolves to the string "null". See :hg:`help revisions.patterns` for the pattern syntax. rs&latesttag expects at most one argumentNr)rr rrrrshowlatesttags)rrr patternr#r#r$ latesttags  rslocaldate(date[, tz])c Csdt|kr dksnttdt|||dtd}t|dkr[d}t|||d}t|tr?t |\}}|r?d}|durZzt |}Wnt t fyYttdwnt d}t|d|fS)zIConverts a date to the specified timezone. The default is local date.rrs&localdate expects one or two argumentsrs$localdate expects a date informationNslocaldate expects a timezone)rr rrrr)rirr parsetimezoneint TypeError ValueErrormakedaterr!)rrr r!tzoffsettz remainderr#r#r$ localdates0    rs max(iterable)c Knt|dkr ttdt|||d}z|||WStjy6}z td}tjt||dd}~ww)zReturn the max of an iterablersmax expects one argumentrs(max first argument should be an iterablerKN)rr rrrogetmaxrrrr kwargsrqrrLr#r#r$max_ rs min(iterable)c Kr)zReturn the min of an iterablersmin expects one argumentrs(min first argument should be an iterablerKN)rr rrrogetminrrr#r#r$min_ rrs mod(a, b)cCs>t|dks ttddd}t||||d|dfS)z0Calculate a mod b such that a / b + a mod b == arsmod expects two argumentscSs||Sr'r#)abr#r#r$$szmod..rr)rr rrr runarithmetic)rrr funcr#r#r$mods rsobsfateoperations(markers)c Csjt|dkr ttdt|||d}z t|}tj|ddWSt t fy4td}t|w)CCompute obsfate related information based on markers (EXPERIMENTAL)rs&obsfateoperations expects one argumentrs operationrs6obsfateoperations first argument should be an iterable) rr rrr)r markersoperationsr hybridlistrKeyErrorrrr markersr4errmsgr#r#r$obsfateoperations*s   rsobsfatedate(markers)c Cslt|dkr ttdt|||d}zt|}tj|dddWSt t fy5td}t|w)rrs obsfatedate expects one argumentrsdates%d %d)rr"s0obsfatedate first argument should be an iterable) rr rrr)r markersdatesrrrrrr#r#r$ obsfatedate<s   rsobsfateusers(markers)c Cslt|dkr ttdt|||d}z t|}tj|ddWSt t t fy5td}t|w)rrs!obsfateusers expects one argumentrsuserrs>obsfateusers first argument should be an iterable of obsmakers) rr rrr)r markersusersrrrrr)rrr rr4msgr#r#r$ obsfateusersOs   rs obsfateverb(successors, markers)cCsjt|dkr ttdt|||d}t|||d}zt||WSty4td}t|w)zFCompute obsfate related information based on successors (EXPERIMENTAL)rs!obsfateverb expects two argumentsrrs.obsfateverb first argument should be countable)rr rrr)r obsfateverbr)rrr successorsrrr#r#r$rds   rs relpath(path)cCs@t|dkr ttd||d}t|||d}||S)zhConvert a repository-absolute path into a filesystem path relative to the current working directory.rsrelpath expects one argumentrwr)rr rrrArpathto)rrr rOpathr#r#r$relpathvs   rsrevset(query[, formatargs...])c st|dks ttdt|d}dfdd}t|dkrCd}fdd |ddD}|tj|g|R}nd }|d i} |}|| vrZ| |}n||}|| |<t j |d |d S)z8Execute a revision set query. See :hg:`help revset`.rs$revset expects one or more argumentsrwcs tjj|td}|S)N)lookup) revsetmodr>rFlookupfn)exprrZ)rOr#r$queryszrevset..queryrNcsg|]}t|qSr#r()r*rr-r#r$ szrevset..rJs revsetcachesrevision)rcachekey) rr rrrrAr formatspecrMrrevslist) rrr rYrr formatargsrevsrT revsetcacher#)rrrOr$rs"       rsrstdoc(text, style)cCsLt|dkr ttdt|||d}t|||d}tj||dgdS)zFormat reStructuredText.rsrstdoc expects two argumentsrrsverbose)stylekeep)rr rrrr format)rrr rbrr#r#r$rstdocs rssearch(pattern, text)c Cst|dkr ttdt|||d}t|||d}zt|}Wntjy5ttd|w|tt |j @}|rZttdd dd t |D|d ||}|setSd |di}|d d t|dD|t |tj|d dS)zLook for the first text matching the regular expression pattern. Groups are accessible as ``{1}``, ``{2}``, ... in %-mapped template.rssearch expects two argumentsrrs!search got an invalid pattern: %ss2invalid group %(group)s in search pattern: %(pat)ss, css|]}d|VqdS)s'%s'Nr#)r*gr#r#r$r.szsearch..)sgroupspat0css |] \}}d||fVqdS)s%dNr#)r*r:r,r#r#r$r.ss{0})tmpl)rr rrrrecompileknownresourcekeyssetr byteskwargs groupindexrDsortedsearchr mappingnonegroupr1 enumerategroups groupdict mappingdict) rrr patsrcpatre badgroupsr>rnr#r#r$rs6   rsseparate(sep, args...)s sep *argsccsfd|vr ttdt|||d}d}|dD]}t|||}|s%q|r*d}n|V|VqdS)z,Add a separator between non-empty arguments.sseps&separate expects at least one argumentTr&FN)r rrr)rrr sepfirstargargstrr#r#r$separates  rsshortest(node, minlength=4)c Cs:dt|kr dksnttdt|||d}d}t|dkr/t|||dtd}||d}d|jj}t||krC|St||kr[zt |}Wn1t yZ|YSwzt ||}Wntj yq|jj}Yn tjy||YSw|s|S||d}z t ||||WStjy|YSw) z1Obtain the shortest representation of a node.rrs'shortest() expects one or two argumentsrr\s'shortest() expects an integer minlengthrwrJ)rr rrrr_rA nodeconstantsnodelenrrrresolvehexnodeidprefixWdirUnsupportedwdirid LookupErrorshortesthexnodeidprefixRepoLookupError) rrr hexnode minlengthrO hexnodelenrurTr#r#r$shortestsH         r sstrip(text[, chars])cCsfdt|kr dksnttdt|||d}t|dkr/t|||d}||S|S)z[Strip characters from a string. By default, strips all leading and trailing whitespace.rrs"strip expects one or two argumentsr)rr rrrr9)rrr rbcharsr#r#r$r9s  r9s%sub(pattern, replacement, expression)ccst|dkrttdt|||d}t|||d}t|||d}zt|}Wntjy>ttd|wz |||VWdStjyZttd|w) z8Perform text substitution using regular expressions.r^ssub expects three argumentsrrrssub got an invalid pattern: %ss"sub got an invalid replacement: %sN)rr rrrrrsub)rrr rrplrrr#r#r$r&s  rsstartswith(pattern, text)cCsLt|dkr ttdt|||d}t|||d}||r$|SdS)ziReturns the value from the "text" argument if it begins with the content from the "pattern" argument.rs startswith expects two argumentsrrr@)rr rrr startswith)rrr patnrbr#r#r$r=s  rssubsetparents(rev, revset)s rev revsetc Csd|vsd|vrttd||d}t|||d}t|||d}t|tjs4ttd| ||}|j }|r_||d}| di} || vrT| |} nt ||} | | |<nt j |||d} t|| |S) z@Look up parents of the rev in the sub graph given by the revset.srevsrevsets#subsetparents expects two argumentsrws&subsetparents expects a queried revsetrJssubsetparentswalker)startrev)r rrrArr_rorirtovaluerrMrsubsetparentswalker parentsset) rrr rOrQqsubsetrrT walkercachewalkerr#r#r$ subsetparentsLs$        rsword(number, text[, separator])cCsdt|kr dksnttdt|t|||dtd}t|||d}t|dkr:t|||d}nd}||}|t|ksN|t| krPdS||S) z"Return the nth word from a string.rr^s+word expects two or three arguments, got %drsword expects an integer indexrNr@)rr rrr_rsplit)rrr numrbsplittertokensr#r#r$wordss$  rcCs"t|jD]\}}|t|<qdS)z2Load template function from specified registrarobjN)r r2_tablefuncs)rFextname registrarobjrrr#r#r$ loadfunctions r$)Q __future__rri18nrrurrrrr r r r r rrrrrrrrrutilsrrrror)rmrr_rrr! templatefuncr!r5rCrUr[rarrrvr}rrrPrrrrrrrrDrrrrrrrrrrrrrrr r9rrrrr$values i18nfunctionsr#r#r#r$s   H               )                            &  ,    "