File: //usr/lib/python3/dist-packages/hgext/__pycache__/fix.cpython-310.pyc
o
�]Lb-� � @ s\ d Z ddlmZ ddlZddlZddlZddlZddlZddlm Z ddl
mZmZm
Z
ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z! dZ"i Z#e�$e#�Z$i Z%e�&e%�Z&ddddd d
d
d�Z'e'�(� D ]\Z)Z*e&dd
e) e*d
d� qre&dddd� e&dddd� dMdd�Z+ddd e d�fZ,ddg e d�e d�fZ-ddg e d�e d�fZ.dd g e d!�e d�fZ/d"d#d e d$�fZ0dd%d e d&�fZ1e d'�Z2e$de,e-e.e/e0e1ge2e$j3d(�d)d*� �Z4d+d,� Z5d-d.� Z6d/d0� Z7d1d2� Z8d3d4� Z9d5d6� Z:d7d8� Z;d9d:� Z<d;d<� Z=d=d>� Z>d?d@� Z?dAdB� Z@dCdD� ZAdEdF� ZBdGdH� ZCdIdJ� ZDG dKdL� dLeE�ZFdS )Na" 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.
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.
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 should always write fixed
file content back to stdout as documented above.
� )�absolute_importN)�_)�nullid�nullrev�wdirrev)�procutil)�cmdutil�context�copies�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� continuec C sJ | � dd�}|dvrtjtd�|f td�d��|dkr#tj||d��dS ) 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 �action� r&