mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 09:44:59 +00:00
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:".
This commit is contained in:
parent
522af186f9
commit
78cc355d58
1 changed files with 41 additions and 0 deletions
41
scripts/blame.py
Normal file
41
scripts/blame.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
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()
|
Loading…
Add table
Add a link
Reference in a new issue