@@ -349,7 +349,7 @@ private void FindTfsParentCommits(List<TfsChangesetInfo> changesets, Commit comm
349
349
350
350
public TfsChangesetInfo GetTfsChangesetById ( string remoteRef , long changesetId , string tfsPath )
351
351
{
352
- var commit = FindCommitsByChangesetId ( changesetId , remoteRef ) . FirstOrDefault ( c => c . Message . Contains ( tfsPath ) ) ;
352
+ var commit = FindCommitByChangesetIdAndPath ( changesetId , tfsPath , remoteRef ) ;
353
353
if ( commit == null )
354
354
return null ;
355
355
return TryParseChangesetInfo ( commit . Message , commit . Sha ) ;
@@ -533,7 +533,7 @@ public bool CreateBranch(string gitBranchName, string target)
533
533
534
534
public string FindCommitHashByChangesetId ( long changesetId , string tfsPath )
535
535
{
536
- var commit = FindCommitsByChangesetId ( changesetId ) . FirstOrDefault ( c => c . Message . Contains ( tfsPath ) ) ;
536
+ var commit = FindCommitByChangesetIdAndPath ( changesetId , tfsPath ) ;
537
537
if ( commit == null )
538
538
return null ;
539
539
@@ -560,6 +560,65 @@ public static bool TryParseChangesetId(string commitMessage, out long changesetI
560
560
return false ;
561
561
}
562
562
563
+ private Commit FindCommitByChangesetIdAndPath ( long changesetId , string tfsPath , string remoteRef = null )
564
+ {
565
+ Trace . WriteLine ( "Looking for changeset " + changesetId . ToString ( ) + " in git repository..." ) ;
566
+
567
+ if ( remoteRef == null )
568
+ {
569
+ IList < string > shas ;
570
+ if ( changesetsCache . TryGetValue ( changesetId , out shas ) )
571
+ {
572
+ var c1 = shas . Select ( sha => _repository . Lookup < Commit > ( sha ) ) . FirstOrDefault ( c => c . Message . Contains ( tfsPath ) ) ;
573
+ if ( c1 != null )
574
+ return c1 ;
575
+ }
576
+
577
+ if ( cacheIsFull )
578
+ return null ;
579
+ }
580
+
581
+ var reachableFromRemoteBranches = new CommitFilter
582
+ {
583
+ Since = _repository . Branches . Where ( p => p . IsRemote ) ,
584
+ SortBy = CommitSortStrategies . Time ,
585
+ } ;
586
+
587
+ if ( remoteRef != null )
588
+ reachableFromRemoteBranches . Since = _repository . Branches . Where ( p => p . IsRemote && p . CanonicalName . EndsWith ( remoteRef ) ) ;
589
+
590
+ var commitsFromRemoteBranches = _repository . Commits . QueryBy ( reachableFromRemoteBranches ) ;
591
+
592
+ Commit commit = null ;
593
+ foreach ( var c in commitsFromRemoteBranches )
594
+ {
595
+ long id ;
596
+ if ( TryParseChangesetId ( c . Message , out id ) )
597
+ {
598
+ AddToChangesetCache ( changesetId , c . Sha ) ;
599
+
600
+ if ( id == changesetId )
601
+ {
602
+ if ( c . Message . Contains ( tfsPath ) )
603
+ {
604
+ commit = c ;
605
+ break ;
606
+ }
607
+ }
608
+ }
609
+ }
610
+
611
+ if ( remoteRef == null && commit == null )
612
+ cacheIsFull = true ; // repository fully scanned
613
+
614
+ if ( commit == null )
615
+ Trace . WriteLine ( " => Commit not found!" ) ;
616
+ else
617
+ Trace . WriteLine ( " => Commit found! hash: " + commit . Sha ) ;
618
+
619
+ return commit ;
620
+ }
621
+
563
622
private IEnumerable < Commit > FindCommitsByChangesetId ( long changesetId , string remoteRef = null )
564
623
{
565
624
Trace . WriteLine ( "Looking for changeset " + changesetId . ToString ( ) + " in git repository..." ) ;
0 commit comments