@@ -72,13 +72,22 @@ public static BranchCommit FindCommitBranchWasBranchedFrom([NotNull] this Branch
72
72
}
73
73
}
74
74
75
+ private static List < MergeBaseData > cachedMergeBase = new List < MergeBaseData > ( ) ;
76
+
75
77
/// <summary>
76
78
/// Find the merge base of the two branches, i.e. the best common ancestor of the two branches' tips.
77
79
/// </summary>
78
80
public static Commit FindMergeBase ( this Branch branch , Branch otherBranch , IRepository repository )
79
81
{
80
82
using ( Logger . IndentLog ( string . Format ( "Finding merge base between '{0}' and '{1}'." , branch . FriendlyName , otherBranch . FriendlyName ) ) )
81
83
{
84
+ // Check the cache.
85
+ var cachedData = cachedMergeBase . FirstOrDefault ( data => IsSameBranch ( branch , data . Branch ) && IsSameBranch ( otherBranch , data . OtherBranch ) && repository == data . Repository ) ;
86
+ if ( cachedData != null )
87
+ {
88
+ return cachedData . MergeBase ;
89
+ }
90
+
82
91
// Otherbranch tip is a forward merge
83
92
var commitToFindCommonBase = otherBranch . Tip ;
84
93
var commit = branch . Tip ;
@@ -113,6 +122,10 @@ public static Commit FindMergeBase(this Branch branch, Branch otherBranch, IRepo
113
122
}
114
123
} while ( mergeBaseWasForwardMerge ) ;
115
124
}
125
+
126
+ // Store in cache.
127
+ cachedMergeBase . Add ( new MergeBaseData ( branch , otherBranch , repository , findMergeBase ) ) ;
128
+
116
129
return findMergeBase ;
117
130
}
118
131
}
@@ -275,5 +288,22 @@ public static void CheckoutFilesIfExist(this IRepository repository, params stri
275
288
}
276
289
}
277
290
}
291
+
292
+ private class MergeBaseData
293
+ {
294
+ public Branch Branch { get ; private set ; }
295
+ public Branch OtherBranch { get ; private set ; }
296
+ public IRepository Repository { get ; private set ; }
297
+
298
+ public Commit MergeBase { get ; private set ; }
299
+
300
+ public MergeBaseData ( Branch branch , Branch otherBranch , IRepository repository , Commit mergeBase )
301
+ {
302
+ Branch = branch ;
303
+ OtherBranch = otherBranch ;
304
+ Repository = repository ;
305
+ MergeBase = mergeBase ;
306
+ }
307
+ }
278
308
}
279
309
}
0 commit comments