prevent creating cyclical dependencies#649
Conversation
Current Aviator status
This PR was merged using Aviator.
See the real-time status of this PR on the
Aviator webapp.
Use the Aviator Chrome Extension
to see the status of your PR within GitHub.
|
✅ FlexReview StatusCommon Owner:
Review SLO: |
Summary of ChangesHello @tulioz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the robustness of the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
29e685c to
e7d3062
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request effectively prevents the creation of cyclical branch dependencies by introducing a ValidateNoCycle function and integrating it into commands that modify branch parentage, such as adopt, branch-meta set, and reorder. A new av validate-db command is also added to help diagnose existing metadata inconsistencies, which is a great addition for repository health. The implementation is robust and includes relevant tests. I have one suggestion to remove a redundant check in the new validation command to avoid duplicate error reporting.
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to prevent cyclical dependencies between branches, which is a crucial safeguard for maintaining a healthy branch stack structure. The core logic is implemented in the new ValidateNoCycle function, which is correctly integrated into various commands that modify branch parent-child relationships, such as adopt, branch-meta set, and reorder.
The addition of the av validate-db command is a great enhancement, providing a tool to diagnose inconsistencies in the av metadata, including the newly-covered cyclical dependencies. The test coverage for the new logic is also solid.
I have one suggestion to improve the diagnostic output of the validate-db command to avoid reporting duplicate errors for the same underlying issue.
cmd/av/validate_db.go
Outdated
| if branch.Parent.Name == branchName { | ||
| issues = append(issues, diagnosticIssue{ | ||
| severity: diagnosticError, | ||
| branch: branchName, | ||
| message: "parent points to itself", | ||
| }) | ||
| } | ||
|
|
||
| if !branch.Parent.Trunk && branch.Parent.Name != "" { | ||
| if _, ok := tx.Branch(branch.Parent.Name); !ok { | ||
| issues = append(issues, diagnosticIssue{ | ||
| severity: diagnosticError, | ||
| branch: branchName, | ||
| message: fmt.Sprintf("parent %q is missing from av metadata", branch.Parent.Name), | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| if err := meta.ValidateNoCycle(tx, branchName, branch.Parent); err != nil { | ||
| issues = append(issues, diagnosticIssue{ | ||
| severity: diagnosticError, | ||
| branch: branchName, | ||
| message: "parent chain introduces cyclical branch dependencies", | ||
| }) | ||
| } |
There was a problem hiding this comment.
The check for a branch being its own parent (a self-loop) on lines 71-77 is a specific case of the general cyclical dependency check on lines 89-95. As meta.ValidateNoCycle also detects self-loops, running both checks unconditionally will result in duplicate error messages for the same issue.
To provide clearer diagnostics, it's better to combine these checks. You can use an else if to run the general cycle detection only if the more specific self-loop check fails. This avoids redundant error reporting and makes the validation output more precise for the user.
if branch.Parent.Name == branchName {
issues = append(issues, diagnosticIssue{
severity: diagnosticError,
branch: branchName,
message: "parent points to itself",
})
} else if err := meta.ValidateNoCycle(tx, branchName, branch.Parent); err != nil {
issues = append(issues, diagnosticIssue{
severity: diagnosticError,
branch: branchName,
message: "parent chain introduces cyclical branch dependencies",
})
}
if !branch.Parent.Trunk && branch.Parent.Name != "" {
if _, ok := tx.Branch(branch.Parent.Name); !ok {
issues = append(issues, diagnosticIssue{
severity: diagnosticError,
branch: branchName,
message: fmt.Sprintf("parent %q is missing from av metadata", branch.Parent.Name),
})
}
}| visited[current] = true | ||
|
|
||
| branch, ok := tx.Branch(current) | ||
| if !ok { |
There was a problem hiding this comment.
should we be returning here also?
There was a problem hiding this comment.
Why don't we return the error here?
internal/meta/branch.go
Outdated
| current := parent.Name | ||
| for current != "" { | ||
| if visited[current] { | ||
| return errors.New("would introduce cyclical branch dependencies") |
There was a problem hiding this comment.
is this error message surfaced anywhere?
There was a problem hiding this comment.
Not directly, but the callers to this method will post specific errors, for example in adopt:
"could not adopt branch %q because it would introduce cyclical branch dependencies",
currentBranch,
)
There was a problem hiding this comment.
I mean this particular error message string is irrelevant then? Consider returning an empty string avoid confusion
cmd/av/validate_db.go
Outdated
| }) | ||
| } | ||
|
|
||
| exists, err := repo.DoesBranchExist(ctx, branchName) |
There was a problem hiding this comment.
is this checking for remote branch? If not, shouldn't this check be done first. If the branch doesn't exist, rest of the checks would be invalid?
There was a problem hiding this comment.
Reordered, I only expect us to need this command in extreme edge cases already (this is the av validate-db command, not part of a normal operation).
e7d3062 to
fb5cc90
Compare
fb5cc90 to
29e0ba0
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces crucial validation to prevent cyclical dependencies in branch stacks by adding a ValidateNoCycle function and integrating it across the codebase where branch parents are modified. It also adds a new av validate-db command to help users diagnose metadata inconsistencies. The changes are well-structured and include relevant tests. I have a couple of suggestions to improve an error message for better clarity and to simplify some of the new validation logic.
d00307f to
83ed0a2
Compare
No description provided.