Struct cargo::sources::registry::remote::RemoteRegistry

source ·
pub struct RemoteRegistry<'gctx> {
    name: InternedString,
    index_path: Filesystem,
    cache_path: Filesystem,
    source_id: SourceId,
    index_git_ref: GitReference,
    gctx: &'gctx GlobalContext,
    tree: RefCell<Option<Tree<'static>>>,
    repo: LazyCell<Repository>,
    head: Cell<Option<Oid>>,
    current_sha: Cell<Option<InternedString>>,
    needs_update: bool,
    quiet: bool,
}
Expand description

A remote registry is a registry that lives at a remote URL (such as crates.io). The git index is cloned locally, and .crate files are downloaded as needed and cached locally.

This type is primarily accessed through the RegistryData trait.

See the module-level documentation for the index format and layout.

§History of Git-based index registry

Using Git to host this index used to be quite efficient. The full index can be stored efficiently locally on disk, and once it is downloaded, all queries of a registry can happen locally and needn’t touch the network. Git-based index was a reasonable design choice at the time when HTTP/2 was just introduced.

However, the full index keeps growing as crates.io grows. It becomes relatively big and slows down the first use of Cargo. Git (specifically libgit2) is not efficient at handling huge amounts of small files either. On the other hand, newer protocols like HTTP/2 are prevalent and capable to serve a bunch of tiny files. Today, it is encouraged to use HttpRegistry, which is the default from 1.70.0. That being said, Cargo will continue supporting Git-based index for a pretty long while.

Fields§

§name: InternedString

The name of this source, a unique string (across all sources) used as the directory name where its cached content is stored.

§index_path: Filesystem

Path to the registry index ($CARGO_HOME/registry/index/$REG-HASH).

§cache_path: Filesystem

Path to the cache of .crate files ($CARGO_HOME/registry/cache/$REG-HASH).

§source_id: SourceId

The unique identifier of this registry source.

§index_git_ref: GitReference

This reference is stored so that when a registry needs update, it knows where to fetch from.

§gctx: &'gctx GlobalContext§tree: RefCell<Option<Tree<'static>>>

A Git tree object to help this registry find crate metadata from the underlying Git repository.

This is stored here to prevent Git from repeatedly creating a tree object during each call into load().

§repo: LazyCell<Repository>

A Git repository that contains the actual index we want.

§head: Cell<Option<Oid>>

The current HEAD commit of the underlying Git repository.

§current_sha: Cell<Option<InternedString>>

This stores sha value of the current HEAD commit for convenience.

§needs_update: bool

Whether this registry needs to update package information.

See RemoteRegistry::mark_updated on how to make sure a registry index is updated only once per session.

§quiet: bool

Disables status messages.

Implementations§

source§

impl<'gctx> RemoteRegistry<'gctx>

source

pub fn new( source_id: SourceId, gctx: &'gctx GlobalContext, name: &str, ) -> RemoteRegistry<'gctx>

Creates a Git-rebased remote registry for source_id.

  • name — Name of a path segment where .crate tarballs and the registry index are stored. Expect to be unique.
source

fn repo(&self) -> CargoResult<&Repository>

Creates intermediate dirs and initialize the repository.

source

fn head(&self) -> CargoResult<Oid>

Get the object ID of the HEAD commit from the underlying Git repository.

source

fn tree(&self) -> CargoResult<Ref<'_, Tree<'_>>>

Returns a git2::Tree object of the current HEAD commit of the underlying Git repository.

source

fn current_version(&self) -> Option<InternedString>

Gets the current version of the registry index.

It is usually sha of the HEAD commit from the underlying Git repository.

source

fn is_updated(&self) -> bool

Whether the registry is up-to-date. See Self::mark_updated for more.

source

fn mark_updated(&self)

Marks this registry as up-to-date.

This makes sure the index is only updated once per session since it is an expensive operation. This generally only happens when the resolver is run multiple times, such as during cargo publish.

Trait Implementations§

source§

impl<'gctx> Drop for RemoteRegistry<'gctx>

Implemented to just be sure to drop tree field before our other fields. See SAFETY inside RemoteRegistry::tree() for more.

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'gctx> RegistryData for RemoteRegistry<'gctx>

source§

fn load( &mut self, _root: &Path, path: &Path, index_version: Option<&str>, ) -> Poll<CargoResult<LoadResponse>>

Read the general concept for load() on RegistryData::load.

index_version is a string representing the version of the file used to construct the cached copy.

Older versions of Cargo used the single value of the hash of the HEAD commit as a index_version. This is technically correct but a little too conservative. If a new commit is fetched all cached files need to be regenerated even if a particular file was not changed.

However if an old cargo has written such a file we still know how to read it, as long as we check for that hash value.

Cargo now uses a hash of the file’s contents as provided by git.

source§

fn invalidate_cache(&mut self)

Read the general concept for invalidate_cache() on RegistryData::invalidate_cache.

To fully invalidate, undo RemoteRegistry::mark_updated’s work.

source§

fn prepare(&self) -> CargoResult<()>

Performs initialization for the registry. Read more
source§

fn index_path(&self) -> &Filesystem

Returns the path to the index. Read more
source§

fn assert_index_locked<'a>(&self, path: &'a Filesystem) -> &'a Path

Validates that the global package cache lock is held. Read more
source§

fn config(&mut self) -> Poll<CargoResult<Option<RegistryConfig>>>

Loads the config.json file and returns it. Read more
source§

fn block_until_ready(&mut self) -> CargoResult<()>

Block until all outstanding Poll::Pending requests are Poll::Ready.
source§

fn set_quiet(&mut self, quiet: bool)

If quiet, the source should not display any progress or status messages.
source§

fn is_updated(&self) -> bool

Is the local cached data up-to-date?
source§

fn download(&mut self, pkg: PackageId, checksum: &str) -> CargoResult<MaybeLock>

Prepare to start downloading a .crate file. Read more
source§

fn finish_download( &mut self, pkg: PackageId, checksum: &str, data: &[u8], ) -> CargoResult<File>

Finish a download by saving a .crate file to disk. Read more
source§

fn is_crate_downloaded(&self, pkg: PackageId) -> bool

Returns whether or not the .crate file is already downloaded.

Auto Trait Implementations§

§

impl<'gctx> !Freeze for RemoteRegistry<'gctx>

§

impl<'gctx> !RefUnwindSafe for RemoteRegistry<'gctx>

§

impl<'gctx> !Send for RemoteRegistry<'gctx>

§

impl<'gctx> !Sync for RemoteRegistry<'gctx>

§

impl<'gctx> Unpin for RemoteRegistry<'gctx>

§

impl<'gctx> !UnwindSafe for RemoteRegistry<'gctx>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

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

source§

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>,

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 192 bytes