MCPcopy Index your code
hub / github.com/anomalyco/opencode / getRevertDiffFiles

Function getRevertDiffFiles

packages/tui/src/util/revert-diff.ts:3–18  ·  view source on GitHub ↗
(diffText: string)

Source from the content-addressed store, hash-verified

1import { parsePatch } from "diff"
2
3export function getRevertDiffFiles(diffText: string) {
4 if (!diffText) return []
5
6 try {
7 return parsePatch(diffText).map((patch) => {
8 const filename = [patch.newFileName, patch.oldFileName].find((item) => item && item !== "/dev/null") ?? "unknown"
9 return {
10 filename: filename.replace(/^[ab]\//, ""),
11 additions: patch.hunks.reduce((sum, hunk) => sum + hunk.lines.filter((line) => line.startsWith("+")).length, 0),
12 deletions: patch.hunks.reduce((sum, hunk) => sum + hunk.lines.filter((line) => line.startsWith("-")).length, 0),
13 }
14 })
15 } catch {
16 return []
17 }
18}

Callers 2

SessionFunction · 0.90

Calls 2

parsePatchFunction · 0.85
findMethod · 0.65

Tested by

no test coverage detected