@@ -124,33 +124,47 @@ public static IEnumerable<Branch> GetBranchesContainingCommit([NotNull] this Com
124124 throw new ArgumentNullException ( "commit" ) ;
125125 }
126126
127- var directBranchHasBeenFound = false ;
128- foreach ( var branch in branches )
127+ using ( Logger . IndentLog ( string . Format ( "Getting branches containing the commit '{0}'." , commit . Id ) ) )
129128 {
130- if ( branch . Tip != null && branch . Tip . Sha != commit . Sha || ( onlyTrackedBranches && ! branch . IsTracking ) )
129+ var directBranchHasBeenFound = false ;
130+ Logger . WriteInfo ( "Trying to find direct branches." ) ;
131+ // TODO: It looks wasteful looping through the branches twice. Can't these loops be merged somehow? @asbjornu
132+ foreach ( var branch in branches )
131133 {
132- continue ;
134+ if ( branch . Tip != null && branch . Tip . Sha != commit . Sha || ( onlyTrackedBranches && ! branch . IsTracking ) )
135+ {
136+ continue ;
137+ }
138+
139+ directBranchHasBeenFound = true ;
140+ Logger . WriteInfo ( string . Format ( "Direct branch found: '{0}'." , branch . FriendlyName ) ) ;
141+ yield return branch ;
133142 }
134143
135- directBranchHasBeenFound = true ;
136- yield return branch ;
137- }
144+ if ( directBranchHasBeenFound )
145+ {
146+ yield break ;
147+ }
138148
139- if ( directBranchHasBeenFound )
140- {
141- yield break ;
142- }
149+ Logger . WriteInfo ( string . Format ( "No direct branches found, searching through {0} branches." , onlyTrackedBranches ? "tracked" : "all" ) ) ;
150+ foreach ( var branch in branches . Where ( b => onlyTrackedBranches && ! b . IsTracking ) )
151+ {
152+ Logger . WriteInfo ( string . Format ( "Searching for commits reachable from '{0}'." , branch . FriendlyName ) ) ;
143153
144- foreach ( var branch in branches . Where ( b => ( onlyTrackedBranches && ! b . IsTracking ) ) )
145- {
146- var commits = repository . Commits . QueryBy ( new CommitFilter { IncludeReachableFrom = branch } ) . Where ( c => c . Sha == commit . Sha ) ;
154+ var commits = repository . Commits . QueryBy ( new CommitFilter
155+ {
156+ IncludeReachableFrom = branch
157+ } ) . Where ( c => c . Sha == commit . Sha ) ;
147158
148- if ( ! commits . Any ( ) )
149- {
150- continue ;
151- }
159+ if ( ! commits . Any ( ) )
160+ {
161+ Logger . WriteInfo ( string . Format ( "The branch '{0}' has no matching commits." , branch . FriendlyName ) ) ;
162+ continue ;
163+ }
152164
153- yield return branch ;
165+ Logger . WriteInfo ( string . Format ( "The branch '{0}' has a matching commit." , branch . FriendlyName ) ) ;
166+ yield return branch ;
167+ }
154168 }
155169 }
156170
0 commit comments