crates_index_diff/index/mod.rs
1use crate::Index;
2use std::str;
3
4static INDEX_GIT_URL: &str = "https://github.com/rust-lang/crates.io-index";
5static LAST_SEEN_REFNAME: &str = "refs/heads/crates-index-diff_last-seen";
6
7/// Declarative macro to generate `impl From<Src> for Error` where the source
8/// error value is boxed into the given `Error` enum variant.
9///
10/// Usage:
11/// impl_from_boxed!(gix::object::find::existing::Error => ErrorEnum::FindObject);
12/// impl_from_boxed!(gix::remote::find::existing::Error => ErrorEnum::FindRemote);
13///
14/// See also:
15/// * https://rust-lang.github.io/rust-clippy/stable/index.html#/result_large_err
16/// * https://github.com/dtolnay/thiserror/pull/419
17/// * https://github.com/dtolnay/thiserror/pull/418
18/// * https://github.com/dtolnay/thiserror/issues/302
19macro_rules! impl_from_boxed {
20 ($src:path => $err:ident::$variant:ident) => {
21 impl From<$src> for $err {
22 fn from(value: $src) -> Self {
23 Self::$variant(Box::new(value))
24 }
25 }
26 };
27}
28
29/// Options for cloning the crates-io index.
30pub struct CloneOptions {
31 /// The url to clone the crates-index repository from.
32 pub url: String,
33}
34
35impl Default for CloneOptions {
36 fn default() -> Self {
37 CloneOptions {
38 url: INDEX_GIT_URL.into(),
39 }
40 }
41}
42
43/// Access
44impl Index {
45 /// Return the crates.io repository.
46 pub fn repository(&self) -> &gix::Repository {
47 &self.repo
48 }
49
50 /// Return the crates.io repository, mutably.
51 pub fn repository_mut(&mut self) -> &mut gix::Repository {
52 &mut self.repo
53 }
54
55 /// Return the reference pointing to the state we have seen after calling `fetch_changes()`.
56 pub fn last_seen_reference(
57 &self,
58 ) -> Result<gix::Reference<'_>, gix::reference::find::existing::Error> {
59 self.repo.find_reference(self.seen_ref_name)
60 }
61}
62
63/// Main index diff functionality
64pub mod diff;
65/// initial index repo loading & cloning
66pub mod init;