21
21
import zlib
22
22
23
23
from typing import (
24
- cast , Any , Collection , Mapping ,
24
+ cast , Any , Callable , Collection , Mapping ,
25
25
Sequence ,
26
26
)
27
27
28
28
from coverage .debug import NoDebugging , auto_repr
29
29
from coverage .exceptions import CoverageException , DataError
30
- from coverage .files import PathAliases
31
30
from coverage .misc import file_be_gone , isolate_module
32
31
from coverage .numbits import numbits_to_nums , numbits_union , nums_to_numbits
33
32
from coverage .sqlitedb import SqliteDb
@@ -647,12 +646,16 @@ def purge_files(self, filenames: Collection[str]) -> None:
647
646
continue
648
647
con .execute_void (sql , (file_id ,))
649
648
650
- def update (self , other_data : CoverageData , aliases : PathAliases | None = None ) -> None :
651
- """Update this data with data from several other :class:`CoverageData` instances.
649
+ def update (
650
+ self ,
651
+ other_data : CoverageData ,
652
+ map_path : Callable [[str ], str ] | None = None ,
653
+ ) -> None :
654
+ """Update this data with data from another :class:`CoverageData`.
652
655
653
- If `aliases ` is provided, it's a `PathAliases` object that is used to
654
- re-map paths to match the local machine's. Note: `aliases ` is None
655
- only when called directly from the test suite.
656
+ If `map_path ` is provided, it's a function that re-map paths to match
657
+ the local machine's. Note: `map_path ` is None only when called
658
+ directly from the test suite.
656
659
657
660
"""
658
661
if self ._debug .should ("dataop" ):
@@ -664,7 +667,7 @@ def update(self, other_data: CoverageData, aliases: PathAliases | None = None) -
664
667
if self ._has_arcs and other_data ._has_lines :
665
668
raise DataError ("Can't combine line data with arc data" )
666
669
667
- aliases = aliases or PathAliases ( )
670
+ map_path = map_path or ( lambda p : p )
668
671
669
672
# Force the database we're writing to to exist before we start nesting contexts.
670
673
self ._start_using ()
@@ -674,7 +677,7 @@ def update(self, other_data: CoverageData, aliases: PathAliases | None = None) -
674
677
with other_data ._connect () as con :
675
678
# Get files data.
676
679
with con .execute ("select path from file" ) as cur :
677
- files = {path : aliases . map (path ) for (path ,) in cur }
680
+ files = {path : map_path (path ) for (path ,) in cur }
678
681
679
682
# Get contexts data.
680
683
with con .execute ("select context from context" ) as cur :
@@ -729,7 +732,7 @@ def update(self, other_data: CoverageData, aliases: PathAliases | None = None) -
729
732
"inner join file on file.id = tracer.file_id" ,
730
733
) as cur :
731
734
this_tracers .update ({
732
- aliases . map (path ): tracer
735
+ map_path (path ): tracer
733
736
for path , tracer in cur
734
737
})
735
738
@@ -768,7 +771,21 @@ def update(self, other_data: CoverageData, aliases: PathAliases | None = None) -
768
771
# and context strings with integer ids. Then use the efficient
769
772
# `executemany()` to insert all rows at once.
770
773
771
- # Get line data.
774
+ if arcs :
775
+ self ._choose_lines_or_arcs (arcs = True )
776
+
777
+ arc_rows = (
778
+ (file_ids [file ], context_ids [context ], fromno , tono )
779
+ for file , context , fromno , tono in arcs
780
+ )
781
+
782
+ # Write the combined data.
783
+ con .executemany_void (
784
+ "insert or ignore into arc " +
785
+ "(file_id, context_id, fromno, tono) values (?, ?, ?, ?)" ,
786
+ arc_rows ,
787
+ )
788
+
772
789
if lines :
773
790
self ._choose_lines_or_arcs (lines = True )
774
791
@@ -779,7 +796,7 @@ def update(self, other_data: CoverageData, aliases: PathAliases | None = None) -
779
796
"inner join context on context.id = line_bits.context_id" ,
780
797
) as cur :
781
798
for path , context , numbits in cur :
782
- key = (aliases . map (path ), context )
799
+ key = (aliases_map (path ), context )
783
800
if key in lines :
784
801
lines [key ] = numbits_union (lines [key ], numbits )
785
802
@@ -792,21 +809,6 @@ def update(self, other_data: CoverageData, aliases: PathAliases | None = None) -
792
809
],
793
810
)
794
811
795
- if arcs :
796
- self ._choose_lines_or_arcs (arcs = True )
797
-
798
- arc_rows = (
799
- (file_ids [file ], context_ids [context ], fromno , tono )
800
- for file , context , fromno , tono in arcs
801
- )
802
-
803
- # Write the combined data.
804
- con .executemany_void (
805
- "insert or ignore into arc " +
806
- "(file_id, context_id, fromno, tono) values (?, ?, ?, ?)" ,
807
- arc_rows ,
808
- )
809
-
810
812
con .executemany_void (
811
813
"insert or ignore into tracer (file_id, tracer) values (?, ?)" ,
812
814
((file_ids [filename ], tracer ) for filename , tracer in tracer_map .items ()),
0 commit comments