@@ -8,13 +8,12 @@ import type { GitBranch } from '../../git/models/branch';
88import type { RepositoryFileSystemChangeEvent } from '../../git/models/repository' ;
99import type { GitUser } from '../../git/models/user' ;
1010import type { CommitsQueryResults , FilesQueryResults } from '../../git/queryResults' ;
11- import { getCommitsQuery , getFilesQuery } from '../../git/queryResults' ;
11+ import { getAheadBehindFilesQuery , getCommitsQuery , getFilesQuery } from '../../git/queryResults' ;
1212import { createRevisionRange , shortenRevision } from '../../git/utils/revision.utils' ;
1313import { CommandQuickPickItem } from '../../quickpicks/items/common' ;
1414import { showReferencePicker } from '../../quickpicks/referencePicker' ;
1515import { debug , log } from '../../system/decorators/log' ;
1616import { weakEvent } from '../../system/event' ;
17- import { getSettledValue } from '../../system/promise' ;
1817import { pluralize } from '../../system/string' ;
1918import type { ViewsWithBranches } from '../viewBase' ;
2019import type { WorktreesView } from '../worktreesView' ;
@@ -149,11 +148,11 @@ export class CompareBranchNode extends SubscribeableViewNode<
149148 authors : this . filterByAuthors ,
150149 } ) ;
151150
152- const refsProvider = this . view . container . git . getRepositoryService ( this . repoPath ) . refs ;
151+ const svc = this . view . container . git . getRepositoryService ( this . repoPath ) ;
153152 const mergeBase =
154- ( await refsProvider . getMergeBase ( behind . ref1 , behind . ref2 , {
153+ ( await svc . refs . getMergeBase ( behind . ref1 , behind . ref2 , {
155154 forkPoint : true ,
156- } ) ) ?? ( await refsProvider . getMergeBase ( behind . ref1 , behind . ref2 ) ) ;
155+ } ) ) ?? ( await svc . refs . getMergeBase ( behind . ref1 , behind . ref2 ) ) ;
157156
158157 const children : ViewNode [ ] = [
159158 new ResultsCommitsNode (
@@ -338,73 +337,21 @@ export class CompareBranchNode extends SubscribeableViewNode<
338337 }
339338
340339 private async getAheadFilesQuery ( ) : Promise < FilesQueryResults > {
341- const comparison = createRevisionRange ( this . _compareWith ?. ref || 'HEAD' , this . branch . ref || 'HEAD' , '...' ) ;
342-
343- const diffProvider = this . view . container . git . getRepositoryService ( this . repoPath ) . diff ;
344- const [ filesResult , workingFilesResult , statsResult , workingStatsResult ] = await Promise . allSettled ( [
345- diffProvider . getDiffStatus ( comparison ) ,
346- this . compareWithWorkingTree ? diffProvider . getDiffStatus ( 'HEAD' ) : undefined ,
347- diffProvider . getChangedFilesCount ( comparison ) ,
348- this . compareWithWorkingTree ? diffProvider . getChangedFilesCount ( 'HEAD' ) : undefined ,
349- ] ) ;
350-
351- let files = getSettledValue ( filesResult ) ?? [ ] ;
352- let stats : FilesQueryResults [ 'stats' ] = getSettledValue ( statsResult ) ;
353-
354- if ( this . compareWithWorkingTree ) {
355- const workingFiles = getSettledValue ( workingFilesResult ) ;
356- if ( workingFiles != null ) {
357- if ( files . length === 0 ) {
358- files = workingFiles ;
359- } else {
360- for ( const wf of workingFiles ) {
361- const index = files . findIndex ( f => f . path === wf . path ) ;
362- if ( index !== - 1 ) {
363- files . splice ( index , 1 , wf ) ;
364- } else {
365- files . push ( wf ) ;
366- }
367- }
368- }
369- }
370-
371- const workingStats = getSettledValue ( workingStatsResult ) ;
372- if ( workingStats != null ) {
373- if ( stats == null ) {
374- stats = workingStats ;
375- } else {
376- stats = {
377- additions : stats . additions + workingStats . additions ,
378- deletions : stats . deletions + workingStats . deletions ,
379- files : files . length ,
380- approximated : true ,
381- } ;
382- }
383- }
384- }
385-
386- return {
387- label : `${ pluralize ( 'file' , files . length , { zero : 'No' } ) } changed` ,
388- files : files ,
389- stats : stats ,
390- } ;
340+ return getAheadBehindFilesQuery (
341+ this . view . container ,
342+ this . repoPath ,
343+ createRevisionRange ( this . _compareWith ?. ref || 'HEAD' , this . branch . ref || 'HEAD' , '...' ) ,
344+ this . compareWithWorkingTree ,
345+ ) ;
391346 }
392347
393348 private async getBehindFilesQuery ( ) : Promise < FilesQueryResults > {
394- const comparison = createRevisionRange ( this . branch . ref , this . _compareWith ?. ref || 'HEAD' , '...' ) ;
395-
396- const diffProvider = this . view . container . git . getRepositoryService ( this . repoPath ) . diff ;
397- const [ filesResult , statsResult ] = await Promise . allSettled ( [
398- diffProvider . getDiffStatus ( comparison ) ,
399- diffProvider . getChangedFilesCount ( comparison ) ,
400- ] ) ;
401-
402- const files = getSettledValue ( filesResult ) ?? [ ] ;
403- return {
404- label : `${ pluralize ( 'file' , files . length , { zero : 'No' } ) } changed` ,
405- files : files ,
406- stats : getSettledValue ( statsResult ) ,
407- } ;
349+ return getAheadBehindFilesQuery (
350+ this . view . container ,
351+ this . repoPath ,
352+ createRevisionRange ( this . branch . ref , this . _compareWith ?. ref || 'HEAD' , '...' ) ,
353+ false ,
354+ ) ;
408355 }
409356
410357 private getCommitsQuery ( range : string ) : ( limit : number | undefined ) => Promise < CommitsQueryResults > {
0 commit comments