summaryrefslogtreecommitdiff
path: root/coverage/sqldata.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2020-10-11 11:12:04 -0400
committerNed Batchelder <ned@nedbatchelder.com>2020-10-11 11:12:04 -0400
commit3274cbad045d9ee2e67384564d772a019cad0c9e (patch)
tree350c4c9b6ca9595b2d5f162b31077832caa628cf /coverage/sqldata.py
parentae35c27be0062721c82f1967e9eb7d6f041e5258 (diff)
downloadpython-coveragepy-git-3274cbad045d9ee2e67384564d772a019cad0c9e.tar.gz
Fix --source performance regression. #1037
Diffstat (limited to 'coverage/sqldata.py')
-rw-r--r--coverage/sqldata.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/coverage/sqldata.py b/coverage/sqldata.py
index b8ee8853..702bd42b 100644
--- a/coverage/sqldata.py
+++ b/coverage/sqldata.py
@@ -167,7 +167,8 @@ class CoverageData(SimpleReprMixin):
To record data for contexts, use :meth:`set_context` to set a context to
be used for subsequent :meth:`add_lines` and :meth:`add_arcs` calls.
- To add a source file without any measured data, use :meth:`touch_file`.
+ To add a source file without any measured data, use :meth:`touch_file`,
+ or :meth:`touch_files` for a list of such files.
Write the data to its file with :meth:`write`.
@@ -536,16 +537,26 @@ class CoverageData(SimpleReprMixin):
`plugin_name` is the name of the plugin responsible for this file. It is used
to associate the right filereporter, etc.
"""
+ self.touch_files([filename], plugin_name)
+
+ def touch_files(self, filenames, plugin_name=""):
+ """Ensure that `filenames` appear in the data, empty if needed.
+
+ `plugin_name` is the name of the plugin responsible for these files. It is used
+ to associate the right filereporter, etc.
+ """
if self._debug.should('dataop'):
- self._debug.write("Touching %r" % (filename,))
+ self._debug.write("Touching %r" % (filenames,))
self._start_using()
- if not self._has_arcs and not self._has_lines:
- raise CoverageException("Can't touch files in an empty CoverageData")
-
- self._file_id(filename, add=True)
- if plugin_name:
- # Set the tracer for this file
- self.add_file_tracers({filename: plugin_name})
+ with self._connect(): # Use this to get one transaction.
+ if not self._has_arcs and not self._has_lines:
+ raise CoverageException("Can't touch files in an empty CoverageData")
+
+ for filename in filenames:
+ self._file_id(filename, add=True)
+ if plugin_name:
+ # Set the tracer for this file
+ self.add_file_tracers({filename: plugin_name})
def update(self, other_data, aliases=None):
"""Update this data with data from several other :class:`CoverageData` instances.