-
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
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?