22import { Uri } from 'vscode' ;
33import { configuration , DateSource , DateStyle , GravatarDefaultStyle } from '../../configuration' ;
44import { Container } from '../../container' ;
5- import { Dates } from '../../system' ;
5+ import { Dates , memoize } from '../../system' ;
66import { CommitFormatter } from '../formatters/formatters' ;
77import { Git } from '../git' ;
88import { GitUri } from '../gitUri' ;
@@ -75,12 +75,9 @@ export abstract class GitCommit {
7575 : this . formatDateFromNow ( ) ;
7676 }
7777
78- private _shortSha : string | undefined ;
78+ @ memoize ( )
7979 get shortSha ( ) {
80- if ( this . _shortSha === undefined ) {
81- this . _shortSha = Git . shortenSha ( this . sha ) ;
82- }
83- return this . _shortSha ;
80+ return Git . shortenSha ( this . sha ) ;
8481 }
8582
8683 get isFile ( ) {
@@ -95,20 +92,14 @@ export abstract class GitCommit {
9592 return this . type === GitCommitType . Stash || this . type === GitCommitType . StashFile ;
9693 }
9794
98- private _isStagedUncommitted : boolean | undefined ;
95+ @ memoize ( )
9996 get isStagedUncommitted ( ) : boolean {
100- if ( this . _isStagedUncommitted === undefined ) {
101- this . _isStagedUncommitted = Git . isUncommittedStaged ( this . sha ) ;
102- }
103- return this . _isStagedUncommitted ;
97+ return Git . isUncommittedStaged ( this . sha ) ;
10498 }
10599
106- private _isUncommitted : boolean | undefined ;
100+ @ memoize ( )
107101 get isUncommitted ( ) : boolean {
108- if ( this . _isUncommitted === undefined ) {
109- this . _isUncommitted = Git . isUncommitted ( this . sha ) ;
110- }
111- return this . _isUncommitted ;
102+ return Git . isUncommitted ( this . sha ) ;
112103 }
113104
114105 get previousFileSha ( ) : string {
@@ -123,33 +114,71 @@ export abstract class GitCommit {
123114 return this . previousFileName ? GitUri . resolveToUri ( this . previousFileName , this . repoPath ) : this . uri ;
124115 }
125116
117+ @memoize ( )
126118 get uri ( ) : Uri {
127119 return GitUri . resolveToUri ( this . fileName , this . repoPath ) ;
128120 }
129121
130- private _workingUriPromise : Promise < Uri | undefined > | undefined ;
131- getWorkingUri ( ) : Promise < Uri | undefined > | undefined {
132- if ( this . _workingUriPromise === undefined ) {
133- this . _workingUriPromise = Container . git . getWorkingUri ( this . repoPath , this . uri ) ;
134- }
122+ // @memoize ()
123+ // getFileStatus() {
124+ // if (!this.isFile) return Promise.resolve(undefined);
125+
126+ // return Container.git.getStatusForFile(this.repoPath, this.fileName);
127+ // }
135128
136- return this . _workingUriPromise ;
129+ // @memoize (
130+ // (uri: Uri, ref: string | undefined, editorLine?: number) =>
131+ // `${uri.toString(true)}|${ref || ''}|${editorLine || ''}`
132+ // )
133+ getPreviousDiffUris ( uri : Uri , ref : string | undefined , editorLine ?: number ) {
134+ if ( ! this . isFile ) return Promise . resolve ( undefined ) ;
135+
136+ return Container . git . getPreviousDiffUris ( this . repoPath , uri , ref , 0 , editorLine ) ;
137+ }
138+
139+ // private _previousUriPromise: Promise<GitUri | undefined> | undefined;
140+ // getPreviousUri(staged: boolean = false) {
141+ // if (!this.isFile) return Promise.resolve(undefined);
142+ // if (!this.isUncommitted && this.previousSha !== undefined && !GitService.isShaParent(this.previousSha)) {
143+ // return Promise.resolve(this.toGitUri(true));
144+ // }
145+
146+ // if (this._previousUriPromise === undefined) {
147+ // this._previousUriPromise = this._getPreviousUriCore(staged);
148+ // }
149+
150+ // return this._previousUriPromise;
151+ // }
152+
153+ // private async _getPreviousUriCore(staged: boolean) {
154+ // if (!staged && !GitService.isStagedUncommitted(this.sha)) {
155+ // const status = await this.getFileStatus();
156+ // if (status !== undefined) {
157+ // // If the file is staged, diff with the staged version
158+ // if (status.indexStatus !== undefined) {
159+ // return GitUri.fromFile(this.fileName, this.repoPath, GitService.stagedUncommittedSha);
160+ // }
161+ // }
162+ // }
163+
164+ // return Container.git.getPreviousUri(this.repoPath, this.uri, this.sha);
165+ // }
166+
167+ @memoize ( )
168+ getWorkingUri ( ) : Promise < Uri | undefined > {
169+ if ( ! this . isFile ) return Promise . resolve ( undefined ) ;
170+
171+ return Container . git . getWorkingUri ( this . repoPath , this . uri ) ;
137172 }
138173
139- private _authorDateFormatter : Dates . DateFormatter | undefined ;
174+ @ memoize ( )
140175 private get authorDateFormatter ( ) : Dates . DateFormatter {
141- if ( this . _authorDateFormatter === undefined ) {
142- this . _authorDateFormatter = Dates . toFormatter ( this . authorDate ) ;
143- }
144- return this . _authorDateFormatter ;
176+ return Dates . toFormatter ( this . authorDate ) ;
145177 }
146178
147- private _committerDateFormatter : Dates . DateFormatter | undefined ;
179+ @ memoize ( )
148180 private get committerDateFormatter ( ) : Dates . DateFormatter {
149- if ( this . _committerDateFormatter === undefined ) {
150- this . _committerDateFormatter = Dates . toFormatter ( this . committerDate ) ;
151- }
152- return this . _committerDateFormatter ;
181+ return Dates . toFormatter ( this . committerDate ) ;
153182 }
154183
155184 private get dateFormatter ( ) : Dates . DateFormatter {
@@ -158,6 +187,7 @@ export abstract class GitCommit {
158187 : this . authorDateFormatter ;
159188 }
160189
190+ @memoize ( format => ( format == null ? 'MMMM Do, YYYY h:mma' : format ) )
161191 formatAuthorDate ( format ?: string | null ) {
162192 if ( format == null ) {
163193 format = 'MMMM Do, YYYY h:mma' ;
@@ -170,6 +200,7 @@ export abstract class GitCommit {
170200 return this . authorDateFormatter . fromNow ( ) ;
171201 }
172202
203+ @memoize ( format => ( format == null ? 'MMMM Do, YYYY h:mma' : format ) )
173204 formatCommitterDate ( format ?: string | null ) {
174205 if ( format == null ) {
175206 format = 'MMMM Do, YYYY h:mma' ;
@@ -182,6 +213,7 @@ export abstract class GitCommit {
182213 return this . committerDateFormatter . fromNow ( ) ;
183214 }
184215
216+ @memoize ( format => ( format == null ? 'MMMM Do, YYYY h:mma' : format ) )
185217 formatDate ( format ?: string | null ) {
186218 if ( format == null ) {
187219 format = 'MMMM Do, YYYY h:mma' ;
@@ -202,11 +234,13 @@ export abstract class GitCommit {
202234 return getGravatarUri ( this . email , fallback , size ) ;
203235 }
204236
237+ @memoize ( )
205238 getShortMessage ( ) {
206239 // eslint-disable-next-line no-template-curly-in-string
207240 return CommitFormatter . fromTemplate ( '${message}' , this , { truncateMessageAtNewLine : true } ) ;
208241 }
209242
243+ @memoize ( )
210244 toGitUri ( previous : boolean = false ) : GitUri {
211245 return GitUri . fromCommit ( this , previous ) ;
212246 }
0 commit comments