Make repository ids self-descriptive and consolidate remote persistence#462
Merged
Conversation
…al settings Remote repositories now persist as self-descriptive `[user@]host[:port]<path>` ids in a top-level `SettingsFile.remoteRepositoryRoots` (the sibling of `repositoryRoots`), instead of `RemoteRepositoryConfig` entries nested in `GlobalSettings`. Both lists merge into the one in-memory repository roster. - Drop the `remote://` scheme prefix: the authority already disambiguates, and a local id is always an absolute path (leading `/`) while a remote authority never is, so that is the local-vs-remote discriminator. - Drop the `folder:` worktree-id prefix; git-vs-folder is a runtime classification carried by `Worktree.kind`, not baked into a persisted id. The kind argument is now required so a worktree can't be silently misclassified. - Dissolve `RemoteRepositoryConfig` into `RepositoryLocation.remote`, and drop the dead `displayName` and `RemoteHost.worktreeBasePath` fields. - Add `RemoteHost.init?(authority:)` and `RepositoryLocation.parse(persistedID:)` to round-trip an id back to host + path. - Teach `RepositoryPathNormalizer.normalize` to leave remote ids verbatim so a pinned / focused / archived remote worktree id is no longer mangled by `URL(fileURLWithPath:)`. - One-shot launch migration (sidebar schema v2): drains the retired `global.remoteRepositories` into `remoteRepositoryRoots` and strips the `remote://` / `folder:` prefixes from persisted repository, pin, and sidebar ids. Idempotent and gated on the schema version.
- Capture the retired global.remoteRepositories before the v0->v1 sidebar migration can re-encode settings and drop the field; skip both passes when settings.json is present but unreadable so a save can't strip it first. - Treat a present-but-unreadable/undecodable sidebar.json as a transient error: bail instead of overwriting the layout with empty state and stamping the schema, which would skip the migration permanently. - Re-key terminal layouts (layouts.json) off the retired remote:// / folder: prefixes so a remote/folder worktree's tabs restore after upgrade. - Decode the legacy remote array per-element lossily so one malformed entry doesn't strand the rest. - Bracket IPv6 hosts in authority/displayAuthority so a bare IPv6 literal round-trips through RemoteHost(authority:); the ssh CLI still gets the bare host. - Log unparseable persisted remote ids instead of dropping them silently. - Add regression tests for each.
split(separator:) omits empty subsequences, so the leaf is never an empty string: drop the redundant emptiness check and force-unwrap.
… gates - Snapshot settings.json + sidebar.json (raw) before any migration or settings hydration can rewrite them, so a botched migration or a downgrade is recoverable by hand. - Drain captured legacy remotes into remoteRepositoryRoots before the sidebar read/gate, so a corrupt sidebar.json can't discard them. - Bail the migration (retry next launch) when a present layouts.json can't be re-keyed, instead of stamping the schema and orphaning its keys. - Add tests for the snapshot, drain-before-sidebar, and layout re-key paths.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
[user@]host[:port]<path>ids in a top-levelSettingsFile.remoteRepositoryRoots(the sibling ofrepositoryRoots), instead ofRemoteRepositoryConfigentries nested inGlobalSettings. Both lists merge into the one in-memory roster.remote://id scheme prefix: the authority already disambiguates, and a local id is always an absolute path (leading/) while a remote authority never is, so that is the local-vs-remote discriminator.folder:worktree-id prefix; git-vs-folder is now a runtimeWorktree.kindrather than baked into a persisted id (a directory can be (un)initialized as a git repo at any time). Thekindargument is required so a worktree can't be silently misclassified.RemoteRepositoryConfig; removed the deaddisplayNameandRemoteHost.worktreeBasePathfields.RemoteHost.init?(authority:)andRepositoryLocation.parse(persistedID:)to round-trip an id back to host + path (IPv6 literals are bracketed).RepositoryPathNormalizer.normalizeto leave remote ids verbatim, so a pinned / focused / archived remote worktree id is no longer mangled byURL(fileURLWithPath:).Migration
A one-shot launch migration (sidebar schema v1 -> v2) drains the retired
global.remoteRepositoriesintoremoteRepositoryRootsand strips theremote:///folder:prefixes from persisted repository, pin, sidebar, and terminal-layout ids. Idempotent and gated on the schema version.Data safety
settings.json+sidebar.jsonare snapshotted to*.pre-remote-id-migration.bakbefore any migration write or settings hydration, so a botched migration or a downgrade is recoverable by hand.Known limitation
An IPv6-literal remote host's sidebar customization / pins / layouts will not carry over (legacy keys were unbracketed, new ids are bracketed). The repository itself still migrates, and the state is recoverable from the snapshot. This is vanishingly rare (IPv6 literal SSH hosts).
Downgrade
One-way: an older build won't see migrated remotes (and never round-tripped the dropped
displayName). The pre-migration snapshot allows manual recovery.Testing
make testgreen (1936 tests, 11 pre-existing known issues);make checkclean.