perf(git): enable parallel checkout for faster worktree creation
Configure checkout.workers=0 (auto-detect CPU count) on all clone
operations. Git 2.33+ supports this feature which parallelizes file
creation during checkout, significantly speeding up worktree creation.
This is applied to:
- Clone() - regular clones
- CloneWithReference() - clones with local reference
- CloneBare() - bare clones (primary source for worktrees)
- CloneBareWithReference() - bare clones with reference
The config is set per-repo so worktrees inherit it automatically.
Older git versions silently ignore this config (non-fatal).
Recovered from: 4ed3e983 (lost commit)
This commit is contained in:
@@ -266,6 +266,8 @@ func (g *Git) Clone(url, dest string) error {
|
|||||||
if err := configureHooksPath(dest); err != nil {
|
if err := configureHooksPath(dest); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// Enable parallel checkout for faster worktree operations
|
||||||
|
_ = configureParallelCheckout(dest)
|
||||||
// Configure sparse checkout to exclude .claude/ from source repo
|
// Configure sparse checkout to exclude .claude/ from source repo
|
||||||
return ConfigureSparseCheckout(dest)
|
return ConfigureSparseCheckout(dest)
|
||||||
}
|
}
|
||||||
@@ -306,6 +308,8 @@ func (g *Git) CloneWithReference(url, dest, reference string) error {
|
|||||||
if err := configureHooksPath(dest); err != nil {
|
if err := configureHooksPath(dest); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// Enable parallel checkout for faster worktree operations
|
||||||
|
_ = configureParallelCheckout(dest)
|
||||||
// Configure sparse checkout to exclude .claude/ from source repo
|
// Configure sparse checkout to exclude .claude/ from source repo
|
||||||
return ConfigureSparseCheckout(dest)
|
return ConfigureSparseCheckout(dest)
|
||||||
}
|
}
|
||||||
@@ -342,10 +346,27 @@ func (g *Git) CloneBare(url, dest string) error {
|
|||||||
return fmt.Errorf("moving clone to destination: %w", err)
|
return fmt.Errorf("moving clone to destination: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable parallel checkout for faster worktree operations
|
||||||
|
_ = configureParallelCheckout(dest)
|
||||||
// Configure refspec so worktrees can fetch and see origin/* refs
|
// Configure refspec so worktrees can fetch and see origin/* refs
|
||||||
return configureRefspec(dest)
|
return configureRefspec(dest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// configureParallelCheckout enables parallel checkout workers for faster file operations.
|
||||||
|
// Git 2.33+ supports checkout.workers which parallelizes file creation during checkout,
|
||||||
|
// significantly speeding up worktree creation and clone operations.
|
||||||
|
func configureParallelCheckout(repoPath string) error {
|
||||||
|
// Enable parallel checkout with automatic worker count (uses all CPUs)
|
||||||
|
cmd := exec.Command("git", "-C", repoPath, "config", "checkout.workers", "0")
|
||||||
|
var stderr bytes.Buffer
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
// Non-fatal: older git versions don't support this
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// configureHooksPath sets core.hooksPath to use the repo's .githooks directory
|
// configureHooksPath sets core.hooksPath to use the repo's .githooks directory
|
||||||
// if it exists. This ensures Gas Town agents use the pre-push hook that blocks
|
// if it exists. This ensures Gas Town agents use the pre-push hook that blocks
|
||||||
// pushes to non-main branches (internal PRs are not allowed).
|
// pushes to non-main branches (internal PRs are not allowed).
|
||||||
@@ -424,6 +445,8 @@ func (g *Git) CloneBareWithReference(url, dest, reference string) error {
|
|||||||
return fmt.Errorf("moving clone to destination: %w", err)
|
return fmt.Errorf("moving clone to destination: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable parallel checkout for faster worktree operations
|
||||||
|
_ = configureParallelCheckout(dest)
|
||||||
// Configure refspec so worktrees can fetch and see origin/* refs
|
// Configure refspec so worktrees can fetch and see origin/* refs
|
||||||
return configureRefspec(dest)
|
return configureRefspec(dest)
|
||||||
}
|
}
|
||||||
@@ -483,10 +506,10 @@ func (g *Git) CommitAll(message string) error {
|
|||||||
|
|
||||||
// GitStatus represents the status of the working directory.
|
// GitStatus represents the status of the working directory.
|
||||||
type GitStatus struct {
|
type GitStatus struct {
|
||||||
Clean bool
|
Clean bool
|
||||||
Modified []string
|
Modified []string
|
||||||
Added []string
|
Added []string
|
||||||
Deleted []string
|
Deleted []string
|
||||||
Untracked []string
|
Untracked []string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1208,8 +1231,8 @@ type UncommittedWorkStatus struct {
|
|||||||
StashCount int
|
StashCount int
|
||||||
UnpushedCommits int
|
UnpushedCommits int
|
||||||
// Details for error messages
|
// Details for error messages
|
||||||
ModifiedFiles []string
|
ModifiedFiles []string
|
||||||
UntrackedFiles []string
|
UntrackedFiles []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean returns true if there is no uncommitted work.
|
// Clean returns true if there is no uncommitted work.
|
||||||
|
|||||||
Reference in New Issue
Block a user