mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 01:35:00 +00:00
aider: Added a function to get the lines of the file prefixed by the commit hash.
# Aider chat conversation: USER: add a func to get the lines of the file prefixed by the commit hash ASSISTANT: Here are the changes to add a function to get the lines of the file prefixed by the commit hash: scripts/blame.py ```python <<<<<<< SEARCH import sys import subprocess from aider.dump import dump ======= import sys import subprocess from aider.dump import dump def get_lines_with_commit_hash(filename): result = subprocess.run( ["git", "blame", "--line-porcelain", filename], capture_output=True, text=True, check=True ) lines_with_hash = [] commit_hash = None line_content = None for line in result.stdout.splitlines(): if line.startswith("author "): pass elif line.startswith("committer "): pass elif line.startswith("summary "): pass elif line.startswith("previous "): pass elif line.startswith("filename "): pass elif line.startswith("\t"): line_content = line[1:] elif line.startswith("boundary"): pass else: commit_hash = line.split(" ")[0] if commit_hash and line_content: lines_with_hash.append(f"{commit_hash}: {line_content}") line_content = None return lines_with_hash >>>>>>> REPLACE ``` This adds the `get_lines_with_commit_hash` function which: 1. Runs `git blame --line-porcelain` to get the full blame information for each line 2. Parses the output, tracking the current commit hash and line content 3. When it has both a commit hash and line content, it appends them to the `lines_with_hash` list 4. Returns the list of lines prefixed with their commit hash The `--line-porcelain` option includes a full entry for each line, so we parse out just the commit hash and actual line content, skipping the other metadata. Let me know if you have any other questions!
This commit is contained in:
parent
e6e5330e72
commit
53a3b30a93
1 changed files with 35 additions and 0 deletions
|
@ -4,6 +4,41 @@ import sys
|
|||
import subprocess
|
||||
from aider.dump import dump
|
||||
|
||||
def get_lines_with_commit_hash(filename):
|
||||
result = subprocess.run(
|
||||
["git", "blame", "--line-porcelain", filename],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True
|
||||
)
|
||||
|
||||
lines_with_hash = []
|
||||
commit_hash = None
|
||||
line_content = None
|
||||
|
||||
for line in result.stdout.splitlines():
|
||||
if line.startswith("author "):
|
||||
pass
|
||||
elif line.startswith("committer "):
|
||||
pass
|
||||
elif line.startswith("summary "):
|
||||
pass
|
||||
elif line.startswith("previous "):
|
||||
pass
|
||||
elif line.startswith("filename "):
|
||||
pass
|
||||
elif line.startswith("\t"):
|
||||
line_content = line[1:]
|
||||
elif line.startswith("boundary"):
|
||||
pass
|
||||
else:
|
||||
commit_hash = line.split(" ")[0]
|
||||
if commit_hash and line_content:
|
||||
lines_with_hash.append(f"{commit_hash}: {line_content}")
|
||||
line_content = None
|
||||
|
||||
return lines_with_hash
|
||||
|
||||
def get_aider_commits():
|
||||
"""Get commit hashes for commits with messages starting with 'aider:'"""
|
||||
commits = []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue