comparison tests/test-fix.t @ 42194:0da689a60163

fix: allow fixer tools to return metadata in addition to the file content With this change, fixer tools can be configured to output a JSON object that will be parsed and passed to hooks that can be used to print summaries of what code was formatted or perform other post-fixing work. The motivation for this change is to allow parallel executions of a "meta-formatter" tool to report back statistics, which are then aggregated and processed after all formatting has completed. Providing an extensible mechanism inside fix.py is far simpler, and more portable, than trying to make a tool like this communicate through some other channel. Differential Revision: https://phab.mercurial-scm.org/D6167
author Danny Hooper <hooper@google.com>
date Thu, 21 Mar 2019 18:32:45 -0700
parents 7f6b375a8903
children b02f3aa2fab5
comparison
equal deleted inserted replaced
42190:7c0ece3cd3ee 42194:0da689a60163
183 To account for changes made by each tool, the line numbers used for 183 To account for changes made by each tool, the line numbers used for
184 incremental formatting are recomputed before executing the next tool. So, each 184 incremental formatting are recomputed before executing the next tool. So, each
185 tool may see different values for the arguments added by the :linerange 185 tool may see different values for the arguments added by the :linerange
186 suboption. 186 suboption.
187 187
188 Each fixer tool is allowed to return some metadata in addition to the fixed
189 file content. The metadata must be placed before the file content on stdout,
190 separated from the file content by a zero byte. The metadata is parsed as a
191 JSON value (so, it should be UTF-8 encoded and contain no zero bytes). A fixer
192 tool is expected to produce this metadata encoding if and only if the
193 :metadata suboption is true:
194
195 [fix]
196 tool:command = tool --prepend-json-metadata
197 tool:metadata = true
198
199 The metadata values are passed to hooks, which can be used to print summaries
200 or perform other post-fixing work. The supported hooks are:
201
202 "postfixfile"
203 Run once for each file in each revision where any fixer tools made changes
204 to the file content. Provides "$HG_REV" and "$HG_PATH" to identify the file,
205 and "$HG_METADATA" with a map of fixer names to metadata values from fixer
206 tools that affected the file. Fixer tools that didn't affect the file have a
207 valueof None. Only fixer tools that executed are present in the metadata.
208
209 "postfix"
210 Run once after all files and revisions have been handled. Provides
211 "$HG_REPLACEMENTS" with information about what revisions were created and
212 made obsolete. Provides a boolean "$HG_WDIRWRITTEN" to indicate whether any
213 files in the working copy were updated. Provides a list "$HG_METADATA"
214 mapping fixer tool names to lists of metadata values returned from
215 executions that modified a file. This aggregates the same metadata
216 previously passed to the "postfixfile" hook.
217
188 list of commands: 218 list of commands:
189 219
190 fix rewrite file content in changesets or working directory 220 fix rewrite file content in changesets or working directory
191 221
192 (use 'hg help -v -e fix' to show built-in aliases and global options) 222 (use 'hg help -v -e fix' to show built-in aliases and global options)