MCPcopy
hub / github.com/desktop/desktop / buildDiff

Function buildDiff

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

Source from the content-addressed store, hash-verified

809}
810
811async function buildDiff(
812 buffer: Buffer,
813 repository: Repository,
814 file: FileChange,
815 newestCommitish: string,
816 oldestCommitish: string,
817 lineEndingsChange?: LineEndingsChange
818): Promise<IDiff> {
819 if (file.status.submoduleStatus !== undefined) {
820 return buildSubmoduleDiff(
821 buffer,
822 repository,
823 file,
824 file.status.submoduleStatus
825 )
826 }
827
828 if (!isValidBuffer(buffer)) {
829 // the buffer's diff is too large to be renderable in the UI
830 return { kind: DiffType.Unrenderable }
831 }
832
833 const diff = diffFromRawDiffOutput(buffer)
834
835 if (isBufferTooLarge(buffer) || isDiffTooLarge(diff)) {
836 // we don't want to render by default
837 // but we keep it as an option by
838 // passing in text and hunks
839 const largeTextDiff: ILargeTextDiff = {
840 kind: DiffType.LargeText,
841 text: diff.contents,
842 hunks: diff.hunks,
843 lineEndingsChange,
844 maxLineNumber: diff.maxLineNumber,
845 hasHiddenBidiChars: diff.hasHiddenBidiChars,
846 }
847
848 return largeTextDiff
849 }
850
851 return convertDiff(
852 repository,
853 file,
854 diff,
855 newestCommitish,
856 oldestCommitish,
857 lineEndingsChange
858 )
859}
860
861/**
862 * Retrieve the binary contents of a blob from the object database

Callers 4

getCommitDiffFunction · 0.85
getBranchMergeBaseDiffFunction · 0.85
getCommitRangeDiffFunction · 0.85
getWorkingDirectoryDiffFunction · 0.85

Calls 6

buildSubmoduleDiffFunction · 0.85
isValidBufferFunction · 0.85
diffFromRawDiffOutputFunction · 0.85
isBufferTooLargeFunction · 0.85
isDiffTooLargeFunction · 0.85
convertDiffFunction · 0.85

Tested by

no test coverage detected