-
Notifications
You must be signed in to change notification settings - Fork 422
OCPBUGS-60989: pkg/cli/admin/release/info: Mention elided first-parent, non-merge commits #2086
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…mmits Originally, the change-log generation focused on merge commits, which are common in many repositories. For example, in this 'oc' repository: $ git log --graph --oneline -10 * 559c67e (HEAD -> main, origin/main) Merge pull request #2083 from wking/oc-adm-upgrade-recommend-certificate-authority |\ | * b98b2e1 pkg/cli/admin/inspectalerts: Pass through --certificate-authority, etc. * | e7900fe Merge pull request #2082 from ardaguclu/code-rabbit-test |\ \ | |/ |/| | * ffe752e Remove mentioning about IRC channel from README * | f114b17 OTA-1581: Promote `oc adm upgrade status` to general availability (#2063) * | 1c54ec0 Merge pull request #2077 from hongkailiu/OTA-1601 |\ \ | * | 5f1dbb8 Move not-lines-related table.Write out of the loop | * | a352662 Truncate long reasons | * | 11f9f47 Reproduce the long reason issue | * | 970f883 status: improve line break handling for CO Message 4299014 (Add squash-merge support into oc adm release info, 2022-04-26, #1116), and mentioned the insights operator: $ git clone --depth 10 --branch master https://github.com/openshift/insights-operator $ cd insights-operator $ git log --graph --oneline -5 * da45333 (HEAD -> master, origin/master, origin/HEAD) OCPBUGS-60611: virt launcher logs gatherer (#1110) * 737b59b fix: incorrect anonymization of domains (#1111) * b5185da feat: add permissions to gather clusterrole (#1106) * 3099eb0 feat: Allow on-demand gathering during initial periodic run (#1109) * 7f8b40d RFE-4152: Add missing readonlyRootFilesystem (#1104) But some repositories also use a mixture of real merges and squash or rebase merges: $ git clone --depth 20 --branch main https://github.com/openshift/operator-framework-operator-controller $ cd operator-framework-operator-controller $ git log --graph --oneline -11 * 9319f22a (HEAD -> main, origin/main, origin/HEAD) UPSTREAM: <carry>: Ensure unique name for bad-catalog tests * 9b50498a UPSTREAM: <carry>: Adds ResourceVersion checks to the tls secret deletion test, mirroring the logic used in the certificate rotation test. This makes the test more robust by ensuring a new secret is created, not just that an existing one is still present. * 2ed1a5c8 UPSTREAM: <carry>: Migrate single/own namespace tests * 0c4f4303 UPSTREAM: <carry>: [OTE] add catalog tests from openshift/origin * 28299f38 UPSTREAM: <carry>: remove obsolete owners * 5aa7897f UPSTREAM: <carry>: [OTE] - Readme:Add info to help use payload-aggregate with new tests * 0bb19537 UPSTREAM: <carry>: Adds ResourceVersion checks to the tls secret deletion test, mirroring the logic used in the certificate rotation test. This makes the test more robust by ensuring a new secret is created, not just that an existing one is still present. * e9e3220f UPSTREAM: <carry>: [OTE] Add webhook to validate openshift-service-ca certificate rotation * a7d35272 Merge pull request #453 from openshift-bot/synchronize-upstream |\ | * d93f9d16 UPSTREAM: <drop>: configure the commit-checker | * 9a69e8ed UPSTREAM: <drop>: remove upstream GitHub configuration Before this commit, the logic would find the merge commits, assume that all content came in via merge commits, and not mention the other changes: $ git log --first-parent --merges --oneline a7d3527 Merge pull request #453 from openshift-bot/synchronize-upstream 4cae159 Merge pull request #449 from openshift-bot/synchronize-upstream 82f63dc Merge pull request #444 from openshift-bot/synchronize-upstream 6f91d84 Merge pull request #435 from openshift-bot/synchronize-upstream With this commit, we'll continue to include a line for each of those merges. But we'll also include the count of any elided, non-merge, first-parent commits: $ git log --first-parent --no-merges --oneline | wc -l 16 Folks interested in what exactly was elided will have to click through to 'Full changelog' or otherwise go digging. But at least they'll get the count of elided commits to know that there is more information there to see behind that click.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -215,34 +215,35 @@ var ( | |||||||||||||||||||||||||||||||||||
| rePrefix = regexp.MustCompile(`^(\[[\w\.\-]+\]\s*)+`) | ||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| func mergeLogForRepo(g gitInterface, repo string, from, to string) ([]MergeCommit, error) { | ||||||||||||||||||||||||||||||||||||
| func mergeLogForRepo(g gitInterface, repo string, from, to string) ([]MergeCommit, int, error) { | ||||||||||||||||||||||||||||||||||||
| if from == to { | ||||||||||||||||||||||||||||||||||||
| return nil, nil | ||||||||||||||||||||||||||||||||||||
| return nil, 0, nil | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| args := []string{"log", "--merges", "--topo-order", "--first-parent", "-z", "--pretty=format:%H %P%x1E%ct%x1E%s%x1E%b", fmt.Sprintf("%s..%s", from, to)} | ||||||||||||||||||||||||||||||||||||
| out, err := g.exec(args...) | ||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||
| // retry once if there's a chance we haven't fetched the latest commits | ||||||||||||||||||||||||||||||||||||
| if !strings.Contains(out, "Invalid revision range") { | ||||||||||||||||||||||||||||||||||||
| return nil, gitOutputToError(err, out) | ||||||||||||||||||||||||||||||||||||
| return nil, 0, gitOutputToError(err, out) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| if _, err := g.exec("fetch", "--all"); err != nil { | ||||||||||||||||||||||||||||||||||||
| return nil, gitOutputToError(err, out) | ||||||||||||||||||||||||||||||||||||
| return nil, 0, gitOutputToError(err, out) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| if _, err := g.exec("cat-file", "-e", from+"^{commit}"); err != nil { | ||||||||||||||||||||||||||||||||||||
| return nil, fmt.Errorf("from commit %s does not exist", from) | ||||||||||||||||||||||||||||||||||||
| return nil, 0, fmt.Errorf("from commit %s does not exist", from) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| if _, err := g.exec("cat-file", "-e", to+"^{commit}"); err != nil { | ||||||||||||||||||||||||||||||||||||
| return nil, fmt.Errorf("to commit %s does not exist", to) | ||||||||||||||||||||||||||||||||||||
| return nil, 0, fmt.Errorf("to commit %s does not exist", to) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| out, err = g.exec(args...) | ||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||
| return nil, gitOutputToError(err, out) | ||||||||||||||||||||||||||||||||||||
| return nil, 0, gitOutputToError(err, out) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| squash := false | ||||||||||||||||||||||||||||||||||||
| elidedCommits := 0 | ||||||||||||||||||||||||||||||||||||
| if out == "" { | ||||||||||||||||||||||||||||||||||||
| // some repositories use squash merging(like insights-operator) and | ||||||||||||||||||||||||||||||||||||
| // out which is populated by --merges flag is empty. Thereby, | ||||||||||||||||||||||||||||||||||||
|
|
@@ -251,9 +252,21 @@ func mergeLogForRepo(g gitInterface, repo string, from, to string) ([]MergeCommi | |||||||||||||||||||||||||||||||||||
| args = []string{"log", "--no-merges", "--topo-order", "-z", "--pretty=format:%H %P%x1E%ct%x1E%s%x1E%b", fmt.Sprintf("%s..%s", from, to)} | ||||||||||||||||||||||||||||||||||||
| out, err = g.exec(args...) | ||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||
| return nil, gitOutputToError(err, out) | ||||||||||||||||||||||||||||||||||||
| return nil, 0, gitOutputToError(err, out) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| squash = true | ||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||
| // some repositories use both real merges and squash or rebase merging. | ||||||||||||||||||||||||||||||||||||
| // Don't flood the output with single-commit noise, which might be poorly curated, | ||||||||||||||||||||||||||||||||||||
| // but do at least mention the fact that there are non-merge commits in the | ||||||||||||||||||||||||||||||||||||
| // first-parent line, so folks who are curious can click through to GitHub for | ||||||||||||||||||||||||||||||||||||
| // details. | ||||||||||||||||||||||||||||||||||||
| args := []string{"log", "--no-merges", "--first-parent", "-z", "--format=%H", fmt.Sprintf("%s..%s", from, to)} | ||||||||||||||||||||||||||||||||||||
| out, err := g.exec(args...) | ||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||
| return nil, 0, gitOutputToError(err, out) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| elidedCommits = strings.Count(out, "\x00") | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if klog.V(5).Enabled() { | ||||||||||||||||||||||||||||||||||||
|
|
@@ -262,16 +275,16 @@ func mergeLogForRepo(g gitInterface, repo string, from, to string) ([]MergeCommi | |||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| var commits []MergeCommit | ||||||||||||||||||||||||||||||||||||
| if len(out) == 0 { | ||||||||||||||||||||||||||||||||||||
| return nil, nil | ||||||||||||||||||||||||||||||||||||
| return nil, elidedCommits, nil | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| for _, entry := range strings.Split(out, "\x00") { | ||||||||||||||||||||||||||||||||||||
| records := strings.Split(entry, "\x1e") | ||||||||||||||||||||||||||||||||||||
| if len(records) != 4 { | ||||||||||||||||||||||||||||||||||||
| return nil, fmt.Errorf("unexpected git log output width %d columns", len(records)) | ||||||||||||||||||||||||||||||||||||
| return nil, elidedCommits, fmt.Errorf("unexpected git log output width %d columns", len(records)) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| unixTS, err := strconv.ParseInt(records[1], 10, 64) | ||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
280
to
286
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. 🛠️ Refactor suggestion Harden parsing against trailing NUL entries git log -z commonly NUL-terminates entries; a trailing NUL would yield an empty entry causing the width check to fail. Skip empty entries to be robust across Git versions. - for _, entry := range strings.Split(out, "\x00") {
+ for _, entry := range strings.Split(out, "\x00") {
+ if len(entry) == 0 {
+ continue
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Member
Author
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'm not touching this null-splitting logic in this branch, I'm just adding 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. @wking Understood! You're absolutely right to keep the scope focused on the elided commits functionality. The parsing robustness improvement can be addressed separately if needed. Thanks for clarifying the scope boundaries of this PR. |
||||||||||||||||||||||||||||||||||||
| return nil, fmt.Errorf("unexpected timestamp: %v", err) | ||||||||||||||||||||||||||||||||||||
| return nil, elidedCommits, fmt.Errorf("unexpected timestamp: %v", err) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| commitValues := strings.Split(records[0], " ") | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
|
@@ -304,7 +317,7 @@ func mergeLogForRepo(g gitInterface, repo string, from, to string) ([]MergeCommi | |||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| mergeCommit.PullRequest, err = strconv.Atoi(m[1]) | ||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||
| return nil, fmt.Errorf("could not extract PR number from %q: %v", mergeMsg, err) | ||||||||||||||||||||||||||||||||||||
| return nil, elidedCommits, fmt.Errorf("could not extract PR number from %q: %v", mergeMsg, err) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| if len(msg) == 0 { | ||||||||||||||||||||||||||||||||||||
| msg = "Merge" | ||||||||||||||||||||||||||||||||||||
|
|
@@ -314,7 +327,7 @@ func mergeLogForRepo(g gitInterface, repo string, from, to string) ([]MergeCommi | |||||||||||||||||||||||||||||||||||
| commits = append(commits, mergeCommit) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return commits, nil | ||||||||||||||||||||||||||||||||||||
| return commits, elidedCommits, nil | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // ensureCloneForRepo ensures that the repo exists on disk, is cloned, and has remotes for | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
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.
I assume that this filter out the commits that we will print and only select the ones that are discarded?