Skip to content

Store each stack in its own file so commands on different stacks do not share one lock #644

Backlog

Description

@michal-samluk

Related: #568

Problem

v0.3.0 has the same cause as #568. gh-stack keeps all stacks in a clone in one file, gh-stack, in the Git common directory. Every command that changes any stack must read and write that one file, so every command must take the same lock. The single file is the bottleneck: two commands for unrelated stacks in different worktrees cannot run at the same time.

Proposal

Replace the single file with a directory that has one file for each stack:

.git/gh-stack/
  stacks/
    <stack-id>.json
  rebase-state/
    <stack-id>.json
  • A command reads and writes only the file of its own stack. Commands on different stacks touch different files, so they do not need a shared lock.
  • To list all stacks, read the directory.
  • To create a stack, add a new file. To delete a stack, delete its file.
  • Write each file atomically (write to a temporary file, then rename it).
  • Keep the stop-and-continue rebase state in one file for each stack too, so a stopped rebase in one worktree does not block other stacks.

Only two commands on the same stack can still conflict, which is the expected behavior.

This is the same solution as for a registry kept in one shared file in a repository. Separate changes to different entries cause merge conflicts in one file, but no conflicts when each entry has its own file. Here the lock has the same role that the merge conflict has there.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions