From 13318219dbfdfeb4e6dd7d417f23a0e1ac826b33 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Tue, 26 Nov 2024 10:45:08 -0800 Subject: [PATCH] feat: add YAML update capability to blame.py for --all-since --- scripts/blame.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/scripts/blame.py b/scripts/blame.py index 629cb0cf8..0c1a84457 100755 --- a/scripts/blame.py +++ b/scripts/blame.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import argparse +import os import subprocess import sys from collections import defaultdict @@ -143,8 +144,31 @@ def main(): return if args.all_since: - results = process_all_tags_since(args.start_tag) - yaml_output = yaml.dump(results, sort_keys=True) + new_results = process_all_tags_since(args.start_tag) + + # If output file exists, read and update it + existing_results = [] + if args.output and os.path.exists(args.output): + with open(args.output, 'r') as f: + existing_results = yaml.safe_load(f) or [] + + # Create a map of start_tag->end_tag to result for existing entries + existing_map = {(r['start_tag'], r['end_tag']): i for i, r in enumerate(existing_results)} + + # Update or append new results + for new_result in new_results: + key = (new_result['start_tag'], new_result['end_tag']) + if key in existing_map: + # Replace existing entry + existing_results[existing_map[key]] = new_result + else: + # Append new entry + existing_results.append(new_result) + + # Sort results by start_tag + existing_results.sort(key=lambda x: semver.Version.parse(x['start_tag'][1:])) + + yaml_output = yaml.dump(existing_results, sort_keys=True) else: all_file_counts, grand_total, total_lines, aider_total, aider_percentage, end_date = blame( args.start_tag, args.end_tag