Skip to content

Commit

Permalink
Merge pull request #34 from jamessan/outdated-crates
Browse files Browse the repository at this point in the history
Improve display of information for outdated crates
  • Loading branch information
kpcyrd committed Jan 21, 2024
2 parents 48e5a60 + b5865cb commit ada6cbb
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl Connection {
if SystemTime::now().duration_since(cache.from)? > CACHE_EXPIRE {
Ok(None)
} else {
debug!("{package} {:?}", cache.info);
Ok(Some(cache.info))
}
}
Expand Down Expand Up @@ -196,6 +197,7 @@ impl Connection {
if is_compatible(debversion, &version)? {
info.version = debversion.to_string();
info.status = PkgStatus::Found;
debug!("{package} {:?}", info);
return Ok(info);
} else if is_compatible(debversion, &semver_version)? {
info.version = debversion.to_string();
Expand All @@ -206,6 +208,7 @@ impl Connection {
}
}

debug!("{package} {:?}", info);
Ok(info)
}
}
Expand Down Expand Up @@ -261,4 +264,26 @@ mod tests {
.unwrap();
assert_eq!(info.status, PkgStatus::NotFound);
}

#[test]
#[ignore]
fn check_zerover_version_reqs() {
let mut db = Connection::new().unwrap();
// Debian bookworm has rust-zoxide v0.4.3 and shouldn't be updated anymore
let query =
"SELECT version::text FROM sources WHERE source in ($1, $2) AND release='bookworm';";
let info = db
.search_generic(query, "zoxide", &Version::parse("0.4.1").unwrap())
.unwrap();
assert_eq!(info.status, PkgStatus::Found);
assert_eq!(info.version, "0.4.3");
let info = db
.search_generic(query, "zoxide", &Version::parse("0.4.5").unwrap())
.unwrap();
assert_eq!(info.status, PkgStatus::Compatible);
let info = db
.search_generic(query, "zoxide", &Version::parse("0.5.0").unwrap())
.unwrap();
assert_eq!(info.status, PkgStatus::Outdated);
}
}
15 changes: 15 additions & 0 deletions src/debian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ impl Pkg {
false
}
}

pub fn show_dependencies(&self) -> bool {
if !self.in_debian() {
return true;
}

if let Some(deb) = &self.debinfo {
!deb.exact_match && (deb.outdated || !deb.compatible)
} else {
true
}
}
}

#[derive(Debug, Clone)]
Expand All @@ -53,6 +65,7 @@ pub struct DebianInfo {
pub in_new: bool,
pub outdated: bool,
pub compatible: bool,
pub exact_match: bool,
pub version: String,
}

Expand All @@ -62,6 +75,7 @@ fn run_task(db: &mut Connection, pkg: Pkg) -> Result<DebianInfo> {
in_new: false,
outdated: false,
compatible: false,
exact_match: false,
version: String::new(),
};

Expand All @@ -80,6 +94,7 @@ fn run_task(db: &mut Connection, pkg: Pkg) -> Result<DebianInfo> {
match info.status {
PkgStatus::Outdated => deb.outdated = true,
PkgStatus::Compatible => deb.compatible = true,
PkgStatus::Found => deb.exact_match = true,
_ => (),
}

Expand Down
16 changes: 15 additions & 1 deletion src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ impl<'a> fmt::Display for Display<'a> {
pkg.green(),
deb.version.yellow()
)?;
} else if deb.outdated {
write!(
fmt,
"{} (outdated, {} in debian)",
pkg.yellow(),
deb.version.red()
)?;
} else {
write!(fmt, "{} (in debian)", pkg.green())?;
}
Expand All @@ -76,11 +83,18 @@ impl<'a> fmt::Display for Display<'a> {
pkg.blue(),
deb.version.yellow()
)?;
} else if deb.outdated {
write!(
fmt,
"{}, (outdated, {} in debian NEW queue)",
pkg.blue(),
deb.version.red()
)?;
} else {
write!(fmt, "{} (in debian NEW queue)", pkg.blue())?;
}
} else if deb.outdated {
write!(fmt, "{} (outdated, {})", pkg.red(), deb.version)?;
write!(fmt, "{} (outdated, {})", pkg.red(), deb.version.red())?;
} else {
write!(fmt, "{pkg}")?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ fn print_package<'a>(

println!("{}", format.display(package));

if package.in_debian() {
if !all && !package.show_dependencies() {
return;
}

Expand Down

0 comments on commit ada6cbb

Please sign in to comment.