Skip to main content

References

Struct References 

Source
pub struct References<'repo> { /* private fields */ }
Expand description

Resolve, list, and update refs for one open repository.

Implementations§

Source§

impl<'repo> References<'repo>

Source

pub fn new(repo: &'repo Repository) -> Self

Bind ref operations to repo.

Source

pub fn repository(&self) -> &'repo Repository

Underlying repository.

Source

pub fn resolve(&self, name: &RefName) -> Result<ObjectId>

Resolve a ref name to an object id, following symbolic refs.

§Errors

Propagates ref store and resolution errors.

§Examples
use grit_lib::refs::store::RefName;
use grit_lib::repo::{InitOptions, Repository};
use grit_lib::ident::Signature;
use grit_lib::porcelain::commit::{create_commit, CommitRequest};
use grit_lib::progress::NullProgress;
let dir = std::env::temp_dir().join("grit-refs-resolve-doc");
let repo = Repository::init(&dir, &InitOptions::default())?;
let mut req = CommitRequest::new("doc");
req.author = Some(Signature::new("Doc", "doc@example.com", repo.identity_now())?);
req.committer = Some(Signature::new("Doc", "doc@example.com", repo.identity_now())?);
req.allow_empty = true;
let _ = create_commit(&repo, &req, &mut NullProgress, &grit_lib::progress::NeverCancel)?;
let main = RefName::try_from("refs/heads/main").expect("valid ref");
let head = repo.references().resolve(&main)?;
assert!(!head.to_hex().is_empty());
Source

pub fn list(&self, prefix: &str) -> Result<Vec<(String, ObjectId)>>

List refs under prefix (for example "refs/heads/"), sorted by name.

§Errors

Propagates ref store iteration errors.

Source

pub fn query( &self, query: &RefQuery, options: &RefQueryOptions, ) -> Result<Vec<RefListing>, RefQueryError>

List refs matching query (patterns, sort, limit) through this repository’s ref store.

§Errors

Returns RefQueryError when the ref store cannot be read, when creator-date sort is requested without object data, or when an object read fails.

Source

pub fn update(&self, name: &RefName, oid: &ObjectId) -> Result<()>

Point name at oid, creating parent directories as needed.

Uses the RefStore installed on this repository (including injected in-memory stores), not a fresh open from git_dir alone.

oid must be stored in this repository, and must be a commit when name is a branch (refs/heads/…) or HEAD. This catches a commit that a concurrent prune deleted after you wrote it, instead of leaving the ref pointing at a missing object.

§Errors

The two object errors are returned as crate::error::Error::RefStore. The ref is unchanged on error.

§Examples
use grit_lib::refs::store::RefName;
use grit_lib::repo::{InitOptions, Repository};
use grit_lib::ident::Signature;
use grit_lib::porcelain::commit::{create_commit, CommitRequest};
use grit_lib::progress::NullProgress;
let dir = std::env::temp_dir().join("grit-refs-write-doc");
let repo = Repository::init(&dir, &InitOptions::default())?;
let mut req = CommitRequest::new("doc");
req.author = Some(Signature::new("Doc", "doc@example.com", repo.identity_now())?);
req.committer = Some(Signature::new("Doc", "doc@example.com", repo.identity_now())?);
req.allow_empty = true;
let commit = create_commit(&repo, &req, &mut NullProgress, &grit_lib::progress::NeverCancel)?.oid;
let name = RefName::try_from("refs/heads/handle-demo").expect("valid ref");
repo.references().update(&name, &commit)?;
assert_eq!(repo.references().resolve(&name)?, commit);
Source

pub fn reflog(&self, name: &RefName) -> Result<Vec<ReflogEntry>>

Read reflog entries for name (oldest first).

§Errors

Propagates reflog parse and backend errors.

Source

pub fn pack(&self, opts: &PackRefsOptions) -> Result<PackRefsReport>

Pack loose refs into packed-refs (files backend) or compact reftable tables.

§Errors

Propagates ref-store, locking, and I/O failures.

Trait Implementations§

Source§

impl<'repo> Clone for References<'repo>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'repo> Copy for References<'repo>

Source§

impl<'repo> Debug for References<'repo>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'repo> !RefUnwindSafe for References<'repo>

§

impl<'repo> !UnwindSafe for References<'repo>

§

impl<'repo> Freeze for References<'repo>

§

impl<'repo> Send for References<'repo>

§

impl<'repo> Sync for References<'repo>

§

impl<'repo> Unpin for References<'repo>

§

impl<'repo> UnsafeUnpin for References<'repo>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.