MCPcopy Create free account
hub / github.com/desktop/desktop / convertDiff

Function convertDiff

app/src/lib/git/diff.ts:654–683  ·  view source on GitHub ↗
(
  repository: Repository,
  file: FileChange,
  diff: IRawDiff,
  newestCommitish: string,
  oldestCommitish: string,
  lineEndingsChange?: LineEndingsChange
)

Source from the content-addressed store, hash-verified

652}
653
654export async function convertDiff(
655 repository: Repository,
656 file: FileChange,
657 diff: IRawDiff,
658 newestCommitish: string,
659 oldestCommitish: string,
660 lineEndingsChange?: LineEndingsChange
661): Promise<IDiff> {
662 const extension = Path.extname(file.path).toLowerCase()
663
664 if (diff.isBinary) {
665 // some extension we don't know how to parse, never mind
666 if (!imageFileExtensions.has(extension)) {
667 return {
668 kind: DiffType.Binary,
669 }
670 } else {
671 return getImageDiff(repository, file, newestCommitish, oldestCommitish)
672 }
673 }
674
675 return {
676 kind: DiffType.Text,
677 text: diff.contents,
678 hunks: diff.hunks,
679 lineEndingsChange,
680 maxLineNumber: diff.maxLineNumber,
681 hasHiddenBidiChars: diff.hasHiddenBidiChars,
682 }
683}
684
685/**
686 * Map a given file extension to the related data URL media type

Callers 2

parseDiffFunction · 0.90
buildDiffFunction · 0.85

Calls 1

getImageDiffFunction · 0.85

Tested by

no test coverage detected