Skip to content

Commit

Permalink
Auto merge of #4155 - ketralnis:fossil, r=alexcrichton
Browse files Browse the repository at this point in the history
Add fossil VCS support to `cargo new`

Fossil is a simple, high-reliability, distributed software configuration management system <https://www.fossil-scm.org/>

I mostly followed #3842 as a template. Like that one, this only adds support for `cargo new`, not for pulling down fossil-hosted dependencies

A problem that i didn't tackle but I'd be willing to is a little more more `trait`ifying of the VCSs. I would need some guidance on that since it looks like git has some more thorough support than e.g. hg does but it looks pretty doable
  • Loading branch information
bors committed Jun 14, 2017
2 parents 46252c6 + 7eca7f2 commit e934177
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/bin/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path>
Expand Down
22 changes: 16 additions & 6 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,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<VersionControl>,
Expand Down Expand Up @@ -50,6 +50,7 @@ impl<'de> Deserialize<'de> for VersionControl {
"git" => VersionControl::Git,
"hg" => VersionControl::Hg,
"pijul" => VersionControl::Pijul,
"fossil" => VersionControl::Fossil,
"none" => VersionControl::NoVcs,
n => {
let value = de::Unexpected::Str(n);
Expand Down Expand Up @@ -342,13 +343,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");
}
}

Expand Down Expand Up @@ -418,6 +423,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)?;
},
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions src/cargo/util/vcs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::path::Path;
use std::fs::create_dir;

use git2;

Expand All @@ -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<GitRepo> {
Expand Down Expand Up @@ -35,3 +37,30 @@ impl PijulRepo {
Ok(PijulRepo)
}
}

impl FossilRepo {
pub fn init(path: &Path, cwd: &Path) -> CargoResult<FossilRepo> {
// 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)
}
}

0 comments on commit e934177

Please # to comment.