
    6h?w                       S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJ	r	  SSK
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJr  SSKJrJr  SSK J!r!  0 r"\RF                  " \"5      r#S	r$S
r%Sr&Sr'Sr(SSSSSS.r)\RT                  " 5       r*0 r+\RX                  " \+5      r,\," SSSS9  \*" S\RZ                  S9S 5       r.\*" S\RZ                  S9S 5       r/\*" S\RZ                  S9S 5       r0SS 0r1S! r2S" r3S# r4 " S$ S%5      r5 " S& S'\R                   5      r6S( r7S) r8\#" S*S+S,S\" S-5      4S.S/S \" S05      \" S15      4/\" S25      S3S49S5 5       r9\#" S6\Rt                  \" S75      S3S89S9 5       r;\#" S:S;S<S\" S=5      4S>S?S\" S@5      4SASBS\" SC5      4/\Rt                  -   \" SD5      S3S89SE 5       r<\#" SF\Rt                  \" SG5      S3S89SH 5       r=SRSI jr>SJ r?SK r@SL rASSSM jrBSN rCSO rDSP rESQ rFg)TaC  expand keywords in tracked files

This extension expands RCS/CVS-like or self-customized $Keywords$ in
tracked text files selected by your configuration.

Keywords are only expanded in local repositories and not stored in the
change history. The mechanism can be regarded as a convenience for the
current user or for archive distribution.

Keywords expand to the changeset data pertaining to the latest change
relative to the working directory parent of each file.

Configuration is done in the [keyword], [keywordset] and [keywordmaps]
sections of hgrc files.

Example::

    [keyword]
    # expand keywords in every python file except those matching "x*"
    **.py =
    x*    = ignore

    [keywordset]
    # prefer svn- over cvs-like default keywordmaps
    svn = True

.. note::

   The more specific you are in your filename patterns the less you
   lose speed in huge repositories.

For [keywordmaps] template mapping and expansion demonstration and
control run :hg:`kwdemo`. See :hg:`help templates` for a list of
available templates and filters.

Three additional date template filters are provided:

:``utcdate``:    "2006/09/18 15:13:13"
:``svnutcdate``: "2006-09-18 15:13:13Z"
:``svnisodate``: "2006-09-18 08:13:13 -700 (Mon, 18 Sep 2006)"

The default template mappings (view with :hg:`kwdemo -d`) can be
replaced with customized keywords and templates. Again, run
:hg:`kwdemo` to control the results of your configuration changes.

Before changing/disabling active keywords, you must run :hg:`kwshrink`
to avoid storing expanded keywords in the change history.

To force expansion after enabling it, or a configuration change, run
:hg:`kwexpand`.

Expansions spanning more than one line and incremental expansions,
like CVS' $Log$, are not supported. A keyword template map "Log =
{desc}" expands to the first line of the changeset description.
    )annotationsN)_)webcommands)cmdutilcontextdispatcherror
extensionsfilelog	localrepo
logcmdutilmatchmergepatchpathutilpycompat	registrarscmutiltemplatefilterstemplateutilutil)dateutil
stringutil)	timestamps   ships-with-hg-coresg   add addremove annotate bundle export grep incoming init log outgoing push tip verify convert email glogz/annotate changeset rev filediff diff comparisonsf   merge kwexpand kwshrink record qrecord resolve transplant unshelve rebase graft backout histedit fetchs   records
   green bolds   cyan bold underlines   greens   bolds   none)s   kwfiles.enableds   kwfiles.deleteds   kwfiles.enabledunknowns   kwfiles.ignoreds   kwfiles.ignoredunknown
   keywordset   svnF)defaults   utcdate)intypec                >    Sn[         R                  " U S   S4U5      $ )z?Date. Returns a UTC-date in this format: "2009/08/18 11:00:13".s   %Y/%m/%d %H:%M:%Sr   r   datestrdate
dateformats     //usr/lib/python3/dist-packages/hgext/keyword.pyutcdater&      s$     &JT!WaL*55    s
   svnisodatec                0    [         R                  " U S5      $ )zUDate. Returns a date in this format: "2009-08-18 13:00:13
+0200 (Tue, 18 Aug 2009)".
s%   %Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)r    )r#   s    r%   
svnisodater)      s    
 D"JKKr'   s
   svnutcdatec                >    Sn[         R                  " U S   S4U5      $ )zADate. Returns a UTC-date in this format: "2009-08-18
11:00:13Z".
s   %Y-%m-%d %H:%M:%SZr   r    r"   s     r%   
svnutcdater+      s$    
 'JT!WaL*55r'      hgcmdr'   c                x    SSS.nSSSSSSS	.S
SSSS
S.4nUR                  X R                  SS5         5        U$ )zBReturns default keywordmaps according to keywordset configuration.s   {node|short}s   {author|user})s   Revisions   Authors   {date|utcdate}s   {file|basename},vs   {root}/{file},vs;   {file|basename},v {node|short} {date|utcdate} {author|user}s9   {root}/{file},v {node|short} {date|utcdate} {author|user})   Dates   RCSfiles   RCSFiles   Source   Ids   Headers   {date|svnisodate}s>   {file|basename},v {node|short} {date|svnutcdate} {author|user})r.   r/   s   LastChangedRevisions   LastChangedBys   LastChangedDater   r   )update
configbool)ui	templateskwsetss      r%   _defaultkwmapsr5      sk     %#I ',,)QS	
 *T$3. 4	
F$ VMM-@ABr'   c                    U" SU 5      $ )zhHelper for keyword expansion removal in text.
Depending on subfunc also returns number of substitutions.s   $\1$ )textsubfuncs     r%   _shrinktextr:      s     8T""r'   c                    U R                    Vs/ s H  o"U;   d  M
  UPM     nnU R                   Vs/ s H  o"U;   d  M
  UPM     nnX44$ s  snf s  snf )zRetrieves modified and added files from a working directory state
and returns the subset of each contained in given changed files
retrieved from a change context.)modifiedadded)wstatuschangedfr<   r=   s        r%   
_preselectrA      sP     #++<+aG|+H<61gQE6? =6s   	A
A
	AAc                      \ rS rSrSrS r\S 5       r\R                  S 5       r
\R                  S 5       r\R                  S 5       rS rS	 rS
 rS rSS jrS rS rS rSrg)kwtemplater   zf
Sets up keyword templates, corresponding keyword regex, and
provides keyword substitution functions.
c                   Xl         [        R                  " U5      U l        [        R                  " UR
                  S/ X45      U l        [        S   [        R                  5       ;   U l	        SU l
        U R                   R                  S5      nU(       a  [        U5      U l        g [        U R                   5      U l        g )Nr'   r,   F   keywordmaps)r2   weakrefref_repor   rootkwtools
restrictedsplitrestrict
postcommitconfigitemsdictr3   r5   )selfr2   repoincexckwmapss         r%   __init__kwtemplater.__init__   s    [[&
[[CS>
)Z-=-=-??$$^4!&\DN+DGG4DNr'   c                "    U R                  5       $ N)rI   rR   s    r%   rS   kwtemplater.repo  s    zz|r'   c                    SR                  [        [        R                  U R                  R                  5       5      5      $ )z+Returns bar-separated and escaped keywords.   |)joinmapr   reescaper3   keysr[   s    r%   escapekwtemplater.escape	  s-     yyZ00$..2E2E2GHIIr'   c                H    [         R                  " SU R                  -  5      $ )z&Returns regex for unexpanded keywords.s   \$(%s)\$recompilerc   r[   s    r%   rekwkwtemplater.rekw  s     zz,455r'   c                H    [         R                  " SU R                  -  5      $ )z$Returns regex for expanded keywords.s   \$(%s): [^$\n\r]*? \$rf   r[   s    r%   rekwexpkwtemplater.rekwexp  s     zz3dkkABBr'   c                (   ^ ^^ UUU 4S jnU" XQ5      $ )z1Replaces keywords in data with expanded template.c                ~  > U R                  S5      n[        R                  " TR                  TR                  TR
                  U   5      nTR                  R                  5         UR                  TTR                  R                  TS9  [        R                  " TR                  R                  5       5      nSX4-  $ )N   )rJ   files	   $%s: %s $)groupr   maketemplaterr2   rS   r3   
pushbuffershowrJ   r   	firstline	popbuffer)mobjkwctekwctxpathrR   s       r%   kwsub%kwtemplater.substitute.<locals>.kwsub  s    AB))DNN2$6B GG GGCdiinn4G8!++DGG,=,=,?@C2)++r'   r7   )rR   datar}   r|   r9   r~   s   ` ``  r%   
substitutekwtemplater.substitute  s    	, u##r'   c                P    U R                   R                  XS9R                  5       $ )z4Similar to filelog.linkrev, but returns a changectx.)fileid)rS   filectx	changectx)rR   r}   r   s      r%   linkctxkwtemplater.linkctx'  s#    yy   5??AAr'   c                    U R                   (       dh  U R                  U5      (       aR  [        R                  " U5      (       d7  U R	                  X5      nU R                  X1X@R                  R                  5      $ U$ )z$Returns data with keywords expanded.)rN   r   r   binaryr   r   ri   sub)rR   r}   noder   r|   s        r%   expandkwtemplater.expand+  sW     

4  %%d++,,t*C??4sIIMMBBr'   c                    U Vs/ s H3  o0R                  U5      (       d  M  SUR                  U5      ;  d  M1  UPM5     sn$ s  snf )zcReturns subset of candidates which are configured for keyword
expansion but are not symbolic links.   l)r   flags)rR   candr|   r@   s       r%   iskwfilekwtemplater.iskwfile6  s5      N4a::a=T15M4NNNs   AAAc                   U R                   (       d  U(       d  U R                  (       a  U R                  X!5      nU(       d  gU R                   =(       a    UnU R                   (       d  U(       a  U(       a  UR                  5       nU R                   (       d  U(       a  U R                  nOU R
                  nU(       a  [        S5      n	O[        S5      n	U R                  S   n
U GHv  nU R                   (       a.  U R                  R                  U5      R                  WU   5      nOU R                  R                  U5      n[        R                  " U5      (       a  M{  U(       a  UR                  5       nU(       a  U R                  UWU   5      nO^U R                   (       aM  [        U5      S:  a>  U H8  nX;   d  M
  X   R!                  X   5      (       a  M&  X   R#                  5       n  O   U R%                  XXR&                  5      u  pO:U R                   (       a  UR)                  U5      nO[+        XR&                  5      u  pU(       d  GMp  U R,                  R/                  X-  5        U R                  R1                  USSS9nUR3                  U5        UR5                  5         U(       an  X   R7                  5       nUR8                  nUR:                  n[<        R>                  " U5      nUUU4nU R                  R@                  RC                  UU5        GM>  U R                  (       d  GMR  U R                  R@                  RE                  USS9  GMy     g)	z7Overwrites selected files expanding/shrinking keywords.Ns"   overwriting %s expanding keywords
s"   overwriting %s shrinking keywords
rp   s   wbT)
atomictemp)
p1_tracked)#rN   rO   r   manifestri   rl   r   rS   rq   readwreadr   r   parentsr   lencmpr   r   subnsearchr:   r2   notewvfswritecloselstatst_modest_sizer   mtime_ofdirstate	set_cleanupdate_file_p1)rR   r|   
candidateslookupr   ri   kwcmdmfre_kwmsgwctxr@   r   r   pfoundfpsmodesizemtime
cache_datas                         r%   	overwritekwtemplater.overwrite;  sN   ==Fdooz7J(&==FvB==DIIELLE:;C:;CyyA}}yy~~a(--be4yyq)  &&++-,,q"Q%0C]]s7|a'7 %6!$((36*:*:"#$.."2C! % #oodsJJGeT*)$

;uSW%YY^^Au^>
A99D99D%..q1E"&e!4JII&&00J?___II&&55aD5IK r'   c                    U R                  U5      (       a:  [        R                  " U5      (       d  [        X R                  R
                  5      $ U$ )z4Returns text with all keyword substitutions removed.)r   r   r   r:   rl   r   )rR   fnamer8   s      r%   shrinkkwtemplater.shrinkt  s;    ::eZ%6%6t%<%<t\\%5%566r'   c                    U R                  U5      (       aZ  SR                  U5      n[        R                  " U5      (       d.  [	        X0R
                  R                  5      R                  S5      $ U$ )z1Returns lines with keyword substitutions removed.r'   T)r   r_   r   r   r:   rl   r   
splitlines)rR   r   linesr8   s       r%   shrinklineskwtemplater.shrinklinesz  sT    ::e88E?D$$T**"4)9)9:EEdKKr'   c                J    U R                   (       a  U R                  X5      $ U$ )zUIf in restricted mode returns data read from wdir with
keyword substitutions removed.)rN   r   )rR   r   r   s      r%   r   kwtemplater.wread  s     ==;;u++r'   )rI   r   rO   rN   r3   r2   NF)__name__
__module____qualname____firstlineno____doc__rW   propertyrS   r   propertycacherc   ri   rl   r   r   r   r   r   r   r   r   __static_attributes__r7   r'   r%   rC   rC      s    
5   
J J 
6 6 
C C$B	O
7Jrr'   rC   c                  T   ^  \ rS rSrSrU 4S jrU 4S jrSU 4S jjrU 4S jrSr	U =r
$ )		kwfilelogi  zz
Subclass of filelog to hook into its read, add, cmp methods.
Keywords are "stored" unexpanded, and processed on reading.
c                <   > [         TU ]  X5        X l        X0l        g rZ   )superrW   kwtr}   )rR   openerr   r}   	__class__s       r%   rW   kwfilelog.__init__  s    &	r'   c                   > [         TU ]  U5      nU R                  U5      (       a  U$ U R                  R	                  U R
                  X5      $ )z&Expands keywords when reading filelog.)r   r   renamedr   r   r}   )rR   r   r   r   s      r%   r   kwfilelog.read  s>    w|D!<<Kxxtyy$55r'   c                r   > U R                   R                  U R                  U5      n[        TU ]  XX4XV5      $ )z5Removes keyword substitutions when adding to filelog.)r   r   r}   r   add)rR   r8   metatrlinkp1p2r   s          r%   r   kwfilelog.add  s.    xxtyy$/w{4r88r'   c                n   > U R                   R                  U R                  U5      n[        TU ]  X5      $ )z-Removes keyword substitutions for comparison.)r   r   r}   r   r   )rR   r   r8   r   s      r%   r   kwfilelog.cmp  s*    xxtyy$/w{4&&r'   )r   r}   )NN)r   r   r   r   r   rW   r   r   r   r   __classcell__)r   s   @r%   r   r     s!    

69
' 'r'   r   c           	     z   U(       aa  UR                  [        R                  " X$[        R                  " U5      5      SUR                  S5      =(       d    UR                  S5      S9$ U R                  S5      (       a  [        R                  " [        S5      5      e[        R                  " [        S5      5      e)zXBails out if [keyword] configuration is not active.
Returns status of working directory.Tunknownall)r   cleanr      keywords   [keyword] patterns cannot matchs    no [keyword] patterns configured)
statusr   r   r   byteskwargsgetrP   r	   Abortr   )r2   rS   r   r   patsoptss         r%   _statusr     s     {{--H,@,@,FGHHY':488E?  
 	

 
~~j!!kk!>?@@
++a;<
==r'   c                ~   US   n[        UR                  5       5      S:  a  [        R                  " [	        S5      5      e[        USS5      nUR                  5          UR                  R                  U5         [        XXV/UQ70 UD6nUR                  (       d3  UR                  (       d"  UR                  (       d  UR                  (       a  [        R                  " [	        S5      5      eUR                  XWR                  SU5        SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       g= f)z7Selects files and passes them to kwtemplater.overwrite.Nrp   s   outstanding uncommitted merge_keywordkwts   outstanding uncommitted changesT)r   r   r	   r   r   getattrwlockr   changing_filesr   r<   r=   removeddeletedr   r   )r2   rS   r   r   r   r   r   r   s           r%   	_kwfwriter     s    :D
4<<>Qkk!<=>>
$t
,C	t}}33D94<t<t<??fllfnn++a BCDDdLL$7	 :99s%   D.;BDD.
D+	'D..
D<s   kwdemo   ds   defaults"   show default keyword template maps   f   rcfiles   read maps from rcfiles   FILEs+   hg kwdemo [-d] [-f RCFILE] [TEMPLATEMAP]...T)optionalrepoc                
  ^  U 4S jnSn[         R                  " SS5      nT R                  [        S5      U-  5        Uc  T nOUR                  n[
        R                  " XvSS9nT R                  S	USS	5        T R                  S
S5      nT R                  S
SUS	5        T R                  S5      n	U(       d  UR                  S5      (       GaF  T R                  [        S5      5        U	(       a  T R                  [        S5      5        UR                  S5      (       d  U	(       d<  U(       a  T R                  [        S5      5        OT R                  [        S5      5        UR                  S5      (       a   T R                  UR                  S5      5        U(       aZ  SSR                  U5      -  n
UR                  R                  SU
5        T R                  UR                  R                  S5      5        [!        T R                  S5      5      nOUR                  S5      (       a  U(       a  T R                  [        S5      5        OT R                  [        S5      5        [#        T 5      nU	(       aF  T R                  [        S5      5        UR%                  5        H  u  pT R                  SXS	5        M     O8T R                  [        S5      5        U	(       a  [!        U	5      nO[#        T 5      n['        T 5        [)        T U5        T R+                  S5        U" S	T R                  S	5      5        U" S
T R                  S
5      5        U" SUR%                  5       5        SSR                  [-        UR/                  5       5      5      -   S-   nUR0                  R                  X^5        UR3                  5          UR4                  R7                  U5         US   R9                  U/5        SSS5        T R                  [        S5      U-  5        T R                  U5        UR4                  R;                  S UR=                  5       5        T R                  S!5       HN  u  nnUR?                  S"S#5      S$   RA                  S%5      S&:  d  M0  URB                  R                  S!USS	5        MP     [        S'5      nT RE                  S(U-  5        URG                  US)9  SSS5        T R                  [        S*5      5        T R                  URI                  U5      5        UR0                  RK                  URL                  5        g! , (       d  f       GN`= f! , (       d  f       N= f)+az  print [keywordmaps] configuration and an expansion example

Show current, custom, or default keyword template maps and their
expansions.

Extend the current configuration by specifying maps as arguments
and using -f/--rcfile to source an external hgrc file.

Use -d/--default to disable current configuration.

See :hg:`help templates` for information on templates and filters.
c                   > TR                  SU -  5        [        U5       HE  u  p#[        U[        5      (       a  [        R
                  " U5      nTR                  SX#4-  5        MG     g )Ns   [%s]
s   %s = %s
)r   sorted
isinstanceboolr   pprint)sectionitemskvr2   s       r%   	demoitemsdemo.<locals>.demoitems  sT    
W$%5MDA!T""%%a(HH\QF*+ "r'   s   demo.txtr'   s   kwdemo.s$   creating temporary repository at %s
NT)creater   r   r   rF   rcfiles3   
	configuration using custom keyword template maps
s!   	extending current template maps
r   s#   	overriding default svn keywordset
s#   	overriding default cvs keywordset
r   s   [keywordmaps]
%s
   
s   hgrcs-   
	configuration using default svn keywordset
s-   
	configuration using default cvs keywordset
s!   	disabling current template maps
s4   
	configuration using current keyword template maps
s   [extensions]
keyword =
   $s   $
$s   $
s   
keywords written to %s:
s
   demobranchs   hooks   .rp   r   s   commits.   hg keyword configuration and expansion examples   hg ci -m '%s'
)r8   s   
	keywords expanded
)'r   mkdtempr   r   baseuir   instance	setconfigr1   rP   r   r   
readconfigr_   vfsr   rQ   r5   r  uisetup	reposetupwritenoi18nr   rb   r   r   r   r   r   	setbranchcurrenttransactionrM   findr2   
notenoi18ncommitr   rmtreerJ   )r2   rS   argsr   r  fntmpdirr  svnuikwmapsrcmapsrV   r  r  keywordsnamecmdr   s   `                 r%   demor(    s   ., 
Bc:.FGGA67&@A|fT:DLLRj1
--v
.CLLZ8~~n-Htxx!!
		!MNOIIa>?@88Ih		!DEF		!DEF88HMM$((9-.+ejj.>>FHHNN7F+MM$((--01bnn^45	)		IIaKLMIIaKLM#IIa>?@^Q:> ' 			!NOP(^F#B'FBKb$NN/0j"..45mR^^M:;nflln-gll6&++-#899FBHIIOOB!	]]))$/JNNB4  0
01B67
t/F/F/HI1ID#zz$"1%**95:!!(D#zB 2 AB
(3./ 
 IIa*+,HHTZZ^IITYY 0/ 
s,   ?UU
1BUAU

U	U
U*s   kwexpands!   hg kwexpand [OPTION]... [FILE]...)	inferrepoc                $    [        XS/UQ70 UD6  g)zexpand keywords in the working directory

Run after (re)enabling keyword expansion.

kwexpand refuses to run if given files contain local changes.
TNr   r2   rS   r   r   s       r%   r   r   )  s     b,t,t,r'      kwfiles   As   alls&   show keyword status flags of all files   i   ignores"   show files excluded from expansion   us   unknowns%   only show unknown (not tracked) filess    hg kwfiles [OPTION]... [FILE]...c           
        [        USS5      nUS   n[        XXT/UQ70 UD6nU(       a  UR                  5       nOSn/ nUR                  S5      (       a  UR                  S5      (       a/  [	        UR
                  UR                  -   UR                  -   5      nUR                  X5      n	UR                  UR                  U5      n
UR                  UR                  U5      nUR                  S5      (       a  UR                  S5      (       a  XU4nO/ / / 4nUR                  S5      (       d  UR                  S5      (       aA  UU Vs/ s H  oU	;  d  M
  UPM     snUR                   Vs/ s H  oU;  d  M
  UPM     sn4-  nSR                  5       n[        U[        R                  " S5      U5      nU R                  S	[        R                   " U5      5      nS
nUR                  S5      (       d  U R"                  (       a  SnU HY  u  nnnSU-   nU HG  nUR%                  5         UR'                  UUS9  UR)                  UUUR+                  X5      4-  US9  MI     M[     UR-                  5         gs  snf s  snf )aG  show files configured for keyword expansion

List which files in the working directory are matched by the
[keyword] configuration patterns.

Useful to prevent inadvertent keyword expansion and to speed up
execution by including only files that are actual candidates for
expansion.

See :hg:`help keyword` on how to construct patterns both for
inclusion and exclusion of files.

With -A/--all and -v/--verbose the codes used to show the status
of files are::

  K = keyword expansion candidate
  k = keyword expansion candidate (not tracked)
  I = ignored
  i = ignored (not tracked)
r   Nr'   r   r   ignores5   enabled deleted enabledunknown ignored ignoredunknowns   K!kIir-  s   %.0s%s
s   %s %s
s   kwfiles.)kwstatusr}   )label)r   r   getcwdr   r   r<   r=   r   r   r   r   rM   zipr   bytestr	formatterr   verbose	startitemr   plainpathtoend)r2   rS   r   r   r   r   r   cwdfileskwfiles	kwdeleted	kwunknown	showfilesr@   kwlabelskwstatesfmfmtkwstatechar	filenamesr5  s                         r%   r@  r@  :  s   @ $t
,C:DRt84848FkkmE88I$((5//v5DEll5'GV^^T2IV^^T2I88H%	1	BJ	xx$((8,,21'!1Q2=19*<Q=
 	
	 HMMOH8X--h7CH	j("6"6t"<	=B
Cxx"**$, yg%ALLNGGTG*HHSD$++a"566eHD  %- FFH 3=s   
	I8I8-	I=:I=s   kwshrinks!   hg kwshrink [OPTION]... [FILE]...c                $    [        XS/UQ70 UD6  g)zrevert expanded keywords in the working directory

Must be run before changing/disabling active keywords.

kwshrink refuses to run if given files contain local changes.
FNr+  r,  s       r%   r   r     s     b---r'   c                    U " XX4XV5        [        [        USS5      SS5      nU(       a,  UR                  UR                  UR                  5      Ul        gg)zpMonkeypatch/wrap patch.patchfile.__init__ to avoid
rejects or conflicts due to expanded keywords in working dir.rS   Nr   )r   r   r   r   )origrR   r2   gpbackendstoreeolmoder   s           r%   kwpatchfile_initrS    sI     	2/
''640-
FC
__TZZ<
 r'   c              /     #    [        USS5      nU(       a  UR                  nSUl         U " U/UQ70 UD6 Sh  vN   U(       a  WUl        gg N! U(       a  WUl        f f = f7f)z*Monkeypatch patch.diff to avoid expansion.r   NT)r   rN   )rN  rS   r  kwargsr   rN   s         r%   kwdiffrV    sg     
$t
,C
<<$.t.v...#CL  	/#CL s+   (A%A AA A%A A""A%c              #     #    [        UR                  SS5      nU(       a!  UR                  n[        R                  Ul         U " U5       Sh  vN   U(       a  WUl        gg N! U(       a  WUl        f f = f7f)z2Wraps webcommands.x turning off keyword expansion.r   N)r   rS   r   r   never)rN  webr   	origmatchs       r%   
kwweb_skipr[    sd     
#((M4
0C
II	JJ	"9!CI  	!CI s0   A A9A% A#A% A9#A% %A66A9c           
        [        USS5      nUc
  U " XX4XV5      $ UR                  5          UR                  R                  U5         SUl        U " XX4XV5      nXR                  5       :w  a3  X(   n	SUl        UR                  XR                  5       SS5        SUl        UsSSS5        sSSS5        $ ! , (       d  f       O= fSSS5        g! , (       d  f       g= f)z3Wraps cmdutil.amend expanding keywords after amend.r   NTF)	r   r   r   changing_parentsrO   r   rN   r   r@  )
rN  r2   rS   oldextrar   r   r   newidr|   s
             r%   kw_amendra    s    
$t
,C
{Bc$55	t}}55d;Rs46HHJ+CCLMM#yy{E48 CL <;;;s$   CAB3 	C3
C	=C
Cc                  ^^	^
^ [        TSS5      m
T
c  U " UTX4U5      $ TR                  5          U " UTX4U5        UR                  S5      (       a
   SSS5        gTS   mTR                  5       m	U	U
UU4S jnTR                  R                  5        Vs/ s H+  nSTR                  U5      ;  d  M  U" U5      (       d  M)  UPM-     nnT
R                  TUSS5        SSS5        gs  snf ! , (       d  f       g= f)a  Wraps cmdutil.copy so that copy/rename destinations do not
contain expanded keywords.
Note that the source of a regular file destination may also be a
symlink:
hg cp sym x                -> x is symlink
cp sym x; hg cp -A sym x   -> x is file (maybe expanded keywords)
For the latter we have to follow the symlink to find out whether its
target is configured for expansion and we therefore must unexpand the
keywords in the destination.r   Ns   dry_runc                  > TR                   R                  U 5      nSTR                  U5      ;   a?  [        R                  " TR
                  T[        R                  R                  U5      5      nTR                  U5      $ )zReturns true if dest is a regular file and configured for
expansion or a symlink which points to a file configured for
expansion.r   )
r   copiedr   r   	canonpathrJ   osr}   realpathr   )destsourcer?  r   rS   r   s     r%   haskwsourcekw_copy.<locals>.haskwsource  se     ]]))$/Ftzz&))!++IIsBGG$4$4V$< 99V$$r'   r   F)r   r   r   r6  r   copiesr   r   )rN  r2   rS   r   r   renamerj  r@   r   r?  r   r   s     `      @@@r%   kw_copyrn    s     $t
,C
{Bd&11	Rt6*88J 
 Dzkkm		% 		% ]]))+
+4::a=( -8^ + 	 

 	dJu5/ 
$
% 
s/   #C,:C,C'3C'C'C,'C,,
C:c           	        [        USS5      nUc  U " XU/UQ70 UD6$ UR                  5          SUl        US   nUR                  5       nU " XU/UQ70 UD6n	US   n
Xz:w  at  [	        XR                  5       5      u  pSUl        UR                  R                  U5         UR                  XSS5        UR                  XSSS5        SSS5        SUl        U	sSSS5        $ ! , (       d  f       N = f! , (       d  f       g= f)z9Wraps record.dorecord expanding keywords after recording.r   NTr  F)
r   r   rO   r   rA   r@  rN   r   r]  r   )rN  r2   rS   
commitfuncr   r   r   r|   r>   retrecctxr<   r=   s                r%   kw_dorecordrs    s    
$t
,C
{Bj848488	 4j**,2Z7$7$7d=(,,.AOH CL//5ft<fUD$? 6  CL 
 65 
s$   A1C2(C!C2!
C/	+C22
D c                B   UR                   (       a  UR                  U5      $ [        UR                  SS 5      nUc  U " X5      $ UR                  cx  UR                  R
                  (       d  UR                  UR                  5       5      (       a  SUR                  5       ;  dG  UR                  5       S-
  UR                  5       :X  d"  UR                  5       UR                  5       :X  a4  UR                  R                  UR                  UR                  5       5      $ g)Nr   r      T)
_customcmpr   r   rI   	_filenode_encodefilterpatsr   r}   r   r   _filelogr   )rN  rR   fctxr   s       r%   kwfilectx_cmpr{    s    xx~
$**mT
2C
{D 	JJ((yy%%DJJL(yy{Q$))+-99;$))+%}}  ==r'   c                v   S n[         R                  " [        SU5        [         R                  " [        R                  S[
        5        [         R                  " [        R                  S[        5        [         R                  " [        S[        5        [         R                  " [        S[        5        [         R                  " [        S[        5        [         R                  " [        S[        5        [        R                  5        H#  n[         R                  " [         U["        5        M%     S	[$        l        g
)a  Monkeypatches dispatch._parse to retrieve user command.
Overrides file method to return kwfilelog instead of filelog
if file matches user configuration.
Wraps commit to overwrite configured files with updated
keyword substitutions.
Monkeypatches patch and webcommands.c                6    U " X5      u  p4p%nU[         S'   X4X%U4$ )z9Monkeypatch dispatch._parse to obtain running hg command.r,   )rK   )rN  r2   r  r'  funcoptions
cmdoptionss          r%   kwdispatch_parse!uisetup.<locals>.kwdispatch_parse$  s)    /3B~,4*$33r'   _parser   rW   diffamendcopydorecordFN)r
   wrapfunctionr   r   r   r{  r   	patchfilerS  rV  r   ra  rn  rs  nokwwebcommandsrM   r   r[  r   MAYBE_USE_RUST_UPDATE)r2   r  cs      r%   r  r    s    4 Hh0@AGOOUMBEOOZ9IJE662GWh7GVW5GZ=""$Q
; %"'Er'   c                  ^  UR                  5       (       ac  [        S   [        R                  5       ;   dD  S[        R
                  " UR                  5      ;   d   UR                  R                  S5      (       a  g / S/p2U R                  S5       H/  u  pEUS:w  a  UR                  U5        M  UR                  U5        M1     U(       d  g[        XX#5      m " U4S jS	UR                  5      nXal        TUl        g! [         a     Nf = f)
z0Sets up repo as kwrepo for keyword substitution.r,   s   .hgs   bundle:Ns   .hg*r   r0  c                  h   >^  \ rS rSrU4S jrU U4S jrU 4S jrSU U4S jjrS	U U4S jjrSr	U =r
$ )
reposetup.<locals>.kwrepoiP  c                N   > US   S:X  a  USS  n[        U R                  TU5      $ )Nr      /rp   )r   svfs)rR   r@   r   s     r%   rq   reposetup.<locals>.kwrepo.fileQ  s,    tt|abETYYQ//r'   c                D   > [         TU ]  U5      nTR                  X5      $ rZ   )r   r   )rR   filenamer   r   r   s      r%   r   reposetup.<locals>.kwrepo.wreadV  s     7=*D99X,,r'   c                Z   > U R                   U l         [        TU ]  " U0 UD6U ?$ ! U ?f = frZ   )kwcommitctx	commitctxr   r  )rR   r  r   r   s      r%   r   reposetup.<locals>.kwrepo.commitZ  s3     "--DN#w~t4t4NDNs   & *c                   > [         TU ]  XU5      nTR                  (       dX  TR                  nSTl        TR	                  X   [        UR                  5       UR                  5       -   5      SS5        UTl        U$ )NTF)r   r  rO   rN   r   r   r=   r<   )rR   r|   r	   origctxnrN   r   r   s         r%   r  %reposetup.<locals>.kwrepo.kwcommitctxc  sf    !#g6A>><<#GVCIIK#,,.$@A5$  (Hr'   c                  > U R                  5          T
R                  n U(       d  U S   R                  5       n[        T	U ]  X5      nU(       dN  U S   n[        UR                  5       W5      u  pxST
l        T
R                  XgSS5        T
R                  XhSS5        UUT
l        sS S S 5        $ ! UT
l        f = f! , (       d  f       g = f)Nr  FT)r   rN   r@  r   rollbackrA   r   r   )rR   dryrunforceorigrestrictr?   rq  r|   r<   r=   r   r   s            r%   r  "reposetup.<locals>.kwrepo.rollbacko  s    "||0!"&t*"2"2"4'*69C!"4j*4SZZ\7*K',cT4@c$>#/CL  $0CL s#   B<A?B0B<0	B99B<<
C
)r  )FN)FF)r   r   r   r   rq   r   r  r  r  r   r   )r   r   s   @r%   kwrepor  P  s&    	0
	-	#
	 
		0 	0r'   r  )localrK   nokwcommandsrM   r   	splitpathrJ   _url
startswithAttributeErrorrP   appendrC   r   r   )r2   rS   rT   rU   patoptr  r   s          @r%   r  r  7  s    	

x L$6$6$88		22yy##J// 0 G9NN:.)JJsOJJsO	 /
 
b
)C.0 .0` ND  s   A8C? ?
DDrZ   r   )Gr   
__future__r   rf  rg   rG   mercurial.i18nr   mercurial.hgwebr   	mercurialr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   mercurial.utilsr   r   mercurial.dirstateutilsr   cmdtablecommand
testedwithr  r  rL   recordextensions
colortabletemplatefilterconfigtable
configitemr#   r&   r)   r+   rK   r5   r:   rA   rC   r   r   r   r(  walkoptsr   r@  r   rS  rV  r[  ra  rn  rs  r{  r  r  r7   r'   r%   <module>r     s  :6r # 	 	   '    ( .


H
%
 #
4  D
5    &.'&
 ))+!!+.
 

 
<#4#456 66 l&7&78L 9L l&7&786 96 S/8#U Up' ':>
8 		z4#H!IJ	y#q!9:AgJG 45[ [ | 	*+	-- 		vtQHIJ	y$"G HI	z4#K!LM
  )*
8
8v 	*+	..=
$
" $6N.,(6Jr'   