From d2c2a5f11ea8253dde9b6f827306f59727159685 Mon Sep 17 00:00:00 2001 From: Itamar Yuran Date: Thu, 12 Sep 2024 18:23:32 +0200 Subject: [PATCH 01/23] fresh start --- cmd/lakectl/cmd/log.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cmd/lakectl/cmd/log.go b/cmd/lakectl/cmd/log.go index a40812d66f1..005dfede8a5 100644 --- a/cmd/lakectl/cmd/log.go +++ b/cmd/lakectl/cmd/log.go @@ -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 + + // 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 ", @@ -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")) @@ -150,6 +164,9 @@ var logCmd = &cobra.Command{ After: pagination.NextOffset, }, } + if noMerges { + data.Commits = filterMergeCommits(data.Commits) + } if dot { graph.Write(data.Commits) @@ -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") From 5b9b954886916ec8b9fc97e076210affd7b68e7a Mon Sep 17 00:00:00 2001 From: Itamar Yuran Date: Mon, 16 Sep 2024 16:32:55 +0200 Subject: [PATCH 02/23] asking for more logs --- cmd/lakectl/cmd/common_helpers.go | 1 + cmd/lakectl/cmd/log.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index bf1b626ea18..05f91231c6b 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -40,6 +40,7 @@ const ( const ( internalPageSize = 1000 // when retrieving all records, use this page size under the hood defaultAmountArgumentValue = 100 // when no amount is specified, use this value for the argument + maxAmountNoMerges = 333 // when using --no-merges & amount, this const is the upper limit use huristic defaultPollInterval = 3 * time.Second // default interval while pulling tasks status minimumPollInterval = time.Second // minimum interval while pulling tasks status diff --git a/cmd/lakectl/cmd/log.go b/cmd/lakectl/cmd/log.go index 005dfede8a5..5975103e9dc 100644 --- a/cmd/lakectl/cmd/log.go +++ b/cmd/lakectl/cmd/log.go @@ -68,7 +68,7 @@ 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 + filteredCommits := make([]apigen.Commit, 0, len(commits)) // iterating through data.Commit, appending every instance with 1 or less parents. for _, commit := range commits { @@ -114,6 +114,10 @@ var logCmd = &cobra.Command{ if amountForPagination <= 0 { amountForPagination = internalPageSize } + // case --no-merges & --amount, ask for more results since some will filter out + if noMerges && amountForPagination < maxAmountNoMerges { + amountForPagination *= 3 + } logCommitsParams := &apigen.LogCommitsParams{ After: apiutil.Ptr(apigen.PaginationAfter(after)), Amount: apiutil.Ptr(apigen.PaginationAmount(amountForPagination)), @@ -164,8 +168,11 @@ var logCmd = &cobra.Command{ After: pagination.NextOffset, }, } + + // 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)) } if dot { @@ -174,7 +181,7 @@ var logCmd = &cobra.Command{ Write(commitsTemplate, data) } - if amount != 0 { + if amount <= 0 { // user request only one page break } From 413e13056ccde4b765c04193a59e974d1ead192a Mon Sep 17 00:00:00 2001 From: Itamar Yuran Date: Thu, 26 Sep 2024 12:02:27 +0300 Subject: [PATCH 03/23] with test --- cmd/lakectl/cmd/common_helpers.go | 5 ++- cmd/lakectl/cmd/log.go | 2 +- esti/golden/lakectl_log_no_merges.golden | 11 ++++++ esti/lakectl_test.go | 45 ++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 esti/golden/lakectl_log_no_merges.golden diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index 05f91231c6b..c8993db7adc 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -40,7 +40,10 @@ const ( const ( internalPageSize = 1000 // when retrieving all records, use this page size under the hood defaultAmountArgumentValue = 100 // when no amount is specified, use this value for the argument - maxAmountNoMerges = 333 // when using --no-merges & amount, this const is the upper limit use huristic + + // when using --no-merges & amount, this const is the upper limit to use huristic. + // The heuristic asks for 3*amount results since some will filter out + maxAmountNoMerges = 333 defaultPollInterval = 3 * time.Second // default interval while pulling tasks status minimumPollInterval = time.Second // minimum interval while pulling tasks status diff --git a/cmd/lakectl/cmd/log.go b/cmd/lakectl/cmd/log.go index 5975103e9dc..51db0629a06 100644 --- a/cmd/lakectl/cmd/log.go +++ b/cmd/lakectl/cmd/log.go @@ -172,7 +172,7 @@ var logCmd = &cobra.Command{ // 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)) + amount -= len(data.Commits) } if dot { diff --git a/esti/golden/lakectl_log_no_merges.golden b/esti/golden/lakectl_log_no_merges.golden new file mode 100644 index 00000000000..f9ea6cebb01 --- /dev/null +++ b/esti/golden/lakectl_log_no_merges.golden @@ -0,0 +1,11 @@ +ID: +Author: esti +Date: