diff --git a/scripts/blame.py b/scripts/blame.py index 18cdc9c1a..3557d3813 100755 --- a/scripts/blame.py +++ b/scripts/blame.py @@ -54,37 +54,46 @@ def get_aider_commits(): -def process(fnames): - aider_commits = get_aider_commits() +def process_fnames(fnames, git_dname): + if not git_dname: + git_dname = "." + + aider_commits = get_aider_commits(git_dname) total_lines = 0 total_aider_lines = 0 for fname in fnames: - num_lines, num_aider_lines = get_lines_with_commit_hash(fname, aider_commits) + num_lines, num_aider_lines = get_lines_with_commit_hash(fname, aider_commits, git_dname) total_lines += num_lines total_aider_lines += num_aider_lines percent_modified = (num_aider_lines / num_lines) * 100 if num_lines > 0 else 0 - print(f"{fname}: {num_aider_lines}/{num_lines} lines modified by aider ({percent_modified:.2f}%)") + if not num_aider_lines: + continue + print(f"{fname}: {num_aider_lines}/{num_lines} ({percent_modified:.2f}%)") total_percent_modified = (total_aider_lines / total_lines) * 100 if total_lines > 0 else 0 - print(f"Total: {total_aider_lines}/{total_lines} lines modified by aider ({total_percent_modified:.2f}%)") + print(f"Total: {total_aider_lines}/{total_lines} lines by aider ({total_percent_modified:.2f}%)") + return total_percent_modified + +def process_repo(git_dname=None): + if not git_dname: + git_dname = "." + result = subprocess.run( + ["git", "-C", git_dname, "ls-files"], + capture_output=True, + text=True, + check=True + ) + fnames = [fname for fname in result.stdout.splitlines() if fname.endswith('.py')] + process_fnames(fnames, git_dname) def main(): if len(sys.argv) < 2: - result = subprocess.run( - ["git", "ls-files"], - capture_output=True, - text=True, - check=True - ) - fnames = [fname for fname in result.stdout.splitlines() if fname.endswith('.py')] - if not fnames: - print("No Python files found in the repository.") - sys.exit(1) + process_repo() else: fnames = sys.argv[1:] - process(sys.argv[1:]) + process_fnames(fnames) if __name__ == "__main__":