You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
replay: make atomic ref updates the default behavior
The git replay command currently outputs update commands that must be
piped to git update-ref --stdin to actually update references:
git replay --onto main topic1..topic2 | git update-ref --stdin
This design has significant limitations for server-side operations. The
two-command pipeline creates coordination complexity, provides no atomic
transaction guarantees by default, and complicates automation in bare
repository environments where git replay is primarily used.
During extensive mailing list discussion, multiple maintainers identified
that the current approach forces users to opt-in to atomic behavior rather
than defaulting to the safer, more reliable option. Elijah Newren noted
that the experimental status explicitly allows such behavior changes, while
Patrick Steinhardt highlighted performance concerns with individual ref
updates in the reftable backend.
The core issue is that git replay was designed around command output rather
than direct action. This made sense for a plumbing tool, but creates barriers
for the primary use case: server-side operations that need reliable, atomic
ref updates without pipeline complexity.
This patch changes the default behavior to update refs directly using Git's
ref transaction API:
git replay --onto main topic1..topic2
# No output; all refs updated atomically or none
The implementation uses ref_store_transaction_begin() with atomic mode by
default, ensuring all ref updates succeed or all fail as a single operation.
This leverages git replay's existing server-side strengths (in-memory operation,
no work tree requirement) while adding the atomic guarantees that server
operations require.
For users needing the traditional pipeline workflow, --output-commands
preserves the original behavior:
git replay --output-commands --onto main topic1..topic2 | git update-ref --stdin
The --allow-partial option enables partial failure tolerance. However, following
maintainer feedback, it implements a "strict success" model: the command exits
with code 0 only if ALL ref updates succeed, and exits with code 1 if ANY
updates fail. This ensures that --allow-partial changes error reporting style
(warnings vs hard errors) but not success criteria, handling edge cases like
"no updates needed" cleanly.
Implementation details:
- Empty commit ranges now return success (exit code 0) rather than failure,
as no commits to replay is a valid successful operation
- Added comprehensive test coverage with 12 new tests covering atomic behavior,
option validation, bare repository support, and edge cases
- Fixed test isolation issues to prevent branch state contamination between tests
- Maintains C89 compliance and follows Git's established coding conventions
- Refactored option validation to use die_for_incompatible_opt2() for both
--advance/--contained and --allow-partial/--output-commands conflicts,
providing consistent error reporting
- Fixed --allow-partial exit code behavior to implement "strict success" model
where any ref update failures result in exit code 1, even with partial tolerance
- Updated documentation with proper line wrapping, consistent terminology using
"old default behavior", performance context, and reorganized examples for clarity
- Eliminates individual ref updates (refs_update_ref calls) that perform
poorly with reftable backend
- Uses only batched ref transactions for optimal performance across all
ref backends
- Avoids naming collision with git rebase --update-refs by using distinct
option names
- Defaults to atomic behavior while preserving pipeline compatibility
The result is a command that works better for its primary use case (server-side
operations) while maintaining full backward compatibility for existing workflows.
Signed-off-by: Siddharth Asthana <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
0 commit comments