Skip to content

Commit

Permalink
Improved logging in LibGitExtensions.GetBranchesContainingCommit() to…
Browse files Browse the repository at this point in the history
… debug GitTools#694.
  • Loading branch information
asbjornu authored and simonejsing committed Jul 7, 2016
1 parent e1d44f4 commit 245e4a1
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions src/GitVersionCore/LibGitExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,33 +124,47 @@ public static IEnumerable<Branch> GetBranchesContainingCommit([NotNull] this Com
throw new ArgumentNullException("commit");
}

var directBranchHasBeenFound = false;
foreach (var branch in branches)
using (Logger.IndentLog(string.Format("Getting branches containing the commit '{0}'.", commit.Id)))
{
if (branch.Tip != null && branch.Tip.Sha != commit.Sha || (onlyTrackedBranches && !branch.IsTracking))
var directBranchHasBeenFound = false;
Logger.WriteInfo("Trying to find direct branches.");
// TODO: It looks wasteful looping through the branches twice. Can't these loops be merged somehow? @asbjornu
foreach (var branch in branches)
{
continue;
if (branch.Tip != null && branch.Tip.Sha != commit.Sha || (onlyTrackedBranches && !branch.IsTracking))
{
continue;
}

directBranchHasBeenFound = true;
Logger.WriteInfo(string.Format("Direct branch found: '{0}'.", branch.FriendlyName));
yield return branch;
}

directBranchHasBeenFound = true;
yield return branch;
}
if (directBranchHasBeenFound)
{
yield break;
}

if (directBranchHasBeenFound)
{
yield break;
}
Logger.WriteInfo(string.Format("No direct branches found, searching through {0} branches.", onlyTrackedBranches ? "tracked" : "all"));
foreach (var branch in branches.Where(b => onlyTrackedBranches && !b.IsTracking))
{
Logger.WriteInfo(string.Format("Searching for commits reachable from '{0}'.", branch.FriendlyName));

foreach (var branch in branches.Where(b => (onlyTrackedBranches && !b.IsTracking)))
{
var commits = repository.Commits.QueryBy(new CommitFilter { IncludeReachableFrom = branch }).Where(c => c.Sha == commit.Sha);
var commits = repository.Commits.QueryBy(new CommitFilter
{
IncludeReachableFrom = branch
}).Where(c => c.Sha == commit.Sha);

if (!commits.Any())
{
continue;
}
if (!commits.Any())
{
Logger.WriteInfo(string.Format("The branch '{0}' has no matching commits.", branch.FriendlyName));
continue;
}

yield return branch;
Logger.WriteInfo(string.Format("The branch '{0}' has a matching commit.", branch.FriendlyName));
yield return branch;
}
}
}

Expand Down

0 comments on commit 245e4a1

Please sign in to comment.