Skip to main content

Module migrate

Module migrate 

Source
Expand description

The one-time move of greengate 3.x’s local state to greengate 4.0’s names (plan “greengate 4.0 renames its data names”, a hard rename: 4.0 reads and writes only the new names, so what 3.x left on this machine is moved once instead of being read twice forever).

Per repository, the first 4.0 command moves, under a flock on $GIT_COMMON_DIR/greengate-migrate.lock:

  • every amont-* file and the amont/ folder in the common dir and in each linked worktree’s private git dir ($GIT_COMMON_DIR/worktrees/*), a ledger’s header line rewritten to its greengate-… spelling first;
  • the repository’s local amont.* config keys to greengate.*, each value copied (--get-all, then --add), then the old key removed.

then writes $GIT_COMMON_DIR/greengate-migrated, which every later command only stats. The machine’s global amont.* keys move the same way, once, under a lock in greengate’s config folder.

Every step is idempotent and ordered so an interrupted migration resumes: a header is rewritten before its file is renamed, and a key is removed only after all its values were copied. A migration that cannot finish leaves what it has not reached under the old names and refuses the command, naming what to fix.

One store is never moved: amont-held holds unstaged changes a 3.x check parked, and 3.x records no owner, so a live 3.x may still be about to put them back. The command is refused until greengate restore (which reads the old store, old_held_store) has put them back.

The old spellings live in names::old and here; the names test exempts both files.

Modules§

tracked
greengate migrate --tracked: the names a repository COMMITS, renamed in its work tree and staged, for the repository to commit (the fleet sweep lands one such commit per repository).

Structs§

Moved
What the first-run migration did, for greengate migrate to say.
Repo
The git dirs of one repository: the common dir, then each linked worktree’s private one.

Enums§

Direction
Which way a migration goes.
MigrateError
Why a migration stopped. Its Display is the line a refused command prints; the variants are what a caller or a test tells apart.
Scope
Where config keys are moved.

Functions§

config_dir
greengate’s folder of machine state: $XDG_CONFIG_HOME/greengate, else ~/.config/greengate.
ensure
Before any command but --help, --version, restore, uninstall, migrate, doctor and a --dry-run: migrate the repository the process stands in, once, then the machine’s global keys, once.
ensure_repo
The repository half of ensure: the one cwd stands in, once, unless a reverse asked 4.0 to leave it alone.
forget_global
Forget that the global keys were moved or reversed, so the next ensure reads the global config again: greengate migrate --global.
leftovers
What greengate doctor reports: the 3.x names still visible from here, one line each, with the command that moves them. Err when git could not answer: a failure never reads as “nothing left”.
migrate_repo
Migrate repo in direction, under its lock. Forward writes the done-marker and clears a reverse; reverse removes the done-marker and leaves the reversed one, so a 4.0 hook does not move it forward again.
move_keys
Move the amont.* keys of scope to greengate.* (or back); how many keys moved. Each value the old key holds is added to the new one unless already there (a migration interrupted between two --adds resumes without losing one), and the old key goes only once every value is present. A new key that holds a value of its own was set by the person: the new name wins, and the old values are dropped. amont.agent.* is greenpiste’s, never moved. A cluster.namespace of amont-gates is dropped on the way forward: 4.0’s default namespace is greengate-gates.
move_state
Move every name of [MOVES] in dir, in direction; how many moved.
old_held_store
The held store greengate 3.x left in this worktree, for greengate restore: $GIT_DIR/amont-held, when it exists.
reverse_global
Move the machine’s global keys back: greengate migrate --reverse --global.
system_git
git, with GIT_DIR set to dir when one is given, as GitFn says.

Type Aliases§

GitFn
A git command for move_keys: (GIT_DIR or None, args) → Ok(Some(stdout)) on exit 0, Ok(None) on exit 1 (git’s “nothing matched”), Err on any other end. A seam, so the tests drive a scratch repository and main composes the real one.