From d1d0c8f172d4f7cbe79f42f455c6480505784835 Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Sat, 8 Jan 2022 17:21:09 -0500 Subject: [PATCH] Nicer, somewhat more consistent messaging. --- src/config.rs | 4 ++-- src/copy.rs | 17 +++++++++++------ src/daemon.rs | 26 ++++++++++++++++---------- src/git.rs | 42 ++++++++++++++++++++++++++---------------- 4 files changed, 55 insertions(+), 34 deletions(-) diff --git a/src/config.rs b/src/config.rs index 0bfbe2c..c59b36e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -163,7 +163,7 @@ pub fn load(candidates: &Vec) -> Result { pub fn reload(pc: &PathConfig) -> Result { info!( - "{} configuration reloaded.", + "Reloaded: Configuration {}.", pc.config.repos.local.display() ); load(&vec![pc.homesync_yml.clone()]) @@ -177,7 +177,7 @@ pub fn list_packages(pc: PathConfig) { println!( "Listing packages in {}...\n", colorize_string(format!( - "{}", + "{}", pc.homesync_yml.unresolved().display() )), ); diff --git a/src/copy.rs b/src/copy.rs index f0bf73a..52b4f6f 100644 --- a/src/copy.rs +++ b/src/copy.rs @@ -8,6 +8,8 @@ use std::{ result, }; +// TODO(jrpotter): Validate local path is a git repository. + // ======================================== // Error // ======================================== @@ -69,7 +71,7 @@ fn apply_all(pc: &PathConfig) -> Result<()> { if let Some(value) = path { fs::copy(repo_file.resolved(), value.resolved())?; info!( - "Copied `{}` from local repository.", + "Copied: {} from local repository.", repo_file.unresolved().display(), ); } else { @@ -82,7 +84,7 @@ fn apply_all(pc: &PathConfig) -> Result<()> { } fs::copy(repo_file.resolved(), expanded)?; info!( - "Copied `{}` from local repository.", + "Copied: {} from local repository.", repo_file.unresolved().display(), ); } @@ -109,10 +111,13 @@ fn apply_one(pc: &PathConfig, package: &str) -> Result<()> { fs::create_dir_all(p)?; } fs::copy(repo_file, expanded)?; - info!("Copied `{}` from local repository.", path.display()); + info!( + "Copied: {} from local repository.", + path.display() + ); } } else { - warn!("Could not find package `{}` in config.", package); + warn!("Could not find package {} in config.", package); } Ok(()) @@ -152,7 +157,7 @@ pub fn stage(pc: &PathConfig) -> Result<()> { // repository. for (key, value) in &package_lookup { if let Some(value) = value { - let mut copy = value.resolved().to_path_buf(); + let mut copy = workdir.resolved().to_path_buf(); copy.push(key); if let Some(p) = copy.parent() { fs::create_dir_all(p)?; @@ -162,7 +167,7 @@ pub fn stage(pc: &PathConfig) -> Result<()> { } info!( - "Staged files. Run git -C {} status to see what changed.", + "Staged: View using `git -C {} status`.", &pc.config.repos.local.display() ); diff --git a/src/daemon.rs b/src/daemon.rs index d3977dc..a1902cf 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -160,20 +160,20 @@ pub fn launch(mut pc: PathConfig, freq_secs: u64) -> Result<(), Box> // Received paths should always be fully resolved. match watch_rx.recv() { Ok(DebouncedEvent::NoticeWrite(p)) => { - trace!("NoticeWrite '{}'", p.display()); + trace!("Noticed: Write at {}", p.display()); } Ok(DebouncedEvent::NoticeRemove(p)) => { - trace!("NoticeRemove '{}'", p.display()); + trace!("Noticed: Removal of {}", p.display()); } Ok(DebouncedEvent::Create(p)) => { - trace!("Create '{}'", p.display()); + trace!("Created: {}", p.display()); if pc.homesync_yml == p { pc = config::reload(&pc)?; state.update(&pc); } } Ok(DebouncedEvent::Write(p)) => { - trace!("Write '{}'", p.display()); + trace!("Wrote: {}", p.display()); if pc.homesync_yml == p { pc = config::reload(&pc)?; state.update(&pc); @@ -184,26 +184,32 @@ pub fn launch(mut pc: PathConfig, freq_secs: u64) -> Result<(), Box> // e.g. been removed, let's just keep using what we have in memory // in the chance it may be added back. Ok(DebouncedEvent::Chmod(p)) => { - trace!("Chmod '{}'", p.display()); + trace!("Chmod: {}", p.display()); } Ok(DebouncedEvent::Remove(p)) => { if pc.homesync_yml == p { warn!( - "Removed primary config '{}'. Continuing to use last loaded state", + "Removed: Primary config {}. Continuing to use last \ + loaded state", p.display() ); } else { - trace!("Remove '{}'", p.display()); + trace!("Removed: {}", p.display()); } } Ok(DebouncedEvent::Rename(src, dst)) => { if pc.homesync_yml == src && pc.homesync_yml != dst { warn!( - "Renamed primary config '{}'. Continuing to use last loaded state", + "Renamed: Primary config {}. Continuing from last \ + loaded state", src.display() ); } else { - trace!("Renamed '{}' to '{}'", src.display(), dst.display()) + trace!( + "Renamed: {} to {}.", + src.display(), + dst.display() + ) } } Ok(DebouncedEvent::Rescan) => { @@ -211,7 +217,7 @@ pub fn launch(mut pc: PathConfig, freq_secs: u64) -> Result<(), Box> } Ok(DebouncedEvent::Error(e, path)) => { warn!( - "Error {} at '{}'", + "Unexpected: Error {} at {}", e, path.unwrap_or_else(|| PathBuf::from("N/A")).display() ); diff --git a/src/git.rs b/src/git.rs index f4d3494..ee8b96e 100644 --- a/src/git.rs +++ b/src/git.rs @@ -106,7 +106,7 @@ pub fn init(pc: &PathConfig) -> Result { match Repository::open(&expanded) { Ok(repo) => { info!( - "Opened local repository {}.", + "Opened: Local repository {}.", &pc.config.repos.local.display() ); Ok(repo) @@ -114,7 +114,7 @@ pub fn init(pc: &PathConfig) -> Result { Err(e) if e.code() == git2::ErrorCode::NotFound => match clone(pc, &expanded) { Ok(repo) => { info!( - "Cloned remote repository {}.", + "Cloned: Remote repository {}.", &pc.config.repos.remote.url ); Ok(repo) @@ -122,11 +122,12 @@ pub fn init(pc: &PathConfig) -> Result { Err(Error::GitError(e)) if e.class() == git2::ErrorClass::Ssh && e.code() == git2::ErrorCode::Eof => { + let repo = Repository::init(&expanded)?; info!( - "Creating local repository at {}.", + "Created: Local repository {}.", pc.config.repos.local.display() ); - Ok(Repository::init(&expanded)?) + Ok(repo) } Err(e) => Err(e)?, }, @@ -161,7 +162,7 @@ pub fn push(pc: &PathConfig, repo: &mut Repository) -> Result<()> { // Want to also reflect this change on the working directory. index.write()?; let index_tree = repo.find_tree(index_oid)?; - info!("Writing index to tree `{}`.", index_oid); + info!("Wrote: Index to tree {}.", index_oid); // Commit our changes and push them to our remote. // TODO(jrpotter): Come up with a more useful message. @@ -186,7 +187,7 @@ pub fn push(pc: &PathConfig, repo: &mut Repository) -> Result<()> { &[], )? }; - info!("Commited `{}` with message \"{}\".", commit_oid, message); + info!("Commited: {}.", commit_oid); let mut remote = find_remote(pc, repo)?; let call_options = get_remote_callbacks(pc)?; @@ -195,7 +196,7 @@ pub fn push(pc: &PathConfig, repo: &mut Repository) -> Result<()> { let mut push_options = get_push_options(pc)?; remote.push(&[&format!("{r}:{r}", r = refspec)], Some(&mut push_options))?; info!( - "Pushed changes to remote `{}`.", + "Pushed: Changes to remote {}.", pc.config.repos.remote.tracking_branch(), ); @@ -212,7 +213,10 @@ fn local_from_remote(pc: &PathConfig, repo: &Repository) -> Result<()> { // It should never be the case this function is called when the local branch // exists. Keep `force` to `false` to catch any misuse here. repo.branch_from_annotated_commit(&pc.config.repos.remote.branch, &remote_ref, false)?; - info!("Created new local branch from `{}`.", &tracking_branch); + info!( + "Created: Local branch {}.", + &pc.config.repos.remote.branch + ); Ok(()) } @@ -233,7 +237,10 @@ fn local_rebase_remote(pc: &PathConfig, repo: &Repository) -> Result<()> { let signature = now_signature(pc)?; repo.rebase(Some(&local_ref), Some(&remote_ref), None, None)? .finish(Some(&signature))?; - info!("Rebased local branch onto `{}`.", &tracking_branch); + info!( + "Rebased: Local branch onto {}.", + &tracking_branch + ); Ok(()) } @@ -267,7 +274,7 @@ pub fn pull(pc: &PathConfig, repo: &mut Repository) -> Result<()> { if let Some(mut index) = index_with_all(repo)? { let index_oid = index.write_tree()?; let index_tree = repo.find_tree(index_oid)?; - info!("Writing tree `{}`.", index_oid); + info!("Wrote: Index to tree {}.", index_oid); let signature = now_signature(pc)?; let message = "Save potentially conflicting files here."; @@ -283,7 +290,7 @@ pub fn pull(pc: &PathConfig, repo: &mut Repository) -> Result<()> { &index_tree, &[&parent_commit], )?; - info!("Saved potentially conflicting files in new commit of HEAD."); + info!("Saved: Potentially conflicting files in new commit of HEAD."); } else { let temp_branch = temporary_branch_name(pc, repo)?; let refspec = format!("refs/heads/{}", &temp_branch); @@ -296,7 +303,7 @@ pub fn pull(pc: &PathConfig, repo: &mut Repository) -> Result<()> { &[], )?; info!( - "Saved potentially conflicting files on branch {}", + "Saved: Potentially conflicting files on branch {}.", temp_branch ); } @@ -347,7 +354,7 @@ where Some(StashFlags::INCLUDE_UNTRACKED), ) { Ok(oid) => { - info!("Stashing changes in `{}`.", oid); + info!("Stashed: Changes in {}.", oid); Some(oid) } Err(e) if e.class() == git2::ErrorClass::Stash && e.code() == git2::ErrorCode::NotFound => { @@ -379,9 +386,9 @@ where apply_options.checkout_options(checkout); repo.stash_apply(index, Some(&mut apply_options))?; - info!("Reapplied stash `{}`.", oid); + info!("Applied Stash {}.", oid); } else { - warn!("Could not find stash `{}`. Ignoring.", oid); + warn!("Could not find stash {}. Ignoring.", oid); } } @@ -418,7 +425,10 @@ fn fetch_remote<'repo>(pc: &PathConfig, repo: &'repo Repository) -> ResultFetched: Remote branch {}.", + &tracking_branch + ); Ok(remote) }