@@ -62,7 +62,7 @@ public class PullRequestService : IPullRequestService, IStaticReviewFileMap
6262 readonly IUsageTracker usageTracker ;
6363
6464 readonly IDictionary < string , ( string commitId , string repoPath ) > tempFileMappings ;
65-
65+
6666 [ ImportingConstructor ]
6767 public PullRequestService (
6868 IGitClient gitClient ,
@@ -751,20 +751,20 @@ public async Task<string> ExtractToTempFile(
751751 Encoding encoding )
752752 {
753753 var tempFilePath = CalculateTempFileName ( relativePath , commitSha , encoding ) ;
754+ var gitPath = relativePath . TrimStart ( '/' ) . Replace ( '\\ ' , '/' ) ;
754755
755756 if ( ! File . Exists ( tempFilePath ) )
756757 {
757758 using ( var repo = gitService . GetRepository ( repository . LocalPath ) )
758759 {
759760 var remote = await gitClient . GetHttpRemote ( repo , "origin" ) ;
760- await ExtractToTempFile ( repo , pullRequest . Number , commitSha , relativePath , encoding , tempFilePath ) ;
761+ await ExtractToTempFile ( repo , pullRequest . Number , commitSha , gitPath , encoding , tempFilePath ) ;
761762 }
762763 }
763764
764- lock ( this . tempFileMappings )
765+ lock ( tempFileMappings )
765766 {
766- string gitRelativePath = relativePath . TrimStart ( '/' ) . Replace ( '\\ ' , '/' ) ;
767- this . tempFileMappings [ CanonicalizeLocalFilePath ( tempFilePath ) ] = ( commitSha , gitRelativePath ) ;
767+ tempFileMappings [ CanonicalizeLocalFilePath ( tempFilePath ) ] = ( commitSha , gitPath ) ;
768768 }
769769
770770 return tempFilePath ;
@@ -894,22 +894,24 @@ async Task ExtractToTempFile(
894894 IRepository repo ,
895895 int pullRequestNumber ,
896896 string commitSha ,
897- string relativePath ,
897+ string path ,
898898 Encoding encoding ,
899899 string tempFilePath )
900900 {
901+ Guard . ArgumentIsGitPath ( path , nameof ( path ) ) ;
902+
901903 string contents ;
902904
903905 try
904906 {
905- contents = await gitClient . ExtractFile ( repo , commitSha , relativePath ) ?? string . Empty ;
907+ contents = await gitClient . ExtractFile ( repo , commitSha , path ) ?? string . Empty ;
906908 }
907909 catch ( FileNotFoundException )
908910 {
909911 var pullHeadRef = $ "refs/pull/{ pullRequestNumber } /head";
910912 var remote = await gitClient . GetHttpRemote ( repo , "origin" ) ;
911913 await gitClient . Fetch ( repo , remote . Name , commitSha , pullHeadRef ) ;
912- contents = await gitClient . ExtractFile ( repo , commitSha , relativePath ) ?? string . Empty ;
914+ contents = await gitClient . ExtractFile ( repo , commitSha , path ) ?? string . Empty ;
913915 }
914916
915917 Directory . CreateDirectory ( Path . GetDirectoryName ( tempFilePath ) ) ;
0 commit comments