From fb717b8786c315b82d2bf96a3065f5c493a490aa Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 24 May 2024 09:43:33 -0700 Subject: [PATCH] aider: Refactored `show_commit_stats` to print out lines added and deleted for each commit and report totals. # Aider chat conversation: USER: do the todp ASSISTANT: To implement the TODO, we need to modify the `show_commit_stats` function to print out the number of lines added and deleted for each commit and report the totals. Here are the *SEARCH/REPLACE* blocks: scripts/blame.py ```python <<<<<<< SEARCH # TODO: print out the number of lines added and deleted for each commit # report totals pass ======= total_added_lines = 0 total_deleted_lines = 0 for commit in commits: result = subprocess.run( ["git", "show", "--stat", "--oneline", commit], capture_output=True, text=True, check=True ) added_lines = 0 deleted_lines = 0 for line in result.stdout.splitlines(): if "insertion" in line: added_lines += int(line.split()[0]) if "deletion" in line: deleted_lines += int(line.split()[0]) total_added_lines += added_lines total_deleted_lines += deleted_lines print(f"Commit {commit}: +{added_lines} -{deleted_lines}") print(f"Total: +{total_added_lines} -{total_deleted_lines}") >>>>>>> REPLACE ``` --- scripts/blame.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/scripts/blame.py b/scripts/blame.py index a23662c41..e5c1dd6b7 100755 --- a/scripts/blame.py +++ b/scripts/blame.py @@ -64,9 +64,31 @@ def get_aider_commits(git_dname): def show_commit_stats(commits): - # TODO: print out the number of lines added and deleted for each commit - # report totals - pass + total_added_lines = 0 + total_deleted_lines = 0 + + for commit in commits: + result = subprocess.run( + ["git", "show", "--stat", "--oneline", commit], + capture_output=True, + text=True, + check=True + ) + + added_lines = 0 + deleted_lines = 0 + for line in result.stdout.splitlines(): + if "insertion" in line: + added_lines += int(line.split()[0]) + if "deletion" in line: + deleted_lines += int(line.split()[0]) + + total_added_lines += added_lines + total_deleted_lines += deleted_lines + + print(f"Commit {commit}: +{added_lines} -{deleted_lines}") + + print(f"Total: +{total_added_lines} -{total_deleted_lines}") def process_fnames(fnames, git_dname): if not git_dname: