MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / unified_diff_hunks

Function unified_diff_hunks

src/tool_system/diff_utils.py:11–38  ·  view source on GitHub ↗
(diff_lines: Iterable[str])

Source from the content-addressed store, hash-verified

9
10
11def unified_diff_hunks(diff_lines: Iterable[str]) -> list[dict]:
12 hunks: list[dict] = []
13 current: dict | None = None
14 for line in diff_lines:
15 m = _HUNK_RE.match(line)
16 if m:
17 if current is not None:
18 hunks.append(current)
19 old_start = int(m.group(1))
20 old_lines = int(m.group(2) or "1")
21 new_start = int(m.group(3))
22 new_lines = int(m.group(4) or "1")
23 current = {
24 "oldStart": old_start,
25 "oldLines": old_lines,
26 "newStart": new_start,
27 "newLines": new_lines,
28 "lines": [],
29 }
30 continue
31 if current is None:
32 continue
33 if line.startswith("---") or line.startswith("+++") or line.startswith("\\ No newline"):
34 continue
35 current["lines"].append(line)
36 if current is not None:
37 hunks.append(current)
38 return hunks
39

Callers 2

_write_callFunction · 0.85
_edit_callFunction · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected