
    	^c7w                     b   d Z ddlZddlZddlZddlm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mZ ddlmZmZ ddlm Z  i Z! ej"        e!          Z"d	Z#d
Z$dZ%dZ&dZ'ddddddZ( ej)                    Z)i Z* ej+        e*          Z+ e+ddd            e)dej,                  d             Z- e)dej,                  d             Z. e)dej,                  d             Z/dd iZ0d! Z1d" Z2d# Z3 G d$ d%          Z4 G d& d'ej                  Z5d( Z6d) Z7 e"d*d+d,d ed-          fd.d/d  ed0           ed1          fg ed2          d34          d5             Z8 e"d6ej9         ed7          d38          d9             Z: e"d:d;d<d ed=          fd>d?d ed@          fdAdBd edC          fgej9        z    edD          d38          dE             Z; e"dFej9         edG          d38          dH             Z<dRdIZ=dJ Z>dK Z?dL Z@dSdMZAdN ZBdO ZCdP ZDdQ ZEdS )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.
    N)_)getattr)webcommands)cmdutilcontextdispatcherror
extensionsfilelog	localrepo
logcmdutilmatch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 glogs/   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                 @    d}t          j        | d         df|          S )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5    s
   svnisodatec                 ,    t          j        | d          S )z]Date. 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KKr&   s
   svnutcdatec                 @    d}t          j        | d         df|          S )zIDate. 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55r&      hgcmdr&   c                     ddd}ddddddd	d
dddd
df}|                     ||                     dd                              |S )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$   _defaultkwmapsr4      s     %# I ',,)QS	
 	
 *T$3. 4	
 	
F$ VBMM-@@ABBBr&   c                      |d|           S )zlHelper for keyword expansion removal in text.
    Depending on subfunc also returns number of substitutions.s   $\1$ )textsubfuncs     r$   _shrinktextr9      s     78T"""r&   c                 X    fd| j         D             }fd| j        D             }||fS )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.c                     g | ]}|v |	S r6   r6   .0fchangeds     r$   
<listcomp>z_preselect.<locals>.<listcomp>   s    <<<aqG|||||r&   c                     g | ]}|v |	S r6   r6   r<   s     r$   r@   z_preselect.<locals>.<listcomp>   s    6661gQr&   )modifiedadded)wstatusr?   rB   rC   s    `  r$   
_preselectrE      sF     =<<<7+<<<H6666666EU?r&   c                       e Zd ZdZd Zed             Zej        d             Z	ej        d             Z
ej        d             Zd Zd Zd	 Zd
 ZddZd Zd Zd ZdS )kwtemplaterzr
    Sets up keyword templates, corresponding keyword regex, and
    provides keyword substitution functions.
    c                    || _         t          j        |          | _        t	          j        |j        dg ||          | _        t          d         t                                          v | _	        d| _
        | j                             d          }|rt          |          | _        d S t          | j                   | _        d S )Nr&   r+   F   keywordmaps)r1   weakrefref_repor   rootkwtools
restrictedsplitrestrict
postcommitconfigitemsdictr2   r4   )selfr1   repoincexckwmapss         r$   __init__zkwtemplater.__init__   s    [&&
[CS#>>
)Z-=-=-?-??$$^44 	5!&\\DNNN+DG44DNNNr&   c                 *    |                                  S N)rL   rU   s    r$   rV   zkwtemplater.repo  s    zz||r&   c                     d                     t          t          j        | j                                                            S )z+Returns bar-separated and escaped keywords.   |)joinmapr   reescaper2   keysr]   s    r$   escapezkwtemplater.escape  s1     yyZ0$.2E2E2G2GHHIIIr&   c                 :    t          j        d| j        z            S )z&Returns regex for unexpanded keywords.s   \$(%s)\$recompilerd   r]   s    r$   rekwzkwtemplater.rekw
  s     z,4555r&   c                 :    t          j        d| j        z            S )z$Returns regex for expanded keywords.s   \$(%s): [^$\n\r]*? \$rf   r]   s    r$   rekwexpzkwtemplater.rekwexp  s     z3dkABBBr&   c                 .      fd} |||          S )z1Replaces keywords in data with expanded template.c                 ^   |                      d          }t          j        j        j        j        |                   }j                                         |                    j        j                   t          j
        j                                                  }d||fz  S )N   )rM   files	   $%s: %s $)groupr   maketemplaterr1   rV   r2   
pushbuffershowrM   r   	firstline	popbuffer)mobjkwctekwctxpathrU   s       r$   kwsubz%kwtemplater.substitute.<locals>.kwsub  s    AB)DN2$6 B G   GGCdin4G888!+DG,=,=,?,?@@C2s)++r&   r6   )rU   datar{   rz   r8   r|   s   ` ``  r$   
substitutezkwtemplater.substitute  s<    	, 	, 	, 	, 	, 	, 	, wud###r&   c                 ^    | j                             ||                                          S )z4Similar to filelog.linkrev, but returns a changectx.)fileid)rV   filectx	changectx)rU   r{   r   s      r$   linkctxzkwtemplater.linkctx#  s)    y  f 55??AAAr&   c                     | j         sa|                     |          rLt          j        |          s8|                     ||          }|                     |||| j        j                  S |S )z$Returns data with keywords expanded.)rQ   r   r   binaryr   r~   ri   sub)rU   r{   noder}   rz   s        r$   expandzkwtemplater.expand'  sp     	C

4  	C %d++	C
 ,,tT**C??4sDIMBBBr&   c                 $      fd|D             S )zkReturns subset of candidates which are configured for keyword
        expansion but are not symbolic links.c                 l    g | ]0}                     |          d                     |          v.|1S    l)r   flags)r=   r>   rz   rU   s     r$   r@   z(kwtemplater.iskwfile.<locals>.<listcomp>5  s<    NNNa4::a==NT15M5M5M5M5Mr&   r6   )rU   candrz   s   ` `r$   iskwfilezkwtemplater.iskwfile2  s$     ONNNN4NNNNr&   Fc                    | j         s	|s| j        r|                     ||          }|sdS | j         o|}| j         s|r|r|                                }| j         s|r| j        }n| j        }|rt          d          }	nt          d          }	| j        d         }
|D ]J}| j         r4| j                            |          	                    ||                   }n| j        
                    |          }t          j        |          rm|r|                                }|r|                     |||                   }n`| j         rYt          |          dk    rF|D ]C}||v r=||                             ||                   s||                                         } nD|                     ||||j                  \  }}n5| j         r|                    |          }nt+          ||j                  \  }}|r| j                            |	|z             | j                            |dd          }|                    |           |                                 |rc|
|                                         }|j        }|j        }t=          j        |          }|||f}| j        j         !                    ||           "| j        r!| j        j         "                    |d           LdS )	z7Overwrites selected files expanding/shrinking keywords.Ns"   overwriting %s expanding keywords
s"   overwriting %s shrinking keywords
rn   s   wbT)
atomictemp)
p1_tracked)#rQ   rR   r   manifestri   rk   r   rV   ro   readwreadr   r   parentsr   lencmpr   r~   subnsearchr9   r1   notewvfswritecloselstatst_modest_sizer   mtime_ofdirstate	set_cleanupdate_file_p1)rU   rz   
candidateslookupr   ri   kwcmdmfre_kwmsgwctxr>   r}   r   pfoundfpsmodesizemtime
cache_datas                         r$   	overwritezkwtemplater.overwrite7  s   = 	8F 	8do 	8z377J 	F(&= 	 F 	 v 	 B= 	!D 	!IEELE 	<:;;CC:;;Cy %	J %	JA} *y~~a((--be44yq)) &&  <++-- 	",,q"Q%00CC] "s7||a'7'7 % " "66!A$((3q6*:*:6"#A$.."2"2C!E"oodAsEJGGee <T**)$
;;e JS1W%%%Y^^Au^>>


 JQA9D9D%.q11E"&e!4JI&00J????_ JI&55aD5IIIK%	J %	Jr&   c                     |                      |          r.t          j        |          st          || j        j                  S |S )z4Returns text with all keyword substitutions removed.)r   r   r   r9   rk   r   )rU   fnamer7   s      r$   shrinkzkwtemplater.shrinkp  sB    ::e 	7Z%6t%<%< 	7tT\%5666r&   c                     |                      |          rVd                    |          }t          j        |          s-t	          || j        j                                      d          S |S )z1Returns lines with keyword substitutions removed.r&   T)r   r`   r   r   r9   rk   r   
splitlines)rU   r   linesr7   s       r$   shrinklineszkwtemplater.shrinklinesv  sb    ::e 	L88E??D$T** L"4)9::EEdKKKr&   c                 @    | j         r|                     ||          S |S )z]If in restricted mode returns data read from wdir with
        keyword substitutions removed.)rQ   r   )rU   r   r}   s      r$   r   zkwtemplater.wread~  s'     = 	,;;ud+++r&   NF)__name__
__module____qualname____doc__rZ   propertyrV   r   propertycacherd   ri   rk   r~   r   r   r   r   r   r   r   r6   r&   r$   rG   rG      s3        
5 5 5   X 
J J J 
6 6 6 
C C C$ $ $B B B	 	 	O O O
7J 7J 7J 7Jr        r&   rG   c                   B     e Zd ZdZ fdZ fdZd fd	Z fdZ xZS )	kwfilelogz
    Subclass of filelog to hook into its read, add, cmp methods.
    Keywords are "stored" unexpanded, and processed on reading.
    c                 v    t          t          |                               ||           || _        || _        d S r\   )superr   rZ   kwtr{   )rU   openerr   r{   	__class__s       r$   rZ   zkwfilelog.__init__  s5    i''555			r&   c                     t          t          |                               |          }|                     |          r|S | j                            | j        ||          S )z&Expands keywords when reading filelog.)r   r   r   renamedr   r   r{   )rU   r   r}   r   s      r$   r   zkwfilelog.read  sS    Y%%**400<< 	Kxty$555r&   Nc                     | j                             | j        |          }t          t          |                               ||||||          S )z5Removes keyword substitutions when adding to filelog.)r   r   r{   r   r   add)rU   r7   metatrlinkp1p2r   s          r$   r   zkwfilelog.add  sB    xty$//Y%%))$b$BGGGr&   c                     | j                             | j        |          }t          t          |                               ||          S )z-Removes keyword substitutions for comparison.)r   r   r{   r   r   r   )rU   r   r7   r   s      r$   r   zkwfilelog.cmp  s:    xty$//Y%%))$555r&   )NN)	r   r   r   r   rZ   r   r   r   __classcell__)r   s   @r$   r   r     s         
    
6 6 6 6 6H H H H H H
6 6 6 6 6 6 6 6 6r&   r   c                    |rht          j        |          }|                    t          j        |||          d|                    d          p|                    d                    S |                     d          r!t          j        t          d                    t          j        t          d                    )z\Bails out if [keyword] configuration is not active.
    Returns status of working directory.T   unknown   all)r   cleanunknown   keywords   [keyword] patterns cannot matchs    no [keyword] patterns configured)
r   byteskwargsstatusr   r   getrS   r	   Abortr   )r1   rV   r   r   patsoptss         r$   _statusr     s      
#D)){{-dD11HHZ((<DHHV,<,<  
 
 	

 
~~j!! Ak!>??@@@
+a;<<
=
==r&   c                    |d         }t          |                                          dk    r!t          j        t	          d                    t          |dd          }|                                5  t          | |||g|R i |}|j        s|j	        s|j
        s|j        r!t          j        t	          d                    |                    ||j        d|           ddd           dS # 1 swxY w Y   dS )z7Selects files and passes them to kwtemplater.overwrite.Nrn   s   outstanding uncommitted merge_keywordkwts   outstanding uncommitted changesT)r   r   r	   r   r   r   wlockr   rB   rC   removeddeletedr   r   )r1   rV   r   r   r   r   r   r   s           r$   	_kwfwriter     sA   :D
4<<>>Qk!<==>>>
$t
,
,C	 8 8T4<t<<<t<<? 	Efl 	Efn 	E 	E+a BCCDDDdFL$777	8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8s   4A.C//C36C3s   kwdemo   ds   defaults"   show default keyword template maps   f   rcfiles   read maps from rcfiles   FILEs+   hg kwdemo [-d] [-f RCFILE] [TEMPLATEMAP]...T)optionalrepoc                      fd}d}t          j        dd          }                     t          d          |z             | }n|j        }t          j        ||d          }                     d	|dd	                                d
d          }                     d
d|d	            	                    d          }	|s|
                    d          rg                     t          d                     |	r"                     t          d                     |
                    d          s|	sG|r#                     t          d                     n"                     t          d                     |
                    d          r(                     |
                    d                     |r`dd                    |          z  }
|j                            d|
                                |j                            d                     t!           	                    d                    }n|
                    d          r|r#                     t          d                     n"                     t          d                     t#                     }|	rT                     t          d                     |                                D ]\  }}                     d||d	           nC                     t          d                     |	rt!          |	          }nt#                     }t'                      t)           |                                d            |d	 	                    d	                      |d
 	                    d
                      |d|                                           dd                    t-          |                                                    z   dz   }|j                            ||           |d                             |g                                t          d          |z                                  |           |                                5  |j                            d            ddd           n# 1 swxY w Y    	                    d!          D ]U\  }}|                    d"d#          d$                             d%          d&k    r|j                            d!|dd	           Vt          d'          }                     d(|z             |                     |)                                t          d*                                          |!                    |                     |j        "                    |j#                   dS )+a  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                                          d| z             t          |          D ]H\  }}t          |t                    rt	          j        |          }                     d||fz             Id S )Ns   [%s]
s   %s = %s
)r   sorted
isinstanceboolr   pprint)sectionitemskvr1   s       r$   	demoitemszdemo.<locals>.demoitems  s}    
W$%%%5MM 	, 	,DAq!T"" )%a((HH\QF*++++	, 	,r&   s   demo.txtr&   s   kwdemo.s$   creating temporary repository at %s
NT)creater   r   r   rI   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   .rn   r   s   commits.   hg keyword configuration and expansion examples   hg ci -m '%s'
)r7   s   
	keywords expanded
)$r   mkdtempr   r   baseuir   instance	setconfigr0   rS   r   r   
readconfigr`   vfsr   rT   r4   r   uisetup	reposetupwritenoi18nr   rc   r   r   r   r   	setbranchrP   findr1   commitr   rmtreerM   )r1   rV   argsr   r   fntmpdirr   svnuikwmapsrcmapsrY   r   r   keywordsnamecmdr   s   `                 r$   demor    s   ., , , , , 
Bc:..FGGA677&@AAA|ffT:::DLLRj111
--v
.
.CLLZ888~~n--H  (txx!!  (
		!MNNOOO 	AIIa>??@@@88I 	Gh 	G G		!DEEFFFF		!DEEFFF88H 	/MM$((9--... 	2+ejj.>.>>FHNN7F+++MM$(--00111bnn^4455	)		 ( 	NIIaKLLMMMMIIaKLLMMM## 	?IIa>??@@@ ? ?1^Q:>>>>
		!NOOPPP 	((^^FF#B''FBKKKb$NN/000Ij"..44555ImR^^M::;;;Infllnn---gll6&++--#8#8999FBHIOOB!!!JNNB4GGA,--2333GGH	 / /.../ / / / / / / / / / / / / / /^^H-- ? ?	c::dAq!&&y11B66Ghc:>>>
=
>
>CGG#%'''KKSKIIa*++,,,HHTZZ^^ITYs   R;;R?R?s   kwexpands!   hg kwexpand [OPTION]... [FILE]...)	inferrepoc                 *    t          | |dg|R i | dS )zexpand keywords in the working directory

    Run after (re)enabling keyword expansion.

    kwexpand refuses to run if given files contain local changes.
    TNr   r1   rV   r   r   s       r$   r   r   %  s,     b$,t,,,t,,,,,r&      kwfiles   Ar   s&   show keyword status flags of all files   i   ignores"   show files excluded from expansion   ur   s%   only show unknown (not tracked) filess    hg kwfiles [OPTION]... [FILE]...c           
         t          |dd          }|d         }t          | |||g|R i |}|r|                                }nd}g }t          j        |          }|                    d          r|                    d          r$t          |j        |j        z   |j	        z             }|
                    ||          |
                    |j        |          }	|
                    |j        |          |                    d          r|                    d          r|	f}
ng g g f}
|                    d          s|                    d          r$|
fd|D             fd|j        D             fz  }
d	                                }t          |t          j        d
          |
          }|                     d|          }d}|                    d          s| j        rd}|D ]k\  }}}d|z   }|D ]]}|                                 |                    ||           |                    |||                    ||          fz  |           ^l|                                 dS )a  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   r  c                     g | ]}|v|	S r6   r6   )r=   r>   kwfiless     r$   r@   zfiles.<locals>.<listcomp>j  s#    2221'!1!1Q!1!1!1r&   c                     g | ]}|v|	S r6   r6   )r=   r>   	kwunknowns     r$   r@   zfiles.<locals>.<listcomp>k  s#    ===1!9*<*<Q*<*<*<r&   s5   enabled deleted enabledunknown ignored ignoredunknowns   K!kIir  s   %.0s%s
s   %s %s
s   kwfiles.)kwstatusr{   )label)r   r   getcwdr   r   r   r   rB   rC   r   r   r   r   rP   zipbytestr	formatterverbose	startitemr}   plainpathtoend)r1   rV   r   r   r   r   r   cwdfiles	kwdeleted	showfileskwlabelskwstatesfmfmtkwstatechar	filenamesr%  r>   r!  r#  s                       @@r$   r0  r0  6  s   @ $t
,
,C:DRtS84888488F kkmmE%%D88J F488F#3#3 Fv5DEEll5$''GV^T22IV^T22I88I $((6"2"2 Y	1		BJ	xx 
488I.. 
2222222=======
 	
	 HMMOOH8X-h77CCH	j$	'	'B
Cxx 2: $, E E yg% 	E 	EALLNNNGGTG***HHSD$++a"5"566eHDDDD	E FFHHHHHr&   s   kwshrinks!   hg kwshrink [OPTION]... [FILE]...c                 *    t          | |dg|R i | dS )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                      | ||||||           t          t          |dd          dd          }|r'|                    |j        |j                  |_        dS dS )ztMonkeypatch/wrap patch.patchfile.__init__ to avoid
    rejects or conflicts due to expanded keywords in working dir.rV   Nr   )r   r   r   r   )origrU   r1   gpbackendstoreeolmoder   s           r$   kwpatchfile_initrA    sj     	Dr2ww///
''6400-
F
FC
 =__TZ<<


= =r&   c              /      K   t          |dd          }|r|j        }d|_        	  | |g|R i |D ]}|V  	 |r	||_        dS dS # |r||_        w xY w)z*Monkeypatch patch.diff to avoid expansion.r   NT)r   rQ   )r<  rV   r  kwargsr   rQ   chunks          r$   kwdiffrE    s      
$t
,
,C
 <$T$000000 	 	EKKKK	  	$#CLLL	$ 	$3 	$#CL####s   A Ac              #      K   t          |j        dd          }|r|j        }t          j        |_        	  | |          D ]}|V  	 |r	||_        dS dS # |r||_        w xY w)z2Wraps webcommands.x turning off keyword expansion.r   N)r   rV   r   r   never)r<  webr   	origmatchrD  s        r$   
kwweb_skiprJ    s      
#(M4
0
0C
 I	J	"T#YY 	 	EKKKK	  	"!CIII	" 	"3 	"!CI!!!!s   A Ac           
         t          |dd          }| | ||||||          S |                                5  |j                                        5  d|_         | ||||||          }||                                k    r@||         }	d|_        |                    |	|	                                dd           d|_        |cddd           cddd           S # 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )z3Wraps cmdutil.amend expanding keywords after amend.r   NTF)	r   r   r   parentchangerR   r   rQ   r   r0  )
r<  r1   rV   oldextrar   r   r   newidrz   s
             r$   kw_amendrP    s   
$t
,
,C
{tBc5$555	  t}1133  RsE466CHHJJu+CCLMM#syy{{E4888 CL                                        s6   C4A1CC4C 	 C4#C 	$C44C8;C8c                   	
 t          dd          		 | ||||          S                                 5   | ||||           |                    d          r	 ddd           dS d         
                                	
fd
fdj                                        D             }	                    
|dd           ddd           dS # 1 swxY w Y   dS )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                     j                             |           }d                    |          v r8t          j        j        t          j                            |                    }	                    |          S )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   	canonpathrM   osr{   realpathr   )destsourcer/  r   rV   r   s     r$   haskwsourcezkw_copy.<locals>.haskwsource  sp     ]))$//Ftzz&))))!+IsBG$4$4V$<$<  99V$$$r&   c                 X    g | ]&}d                      |          v |          $|'S r   )r   )r=   r>   rY  r   s     r$   r@   zkw_copy.<locals>.<listcomp>  sE     
 
 
4::a==(([[^^( (((r&   F)r   r   r   r&  r   copiesr   )r<  r1   rV   r   r   renamer   r/  rY  r   r   s     `    @@@@r$   kw_copyr]    s    $t
,
,C
{tBdD&111	 6 6RtT6***88J 	6 6 6 6 6 6 6 6 Dzkkmm		% 		% 		% 		% 		% 		% 		% 		%
 
 
 
 
]))++
 
 


 	dJu555/6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6s   &C/A"CC"%C"c           	      L   t          |dd          }| | |||g|R i |S |                                5  d|_        |d         }|                                } | |||g|R i |}	|d         }
||
k    rt	          ||
                                          \  }}d|_        |j                                        5  |	                    |
|dd           |	                    |
|ddd           ddd           n# 1 swxY w Y   d|_        |	cddd           S # 1 swxY w Y   dS )z9Wraps record.dorecord expanding keywords after recording.r   NTr   F)
r   r   rR   r   rE   r0  rQ   r   rL  r   )r<  r1   rV   
commitfuncr   r   r   rz   rD   retrecctxrB   rC   s                r$   kw_dorecordrb    s   
$t
,
,C
{tBj848884888	   4j**,,d2tZ7$777$77d&==(&,,..AAOHe CL++-- @ @fht<<<feUD$???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @  CL                 s6   BD;2C9-D9C=	=D C=	DD Dc                 8   |j         r|                    |          S t          |j        dd           }| | ||          S |j        v|j        j        s|                    |                                          rd|                                vsW|	                                dz
  |	                                k    s*|	                                |	                                k    r2|j
                            |j        |                                          S dS )Nr   r      T)
_customcmpr   r   rL   	_filenode_encodefilterpatsr   r{   r   r   _filelogr}   )r<  rU   fctxr   s       r$   kwfilectx_cmprj    s     xx~~
$*mT
2
2C
{tD$ 	J( 	 yy%% 	 DJJLL((yy{{Q$))++--99;;$))++%%}  ===4r&   c                 N   d }t          j        t          d|           t          j        t          j        dt
                     t          j        t          j        dt                     t          j        t          dt                     t          j        t          dt                     t          j        t          dt                     t          j        t          dt                     t                                          D ]"}t          j        t           |t"                     #d	S )
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                 H     | ||          \  }}}}}|t           d<   |||||fS )z9Monkeypatch dispatch._parse to obtain running hg command.r+   )rN   )r<  r1   r  r  funcoptions
cmdoptionss          r$   kwdispatch_parsez!uisetup.<locals>.kwdispatch_parse"  s7    /3tB~~,T4*D$33r&   s   _parses   cmps   __init__s   diffs   amends   copys   dorecordN)r
   wrapfunctionr   r   r   rj  r   	patchfilerA  rE  r   rP  r]  rb  nokwwebcommandsrP   r   rJ  )r1   rp  cs      r$   r  r    s    4 4 4 Hi1ABBBGOV]CCCEO[:JKKKE7F333GXx888GWg666G[+>>>""$$ < <Q
;;;;< <r&   c                 &   	 |                                 r[t          d         t                                          v s5dt	          j        |j                  v s|j                            d          rdS n# t          $ r Y nw xY wg dg}}| 
                    d          D ]6\  }}|dk    r|                    |           !|                    |           7|sdS t          | |||           G fdd	|j                  |_        |_        dS )
z0Sets up repo as kwrepo for keyword substitution.r+   s   .hgs   bundle:Ns   .hg*r   r  c                   Z     e Zd ZfdZ fdZ fdZd fd	Zd	 fd	Z xZS )
reposetup.<locals>.kwrepoc                 \    |d         dk    r
|dd          }t          | j        |          S )Nr      /rn   )r   svfs)rU   r>   r   s     r$   ro   zreposetup.<locals>.kwrepo.fileN  s1    tt||abbETYQ///r&   c                 v    t          |                               |          }                    ||          S r\   )r   r   )rU   filenamer}   r   kwrepor   s      r$   r   zreposetup.<locals>.kwrepo.wreadS  s4    &&,,X66D99Xt,,,r&   c                 f    | j         | _        	  t          |           j        |i || `S # | `w xY wr\   )kwcommitctx	commitctxr   r
  )rU   r  r   r   r}  s      r$   r
  z reposetup.<locals>.kwrepo.commitW  sK     "-DN#1uVT**14@4@@NNDN""""s   , 0FNc                 .   t          |                               |||          }j        sgj        }d_                            | |         t          |                                |                                z             dd           |_        |S )NTF)r   r  rR   rQ   r   r   rC   rB   )	rU   rz   r	   origctxnrQ   r   r}  r   s	         r$   r  z%reposetup.<locals>.kwrepo.kwcommitctx`  s    fd##--c5'BBA> (<#GVCIIKK#,,..$@AA5$    (Hr&   c                    |                                  5  j        }	 |s| d                                         }t          
|                               ||          }|sd| d         }t          |                                |          \  }}d_                            ||dd                               ||dd           ||_        cd d d            S # |_        w xY w# 1 swxY w Y   d S )Nr   FT)r   rQ   r0  r   rollbackrE   r   r   )rU   dryrunforceorigrestrictr?   r`  rz   rB   rC   r   r}  r   s            r$   r  z"reposetup.<locals>.kwrepo.rollbackl  s@    0 0"|0! 5"&t*"2"2"4"4--66vuEEC! ?"4j*4SZZ\\7*K*K%',c8T4@@@c5$>>>#/CL0 0 0 0 0 0 0 0 $0CL////0 0 0 0 0 0 0 0 0 0s)   C&B'CC&	C##C&&C*-C*)FN)FF)	r   r   r   ro   r   r
  r  r  r   )r   r}  r   s   @r$   r}  rw  M  s        	0 	0 	0 	0 	0
	- 	- 	- 	- 	- 	- 	-	# 	# 	# 	# 	# 	#
	 
	 
	 
	 
	 
	 
	 
		0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0r&   r}  )localrN   nokwcommandsrP   r   	splitpathrM   _url
startswithAttributeErrorrS   appendrG   r   r   )r1   rV   rW   rX   patoptr}  r   s         @@r$   r  r  4  s^   	

	x L$6$6$8$888	2222y##J// 3 F 3     G9CNN:..  S)JJsOOOOJJsOOOO 
b$S
)
)C.0 .0 .0 .0 .0 .0 .0 .0 .0 .0 .0` DNDs   A/A6 6
BBr\   r   )Fr   rU  rg   rJ   mercurial.i18nr   mercurial.pycompatr   mercurial.hgwebr   	mercurialr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   mercurial.utilsr   r   mercurial.dirstateutilsr   cmdtablecommand
testedwithr  rs  rO   recordextensions
colortabletemplatefilterconfigtable
configitemr"   r%   r(   r*   rN   r4   r9   rE   rG   r   r   r   r  walkoptsr   r0  r   rA  rE  rJ  rP  r]  rb  rj  r  r  r6   r&   r$   <module>r     s  :6 6r 
			 				        & & & & & & ' ' ' ' ' '                                     &        . - - - - -
)
H
%
%
 #
4  E
5    &.'& 
 *)++!Y!+..
 


    
<#45556 6 656 l&7888L L 98L l&78886 6 986 S/  8# # #  U U U U U U U Up6 6 6 6 6 6 6 6:> > >
8 
8 
8 		z4#H!I!IJ	y#qq!9::AAgJJG A455  Z  Z  Z z 	A*++	  - - - 		vtQQHIIJ	y$"G H HI	z4#K!L!LM
  A)**
 
 
8 8
 
8v 	A*++	  . . .= = = =$ $ $" " "   $6 $6 $6 $6N  .  ,< < <4J J J J Jr&   