@@ -1023,36 +1023,49 @@ export class ComposerWebviewProvider implements WebviewProvider<State, State, Co
10231023 params . commitsToReplace . commits [ params . commitsToReplace . commits . length - 1 ] . sha ??
10241024 this . _safetyState . headSha ! ;
10251025 }
1026- const combinedDiff = await calculateCombinedDiffBetweenCommits (
1027- this . _currentRepository ! ,
1028- baseSha ,
1029- headSha ,
1030- ) ;
1031-
1032- const combinedHunks = createHunksFromDiffs ( combinedDiff ! . contents ) ;
1033- for ( const hunk of combinedHunks ) {
1034- const { author, coAuthors } = getAuthorAndCoAuthorsForCombinedDiffHunk ( this . _hunks , hunk ) ;
1035- hunk . author = author ;
1036- hunk . coAuthors = coAuthors . length ? coAuthors : undefined ;
1037- hunks . push ( { ...hunk , assigned : true } ) ;
1038- }
10391026
1040- // Update the hunks. Note that if params.commitsToReplace is defined, then we need to remove all the hunks with indices that match the hunkIndices of the commits to replace, then add in the new hunks and
1041- // reinder all of the hunks. Otherwise, we just replace the existing hunks with the new ones
1042- if ( params . commitsToReplace ) {
1043- const hunkIndicesToRemove = new Set ( params . commitsToReplace . commits . flatMap ( c => c . hunkIndices ) ) ;
1044- this . _hunks = this . _hunks . filter ( h => ! hunkIndicesToRemove . has ( h . index ) ) ;
1045- // Reindex the hunks
1046- let newIndexCounter = 1 ;
1047- this . _hunks . forEach ( hunk => {
1048- hunk . index = newIndexCounter ++ ;
1049- } ) ;
1050- hunks . forEach ( hunk => {
1051- hunk . index = newIndexCounter ++ ;
1052- } ) ;
1053- this . _hunks . push ( ...hunks ) ;
1027+ const shouldSkipDiffCalculation =
1028+ params . commitsToReplace ?. commits ?. length && params . commitsToReplace . commits . every ( c => ! c . sha ) ;
1029+ if ( shouldSkipDiffCalculation ) {
1030+ // just set hunks to the existing hunks and move on
1031+ const hunkIndices = new Set ( params . commitsToReplace ! . commits . flatMap ( c => c . hunkIndices ) ) ;
1032+ for ( const index of hunkIndices ) {
1033+ hunks . push ( { ...this . _hunks . find ( m => m . index === index ) ! , assigned : true } ) ;
1034+ }
10541035 } else {
1055- this . _hunks = hunks ;
1036+ const combinedDiff = await calculateCombinedDiffBetweenCommits (
1037+ this . _currentRepository ! ,
1038+ baseSha ,
1039+ headSha ,
1040+ ) ;
1041+
1042+ const combinedHunks = createHunksFromDiffs ( combinedDiff ! . contents ) ;
1043+ for ( const hunk of combinedHunks ) {
1044+ const { author, coAuthors } = getAuthorAndCoAuthorsForCombinedDiffHunk ( this . _hunks , hunk ) ;
1045+ hunk . author = author ;
1046+ hunk . coAuthors = coAuthors . length ? coAuthors : undefined ;
1047+ hunks . push ( { ...hunk , assigned : true } ) ;
1048+ }
1049+
1050+ // Update the hunks. Note that if params.commitsToReplace is defined, then we need to remove all the hunks with indices that match the hunkIndices of the commits to replace, then add in the new hunks and
1051+ // reinder all of the hunks. Otherwise, we just replace the existing hunks with the new ones
1052+ if ( params . commitsToReplace ) {
1053+ const hunkIndicesToRemove = new Set (
1054+ params . commitsToReplace . commits . flatMap ( c => c . hunkIndices ) ,
1055+ ) ;
1056+ this . _hunks = this . _hunks . filter ( h => ! hunkIndicesToRemove . has ( h . index ) ) ;
1057+ // Reindex the hunks
1058+ let newIndexCounter = 1 ;
1059+ this . _hunks . forEach ( hunk => {
1060+ hunk . index = newIndexCounter ++ ;
1061+ } ) ;
1062+ hunks . forEach ( hunk => {
1063+ hunk . index = newIndexCounter ++ ;
1064+ } ) ;
1065+ this . _hunks . push ( ...hunks ) ;
1066+ } else {
1067+ this . _hunks = hunks ;
1068+ }
10561069 }
10571070 } else {
10581071 // Working directory mode: use existing hunks
0 commit comments