MCPcopy
hub / github.com/Aider-AI/aider / apply_edits

Method apply_edits

aider/coders/udiff_coder.py:69–118  ·  view source on GitHub ↗
(self, edits)

Source from the content-addressed store, hash-verified

67 return edits
68
69 def apply_edits(self, edits):
70 seen = set()
71 uniq = []
72 for path, hunk in edits:
73 hunk = normalize_hunk(hunk)
74 if not hunk:
75 continue
76
77 this = [path + "\n"] + hunk
78 this = "".join(this)
79
80 if this in seen:
81 continue
82 seen.add(this)
83
84 uniq.append((path, hunk))
85
86 errors = []
87 for path, hunk in uniq:
88 full_path = self.abs_root_path(path)
89 content = self.io.read_text(full_path)
90
91 original, _ = hunk_to_before_after(hunk)
92
93 try:
94 content = do_replace(full_path, content, hunk)
95 except SearchTextNotUnique:
96 errors.append(
97 not_unique_error.format(
98 path=path, original=original, num_lines=len(original.splitlines())
99 )
100 )
101 continue
102
103 if not content:
104 errors.append(
105 no_match_error.format(
106 path=path, original=original, num_lines=len(original.splitlines())
107 )
108 )
109 continue
110
111 # SUCCESS!
112 self.io.write_text(full_path, content)
113
114 if errors:
115 errors = "\n\n".join(errors)
116 if len(errors) < len(uniq):
117 errors += other_hunks_applied
118 raise ValueError(errors)
119
120
121def do_replace(fname, content, hunk):

Callers

nothing calls this directly

Calls 6

normalize_hunkFunction · 0.85
hunk_to_before_afterFunction · 0.85
write_textMethod · 0.80
do_replaceFunction · 0.70
abs_root_pathMethod · 0.45
read_textMethod · 0.45

Tested by

no test coverage detected