mirror of
https://github.com/RGBCube/dix
synced 2025-07-28 12:17:45 +00:00
feat: write rest of main
This commit is contained in:
parent
a1ccf88d0c
commit
baaf63fdf2
5 changed files with 57 additions and 60 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -327,6 +327,7 @@ dependencies = [
|
||||||
"regex",
|
"regex",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
|
"size",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"unicode-width 0.2.0",
|
"unicode-width 0.2.0",
|
||||||
"yansi",
|
"yansi",
|
||||||
|
@ -780,6 +781,12 @@ version = "1.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "size"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1b6709c7b6754dca1311b3c73e79fcce40dd414c782c66d88e8823030093b02b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smallvec"
|
name = "smallvec"
|
||||||
version = "1.15.0"
|
version = "1.15.0"
|
||||||
|
|
|
@ -17,6 +17,7 @@ ref-cast = "1.0.24"
|
||||||
regex = "1.11.1"
|
regex = "1.11.1"
|
||||||
rusqlite = { version = "0.35.0", features = [ "bundled" ] }
|
rusqlite = { version = "0.35.0", features = [ "bundled" ] }
|
||||||
rustc-hash = "2.1.1"
|
rustc-hash = "2.1.1"
|
||||||
|
size = "0.5.0"
|
||||||
thiserror = "2.0.12"
|
thiserror = "2.0.12"
|
||||||
unicode-width = "0.2.0"
|
unicode-width = "0.2.0"
|
||||||
yansi = { version = "1.0.1", features = [ "detect-env", "detect-tty" ] }
|
yansi = { version = "1.0.1", features = [ "detect-env", "detect-tty" ] }
|
||||||
|
|
|
@ -43,7 +43,7 @@ impl DiffStatus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn diff<'a>(
|
pub fn write_diffln<'a>(
|
||||||
writer: &mut dyn fmt::Write,
|
writer: &mut dyn fmt::Write,
|
||||||
paths_old: impl Iterator<Item = &'a StorePath>,
|
paths_old: impl Iterator<Item = &'a StorePath>,
|
||||||
paths_new: impl Iterator<Item = &'a StorePath>,
|
paths_new: impl Iterator<Item = &'a StorePath>,
|
||||||
|
@ -107,8 +107,6 @@ pub fn diff<'a>(
|
||||||
|
|
||||||
for (name, versions, status) in diffs {
|
for (name, versions, status) in diffs {
|
||||||
if last_status != Some(status) {
|
if last_status != Some(status) {
|
||||||
last_status = Some(status);
|
|
||||||
|
|
||||||
writeln!(
|
writeln!(
|
||||||
writer,
|
writer,
|
||||||
"{nl}{status}",
|
"{nl}{status}",
|
||||||
|
@ -120,6 +118,8 @@ pub fn diff<'a>(
|
||||||
}
|
}
|
||||||
.bold(),
|
.bold(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
last_status = Some(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(
|
write!(
|
||||||
|
|
|
@ -13,7 +13,7 @@ use anyhow::{
|
||||||
use derive_more::Deref;
|
use derive_more::Deref;
|
||||||
|
|
||||||
mod diff;
|
mod diff;
|
||||||
pub use diff::diff;
|
pub use diff::write_diffln;
|
||||||
|
|
||||||
pub mod store;
|
pub mod store;
|
||||||
|
|
||||||
|
|
101
src/main.rs
101
src/main.rs
|
@ -16,12 +16,9 @@ use anyhow::{
|
||||||
Context as _,
|
Context as _,
|
||||||
Error,
|
Error,
|
||||||
Result,
|
Result,
|
||||||
|
anyhow,
|
||||||
};
|
};
|
||||||
use clap::Parser as _;
|
use clap::Parser as _;
|
||||||
use dix::{
|
|
||||||
diff,
|
|
||||||
store,
|
|
||||||
};
|
|
||||||
use yansi::Paint as _;
|
use yansi::Paint as _;
|
||||||
|
|
||||||
struct WriteFmt<W: io::Write>(W);
|
struct WriteFmt<W: io::Write>(W);
|
||||||
|
@ -57,15 +54,15 @@ fn real_main() -> Result<()> {
|
||||||
|
|
||||||
// Handle to the thread collecting closure size information.
|
// Handle to the thread collecting closure size information.
|
||||||
// We do this as early as possible because Nix is slow.
|
// We do this as early as possible because Nix is slow.
|
||||||
let _closure_size_handle = {
|
let closure_size_handle = {
|
||||||
log::debug!("calculating closure sizes in background");
|
log::debug!("calculating closure sizes in background");
|
||||||
|
|
||||||
let mut connection = store::connect()?;
|
|
||||||
|
|
||||||
let old_path = old_path.clone();
|
let old_path = old_path.clone();
|
||||||
let new_path = new_path.clone();
|
let new_path = new_path.clone();
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
|
let mut connection = dix::store::connect()?;
|
||||||
|
|
||||||
Ok::<_, Error>((
|
Ok::<_, Error>((
|
||||||
connection.query_closure_size(&old_path)?,
|
connection.query_closure_size(&old_path)?,
|
||||||
connection.query_closure_size(&new_path)?,
|
connection.query_closure_size(&new_path)?,
|
||||||
|
@ -73,7 +70,7 @@ fn real_main() -> Result<()> {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut connection = store::connect()?;
|
let mut connection = dix::store::connect()?;
|
||||||
|
|
||||||
let paths_old =
|
let paths_old =
|
||||||
connection.query_depdendents(&old_path).with_context(|| {
|
connection.query_depdendents(&old_path).with_context(|| {
|
||||||
|
@ -105,64 +102,56 @@ fn real_main() -> Result<()> {
|
||||||
|
|
||||||
let mut out = WriteFmt(io::stdout());
|
let mut out = WriteFmt(io::stdout());
|
||||||
|
|
||||||
|
writeln!(
|
||||||
|
out,
|
||||||
|
"{arrows} {old_path}",
|
||||||
|
arrows = "<<<".bold(),
|
||||||
|
old_path = old_path.display(),
|
||||||
|
)?;
|
||||||
|
writeln!(
|
||||||
|
out,
|
||||||
|
"{arrows} {new_path}",
|
||||||
|
arrows = ">>>".bold(),
|
||||||
|
new_path = new_path.display(),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
writeln!(out)?;
|
||||||
|
|
||||||
#[expect(clippy::pattern_type_mismatch)]
|
#[expect(clippy::pattern_type_mismatch)]
|
||||||
diff(
|
dix::write_diffln(
|
||||||
&mut out,
|
&mut out,
|
||||||
paths_old.iter().map(|(_, path)| path),
|
paths_old.iter().map(|(_, path)| path),
|
||||||
paths_new.iter().map(|(_, path)| path),
|
paths_new.iter().map(|(_, path)| path),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// println!("Difference between the two generations:");
|
let (closure_size_old, closure_size_new) = closure_size_handle
|
||||||
// println!();
|
.join()
|
||||||
|
.map_err(|_| anyhow!("failed to get closure size due to thread error"))??;
|
||||||
|
|
||||||
// let width_changes = changed.iter().filter(|&&p| {
|
let size_old = size::Size::from_bytes(closure_size_old);
|
||||||
// match (pre.get(p), post.get(p)) {
|
let size_new = size::Size::from_bytes(closure_size_new);
|
||||||
// (Some(version_pre), Some(version_post)) => version_pre != version_post,
|
let size_diff = size_new - size_old;
|
||||||
// _ => false,
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// let col_width = added
|
writeln!(out)?;
|
||||||
// .iter()
|
|
||||||
// .chain(removed.iter())
|
|
||||||
// .chain(width_changes)
|
|
||||||
// .map(|p| p.len())
|
|
||||||
// .max()
|
|
||||||
// .unwrap_or_default();
|
|
||||||
|
|
||||||
// println!("<<< {}", cli.path.to_string_lossy());
|
writeln!(
|
||||||
// println!(">>> {}", cli.path2.to_string_lossy());
|
out,
|
||||||
// print::print_added(&added, &post, col_width);
|
"{header}: {size_old} → {size_new}",
|
||||||
// print::print_removed(&removed, &pre, col_width);
|
header = "SIZE".bold(),
|
||||||
// print::print_changes(&changed, &pre, &post, col_width);
|
size_old = size_old.red(),
|
||||||
|
size_new = size_new.green(),
|
||||||
|
)?;
|
||||||
|
|
||||||
// if let Some((pre_handle, post_handle)) = closure_size_handles {
|
writeln!(
|
||||||
// match (pre_handle.join(), post_handle.join()) {
|
out,
|
||||||
// (Ok(Ok(pre_size)), Ok(Ok(post_size))) => {
|
"{header}: {size_diff}",
|
||||||
// let pre_size = pre_size / 1024 / 1024;
|
header = "DIFF".bold(),
|
||||||
// let post_size = post_size / 1024 / 1024;
|
size_diff = if size_diff.bytes() > 0 {
|
||||||
// log::debug!("Pre closure size: {pre_size} MiB");
|
size_diff.green()
|
||||||
// log::debug!("Post closure size: {post_size} MiB");
|
} else {
|
||||||
|
size_diff.red()
|
||||||
// println!("{}", "Closure Size:".underline().bold());
|
},
|
||||||
// println!("Before: {pre_size} MiB");
|
)?;
|
||||||
// println!("After: {post_size} MiB");
|
|
||||||
// println!("Difference: {} MiB", post_size - pre_size);
|
|
||||||
// },
|
|
||||||
// (Ok(Err(e)), _) | (_, Ok(Err(e))) => {
|
|
||||||
// log::error!("Error getting closure size: {e}");
|
|
||||||
// eprintln!("Error getting closure size: {e}");
|
|
||||||
// },
|
|
||||||
// _ => {
|
|
||||||
// log::error!(
|
|
||||||
// "Failed to get closure size information due to a thread error"
|
|
||||||
// );
|
|
||||||
// eprintln!(
|
|
||||||
// "Error: Failed to get closure size information due to a thread
|
|
||||||
// error" );
|
|
||||||
// },
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue