88using System . Reactive ;
99using System . Reactive . Linq ;
1010using System . Reactive . Threading . Tasks ;
11+ using System . Runtime . InteropServices ;
1112using System . Text ;
1213using System . Text . RegularExpressions ;
14+ using System . Threading ;
1315using System . Threading . Tasks ;
1416using System . Windows . Forms ;
1517using GitHub . Api ;
1921using GitHub . Models ;
2022using GitHub . Primitives ;
2123using LibGit2Sharp ;
24+ using Microsoft . VisualStudio . StaticReviews . Contracts ;
2225using Octokit . GraphQL ;
2326using Octokit . GraphQL . Model ;
2427using Rothko ;
@@ -32,7 +35,7 @@ namespace GitHub.Services
3235{
3336 [ Export ( typeof ( IPullRequestService ) ) ]
3437 [ PartCreationPolicy ( CreationPolicy . Shared ) ]
35- public class PullRequestService : IPullRequestService
38+ public class PullRequestService : IPullRequestService , IStaticReviewFileMap
3639 {
3740 const string SettingCreatedByGHfVS = "created-by-ghfvs" ;
3841 const string SettingGHfVSPullRequest = "ghfvs-pr-owner-number" ;
@@ -58,6 +61,8 @@ public class PullRequestService : IPullRequestService
5861 readonly IOperatingSystem os ;
5962 readonly IUsageTracker usageTracker ;
6063
64+ readonly IDictionary < string , ( string commitId , string repoPath ) > tempFileMappings ;
65+
6166 [ ImportingConstructor ]
6267 public PullRequestService (
6368 IGitClient gitClient ,
@@ -73,6 +78,7 @@ public PullRequestService(
7378 this . graphqlFactory = graphqlFactory ;
7479 this . os = os ;
7580 this . usageTracker = usageTracker ;
81+ this . tempFileMappings = new Dictionary < string , ( string commitId , string repoPath ) > ( StringComparer . OrdinalIgnoreCase ) ;
7682 }
7783
7884 public async Task < Page < PullRequestListItemModel > > ReadPullRequests (
@@ -755,6 +761,12 @@ public async Task<string> ExtractToTempFile(
755761 }
756762 }
757763
764+ lock ( this . tempFileMappings )
765+ {
766+ string gitRelativePath = relativePath . TrimStart ( '/' ) . Replace ( '\\ ' , '/' ) ;
767+ this . tempFileMappings [ CanonicalizeLocalFilePath ( tempFilePath ) ] = ( commitSha , gitRelativePath ) ;
768+ }
769+
758770 return tempFilePath ;
759771 }
760772
@@ -827,6 +839,28 @@ public bool ConfirmCancelPendingReview()
827839 MessageBoxIcon . Question ) == DialogResult . Yes ;
828840 }
829841
842+ /// <inheritdoc />
843+ public Task < string > GetObjectishFromLocalPathAsync ( string localPath , CancellationToken cancellationToken )
844+ {
845+ lock ( this . tempFileMappings )
846+ {
847+ var canonicalizedPath = CanonicalizeLocalFilePath ( localPath ) ;
848+ if ( this . tempFileMappings . TryGetValue ( canonicalizedPath , out ( string commitId , string repoPath ) result ) )
849+ {
850+ return Task . FromResult ( $ "{ result . commitId } :{ result . repoPath } ") ;
851+ }
852+ }
853+
854+ return Task . FromResult < string > ( null ) ;
855+ }
856+
857+ /// <inheritdoc />
858+ public Task < string > GetLocalPathFromObjectishAsync ( string objectish , CancellationToken cancellationToken )
859+ {
860+ throw new NotImplementedException ( ) ;
861+ }
862+
863+
830864 async Task < string > CreateRemote ( IRepository repo , UriString cloneUri )
831865 {
832866 foreach ( var remote in repo . Network . Remotes )
@@ -1006,6 +1040,12 @@ static string BuildGHfVSConfigKeyValue(string owner, int number)
10061040 return default ;
10071041 }
10081042
1043+ static string CanonicalizeLocalFilePath ( string localPath )
1044+ {
1045+ localPath = localPath . Replace ( "\\ \\ " , "\\ " ) ;
1046+ return Path . GetFullPath ( localPath ) ;
1047+ }
1048+
10091049 class ListItemAdapter : PullRequestListItemModel
10101050 {
10111051 public IList < ReviewAdapter > Reviews { get ; set ; }
0 commit comments