MCPcopy Index your code
hub / github.com/21st-dev/1code / parseDiffNumstat

Function parseDiffNumstat

src/main/lib/git/utils/parse-status.ts:122–152  ·  view source on GitHub ↗
(
	numstatOutput: string,
)

Source from the content-addressed store, hash-verified

120}
121
122export function parseDiffNumstat(
123 numstatOutput: string,
124): Map<string, { additions: number; deletions: number }> {
125 const stats = new Map<string, { additions: number; deletions: number }>();
126
127 for (const line of numstatOutput.trim().split("\n")) {
128 if (!line.trim()) continue;
129
130 // Format: additions\tdeletions\tfilepath
131 // For renames: additions\tdeletions\toldpath => newpath
132 const [addStr, delStr, ...pathParts] = line.split("\t");
133 const rawPath = pathParts.join("\t");
134 if (!rawPath) continue;
135
136 const additions = addStr === "-" ? 0 : Number.parseInt(addStr, 10) || 0;
137 const deletions = delStr === "-" ? 0 : Number.parseInt(delStr, 10) || 0;
138 const statEntry = { additions, deletions };
139
140 const renameMatch = rawPath.match(/^(.+) => (.+)$/);
141 if (renameMatch) {
142 const oldPath = renameMatch[1];
143 const newPath = renameMatch[2];
144 stats.set(newPath, statEntry);
145 stats.set(oldPath, statEntry);
146 } else {
147 stats.set(rawPath, statEntry);
148 }
149 }
150
151 return stats;
152}
153
154export function parseNameStatus(nameStatusOutput: string): ChangedFile[] {
155 const files: ChangedFile[] = [];

Callers 1

applyNumstatToFilesFunction · 0.90

Calls 1

setMethod · 0.45

Tested by

no test coverage detected