Unified diff (git diff format) between two strings.
(
original: str,
updated: str,
*,
filename: str = SKILL_FILENAME,
context: int = 3,
)
| 901 | |
| 902 | # DIFF COMPUTATION & SNAPSHOT |
| 903 | def compute_unified_diff( |
| 904 | original: str, |
| 905 | updated: str, |
| 906 | *, |
| 907 | filename: str = SKILL_FILENAME, |
| 908 | context: int = 3, |
| 909 | ) -> str: |
| 910 | """Unified diff (git diff format) between two strings.""" |
| 911 | diff_lines = difflib.unified_diff( |
| 912 | original.splitlines(keepends=True), |
| 913 | updated.splitlines(keepends=True), |
| 914 | fromfile=f"a/{filename}", |
| 915 | tofile=f"b/{filename}", |
| 916 | n=context, |
| 917 | ) |
| 918 | return "".join(diff_lines) |
| 919 | |
| 920 | def compute_skill_diff(old_dir: Path, new_dir: Path) -> str: |
| 921 | """Compare all files in two skill directories, return combined diff.""" |
no outgoing calls
no test coverage detected