aider/scripts
Paul Gauthier 78cc355d58 aider: Marked code lines introduced by commits with messages starting with "aider:".
# Aider chat conversation:

USER: i want to do something like `git blame` but i rather than marking each line with the author i want to mark all the code lines which were introduced from a commit with  a commit message that starts with a specific string: "aider:"

ASSISTANT: To achieve this, we need to:

1. Parse the git log to find commits with messages starting with "aider:".
2. Use `git blame` to find the lines introduced by these commits.
3. Mark these lines in the code.

Here is the implementation:

scripts/blame.py
```python
<<<<<<< SEARCH
=======
import subprocess

def get_aider_commits():
    """Get commit hashes for commits with messages starting with 'aider:'"""
    result = subprocess.run(
        ["git", "log", "--pretty=format:%H %s"],
        capture_output=True,
        text=True,
        check=True
    )
    commits = []
    for line in result.stdout.splitlines():
        commit_hash, commit_message = line.split(" ", 1)
        if commit_message.startswith("aider:"):
            commits.append(commit_hash)
    return commits

def get_blame_lines(commit_hash):
    """Get lines introduced by a specific commit"""
    result = subprocess.run(
        ["git", "blame", "--line-porcelain", commit_hash],
        capture_output=True,
        text=True,
        check=True
    )
    lines = []
    for line in result.stdout.splitlines():
        if line.startswith("author "):
            lines.append(line)
    return lines

def mark_aider_lines():
    """Mark lines introduced by 'aider:' commits"""
    aider_commits = get_aider_commits()
    for commit in aider_commits:
        blame_lines = get_blame_lines(commit)
        for line in blame_lines:
            print(f"AIDER: {line}")

if __name__ == "__main__":
    mark_aider_lines()
>>>>>>> REPLACE
```

This script will:

1. Find all commits with messages starting with "aider:".
2. Use `git blame` to find the lines introduced by these commits.
3. Print these lines prefixed with "AIDER:".
2024-05-24 08:18:30 -07:00
..
blame.py aider: Marked code lines introduced by commits with messages starting with "aider:". 2024-05-24 08:18:30 -07:00
Dockerfile.jekyll moved 2024-05-15 11:00:18 -07:00
jekyll_build.sh renamed dockerfile 2024-05-15 11:29:34 -07:00
jekyll_run.sh moved 2024-05-15 11:00:18 -07:00
versionbump.py aider: Add logic to compare commit dates of main and origin/main and print a message explaining which one is behind. 2023-11-17 15:50:37 -08:00