11import { fetchGithubCommitDiff , fetchGithubComparison , fetchGithubPRComparison , type FileStatus , getGithubToken , type GithubDiff } from "./github.svelte" ;
2- import { type StructuredPatch , parsePatch } from "diff" ;
2+ import { type StructuredPatch } from "diff" ;
33import {
44 ConciseDiffViewCachedState ,
55 DEFAULT_THEME_DARK ,
@@ -150,8 +150,7 @@ export type CommonFileDetails = {
150150
151151export type TextFileDetails = CommonFileDetails & {
152152 type : "text" ;
153- patchText : string ;
154- structuredPatch : Promise < StructuredPatch > ;
153+ structuredPatch : StructuredPatch ;
155154} ;
156155
157156export type ImageFileDetails = CommonFileDetails & {
@@ -165,8 +164,7 @@ export function makeTextDetails(fromFile: string, toFile: string, status: FileSt
165164 fromFile,
166165 toFile,
167166 status,
168- patchText,
169- structuredPatch : ( async ( ) => parseSinglePatch ( patchText ) ) ( ) ,
167+ structuredPatch : parseSinglePatch ( patchText ) ,
170168 } ;
171169}
172170
@@ -286,35 +284,20 @@ export function getFileStatusProps(status: FileStatus): FileStatusProps {
286284}
287285
288286export function findHeaderChangeOnlyPatches ( fileDetails : FileDetails [ ] ) {
289- const patchStrings = fileDetails . map ( ( details ) => {
290- if ( details . type === "text" ) {
291- return details . patchText ;
292- }
293- return undefined ;
294- } ) ;
295-
296287 const result : boolean [ ] = [ ] ;
297288
298- for ( let i = 0 ; i < patchStrings . length ; i ++ ) {
299- const patchString = patchStrings [ i ] ;
300- if ( patchString === undefined || patchString . length === 0 ) {
301- result . push ( false ) ;
302- continue ;
303- }
304- // TODO: Parsing twice is wasteful
305- const patches = parsePatch ( patchString ) ;
306- if ( patches . length !== 1 ) {
289+ for ( const details of fileDetails ) {
290+ if ( details . type !== "text" ) {
307291 result . push ( false ) ;
308292 continue ;
309293 }
310- const patch = patches [ 0 ] ;
311- if ( patch . hunks . length === 0 ) {
294+ if ( details . structuredPatch . hunks . length === 0 ) {
312295 result . push ( false ) ;
313296 continue ;
314297 }
315298 let onlyHeaderChanges = true ;
316- for ( let j = 0 ; j < patch . hunks . length ; j ++ ) {
317- if ( hasNonHeaderChanges ( patch . hunks [ j ] . lines ) ) {
299+ for ( let j = 0 ; j < details . structuredPatch . hunks . length ; j ++ ) {
300+ if ( hasNonHeaderChanges ( details . structuredPatch . hunks [ j ] . lines ) ) {
318301 onlyHeaderChanges = false ;
319302 }
320303 }
@@ -368,7 +351,7 @@ export class MultiFileDiffViewerState {
368351
369352 readonly fileTreeFilterDebounced = new Debounced ( ( ) => this . fileTreeFilter , 500 ) ;
370353 readonly searchQueryDebounced = new Debounced ( ( ) => this . searchQuery , 500 ) ;
371- readonly stats : Promise < ViewerStatistics > = $derived ( this . countStats ( ) ) ;
354+ readonly stats : ViewerStatistics = $derived ( this . countStats ( ) ) ;
372355 readonly fileTreeRoots : TreeNode < FileTreeNodeData > [ ] = $derived ( makeFileTree ( this . fileDetails ) ) ;
373356 readonly filteredFileDetails : FileDetails [ ] = $derived (
374357 this . fileTreeFilterDebounced . current ? this . fileDetails . filter ( ( f ) => this . filterFile ( f ) ) : this . fileDetails ,
@@ -543,7 +526,7 @@ export class MultiFileDiffViewerState {
543526 return false ;
544527 }
545528
546- private async countStats ( ) : Promise < ViewerStatistics > {
529+ private countStats ( ) : ViewerStatistics {
547530 let addedLines = 0 ;
548531 let removedLines = 0 ;
549532 const fileAddedLines : number [ ] = [ ] ;
@@ -554,7 +537,7 @@ export class MultiFileDiffViewerState {
554537 if ( details . type !== "text" ) {
555538 continue ;
556539 }
557- const diff = await details . structuredPatch ;
540+ const diff = details . structuredPatch ;
558541
559542 for ( let j = 0 ; j < diff . hunks . length ; j ++ ) {
560543 const hunk = diff . hunks [ j ] ;
0 commit comments