MCPcopy
hub / github.com/codeaashu/claude-code / countLinesChanged

Function countLinesChanged

src/utils/diff.ts:49–79  ·  view source on GitHub ↗
(
  patch: StructuredPatchHunk[],
  newFileContent?: string,
)

Source from the content-addressed store, hash-verified

47 * @param newFileContent Optional content string for new files
48 */
49export function countLinesChanged(
50 patch: StructuredPatchHunk[],
51 newFileContent?: string,
52): void {
53 let numAdditions = 0
54 let numRemovals = 0
55
56 if (patch.length === 0 && newFileContent) {
57 // For new files, count all lines as additions
58 numAdditions = newFileContent.split(/\r?\n/).length
59 } else {
60 numAdditions = patch.reduce(
61 (acc, hunk) => acc + count(hunk.lines, _ => _.startsWith('+')),
62 0,
63 )
64 numRemovals = patch.reduce(
65 (acc, hunk) => acc + count(hunk.lines, _ => _.startsWith('-')),
66 0,
67 )
68 }
69
70 addToTotalLinesChanged(numAdditions, numRemovals)
71
72 getLocCounter()?.add(numAdditions, { type: 'added' })
73 getLocCounter()?.add(numRemovals, { type: 'removed' })
74
75 logEvent('tengu_file_changed', {
76 lines_added: numAdditions,
77 lines_removed: numRemovals,
78 })
79}
80
81export function getPatchFromContents({
82 filePath,

Callers 2

callFunction · 0.85
callFunction · 0.85

Calls 5

countFunction · 0.85
addToTotalLinesChangedFunction · 0.85
getLocCounterFunction · 0.85
logEventFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected