Mercurial > hg
comparison hgext/fix.py @ 45074:797ef6f8295e
fix: prefetch file contents
This prevents the worker subprocesses from contacting the server individually,
which is either inefficient, or leads to problems if the connection is shared
among them.
Differential Revision: https://phab.mercurial-scm.org/D8723
author | Rodrigo Damazio Bovendorp <rdamazio@google.com> |
---|---|
date | Thu, 09 Jul 2020 20:46:52 -0700 |
parents | 54009f8c3e25 |
children | 3ea3b85df03f |
comparison
equal
deleted
inserted
replaced
45073:54009f8c3e25 | 45074:797ef6f8295e |
---|---|
268 workqueue, numitems = getworkqueue( | 268 workqueue, numitems = getworkqueue( |
269 ui, repo, pats, opts, revstofix, basectxs | 269 ui, repo, pats, opts, revstofix, basectxs |
270 ) | 270 ) |
271 basepaths = getbasepaths(repo, opts, workqueue, basectxs) | 271 basepaths = getbasepaths(repo, opts, workqueue, basectxs) |
272 fixers = getfixers(ui) | 272 fixers = getfixers(ui) |
273 | |
274 # Rather than letting each worker independently fetch the files | |
275 # (which also would add complications for shared/keepalive | |
276 # connections), prefetch them all first. | |
277 _prefetchfiles(repo, workqueue, basepaths) | |
273 | 278 |
274 # There are no data dependencies between the workers fixing each file | 279 # There are no data dependencies between the workers fixing each file |
275 # revision, so we can use all available parallelism. | 280 # revision, so we can use all available parallelism. |
276 def getfixes(items): | 281 def getfixes(items): |
277 for rev, path in items: | 282 for rev, path in items: |
626 if pctx.rev() in basectxs: | 631 if pctx.rev() in basectxs: |
627 basectxs[rev].update(basectxs[pctx.rev()]) | 632 basectxs[rev].update(basectxs[pctx.rev()]) |
628 else: | 633 else: |
629 basectxs[rev].add(pctx) | 634 basectxs[rev].add(pctx) |
630 return basectxs | 635 return basectxs |
636 | |
637 | |
638 def _prefetchfiles(repo, workqueue, basepaths): | |
639 toprefetch = set() | |
640 | |
641 # Prefetch the files that will be fixed. | |
642 for rev, path in workqueue: | |
643 if rev == wdirrev: | |
644 continue | |
645 toprefetch.add((rev, path)) | |
646 | |
647 # Prefetch the base contents for lineranges(). | |
648 for (baserev, fixrev, path), basepath in basepaths.items(): | |
649 toprefetch.add((baserev, basepath)) | |
650 | |
651 if toprefetch: | |
652 scmutil.prefetchfiles( | |
653 repo, | |
654 [ | |
655 (rev, scmutil.matchfiles(repo, [path])) | |
656 for rev, path in toprefetch | |
657 ], | |
658 ) | |
631 | 659 |
632 | 660 |
633 def fixfile(ui, repo, opts, fixers, fixctx, path, basepaths, basectxs): | 661 def fixfile(ui, repo, opts, fixers, fixctx, path, basepaths, basectxs): |
634 """Run any configured fixers that should affect the file in this context | 662 """Run any configured fixers that should affect the file in this context |
635 | 663 |