Skip to content

Improved logging in GetBranchesContainingCommit #919

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
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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