Struct crates_index_diff::Index

source ·
pub struct Index {
    pub seen_ref_name: &'static str,
    pub branch_name: &'static str,
    pub remote_name: Option<BString>,
    /* private fields */
}
Expand description

A wrapper for a repository of the crates.io index.

Fields§

§seen_ref_name: &'static str

The name and path of the reference used to keep track of the last seen state of the crates.io repository. The default value is refs/heads/crates-index-diff_last-seen.

§branch_name: &'static str

The name of the branch to fetch. This value also affects the tracking branch.

§remote_name: Option<BString>

The name of the symbolic name of the remote to fetch from. If None, obtain the remote name from the configuration of the currently checked-out branch.

Implementations§

source§

impl Index

Find changes without modifying the underling repository

source

pub fn peek_changes(&self) -> Result<(Vec<Change>, ObjectId), Error>

As peek_changes_with_options(), but without the options.

source

pub fn peek_changes_ordered(&self) -> Result<(Vec<Change>, ObjectId), Error>

As peek_changes() but provides changes similar to those in the crates index.

source

pub fn peek_changes_with_options<P>( &self, progress: P, should_interrupt: &AtomicBool, order: Order ) -> Result<(Vec<Change>, ObjectId), Error>
where P: NestedProgress, P::SubProgress: 'static,

Return all Changes that are observed between the last time peek_changes*(…) was called and the latest state of the crates.io index repository, which is obtained by fetching the remote called origin or whatever is configured for the current HEAD branch and lastly what it should be based on knowledge about he crates index. The Self::last_seen_reference() will not be created or updated. The second field in the returned tuple is the commit object to which the changes were provided. If one would set the Self::last_seen_reference() to that object, the effect is exactly the same as if Self::fetch_changes() had been called.

The progress and should_interrupt parameters are used to provide progress for fetches and allow these operations to be interrupted gracefully.

§Resource Usage

As this method fetches the git repository, loose objects or small packs may be created. Over time, these will accumulate and either slow down subsequent operations, or cause them to fail due to exhaustion of the maximum number of open file handles as configured with ulimit.

Thus it is advised for the caller to run git gc occasionally based on their own requirements and usage patterns.

source

pub fn changes_between_commits( &self, from: impl Into<ObjectId>, to: impl Into<ObjectId> ) -> Result<Vec<Change>, Error>

Similar to Self::changes(), but requires from and to objects to be provided. They may point to either Commits or Trees.

§Returns

A list of atomic changes that were performed on the index between the two revisions.

§Grouping and Ordering

The changes are grouped by the crate they belong to. The order of the changes for each crate is deterministic as they are ordered by line number, ascending. The order of crates is non-deterministic.

If a specific order is required, the changes must be sorted by the caller.

source

pub fn changes_between_ancestor_commits( &self, ancestor_commit: impl Into<ObjectId>, current_commit: impl Into<ObjectId> ) -> Result<(Vec<Change>, Order), Error>

Similar to Self::changes(), but requires ancestor_commit and current_commit objects to be provided with ancestor_commit being in the ancestry of current_commit.

If the invariants regarding ancestor_commit and current_commit are not upheld, we fallback to changes_between_commits() which doesn’t have such restrictions. This can happen if the crates-index was squashed for instance.

§Returns

A list of atomic changes that were performed on the index between the two revisions, but looking at it one commit at a time, along with the Order that the changes are actually in in case one of the invariants wasn’t met.

§Grouping and Ordering

Note that the order of the changes for each crate is deterministic, should they happen within one commit, as the ordering is imposed to be by line number, ascending. Typically one commit does not span multiple crates, but if it does, for instance when rollups happen, then the order of crates is also non-deterministic.

source§

impl Index

Find changes while changing the underlying repository in one way or another.

source

pub fn fetch_changes(&self) -> Result<Vec<Change>, Error>

As fetch_changes_with_options(), but without the options.

source

pub fn fetch_changes_ordered(&self) -> Result<Vec<Change>, Error>

As fetch_changes(), but returns an ordered result.

source

pub fn fetch_changes_with_options<P>( &self, progress: P, should_interrupt: &AtomicBool, order: Order ) -> Result<Vec<Change>, Error>
where P: NestedProgress, P::SubProgress: 'static,

Return all Changes that are observed between the last time this method was called and the latest state of the crates.io index repository, which is obtained by fetching the remote called origin. The Self::last_seen_reference() will be created or adjusted to point to the latest fetched state, which causes this method to have a different result each time it is called.

The progress and should_interrupt parameters are used to provide progress for fetches and allow these operations to be interrupted gracefully.

order configures how changes should be ordered.

§Resource Usage

As this method fetches the git repository, loose objects or small packs may be created. Over time, these will accumulate and either slow down subsequent operations, or cause them to fail due to exhaustion of the maximum number of open file handles as configured with ulimit.

Thus it is advised for the caller to run git gc occasionally based on their own requirements and usage patterns.

source

pub fn set_last_seen_reference(&self, to: ObjectId) -> Result<(), Error>

Set the last seen reference to the given Oid. It will be created if it does not yet exists.

source

pub fn changes( &self, from: impl AsRef<str>, to: impl AsRef<str> ) -> Result<Vec<Change>, Error>

Return all CreateVersions observed between from and to. Both parameter are ref-specs pointing to either a commit or a tree. Learn more about specifying revisions in the official documentation

§Returns

A list of atomic chanes that were performed on the index between the two revisions.

§Grouping and Ordering

The changes are grouped by the crate they belong to. The order of the changes for each crate is deterministic as they are ordered by line number, ascending. The order of crates is also non-deterministic.

If a specific order is required, the changes must be sorted by the caller.

source§

impl Index

Initialization

source

pub fn from_path_or_cloned_with_options<P>( path: impl AsRef<Path>, progress: P, should_interrupt: &AtomicBool, _: CloneOptions ) -> Result<Index, Error>
where P: NestedProgress, P::SubProgress: 'static,

Return a new Index instance from the given path, which should contain a bare clone of the crates.io index. If the directory does not contain the repository or does not exist, it will be cloned from the official location automatically (with complete history).

An error will occour if the repository exists and the remote URL does not match the given repository URL.

§Examples
use std::sync::atomic::AtomicBool;
use crates_index_diff::{Index, index, git};

// Note that credentials are automatically picked up from the standard git configuration.
let mut options = index::CloneOptions {
  url: "https://github.com/rust-lang/staging.crates.io-index".into(),
};


let index = Index::from_path_or_cloned_with_options(path, gix::progress::Discard, &AtomicBool::default(), options)?;
source

pub fn from_path_or_cloned(path: impl AsRef<Path>) -> Result<Index, Error>

Return a new Index instance from the given path, which should contain a bare or non-bare clone of the crates.io index. If the directory does not contain the repository or does not exist, it will be cloned from the official location automatically (with complete history).

source§

impl Index

Access

source

pub fn repository(&self) -> &Repository

Return the crates.io repository.

source

pub fn repository_mut(&mut self) -> &mut Repository

Return the crates.io repository, mutably.

source

pub fn last_seen_reference(&self) -> Result<Reference<'_>, Error>

Return the reference pointing to the state we have seen after calling fetch_changes().

Auto Trait Implementations§

§

impl !Freeze for Index

§

impl !RefUnwindSafe for Index

§

impl Send for Index

§

impl !Sync for Index

§

impl Unpin for Index

§

impl !UnwindSafe for Index

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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.