diff --git a/seal5/flow.py b/seal5/flow.py index 73d25af9..fc1e7068 100644 --- a/seal5/flow.py +++ b/seal5/flow.py @@ -764,6 +764,7 @@ def patch(self, verbose: bool = False, stages: List[PatchStage] = None, force: b stages = list(map(PatchStage, range(PatchStage.PHASE_5 + 1))) assert len(stages) > 0 patches_per_stage = self.collect_patches() + stages_metrics = {} for stage in stages: logger.info("Current stage: %s", stage) patches = patches_per_stage.get(stage, []) @@ -779,11 +780,23 @@ def patch(self, verbose: bool = False, stages: List[PatchStage] = None, force: b # author = git_.get_author(self.settings.git) # self.repo.create_tag(tag_name, message=tag_msg, force=True, author=author) self.repo.create_tag(tag_name, message=tag_msg, force=True) + base_tag = f"seal5-{self.name}-base" + if int(stage) > 0: + prev_tag = f"seal5-{self.name}-stage{int(stage)-1}" + else: + prev_tag = base_tag + n_files_changed, n_insertions, n_deletions = inject_patches.analyze_diff(self.repo, cur=tag_name, base=prev_tag) + stage_metrics = {} + stage_metrics["n_files_changed"] = n_files_changed + stage_metrics["n_insertions"] = n_insertions + stage_metrics["n_deletions"] = n_deletions + stages_metrics[PatchStage(stage).name] = stage_metrics end = time.time() diff = end - start metrics["start"] = start metrics["end"] = end metrics["time_s"] = diff + metrics["stages"] = stages_metrics self.settings.metrics.append({"patch": metrics}) self.settings.save() logger.info("Completed application of Seal5 patches") diff --git a/seal5/tools/inject_patches.py b/seal5/tools/inject_patches.py index b0be4091..1256416b 100644 --- a/seal5/tools/inject_patches.py +++ b/seal5/tools/inject_patches.py @@ -20,10 +20,12 @@ import os import argparse from pathlib import Path +from typing import Optional from email.utils import formatdate import yaml +from seal5 import utils from seal5.logging import get_logger logger = get_logger() @@ -230,6 +232,35 @@ def process_arguments(): return args +def analyze_diff(repo, base: str, cur: Optional[str] = None): + args = ["git", "diff", "--shortstat"] + args += [base] + if cur is not None: + args += [cur] + out = utils.exec_getout( + *args, + cwd=repo.working_tree_dir, + print_func=lambda *args, **kwargs: None, + live=False, + ) + n_files_changed = 0 + n_insertions = 0 + n_deletions = 0 + for x in out.split(","): + x = x.strip() + if len(x) == 0: + continue + val, key = x.split(" ", 1) + val = int(val) + if "files changed" in key: + n_files_changed = val + elif "insertions" in key: + n_insertions = val + elif "deletions" in key: + n_deletions = val + return n_files_changed, n_insertions, n_deletions + + def main(): """Main entry point.""" args = process_arguments()