Skip to content

Commit

Permalink
Fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
orf committed Jan 15, 2022
1 parent ceedb1c commit 3b13234
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
use std::ffi::OsString;
use std::fmt;
use std::fs;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use structopt::StructOpt;

#[derive(Deserialize, Serialize, Debug)]
Expand All @@ -18,7 +18,7 @@ pub struct Config {
files: Vec<PathBuf>,
}

pub fn all_config_files(workspace: &PathBuf) -> anyhow::Result<Vec<PathBuf>> {
pub fn all_config_files(workspace: &Path) -> anyhow::Result<Vec<PathBuf>> {
let matcher = globset::GlobBuilder::new("workspace*.toml")
.literal_separator(true)
.build()?
Expand Down Expand Up @@ -60,7 +60,7 @@ impl Config {
pub fn write(
&self,
providers: Vec<ProviderSource>,
config_path: &PathBuf,
config_path: &Path,
) -> anyhow::Result<()> {
let toml = toml::to_string(&ConfigContents { providers })?;
fs::write(config_path, toml)
Expand Down Expand Up @@ -91,7 +91,7 @@ impl ProviderSource {
}

pub fn fetch_repositories(&self) -> anyhow::Result<Vec<Repository>> {
Ok(self.provider().fetch_repositories()?)
self.provider().fetch_repositories()
}
}

Expand Down
32 changes: 16 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern crate ureq;
extern crate walkdir;

use std::collections::HashSet;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::thread;
use std::thread::JoinHandle;
Expand Down Expand Up @@ -173,9 +173,9 @@ fn handle_main(args: Args) -> anyhow::Result<()> {

/// Add a given ProviderSource to our configuration file.
fn add_provider_to_config(
workspace: &PathBuf,
workspace: &Path,
provider_source: ProviderSource,
file: &PathBuf,
file: &Path,
) -> anyhow::Result<()> {
if !provider_source.correctly_configured() {
return Err(anyhow!("Provider is not correctly configured"));
Expand All @@ -199,7 +199,7 @@ fn add_provider_to_config(
}

/// Update our workspace. This clones any new repositories and archives old ones.
fn update(workspace: &PathBuf, threads: usize) -> anyhow::Result<()> {
fn update(workspace: &Path, threads: usize) -> anyhow::Result<()> {
// Load our lockfile
let lockfile = Lockfile::new(workspace.join("workspace-lock.toml"));
let repositories = lockfile.read().with_context(|| "Error reading lockfile")?;
Expand All @@ -209,9 +209,9 @@ fn update(workspace: &PathBuf, threads: usize) -> anyhow::Result<()> {
map_repositories(&repositories, threads, |r, progress_bar| {
// Only clone repositories that don't exist
if !r.exists(workspace) {
r.clone(&workspace, &progress_bar)?;
r.clone(workspace, progress_bar)?;
// Maybe this should always be run, but whatever. It's fine for now.
r.set_upstream(&workspace)?;
r.set_upstream(workspace)?;
}
Ok(())
})?;
Expand All @@ -222,7 +222,7 @@ fn update(workspace: &PathBuf, threads: usize) -> anyhow::Result<()> {
Ok(())
}

fn pull_all_repositories(workspace: &PathBuf, threads: usize) -> anyhow::Result<()> {
fn pull_all_repositories(workspace: &Path, threads: usize) -> anyhow::Result<()> {
let lockfile = Lockfile::new(workspace.join("workspace-lock.toml"));
let repositories = lockfile.read().with_context(|| "Error reading lockfile")?;

Expand All @@ -232,7 +232,7 @@ fn pull_all_repositories(workspace: &PathBuf, threads: usize) -> anyhow::Result<
);

map_repositories(&repositories, threads, |r, progress_bar| {
r.switch_to_primary_branch(&workspace)?;
r.switch_to_primary_branch(workspace)?;
let pull_args = match (&r.upstream, &r.branch) {
// This fucking sucks, but it's because my abstractions suck ass.
// I need to learn how to fix this.
Expand All @@ -243,7 +243,7 @@ fn pull_all_repositories(workspace: &PathBuf, threads: usize) -> anyhow::Result<
],
_ => vec!["pull".to_string()],
};
r.execute_cmd(&workspace, &progress_bar, "git", &pull_args)?;
r.execute_cmd(workspace, progress_bar, "git", &pull_args)?;
Ok(())
})?;

Expand All @@ -252,7 +252,7 @@ fn pull_all_repositories(workspace: &PathBuf, threads: usize) -> anyhow::Result<

/// Execute a command on all our repositories
fn execute_cmd(
workspace: &PathBuf,
workspace: &Path,
threads: usize,
cmd: String,
args: Vec<String>,
Expand All @@ -277,13 +277,13 @@ fn execute_cmd(

// Run fetch on them
map_repositories(&repos_to_fetch, threads, |r, progress_bar| {
r.execute_cmd(&workspace, &progress_bar, &cmd, &args)
r.execute_cmd(workspace, progress_bar, &cmd, &args)
})?;
Ok(())
}

/// Run `git fetch` on all our repositories
fn fetch(workspace: &PathBuf, threads: usize) -> anyhow::Result<()> {
fn fetch(workspace: &Path, threads: usize) -> anyhow::Result<()> {
let cmd = vec![
"fetch",
"--all",
Expand All @@ -301,7 +301,7 @@ fn fetch(workspace: &PathBuf, threads: usize) -> anyhow::Result<()> {
}

/// Update our lockfile
fn lock(workspace: &PathBuf) -> anyhow::Result<()> {
fn lock(workspace: &Path) -> anyhow::Result<()> {
// Find all config files
let config_files = all_config_files(workspace).context("Error loading config files")?;
// Read the configuration sources
Expand Down Expand Up @@ -341,11 +341,11 @@ fn lock(workspace: &PathBuf) -> anyhow::Result<()> {
}

/// List the contents of our workspace
fn list(workspace: &PathBuf, full: bool) -> anyhow::Result<()> {
fn list(workspace: &Path, full: bool) -> anyhow::Result<()> {
// Read and parse the lockfile
let lockfile = Lockfile::new(workspace.join("workspace-lock.toml"));
let repositories = lockfile.read().context("Error reading lockfile")?;
let existing_repositories = repositories.iter().filter(|r| r.exists(&workspace));
let existing_repositories = repositories.iter().filter(|r| r.exists(workspace));
for repo in existing_repositories {
if full {
println!("{}", repo.get_path(workspace).unwrap().display());
Expand Down Expand Up @@ -452,7 +452,7 @@ where
}

/// Find all projects that have been archived or deleted on our providers
fn archive_repositories(workspace: &PathBuf, repositories: Vec<Repository>) -> anyhow::Result<()> {
fn archive_repositories(workspace: &Path, repositories: Vec<Repository>) -> anyhow::Result<()> {
// The logic here is as follows:
// 1. Iterate through all directories. If it's a "safe" directory (one that contains a project
// in our lockfile), we skip it entirely.
Expand Down
2 changes: 1 addition & 1 deletion src/providers/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Provider for GithubProvider {
.iter()
.map(|r| r.as_ref().unwrap())
.filter(|r| !r.is_archived)
.map(|repo| self.parse_repo(&self.path, &repo)),
.map(|repo| self.parse_repo(&self.path, repo)),
);

if !response_repositories.page_info.has_next_page {
Expand Down
4 changes: 2 additions & 2 deletions src/providers/gitlab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Provider for GitlabProvider {
.expect("missing edges")
.into_iter()
// Some(T) -> T
.filter_map(|x| x)
.flatten()
// Extract the node, which is also Some(T)
.filter_map(|x| x.node)
.map(ProjectNode::from)
Expand All @@ -171,7 +171,7 @@ impl Provider for GitlabProvider {
.expect("missing edges")
.into_iter()
// Some(T) -> T
.filter_map(|x| x)
.flatten()
// Extract the node, which is also Some(T)
.filter_map(|x| x.node)
.map(ProjectNode::from)
Expand Down
18 changes: 9 additions & 9 deletions src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Repository {
}
}

pub fn set_upstream(&self, root: &PathBuf) -> anyhow::Result<()> {
pub fn set_upstream(&self, root: &Path) -> anyhow::Result<()> {
let upstream = match &self.upstream {
Some(upstream) => upstream,
None => return Ok(()),
Expand Down Expand Up @@ -126,7 +126,7 @@ impl Repository {

pub fn execute_cmd(
&self,
root: &PathBuf,
root: &Path,
progress_bar: &ProgressBar,
cmd: &str,
args: &[String],
Expand All @@ -140,7 +140,7 @@ impl Repository {
Ok(())
}

pub fn switch_to_primary_branch(&self, root: &PathBuf) -> anyhow::Result<()> {
pub fn switch_to_primary_branch(&self, root: &Path) -> anyhow::Result<()> {
let branch = match &self.branch {
None => return Ok(()),
Some(b) => b,
Expand All @@ -153,14 +153,14 @@ impl Repository {
branch
));
}
repo.set_head(&format!("refs/heads/{}", branch).to_string())
repo.set_head(&format!("refs/heads/{}", branch))
.with_context(|| format!("Cannot find branch {}", branch))?;
repo.checkout_head(Some(CheckoutBuilder::default().safe().force()))
.with_context(|| format!("Error checking out branch {}", branch))?;
Ok(())
}

pub fn clone(&self, root: &PathBuf, progress_bar: &ProgressBar) -> anyhow::Result<()> {
pub fn clone(&self, root: &Path, progress_bar: &ProgressBar) -> anyhow::Result<()> {
let mut command = Command::new("git");

let child = command
Expand All @@ -182,12 +182,12 @@ impl Repository {
}
pub fn get_path(&self, root: &Path) -> anyhow::Result<PathBuf> {
let joined = root.join(&self.name());
Ok(joined
joined
.canonicalize()
.with_context(|| format!("Cannot resolve {}", joined.display()))?)
.with_context(|| format!("Cannot resolve {}", joined.display()))
}
pub fn exists(&self, root: &PathBuf) -> bool {
match self.get_path(&root) {
pub fn exists(&self, root: &Path) -> bool {
match self.get_path(root) {
Ok(path) => {
let git_dir = root.join(path).join(".git");
git_dir.exists() && git_dir.is_dir()
Expand Down

0 comments on commit 3b13234

Please sign in to comment.