support av sync on checked out worktree branches#677
support av sync on checked out worktree branches#677aviator-app[bot] merged 2 commits intomasterfrom
av sync on checked out worktree branches#677Conversation
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, 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 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. Changelog
Activity
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
|
There was a problem hiding this comment.
Code Review
This pull request adds support for av sync on branches that are checked out in separate Git worktrees. The implementation is robust, correctly identifying branches in worktrees, skipping those with uncommitted changes, and detaching the HEAD for clean ones before proceeding with the rebase. After the operation, it correctly restores the branches. The overall approach is solid. I've identified a high-severity issue regarding context propagation for cancellation handling, and a few medium-severity suggestions to enhance performance and code clarity in the new sequencer logic.
| case *RestackProgress: | ||
| if msg.err == nil && msg.result == nil { | ||
| // Finished the sequence. | ||
| restoreMessages := vm.state.Seq.RestoreWorktrees(context.Background()) |
There was a problem hiding this comment.
Using context.Background() here (and on line 94, and in runSeq* methods) prevents proper cancellation of the git operations. If the user cancels the command (e.g., with Ctrl-C), the context passed from cobra will be canceled, but since a background context is used here, the underlying git commands will continue to run detached from the UI. This can lead to a confusing state for the user.
To fix this, you should propagate the context.Context from the cobra.Command down into the RestackModel. The model can then use this context when calling long-running operations like RestoreWorktrees and repo.CheckoutBranch. This will ensure that if the main process is cancelled, all child operations are cancelled as well.
There was a problem hiding this comment.
Probably you should. But for now, you can use context.TODO()
| return messages, nil | ||
| } | ||
|
|
||
| func (seq *Sequencer) skipDescendants(skippedSet map[string]bool) { |
There was a problem hiding this comment.
The current implementation for finding descendant branches to skip is correct, but it could be inefficient for stacks with many branches. It repeatedly iterates over all operations in a loop until no more changes are detected, which can lead to a quadratic time complexity in the worst case (O(number of branches in stack ^ 2)).
A more performant approach would be to first build a parent-to-children map of the branch hierarchy. Then, you can perform a single graph traversal (like Breadth-First Search or Depth-First Search) starting from the initially skipped branches to find all their descendants. This would reduce the complexity to be linear in the number of branches and relationships, which is more scalable.
| var filtered []RestackOp | ||
| for _, op := range seq.Operations { | ||
| if seq.SkippedBranches[op.Name.Short()] == "" { | ||
| filtered = append(filtered, op) | ||
| } | ||
| } | ||
| seq.Operations = filtered |
There was a problem hiding this comment.
This implementation for filtering the Operations slice allocates a new slice (filtered) and then copies the elements. For better performance and memory efficiency, you can filter the slice in-place. This is a common Go idiom that avoids unnecessary allocations by reusing the underlying array of the original slice.
| var filtered []RestackOp | |
| for _, op := range seq.Operations { | |
| if seq.SkippedBranches[op.Name.Short()] == "" { | |
| filtered = append(filtered, op) | |
| } | |
| } | |
| seq.Operations = filtered | |
| filtered := seq.Operations[:0] | |
| for _, op := range seq.Operations { | |
| if seq.SkippedBranches[op.Name.Short()] == "" { | |
| filtered = append(filtered, op) | |
| } | |
| } | |
| seq.Operations = filtered |
| seq.CurrentSyncRef = "" | ||
| } | ||
|
|
||
| func (seq *Sequencer) RestoreWorktrees(ctx context.Context) []string { |
There was a problem hiding this comment.
This function has a side effect: it clears seq.DetachedWorktrees after restoring the branches. This mutation of the Sequencer state is not obvious from the function name RestoreWorktrees. This can make the code harder to understand and maintain.
To improve clarity, consider renaming the function to be more explicit about its side effects, for example, RestoreAndClearWorktrees. Alternatively, you could move the responsibility of clearing the map to the caller.
35e7908 to
7f38a38
Compare
7f38a38 to
c1fb68b
Compare
c1fb68b to
e4ba3ad
Compare
No description provided.