Skip to content

Improve performance - Filter list of all tags first by those parsable to a semantic version #1374

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 3 commits into from
Mar 9, 2018
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
18 changes: 8 additions & 10 deletions src/GitVersionCore/GitRepoMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,17 @@ public IEnumerable<SemanticVersion> GetVersionTagsOnBranch(Branch branch, string

using (Logger.IndentLog(string.Format("Getting version tags from branch '{0}'.", branch.CanonicalName)))
{
var tags = this.Repository.Tags.Select(t => t).ToList();

var versionTags = this.Repository.Commits.QueryBy(new CommitFilter
{
IncludeReachableFrom = branch.Tip
})
.SelectMany(c => tags.Where(t => c.Sha == t.Target.Sha).SelectMany(t =>
var tags = new List<Tuple<Tag, SemanticVersion>>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please extract this tag filter logic out to a descriptive method?

foreach(var t in this.Repository.Tags)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please insert a space between foreach and (?

{
SemanticVersion semver;
if (SemanticVersion.TryParse(t.FriendlyName, tagPrefixRegex, out semver))
return new[] { semver };
return new SemanticVersion[0];
})).ToList();
{
tags.Add(Tuple.Create(t, semver));
}
}

var versionTags = branch.Commits.SelectMany(c => tags.Where(t => c.Sha == t.Item1.Target.Sha).Select(t => t.Item2)).ToList();

semanticVersionTagsOnBranchCache.Add(branch, versionTags);
return versionTags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,31 @@ public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)

public IEnumerable<BaseVersion> GetTaggedVersions(GitVersionContext context, Branch currentBranch, DateTimeOffset? olderThan)
{
var allTags = context.Repository.Tags
.Where(tag => !olderThan.HasValue || ((Commit) tag.PeeledTarget()).When() <= olderThan.Value)
.ToList();
var allTags = new List<Tuple<Tag, SemanticVersion>>();
foreach(var tag in context.Repository.Tags)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please insert a space between foreach and (?

{
if (olderThan.HasValue && ((Commit)tag.PeeledTarget()).When() > olderThan.Value)
continue;

SemanticVersion version;

if (!SemanticVersion.TryParse(tag.FriendlyName, context.Configuration.GitTagPrefix, out version))
{
continue;
}

allTags.Add(Tuple.Create(tag, version));
}

var tagsOnBranch = currentBranch
.Commits
.SelectMany(commit => { return allTags.Where(t => IsValidTag(t, commit)); })
.SelectMany(commit => { return allTags.Where(t => IsValidTag(t.Item1, commit)); })
.Select(t =>
{
SemanticVersion version;
if (SemanticVersion.TryParse(t.FriendlyName, context.Configuration.GitTagPrefix, out version))
{
var commit = t.PeeledTarget() as Commit;
if (commit != null)
return new VersionTaggedCommit(commit, version, t.FriendlyName);
}
var commit = t.Item1.PeeledTarget() as Commit;
if (commit != null)
return new VersionTaggedCommit(commit, t.Item2, t.Item1.FriendlyName);

return null;
})
.Where(a => a != null)
Expand Down