Generalize showing an inline status on several branches to any items

Deleting and pushing a range selection of tags will need to show their
operation on all the selected tags. Move the code from BranchesHelper
into a generic function that takes the items and the key of the context
that shows them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-09-27 11:19:25 +02:00
co-authored by Claude Opus 5.5
parent 02e103c873
commit fc6ed07747
2 changed files with 18 additions and 12 deletions
+1 -12
View File
@@ -504,18 +504,7 @@ func (self *BranchesHelper) PrepareFastForward(branches []*models.Branch) (func(
// Runs f on a worker with all the given branches shown as being in the given
// operation while it runs
func (self *BranchesHelper) WithInlineStatusOnBranches(branches []*models.Branch, operation types.ItemOperation, f func(gocui.Task) error) error {
return self.c.WithInlineStatus(branches[0], operation, context.LOCAL_BRANCHES_CONTEXT_KEY, func(task gocui.Task) error {
for _, branch := range branches[1:] {
self.c.State().SetItemOperation(branch, operation)
}
defer func() {
for _, branch := range branches[1:] {
self.c.State().ClearItemOperation(branch)
}
}()
return f(task)
})
return WithInlineStatusOnItems(self.c, branches, operation, context.LOCAL_BRANCHES_CONTEXT_KEY, f)
}
func (self *BranchesHelper) fetchUpstreamBranches(task gocui.Task, branches []*models.Branch) error {
@@ -94,6 +94,23 @@ func (self *InlineStatusHelper) WithInlineStatus(opts InlineStatusOpts, f func(g
}
}
// Runs f on a worker with all the given items shown as being in the given
// operation while it runs
func WithInlineStatusOnItems[T types.HasUrn](c *HelperCommon, items []T, operation types.ItemOperation, contextKey types.ContextKey, f func(gocui.Task) error) error {
return c.WithInlineStatus(items[0], operation, contextKey, func(task gocui.Task) error {
for _, item := range items[1:] {
c.State().SetItemOperation(item, operation)
}
defer func() {
for _, item := range items[1:] {
c.State().ClearItemOperation(item)
}
}()
return f(task)
})
}
func (self *InlineStatusHelper) start(opts InlineStatusOpts) {
self.c.State().SetItemOperation(opts.Item, opts.Operation)