Skip to content

Simplify pkg/cwhub/sync.go#165

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/simplify-cwhub-sync
Draft

Simplify pkg/cwhub/sync.go#165
Copilot wants to merge 3 commits intomasterfrom
copilot/simplify-cwhub-sync

Conversation

Copy link

Copilot AI commented Feb 23, 2026

Three targeted simplifications to sync.go reducing redundant iteration, duplicate logic, and O(n) lookups.

  • syncDir: Replace double iteration (skip-local, then skip-non-local) with slices.SortStableFunc to partition non-local items first, then single loop
  • updateNonLocalItem: For hub items (spec.inhub), construct item name from fauthor/fname and use direct GetItem() O(1) lookup instead of iterating all items of the type. Remove redundant parameters (path = spec.path, symlinkTarget = spec.target). Remove now-dead validPath method from item.go
  • checkSubItemVersions: Merge duplicate sub.State.Tainted branches into single check. Remove redundant i.State.IsInstalled() guard (already guaranteed by early continue)
// Before: two passes over specs
for _, spec := range specs {
    if spec.local { continue }
    h.addItemFromSpec(spec)
}
for _, spec := range specs {
    if !spec.local { continue }
    h.addItemFromSpec(spec)
}

// After: sort + single pass
slices.SortStableFunc(specs, func(a, b *itemSpec) int {
    if a.local == b.local { return 0 }
    if !a.local { return -1 }
    return 1
})
for _, spec := range specs {
    h.addItemFromSpec(spec)
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • x
    • Triggering command: /tmp/go-build3876759510/b001/cwhub.test /tmp/go-build3876759510/b001/cwhub.test -test.paniconexit0 -test.count=1 -test.timeout=2m0s /tmp/go-build3876759510/b249/vet.cfg 0.1-go1.25.1.linux-amd64/src/run--gdwarf-5 r ux-amd64/pkg/tool/linux_amd64/vet (dns block)
    • Triggering command: /tmp/go-build2351875117/b001/cwhub.test /tmp/go-build2351875117/b001/cwhub.test -test.paniconexit0 -test.count=1 -test.timeout=2m0s conf�� 5519/field --global ux-amd64/pkg/tool/linux_amd64/vet pull.rebase 0.1-go1.25.1.lin-unsafeptr=false (dns block)
    • Triggering command: /tmp/go-build2071247285/b001/cwhub.test /tmp/go-build2071247285/b001/cwhub.test -test.paniconexit0 -test.timeout=10m0s -test.count=1 6759�� pkg/mod/golang.org/toolchain@v0.-errorsas _cgo_.o ux-amd64/pkg/tool/linux_amd64/vet --glob !.git --with-filename ux-amd64/pkg/tool/linux_amd64/vet 6759�� pkg/mod/golang.org/toolchain@v0.-errorsas pkg/mod/golang.org/toolchain@v0.-ifaceassert ux-amd64/pkg/tool/linux_amd64/vet -p o_import.go l/linux_amd64/co. ux-amd64/pkg/too-v (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@semanticdiff-com
Copy link

semanticdiff-com bot commented Feb 23, 2026

Review changes with  SemanticDiff

Changed Files
File Status
  pkg/cwhub/sync.go  29% smaller
  pkg/cwhub/item.go  0% smaller

Copilot AI and others added 2 commits February 23, 2026 22:16
…ks, direct hub item lookup

Co-authored-by: mmetc <92726601+mmetc@users.noreply.github.com>
Co-authored-by: mmetc <92726601+mmetc@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor sync.go to simplify cwhub Simplify pkg/cwhub/sync.go Feb 23, 2026
Copilot AI requested a review from mmetc February 23, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants