diff options
-rw-r--r-- | CHANGELOG.md | 7 | ||||
-rw-r--r-- | Cargo.lock | 23 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/driver.rs | 35 | ||||
-rw-r--r-- | src/main.rs | 9 | ||||
-rw-r--r-- | src/util.rs | 90 |
6 files changed, 41 insertions, 126 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fa1bff..b309e09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Config type to be embedded within the Driver - Not in public library modules, but this should improve generation efficiency +### Removed + +- `-d/--debug` flag since all logging has been removed from the librariy, and `main.rs` does not log +- `env_logger` crate +- `log` crate +- Logging from the entire library in favor of returning errors when needed and handling when possible/preferred + ## [1.2.1] - 2021-05-23 ### Changed @@ -75,9 +75,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cc" -version = "1.0.67" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" +checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" dependencies = [ "jobserver", ] @@ -134,15 +134,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] -name = "env_logger" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f" -dependencies = [ - "log", -] - -[[package]] name = "form_urlencoded" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -169,18 +160,16 @@ version = "1.2.1" dependencies = [ "ansi_term", "anyhow", - "env_logger", "git2", - "log", "prettytable-rs", "structopt", ] [[package]] name = "git2" -version = "0.13.19" +version = "0.13.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17929de7239dea9f68aa14f94b2ab4974e7b24c1314275ffcc12a7758172fa18" +checksum = "d9831e983241f8c5591ed53f17d874833e2fa82cac2625f3888c50cbfe136cba" dependencies = [ "bitflags", "libc", @@ -241,9 +230,9 @@ checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" [[package]] name = "libgit2-sys" -version = "0.12.20+1.1.0" +version = "0.12.21+1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e2f09917e00b9ad194ae72072bb5ada2cca16d8171a43e91ddba2afbb02664b" +checksum = "86271bacd72b2b9e854c3dcfb82efd538f15f870e4c11af66900effb462f6825" dependencies = [ "cc", "libc", @@ -13,9 +13,7 @@ version = "1.2.1" [dependencies] ansi_term = { version = "^0", default-features = false } -env_logger = { version = "^0", default-features = false } git2 = { version = "^0", default-features = false } -log = { version = "^0", default-features = false } prettytable-rs = { version = "^0", default-features = false } structopt = { version = "^0", default-features = false } @@ -29,7 +27,6 @@ codegen-units = 1 lto = true # These applications should not panic often and only read from the filesystem. -# Thus, setting "RUST_LOG=debug" and running again is relatively safe. panic = "abort" # There noticeable speed difference from level 3 to 'z' or 's'. diff --git a/src/driver.rs b/src/driver.rs index 5291daf..b01d814 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -1,8 +1,7 @@ //! This module contains the types required for generating results for `gfold`. use crate::{driver_internal::TableWrapper, util}; use ansi_term::Style; -use anyhow::Result; -use log::{debug, error, warn}; +use anyhow::{anyhow, Result}; use std::{ cmp::Ordering, fs, @@ -35,8 +34,6 @@ pub struct Driver { impl Driver { /// Constructing a `Driver` will generate results with a given `&Path` and `&Config`. pub fn new(path: &Path, config: Config) -> Result<Driver> { - debug!("Running with config: {:#?}", &config); - debug!("Running in path: {:#?}", &path); let mut driver = Driver { tables: Vec::new(), config, @@ -49,23 +46,17 @@ impl Driver { } /// Print results to `STDOUT` after generation. - pub fn print_results(self) { + pub fn print_results(self) -> Result<()> { #[cfg(windows)] if !self.config.no_color { ansi_term::enable_ansi_support(); } - debug!("Printing results with {} tables...", self.tables.len()); match self.tables.len().cmp(&1) { Ordering::Greater => { let last = match self.tables.last() { Some(s) => s.path_string.clone(), - None => { - error!( - "Last object not found for table vector. Continuing with empty string." - ); - String::from("") - } + None => return Err(anyhow!("Last object not found for table vector")), }; for table_wrapper in self.tables { match self.config.no_color { @@ -85,6 +76,7 @@ impl Driver { } _ => {} }; + Ok(()) } // Sequential exeuction has benchmarked faster than concurrent implementations. @@ -102,32 +94,18 @@ impl Driver { let entry_path = entry.path(); match git2::Repository::open(&entry_path) { Ok(_) => repos.push(entry_path), - Err(e) => { - debug!( - "Tried to open {:#?} as git repository: {:#?}", - entry_path, - e.message() - ); + Err(_) => { if self.config.include_non_repos { non_repos.push(entry_path.clone()); } if !self.config.shallow { - if let Err(e) = self.execute_in_directory(&entry_path) { - warn!( - "Encountered error during recursive walk into {:#?}: {:#?}", - &entry_path, e - ); - } + self.execute_in_directory(&entry_path)?; } } } } } - debug!("Git repositories found: {:#?}", repos); - if self.config.include_non_repos { - debug!("Standard directories found: {:#?}", non_repos); - } if !repos.is_empty() { if !self.config.skip_sort { repos.sort(); @@ -147,7 +125,6 @@ impl Driver { } fn sort_results(&mut self) { - debug!("Sorting {:#?} tables...", self.tables.len()); if self.tables.len() >= 2 { // FIXME: find a way to do this without cloning. self.tables.sort_by_key(|table| table.path_string.clone()); diff --git a/src/main.rs b/src/main.rs index 7f16995..eb56b84 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,8 +11,6 @@ By default, it displays relevant information for all repos in the current\n\ working directory." )] struct Opt { - #[structopt(short, long, help = "Set to debug mode")] - debug: bool, #[structopt( short, long, @@ -40,11 +38,6 @@ struct Opt { fn main() -> Result<()> { let opt = Opt::from_args(); - if opt.debug { - env::set_var("RUST_LOG", "debug"); - } - env_logger::init(); - let mut path = env::current_dir()?; if let Some(provided_path) = opt.path { path.push(provided_path) @@ -61,6 +54,6 @@ fn main() -> Result<()> { skip_sort: opt.skip_sort, }, )? - .print_results(); + .print_results()?; Ok(()) } diff --git a/src/util.rs b/src/util.rs index ea53e0e..de4dcc9 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,5 +1,4 @@ use crate::driver_internal::TableWrapper; -use log::{debug, warn}; use prettytable::{Cell, Row}; use std::path::{Path, PathBuf}; @@ -30,30 +29,20 @@ pub fn create_table_from_paths( // FIXME: maximize error recovery in this loop. for repo in repos { - debug!("Creating row from path: {:#?}", repo); let repo_obj = match git2::Repository::open(&repo) { Ok(repo) => repo, - Err(_) => { - debug!("Could not open Git repository. Continuing to next repository..."); - continue; - } + Err(_) => continue, }; // FIXME: in case deeper recoverable errors are desired, use the match arm... // Err(error) if error.class() == git2::ErrorClass::Config => continue, let origin = match repo_obj.find_remote("origin") { Ok(origin) => origin, - Err(_) => { - debug!("Could not find remote origin. Continuing to next repository..."); - continue; - } + Err(_) => continue, }; let url = origin.url().unwrap_or("none"); - debug!("> url: {:#?}", url); - let head = repo_obj.head().ok()?; let branch = head.shorthand().unwrap_or("none"); - debug!("> branch: {:#?}", branch); // FIXME: test using the "is_bare()" method for a repository object. let mut opts = git2::StatusOptions::new(); @@ -99,7 +88,6 @@ pub fn create_table_from_paths( Condition::Unpushed => table.add_row(create_row("Fcl", "unpushed")), _ => table.add_row(create_row("Frl", "error")), }; - debug!("> condition: {:#?}", condition); } // D.R.Y. is important, but the "non_repos" loop would not benefit from the closure used by @@ -118,7 +106,6 @@ pub fn create_table_from_paths( table.add_row(Row::new(cells)); } - debug!("Generated {:#?} rows for table object", table.len()); match table.is_empty() { true => None, false => Some(TableWrapper { @@ -132,55 +119,30 @@ pub fn create_table_from_paths( fn is_unpushed(repo: &git2::Repository, head: &git2::Reference) -> bool { let local = match head.peel_to_commit() { Ok(local) => local, - Err(e) => { - debug!("> error: {}", e); - return false; - } + Err(_) => return false, }; - debug!("> local commit: {:#?}", local.id()); - if let Some(name) = head.name() { - debug!("> local ref: {}", name); - } let upstream = match repo.resolve_reference_from_short_name("origin") { - Ok(reference) => { - if let Some(name) = reference.name() { - debug!("> origin ref: {}", name); - } - match reference.peel_to_commit() { - Ok(upstream) => upstream, - Err(e) => { - debug!("> error: {}", e); - return false; - } - } - } - Err(e) => { - debug!("> error: {}", e); - return false; - } + Ok(reference) => match reference.peel_to_commit() { + Ok(upstream) => upstream, + Err(_) => return false, + }, + Err(_) => return false, }; - debug!("> origin commit: {:#?}", upstream.id()); matches!(repo.graph_ahead_behind(local.id(), upstream.id()), Ok(ahead) if ahead.0 > 0) } fn get_email(repo_path: &Path) -> String { - let func = |cfg: git2::Config| -> Option<String> { + let find_email_in_config = |cfg: git2::Config| -> Option<String> { let entries = match cfg.entries(None) { Ok(o) => o, - Err(e) => { - debug!("Encountered error. Returning none: {:#?}", e); - return None; - } + Err(_) => return None, }; for entry in &entries { let entry = match entry { Ok(o) => o, - Err(e) => { - warn!("Encountered error: {:#?}", e); - continue; - } + Err(_) => continue, }; let key = match entry.name() { Some(s) => s, @@ -197,25 +159,15 @@ fn get_email(repo_path: &Path) -> String { None }; - match git2::Config::open(&repo_path.join(".git").join("config")) { - Ok(o) => match func(o) { - Some(value) => return value, - None => debug!("Email not found. Trying default config..."), - }, - Err(e) => debug!( - "Encountered error accessing config in .git/config for {:#?}: {:#?}", - &repo_path, e - ), - }; - match git2::Config::open_default() { - Ok(o) => match func(o) { - Some(value) => return value, - None => debug!("Email not found in neither the default config nor the local config."), - }, - Err(e) => debug!( - "Encountered error accessing default git config for {:#?}: {:#?}", - &repo_path, e - ), - }; + if let Ok(o) = git2::Config::open(&repo_path.join(".git").join("config")) { + if let Some(o) = find_email_in_config(o) { + return o; + } + } + if let Ok(o) = git2::Config::open_default() { + if let Some(o) = find_email_in_config(o) { + return o; + } + } "-".to_string() } |