Skip to content

Commit 22f5093

Browse files
committed
Use new Logger.Is<Level>Enabled properties
1 parent af70c48 commit 22f5093

11 files changed

+31
-28
lines changed

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public static BranchConfig GetBranchConfiguration(GitVersionContext context, Bra
3232
}
3333
else
3434
{
35-
Logger.WriteInfo(string.Format(
36-
"No branch configuration found for branch {0}, falling back to default configuration",
37-
targetBranch.FriendlyName));
35+
if (Logger.IsInfoEnabled) Logger.WriteInfo(string.Format(
36+
"No branch configuration found for branch {0}, falling back to default configuration",
37+
targetBranch.FriendlyName));
3838

3939
branchConfiguration = new BranchConfig { Name = string.Empty };
4040
ConfigurationProvider.ApplyBranchDefaults(context.FullConfiguration, branchConfiguration, "");
@@ -119,7 +119,7 @@ static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch
119119
}
120120
}
121121

122-
Logger.WriteInfo("Found possible parent branches: " + string.Join(", ", possibleParents.Select(p => p.FriendlyName)));
122+
if (Logger.IsInfoEnabled) Logger.WriteInfo("Found possible parent branches: " + string.Join(", ", possibleParents.Select(p => p.FriendlyName)));
123123

124124
if (possibleParents.Count == 1)
125125
{

src/GitVersionCore/ExecuteCore.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicReposi
4242
// },
4343
// Directory = workingDirectory
4444
//});
45-
Logger.WriteInfo(string.Format("Project root is: {0}", projectRoot));
46-
Logger.WriteInfo(string.Format("DotGit directory is: {0}", dotGitDirectory));
45+
if (Logger.IsInfoEnabled)
46+
{
47+
Logger.WriteInfo(string.Format("Project root is: {0}", projectRoot));
48+
Logger.WriteInfo(string.Format("DotGit directory is: {0}", dotGitDirectory));
49+
}
4750
if (string.IsNullOrEmpty(dotGitDirectory) || string.IsNullOrEmpty(projectRoot))
4851
{
4952
// TODO Link to wiki article

src/GitVersionCore/GitPreparer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public string GetDotGitDirectory()
125125

126126
public string GetProjectRootDirectory()
127127
{
128-
Logger.WriteInfo(string.Format("IsDynamicGitRepository: {0}", IsDynamicGitRepository));
128+
if(Logger.IsInfoEnabled) Logger.WriteInfo(string.Format("IsDynamicGitRepository: {0}", IsDynamicGitRepository));
129129
if (IsDynamicGitRepository)
130130
{
131131
Logger.WriteInfo(string.Format("Returning Project Root as {0}", targetPath));
@@ -134,7 +134,7 @@ public string GetProjectRootDirectory()
134134

135135
var dotGetGitDirectory = GetDotGitDirectory();
136136
var result = Directory.GetParent(dotGetGitDirectory).FullName;
137-
Logger.WriteInfo(string.Format("Returning Project Root from DotGitDirectory: {0} - {1}", dotGetGitDirectory, result));
137+
if (Logger.IsInfoEnabled) Logger.WriteInfo(string.Format("Returning Project Root from DotGitDirectory: {0} - {1}", dotGetGitDirectory, result));
138138
return result;
139139
}
140140

src/GitVersionCore/GitRepoMetadataProvider.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public IEnumerable<Branch> GetBranchesContainingCommit([NotNull] Commit commit,
6262
using (Logger.IndentLog(string.Format("Getting branches containing the commit '{0}'.", commit.Id)))
6363
{
6464
var directBranchHasBeenFound = false;
65-
Logger.WriteInfo("Trying to find direct branches.");
65+
if (Logger.IsInfoEnabled) Logger.WriteInfo("Trying to find direct branches.");
6666
// TODO: It looks wasteful looping through the branches twice. Can't these loops be merged somehow? @asbjornu
6767
foreach (var branch in branches)
6868
{
@@ -81,10 +81,10 @@ public IEnumerable<Branch> GetBranchesContainingCommit([NotNull] Commit commit,
8181
yield break;
8282
}
8383

84-
Logger.WriteInfo(string.Format("No direct branches found, searching through {0} branches.", onlyTrackedBranches ? "tracked" : "all"));
84+
if (Logger.IsInfoEnabled) Logger.WriteInfo(string.Format("No direct branches found, searching through {0} branches.", onlyTrackedBranches ? "tracked" : "all"));
8585
foreach (var branch in branches.Where(b => onlyTrackedBranches && !b.IsTracking))
8686
{
87-
Logger.WriteInfo(string.Format("Searching for commits reachable from '{0}'.", branch.FriendlyName));
87+
if (Logger.IsInfoEnabled) Logger.WriteInfo(string.Format("Searching for commits reachable from '{0}'.", branch.FriendlyName));
8888

8989
var commits = this.Repository.Commits.QueryBy(new CommitFilter
9090
{
@@ -93,11 +93,11 @@ public IEnumerable<Branch> GetBranchesContainingCommit([NotNull] Commit commit,
9393

9494
if (!commits.Any())
9595
{
96-
Logger.WriteInfo(string.Format("The branch '{0}' has no matching commits.", branch.FriendlyName));
96+
if (Logger.IsInfoEnabled) Logger.WriteInfo(string.Format("The branch '{0}' has no matching commits.", branch.FriendlyName));
9797
continue;
9898
}
9999

100-
Logger.WriteInfo(string.Format("The branch '{0}' has a matching commit.", branch.FriendlyName));
100+
if (Logger.IsInfoEnabled) Logger.WriteInfo(string.Format("The branch '{0}' has a matching commit.", branch.FriendlyName));
101101
yield return branch;
102102
}
103103
}
@@ -131,7 +131,7 @@ public Commit FindMergeBase(Branch branch, Branch otherBranch)
131131
var findMergeBase = this.Repository.ObjectDatabase.FindMergeBase(commit, commitToFindCommonBase);
132132
if (findMergeBase != null)
133133
{
134-
Logger.WriteInfo(string.Format("Found merge base of {0}", findMergeBase.Sha));
134+
if (Logger.IsInfoEnabled) Logger.WriteInfo(string.Format("Found merge base of {0}", findMergeBase.Sha));
135135
// We do not want to include merge base commits which got forward merged into the other branch
136136
bool mergeBaseWasForwardMerge;
137137
do
@@ -150,7 +150,7 @@ public Commit FindMergeBase(Branch branch, Branch otherBranch)
150150
break;
151151
}
152152
findMergeBase = mergeBase;
153-
Logger.WriteInfo(string.Format("Merge base was due to a forward merge, next merge base is {0}", findMergeBase));
153+
if (Logger.IsInfoEnabled) Logger.WriteInfo(string.Format("Merge base was due to a forward merge, next merge base is {0}", findMergeBase));
154154
}
155155
} while (mergeBaseWasForwardMerge);
156156
}

src/GitVersionCore/GitVersionCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public VersionVariables LoadVersionVariablesFromDiskCache(GitPreparer gitPrepare
7474
var cacheFileName = GetCacheFileName(key, cacheDir);
7575
if (!fileSystem.Exists(cacheFileName))
7676
{
77-
Logger.WriteInfo("Cache file " + cacheFileName + " not found.");
77+
if (Logger.IsInfoEnabled) Logger.WriteInfo("Cache file " + cacheFileName + " not found.");
7878
return null;
7979
}
8080

src/GitVersionCore/GitVersionContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public GitVersionContext(IRepository repository, Branch currentBranch, Config co
4141

4242
if (CurrentCommit == null)
4343
{
44-
Logger.WriteInfo("Using latest commit on specified branch");
44+
if (Logger.IsInfoEnabled) Logger.WriteInfo("Using latest commit on specified branch");
4545
CurrentCommit = currentBranch.Tip;
4646
}
4747

src/GitVersionCore/GitVersionFinder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ public class GitVersionFinder
88
{
99
public SemanticVersion FindVersion(GitVersionContext context)
1010
{
11-
Logger.WriteInfo(string.Format(
12-
"Running against branch: {0} ({1})",
13-
context.CurrentBranch.FriendlyName,
14-
context.CurrentCommit == null ? "-" : context.CurrentCommit.Sha));
11+
if (Logger.IsInfoEnabled) Logger.WriteInfo(string.Format(
12+
"Running against branch: {0} ({1})",
13+
context.CurrentBranch.FriendlyName,
14+
context.CurrentCommit == null ? "-" : context.CurrentCommit.Sha));
1515
EnsureMainTopologyConstraints(context);
1616

1717
var filePath = Path.Combine(context.Repository.GetRepositoryDirectory(), "NextVersion.txt");

src/GitVersionCore/VersionCalculation/BaseVersionCalculator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ public BaseVersion GetBaseVersion(GitVersionContext context)
2323
{
2424
if (v == null) return false;
2525

26-
Logger.WriteInfo(v.ToString());
26+
if (Logger.IsInfoEnabled) Logger.WriteInfo(v.ToString());
2727

2828
foreach (var filter in context.Configuration.VersionFilters)
2929
{
3030
string reason;
3131
if (filter.Exclude(v, out reason))
3232
{
33-
Logger.WriteInfo(reason);
33+
if (Logger.IsInfoEnabled) Logger.WriteInfo(reason);
3434
return false;
3535
}
3636
}
@@ -52,7 +52,7 @@ public BaseVersion GetBaseVersion(GitVersionContext context)
5252
if (matchingVersionsOnceIncremented.Any())
5353
{
5454
baseVersionWithOldestSource = matchingVersionsOnceIncremented.Aggregate((v1, v2) => v1.Version.BaseVersionSource.Committer.When < v2.Version.BaseVersionSource.Committer.When ? v1 : v2).Version;
55-
Logger.WriteInfo(string.Format(
55+
if (Logger.IsInfoEnabled) Logger.WriteInfo(string.Format(
5656
"Found multiple base versions which will produce the same SemVer ({0}), taking oldest source for commit counting ({1})",
5757
maxVersion.IncrementedVersion,
5858
baseVersionWithOldestSource.Source));
@@ -74,7 +74,7 @@ public BaseVersion GetBaseVersion(GitVersionContext context)
7474
context, maxVersion.Version.Source, maxVersion.Version.ShouldIncrement, maxVersion.Version.SemanticVersion,
7575
baseVersionWithOldestSource.BaseVersionSource, maxVersion.Version.BranchNameOverride);
7676

77-
Logger.WriteInfo(string.Format("Base version used: {0}", calculatedBase));
77+
if (Logger.IsInfoEnabled) Logger.WriteInfo(string.Format("Base version used: {0}", calculatedBase));
7878

7979
return calculatedBase;
8080
}

src/GitVersionCore/VersionCalculation/MetaDataCalculator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public SemanticVersionBuildMetaData Create(Commit baseVersionSource, GitVersionC
1616

1717
var commitLog = context.Repository.Commits.QueryBy(qf);
1818
var commitsSinceTag = commitLog.Count();
19-
Logger.WriteInfo(string.Format("{0} commits found between {1} and {2}", commitsSinceTag, baseVersionSource.Sha, context.CurrentCommit.Sha));
19+
if (Logger.IsInfoEnabled) Logger.WriteInfo(string.Format("{0} commits found between {1} and {2}", commitsSinceTag, baseVersionSource.Sha, context.CurrentCommit.Sha));
2020

2121
return new SemanticVersionBuildMetaData(
2222
commitsSinceTag,

src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public static string GetBranchSpecificTag(EffectiveConfiguration configuration,
286286
}
287287
if (tagToUse.Contains("{BranchName}"))
288288
{
289-
Logger.WriteInfo("Using branch name to calculate version tag");
289+
if (Logger.IsInfoEnabled) Logger.WriteInfo("Using branch name to calculate version tag");
290290

291291
var branchName = branchNameOverride ?? branchFriendlyName;
292292
if (!string.IsNullOrWhiteSpace(configuration.BranchPrefixToTrim))

src/GitVersionExe/SpecifiedArgumentRunner.cs

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

1515
public static void Run(Arguments arguments, IFileSystem fileSystem)
1616
{
17-
Logger.WriteInfo(string.Format("Running on {0}.", runningOnMono ? "Mono" : "Windows"));
17+
if (Logger.IsInfoEnabled) Logger.WriteInfo(string.Format("Running on {0}.", runningOnMono ? "Mono" : "Windows"));
1818

1919
var noFetch = arguments.NoFetch;
2020
var authentication = arguments.Authentication;

0 commit comments

Comments
 (0)