@@ -93,12 +93,9 @@ export enum GitRepoSearchBy {
9393 Sha = 'sha'
9494}
9595
96- export class GitService implements Disposable {
97- static emptyPromise : Promise < GitBlame | GitDiff | GitLog | undefined > = Promise . resolve ( undefined ) ;
98- static deletedOrMissingSha = Git . deletedOrMissingSha ;
99- static stagedUncommittedSha = Git . stagedUncommittedSha ;
100- static uncommittedSha = Git . uncommittedSha ;
96+ const emptyPromise : Promise < GitBlame | GitDiff | GitLog | undefined > = Promise . resolve ( undefined ) ;
10197
98+ export class GitService implements Disposable {
10299 private _onDidChangeRepositories = new EventEmitter < void > ( ) ;
103100 get onDidChangeRepositories ( ) : Event < void > {
104101 return this . _onDidChangeRepositories . event ;
@@ -672,7 +669,7 @@ export class GitService implements Disposable {
672669 ) : Promise < GitBlame | undefined > {
673670 if ( ! ( await this . isTracked ( uri ) ) ) {
674671 Logger . log ( cc , `Skipping blame; '${ uri . fsPath } ' is not tracked` ) ;
675- return GitService . emptyPromise as Promise < GitBlame > ;
672+ return emptyPromise as Promise < GitBlame > ;
676673 }
677674
678675 const [ file , root ] = Git . splitPath ( uri . fsPath , uri . repoPath , false ) ;
@@ -692,14 +689,14 @@ export class GitService implements Disposable {
692689 Logger . debug ( cc , `Cache replace (with empty promise): '${ key } '` ) ;
693690
694691 const value : CachedBlame = {
695- item : GitService . emptyPromise as Promise < GitBlame > ,
692+ item : emptyPromise as Promise < GitBlame > ,
696693 errorMessage : msg
697694 } ;
698695 document . state . set < CachedBlame > ( key , value ) ;
699696
700697 document . setBlameFailure ( ) ;
701698
702- return GitService . emptyPromise as Promise < GitBlame > ;
699+ return emptyPromise as Promise < GitBlame > ;
703700 }
704701
705702 return undefined ;
@@ -756,7 +753,7 @@ export class GitService implements Disposable {
756753 ) : Promise < GitBlame | undefined > {
757754 if ( ! ( await this . isTracked ( uri ) ) ) {
758755 Logger . log ( cc , `Skipping blame; '${ uri . fsPath } ' is not tracked` ) ;
759- return GitService . emptyPromise as Promise < GitBlame > ;
756+ return emptyPromise as Promise < GitBlame > ;
760757 }
761758
762759 const [ file , root ] = Git . splitPath ( uri . fsPath , uri . repoPath , false ) ;
@@ -777,13 +774,13 @@ export class GitService implements Disposable {
777774 Logger . debug ( cc , `Cache replace (with empty promise): '${ key } '` ) ;
778775
779776 const value : CachedBlame = {
780- item : GitService . emptyPromise as Promise < GitBlame > ,
777+ item : emptyPromise as Promise < GitBlame > ,
781778 errorMessage : msg
782779 } ;
783780 document . state . set < CachedBlame > ( key , value ) ;
784781
785782 document . setBlameFailure ( ) ;
786- return GitService . emptyPromise as Promise < GitBlame > ;
783+ return emptyPromise as Promise < GitBlame > ;
787784 }
788785
789786 return undefined ;
@@ -1169,7 +1166,7 @@ export class GitService implements Disposable {
11691166
11701167 try {
11711168 let data ;
1172- if ( ref1 !== undefined && ref2 === undefined && ! GitService . isStagedUncommitted ( ref1 ) ) {
1169+ if ( ref1 !== undefined && ref2 === undefined && ! GitService . isUncommittedStaged ( ref1 ) ) {
11731170 data = await Git . show__diff ( root , file , ref1 , originalFileName , {
11741171 similarityThreshold : Container . config . advanced . similarityThreshold
11751172 } ) ;
@@ -1192,12 +1189,12 @@ export class GitService implements Disposable {
11921189 Logger . debug ( cc , `Cache replace (with empty promise): '${ key } '` ) ;
11931190
11941191 const value : CachedDiff = {
1195- item : GitService . emptyPromise as Promise < GitDiff > ,
1192+ item : emptyPromise as Promise < GitDiff > ,
11961193 errorMessage : msg
11971194 } ;
11981195 document . state . set < CachedDiff > ( key , value ) ;
11991196
1200- return GitService . emptyPromise as Promise < GitDiff > ;
1197+ return emptyPromise as Promise < GitDiff > ;
12011198 }
12021199
12031200 return undefined ;
@@ -1216,7 +1213,7 @@ export class GitService implements Disposable {
12161213 let diff = await this . getDiffForFile ( uri , ref1 , ref2 , originalFileName ) ;
12171214 // If we didn't find a diff & ref1 is undefined (meaning uncommitted), check for a staged diff
12181215 if ( diff === undefined && ref1 === undefined ) {
1219- diff = await this . getDiffForFile ( uri , Git . stagedUncommittedSha , ref2 , originalFileName ) ;
1216+ diff = await this . getDiffForFile ( uri , Git . uncommittedStagedSha , ref2 , originalFileName ) ;
12201217 }
12211218
12221219 if ( diff === undefined ) return undefined ;
@@ -1537,7 +1534,7 @@ export class GitService implements Disposable {
15371534 ) : Promise < GitLog | undefined > {
15381535 if ( ! ( await this . isTracked ( fileName , repoPath , { ref : ref } ) ) ) {
15391536 Logger . log ( cc , `Skipping log; '${ fileName } ' is not tracked` ) ;
1540- return GitService . emptyPromise as Promise < GitLog > ;
1537+ return emptyPromise as Promise < GitLog > ;
15411538 }
15421539
15431540 const [ file , root ] = Git . splitPath ( fileName , repoPath , false ) ;
@@ -1582,12 +1579,12 @@ export class GitService implements Disposable {
15821579 Logger . debug ( cc , `Cache replace (with empty promise): '${ key } '` ) ;
15831580
15841581 const value : CachedLog = {
1585- item : GitService . emptyPromise as Promise < GitLog > ,
1582+ item : emptyPromise as Promise < GitLog > ,
15861583 errorMessage : msg
15871584 } ;
15881585 document . state . set < CachedLog > ( key , value ) ;
15891586
1590- return GitService . emptyPromise as Promise < GitLog > ;
1587+ return emptyPromise as Promise < GitLog > ;
15911588 }
15921589
15931590 return undefined ;
@@ -1641,7 +1638,7 @@ export class GitService implements Disposable {
16411638
16421639 const fileName = GitUri . getRelativePath ( uri , repoPath ) ;
16431640
1644- if ( Git . isStagedUncommitted ( ref ) ) {
1641+ if ( Git . isUncommittedStaged ( ref ) ) {
16451642 return {
16461643 current : GitUri . fromFile ( fileName , repoPath , ref ) ,
16471644 next : GitUri . fromFile ( fileName , repoPath , undefined )
@@ -1656,7 +1653,7 @@ export class GitService implements Disposable {
16561653 if ( status . indexStatus !== undefined ) {
16571654 return {
16581655 current : GitUri . fromFile ( fileName , repoPath , ref ) ,
1659- next : GitUri . fromFile ( fileName , repoPath , GitService . stagedUncommittedSha )
1656+ next : GitUri . fromFile ( fileName , repoPath , GitService . uncommittedStagedSha )
16601657 } ;
16611658 }
16621659 }
@@ -1682,7 +1679,7 @@ export class GitService implements Disposable {
16821679 // editorLine?: number
16831680 ) : Promise < GitUri | undefined > {
16841681 // If we have no ref (or staged ref) there is no next commit
1685- if ( ref === undefined || ref . length === 0 || Git . isStagedUncommitted ( ref ) ) return undefined ;
1682+ if ( ref === undefined || ref . length === 0 || Git . isUncommittedStaged ( ref ) ) return undefined ;
16861683
16871684 let filters : GitLogDiffFilter [ ] | undefined ;
16881685 if ( ref === GitService . deletedOrMissingSha ) {
@@ -1746,18 +1743,18 @@ export class GitService implements Disposable {
17461743 if ( skip === 0 ) {
17471744 return {
17481745 current : GitUri . fromFile ( fileName , repoPath , ref ) ,
1749- previous : GitUri . fromFile ( fileName , repoPath , GitService . stagedUncommittedSha )
1746+ previous : GitUri . fromFile ( fileName , repoPath , GitService . uncommittedStagedSha )
17501747 } ;
17511748 }
17521749
17531750 return {
1754- current : GitUri . fromFile ( fileName , repoPath , GitService . stagedUncommittedSha ) ,
1751+ current : GitUri . fromFile ( fileName , repoPath , GitService . uncommittedStagedSha ) ,
17551752 previous : await this . getPreviousUri ( repoPath , uri , ref , skip - 1 , editorLine )
17561753 } ;
17571754 }
17581755 }
17591756 }
1760- else if ( GitService . isStagedUncommitted ( ref ) ) {
1757+ else if ( GitService . isUncommittedStaged ( ref ) ) {
17611758 const current =
17621759 skip === 0
17631760 ? GitUri . fromFile ( fileName , repoPath , ref )
@@ -1791,6 +1788,9 @@ export class GitService implements Disposable {
17911788 editorLine ?: number
17921789 ) : Promise < GitUri | undefined > {
17931790 if ( ref === GitService . deletedOrMissingSha ) return undefined ;
1791+ if ( ref === GitService . uncommittedSha ) {
1792+ ref = undefined ;
1793+ }
17941794
17951795 if ( ref !== undefined ) {
17961796 skip ++ ;
@@ -2130,14 +2130,14 @@ export class GitService implements Disposable {
21302130 ) : Promise < Uri | undefined > {
21312131 if ( ref === GitService . deletedOrMissingSha ) return undefined ;
21322132
2133- if ( ! ref || ( Git . isUncommitted ( ref ) && ! Git . isStagedUncommitted ( ref ) ) ) {
2133+ if ( ! ref || ( Git . isUncommitted ( ref ) && ! Git . isUncommittedStaged ( ref ) ) ) {
21342134 const data = await Git . ls_files ( repoPath ! , fileName ) ;
21352135 if ( data !== undefined ) return GitUri . file ( fileName ) ;
21362136
21372137 return undefined ;
21382138 }
21392139
2140- if ( Git . isStagedUncommitted ( ref ) ) {
2140+ if ( Git . isUncommittedStaged ( ref ) ) {
21412141 return GitUri . git ( fileName , repoPath ) ;
21422142 }
21432143
@@ -2435,24 +2435,25 @@ export class GitService implements Disposable {
24352435 return Git . getEncoding ( workspace . getConfiguration ( 'files' , uri ) . get < string > ( 'encoding' ) ) ;
24362436 }
24372437
2438+ static deletedOrMissingSha = Git . deletedOrMissingSha ;
24382439 static getGitPath = Git . getGitPath ;
24392440 static getGitVersion = Git . getGitVersion ;
24402441 static isShaLike = Git . isShaLike ;
24412442 static isShaParent = Git . isShaParent ;
2442- static isStagedUncommitted = Git . isStagedUncommitted ;
24432443 static isUncommitted = Git . isUncommitted ;
2444+ static isUncommittedStaged = Git . isUncommittedStaged ;
2445+ static uncommittedSha = Git . uncommittedSha ;
2446+ static uncommittedStagedSha = Git . uncommittedStagedSha ;
24442447
24452448 static shortenSha (
24462449 ref : string | undefined ,
2447- strings : { deletedOrMissing ?: string ; stagedUncommitted ?: string ; uncommitted ?: string ; working ?: string } = { }
2450+ {
2451+ deletedOrMissing = '(deleted)' ,
2452+ ...strings
2453+ } : { deletedOrMissing ?: string ; stagedUncommitted ?: string ; uncommitted ?: string ; working ?: string } = { }
24482454 ) {
2449- if ( ref === undefined ) return undefined ;
2450-
2451- strings = { deletedOrMissing : '(deleted)' , working : emptyStr , ...strings } ;
2452-
2453- if ( ref == null || ref . length === 0 ) return strings . working ;
2454- if ( ref === GitService . deletedOrMissingSha ) return strings . deletedOrMissing ;
2455+ if ( ref === GitService . deletedOrMissingSha ) return deletedOrMissing ;
24552456
2456- return Git . isShaLike ( ref ) || Git . isStagedUncommitted ( ref ) ? Git . shortenSha ( ref , strings ) : ref ;
2457+ return Git . shortenSha ( ref , strings ) ;
24572458 }
24582459}
0 commit comments