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

Function countTextDiffStats

src/utils/git-diff-stats.ts:45–99  ·  view source on GitHub ↗
(
  original: string,
  modified: string,
)

Source from the content-addressed store, hash-verified

43}
44
45function countTextDiffStats(
46 original: string,
47 modified: string,
48): GitDiffLineStats {
49 const originalLines = original.length === 0 ? [] : original.split("\n");
50 const modifiedLines = modified.length === 0 ? [] : modified.split("\n");
51
52 if (originalLines.length === 0) {
53 return { additions: modifiedLines.length, deletions: 0 };
54 }
55
56 if (modifiedLines.length === 0) {
57 return { additions: 0, deletions: originalLines.length };
58 }
59
60 let additions = 0;
61 let deletions = 0;
62 let originalIndex = 0;
63 let modifiedIndex = 0;
64
65 while (
66 originalIndex < originalLines.length ||
67 modifiedIndex < modifiedLines.length
68 ) {
69 const originalLine = originalLines[originalIndex];
70 const modifiedLine = modifiedLines[modifiedIndex];
71
72 if (
73 originalIndex < originalLines.length &&
74 modifiedIndex < modifiedLines.length &&
75 originalLine === modifiedLine
76 ) {
77 originalIndex += 1;
78 modifiedIndex += 1;
79 continue;
80 }
81
82 if (
83 modifiedIndex < modifiedLines.length &&
84 (originalIndex >= originalLines.length ||
85 !originalLines.slice(originalIndex).includes(modifiedLine))
86 ) {
87 additions += 1;
88 modifiedIndex += 1;
89 continue;
90 }
91
92 if (originalIndex < originalLines.length) {
93 deletions += 1;
94 originalIndex += 1;
95 }
96 }
97
98 return { additions, deletions };
99}
100
101export function countGitChangeDiffStats(
102 diff: GitChangeDiff & { diff?: string },

Callers 1

countGitChangeDiffStatsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected