Skip to content

Commit

Permalink
fix: cherry-pick commit duplication
Browse files Browse the repository at this point in the history
When commits are cherry picked from another branch they will be reported
multiple times. Implement equality interface for WalrusCommit and filter
repo commits to Distinct() based on this rule. Commits are equal if they
are from the same local repo (by path, not just name) and have matching
shas.

Signed-off-by: Cory Todd <[email protected]>
  • Loading branch information
corytodd committed Jun 29, 2023
1 parent 08cc99d commit 349a8a3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Walrus.Core.Tests/MockRepoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ public IEnumerable<WalrusRepository> GetRepositories(string rootDirectory, int s
AuthorEmail = "[email protected]",
RepoName = "project_2",
RepoPath = "/home/user/code/project_2"
},
// A cherry-pick
new WalrusCommit
{
Branch = "feature",
Message = "[bugfix] really fix issue #2252",
Sha = "0335f9a11ec0c5f83c0f412ed49e816f815d9089",
Timestamp = ConstantDateTimes.Today,
AuthorEmail = "[email protected]",
RepoName = "project_2",
RepoPath = "/home/user/code/project_2"
}
})
};
Expand Down
22 changes: 22 additions & 0 deletions Walrus.Core/Repository/WalrusCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ public class WalrusCommit
/// </summary>
public DateTime Timestamp { get; init; }

/// <inheritdoc />
public override bool Equals(object? obj)
{
return Equals(obj as WalrusCommit);
}

/// <summary>
/// Commits with the same sha from the same repo path are equal
/// </summary>
public bool Equals(WalrusCommit? other)
{
return other != null &&
Sha == other.Sha &&
RepoPath == other.RepoPath;
}

/// <inheritdoc />
public override int GetHashCode()
{
return HashCode.Combine(Sha, RepoPath);
}

/// <inheritdoc />
public override string ToString()
{
Expand Down
4 changes: 3 additions & 1 deletion Walrus.Core/WalrusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public IEnumerable<CommitGroup> QueryCommits(WalrusQuery query)
var commits =
QueryRepositories(query)
.AsParallel()
.SelectMany(r => r.Commits.Where(preparedQuery.IsMatch));
.SelectMany(r => r.Commits
.Distinct()
.Where(preparedQuery.IsMatch));

// Wrap GroupBy in a CommitGroup so we can have keys of different types
var grouped = query.GroupBy switch
Expand Down

0 comments on commit 349a8a3

Please sign in to comment.