-
Notifications
You must be signed in to change notification settings - Fork 653
Feature/introduce in memory git metadata #1243
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
Changes from all commits
271a403
e44aa1b
1677a83
20f7a14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using GitTools; | ||
using GitTools.Testing; | ||
using GitVersion; | ||
using GitVersion.GitRepoInformation; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
using System; | ||
|
||
[TestFixture] | ||
public class QueryRequirements | ||
{ | ||
[Test] | ||
public void ListsAllMergeCommits() | ||
{ | ||
var config = new Config(); | ||
ConfigurationProvider.ApplyDefaultsTo(config); | ||
using (var fixture = new EmptyRepositoryFixture()) | ||
{ | ||
fixture.MakeACommit(); | ||
fixture.MakeACommit(); | ||
fixture.BranchTo("feature/foo"); | ||
fixture.MakeACommit(); | ||
fixture.Checkout("master"); | ||
fixture.MergeNoFF("feature/foo"); | ||
|
||
fixture.Repository.DumpGraph(); | ||
|
||
var metadata = Libgit2RepoMetadataProvider.ReadMetadata(new GitVersionContext(fixture.Repository, config)); | ||
|
||
metadata.CurrentBranch.MergeMessages.Count.ShouldBe(1); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using LibGit2Sharp; | ||
|
||
public class MockObjectDatabase : ObjectDatabase | ||
{ | ||
public override Commit FindMergeBase(Commit first, Commit second) | ||
{ | ||
return second; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace GitVersion.GitRepoInformation | ||
{ | ||
public class GitRepoMetadata | ||
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. Is this the repository metadata or data? Since GitVersion's job is to walk the graph, count commits, etc., I'd say that anything required to calculate the version is data, not metadata. I think this class can be called just 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. I am unsure at the moment to be honest. I don't want to re-implement git data structures, this really is information about the commit graph with a bunch of pre-calculated stuff. Lets see where it goes then fix naming next |
||
{ | ||
public GitRepoMetadata( | ||
List<MTag> tags, MBranch currentBranch, MBranch master, | ||
List<MBranch> releaseBranches) | ||
{ | ||
Tags = tags; | ||
MasterBranch = master; | ||
CurrentBranch = currentBranch; | ||
ReleaseBranches = releaseBranches; | ||
} | ||
|
||
// Wonder if this can be 'mainline' | ||
public MBranch MasterBranch { get; } | ||
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. I like the immutability here. 👍 |
||
public List<MBranch> ReleaseBranches { get; } | ||
public MBranch CurrentBranch { get; } | ||
public List<MTag> Tags { get; private set; } | ||
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. Why the |
||
} | ||
|
||
public class MTag | ||
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. What's the 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. Rather than aliasing in a bunch of files which reference both this namespace and libgit2 the metadata related ones are prefixed with M. I expect this to go at some point |
||
{ | ||
public MTag(string sha, string friendlyName, Config config, bool createdAfterHead) | ||
{ | ||
Sha = sha; | ||
Name = friendlyName; | ||
CreatedAfterHead = createdAfterHead; | ||
SemanticVersion version; | ||
if (SemanticVersion.TryParse(friendlyName, config.TagPrefix, out version)) | ||
{ | ||
Version = version; | ||
} | ||
} | ||
|
||
public string Sha { get; } | ||
public string Name { get; } | ||
public bool CreatedAfterHead { get; } | ||
public SemanticVersion Version { get; } | ||
} | ||
|
||
public class MBranch | ||
{ | ||
public MBranch( | ||
string name, | ||
string tipSha, | ||
MParent parent, | ||
List<MTag> tags, | ||
List<MergeMessage> mergeMessages) | ||
{ | ||
Name = name; | ||
TipSha = tipSha; | ||
Parent = parent; | ||
MergeMessages = mergeMessages; | ||
Tags = tags; | ||
} | ||
|
||
public string Name { get; } | ||
public string TipSha { get; } | ||
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. Perhaps the |
||
public MParent Parent { get; } | ||
public List<MergeMessage> MergeMessages { get; } | ||
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. Not sure it matters much, I've just got a habit of using 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. 👍 |
||
public List<MTag> Tags { get; } | ||
} | ||
|
||
public class MParent | ||
{ | ||
public MParent(string mergeBase) | ||
{ | ||
MergeBase = mergeBase; | ||
} | ||
|
||
public string MergeBase { get; } | ||
} | ||
} |
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.
If this is going to be GitVersion's "Core", i.e. Domain Model (in DDD terms), wouldn't a more authoritative sounding namespace like
GitVersion.Repositories
,GitVersion.Graph
be good?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.
I like GitVersion.Graph! Will keep that in mind as a progress