
    q&fx                     b   d dl Z d dlZddlmZ ddlmZ ddlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZ ej6                  Zej8                  Zej:                  Zej<                  Zej>                  Zej@                  Z ejB                  Z!ejD                  Z"i Z# ejH                  e#      Z$ e$d      d        Z% e$d	d
      d        Z& e$dddh      d        Z' e$ddddh      d        Z( e$ddh      d        Z) e$d      d        Z* e$d      d        Z+ e$ddh      d        Z, e$dd dh      d!        Z- e$d"d#      d$        Z. e$d%      d&        Z/ e$d'      d(        Z0 e$d)dh      d*        Z1 e$d+dh      d,        Z2 e$d-dh      d.        Z3d/ Z4 e$d0      d1        Z5 e$d2      d3        Z6 e$d4      d5        Z7 e$d6      d7        Z8 e$d8dh      d9        Z9 e$d:      d;        Z: e$d<      d=        Z; e$d>      d?        Z< e$d@      dA        Z= e$dB      dC        Z> e$dD      dE        Z? e$dF      dG        Z@ e$dH      dI        ZA e$dJ      dK        ZB e$dLd h      dM        ZC e$dNd dh      dO        Z e$dP      dQ        ZD e$dR      dS        ZE e$dTdU      dV        ZF e$dWd dh      dX        ZG e$dY      dZ        ZH e$d[      d\        ZI e$d]      d^        ZJ e$d_d`d dh      da        ZK e$db      dc        ZLdd ZMe#j                         ZOy)e    N   )_)bin)colordagopdiffutilencodingerrorminirstobsutilpycompat	registrarrevset
revsetlangscmutiltemplatefilters
templatekwtemplateutilutil)dateutil
stringutils   date(date[, fmt])c                 8   dt        |      cxk  rdk  s n t        j                  t        d            t	        | ||d   t        d            }d}t        |      dk(  rt        | ||d         }|t        j                  |      S t        j                  ||      S )zFormat a date. The format string uses the Python strftime format.
    The default is a Unix date format, including the timezone:
    "Mon Sep 04 15:13:13 2006 0700".r      s!   date expects one or two argumentsr   s   date expects a date informationN)lenr
   
ParseErrorr   evaldate
evalstringr   datestr)contextmappingargsdatefmts        9/usr/lib/python3/dist-packages/mercurial/templatefuncs.pyr"   r"   3   s    
 Taq!EFGGQ	
,-D C
4yA~'473
{%%c**    s   dict([[key=]value...])s   *args **kwargs)argspecc                     t        j                         }|d   D ]s  }t        j                  |      }|st	        j
                  t        d            ||v s||d   v r!t	        j
                  t        d      |z        t         |      ||<   u |j                   fd|d   j                         D               t        j                  |      S )zvConstruct a dict from key-value pairs. A key may be omitted if
    a value expression can provide an unambiguous name.   argss   dict key cannot be inferreds   kwargss!   duplicated dict key '%s' inferredc              3   B   K   | ]  \  }}|t        |      f  y wN)evalfuncarg).0kvr   r    s      r$   	<genexpr>zdict_.<locals>.<genexpr>Z   s+      Aq 
K!,-s   )r   sortdictr   findsymbolicnamer
   r   r   r+   updateitems
hybriddict)r   r    r!   datar.   r-   s   ``    r$   dict_r6   L   s     ==?D'] 3))!,""1%C#DEE9T)_,""1%I#JQ#NOOgw2Q3 	KK O))+  ""4((r%   s)   diff([includepattern [, excludepattern]])   ctx   ui)requiresc           	      b    t              dkD  rt        j                  t        d             fd} j	                  d      } j	                  d      }t        j                  |      }|j                  |j                  g  |d       |d            |      }d	j                  |      S )
zCShow a diff, optionally
    specifying files to include or exclude.r   s(   diff expects zero, one, or two argumentsc                 j    | t              k  r#t        |          j                         }|r|gS g S r*   )r   r   strip)isr!   r   r    s     r$   getpatternszdiff.<locals>.getpatternsk   s8    s4y=7GT!W5;;=As
	r%   r7   r8   r   r   )matchoptsr%   )
r   r
   r   r   resourcer   diffalloptsdiffr@   join)r   r    r!   r?   ctxuidiffoptschunkss   ```     r$   rD   rD   a   s     4y1}q!LMNN 

7F
+C			'5	)B##B'HXXiiKNKN;(  F 88Fr%   s   extdata(source)   source   cache)r&   r9   c                 @   d|vrt        j                  t        d            t        | ||d         }|sdt	        j
                  |d         }|r,t        j                  t        d      t        d      |z        t        j                  t        d            | j                  |d      j                  di       }| j                  |d      }||v r||   }n)t        j                  |j                         |      x}||<   |j                  |j                         d	      S )
zBShow a text read from the specified extdata source. (EXPERIMENTAL)rJ   s   extdata expects one arguments   empty data source specifieds   did you mean extdata('%s')?hintrK   s   extdatar7   r%   )r
   r   r   r   r   r1   rB   
setdefaultr   extdatasourcerepogetrev)r   r    r!   sourcesymcacherF   r5   s           r$   extdatarW   |   s   
 q!@ABB$y/:F++DO<""0156< 
 ""1%C#DEEWh/:::rJE


7F
+CV}&44SXXZHHuV}88CGGIs##r%   s   files(pattern)c                 &   t        |      dk(  st        j                  t        d            t	        | ||d         }| j                  |d      }|j                  |g      }t        |j                  |            }t        j                  | |d|      S )zUAll files of the current changeset matching the pattern. See
    :hg:`help patterns`.r   s   files expects one argumentr   r7   s   file)r   r
   r   r   r   rB   r@   listmatchesr   compatfileslist)r   r    r!   rawrF   mfiless          r$   r^   r^      s     t9>q!>?@@
WgtAw
/C


7F
+C		3%AQ E'''5IIr%   s1   fill(text[, width[, initialident[, hangindent]]])c                    dt        |      cxk  rdk  s n t        j                  t        d            t	        | ||d         }d}d}d}dt        |      cxk  rdk  r>n n;t        | ||d   t        d            }	 t	        | ||d         }t	        | ||d	         }t        j                  ||||      S # t        $ r Y #w xY w)
zJFill many
    paragraphs with optional indentation. See the "fill" filter.r      s"   fill expects one to four argumentsr   L   r%   r   s   fill expects an integer width   )	r   r
   r   r   r   evalinteger
IndexErrorr   fill)r   r    r!   textwidth
initindent
hangindents          r$   re   re      s     Taq!FGHHgwQ0DEJJCIG./
	#GWd1g>J#GWd1g>J eZDD  		s   = B5 5	C Cs   filter(iterable[, expr])c                      dt              cxk  rdk  s n t        j                  t        d            t	         d         }t              dk(  r fd}n fd}|j                   |      S )zsRemove empty elements from a list or a dict. If expr specified, it's
    applied to each element to test emptiness.r   r   s#   filter expects one or two argumentsr   c                 (    | j                        S r*   )tobool)wr   r    s    r$   selectzfilter_.<locals>.select   s    88GW--r%   c                     t        | t        j                        st        j                  t        d            j                  | j                              }t        |d         S )Ns   not filterable by expressionr   )	
isinstancer   mappabler
   r   r   
overlaymaptomapevalboolean)rm   lmr!   r   r    s     r$   rn   zfilter_.<locals>.select   sX    a!6!67&&q)H'IJJ##GQWWW-=>BwDG44r%   )r   r
   r   r   evalwrappedfilter)r   r    r!   iterablern   s   ```  r$   filter_ry      si     Taq!GHII7GT!W5H
4yA~	.
	5 ??7GV44r%   s   formatnode(node)c                     t        |      dk7  rt        j                  t        d            | j	                  |d      }t        | ||d         }|j                  r|S t        j                  |      S )z;Obtain the preferred form of a changeset hash. (DEPRECATED)r   s   formatnode expects one argumentr8   r   )	r   r
   r   r   rB   r   	debugflagr   short)r   r    r!   rG   nodes        r$   
formatnoder~      sg     4yA~q!CDEE			'5	)BgwQ0D	||  &&r%   s   mailmap(author)   repoc                 b   t        |      dk7  rt        j                  t        d            t	        | ||d         }| j                  |d      }| j                  |d      }d|vr3|j                  j                  d      }t        j                  |      |d<   t        j                  |d   |      S )zNReturn the author, updated according to the value
    set in the .mailmap filer   s   mailmap expects one argumentr   rK   r   s   mailmaps   .mailmap)r   r
   r   r   r   rB   wvfstryreadr   parsemailmapmapname)r   r    r!   authorrV   rQ   r5   s          r$   mailmapr      s     4yA~q!@ABB$q'2FWh/EGW-Dyy  -&33D9jeJ/88r%   s@   pad(text, width[, fillchar=' '[, left=False[, truncate=False]]])s!   text width fillchar left truncatec                    d|vsd|vrt        j                  t        d            t        | ||d   t        d            }t	        | ||d         }d}d}d}d|v rOt	        | ||d         }t        t        j                  |            dk7  rt        j                  t        d	            d
|v rt        | ||d
         }d|v rt        | ||d         }|t        j                  t        j                  |            z
  }|dk  r-|r+t        j                  t        j                  |      ||      S |dk  r|S |r||z  |z   S |||z  z   S )z#Pad text with a
    fill character.s   texts   widths#   pad() expects two to four argumentss   pad() expects an integer widthF    s   fillcharr   s%   pad() expects a single fill characters   lefts   truncater   )leftside)r
   r   r   rc   r   r   r   stripeffectsrt   r	   colwidthtrim)	r   r    r!   rg   rf   truncateleftfillchar	fillwidths	            r$   padr      sa    dhd2q!GHIIX	
+,E gwW6DHDHdgw[0ABu!!(+,1""1%M#NOO$7GT'];dwk1BC))%*<*<T*BCCI1}}}U//5utLLA~)#d**h***r%   s&   indent(text, indentchars[, firstline])c                    dt        |      cxk  rdk  s n t        j                  t        d            t	        | ||d         }t	        | ||d         }|}t        |      dk(  rt	        | ||d         }t        j                  |||      S )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.r   rb   s'   indent() expects two or three argumentsr   r   )	firstline)r   r
   r   r   r   r   indent)r   r    r!   rf   r   r   s         r$   r   r   *  s     Taq!KLMMgwQ0D$q'2FI
4yA~wa9	!!$)DDr%   s   get(dict, key)c                 N   t        |      dk7  rt        j                  t        d            t	        | ||d         }t        | ||d         }	 |j                  | ||      S # t        j                  $ r0}t        d      }t        j                  t        |      |      d}~ww xY w)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.r   s   get() expects two argumentsr   r   s&   get() expects a dict as first argumentrM   N)r   r
   r   r   rv   
evalrawexp	getmemberbytes)r   r    r!   dictargkeyerrrN   s          r$   rR   rR   >  s    
 4yA~q!?@AA'7DG4G
WgtAw
/C6  '377 6:;uSz556s   A! !B$4+BB$s    config(section, name[, default])c                 `    | j                  |d      j                  }t        | |||t              S )z5Returns the requested hgrc config option as a string.r8   )rB   config_configr   r   r    r!   fns       r$   r   r   Q  s/     
		'5	)	0	0B7GT2z::r%   s$   configbool(section, name[, default])c                 `    | j                  |d      j                  }t        | |||t              S )z6Returns the requested hgrc config option as a boolean.r8   )rB   
configboolr   rt   r   s       r$   r   r   X  s/     
		'5	)	4	4B7GT2{;;r%   s#   configint(section, name[, default])c                 `    | j                  |d      j                  }t        | |||t              S )z7Returns the requested hgrc config option as an integer.r8   )rB   	configintr   rc   r   s       r$   r   r   _  s/     
		'5	)	3	3B7GT2{;;r%   c                    dt        |      cxk  rdk  s n t        j                  t        d            t	        | ||d         }t	        | ||d         }t        |      dk(  r || ||d         } ||||      S  |||      S )Nr   rb   s%   config expects two or three argumentsr   r   )r   r
   r   r   evalstringliteral)r   r    r!   configfn	defaultfnsectionnamedefaults           r$   r   r   f  s    Taq!IJKK
  $q':GWgtAw7D
4yA~GWd1g6w//&&r%   s   if(expr, then[, else])c                     dt        |      cxk  rdk  s n t        j                  t        d            t	        | ||d         }|rt        | ||d         S t        |      dk(  rt        | ||d         S y)z?Conditionally execute based on the result of
    an expression.r   rb   s!   if expects two or three argumentsr   r   N)r   r
   r   r   rt   r   )r   r    r!   tests       r$   if_r   v  sw     Taq!EFGGwa1D'7DG44	Ta'7DG44 
r%   s*   ifcontains(needle, haystack, then[, else])c                 j   dt        |      cxk  rdk  s n t        j                  t        d            t	        | ||d         }	 t        | ||d         }|j                  | ||      }|rt        | ||d         S t        |      dk(  rt        | ||d         S y# t        j                  $ r d}Y Hw xY w)	zNConditionally execute based
    on whether the item "needle" is in "haystack".rb   r`   s*   ifcontains expects three or four argumentsr   r   Fr   N)r   r
   r   r   rv   r   contains)r   r    r!   haystackneedlefounds         r$   
ifcontainsr     s     Taq!NOPP7GT!W5HGWd1g6!!'7F; '7DG44	Ta'7DG44 
  s   #B B21B2s    ifeq(expr1, expr2, then[, else])c                    dt        |      cxk  rdk  s n t        j                  t        d            t	        | ||d         }t	        | ||d         }||k(  rt        | ||d         S t        |      dk(  rt        | ||d         S y)zBConditionally execute based on
    whether 2 items are equivalent.rb   r`   s$   ifeq expects three or four argumentsr   r   r   N)r   r
   r   r   r   r   )r   r    r!   r   r@   s        r$   ifeqr     s     Taq!HIJJgwQ0Dwa1Eu}'7DG44	Ta'7DG44 
r%   s   join(list, sep)c                     dt        |      cxk  rdk  s n t        j                  t        d            t	        | ||d         }d}t        |      dkD  rt        | ||d         }|j                  | ||      S )z&Join items in a list with a delimiter.r   r   s!   join expects one or two argumentsr   r   )r   r
   r   r   rv   r   rE   )r   r    r!   joinsetjoiners        r$   rE   rE     ss     Taq!EFGG'7DG4GF
4y1}GWd1g6<<&11r%   s   label(label, expr)c                     t        |      dk7  rt        j                  t        d            | j	                  |d      }t        | ||d         }t        | ||d         }|j                  ||      S )zApply a label to generated content. Content with a label
    applied can result in additional post-processing, such as
    automatic colorization. In order to receive effects, labels must
    have a dot, such as `log.secret` or `branch.active`.r   s   label expects two argumentsr8   r   r   )r   r
   r   r   rB   r   r   label)r   r    r!   rG   thingr   s         r$   r   r     so     4yA~q!?@AA			'5	)Bwa1E gwQ8E88E5!!r%   s   latesttag([pattern])c                     t        |      dkD  rt        j                  t        d            d}t        |      dk(  rt	        | ||d         }t        j                  | ||      S )a  The 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.
    r   s&   latesttag expects at most one argumentNr   )r   r
   r   r   r   r   showlatesttags)r   r    r!   patterns       r$   	latesttagr     s]     4y1}q!JKLLG
4yA~WgtAw7$$Wgw??r%   s   localdate(date[, tz])c                    dt        |      cxk  rdk  s n t        j                  t        d            t	        | ||d   t        d            }t        |      dk\  rMd}t        | ||d         }t        |t              rt        j                  |      \  }}|rd}|$	 t        |      }nt        j                         d   }t        j                  |d   |f      S # t        t        f$ r t        j                  t        d            w xY w)zIConverts a date to the specified timezone.
    The default is local date.r   r   s&   localdate expects one or two argumentsr   s$   localdate expects a date informationNs   localdate expects a timezone)r   r
   r   r   r   r+   rp   r   r   parsetimezoneint	TypeError
ValueErrormakedater   r"   )r   r    r!   r"   tzoffsettz	remainders          r$   	localdater     s
    Taq!JKLLQ	
12D 4yA~'473b% "*"8"8"<HiKr7
 $$&q)d1gx011 z* K&&q)H'IJJKs   C .D	s   max(iterable)c                 ,   t        |      dk7  rt        j                  t        d            t	        | ||d         }	 |j                  | |      S # t        j                  $ r0}t        d      }t        j                  t        |      |      d}~ww xY w)zReturn the max of an iterabler   s   max expects one argumentr   s(   max first argument should be an iterablerM   N)r   r
   r   r   rv   getmaxr   r   r    r!   kwargsrx   r   rN   s          r$   max_r          4yA~q!<=>>7GT!W5H6w00 6<=uSz556   A B#+BBs   min(iterable)c                 ,   t        |      dk7  rt        j                  t        d            t	        | ||d         }	 |j                  | |      S # t        j                  $ r0}t        d      }t        j                  t        |      |      d}~ww xY w)zReturn the min of an iterabler   s   min expects one argumentr   s(   min first argument should be an iterablerM   N)r   r
   r   r   rv   getminr   r   s          r$   min_r     r   r   s	   mod(a, b)c                     t        |      dk(  st        j                  t        d            d }t	        j
                  | |||d   |d   f      S )z0Calculate a mod b such that a / b + a mod b == ar   s   mod expects two argumentsc                     | |z  S r*    )abs     r$   <lambda>zmod.<locals>.<lambda>%  s
    A r%   r   r   )r   r
   r   r   r   runarithmetic)r   r    r!   funcs       r$   modr     sT     t9>q!=>??D%%4a$q'2 r%   s   obsfateoperations(markers)c                 :   t        |      dk7  rt        j                  t        d            t	        | ||d         }	 t        j                  |      }t        j                  |d      S # t        t        f$ r! t        d      }t        j                  |      w xY w)CCompute obsfate related information based on markers (EXPERIMENTAL)r   s&   obsfateoperations expects one argumentr   s	   operationr   s6   obsfateoperations first argument should be an iterable)r   r
   r   r   r+   r   markersoperationsr   
hybridlistr   KeyErrorr   r    r!   markersr5   errmsgs         r$   obsfateoperationsr   +  s     4yA~q!JKLL'7DG4G'((1&&t,??x  'LMv&&'s   +A* *0Bs   obsfatedate(markers)c                 <   t        |      dk7  rt        j                  t        d            t	        | ||d         }	 t        j                  |      }t        j                  |dd      S # t        t        f$ r! t        d      }t        j                  |      w xY w)r   r   s    obsfatedate expects one argumentr   s   dates   %d %d)r   r#   s0   obsfatedate first argument should be an iterable)r   r
   r   r   r+   r   markersdatesr   r   r   r   r   s         r$   obsfatedater   =  s     4yA~q!DEFF'7DG4G'##G,&&t'xHHx  'FGv&&'s   ,A+ +0Bs   obsfateusers(markers)c                 D   t        |      dk7  rt        j                  t        d            t	        | ||d         }	 t        j                  |      }t        j                  |d      S # t        t        t        f$ r! t        d      }t        j                  |      w xY w)r   r   s!   obsfateusers expects one argumentr   s   userr   s>   obsfateusers first argument should be an iterable of obsmakers)r   r
   r   r   r+   r   markersusersr   r   r   r   r   )r   r    r!   r   r5   msgs         r$   obsfateusersr   P  s     4yA~q!EFGG'7DG4G	$##G,&&t'::x, $
 s##$s   +A* *5Bs    obsfateverb(successors, markers)c                 "   t        |      dk7  rt        j                  t        d            t	        | ||d         }t	        | ||d         }	 t        j                  ||      S # t        $ r! t        d      }t        j                  |      w xY w)zFCompute obsfate related information based on successors (EXPERIMENTAL)r   s!   obsfateverb expects two argumentsr   r   s.   obsfateverb first argument should be countable)r   r
   r   r   r+   r   obsfateverbr   )r   r    r!   
successorsr   r   s         r$   r   r   e  s     4yA~q!EFGGWgtAw7J'7DG4G'"":w77 'DEv&&'s   A$ $*Bs   relpath(path)c                     t        |      dk7  rt        j                  t        d            | j	                  |d      }t        | ||d         }|j                  |      S )zhConvert a repository-absolute path into a filesystem path relative to
    the current working directory.r   s   relpath expects one argumentr   r   )r   r
   r   r   rB   r   pathto)r   r    r!   rQ   paths        r$   relpathr   w  sY     4yA~q!@ABBGW-DgwQ0D;;tr%   s   revset(query[, formatargs...])c                    t        |      dkD  st        j                  t        d            t	        | ||d         }| j                  |d      fd}t        |      dkD  r<d}|dd D cg c]  }t        | ||       }} |t        j                  |g|       }n=| j                  |d      }	|	j                  di       }
|}||
v r|
|   }n ||      }||
|<   t        j                  |d	|
      S c c}w )z8Execute a revision set query. See
    :hg:`help revset`.r   s$   revset expects one or more argumentsr   c                 ~    t        j                  j                  | t        j                              } |      S )N)lookup)	revsetmodr@   rG   lookupfn)exprr]   rQ   s     r$   queryzrevset.<locals>.query  s-    OODGGT)2D2DT2JKwr%   r   NrK   s   revsetcaches   revision)r   cachekey)r   r
   r   r   r   rB   r+   r   
formatspecrO   r   revslist)r   r    r!   r\   r   r   r   
formatargsrevsrV   revsetcacherQ   s              @r$   r   r     s	    t9q=q!HIJJ
WgtAw
/CGW-D 4y1}@DQRI1k'7A6I
IZ**3<<=  (3&&~r:+s#D:D#K  t+LL Js   ,C5s   rstdoc(text, style)c                     t        |      dk7  rt        j                  t        d            t	        | ||d         }t	        | ||d         }t        j                  ||dg      S )zFormat reStructuredText.r   s   rstdoc expects two argumentsr   r   s   verbose)stylekeep)r   r
   r   r   r   r   format)r   r    r!   rf   r  s        r$   rstdocr    s_     4yA~q!@ABBgwQ0Dwa1E>>$e:,??r%   s   search(pattern, text)c           	         t        |      dk7  rt        j                  t        d            t	        | ||d         }t	        | ||d         }	 t        j                  |      }| j                         t        t        j                  |j                              z  }|rCt        j                  t        d      dj                  d t        |      D              |d	z        |j                  |      }|st        j                          S d
|j#                  d      i}|j%                  d t'        |j)                         d      D               |j%                  t        j                  |j+                                      t        j,                  |d      S # t
        j                  $ r" t        j                  t        d      |z        w xY w)zLook for the first text matching the regular expression pattern.
    Groups are accessible as ``{1}``, ``{2}``, ... in %-mapped template.r   s   search expects two argumentsr   r   s!   search got an invalid pattern: %ss2   invalid group %(group)s in search pattern: %(pat)ss   , c              3   &   K   | ]	  }d |z    yw)s   '%s'Nr   )r,   gs     r$   r/   zsearch.<locals>.<genexpr>  s     $LQWq[$Ls   )s   groups   pat   0c              3   0   K   | ]  \  }}d |z  |f  yw)s   %dNr   )r,   r=   r.   s      r$   r/   zsearch.<locals>.<genexpr>  s     FAuqy!nFs   s   {0})tmpl)r   r
   r   r   r   recompileknownresourcekeyssetr   byteskwargs
groupindexrE   sortedsearchr   mappingnonegroupr2   	enumerategroups	groupdictmappingdict)	r   r    r!   patsrcpatre	badgroupsr@   ru   s	            r$   r  r    s    4yA~q!@ABB
WgtAw
/C
WgtAw
/CN

3
 ))+cU--./ I CD**$L&:K$LL
 	
 LLE''))
A	BIIF5<<>1)EFFIIh""5??#456##BV441 88 Nq!EFLMMNs   F 5G	s   separate(sep, args...)s	   sep *argsc              #      K   d|vrt        j                  t        d            t        | ||d         }d}|d   D ]  }t        | ||      }|s|rd}n| | ! yw)z,Add a separator between non-empty arguments.s   seps&   separate expects at least one argumentTr(   FN)r
   r   r   r   )r   r    r!   sepfirstargargstrs          r$   separater%    sw      Tq!JKLL
WgtF|
4CEG} GWc2EIs   AAs   shortest(node, minlength=4)c                    dt        |      cxk  rdk  s n t        j                  t        d            t	        | ||d         }d}t        |      dkD  rt        | ||d   t        d            }| j                  |d      }d|j                  j                  z  }t        |      |kD  r|S t        |      |k(  r	 t        |      }n	 t        j                  ||      }|s|S | j                  |d      }	 t        j"                  ||||      S # t        j                  $ r |cY S w xY w# t        j                  $ r |j                  j                  }Y ut        j                   $ r |cY S w xY w# t        j$                  $ r |cY S w xY w)	z1Obtain the shortest representation of
    a node.r   r   s'   shortest() expects one or two argumentsr   r`   s'   shortest() expects an integer minlengthr   rK   )r   r
   r   r   r   rc   rB   nodeconstantsnodelenr   binasciiErrorr   resolvehexnodeidprefixWdirUnsupportedwdiridLookupErrorshortesthexnodeidprefixRepoLookupError)	r   r    r!   hexnode	minlengthrQ   
hexnodelenr}   rV   s	            r$   shortestr4    s    Taq!KLMM'473GI
4y1}G89
	 GW-DT''///J
7|j 	W	#	w<D	11$@D
 NWh/E..tT9eLL ~~ 	N	
 $$ 	-%%,,D   	N	    s<   9D D& 3E+ D#"D#&)E(E('E(+FFs   strip(text[, chars])c                    dt        |      cxk  rdk  s n t        j                  t        d            t	        | ||d         }t        |      dk(  r!t	        | ||d         }|j                  |      S |j                         S )z[Strip characters from a string. By default,
    strips all leading and trailing whitespace.r   r   s"   strip expects one or two argumentsr   )r   r
   r   r   r   r<   )r   r    r!   rf   charss        r$   r<   r<     sv     Taq!FGHHgwQ0D
4yA~7GT!W5zz%  ::<r%   s%   sub(pattern, replacement, expression)c              #     K   t        |      dk7  rt        j                  t        d            t	        | ||d         }t	        | ||d         }t	        | ||d         }	 t        j                  |      }	 |j                  ||       y# t
        j                  $ r" t        j                  t        d      |z        w xY w# t
        j                  $ r" t        j                  t        d      |z        w xY ww)	z8Perform text substitution
    using regular expressions.rb   s   sub expects three argumentsr   r   r   s   sub got an invalid pattern: %ss"   sub got an invalid replacement: %sN)r   r
   r   r   r   r  r  sub)r   r    r!   r  rplr  r  s          r$   r8  r8  '  s      4yA~q!?@AA
WgtAw
/C
WgtAw
/C
WgtAw
/CK

3OiiS!!	 88 Kq!BCcIJJK
 88 Oq!FG#MNNOs0   AC; B 6C 
C;5C  C;5C88C;s   startswith(pattern, text)c                     t        |      dk7  rt        j                  t        d            t	        | ||d         }t	        | ||d         }|j                  |      r|S y)ziReturns the value from the "text" argument
    if it begins with the content from the "pattern" argument.r   s    startswith expects two argumentsr   r   r%   )r   r
   r   r   r   
startswith)r   r    r!   patnrf   s        r$   r;  r;  >  s^     4yA~q!DEFFgwQ0DgwQ0Dtr%   s   subsetparents(rev, revset)s
   rev revsetc                    d|vsd|vrt        j                  t        d            | j                  |d      }t	        j
                  | ||d         }t	        j                  | ||d         }t        |t        j                        st        j                  t        d            |j                  | |      }|j                  }|rJ| j                  |d      }|j                  di       }	||	v r|	|   }
n4t        j                  ||      }
|
|	|<   nt        j                  |||      }
t	        j                  ||
j                  |            S )	z@Look up parents of the rev in the sub graph given by the revset.s   revs   revsets#   subsetparents expects two argumentsr   s&   subsetparents expects a queried revsetrK   s   subsetparentswalker)startrev)r
   r   r   rB   r   rc   rv   rp   r   tovaluer   rO   r   subsetparentswalker
parentsset)r   r    r!   rQ   rS   qsubsetr   rV   walkercachewalkers              r$   subsetparentsrF  M  s8    TYd2q!GHIIGW-D

"
"7GT&\
BC 	  '4	?CAa../q!JKLLYYw(F
**C
  (3&&'=rB+ %F..tV<F%K **4#F  v'8'8'=>>r%   s   word(number, text[, separator])c                    dt        |      cxk  rdk  s,n t        j                  t        d      t        |      z        t	        | ||d   t        d            }t        | ||d         }t        |      dk(  rt        | ||d         }nd}|j                  |      }|t        |      k\  s|t        |       k  ry||   S )	z"Return the nth word from a string.r   rb   s+   word expects two or three arguments, got %dr   s   word expects an integer indexr   Nr%   )r   r
   r   r   rc   r   split)r   r    r!   numrf   splittertokenss          r$   wordrL  t  s     Ta<=D	I
 	
 Q	
*+C gwQ0D
4yA~gwQ8ZZ!F
c&kSCK</c{r%   c                 Z    |j                   j                         D ]  \  }}|t        |<    y)z2Load template function from specified registrarobjN)_tabler3   funcs)rG   extnameregistrarobjr   r   s        r$   loadfunctionrR    s-    "))//1 
ddr%   )Pr)  r  i18nr   r}   r    r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   utilsr   r   r   rv   r+   rt   r   rc   r   r   rO  templatefuncr"   r6   rD   rW   r^   re   ry   r~   r   r   r   rR   r   r   r   r   r   r   r   rE   r   r   r   r   r   r   r   r   r   r   r   r  r  r%  r4  r<   r8  r;  rF  rL  rR  valuesi18nfunctionsr   r%   r$   <module>rY     sA    	      $
 $$
&&&&&&  &&$$
 22  	%y%%e, "#+ $+0 '1BC) D)( 0FE?0 	VX4F$$2 6(3J 4J BCE DE8 )*5 +5. !UG4
' 5
'  GX+>?9 @9$ I0&+	&+R 78E 9E&  6 !6$ 1UGD; E; 5H< I< 4wG< H<'  '(5 )5 ;<5 =5( 125 35  !
2 "
2 #ug6" 7"$ %&@ '@" &'2 (2@ 6  6 6  6 l	 	 +,' -'" %&' ''$ &'$ ($( 12' 3'" '3	 4	 /7H:MNM OM< $%	@ &	@ &'#5 (#5L '> ?& ,7JK) L)X %& ' 67O 8O, *+ , !x 
?
?D 01 28 r%   