MCPcopy Index your code
hub / github.com/ds300/patch-package / interpretParsedPatchFile

Function interpretParsedPatchFile

src/patch/parse.ts:301–400  ·  view source on GitHub ↗
(files: FileDeets[])

Source from the content-addressed store, hash-verified

299}
300
301export function interpretParsedPatchFile(files: FileDeets[]): ParsedPatchFile {
302 const result: ParsedPatchFile = []
303
304 for (const file of files) {
305 const {
306 diffLineFromPath,
307 diffLineToPath,
308 oldMode,
309 newMode,
310 deletedFileMode,
311 newFileMode,
312 renameFrom,
313 renameTo,
314 beforeHash,
315 afterHash,
316 fromPath,
317 toPath,
318 hunks,
319 } = file
320 const type: PatchFilePart["type"] = renameFrom
321 ? "rename"
322 : deletedFileMode
323 ? "file deletion"
324 : newFileMode
325 ? "file creation"
326 : hunks && hunks.length > 0
327 ? "patch"
328 : "mode change"
329
330 let destinationFilePath: string | null = null
331 switch (type) {
332 case "rename":
333 if (!renameFrom || !renameTo) {
334 throw new Error("Bad parser state: rename from & to not given")
335 }
336 result.push({
337 type: "rename",
338 fromPath: renameFrom,
339 toPath: renameTo,
340 })
341 destinationFilePath = renameTo
342 break
343 case "file deletion": {
344 const path = diffLineFromPath || fromPath
345 if (!path) {
346 throw new Error("Bad parse state: no path given for file deletion")
347 }
348 result.push({
349 type: "file deletion",
350 hunk: (hunks && hunks[0]) || null,
351 path,
352 mode: parseFileMode(deletedFileMode!),
353 hash: beforeHash,
354 })
355 break
356 }
357 case "file creation": {
358 const path = diffLineToPath || toPath

Callers 1

parsePatchFileFunction · 0.85

Calls 2

assertNeverFunction · 0.90
parseFileModeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…