Skip to content
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

lakectl log: add option to filter merge commits #8142

Merged
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions cmd/lakectl/cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ func (d *dotWriter) Write(commits []apigen.Commit) {
}
}

// filter merge commits, used for --no-merges flag
func filterMergeCommits(commits []apigen.Commit) []apigen.Commit {
var filteredCommits []apigen.Commit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var filteredCommits []apigen.Commit
filteredCommits := make([]apigen.Commit, 0, len(commits))

This is fairly idiomatic Go for when you know roughly the expected length of the result. It says to reserve space for the same number of commits, but keep the slice itself at length 0.


// iterating through data.Commit, appending every instance with 1 or less parents.
for _, commit := range commits {
if len(commit.Parents) <= 1 {
filteredCommits = append(filteredCommits, commit)
}
}
return filteredCommits
}

// logCmd represents the log command
var logCmd = &cobra.Command{
Use: "log <branch URI>",
Expand All @@ -80,6 +93,7 @@ var logCmd = &cobra.Command{
limit := Must(cmd.Flags().GetBool("limit"))
since := Must(cmd.Flags().GetString("since"))
dot := Must(cmd.Flags().GetBool("dot"))
noMerges := Must(cmd.Flags().GetBool("no-merges"))
firstParent := Must(cmd.Flags().GetBool("first-parent"))
objects := Must(cmd.Flags().GetStringSlice("objects"))
prefixes := Must(cmd.Flags().GetStringSlice("prefixes"))
Expand Down Expand Up @@ -150,6 +164,9 @@ var logCmd = &cobra.Command{
After: pagination.NextOffset,
},
}
if noMerges {
data.Commits = filterMergeCommits(data.Commits)
}

if dot {
graph.Write(data.Commits)
Expand Down Expand Up @@ -177,6 +194,7 @@ func init() {
logCmd.Flags().String("after", "", "show results after this value (used for pagination)")
logCmd.Flags().Bool("dot", false, "return results in a dotgraph format")
logCmd.Flags().Bool("first-parent", false, "follow only the first parent commit upon seeing a merge commit")
logCmd.Flags().Bool("no-merges", false, "skip merge commits")
logCmd.Flags().Bool("show-meta-range-id", false, "also show meta range ID")
logCmd.Flags().StringSlice("objects", nil, "show results that contains changes to at least one path in that list of objects. Use comma separator to pass all objects together")
logCmd.Flags().StringSlice("prefixes", nil, "show results that contains changes to at least one path in that list of prefixes. Use comma separator to pass all prefixes together")
Expand Down
Loading