##// END OF EJS Templates
fix: run fixer tools in the repo root as cwd so they can use the working copy...
Danny Hooper -
r42900:74b4cd09 default
parent child Browse files
Show More
@@ -102,6 +102,13 b' perform other post-fixing work. The supp'
102 mapping fixer tool names to lists of metadata values returned from
102 mapping fixer tool names to lists of metadata values returned from
103 executions that modified a file. This aggregates the same metadata
103 executions that modified a file. This aggregates the same metadata
104 previously passed to the "postfixfile" hook.
104 previously passed to the "postfixfile" hook.
105
106 Fixer tools are run the in repository's root directory. This allows them to read
107 configuration files from the working copy, or even write to the working copy.
108 The working copy is not updated to match the revision being fixed. In fact,
109 several revisions may be fixed in parallel. Writes to the working copy are not
110 amended into the revision being fixed; fixer tools should always write fixed
111 file content back to stdout as documented above.
105 """
112 """
106
113
107 from __future__ import absolute_import
114 from __future__ import absolute_import
@@ -232,7 +239,7 b' def fix(ui, repo, *pats, **opts):'
232 for rev, path in items:
239 for rev, path in items:
233 ctx = repo[rev]
240 ctx = repo[rev]
234 olddata = ctx[path].data()
241 olddata = ctx[path].data()
235 metadata, newdata = fixfile(ui, opts, fixers, ctx, path,
242 metadata, newdata = fixfile(ui, repo, opts, fixers, ctx, path,
236 basectxs[rev])
243 basectxs[rev])
237 # Don't waste memory/time passing unchanged content back, but
244 # Don't waste memory/time passing unchanged content back, but
238 # produce one result per item either way.
245 # produce one result per item either way.
@@ -529,7 +536,7 b' def getbasectxs(repo, opts, revstofix):'
529 basectxs[rev].add(pctx)
536 basectxs[rev].add(pctx)
530 return basectxs
537 return basectxs
531
538
532 def fixfile(ui, opts, fixers, fixctx, path, basectxs):
539 def fixfile(ui, repo, opts, fixers, fixctx, path, basectxs):
533 """Run any configured fixers that should affect the file in this context
540 """Run any configured fixers that should affect the file in this context
534
541
535 Returns the file content that results from applying the fixers in some order
542 Returns the file content that results from applying the fixers in some order
@@ -538,7 +545,8 b' def fixfile(ui, opts, fixers, fixctx, pa'
538 (i.e. they will only avoid lines that are common to all basectxs).
545 (i.e. they will only avoid lines that are common to all basectxs).
539
546
540 A fixer tool's stdout will become the file's new content if and only if it
547 A fixer tool's stdout will become the file's new content if and only if it
541 exits with code zero.
548 exits with code zero. The fixer tool's working directory is the repository's
549 root.
542 """
550 """
543 metadata = {}
551 metadata = {}
544 newdata = fixctx[path].data()
552 newdata = fixctx[path].data()
@@ -552,7 +560,7 b' def fixfile(ui, opts, fixers, fixctx, pa'
552 proc = subprocess.Popen(
560 proc = subprocess.Popen(
553 procutil.tonativestr(command),
561 procutil.tonativestr(command),
554 shell=True,
562 shell=True,
555 cwd=procutil.tonativestr(b'/'),
563 cwd=repo.root,
556 stdin=subprocess.PIPE,
564 stdin=subprocess.PIPE,
557 stdout=subprocess.PIPE,
565 stdout=subprocess.PIPE,
558 stderr=subprocess.PIPE)
566 stderr=subprocess.PIPE)
@@ -215,6 +215,13 b' Help text for fix.'
215 executions that modified a file. This aggregates the same metadata
215 executions that modified a file. This aggregates the same metadata
216 previously passed to the "postfixfile" hook.
216 previously passed to the "postfixfile" hook.
217
217
218 Fixer tools are run the in repository's root directory. This allows them to
219 read configuration files from the working copy, or even write to the working
220 copy. The working copy is not updated to match the revision being fixed. In
221 fact, several revisions may be fixed in parallel. Writes to the working copy
222 are not amended into the revision being fixed; fixer tools should always write
223 fixed file content back to stdout as documented above.
224
218 list of commands:
225 list of commands:
219
226
220 fix rewrite file content in changesets or working directory
227 fix rewrite file content in changesets or working directory
@@ -1269,6 +1276,41 b' three revisions instead of two.'
1269
1276
1270 $ cd ..
1277 $ cd ..
1271
1278
1279 We run fixer tools in the repo root so they can look for config files or other
1280 important things in the working directory. This does NOT mean we are
1281 reconstructing a working copy of every revision being fixed; we're just giving
1282 the tool knowledge of the repo's location in case it can do something
1283 reasonable with that.
1284
1285 $ hg init subprocesscwd
1286 $ cd subprocesscwd
1287
1288 $ cat >> .hg/hgrc <<EOF
1289 > [fix]
1290 > printcwd:command = pwd
1291 > printcwd:pattern = path:foo/bar
1292 > EOF
1293
1294 $ mkdir foo
1295 $ printf "bar\n" > foo/bar
1296 $ hg commit -Aqm blah
1297
1298 $ hg fix -w -r . foo/bar
1299 $ hg cat -r tip foo/bar
1300 $TESTTMP/subprocesscwd
1301 $ cat foo/bar
1302 $TESTTMP/subprocesscwd
1303
1304 $ cd foo
1305
1306 $ hg fix -w -r . bar
1307 $ hg cat -r tip bar
1308 $TESTTMP/subprocesscwd
1309 $ cat bar
1310 $TESTTMP/subprocesscwd
1311
1312 $ cd ../..
1313
1272 Tools configured without a pattern are ignored. It would be too dangerous to
1314 Tools configured without a pattern are ignored. It would be too dangerous to
1273 run them on all files, because this might happen while testing a configuration
1315 run them on all files, because this might happen while testing a configuration
1274 that also deletes all of the file content. There is no reasonable subset of the
1316 that also deletes all of the file content. There is no reasonable subset of the
General Comments 0
You need to be logged in to leave comments. Login now