@@ -124,33 +124,47 @@ public static IEnumerable<Branch> GetBranchesContainingCommit([NotNull] this Com
124
124
throw new ArgumentNullException ( "commit" ) ;
125
125
}
126
126
127
- var directBranchHasBeenFound = false ;
128
- foreach ( var branch in branches )
127
+ using ( Logger . IndentLog ( string . Format ( "Getting branches containing the commit '{0}'." , commit . Id ) ) )
129
128
{
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 )
131
133
{
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 ;
133
142
}
134
143
135
- directBranchHasBeenFound = true ;
136
- yield return branch ;
137
- }
144
+ if ( directBranchHasBeenFound )
145
+ {
146
+ yield break ;
147
+ }
138
148
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 ) ) ;
143
153
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 ) ;
147
158
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
+ }
152
164
153
- yield return branch ;
165
+ Logger . WriteInfo ( string . Format ( "The branch '{0}' has a matching commit." , branch . FriendlyName ) ) ;
166
+ yield return branch ;
167
+ }
154
168
}
155
169
}
156
170
0 commit comments