diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:41 +0000 |
commit | 10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 (patch) | |
tree | bdffd5d80c26cf4a7a518281a204be1ace85b4c1 /vendor/gix/src/reference/edits.rs | |
parent | Releasing progress-linux version 1.70.0+dfsg1-9~progress7.99u1. (diff) | |
download | rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.tar.xz rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.zip |
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix/src/reference/edits.rs')
-rw-r--r-- | vendor/gix/src/reference/edits.rs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/vendor/gix/src/reference/edits.rs b/vendor/gix/src/reference/edits.rs new file mode 100644 index 000000000..aadd087ba --- /dev/null +++ b/vendor/gix/src/reference/edits.rs @@ -0,0 +1,75 @@ +/// +pub mod set_target_id { + use gix_ref::{transaction::PreviousValue, Target}; + + use crate::{bstr::BString, Reference}; + + mod error { + use gix_ref::FullName; + + /// The error returned by [`Reference::set_target_id()`][super::Reference::set_target_id()]. + #[derive(Debug, thiserror::Error)] + #[allow(missing_docs)] + pub enum Error { + #[error("Cannot change symbolic reference {name:?} into a direct one by setting it to an id")] + SymbolicReference { name: FullName }, + #[error(transparent)] + ReferenceEdit(#[from] crate::reference::edit::Error), + } + } + pub use error::Error; + + impl<'repo> Reference<'repo> { + /// Set the id of this direct reference to `id` and use `reflog_message` for the reflog (if enabled in the repository). + /// + /// Note that the operation will fail on symbolic references, to change their type use the lower level reference database, + /// or if the reference was deleted or changed in the mean time. + /// Furthermore, refrain from using this method for more than a one-off change as it creates a transaction for each invocation. + /// If multiple reference should be changed, use [Repository::edit_references()][crate::Repository::edit_references()] + /// or the lower level reference database instead. + #[allow(clippy::result_large_err)] + pub fn set_target_id( + &mut self, + id: impl Into<gix_hash::ObjectId>, + reflog_message: impl Into<BString>, + ) -> Result<(), Error> { + match &self.inner.target { + Target::Symbolic(name) => return Err(Error::SymbolicReference { name: name.clone() }), + Target::Peeled(current_id) => { + let changed = self.repo.reference( + self.name(), + id, + PreviousValue::MustExistAndMatch(Target::Peeled(current_id.to_owned())), + reflog_message, + )?; + *self = changed; + } + } + Ok(()) + } + } +} + +/// +pub mod delete { + use gix_ref::transaction::{Change, PreviousValue, RefEdit, RefLog}; + + use crate::Reference; + + impl<'repo> Reference<'repo> { + /// Delete this reference or fail if it was changed since last observed. + /// Note that this instance remains available in memory but probably shouldn't be used anymore. + pub fn delete(&self) -> Result<(), crate::reference::edit::Error> { + self.repo + .edit_reference(RefEdit { + change: Change::Delete { + expected: PreviousValue::MustExistAndMatch(self.inner.target.clone()), + log: RefLog::AndReference, + }, + name: self.inner.name.clone(), + deref: false, + }) + .map(|_| ()) + } + } +} |