##// END OF EJS Templates
fix: reduce number of tool executions...
fix: reduce number of tool executions By grouping together (path, ctx) pairs according to the inputs they would provide to fixer tools, we can deduplicate executions of fixer tools to significantly reduce the amount of time spent running slow tools. This change does not handle clean files in the working copy, which could still be deduplicated against the files in the checked out commit. It's a little harder to do that because the filerev is not available in the workingfilectx (and it doesn't exist for added files). Anecdotally, this change makes some real uses cases at Google 10x faster. I think we were originally hesitant to do this because the benefits weren't obvious, and implementing it efficiently is kind of tricky. If we simply memoized the formatter execution function, we would be keeping tons of file content in memory. Also included is a regression test for a corner case that I broke with my first attempt at optimizing this code. Differential Revision: https://phab.mercurial-scm.org/D11280

File last commit:

r46554:89a2afe3 default
r48992:f12a19d0 default
Show More
record.py
175 lines | 5.1 KiB | text/x-python | PythonLexer
Bryan O'Sullivan
Add record extension, giving darcs-like interactive hunk picking
r5037 # record.py
#
# Copyright 2007 Bryan O'Sullivan <bos@serpentine.com>
#
Martin Geisler
updated license to be explicit about GPL version 2
r8225 # This software may be used and distributed according to the terms of the
Matt Mackall
Update license to GPLv2+
r10263 # GNU General Public License version 2 or any later version.
Bryan O'Sullivan
Add record extension, giving darcs-like interactive hunk picking
r5037
Pierre-Yves David
record: deprecate the extension...
r28697 '''commands to interactively select changes for commit/qrefresh (DEPRECATED)
The feature provided by this extension has been moved into core Mercurial as
:hg:`commit --interactive`.'''
timeless
record: use absolute_import
r28381 from __future__ import absolute_import
Bryan O'Sullivan
Add record extension, giving darcs-like interactive hunk picking
r5037
Yuya Nishihara
py3: move up symbol imports to enforce import-checker rules...
r29205 from mercurial.i18n import _
timeless
record: use absolute_import
r28381 from mercurial import (
cmdutil,
commands,
error,
extensions,
Yuya Nishihara
registrar: move cmdutil.command to registrar module (API)...
r32337 registrar,
timeless
record: use absolute_import
r28381 )
Bryan O'Sullivan
Add record extension, giving darcs-like interactive hunk picking
r5037
Idan Kamara
record: use cmdutil.command decorator
r14408 cmdtable = {}
Yuya Nishihara
registrar: move cmdutil.command to registrar module (API)...
r32337 command = registrar.command(cmdtable)
Augie Fackler
extensions: change magic "shipped with hg" string...
r29841 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
Augie Fackler
extensions: document that `testedwith = 'internal'` is special...
r25186 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
# be specifying the version(s) of Mercurial they are tested with, or
# leave the attribute unspecified.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 testedwith = b'ships-with-hg-core'
Idan Kamara
record: use cmdutil.command decorator
r14408
Bryan O'Sullivan
Add record extension, giving darcs-like interactive hunk picking
r5037
Augie Fackler
formatting: blacken the codebase...
r43346 @command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"record",
Augie Fackler
formatting: blacken the codebase...
r43346 # same options as commit + white space diff options
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [c for c in commands.table[b'commit|ci'][1][:] if c[1] != b"interactive"]
Augie Fackler
formatting: blacken the codebase...
r43346 + cmdutil.diffwsopts,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'hg record [OPTION]... [FILE]...'),
Augie Fackler
formatting: blacken the codebase...
r43346 helpcategory=command.CATEGORY_COMMITTING,
)
Bryan O'Sullivan
Add record extension, giving darcs-like interactive hunk picking
r5037 def record(ui, repo, *pats, **opts):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """interactively select changes to commit
Bryan O'Sullivan
record: improve docs, improve prompts
r5154
Martin Geisler
Use hg role in help strings
r10973 If a list of files is omitted, all changes reported by :hg:`status`
Martin Geisler
record: wrap docstrings at 70 characters
r9272 will be candidates for recording.
Bryan O'Sullivan
record: improve docs, improve prompts
r5154
Martin Geisler
Use hg role in help strings
r10973 See :hg:`help dates` for a list of formats valid for -d/--date.
Thomas Arendsen Hein
Document log date ranges and mention 'hg help dates' for all commands (issue998)
r6163
eloimorlaas
record: update help to describe ui.interface...
r31065 If using the text interface (see :hg:`help config`),
you will be prompted for whether to record changes to each
Martin Geisler
record: wrap docstrings at 70 characters
r9272 modified file, and for files with multiple changes, for each
change to use. For each query, the following responses are
possible::
Bryan O'Sullivan
record: improve docs, improve prompts
r5154
Martin Geisler
commands: use minirst parser when displaying help
r9157 y - record this change
n - skip this change
A. S. Budden
record: allow splitting of hunks by manually editing patches...
r16324 e - edit this change manually
Bryan O'Sullivan
record: improve docs, improve prompts
r5154
Martin Geisler
commands: use minirst parser when displaying help
r9157 s - skip remaining changes to this file
f - record remaining changes to this file
Bryan O'Sullivan
record: improve docs, improve prompts
r5154
Martin Geisler
commands: use minirst parser when displaying help
r9157 d - done, skip remaining changes and files
a - record all changes to all remaining files
q - quit, recording no changes
Bryan O'Sullivan
record: improve docs, improve prompts
r5154
Nicolas Dumazet
record: check that we are not committing a merge before patch selection...
r11237 ? - display help
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 This command is not available when committing a merge."""
Bryan O'Sullivan
Add record extension, giving darcs-like interactive hunk picking
r5037
FUJIWARA Katsunori
record: omit meaningless 'commit' suggestion at 'hg commit -i'...
r25796 if not ui.interactive():
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'running non-interactively, use %s instead') % b'commit'
Augie Fackler
formatting: blacken the codebase...
r43346 )
FUJIWARA Katsunori
record: omit meaningless 'commit' suggestion at 'hg commit -i'...
r25796
Augie Fackler
cleanup: remove pointless r-prefixes on double-quoted strings...
r43809 opts["interactive"] = True
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 overrides = {(b'experimental', b'crecord'): False}
with ui.configoverride(overrides, b'record'):
Philippe Pepiot
record: return code from underlying commit
r30158 return commands.commit(ui, repo, *pats, **opts)
Kirill Smelkov
hg qrecord -- like record, but for mq...
r5830
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Mackall
record: use command wrapper properly for qnew/qrefresh (issue3001)
r15184 def qrefresh(origfn, ui, repo, *pats, **opts):
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 if not opts['interactive']:
Matt Mackall
record: use command wrapper properly for qnew/qrefresh (issue3001)
r15184 return origfn(ui, repo, *pats, **opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 mq = extensions.find(b'mq')
Idan Kamara
record: add qrefresh -i/--interactive...
r14426
def committomq(ui, repo, *pats, **opts):
# At this point the working copy contains only changes that
# were accepted. All other changes were reverted.
# We can't pass *pats here since qrefresh will undo all other
# changed files in the patch that aren't in pats.
mq.refresh(ui, repo, **opts)
# backup all changed files
Augie Fackler
formatting: blacken the codebase...
r43346 cmdutil.dorecord(
ui, repo, committomq, None, True, cmdutil.recordfilter, *pats, **opts
)
Kirill Smelkov
hg qrecord -- like record, but for mq...
r5830
Gregory Szorc
record: declare commands using decorator
r21251 # This command registration is replaced during uisetup().
Augie Fackler
formatting: blacken the codebase...
r43346 @command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'qrecord',
Gregory Szorc
record: define inferrepo in command decorator
r21787 [],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'hg qrecord [OPTION]... PATCH [FILE]...'),
rdamazio@google.com
help: assigning categories to existing commands...
r40329 helpcategory=command.CATEGORY_COMMITTING,
Augie Fackler
formatting: blacken the codebase...
r43346 inferrepo=True,
)
Kirill Smelkov
qrecord: record complements commit, so qrecord should complement qnew...
r5932 def qrecord(ui, repo, patch, *pats, **opts):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """interactively record a new patch
Kirill Smelkov
hg qrecord -- like record, but for mq...
r5830
Martin Geisler
Use hg role in help strings
r10973 See :hg:`help qnew` & :hg:`help record` for more information and
Martin Geisler
record: wrap docstrings at 70 characters
r9272 usage.
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return _qrecord(b'qnew', ui, repo, patch, *pats, **opts)
Kirill Smelkov
hg qrecord -- like record, but for mq...
r5830
Augie Fackler
formatting: blacken the codebase...
r43346
FUJIWARA Katsunori
record: omit meaningless 'qnew' suggestion at 'hg qnew -i'...
r25797 def _qrecord(cmdsuggest, ui, repo, patch, *pats, **opts):
Kirill Smelkov
hg qrecord -- like record, but for mq...
r5830 try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 mq = extensions.find(b'mq')
Kirill Smelkov
hg qrecord -- like record, but for mq...
r5830 except KeyError:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b"'mq' extension not loaded"))
Kirill Smelkov
hg qrecord -- like record, but for mq...
r5830
Idan Kamara
record: check patch name is valid before prompting in qrecord
r14424 repo.mq.checkpatchname(patch)
Dan Villiom Podlaski Christiansen
record: function variable naming & signature cleanup....
r10323 def committomq(ui, repo, *pats, **opts):
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 opts['checkname'] = False
Kirill Smelkov
qrecord: record complements commit, so qrecord should complement qnew...
r5932 mq.new(ui, repo, patch, *pats, **opts)
Kirill Smelkov
hg qrecord -- like record, but for mq...
r5830
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 overrides = {(b'experimental', b'crecord'): False}
with ui.configoverride(overrides, b'record'):
Navaneeth Suresh
mq: disable qrecord during histedit (issue5981)...
r41956 cmdutil.checkunfinished(repo)
Augie Fackler
formatting: blacken the codebase...
r43346 cmdutil.dorecord(
ui,
repo,
committomq,
cmdsuggest,
False,
cmdutil.recordfilter,
*pats,
**opts
)
Kirill Smelkov
record: refactor record into generic record driver...
r5827
Matt Mackall
record: use command wrapper properly for qnew/qrefresh (issue3001)
r15184 def qnew(origfn, ui, repo, patch, *args, **opts):
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 if opts['interactive']:
FUJIWARA Katsunori
record: omit meaningless 'qnew' suggestion at 'hg qnew -i'...
r25797 return _qrecord(None, ui, repo, patch, *args, **opts)
Matt Mackall
record: use command wrapper properly for qnew/qrefresh (issue3001)
r15184 return origfn(ui, repo, patch, *args, **opts)
Bryan O'Sullivan
Add record extension, giving darcs-like interactive hunk picking
r5037
Martin Geisler
record: use uisetup instead of extsetup to register qrecord...
r9710 def uisetup(ui):
Kirill Smelkov
hg qrecord -- like record, but for mq...
r5830 try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 mq = extensions.find(b'mq')
Kirill Smelkov
hg qrecord -- like record, but for mq...
r5830 except KeyError:
return
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 cmdtable[b"qrecord"] = (
Augie Fackler
cleanup: use () to wrap long lines instead of \...
r41925 qrecord,
# same options as qnew, but copy them so we don't get
# -i/--interactive for qrecord and add white space diff options
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 mq.cmdtable[b'qnew'][1][:] + cmdutil.diffwsopts,
_(b'hg qrecord [OPTION]... PATCH [FILE]...'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Idan Kamara
record: add qrefresh -i/--interactive...
r14426
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _wrapcmd(b'qnew', mq.cmdtable, qnew, _(b"interactively record a new patch"))
Augie Fackler
formatting: blacken the codebase...
r43346 _wrapcmd(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'qrefresh',
Augie Fackler
formatting: blacken the codebase...
r43346 mq.cmdtable,
qrefresh,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"interactively select changes to refresh"),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Idan Kamara
record: add qrefresh -i/--interactive...
r14426
def _wrapcmd(cmd, table, wrapfn, msg):
Matt Mackall
record: use command wrapper properly for qnew/qrefresh (issue3001)
r15184 entry = extensions.wrapcommand(table, cmd, wrapfn)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 entry[1].append((b'i', b'interactive', None, msg))