diff options
author | Jelmer Vernooij <jelmer@jelmer.uk> | 2021-09-18 16:55:06 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@jelmer.uk> | 2021-09-18 16:55:06 +0100 |
commit | 90cc92891309e192f6c6ba2665badac12619a1ed (patch) | |
tree | c6e3e5720f914749799946f40bca3a39b0729f02 /fastimport/processors/info_processor.py | |
parent | 088bc0459e50bbcb948f3317772825859347b014 (diff) | |
parent | 6ed4b196e21974c6bac4323522cd086794618068 (diff) | |
download | python-fastimport-git-upstream.tar.gz |
Import upstream version 0.9.14upstream/0.9.14upstream
Diffstat (limited to 'fastimport/processors/info_processor.py')
-rw-r--r-- | fastimport/processors/info_processor.py | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/fastimport/processors/info_processor.py b/fastimport/processors/info_processor.py index 28c7300..3268e29 100644 --- a/fastimport/processors/info_processor.py +++ b/fastimport/processors/info_processor.py @@ -18,16 +18,14 @@ from __future__ import absolute_import from .. import ( + commands, + processor, reftracker, ) from ..helpers import ( invert_dict, invert_dictset, ) -from fastimport import ( - commands, - processor, - ) import stat @@ -43,8 +41,8 @@ class InfoProcessor(processor.ImportProcessor): """ def __init__(self, params=None, verbose=0, outf=None): - processor.ImportProcessor.__init__(self, params, verbose, - outf=outf) + processor.ImportProcessor.__init__( + self, params, verbose, outf=outf) def pre_process(self): # Init statistics @@ -79,10 +77,13 @@ class InfoProcessor(processor.ImportProcessor): # Dump statistics cmd_names = commands.COMMAND_NAMES fc_names = commands.FILE_COMMAND_NAMES - self._dump_stats_group("Command counts", + self._dump_stats_group( + "Command counts", [(c.decode('utf-8'), self.cmd_counts[c]) for c in cmd_names], str) - self._dump_stats_group("File command counts", - [(c.decode('utf-8'), self.file_cmd_counts[c]) for c in fc_names], str) + self._dump_stats_group( + "File command counts", + [(c.decode('utf-8'), self.file_cmd_counts[c]) for c in fc_names], + str) # Commit stats if self.cmd_counts[b'commit']: @@ -100,7 +101,8 @@ class InfoProcessor(processor.ImportProcessor): 'blobs referenced by SHA': self.sha_blob_references, } self._dump_stats_group("Parent counts", p_items, str) - self._dump_stats_group("Commit analysis", sorted(flags.items()), _found) + self._dump_stats_group( + "Commit analysis", sorted(flags.items()), _found) heads = invert_dictset(self.reftracker.heads) self._dump_stats_group( "Head analysis", @@ -114,10 +116,12 @@ class InfoProcessor(processor.ImportProcessor): # (verbose=2) is specified. The output here for mysql's data can't # be parsed currently so this bit of code needs more work anyhow .. if self.verbose >= 2: - self._dump_stats_group("Rename old paths", + self._dump_stats_group( + "Rename old paths", self.rename_old_paths.items(), len, _iterable_as_config_list) - self._dump_stats_group("Copy source paths", + self._dump_stats_group( + "Copy source paths", self.copy_source_paths.items(), len, _iterable_as_config_list) @@ -126,12 +130,16 @@ class InfoProcessor(processor.ImportProcessor): # In verbose mode, don't list every blob used if self.verbose: del self.blobs['used'] - self._dump_stats_group("Blob usage tracking", - self.blobs.items(), len, _iterable_as_config_list) + self._dump_stats_group( + "Blob usage tracking", + [(k, set([v1.decode() for v1 in v])) + for (k, v) in self.blobs.items()], + len, _iterable_as_config_list) if self.blob_ref_counts: blobs_by_count = invert_dict(self.blob_ref_counts) blob_items = sorted(blobs_by_count.items()) - self._dump_stats_group("Blob reference counts", + self._dump_stats_group( + "Blob reference counts", blob_items, len, _iterable_as_config_list) # Other stats @@ -142,9 +150,9 @@ class InfoProcessor(processor.ImportProcessor): self._dump_stats_group("Reset analysis", reset_stats.items()) def _dump_stats_group(self, title, items, normal_formatter=None, - verbose_formatter=None): + verbose_formatter=None): """Dump a statistics group. - + In verbose mode, do so as a config file so that other processors can load the information if they want to. :param normal_formatter: the callable to apply to the value @@ -210,9 +218,11 @@ class InfoProcessor(processor.ImportProcessor): else: self.sha_blob_references = True elif isinstance(fc, commands.FileRenameCommand): - self.rename_old_paths.setdefault(cmd.id, set()).add(fc.old_path) + self.rename_old_paths.setdefault(cmd.id, set()).add( + fc.old_path) elif isinstance(fc, commands.FileCopyCommand): - self.copy_source_paths.setdefault(cmd.id, set()).add(fc.src_path) + self.copy_source_paths.setdefault(cmd.id, set()).add( + fc.src_path) # Track the heads parents = self.reftracker.track_heads(cmd) @@ -228,7 +238,6 @@ class InfoProcessor(processor.ImportProcessor): # Remember the merges if cmd.merges: - #self.merges.setdefault(cmd.ref, set()).update(cmd.merges) for merge in cmd.merges: if merge in self.merges: self.merges[merge] += 1 @@ -238,7 +247,7 @@ class InfoProcessor(processor.ImportProcessor): def reset_handler(self, cmd): """Process a ResetCommand.""" self.cmd_counts[cmd.name] += 1 - if cmd.ref.startswith('refs/tags/'): + if cmd.ref.startswith(b'refs/tags/'): self.lightweight_tags += 1 else: if cmd.from_ is not None: @@ -254,7 +263,8 @@ class InfoProcessor(processor.ImportProcessor): self.cmd_counts[cmd.name] += 1 feature = cmd.feature_name if feature not in commands.FEATURE_NAMES: - self.warning("feature %s is not supported - parsing may fail" + self.warning( + "feature %s is not supported - parsing may fail" % (feature,)) def _track_blob(self, mark): @@ -270,13 +280,15 @@ class InfoProcessor(processor.ImportProcessor): else: self.blobs['unknown'].add(mark) + def _found(b): """Format a found boolean as a string.""" return ['no', 'found'][b] + def _iterable_as_config_list(s): """Format an iterable as a sequence of comma-separated strings. - + To match what ConfigObj expects, a single item list has a trailing comma. """ items = sorted(s) |