Skip to content

Perf improve part1 #765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/GitVersionCore/BranchConfigurationCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEv
List<Branch> possibleParents;
if (branchPoint == null)
{
possibleParents = currentCommit.GetBranchesContainingCommit(repository, branchesToEvaluate, true).ToList();
possibleParents = currentCommit.GetBranchesContainingCommit(repository, branchesToEvaluate, true)
// It fails to inherit Increment branch configuration if more than 1 parent;
// therefore no point to get more than 2 parents
.Take(2)
.ToList();
}
else
{
Expand Down
9 changes: 8 additions & 1 deletion src/GitVersionCore/LibGitExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,22 @@ public static IEnumerable<Branch> GetBranchesContainingCommit([NotNull] this Com
}
}

private static Dictionary<string, GitObject> _cachedPeeledTarget = new Dictionary<string, GitObject>();

public static GitObject PeeledTarget(this Tag tag)
{
GitObject cachedTarget;
if(_cachedPeeledTarget.TryGetValue(tag.Target.Sha, out cachedTarget))
{
return cachedTarget;
}
var target = tag.Target;

while (target is TagAnnotation)
{
target = ((TagAnnotation)(target)).Target;
}

_cachedPeeledTarget.Add(tag.Target.Sha, target);
return target;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ public class TaggedCommitVersionStrategy : BaseVersionStrategy
{
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
{
string currentBranchName = null;
var head = context.Repository.Head;
if (head != null)
{
currentBranchName = head.CanonicalName;
}

var olderThan = context.CurrentCommit.When();
var allTags = context.Repository.Tags
.Where(tag => ((Commit)tag.PeeledTarget()).When() <= olderThan)
Expand All @@ -23,7 +16,7 @@ public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
.Commits
.SelectMany(commit =>
{
return allTags.Where(t => IsValidTag(context, currentBranchName, t, commit));
return allTags.Where(t => IsValidTag(t, commit));
})
.Select(t =>
{
Expand All @@ -39,19 +32,7 @@ public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
.Where(a => a != null)
.ToList();

if (tagsOnBranch.Count == 0)
{
yield break;
}
if (tagsOnBranch.Count == 1)
{
yield return CreateBaseVersion(context, tagsOnBranch[0]);
}

foreach (var result in tagsOnBranch.Select(t => CreateBaseVersion(context, t)))
{
yield return result;
}
return tagsOnBranch.Select(t => CreateBaseVersion(context, t));
}

BaseVersion CreateBaseVersion(GitVersionContext context, VersionTaggedCommit version)
Expand All @@ -66,7 +47,7 @@ protected virtual string FormatSource(VersionTaggedCommit version)
return string.Format("Git tag '{0}'", version.Tag);
}

protected virtual bool IsValidTag(GitVersionContext context, string branchName, Tag tag, Commit commit)
protected virtual bool IsValidTag(Tag tag, Commit commit)
{
return tag.PeeledTarget() == commit;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
namespace GitVersion.VersionCalculation.BaseVersionCalculators
{
using System;
using System.Collections.Generic;
using System.Linq;
using LibGit2Sharp;

public class TrackMergeTargetBaseVersionStrategy : TaggedCommitVersionStrategy
{
protected override bool IsValidTag(GitVersionContext context, string branchName, Tag tag, Commit commit)
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
{
if (!string.IsNullOrWhiteSpace(branchName))
if(!context.Configuration.TrackMergeTarget)
{
if (context.Configuration.TrackMergeTarget)
{
return IsDirectMergeFromCommit(tag, commit);
}
yield break;
}

return false;
string currentBranchName = null;
var head = context.Repository.Head;
if (head != null)
{
currentBranchName = head.CanonicalName;
}

if (string.IsNullOrWhiteSpace(currentBranchName))
{
yield break;
}

foreach (var version in base.GetVersions(context))
{
yield return version;
}
}

protected override bool IsValidTag(Tag tag, Commit commit)
{
return IsDirectMergeFromCommit(tag, commit);
}

protected override string FormatSource(VersionTaggedCommit version)
Expand Down