MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / countUnifiedDiffStats

Function countUnifiedDiffStats

src/utils/git-diff-stats.ts:8–43  ·  view source on GitHub ↗
(diff: string)

Source from the content-addressed store, hash-verified

6}
7
8export function countUnifiedDiffStats(diff: string): {
9 additions: number;
10 deletions: number;
11} {
12 let additions = 0;
13 let deletions = 0;
14 let inHunk = false;
15
16 for (const line of diff.split("\n")) {
17 if (line.startsWith("diff --git") || line.startsWith("index ")) {
18 inHunk = false;
19 continue;
20 }
21
22 if (line.startsWith("@@")) {
23 inHunk = true;
24 continue;
25 }
26
27 if (!inHunk) {
28 if (line.startsWith("---") || line.startsWith("+++")) {
29 continue;
30 }
31 }
32
33 if (inHunk) {
34 if (line.startsWith("+")) {
35 additions += 1;
36 } else if (line.startsWith("-")) {
37 deletions += 1;
38 }
39 }
40 }
41
42 return { additions, deletions };
43}
44
45function countTextDiffStats(
46 original: string,

Callers 2

countGitChangeDiffStatsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected