@@ -18,8 +18,8 @@ export class CompareResultsNode extends SubscribeableViewNode<CompareView> {
1818 constructor (
1919 view : CompareView ,
2020 public readonly repoPath : string ,
21- private _ref1 : NamedRef ,
22- private _ref2 : NamedRef ,
21+ private _ref : NamedRef ,
22+ private _compareWith : NamedRef ,
2323 private _pinned : boolean = false ,
2424 private _comparisonNotation ?: '...' | '..'
2525 ) {
@@ -28,33 +28,16 @@ export class CompareResultsNode extends SubscribeableViewNode<CompareView> {
2828 }
2929
3030 get id ( ) : string {
31- return `gitlens:repository(${ this . repoPath } ):compare(${ this . _ref1 . ref } :${ this . _ref2 . ref } )|${ this . _instanceId } ` ;
32- }
33-
34- get label ( ) {
35- return `Comparing ${ this . _ref1 . label ||
36- GitService . shortenSha ( this . _ref1 . ref , { working : 'Working Tree' } ) } to ${ this . _ref2 . label ||
37- GitService . shortenSha ( this . _ref2 . ref , { working : 'Working Tree' } ) } `;
31+ return `gitlens:repository(${ this . repoPath } ):compare(${ this . _ref . ref } :${ this . _compareWith . ref } )|${ this . _instanceId } ` ;
3832 }
3933
4034 get pinned ( ) : boolean {
4135 return this . _pinned ;
4236 }
4337
44- get ref1 ( ) : NamedRef {
45- return this . _ref1 ;
46- }
47-
48- get ref2 ( ) : NamedRef {
49- return this . _ref2 ;
50- }
51-
5238 async getChildren ( ) : Promise < ViewNode [ ] > {
5339 if ( this . _children === undefined ) {
54- let ref1 = this . _ref1 . ref ;
55- if ( this . comparisonNotation === '..' ) {
56- ref1 = ( await Container . git . getMergeBase ( this . repoPath , ref1 , this . _ref2 . ref ) ) || ref1 ;
57- }
40+ const [ ref1 , ref2 ] = await this . getDiffRefs ( ) ;
5841
5942 this . _children = [
6043 new ResultsCommitsNode (
@@ -68,14 +51,7 @@ export class CompareResultsNode extends SubscribeableViewNode<CompareView> {
6851 includeDescription : true
6952 }
7053 ) ,
71- new ResultsFilesNode (
72- this . view ,
73- this ,
74- this . uri . repoPath ! ,
75- ref1 ,
76- this . _ref2 . ref ,
77- this . getFilesQuery . bind ( this )
78- )
54+ new ResultsFilesNode ( this . view , this , this . uri . repoPath ! , ref1 , ref2 , this . getFilesQuery . bind ( this ) )
7955 ] ;
8056 }
8157 return this . _children ;
@@ -88,7 +64,11 @@ export class CompareResultsNode extends SubscribeableViewNode<CompareView> {
8864 description = ( repo && repo . formattedName ) || this . uri . repoPath ;
8965 }
9066
91- const item = new TreeItem ( this . label , this . _state || TreeItemCollapsibleState . Collapsed ) ;
67+ const item = new TreeItem (
68+ `Comparing ${ this . _ref . label || GitService . shortenSha ( this . _ref . ref , { working : 'Working Tree' } ) } to ${ this
69+ . _compareWith . label || GitService . shortenSha ( this . _compareWith . ref , { working : 'Working Tree' } ) } `,
70+ this . _state || TreeItemCollapsibleState . Collapsed
71+ ) ;
9272 item . contextValue = `${ ResourceType . CompareResults } +${
9373 this . comparisonNotation === '..' ? 'twodot' : 'threedot'
9474 } `;
@@ -111,14 +91,28 @@ export class CompareResultsNode extends SubscribeableViewNode<CompareView> {
11191 return ! this . _pinned ;
11292 }
11393
94+ @gate ( )
95+ @debug ( )
96+ async getDiffRefs ( ) : Promise < [ string , string ] > {
97+ if ( this . comparisonNotation === '..' ) {
98+ return [
99+ ( await Container . git . getMergeBase ( this . repoPath , this . _compareWith . ref , this . _ref . ref ) ) ||
100+ this . _compareWith . ref ,
101+ this . _ref . ref
102+ ] ;
103+ }
104+
105+ return [ this . _compareWith . ref , this . _ref . ref ] ;
106+ }
107+
114108 @log ( )
115109 async pin ( ) {
116110 if ( this . _pinned ) return ;
117111
118112 await this . view . updatePinnedComparison ( this . getPinnableId ( ) , {
119113 path : this . repoPath ,
120- ref1 : this . ref1 ,
121- ref2 : this . ref2 ,
114+ ref1 : this . _ref ,
115+ ref2 : this . _compareWith ,
122116 notation : this . _comparisonNotation
123117 } ) ;
124118
@@ -141,8 +135,8 @@ export class CompareResultsNode extends SubscribeableViewNode<CompareView> {
141135 if ( this . _pinned ) {
142136 await this . view . updatePinnedComparison ( this . getPinnableId ( ) , {
143137 path : this . repoPath ,
144- ref1 : this . ref1 ,
145- ref2 : this . ref2 ,
138+ ref1 : this . _ref ,
139+ ref2 : this . _compareWith ,
146140 notation : this . _comparisonNotation
147141 } ) ;
148142 }
@@ -156,17 +150,17 @@ export class CompareResultsNode extends SubscribeableViewNode<CompareView> {
156150 // Save the current id so we can update it later
157151 const currentId = this . getPinnableId ( ) ;
158152
159- const ref1 = this . _ref1 ;
160- this . _ref1 = this . _ref2 ;
161- this . _ref2 = ref1 ;
153+ const ref1 = this . _ref ;
154+ this . _ref = this . _compareWith ;
155+ this . _compareWith = ref1 ;
162156
163157 // If we were pinned, remove the existing pin and save a new one
164158 if ( this . _pinned ) {
165159 await this . view . updatePinnedComparison ( currentId ) ;
166160 await this . view . updatePinnedComparison ( this . getPinnableId ( ) , {
167161 path : this . repoPath ,
168- ref1 : this . ref1 ,
169- ref2 : this . ref2 ,
162+ ref1 : this . _ref ,
163+ ref2 : this . _compareWith ,
170164 notation : this . _comparisonNotation
171165 } ) ;
172166 }
@@ -203,7 +197,7 @@ export class CompareResultsNode extends SubscribeableViewNode<CompareView> {
203197 private async getCommitsQuery ( maxCount : number | undefined ) : Promise < CommitsQueryResults > {
204198 const log = await Container . git . getLog ( this . uri . repoPath ! , {
205199 maxCount : maxCount ,
206- ref : `${ this . _ref1 . ref } ${ this . comparisonNotation } ${ this . _ref2 . ref || 'HEAD' } `
200+ ref : `${ this . _compareWith . ref || 'HEAD' } ${ this . comparisonNotation } ${ this . _ref . ref } `
207201 } ) ;
208202
209203 const count = log !== undefined ? log . count : 0 ;
@@ -218,7 +212,7 @@ export class CompareResultsNode extends SubscribeableViewNode<CompareView> {
218212 private async getFilesQuery ( ) : Promise < FilesQueryResults > {
219213 const diff = await Container . git . getDiffStatus (
220214 this . uri . repoPath ! ,
221- `${ this . _ref1 . ref } ${ this . diffComparisonNotation } ${ this . _ref2 . ref || 'HEAD' } `
215+ `${ this . _compareWith . ref || 'HEAD' } ${ this . diffComparisonNotation } ${ this . _ref . ref || 'HEAD' } `
222216 ) ;
223217
224218 return {
@@ -228,6 +222,6 @@ export class CompareResultsNode extends SubscribeableViewNode<CompareView> {
228222 }
229223
230224 private getPinnableId ( ) {
231- return Strings . sha1 ( `${ this . repoPath } |${ this . ref1 . ref } |${ this . ref2 . ref } ` ) ;
225+ return Strings . sha1 ( `${ this . repoPath } |${ this . _ref . ref } |${ this . _compareWith . ref } ` ) ;
232226 }
233227}
0 commit comments