MCPcopy Create free account
hub / github.com/banga/git-split-diffs / iterFormatCombinedDiffHunkUnified

Function iterFormatCombinedDiffHunkUnified

src/iterFormatHunkUnified.ts:103–135  ·  view source on GitHub ↗
(
    context: Context,
    hunkParts: HunkPart[],
    lineChanges: (Change[] | null)[]
)

Source from the content-addressed store, hash-verified

101 * --cc or --combined options, which are defaults for merge commits.
102 */
103export async function* iterFormatCombinedDiffHunkUnified(
104 context: Context,
105 hunkParts: HunkPart[],
106 lineChanges: (Change[] | null)[]
107): AsyncIterable<FormattedString> {
108 const lineWidth = context.SCREEN_WIDTH;
109
110 // The final hunk part shows the current state of the file, so we just
111 // display that with additions and deletions highlighted.
112 const { fileName, lines, startLineNo } = hunkParts[hunkParts.length - 1];
113 let lineNo = startLineNo;
114 let numDeletes = 0;
115
116 for (let i = 0; i < lines.length; i++) {
117 const line = lines[i];
118 const prefix = line?.slice(0, 1) ?? null;
119 if (prefix == '-') {
120 numDeletes++;
121 } else {
122 lineNo -= numDeletes;
123 numDeletes = 0;
124 }
125 yield* formatAndFitHunkLine(
126 context,
127 lineWidth,
128 fileName,
129 lineNo,
130 line,
131 lineChanges[i]
132 );
133 lineNo++;
134 }
135}

Callers 1

iterFormatHunkFunction · 0.90

Calls 2

formatAndFitHunkLineFunction · 0.90
sliceMethod · 0.80

Tested by

no test coverage detected