@@ -116,52 +116,67 @@ public IEnumerable<IBranch> GetSourceBranches(
116116 var commitBranches = FindCommitBranchesBranchedFrom ( branch , configuration , excludedBranches ) . ToHashSet ( ) ;
117117
118118 var ignore = new HashSet < BranchCommit > ( ) ;
119- foreach ( var commitBranch in commitBranches )
119+ using ( this . log . IndentLog ( $ "Finding ignore branches" ) )
120120 {
121- foreach ( var commit in branch . Commits . Where ( element => element . When > commitBranch . Commit . When ) )
121+ foreach ( var commitBranch in commitBranches )
122122 {
123- var parents = commit . Parents . ToArray ( ) ;
124- if ( parents . Length > 1 && parents . Any ( element => element . Equals ( commitBranch . Commit ) ) )
123+ foreach ( var commit in branch . Commits . Where ( element => element . When > commitBranch . Commit . When ) )
125124 {
126- ignore . Add ( commitBranch ) ;
125+ var parents = commit . Parents . ToArray ( ) ;
126+ if ( parents . Length > 1 && parents . Any ( element => element . Equals ( commitBranch . Commit ) ) )
127+ {
128+ ignore . Add ( commitBranch ) ;
129+ }
127130 }
128131 }
129132 }
130133
131- foreach ( var item in commitBranches . Skip ( 1 ) . Reverse ( ) )
134+ using ( this . log . IndentLog ( $ "Filtering out branches" ) )
132135 {
133- if ( ignore . Contains ( item ) ) continue ;
136+ IEnumerable < BranchCommit > commitBranchesReversed = new List < BranchCommit > ( ) ;
137+ using ( this . log . IndentLog ( $ "Reverse commit branches") )
138+ {
139+ commitBranchesReversed = commitBranches . Skip ( 1 ) . Reverse ( ) ;
140+ }
134141
135- foreach ( var commitBranch in commitBranches )
142+ foreach ( var item in commitBranchesReversed )
136143 {
137- if ( item . Commit . Equals ( commitBranch . Commit ) ) break ;
144+ if ( ignore . Contains ( item ) ) continue ;
138145
139- foreach ( var commit in commitBranch . Branch . Commits . Where ( element => element . When >= item . Commit . When ) )
146+ foreach ( var commitBranch in commitBranches )
140147 {
141- if ( commit . Equals ( item . Commit ) )
148+ if ( item . Commit . Equals ( commitBranch . Commit ) ) break ;
149+
150+ foreach ( var commit in commitBranch . Branch . Commits . Where ( element => element . When >= item . Commit . When ) )
142151 {
143- commitBranches . Remove ( item ) ;
152+ if ( commit . Equals ( item . Commit ) )
153+ {
154+ commitBranches . Remove ( item ) ;
155+ }
144156 }
145157 }
146158 }
147159 }
148160
149- foreach ( var branchGrouping in commitBranches . GroupBy ( element => element . Commit , element => element . Branch ) )
161+ using ( this . log . IndentLog ( $ "Iterate grouped branches by commit" ) )
150162 {
151- var referenceMatchFound = false ;
152- var referenceNames = referenceLookup [ branchGrouping . Key . Sha ] . Select ( element => element . Name ) . ToHashSet ( ) ;
153-
154- foreach ( var item in branchGrouping )
163+ foreach ( var branchGrouping in commitBranches . GroupBy ( element => element . Commit , element => element . Branch ) )
155164 {
156- if ( ! referenceNames . Contains ( item . Name ) ) continue ;
157- if ( returnedBranches . Add ( item ) ) yield return item ;
158- referenceMatchFound = true ;
159- }
165+ var referenceMatchFound = false ;
166+ var referenceNames = referenceLookup [ branchGrouping . Key . Sha ] . Select ( element => element . Name ) . ToHashSet ( ) ;
160167
161- if ( referenceMatchFound ) continue ;
162- foreach ( var item in branchGrouping )
163- {
164- if ( returnedBranches . Add ( item ) ) yield return item ;
168+ foreach ( var item in branchGrouping )
169+ {
170+ if ( ! referenceNames . Contains ( item . Name ) ) continue ;
171+ if ( returnedBranches . Add ( item ) ) yield return item ;
172+ referenceMatchFound = true ;
173+ }
174+
175+ if ( referenceMatchFound ) continue ;
176+ foreach ( var item in branchGrouping )
177+ {
178+ if ( returnedBranches . Add ( item ) ) yield return item ;
179+ }
165180 }
166181 }
167182 }
0 commit comments