MCPcopy Index your code
hub / github.com/HelloZeroNet/ZeroNet / diff

Function diff

src/util/Diff.py:10–30  ·  view source on GitHub ↗
(old, new, limit=False)

Source from the content-addressed store, hash-verified

8
9
10def diff(old, new, limit=False):
11 matcher = difflib.SequenceMatcher(None, old, new)
12 actions = []
13 size = 0
14 for tag, old_from, old_to, new_from, new_to in matcher.get_opcodes():
15 if tag == "insert":
16 new_line = new[new_from:new_to]
17 actions.append(("+", new_line))
18 size += sum(map(len, new_line))
19 elif tag == "equal":
20 actions.append(("=", sumLen(old[old_from:old_to])))
21 elif tag == "delete":
22 actions.append(("-", sumLen(old[old_from:old_to])))
23 elif tag == "replace":
24 actions.append(("-", sumLen(old[old_from:old_to])))
25 new_lines = new[new_from:new_to]
26 actions.append(("+", new_lines))
27 size += sumLen(new_lines)
28 if limit and size > limit:
29 return False
30 return actions
31
32
33def patch(old_f, actions):

Callers

nothing calls this directly

Calls 2

sumFunction · 0.85
sumLenFunction · 0.85

Tested by

no test coverage detected