reverse method
Create a reversed patch that undoes this patch.
Implementation
PatchSet reverse() {
final reversed = hunks.map((h) {
final lines = h.lines.map((l) {
final newType = switch (l.type) {
DiffType.add => DiffType.remove,
DiffType.remove => DiffType.add,
DiffType.context => DiffType.context,
};
return LineDiff(
lineNumber: l.lineNumber,
content: l.content,
type: newType,
);
}).toList();
return Hunk(
oldStart: h.newStart,
oldCount: h.newCount,
newStart: h.oldStart,
newCount: h.oldCount,
lines: lines,
);
}).toList();
return PatchSet(hunks: reversed);
}