Initial upload: TermDiagram v0.1.0
This commit is contained in:
35
src/termdiagram/git/diff_analyzer.py
Normal file
35
src/termdiagram/git/diff_analyzer.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
from typing import Dict, Any, Optional
|
||||||
|
from git import Repo
|
||||||
|
|
||||||
|
|
||||||
|
class ArchitectureDiffAnalyzer:
|
||||||
|
def __init__(self, repo_path: str):
|
||||||
|
self.repo_path = repo_path
|
||||||
|
self.repo: Optional[Repo] = None
|
||||||
|
|
||||||
|
def initialize(self) -> bool:
|
||||||
|
try:
|
||||||
|
self.repo = Repo(self.repo_path)
|
||||||
|
return not self.repo.bare
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def get_change_report(self, old_commit: str, new_commit: str) -> str:
|
||||||
|
if not self.repo:
|
||||||
|
if not self.initialize():
|
||||||
|
return "Error: Not a git repository"
|
||||||
|
|
||||||
|
try:
|
||||||
|
old_tree = self.repo.commit(old_commit).tree
|
||||||
|
new_tree = self.repo.commit(new_commit).tree
|
||||||
|
|
||||||
|
diffs = old_tree.diff(new_tree)
|
||||||
|
|
||||||
|
report = [f"Architecture changes from {old_commit} to {new_commit}", "=" * 60]
|
||||||
|
|
||||||
|
for diff in diffs:
|
||||||
|
report.append(f" {diff.a_path} -> {diff.b_path}")
|
||||||
|
|
||||||
|
return "\n".join(report)
|
||||||
|
except Exception as e:
|
||||||
|
return f"Error comparing commits: {e}"
|
||||||
Reference in New Issue
Block a user