Skip to content

Commit 6a4d975

Browse files
committed
Spike of performance inprovment when fetching base configuration.
This is just spike to see if it's possible to fetch the base configuraton a little bit faster.
1 parent 9da7b3b commit 6a4d975

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEv
5656
excludedInheritBranches = repository.Branches.Where(b =>
5757
{
5858
var branchConfig = LookupBranchConfiguration(config, b);
59-
return branchConfig.Length == 1 && branchConfig[0].Value.Increment == IncrementStrategy.Inherit;
59+
// TODO: I don't this there's the branch if no branchConfig exists?
60+
// TODO: we should probably warn if we find more than one branch config?
61+
return (branchConfig.Length != 1) || (branchConfig.Length == 1 && branchConfig[0].Value.Increment == IncrementStrategy.Inherit);
6062
}).ToList();
6163
}
6264
excludedBranches.ToList().ForEach(excludedInheritBranches.Add);
@@ -66,14 +68,14 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEv
6668
List<Branch> possibleParents;
6769
if (branchPoint == null)
6870
{
69-
possibleParents = currentCommit.GetBranchesContainingCommit(repository, true).Except(excludedInheritBranches).ToList();
71+
possibleParents = currentCommit.GetBranchesContainingCommit(repository, true, excludedInheritBranches).ToList();
7072
}
7173
else
7274
{
73-
var branches = branchPoint.GetBranchesContainingCommit(repository, true).Except(excludedInheritBranches).ToList();
75+
var branches = branchPoint.GetBranchesContainingCommit(repository, true, excludedInheritBranches).ToList();
7476
if (branches.Count > 1)
7577
{
76-
var currentTipBranches = currentCommit.GetBranchesContainingCommit(repository, true).Except(excludedInheritBranches).ToList();
78+
var currentTipBranches = currentCommit.GetBranchesContainingCommit(repository, true, excludedInheritBranches).ToList();
7779
possibleParents = branches.Except(currentTipBranches).ToList();
7880
}
7981
else

src/GitVersionCore/GitVersionContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public GitVersionContext(IRepository repository, Branch currentBranch, Config co
4848

4949
if (currentBranch.IsDetachedHead())
5050
{
51-
CurrentBranch = CurrentCommit.GetBranchesContainingCommit(repository, OnlyEvaluateTrackedBranches).OnlyOrDefault() ?? currentBranch;
51+
CurrentBranch = CurrentCommit.GetBranchesContainingCommit(repository, OnlyEvaluateTrackedBranches, new Branch[] {}).OnlyOrDefault() ?? currentBranch;
5252
}
5353
else
5454
{

src/GitVersionCore/LibGitExtensions.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,15 @@ static bool IsSameBranch(Branch branch, Branch b)
6868
return (b.IsRemote ? b.Name.Replace(b.Remote.Name + "/", string.Empty) : b.Name) != branch.Name;
6969
}
7070

71-
public static IEnumerable<Branch> GetBranchesContainingCommit(this Commit commit, IRepository repository, bool onlyTrackedBranches)
71+
// TODO: we should probably pass a ISet<Branch> here
72+
public static IEnumerable<Branch> GetBranchesContainingCommit(this Commit commit, IRepository repository, bool onlyTrackedBranches, IList<Branch> excludedInheritBranches)
7273
{
74+
var excludedSet = new HashSet<Branch>(excludedInheritBranches);
75+
var remainingBranches = repository.Branches.Where(b => !excludedSet.Contains(b)).ToList();
76+
77+
7378
var directBranchHasBeenFound = false;
74-
foreach (var branch in repository.Branches)
79+
foreach (var branch in remainingBranches)
7580
{
7681
if (branch.Tip.Sha != commit.Sha || (onlyTrackedBranches && !branch.IsTracking))
7782
{
@@ -87,8 +92,9 @@ public static IEnumerable<Branch> GetBranchesContainingCommit(this Commit commit
8792
yield break;
8893
}
8994

90-
foreach (var branch in repository.Branches.Where(b => (onlyTrackedBranches && !b.IsTracking)))
95+
foreach (var branch in remainingBranches.Where(b => (onlyTrackedBranches && !b.IsTracking)))
9196
{
97+
// NOTE: is it better to compare Sha instead of commit?
9298
var commits = repository.Commits.QueryBy(new CommitFilter { Since = branch }).Where(c => c.Sha == commit.Sha);
9399

94100
if (!commits.Any())

0 commit comments

Comments
 (0)