cargo_update::ops

Struct GitRepoPackage

Source
pub struct GitRepoPackage {
    pub name: String,
    pub url: String,
    pub branch: Option<String>,
    pub id: Oid,
    pub newest_id: Result<Oid, Error>,
    pub executables: Vec<String>,
}
Expand description

A representation of a package a remote git repository.

The newest commit is pulled from that repo via pull_version().

The parse() function parses the format used in $HOME/.cargo/.crates.toml.

§Examples

let package_s = "alacritty 0.1.0 (git+https://github.com/jwilm/alacritty#eb231b3e70b87875df4bdd1974d5e94704024d70)";
let mut package = GitRepoPackage::parse(package_s, vec!["alacritty".to_string()]).unwrap();
assert_eq!(package,
           GitRepoPackage {
               name: "alacritty".to_string(),
               url: "https://github.com/jwilm/alacritty".to_string(),
               branch: None,
               id: git2::Oid::from_str("eb231b3e70b87875df4bdd1974d5e94704024d70").unwrap(),
               newest_id: Err(git2::Error::from_str("")),
               executables: vec!["alacritty".to_string()],
           });

package.pull_version(&registry_tree, &registry);
assert!(package.newest_id.is_ok());

Fields§

§name: String

The package’s name.

§url: String

The remote git repo URL.

§branch: Option<String>

The installed branch, or None for default.

§id: Oid

The package’s locally installed version’s object hash.

§newest_id: Result<Oid, Error>

The latest version of the package available at the main crates.io repository.

None by default, acquire via GitRepoPackage::pull_version().

§executables: Vec<String>

Executables currently installed for this package.

Implementations§

Source§

impl GitRepoPackage

Source

pub fn parse(what: &str, executables: Vec<String>) -> Option<GitRepoPackage>

Try to decypher a package descriptor into a GitRepoPackage.

Will return None if:

  • the given package descriptor is invalid, or
  • the package descriptor is not from a git repository.

In the returned instance, newest_version is always None, get it via GitRepoPackage::pull_version().

The executable list is used as-is.

§Examples

Remote git repo packages:

let package_s = "alacritty 0.1.0 (git+https://github.com/jwilm/alacritty#eb231b3e70b87875df4bdd1974d5e94704024d70)";
assert_eq!(GitRepoPackage::parse(package_s, vec!["alacritty".to_string()]).unwrap(),
           GitRepoPackage {
               name: "alacritty".to_string(),
               url: "https://github.com/jwilm/alacritty".to_string(),
               branch: None,
               id: git2::Oid::from_str("eb231b3e70b87875df4bdd1974d5e94704024d70").unwrap(),
               newest_id: Err(git2::Error::from_str("")),
               executables: vec!["alacritty".to_string()],
           });

let package_s = "chattium-oxide-client 0.1.0 \
                 (git+https://github.com/nabijaczleweli/chattium-oxide-client\
                      ?branch=master#108a7b94f0e0dcb2a875f70fc0459d5a682df14c)";
assert_eq!(GitRepoPackage::parse(package_s, vec!["chattium-oxide-client.exe".to_string()]).unwrap(),
           GitRepoPackage {
               name: "chattium-oxide-client".to_string(),
               url: "https://github.com/nabijaczleweli/chattium-oxide-client".to_string(),
               branch: Some("master".to_string()),
               id: git2::Oid::from_str("108a7b94f0e0dcb2a875f70fc0459d5a682df14c").unwrap(),
               newest_id: Err(git2::Error::from_str("")),
               executables: vec!["chattium-oxide-client.exe".to_string()],
           });

Main repository package:

let package_s = "racer 1.2.10 (registry+https://github.com/rust-lang/crates.io-index)";
assert!(GitRepoPackage::parse(package_s, vec!["racer".to_string()]).is_none());
Source

pub fn pull_version<Pt: AsRef<Path>, Pg: AsRef<Path>>( &mut self, temp_dir: Pt, git_db_dir: Pg, http_proxy: Option<&str>, fork_git: bool, )

Clone the repo and check what the latest commit’s hash is.

Source

pub fn needs_update(&self) -> bool

Check whether this package needs to be installed

§Examples
assert!(GitRepoPackage {
            name: "alacritty".to_string(),
            url: "https://github.com/jwilm/alacritty".to_string(),
            branch: None,
            id: git2::Oid::from_str("eb231b3e70b87875df4bdd1974d5e94704024d70").unwrap(),
            newest_id: git2::Oid::from_str("5f7885749c4d7e48869b1fc0be4d430601cdbbfa"),
            executables: vec!["alacritty".to_string()],
        }.needs_update());
assert!(!GitRepoPackage {
            name: "alacritty".to_string(),
            url: "https://github.com/jwilm/alacritty".to_string(),
            branch: None,
            id: git2::Oid::from_str("5f7885749c4d7e48869b1fc0be4d430601cdbbfa").unwrap(),
            newest_id: git2::Oid::from_str("5f7885749c4d7e48869b1fc0be4d430601cdbbfa"),
            executables: vec!["alacritty".to_string()],
        }.needs_update());

Trait Implementations§

Source§

impl Debug for GitRepoPackage

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Hash for GitRepoPackage

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for GitRepoPackage

Source§

fn eq(&self, other: &GitRepoPackage) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for GitRepoPackage

Auto Trait Implementations§

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