Skip to content

Commit 808f50e

Browse files
committed
code cleanup
1 parent 4649af9 commit 808f50e

File tree

11 files changed

+28
-38
lines changed

11 files changed

+28
-38
lines changed

src/GitVersionCore.Tests/Mocks/MockTag.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class MockTag : Tag
1414

1515
public MockTag() { }
1616

17-
public MockTag(string name, Commit target)
17+
public MockTag(string name, GitObject target)
1818
{
1919
NameEx = name;
2020
TargetEx = target;

src/GitVersionCore.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void TakesVersionFromMergeOfConfiguredReleaseBranch(string message, strin
154154
AssertMergeMessage(message, expectedVersion, parents, config);
155155
}
156156

157-
private void AssertMergeMessage(string message, string expectedVersion, List<Commit> parents, Config config = null)
157+
private void AssertMergeMessage(string message, string expectedVersion, IList<Commit> parents, Config config = null)
158158
{
159159
var commit = new MockCommit
160160
{

src/GitVersionCore/Cache/GitVersionCacheKeyFactory.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Text;
77
using GitVersion.Configuration;
88
using GitVersion.Logging;
9-
using GitVersion.Extensions;
9+
using LibGit2Sharp;
1010

1111
namespace GitVersion.Cache
1212
{
@@ -143,17 +143,15 @@ private List<string> CalculateDirectoryContents(string root)
143143

144144
private string GetRepositorySnapshotHash()
145145
{
146-
var repositorySnapshot = gitPreparer.GetDotGitDirectory().WithRepository(repo =>
146+
using var repo = new Repository(gitPreparer.GetDotGitDirectory());
147+
148+
var head = repo.Head;
149+
if (head.Tip == null)
147150
{
148-
var head = repo.Head;
149-
if (head.Tip == null)
150-
{
151-
return head.CanonicalName;
152-
}
153-
var hash = string.Join(":", head.CanonicalName, head.Tip.Sha);
154-
return hash;
155-
});
156-
return GetHash(repositorySnapshot);
151+
return head.CanonicalName;
152+
}
153+
var hash = string.Join(":", head.CanonicalName, head.Tip.Sha);
154+
return GetHash(hash);
157155
}
158156

159157
private static string GetOverrideConfigHash(Config overrideConfig)

src/GitVersionCore/Extensions/LibGitExtensions.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ namespace GitVersion.Extensions
1010
{
1111
public static class LibGitExtensions
1212
{
13-
public static TResult WithRepository<TResult>(this string dotGitDirectory, Func<IRepository, TResult> action)
14-
{
15-
using var repo = new Repository(dotGitDirectory);
16-
return action(repo);
17-
}
18-
1913
public static DateTimeOffset When(this Commit commit)
2014
{
2115
return commit.Committer.When;

src/GitVersionCore/GitVersionCalculator.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
using GitVersion.Cache;
55
using GitVersion.Logging;
66
using Microsoft.Extensions.Options;
7-
using GitVersion.Extensions;
87
using GitVersion.VersionCalculation;
8+
using LibGit2Sharp;
99

1010
namespace GitVersion
1111
{
@@ -104,13 +104,12 @@ private VersionVariables ExecuteInternal(string targetBranch, string commitId, C
104104
{
105105
var configuration = configProvider.Provide(overrideConfig: overrideConfig);
106106

107-
return gitPreparer.GetDotGitDirectory().WithRepository(repo =>
108-
{
109-
var gitVersionContext = new GitVersionContext(repo, log, targetBranch, configuration, commitId: commitId);
110-
var semanticVersion = nextVersionCalculator.FindVersion(gitVersionContext);
107+
using var repo = new Repository(gitPreparer.GetDotGitDirectory());
108+
109+
var gitVersionContext = new GitVersionContext(repo, log, targetBranch, configuration, commitId: commitId);
110+
var semanticVersion = nextVersionCalculator.FindVersion(gitVersionContext);
111111

112-
return variableProvider.GetVariablesFor(semanticVersion, gitVersionContext.Configuration, gitVersionContext.IsCurrentCommitTagged);
113-
});
112+
return variableProvider.GetVariablesFor(semanticVersion, gitVersionContext.Configuration, gitVersionContext.IsCurrentCommitTagged);
114113
}
115114
}
116115
}

src/GitVersionCore/Helpers/GitRepositoryHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private static void Fetch(ILog log, AuthenticationInfo authentication, Remote re
144144
Commands.Fetch(repo, remote.Name, new string[0], authentication.ToFetchOptions(), null);
145145
}
146146

147-
private static void EnsureLocalBranchExistsForCurrentBranch(ILog log, Repository repo, Remote remote, string currentBranch)
147+
private static void EnsureLocalBranchExistsForCurrentBranch(ILog log, IRepository repo, Remote remote, string currentBranch)
148148
{
149149
if (string.IsNullOrEmpty(currentBranch)) return;
150150

@@ -180,7 +180,7 @@ private static void EnsureLocalBranchExistsForCurrentBranch(ILog log, Repository
180180
Commands.Checkout(repo, localCanonicalName);
181181
}
182182

183-
private static void AddMissingRefSpecs(ILog log, Repository repo, Remote remote)
183+
private static void AddMissingRefSpecs(ILog log, IRepository repo, Remote remote)
184184
{
185185
if (remote.FetchRefSpecs.Any(r => r.Source == "refs/heads/*"))
186186
return;
@@ -248,7 +248,7 @@ private static void CreateFakeBranchPointingAtThePullRequestTip(ILog log, Reposi
248248
Commands.Checkout(repo, fakeBranchName);
249249
}
250250

251-
private static IEnumerable<DirectReference> GetRemoteTipsUsingUsernamePasswordCredentials(Repository repo, Remote remote, string username, string password)
251+
private static IEnumerable<DirectReference> GetRemoteTipsUsingUsernamePasswordCredentials(IRepository repo, Remote remote, string username, string password)
252252
{
253253
return repo.Network.ListReferences(remote, (url, fromUrl, types) => new UsernamePasswordCredentials
254254
{
@@ -257,7 +257,7 @@ private static IEnumerable<DirectReference> GetRemoteTipsUsingUsernamePasswordCr
257257
}).Select(r => r.ResolveToDirectReference());
258258
}
259259

260-
private static IEnumerable<DirectReference> GetRemoteTipsForAnonymousUser(Repository repo, Remote remote)
260+
private static IEnumerable<DirectReference> GetRemoteTipsForAnonymousUser(IRepository repo, Remote remote)
261261
{
262262
return repo.Network.ListReferences(remote).Select(r => r.ResolveToDirectReference());
263263
}

src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ public IEnumerable<BaseVersion> GetTaggedVersions(GitVersionContext context, Bra
3636
.SelectMany(commit => { return allTags.Where(t => IsValidTag(t.Item1, commit)); })
3737
.Select(t =>
3838
{
39-
var commit = t.Item1.PeeledTarget() as Commit;
40-
if (commit != null)
41-
return new VersionTaggedCommit(commit, t.Item2, t.Item1.FriendlyName);
39+
if (t.Item1.PeeledTarget() is Commit)
40+
return new VersionTaggedCommit(t.Item1.PeeledTarget() as Commit, t.Item2, t.Item1.FriendlyName);
4241

4342
return null;
4443
})

src/GitVersionCore/VersionCalculation/IncrementStrategyFinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private static Regex TryGetRegexOrDefault(string messageRegex, Regex defaultRege
104104
return CompiledRegexCache.GetOrAdd(messageRegex, pattern => new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase));
105105
}
106106

107-
private static IEnumerable<Commit> GetIntermediateCommits(IRepository repo, Commit baseCommit, Commit headCommit)
107+
private static IEnumerable<Commit> GetIntermediateCommits(IRepository repo, GitObject baseCommit, Commit headCommit)
108108
{
109109
if (baseCommit == null) yield break;
110110

src/GitVersionCore/VersioningModes/ContinuousDeliveryMode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public override SemanticVersionPreReleaseTag GetPreReleaseTag(GitVersionContext
1212
return RetrieveMostRecentOptionalTagVersion(context, possibleCommits) ?? context.Configuration.Tag + ".1";
1313
}
1414

15-
private static SemanticVersionPreReleaseTag RetrieveMostRecentOptionalTagVersion(GitVersionContext context, List<Tag> applicableTagsInDescendingOrder)
15+
private static SemanticVersionPreReleaseTag RetrieveMostRecentOptionalTagVersion(GitVersionContext context, IReadOnlyCollection<Tag> applicableTagsInDescendingOrder)
1616
{
1717
if (applicableTagsInDescendingOrder.Any())
1818
{

src/GitVersionExe.Tests/HelpWriterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void AllArgsAreInHelp()
4242
.ShouldBeEmpty();
4343
}
4444

45-
private static bool IsNotInHelp(Dictionary<string, string> lookup, string propertyName, string helpText)
45+
private static bool IsNotInHelp(IReadOnlyDictionary<string, string> lookup, string propertyName, string helpText)
4646
{
4747
if (lookup.ContainsKey(propertyName))
4848
return !helpText.Contains(lookup[propertyName]);

0 commit comments

Comments
 (0)