@@ -22,7 +22,7 @@ public GitContentSearcher(IGitHelper gitHelper, IFileSearcher fileSearcher, IFil
2222
2323 public void SearchContent ( string filePath , string searchString , string earliestCommit = "" , string latestCommit = "" )
2424 {
25- var commits = _gitHelper . GetGitCommits ( earliestCommit , latestCommit ) ;
25+ var commits = _gitHelper . GetGitCommits ( earliestCommit , latestCommit , filePath ) ;
2626 commits = commits . Reverse ( ) . ToArray ( ) ;
2727
2828 if ( commits == null || commits . Length == 0 )
@@ -40,7 +40,7 @@ public void SearchContent(string filePath, string searchString, string earliestC
4040 int firstMatchIndex = FindFirstMatchIndex ( commits , filePath , searchString ) ;
4141 int lastMatchIndex = FindLastMatchIndex ( commits , filePath , searchString , firstMatchIndex ) ;
4242
43- LogResults ( firstMatchIndex , lastMatchIndex , commits , searchString , _logWriter ) ;
43+ LogResults ( firstMatchIndex , lastMatchIndex , commits , searchString ) ;
4444 }
4545
4646 private int FindFirstMatchIndex ( string [ ] commits , string filePath , string searchString )
@@ -54,7 +54,7 @@ private int FindFirstMatchIndex(string[] commits, string filePath, string search
5454 int mid = left + ( right - left ) / 2 ;
5555 string commit = commits [ mid ] ;
5656 string tempFileName = _fileManager . GenerateTempFileName ( commit , filePath ) ;
57- string commitTime = GetCommitTime ( commit , _logWriter ) ;
57+ string commitTime = GetCommitTime ( commit ) ;
5858
5959 bool gitShowSuccess = false ;
6060 try
@@ -99,7 +99,7 @@ private int FindLastMatchIndex(string[] commits, string filePath, string searchS
9999 int mid = left + ( right - left ) / 2 ;
100100 string commit = commits [ mid ] ;
101101 string tempFileName = _fileManager . GenerateTempFileName ( commit , filePath ) ;
102- string commitTime = GetCommitTime ( commit , _logWriter ) ;
102+ string commitTime = GetCommitTime ( commit ) ;
103103
104104 bool gitShowSuccess = false ;
105105 try
@@ -133,33 +133,35 @@ private int FindLastMatchIndex(string[] commits, string filePath, string searchS
133133 return lastMatchIndex ?? - 1 ;
134134 }
135135
136- private string GetCommitTime ( string commit , TextWriter logWriter )
136+ private string GetCommitTime ( string commit )
137137 {
138138 try
139139 {
140140 return _gitHelper . GetCommitTime ( commit ) ;
141141 }
142142 catch ( Exception ex )
143143 {
144- logWriter . WriteLine ( $ "Error retrieving commit time for { commit } : { ex . Message } ") ;
144+ _logWriter . WriteLine ( $ "Error retrieving commit time for { commit } : { ex . Message } ") ;
145145 return "unknown time" ;
146146 }
147147 }
148148
149- private void LogResults ( int firstMatchIndex , int lastMatchIndex , string [ ] commits , string searchString , TextWriter logWriter )
149+ private void LogResults ( int firstMatchIndex , int lastMatchIndex , string [ ] commits , string searchString )
150150 {
151151 if ( firstMatchIndex == - 1 )
152152 {
153- logWriter . WriteLine ( $ "Search string \" { searchString } \" does not appear in any of the checked commits.") ;
153+ _logWriter . WriteLine ( $ "Search string \" { searchString } \" does not appear in any of the checked commits.") ;
154154 }
155155 else
156156 {
157- logWriter . WriteLine ( $ "Search string \" { searchString } \" first appears in commit { commits [ firstMatchIndex ] } .") ;
157+ _logWriter . WriteLine ( $ "Search string \" { searchString } \" first appears in commit { commits [ firstMatchIndex ] } .") ;
158158 if ( lastMatchIndex != - 1 )
159159 {
160- logWriter . WriteLine ( $ "Search string \" { searchString } \" last appears in commit { commits [ lastMatchIndex ] } .") ;
160+ _logWriter . WriteLine ( $ "Search string \" { searchString } \" last appears in commit { commits [ lastMatchIndex ] } .") ;
161161 }
162162 }
163+
164+ _logWriter . Flush ( ) ;
163165 }
164166 }
165167}
0 commit comments