-
Notifications
You must be signed in to change notification settings - Fork 653
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>>(); | ||
foreach(var t in this.Repository.Tags) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please insert a space between |
||
{ | ||
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; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please insert a space between |
||
{ | ||
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) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?