-
Notifications
You must be signed in to change notification settings - Fork 352
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
Changes from 2 commits
d2c2a5f
5b9b954
413e130
8578938
bdb751a
3791404
90e5605
842f365
f009268
8d5f948
8948ecd
5cd8b5a
065bfe4
2fe7125
a82f9e9
3a2dbe3
a9b50cd
d67ddbf
7e18b0d
be315e5
b424591
35e0af6
91df0b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,19 @@ | |
} | ||
} | ||
|
||
// filter merge commits, used for --no-merges flag | ||
func filterMergeCommits(commits []apigen.Commit) []apigen.Commit { | ||
filteredCommits := make([]apigen.Commit, 0, len(commits)) | ||
itaiad200 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 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>", | ||
|
@@ -80,6 +93,7 @@ | |
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")) | ||
|
@@ -100,6 +114,10 @@ | |
if amountForPagination <= 0 { | ||
amountForPagination = internalPageSize | ||
} | ||
// case --no-merges & --amount, ask for more results since some will filter out | ||
if noMerges && amountForPagination < maxAmountNoMerges { | ||
amountForPagination *= 3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now I get the |
||
} | ||
logCommitsParams := &apigen.LogCommitsParams{ | ||
After: apiutil.Ptr(apigen.PaginationAfter(after)), | ||
Amount: apiutil.Ptr(apigen.PaginationAmount(amountForPagination)), | ||
|
@@ -151,13 +169,19 @@ | |
}, | ||
} | ||
|
||
// case --no-merges, filter commits and subtract that amount from amount desired | ||
if noMerges { | ||
data.Commits = filterMergeCommits(data.Commits) | ||
amount = amount - (3 * len(data.Commits)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it tripled here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My thought was that if we use that heuristic, in this way we stay true to it. We asked for three times the amount we needed to get ~1/3 results of that. Updating the amount this way will keep that heuristic in every request. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better if we have a single location to handle amount heuristics. Can you try to combine this block and the above one (lines 114-120) into one? Preferably where the loop starts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wrong here, works better with subtracting only the original size. subtracting X3 amount caused receiving less results than asked. |
||
} | ||
|
||
if dot { | ||
graph.Write(data.Commits) | ||
} else { | ||
Write(commitsTemplate, data) | ||
} | ||
|
||
if amount != 0 { | ||
if amount <= 0 { | ||
// user request only one page | ||
break | ||
} | ||
|
@@ -177,6 +201,7 @@ | |
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") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rephrase, I don't understand what this means and why 333(?!)