From 7eca7f271d10eb78e1118d710e9e954a1c526bc4 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 9 Jun 2017 17:51:56 -0700 Subject: [PATCH] Add fossil VCS support to `cargo new` Fossil is a simple, high-reliability, distributed software configuration management system --- src/bin/new.rs | 5 +++-- src/cargo/ops/cargo_new.rs | 22 ++++++++++++++++------ src/cargo/util/mod.rs | 2 +- src/cargo/util/vcs.rs | 29 +++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/bin/new.rs b/src/bin/new.rs index aeee334a965..dfa3668076d 100644 --- a/src/bin/new.rs +++ b/src/bin/new.rs @@ -27,8 +27,9 @@ Usage: Options: -h, --help Print this message --vcs VCS Initialize a new repository for the given version - control system (git, hg, or pijul) or do not initialize any version - control at all (none) overriding a global configuration. + control system (git, hg, pijul, or fossil) or do not + initialize any version control at all (none), overriding + a global configuration. --bin Use a binary (application) template --lib Use a library template [default] --name NAME Set the resulting package name, defaults to the value of diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 846e7c0d444..b41aee94ade 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -12,14 +12,14 @@ use term::color::BLACK; use core::Workspace; use ops::is_bad_artifact_name; -use util::{GitRepo, HgRepo, PijulRepo, internal}; +use util::{GitRepo, HgRepo, PijulRepo, FossilRepo, internal}; use util::{Config, paths}; use util::errors::{CargoError, CargoResult, CargoResultExt}; use toml; #[derive(Clone, Copy, Debug, PartialEq)] -pub enum VersionControl { Git, Hg, Pijul, NoVcs } +pub enum VersionControl { Git, Hg, Pijul, Fossil, NoVcs } pub struct NewOptions<'a> { pub version_control: Option, @@ -49,6 +49,7 @@ impl Decodable for VersionControl { "git" => VersionControl::Git, "hg" => VersionControl::Hg, "pijul" => VersionControl::Pijul, + "fossil" => VersionControl::Fossil, "none" => VersionControl::NoVcs, n => { let err = format!("could not decode '{}' as version control", n); @@ -340,13 +341,17 @@ pub fn init(opts: NewOptions, config: &Config) -> CargoResult<()> { num_detected_vsces += 1; } + if fs::metadata(&path.join(".fossil")).is_ok() { + version_control = Some(VersionControl::Fossil); + num_detected_vsces += 1; + } + // if none exists, maybe create git, like in `cargo new` if num_detected_vsces > 1 { - bail!("more than one of .hg, .git, or .pijul directories found \ - and the ignore file can't be \ - filled in as a result, \ - specify --vcs to override detection"); + bail!("more than one of .hg, .git, .pijul, .fossil configurations \ + found and the ignore file can't be filled in as \ + a result. specify --vcs to override detection"); } } @@ -415,6 +420,11 @@ fn mk(config: &Config, opts: &MkOptions) -> CargoResult<()> { PijulRepo::init(path, config.cwd())?; } }, + VersionControl::Fossil => { + if !fs::metadata(&path.join(".fossil")).is_ok() { + FossilRepo::init(path, config.cwd())?; + } + }, VersionControl::NoVcs => { fs::create_dir_all(path)?; }, diff --git a/src/cargo/util/mod.rs b/src/cargo/util/mod.rs index b1eda3cabeb..9c1c9c5e064 100644 --- a/src/cargo/util/mod.rs +++ b/src/cargo/util/mod.rs @@ -16,7 +16,7 @@ pub use self::rustc::Rustc; pub use self::sha256::Sha256; pub use self::to_semver::ToSemver; pub use self::to_url::ToUrl; -pub use self::vcs::{GitRepo, HgRepo, PijulRepo}; +pub use self::vcs::{GitRepo, HgRepo, PijulRepo, FossilRepo}; pub use self::read2::read2; pub mod config; diff --git a/src/cargo/util/vcs.rs b/src/cargo/util/vcs.rs index 61a4b1c3942..1d3188e2630 100644 --- a/src/cargo/util/vcs.rs +++ b/src/cargo/util/vcs.rs @@ -1,4 +1,5 @@ use std::path::Path; +use std::fs::create_dir; use git2; @@ -7,6 +8,7 @@ use util::{CargoResult, process}; pub struct HgRepo; pub struct GitRepo; pub struct PijulRepo; +pub struct FossilRepo; impl GitRepo { pub fn init(path: &Path, _: &Path) -> CargoResult { @@ -35,3 +37,30 @@ impl PijulRepo { Ok(PijulRepo) } } + +impl FossilRepo { + pub fn init(path: &Path, cwd: &Path) -> CargoResult { + // fossil doesn't create the directory so we'll do that first + create_dir(path)?; + + // set up the paths we'll use + let db_fname = ".fossil"; + let mut db_path = path.to_owned(); + db_path.push(db_fname); + + // then create the fossil DB in that location + process("fossil").cwd(cwd).arg("init").arg(&db_path).exec()?; + + // open it in that new directory + process("fossil").cwd(&path).arg("open").arg(db_fname).exec()?; + + // set `target` as ignoreable and cleanable + process("fossil").cwd(cwd).arg("settings") + .arg("ignore-glob") + .arg("target"); + process("fossil").cwd(cwd).arg("settings") + .arg("clean-glob") + .arg("target"); + Ok(FossilRepo) + } +}