pub struct FileRefTransaction<'a> { /* private fields */ }Implementations§
Source§impl<'a> FileRefTransaction<'a>
impl<'a> FileRefTransaction<'a>
Sourcepub fn with_hook(self, hook: &'a dyn ReferenceTransactionHook) -> Self
pub fn with_hook(self, hook: &'a dyn ReferenceTransactionHook) -> Self
Attach the reference-transaction hook handler this transaction fires at
each phase. Without one the transaction behaves exactly as before (no
hook is run). This is the single point through which every ref-write path
— update-ref, symbolic-ref, update-ref --stdin, push — gets hook
coverage, so a new write site cannot silently skip the hook.
Sourcepub fn update(&mut self, update: RefUpdate)
pub fn update(&mut self, update: RefUpdate)
Queue a ref update whose precondition comes from RefUpdate::expected
(None = no check; Some(target) = the ref must currently match
target). For create-only or match-or-create semantics use
update_to.
Sourcepub fn update_to(
&mut self,
name: impl Into<String>,
new: RefTarget,
precondition: RefPrecondition,
reflog: Option<ReflogEntry>,
)
pub fn update_to( &mut self, name: impl Into<String>, new: RefTarget, precondition: RefPrecondition, reflog: Option<ReflogEntry>, )
Queue a ref update with an explicit compare-and-swap RefPrecondition
(e.g. MustNotExist for create-only, or
ExistingMustMatch for
match-or-create). The precondition is re-verified while the ref is
locked.
Sourcepub fn delete(&mut self, delete: DeleteRef)
pub fn delete(&mut self, delete: DeleteRef)
Queue a direct ref delete using the historical checked-delete shape.
expected_old = None means “delete any direct ref”; Some(oid) means
the direct ref must currently point at that object id.
Sourcepub fn delete_with_precondition(
&mut self,
name: impl Into<String>,
precondition: RefDeletePrecondition,
_reflog: Option<DeleteRefReflog>,
)
pub fn delete_with_precondition( &mut self, name: impl Into<String>, precondition: RefDeletePrecondition, _reflog: Option<DeleteRefReflog>, )
Queue a ref delete with an explicit direct/symbolic precondition.
_reflog is accepted for API compatibility but ignored: git unlinks the
reflog on delete rather than writing a deletion entry, so a
caller-supplied deletion message has no on-disk effect.
Sourcepub fn commit(self) -> Result<()>
pub fn commit(self) -> Result<()>
Commit all queued updates and deletes atomically and durably.
All ref changes succeed together or none take effect. For the loose-ref backend the sequence is:
- Preserve the historical update-only coalescing behavior. Mixed transactions reject duplicate ref names so a delete and write cannot target the same ref ambiguously.
- Take an exclusive
<ref>.lockfile for every ref up front, and lockpacked-refsbefore checked deletes can inspect or rewrite it. - Re-verify every precondition while holding the locks, closing the check-then-write race that a pre-lock verification would leave open.
- Stage every write, delete marker, and packed-refs rewrite.
- Rename/remove staged paths, rolling back already-applied paths if a later step fails.
If any step fails, every path already changed in this commit is restored to the exact bytes it held beforehand (or removed if it did not exist), and all outstanding lock files are deleted. Reflog entries are appended only after every ref change has landed.