pub struct RemoteRegistry<'cfg> {
index_path: Filesystem,
cache_path: Filesystem,
source_id: SourceId,
index_git_ref: GitReference,
config: &'cfg Config,
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§
§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.
config: &'cfg Config
§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<'cfg> RemoteRegistry<'cfg>
impl<'cfg> RemoteRegistry<'cfg>
sourcepub fn new(
source_id: SourceId,
config: &'cfg Config,
name: &str
) -> RemoteRegistry<'cfg>
pub fn new( source_id: SourceId, config: &'cfg Config, name: &str ) -> RemoteRegistry<'cfg>
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.
sourcefn repo(&self) -> CargoResult<&Repository>
fn repo(&self) -> CargoResult<&Repository>
Creates intermediate dirs and initialize the repository.
sourcefn head(&self) -> CargoResult<Oid>
fn head(&self) -> CargoResult<Oid>
Get the object ID of the HEAD commit from the underlying Git repository.
sourcefn tree(&self) -> CargoResult<Ref<'_, Tree<'_>>>
fn tree(&self) -> CargoResult<Ref<'_, Tree<'_>>>
Returns a git2::Tree
object of the current HEAD commit of the
underlying Git repository.
sourcefn current_version(&self) -> Option<InternedString>
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.
sourcefn is_updated(&self) -> bool
fn is_updated(&self) -> bool
Whether the registry is up-to-date. See Self::mark_updated
for more.
sourcefn mark_updated(&self)
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<'cfg> Drop for RemoteRegistry<'cfg>
impl<'cfg> Drop for RemoteRegistry<'cfg>
Implemented to just be sure to drop tree
field before our other fields.
See SAFETY inside RemoteRegistry::tree()
for more.
source§impl<'cfg> RegistryData for RemoteRegistry<'cfg>
impl<'cfg> RegistryData for RemoteRegistry<'cfg>
source§fn load(
&mut self,
_root: &Path,
path: &Path,
index_version: Option<&str>
) -> Poll<CargoResult<LoadResponse>>
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)
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 index_path(&self) -> &Filesystem
fn index_path(&self) -> &Filesystem
source§fn assert_index_locked<'a>(&self, path: &'a Filesystem) -> &'a Path
fn assert_index_locked<'a>(&self, path: &'a Filesystem) -> &'a Path
source§fn config(&mut self) -> Poll<CargoResult<Option<RegistryConfig>>>
fn config(&mut self) -> Poll<CargoResult<Option<RegistryConfig>>>
config.json
file and returns it. Read moresource§fn block_until_ready(&mut self) -> CargoResult<()>
fn block_until_ready(&mut self) -> CargoResult<()>
source§fn set_quiet(&mut self, quiet: bool)
fn set_quiet(&mut self, quiet: bool)
source§fn is_updated(&self) -> bool
fn is_updated(&self) -> bool
source§fn download(&mut self, pkg: PackageId, checksum: &str) -> CargoResult<MaybeLock>
fn download(&mut self, pkg: PackageId, checksum: &str) -> CargoResult<MaybeLock>
.crate
file. Read moresource§fn finish_download(
&mut self,
pkg: PackageId,
checksum: &str,
data: &[u8]
) -> CargoResult<File>
fn finish_download( &mut self, pkg: PackageId, checksum: &str, data: &[u8] ) -> CargoResult<File>
.crate
file to disk. Read moresource§fn is_crate_downloaded(&self, pkg: PackageId) -> bool
fn is_crate_downloaded(&self, pkg: PackageId) -> bool
.crate
file is already downloaded.Auto Trait Implementations§
impl<'cfg> !RefUnwindSafe for RemoteRegistry<'cfg>
impl<'cfg> !Send for RemoteRegistry<'cfg>
impl<'cfg> !Sync for RemoteRegistry<'cfg>
impl<'cfg> Unpin for RemoteRegistry<'cfg>
impl<'cfg> !UnwindSafe for RemoteRegistry<'cfg>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
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: 176 bytes