
    6hܖ              	      (   S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSKJrJr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#  Sr$0 r%\RL                  " \%5      r&0 r'\RP                  " \'5      r(SSSSS	S
S
S.r)\)RU                  5        H  u  r+r,\(" SS\+-  \,S
S9  M     \(" SSSS9  \(" SSSS9  \(" SS\-S9  S=S jr.SSS	\
" S5      4r/SS/ \
" S5      \
" S5      4r0SS/ \
" S5      \
" S5      4r1SS / \
" S!5      \
" S5      4r2S"S#S	\
" S$5      4r3SS%S	\
" S&5      4r4\
" S'5      r5\&" S\/\0\1\2\3\4/\5\&Rl                  S(9S) 5       r7S* r8S+ r9S, r:S- r;S. r<S/ r=S0 r>S1 r?S2 r@S3 rAS4 rBS5 rCS6 rDS7 rES8 rFS9 rGS: rH " S; S<5      rIg)>a  rewrite file content in changesets or working copy (EXPERIMENTAL)

Provides a command that runs configured tools on the contents of modified files,
writing back any fixes to the working copy or replacing changesets.

Fixer tools are run in the repository's root directory. This allows them to read
configuration files from the working copy, or even write to the working copy.
The working copy is not updated to match the revision being fixed. In fact,
several revisions may be fixed in parallel. Writes to the working copy are not
amended into the revision being fixed; fixer tools MUST always read content to
be fixed from stdin, and write fixed file content back to stdout.

Here is an example configuration that causes :hg:`fix` to apply automatic
formatting fixes to modified lines in C++ code::

  [fix]
  clang-format:command=clang-format --assume-filename={rootpath}
  clang-format:linerange=--lines={first}:{last}
  clang-format:pattern=set:**.cpp or **.hpp

The :command suboption forms the first part of the shell command that will be
used to fix a file. The content of the file is passed on standard input, and the
fixed file content is expected on standard output. Any output on standard error
will be displayed as a warning. If the exit status is not zero, the file will
not be affected. A placeholder warning is displayed if there is a non-zero exit
status but no standard error output. Some values may be substituted into the
command::

  {rootpath}  The path of the file being fixed, relative to the repo root
  {basename}  The name of the file being fixed, without the directory path

If the :linerange suboption is set, the tool will only be run if there are
changed lines in a file. The value of this suboption is appended to the shell
command once for every range of changed lines in the file. Some values may be
substituted into the command::

  {first}   The 1-based line number of the first line in the modified range
  {last}    The 1-based line number of the last line in the modified range

Deleted sections of a file will be ignored by :linerange, because there is no
corresponding line range in the version being fixed.

By default, tools that set :linerange will only be executed if there is at least
one changed line range. This is meant to prevent accidents like running a code
formatter in such a way that it unexpectedly reformats the whole file. If such a
tool needs to operate on unchanged files, it should set the :skipclean suboption
to false.

The :pattern suboption determines which files will be passed through each
configured tool. See :hg:`help patterns` for possible values. However, all
patterns are relative to the repo root, even if that text says they are relative
to the current working directory. If there are file arguments to :hg:`fix`, the
intersection of these patterns is used.

There is also a configurable limit for the maximum size of file that will be
processed by :hg:`fix`::

  [fix]
  maxfilesize = 2MB

Normally, execution of configured tools will continue after a failure (indicated
by a non-zero exit status). It can also be configured to abort after the first
such failure, so that no files will be affected if any tool fails. This abort
will also cause :hg:`fix` to exit with a non-zero status::

  [fix]
  failure = abort

When multiple tools are configured to affect a file, they execute in an order
defined by the :priority suboption. The priority suboption has a default value
of zero for each tool. Tools are executed in order of descending priority. The
execution order of tools with equal priority is unspecified. For example, you
could use the 'sort' and 'head' utilities to keep only the 10 smallest numbers
in a text file by ensuring that 'sort' runs before 'head'::

  [fix]
  sort:command = sort -n
  head:command = head -n 10
  sort:pattern = numbers.txt
  head:pattern = numbers.txt
  sort:priority = 2
  head:priority = 1

To account for changes made by each tool, the line numbers used for incremental
formatting are recomputed before executing the next tool. So, each tool may see
different values for the arguments added by the :linerange suboption.

Each fixer tool is allowed to return some metadata in addition to the fixed file
content. The metadata must be placed before the file content on stdout,
separated from the file content by a zero byte. The metadata is parsed as a JSON
value (so, it should be UTF-8 encoded and contain no zero bytes). A fixer tool
is expected to produce this metadata encoding if and only if the :metadata
suboption is true::

  [fix]
  tool:command = tool --prepend-json-metadata
  tool:metadata = true

The metadata values are passed to hooks, which can be used to print summaries or
perform other post-fixing work. The supported hooks are::

  "postfixfile"
    Run once for each file in each revision where any fixer tools made changes
    to the file content. Provides "$HG_REV" and "$HG_PATH" to identify the file,
    and "$HG_METADATA" with a map of fixer names to metadata values from fixer
    tools that affected the file. Fixer tools that didn't affect the file have a
    value of None. Only fixer tools that executed are present in the metadata.

  "postfix"
    Run once after all files and revisions have been handled. Provides
    "$HG_REPLACEMENTS" with information about what revisions were created and
    made obsolete. Provides a boolean "$HG_WDIRWRITTEN" to indicate whether any
    files in the working copy were updated. Provides a list "$HG_METADATA"
    mapping fixer tool names to lists of metadata values returned from
    executions that modified a file. This aggregates the same metadata
    previously passed to the "postfixfile" hook.

You can specify a list of directories to search the tool command in using the
`fix.extra-bin-paths` configuration.
    )annotationsN)_)nullidnullrevwdirrev)procutil)cmdutilcontextcopiesencodingerror
logcmdutilmatchmdiffmerge
mergestatepycompat	registrarrewriteutilscmutilutilworkers   ships-with-hg-coreFT)s   commands	   lineranges   patterns   priority   metadatas	   skipcleans   enabled   fixs   .*:%s$)defaultgeneric   maxfilesizes   2MB)r      failure   continue   extra-bin-pathsc                    U R                  SS5      nUS;  a+  [        R                  " [        S5      U4-  [        S5      S9eUS:X  a  [        R                  " XS9eg)	z)Abort with 'message' if fix.failure=abortr   r   )r      aborts   unknown fix.failure action: %ss   use "continue" or "abort"hintr"   N)configr   Abortr   )uimessager$   actions       +/usr/lib/python3/dist-packages/hgext/fix.pychecktoolfailureactionr+      sc    YYvz*F,,kk/0F9</0
 	
 kk'--     r,      alls)   fix all non-public non-obsolete revisions   basesd   revisions to diff against (overrides automatic selection, and applies to every revision being fixed)s   REV   r   revs   revisions to fix (ADVANCED)   s   sources1   fix the specified revisions and their descendants   ws   working-dirs   fix the working directory   wholes   always fix every line of a files   [OPTION]... [FILE]...)helpcategoryc                \  ^ ^^^^^ [         R                  " T5      m[        R                  " TSSS5        [        R                  " TSSS/5        TR                  5          TR                  5          TR                  S5         [        T TT5      n[        TTU5      m[        T TUTUT5      u  pV[        TTUT5      m[        T 5      m[        TUT5        UUUUUU 4S jn[        R                  " T SU[        5       USS	9n[         R"                  " [$        5      n	[         R"                  " [&        5      n
0 nSn[)        US
S9nT R+                  [-        S5      [-        S5      [/        UR1                  5       5      S9 nU GH	  u  nnnnUR3                  US9  UR5                  5        H  u  nnU
U   R7                  U5        M     Ub6  UX   U'   UUUS.nTR8                  "  SSS0[         R:                  " U5      D6  Xo==   S-  ss'   U(       d  M  XmS      (       a  M  UR=                  5       nTU   nU[>        :X  a  [A        TUX   U5        [C        X   5      nO[E        T TUX   U5        X	 U(       d  M  XmS      (       d  Mg  GM     SSS5        [G        TX5        UUU
S.nTR8                  " SSS
0[         R:                  " U5      D6  SSS5        SSS5        SSS5        g! , (       d  f       Na= f! , (       d  f       N0= f! , (       d  f       N9= f! , (       d  f       g= f)a  rewrite file content in changesets or working directory

Runs any configured tools to fix the content of files. (See
:hg:`help -e fix` for details about configuring tools.) Only affects files
with changes, unless file arguments are provided. Only affects changed lines
of files, unless the --whole flag is used. Some tools may always affect the
whole file regardless of --whole.

If --working-dir is used, files with uncommitted changes in the working copy
will be fixed. Note that no backup are made.

If revisions are specified with --source, those revisions and their
descendants will be checked, and they may be replaced with new revisions
that have fixed file content. By automatically including the descendants,
no merging, rebasing, or evolution will be required. If an ancestor of the
working copy is included, then the working copy itself will also be fixed,
and the working copy will be updated to the fixed parent.

When determining what lines of each file to fix at each revision, the whole
set of revisions being fixed is considered, so that fixes to earlier
revisions are not forgotten in later ones. The --base flag can be used to
override this default behavior, though it is not usually desirable to do so.
r-   r2   r0      working_dirr   c              3     >#    U  HL  u  pnTU   nXB   R                  5       n[        TTTTUUTT
U   5      u  pgXu:w  a  UOS nU H	  n	XXh4v   M     MN     g 7fN)datafixfile)itemssrcrevpathdstrevsctxolddatametadatanewdatar:   dstrevbasectxs	basepathsfixersoptsrepor'   s             r*   getfixesfix.<locals>.getfixes%  sy     ).%g6l)..*$+V$	%!" #*"4w$%F!88 &+ */s   AAg      ?F)
threadsafeT)reverses   fixings   files)topicunittotalitemN)r0   s   pathr   throw   )s   replacementss   wdirwrittenr   )s   postfixfile)s   postfix)$r   byteskwargsr	   check_at_most_one_argcheck_incompatible_argumentswlocklocktransactiongetrevstofixgetbasectxsgetworkqueuegetbasepaths	getfixers_prefetchfilesr   tuplecollectionsdefaultdictdictlistsortedmakeprogressr   sumvalues	incrementr<   appendhook	strkwargspopr   writeworkingdirbool
replacerevcleanup)r'   rI   patsrH   	revstofix	workqueuenumitemsrJ   resultsfiledataaggregatemetadatareplacementswdirwrittencommitorderprogressrevr>   filerevmetadatarC   	fixernamefixermetadatahookargsr@   rE   rF   rG   s   `` `                   @@@r*   fixr      s   < %D!!$	6B((nvy1 
tyy{D$4$4V$< T40	tT95*dD)X
	 !tYA	2
 	tY	2	9 	92 --Xuw	e
 **40'33D9Y5__I,Qx[HOO<M8N  
7>3T?G"""-0?0E0E0G,I}%i077F 1H&*1HM$' #!%%4 H
 II&# #,,X6
 "
 "k(r?*C*C%//+Cs)Cg~'c8=,O&*8=&9"2tS(-N  "k(r?*C*C+ 8?
D 	l0)'*

 			IDIH,>,>x,HIA %={p
 
q %=$<{{sp    L1LC;K;>BK*	
K*	#AK*	<K*	
K*	AK;LL*
K84K;;
L	L
L	L
L+c                    UR                  5        VVs0 s H  u  p4X4/_M
     nnn[        R                  " XSSS9  gs  snnf )a  Calls scmutil.cleanupnodes() with the given replacements.

"replacements" is a dict from nodeid to nodeid, with one key and one value
for every revision that was affected by fixing. This is slightly different
from cleanupnodes().

"wdirwritten" is a bool which tells whether the working copy was affected by
fixing, since it has no entry in "replacements".

Useful as a hook point for extending "hg fix" with output summarizing the
effects of the command, though we choose not to output anything here.
r   T)fixphaseN)r<   r   cleanupnodes)rI   r{   r|   precsuccs        r*   rs   rs   x  sB     4@3E3E3GH3GZTD&L3GLHVdC Is   =c                "   [         R                  " [        5      n[         R                  " [        5      nU R	                  SS5      n[        U5       H  n	X   n
[        R                  " XU5      n[        [        XX#XU	   U
5      5       H  nX   nUR                  5       (       a  M  UR                  5       U:  a5  U R                  [        S5      [        R                  " U5      U4-  5        Mg  [        S XY    5       5      nXmR!                  5       X4   R#                  U	5        Xy==   S-  ss'   M     M     UR%                  5        VVVVs/ s H  u  u  nnnn['        U5      UU4PM     nnnnnUR)                  5         UU4$ s  snnnnf )a  Constructs a list of files to fix and which revisions each fix applies to

To avoid duplicating work, there is usually only one work item for each file
revision that might need to be fixed. There can be multiple work items per
file revision if the same file needs to be fixed in multiple changesets with
different baserevs. Each work item also contains a list of changesets where
the file's data should be replaced with the fixed data. The work items for
earlier changesets come earlier in the work queue, to improve pipelining by
allowing the first changeset to be replaced while fixes are still being
computed for later changesets.

Also returned is a map from changesets to the count of work items that might
affect each changeset. This is used later to count when all of a changeset's
work items have been finished, without having to inspect the remaining work
queue in each worker subprocess.

The example work item (1, "foo/bar.txt", (1, 2, 3)) means that the data of
bar.txt should be read from revision 1, then fixed, and written back to
revisions 1, 2 and 3. Revision 1 is called the "srcrev" and the list of
revisions is called the "dstrevs". In practice the srcrev is always one of
the dstrevs, and we make that choice when constructing the work item so that
the choice can't be made inconsistently later on. The dstrevs should all
have the same file revision for the given path, so the choice of srcrev is
arbitrary. The wdirrev can be a dstrev and a srcrev.
r   r   s!   ignoring file larger than %s: %s
c              3  @   #    U  H  oR                  5       v   M     g 7fr9   )r   ).0r@   s     r*   	<genexpr>getworkqueue.<locals>.<genexpr>  s     @-3WWYY-s   rT   )rc   rd   rf   intconfigbytesrg   r   r   
pathstofixislinksizewarnr   r   	bytecountrb   filerevrl   r<   minsort)r'   rI   rt   rH   ru   rE   	dstrevmaprw   maxfilesizer   fixctxr   r>   fctxbaserevs_filerev	_baserevsr?   rv   s                      r*   r^   r^     sf   4 ''-I&&s+H..8Ki fD1rUSM6J
D <D{{}}yy{[(;<~~k2D9: @(-@@H||~x67>>sCMQM
 !( 5>OO4E4E0'Xy$ 
WtW%4E   NNhs   F	
c                R   US   (       a  UR                  S5      nOUS   (       a  [        R                  " XS   5      n[        UR                  SU5      5      n[        U;   a  UR                  [        5        US   R                  5       U;   a  UR                  [        5        OM[        [        R                  " XS   5      5      nUR                  S5      (       a  UR                  [        5        [        U5      S:X  a
  [        U;   d-  [        R                  " U5        [        R                  " XS	5        [        U;   aG  [        R                  R                  U5      R!                  5       (       a  ["        R$                  " S
SS9eU(       d  ["        R$                  " SSS9eU$ )z8Returns the set of revision numbers that should be fixedr-   s+   (not public() and not obsolete()) or wdir()r2   s   (%ld::) - obsolete()   .r0   r7   rT   r   s   unresolved conflictss   use 'hg resolve'r#   s   no changesets specifieds   use --source or --working-dir)revsr   revrangesetr   addr   getlenr	   checkunfinishedr   precheckmergestatemodr   readunresolvedcountr   r&   )r'   rI   rH   r   source_revss        r*   r\   r\     s;   F|yyGH	i ))$Y@4994kBCk!HHW:>>t#HHW:&&t&\:;88N##HHWINw$%T04$$))$/??AAkk18KLLkk&-M
 	
 Kr,   c                $   [        5       nU H  nUR                  Xd[        U5      [        U5      S9n	UR                  [        [        R
                  " U	R                  U	R                  U	R                  U	R                  5      5      5        M     U$ )zReturns the set of files that should be fixed in a context

The result depends on the base contexts; we include any file that has
changed relative to any of the base contexts. Base contexts should be
ancestors of the context being fixed.
)r   	listcleanlistunknown)
r   statusrq   update	itertoolschainaddedmodifiedcleanunknown)
r'   rI   rt   rH   r   rE   r   filesbasectxstats
             r*   r   r     sy     EE~~4:4:  
 	JJtzz4<<	
	  Lr,   c                <   U R                  S5      (       a  [        SU5      $ / nU Hh  nUR                  UR                  5       UR                  5       U4U5      nX;   a  Xx   R                  5       n	OSn	UR	                  [        X5      5        Mj     [        U5      $ )a  Returns the set of line ranges that should be fixed in a file

Of the form [(10, 20), (30, 40)].

This depends on the given base contexts; we must consider lines that have
changed versus any of the base contexts, and whether the file has been
renamed versus any of them.

Another way to understand this is that we exclude line ranges that are
common to the file in all base contexts.
r4   r,   )r   difflinerangesr   r:   extendunionranges)
rH   r>   rF   rE   r   content2
rangeslistr   basepathcontent1s
             r*   
linerangesr     s     xx c8,,J=='++-t!DdK(--/HH.<=  z""r,   c                   UR                  S5      (       a  0 $ 0 nU Hd  u  pVnX   nX5    HR  n	[        R                  " X5      R                  Xf5      n
X;   d  M/  XU	R                  5       UR                  5       U4'   MT     Mf     U$ )Nr4   )r   r   
pathcopiesr   )rI   rH   rv   rE   rF   r=   r>   _dstrevsr   r   r   s              r*   r_   r_     s    xx	I"+h'G((9==dIH"AI7;;=&**,=> ( #, r,   c                    [        [        U 5      5      n / nU (       a
  U S   /U SS pU  H8  u  p#US   u  pEX%S-   :  a  UR                  X#45        M(  U[        X55      4US'   M:     U$ )a  Return the union of some closed intervals

>>> unionranges([])
[]
>>> unionranges([(1, 100)])
[(1, 100)]
>>> unionranges([(1, 100), (1, 100)])
[(1, 100)]
>>> unionranges([(1, 100), (2, 100)])
[(1, 100)]
>>> unionranges([(1, 99), (1, 100)])
[(1, 100)]
>>> unionranges([(1, 100), (40, 60)])
[(1, 100)]
>>> unionranges([(1, 49), (50, 100)])
[(1, 100)]
>>> unionranges([(1, 48), (50, 100)])
[(1, 48), (50, 100)]
>>> unionranges([(1, 2), (3, 4), (5, 6)])
[(1, 6)]
r   rT   NrU   )rg   r   rl   max)r   unionedabcds         r*   r   r   )  ss    , J(JG)!}oz!"~r{1u9NNA6"c!i.GBK  Nr,   c                    / n[         R                  " X5       H1  u  p4USS u  pVUS:X  d  M  XV:w  d  M  UR                  US-   U45        M3     U$ )aN  Return list of line number ranges in content2 that differ from content1.

Line numbers are 1-based. The numbers are the first and last line contained
in the range. Single-line ranges have the same line number for the first and
last line. Excludes any empty ranges that result from lines that are only
present in content1. Relies on mdiff's idea of where the line endings are in
the string.

>>> from mercurial import pycompat
>>> lines = lambda s: b'\n'.join([c for c in pycompat.iterbytestr(s)])
>>> difflineranges2 = lambda a, b: difflineranges(lines(a), lines(b))
>>> difflineranges2(b'', b'')
[]
>>> difflineranges2(b'a', b'')
[]
>>> difflineranges2(b'', b'A')
[(1, 1)]
>>> difflineranges2(b'a', b'a')
[]
>>> difflineranges2(b'a', b'A')
[(1, 1)]
>>> difflineranges2(b'ab', b'')
[]
>>> difflineranges2(b'', b'AB')
[(1, 2)]
>>> difflineranges2(b'abc', b'ac')
[]
>>> difflineranges2(b'ab', b'aCb')
[(2, 2)]
>>> difflineranges2(b'abc', b'aBc')
[(2, 2)]
>>> difflineranges2(b'ab', b'AB')
[(1, 2)]
>>> difflineranges2(b'abcde', b'aBcDe')
[(2, 2), (4, 4)]
>>> difflineranges2(b'abcde', b'aBCDe')
[(2, 4)]
         !rT   )r   	allblocksrl   )r   r   rangeslineskind	firstlinelastlines          r*   r   r   L  sU    N Fx:#Aaj	4<I1MM9q=(34 ; Mr,   c                2   UR                  S5      (       ac  [        [        R                  " XR                  S5      5      5      nU(       d  [        1nU Vs1 s H  o@U   iM	     nnU Vs0 s H  oDU_M     sn$ [
        R                  " [        5      n[        U5       Hj  nX   nUR                  5        HO  nUR                  5       U;   a%  XT   R                  XWR                  5          5        M<  XT   R                  U5        MQ     Ml     U$ s  snf s  snf )a   Returns a map of the base contexts for each revision

The base contexts determine which lines are considered modified when we
attempt to fix just the modified lines in a file. It also determines which
files we attempt to fix, so it is important to compute this even when
--whole is used.
r.   )r   r   r   r   r   rc   rd   rg   parentsr   r   r   )rI   rH   ru   r   r   rE   r@   pctxs           r*   r]   r]   {  s     xxz**4'1BCDyH)12#I2)23#X33 &&s+Hi iKKMDxxzX%$$Xhhj%9:!!$'	 " ! O 33s   D+Dc                j   [        5       nU H$  u  pEnU[        :X  a  M  UR                  XE45        M&     UR                  5        H  u  u  pxpYUR                  Xy45        M     U(       aD  [        R
                  " U U V
Vs/ s H  u  pU
[        R                  " X/5      4PM      snn
5        g g s  snn
f r9   )r   r   r   r<   r   prefetchfiles
matchfiles)rI   rv   rF   
toprefetchr=   r>   r   baserevfixrevr   r   s              r*   ra   ra     s    J #,hW~& #, .7__->)$*+ .?  ",!+IC g((v67!+	
 s    %B/c                   [         R                  (       a  [        R                  R	                  5       nUR                  SS5      nU Vs/ s H  o@R                  U5      PM     nnXR                  [        R                  5      -   n[        R                  R                  U5      US'   U$ [        R                  " 5       =(       d    [        R                  " 5       nU Vs/ s H  owR                  US5      PM     nnU R                  R                  US5      n	U Vs/ s H"  n[         R                  R                  X5      PM$     nn[         R                  R	                  5       nUR                  SS5      nXR                  [         R                   5      -   n[         R                   R                  U5      US'   U$ s  snf s  snf s  snf )Ns   PATHr,   ignorePATH )ossupports_bytes_environr   environcopyr   joinsplitr   	ospathsepsysgetfilesystemencodinggetdefaultencodingdecodebaser>   pathsep)
wvfsextra_pathsenvraw_pathi
path_itemspath_encodingp	extra_strr   s
             r*   _augmented_envr     sW   	  ##%777C(-89[yy|[9 >>(2D2D#EE
))..z:G J 113Os7M7M7O@KL1XXmX6	Lyyx84=>IqRWW\\$*I	> ll!7762&!==
ll''
3FJ :
 M>s   
F= G)Gc                   0 nXE   R                  5       n	Sn
U R                  SS5      nU(       a  [        UR                  U5      n
UR	                  5        GH  u  pUR                  X$U5      (       d  M  [        X%XgXI5      nUR                  XU5      nUc  MC  SnUXLU4-  nU R                  U5        U R                  SU4-  5        [        R                  " [        R                  " U5      S[        R                  " UR                  5      [        R                  [        R                  [        R                  U
S9nUR                  U	5      u  nnU(       a  [!        XR#                  5       UU5        UnUR%                  5       (       a/   UR'                  SS	5      u  nn[(        R*                  " U5      X'   OSX'   UR2                  S:X  a  Un	GM}  U(       d4  [1        S5      UR2                  4-  n[!        XR#                  5       UU5        [5        U [1        S5      [1        S5      S9  GM     X4$ ! [,         a#    U R/                  [1        S
5      U4-  5         GM	  f = f)a
  Run any configured fixers that should affect the file in this context

Returns the file content that results from applying the fixers in some order
starting with the file's content in the fixctx. Fixers that support line
ranges will affect lines that have changed relative to any of the basectxs
(i.e. they will only avoid lines that are common to all basectxs).

A fixer tool's stdout will become the file's new content if and only if it
exits with code zero. The fixer tool's working directory is the repository's
root.
Nr   r    s   fixing: %s - %s - %s
s   subprocess: %s
T)shellcwdstdinstdoutstderrr       rT   s+   ignored invalid output from fixer tool: %s
r   s   exited with status %d
s   no fixes will be appliedsF   use --config fix.failure=continue to apply any successful fixes anywayr#   )r:   
configlistr   r   r<   affectsr   commanddebug
subprocessPopenr   tonativestrrootPIPEcommunicate
showstderrr   shouldoutputmetadatar   r   
json_loads
ValueErrorr   r   
returncoder+   )r'   rI   rH   rG   r   r>   rF   rE   rB   rC   r   r   r   fixerr   r  msgprocr  r  	newerdatametadatajsonr(   s                          r*   r;   r;     s%    Hl!G
C--(:;KTYY4"LLN	==t,,IF mmBf5G+CFt,,CHHSMHH(G:56##$$W-((3 oo!!D "--g6NFF2zz|Y?I))++.4ll5!.D+L)*2*=*=l*KH' '+#!## :;t>PPGr::<GD&123W +f - " GGIJ$,' s   -H33(I I c                    [         R                  " SU5       Hb  nU(       d  M  U R                  S5        Uc  U R                  [        S5      SS9  OU R                  SU-  SS9  U R                  SX$4-  5        Md     g)	a%  Writes the lines of the stderr string as warnings on the ui

Uses the revision number and fixername to give more context to each line of
the error message. Doesn't include file names, since those take up a lot of
space and would tend to be included in the error message if they were
relevant.
s   [
]+   [Ns   wdirs
   evolve.rev)labels   %ds	   ] %s: %s
)rer   r   r   )r'   r   r   r  lines        r*   r  r    sj     V,4GGDM{'
-8=9GGMY$556 -r,   c                   UR                  5        H(  u  pEX   nUR                  XVR                  5       5        M*     U R                  R	                  5       nUR                  Xw5      nX:w  ab  U R                  R                  5       [        :X  d   eU R                  R                  U 5         [        R                  " X U   5        SSS5        gg! , (       d  f       g= f)a  Write new content to the working copy and check out the new p1 if any

We check out a new revision if and only if we fixed something in both the
working directory and its parent revision. This avoids the need for a full
update/merge, and means that the working directory simply isn't affected
unless the --working-dir flag is given.

Directly updates the dirstate for the affected files.
N)r<   writeflagsdirstatep1r   p2r   changing_parentsr   movedirstate)	rI   r@   ry   r{   r>   r:   r   oldp1newp1s	            r*   rp   rp   !  s     nn&
y

4& ' MMEU*E~}}!V+++]]++D1  E{3 21 11s   ,C
Cc           
     J   UR                   R                  UR                  5       5      u  pVX   X   pUR                  UR	                  5       UR	                  5       5      n	UR                  UR	                  5       UR	                  5       5      n
U(       d)  UR	                  5       U;  a  UR	                  5       U;  a  gUR                  5       R                  5       nUR                  5       US'   [        R                  " U5      nUR                  X   5        [        R                  " X,S9  [        R                  " XUR                  5       5        UR!                  5        HR  nX-   nUR#                  5       nUR%                  XU   UR'                  5       S9  U(       d  MA  UR)                  X5        MT     [*        R,                  " UUR/                  5       UR1                  5        VVs0 s H
  u  nnUU/_M     snn5      nUR3                  UUR5                  5       UUR7                  5       X4UR9                  5       S9nUR;                  5       nUR	                  5       nUU:X  a#  U R=                  SUR                  5       -  5        gUXBR	                  5       '   gs  snnf )aw  Commit a new revision like the given one, but with file content changes

"ctx" is the original revision to be replaced by a modified one.

"filedata" is a dict that maps paths to their new file content. All other
paths will be recreated from the original revision without changes.
"filedata" may contain paths that didn't exist in the original revision;
they will be added.

"replacements" is a dict that maps a single node to a single node, and it is
updated to indicate the original revision is replaced by the newly created
one. No entry is added if the replacement's node already exists.

The new revision has the same parents as the old one, unless those parents
have already been replaced, in which case those replacements are the parents
of this new revision. Thus, if revisions are replaced in topological order,
there is no need to rebase them into the original topology later.
Ns
   fix_source)wc)r  )textbranchextradater   users   node %s already existed
)	changelog
parentrevsr   r   noder+  r   hexr
   overlayworkingctxsetbaser   	revert_tor   graftcopiesr!  keys
copysourcer  r  
markcopiedr   update_hash_refsdescriptionr<   tomemctxr*  r,  r-  commitr  )r'   rI   r@   ry   r{   p1revp2revp1ctxp2ctx	newp1node	newp2noder+  wctxr>   r   r7  oldnodenewnodedescmemctxsucnodeprenodes                         r*   rr   rr   7  s   ( >>,,SWWY7LE;5  uzz|<I  uzz|<I JJL,JJL,IIKE779E-$$T*DLL!	OOC!
t#&&(+y__&


4$tzz|
<:OOD-   ''4@4F4F4HI4H 07)	4HID ]]zz|XXZ&XXZ  F mmoGhhjG'
-;<#*XXZ # 	Js   +Jc           	        0 n[        U 5       GH
  nU R                  SUS-   5      nU R                  SUS-   5      nU R                  SUS-   5      nU R                  SUS-   5      nU R                  SUS-   5      nU R                  SUS-   5      nU R                  SUS-   5      n	Uc   U R	                  [        S	5      U4-  5        M  Uc   U R	                  [        S
5      U4-  5        M  U(       d  U R                  SU4-  5        M  [        XEXgX5      X'   GM     [        R                  " [        UR                  5       S SS95      $ )zReturns a map of configured fixer tools indexed by their names

Each value is a Fixer object with methods that implement the behavior of the
fixer's config suboptions. Does not validate the config values.
r   s   :enableds   :commands   :patterns
   :lineranges	   :prioritys	   :metadatas
   :skipcleans,   fixer tool has no command configuration: %s
s,   fixer tool has no pattern configuration: %s
s!   ignoring disabled fixer tool: %s
c                     U S   R                   $ )NrT   )	_priorityrQ   s    r*   <lambda>getfixers.<locals>.<lambda>  s    Q0A0Ar,   T)keyrM   )
fixernames
configboolr%   	configintr   r   r  Fixerrc   OrderedDictrg   r<   )
r'   rG   nameenabledr  pattern	linerangepriorityrB   	skipcleans
             r*   r`   r`     sD    F2--{(:;))FD;$67))FD;$67IIfd]&:;	<<|(;<==)<=MM&$*>?	
 ?GGBCtgM _GGBCtgM HH:dWDE )xFL/ 4 ""v||~#A4P r,   c                    [        5       nU R                  S5       H1  u  p#SU;   d  M  UR                  UR                  SS5      S   5        M3     U$ )z>Returns the names of [fix] config options that have suboptionsr      :rT   r   )r   configitemsr   r   )r'   nameskvs       r*   rP  rP    sH    EEv&19IIaggdA&q)* ' Lr,   c                  0    \ rS rSrSrS rS rS rS rSr	g)	rS  i  z4Wraps the raw config values for a fixer with methodsc                L    Xl         X l        X0l        X@l        XPl        X`l        g r9   )_command_pattern
_linerangerL  	_metadata
_skipclean)selfr  rW  rX  rY  rB   rZ  s          r*   __init__Fixer.__init__  s"      #!!#r,   c                    UR                  5       n[        R                  " UR                  UR                  U R                  /US9nU" U5      $ )z@Should this fixer run on the file at the given path and context?)r@   )rI   matchmodr   r  rd  )rh  rH   r   r>   rI   matchers         r*   r  Fixer.affects  s>    {{}..IItyy4==/v
 t}r,   c                    U R                   $ )z@Should the stdout of this fixer start with JSON and a null byte?)rf  )rh  s    r*   r  Fixer.shouldoutputmetadata  s    ~~r,   c           
     `   [         R                  nU" UU R                  U[        R                  R                  U5      S.5      /nU R                  (       aH  U R                  (       a  U(       d  gU H)  u  pgUR                  U" XR                  XgS.5      5        M+     SR                  U5      $ )zA shell command to use to invoke this fixer on the given file/lines

May return None if there is no appropriate command to run for the given
parameters.
)s   rootpaths   basenameN)s   firsts   last    )
r	   rendercommandtemplaterc  r   r>   basenamere  rg  rl   r   )rh  r'   r>   r   expandpartsfirstlasts           r*   r  Fixer.command  s     .."1A1A$1GH
 ??v%OO-M  & yyr,   )rc  re  rf  rd  rL  rg  N)
__name__
__module____qualname____firstlineno____doc__ri  r  r  r  __static_attributes__ r,   r*   rS  rS    s    >$ r,   rS  r9   )Jr~  
__future__r   rc   r   r   r  r  r   mercurial.i18nr   mercurial.noder   r   r   mercurial.utilsr   	mercurialr	   r
   r   r   r   r   r   rl  r   r   r   r   r   r   r   r   r   r   
testedwithcmdtabler  configtable
configitemFIXER_ATTRSr<   rO  r   rf   r+   alloptbaseoptrevopt	sourceoptwdiroptwholeoptusageCATEGORY_FILE_CONTENTSr   rs   r^   r\   r   r   r_   r   r   r]   ra   r   r;   r  rp   rr   r`   rP  rS  r  r,   r*   <module>r     sI  wr #   	 	  
   %    . #



H
%!!+.
   %%'LCvy3F ( 6>6 2
 6:{ 3 
6%t 4	. vua LM	N	
 fI
 A<=qy	I:;fI	 *F(G
H5!$F"GH	
"# 	
Wfi(;	//	~J~JBD";|@,#: F,^<
.,FR7$4,I+X#L1  1 r,   