Skip to content

Commit faa7fd6

Browse files
committed
add rcs support to cargo-new|init
RCS is a venerable version control system available in many UNIX systems for local version tracking. Adds support for initializing an RCS repo and discovering it as an existing version control system.
1 parent 3c5bb55 commit faa7fd6

File tree

11 files changed

+90
-14
lines changed

11 files changed

+90
-14
lines changed

src/cargo/ops/cargo_new.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::core::{Edition, Shell, Workspace};
22
use crate::util::errors::CargoResult;
33
use crate::util::important_paths::find_root_manifest_for_wd;
4-
use crate::util::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo};
4+
use crate::util::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo, RcsRepo};
55
use crate::util::{restricted_names, GlobalContext};
66
use anyhow::{anyhow, Context as _};
77
use cargo_util::paths::{self, write_atomic};
@@ -22,6 +22,7 @@ pub enum VersionControl {
2222
Hg,
2323
Pijul,
2424
Fossil,
25+
Rcs,
2526
NoVcs,
2627
}
2728

@@ -34,6 +35,7 @@ impl FromStr for VersionControl {
3435
"hg" => Ok(VersionControl::Hg),
3536
"pijul" => Ok(VersionControl::Pijul),
3637
"fossil" => Ok(VersionControl::Fossil),
38+
"rcs" => Ok(VersionControl::Rcs),
3739
"none" => Ok(VersionControl::NoVcs),
3840
other => anyhow::bail!("unknown vcs specification: `{}`", other),
3941
}
@@ -542,11 +544,16 @@ pub fn init(opts: &NewOptions, gctx: &GlobalContext) -> CargoResult<NewProjectKi
542544
num_detected_vcses += 1;
543545
}
544546

547+
if path.join("RCS").exists() {
548+
version_control = Some(VersionControl::Rcs);
549+
num_detected_vcses += 1;
550+
}
551+
545552
// if none exists, maybe create git, like in `cargo new`
546553

547554
if num_detected_vcses > 1 {
548555
anyhow::bail!(
549-
"more than one of .hg, .git, .pijul, .fossil configurations \
556+
"more than one of .hg, .git, .pijul, .fossil, RCS configurations \
550557
found and the ignore file can't be filled in as \
551558
a result. specify --vcs to override detection"
552559
);
@@ -688,7 +695,7 @@ fn write_ignore_file(base_path: &Path, list: &IgnoreList, vcs: VersionControl) -
688695
base_path.join(".fossil-settings/ignore-glob"),
689696
base_path.join(".fossil-settings/clean-glob"),
690697
],
691-
VersionControl::NoVcs => return Ok(()),
698+
VersionControl::Rcs | VersionControl::NoVcs => return Ok(()),
692699
} {
693700
let ignore: String = match paths::open(&fp_ignore) {
694701
Err(err) => match err.downcast_ref::<std::io::Error>() {
@@ -731,6 +738,11 @@ fn init_vcs(path: &Path, vcs: VersionControl, gctx: &GlobalContext) -> CargoResu
731738
FossilRepo::init(path, gctx.cwd())?;
732739
}
733740
}
741+
VersionControl::Rcs => {
742+
if !path.join("RCS").exists() {
743+
RcsRepo::init(path, gctx.cwd())?;
744+
}
745+
}
734746
VersionControl::NoVcs => {
735747
paths::create_dir_all(path)?;
736748
}
@@ -914,6 +926,10 @@ mod tests {
914926
);
915927
}
916928

929+
if vcs == VersionControl::Rcs {
930+
RcsRepo::late_init(path)?;
931+
}
932+
917933
gctx.shell().note(
918934
"see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html",
919935
)?;

src/cargo/util/command_prelude.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ pub trait CommandExt: Sized {
403403
a global configuration.",
404404
)
405405
.value_name("VCS")
406-
.value_parser(["git", "hg", "pijul", "fossil", "none"]),
406+
.value_parser(["git", "hg", "pijul", "fossil", "rcs", "none"]),
407407
)
408408
._arg(
409409
flag("bin", "Use a binary (application) template [default]")
@@ -906,6 +906,7 @@ Run `{cmd}` to see possible targets."
906906
"hg" => VersionControl::Hg,
907907
"pijul" => VersionControl::Pijul,
908908
"fossil" => VersionControl::Fossil,
909+
"rcs" => VersionControl::Rcs,
909910
"none" => VersionControl::NoVcs,
910911
vcs => panic!("Impossible vcs: {:?}", vcs),
911912
});

src/cargo/util/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub use self::progress::{Progress, ProgressStyle};
2222
pub use self::queue::Queue;
2323
pub use self::rustc::Rustc;
2424
pub use self::semver_ext::{OptVersionReq, VersionExt};
25-
pub use self::vcs::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo};
25+
pub use self::vcs::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo, RcsRepo};
2626
pub use self::workspace::{
2727
add_path_args, path_args, print_available_benches, print_available_binaries,
2828
print_available_examples, print_available_packages, print_available_tests,

src/cargo/util/vcs.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ pub fn existing_vcs_repo(path: &Path, cwd: &Path) -> bool {
2222
}
2323
}
2424

25-
in_git_repo(path, cwd) || HgRepo::discover(path, cwd).is_ok()
25+
in_git_repo(path, cwd)
26+
|| HgRepo::discover(path, cwd).is_ok()
27+
|| RcsRepo::discover(path, cwd).is_ok()
2628
}
2729

2830
pub struct HgRepo;
2931
pub struct GitRepo;
3032
pub struct PijulRepo;
3133
pub struct FossilRepo;
34+
pub struct RcsRepo;
3235

3336
impl GitRepo {
3437
pub fn init(path: &Path, _: &Path) -> CargoResult<GitRepo> {
@@ -102,3 +105,44 @@ impl FossilRepo {
102105
Ok(FossilRepo)
103106
}
104107
}
108+
109+
impl RcsRepo {
110+
pub fn init(path: &Path, _cwd: &Path) -> CargoResult<RcsRepo> {
111+
paths::create_dir_all(path.join("RCS"))?;
112+
Ok(RcsRepo)
113+
}
114+
115+
pub fn late_init(path: &Path) -> CargoResult<()> {
116+
for entry in walkdir::WalkDir::new(path)
117+
.into_iter()
118+
.filter_entry(|e| e.file_name() != "RCS")
119+
.filter_map(|e| e.ok())
120+
{
121+
let p = entry.path();
122+
if p.is_file() {
123+
if let Some(parent) = p.parent() {
124+
ProcessBuilder::new("ci")
125+
.cwd(parent)
126+
.arg("-i")
127+
.arg("-l")
128+
.arg("-q")
129+
.arg("-t-''")
130+
.arg(entry.file_name())
131+
.exec()?;
132+
}
133+
} else if p.is_dir() {
134+
paths::create_dir_all(p.join("RCS"))?;
135+
}
136+
}
137+
138+
Ok(())
139+
}
140+
141+
pub fn discover(path: &Path, _cwd: &Path) -> CargoResult<RcsRepo> {
142+
ProcessBuilder::new("rlog")
143+
.cwd(&path)
144+
.arg("Cargo.toml")
145+
.exec_with_output()?;
146+
Ok(RcsRepo {})
147+
}
148+
}

src/doc/man/includes/options-new.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Set the package name. Defaults to the directory name.
2020

2121
{{#option "`--vcs` _vcs_" }}
2222
Initialize a new VCS repository for the given version control system (git,
23-
hg, pijul, or fossil) or do not initialize any version control at all
23+
hg, pijul, fossil, or rcs) or do not initialize any version control at all
2424
(none). If not specified, defaults to `git` or the configuration value
2525
`cargo-new.vcs`, or `none` if already inside a VCS repository.
2626
{{/option}}

src/doc/src/reference/config.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ frequency = 'always' # when to display a notification about a future incompat re
9999
auto-clean-frequency = "1 day" # How often to perform automatic cache cleaning
100100

101101
[cargo-new]
102-
vcs = "none" # VCS to use ('git', 'hg', 'pijul', 'fossil', 'none')
102+
vcs = "none" # VCS to use ('git', 'hg', 'pijul', 'fossil', 'rcs', 'none')
103103

104104
[http]
105105
debug = false # HTTP debugging
@@ -625,8 +625,8 @@ This option is deprecated and unused.
625625
* Environment: `CARGO_CARGO_NEW_VCS`
626626

627627
Specifies the source control system to use for initializing a new repository.
628-
Valid values are `git`, `hg` (for Mercurial), `pijul`, `fossil` or `none` to
629-
disable this behavior. Defaults to `git`, or `none` if already inside a VCS
628+
Valid values are `git`, `hg` (for Mercurial), `pijul`, `fossil`, `rcs` or `none`
629+
to disable this behavior. Defaults to `git`, or `none` if already inside a VCS
630630
repository. Can be overridden with the `--vcs` CLI option.
631631

632632
### `[env]`

src/etc/_cargo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ _cargo() {
173173
_arguments -s -S $common $registry \
174174
'--lib[use library template]' \
175175
'--edition=[specify edition to set for the crate generated]:edition:(2015 2018 2021)' \
176-
'--vcs=[initialize a new repo with a given VCS]:vcs:(git hg pijul fossil none)' \
176+
'--vcs=[initialize a new repo with a given VCS]:vcs:(git hg pijul fossil rcs none)' \
177177
'--name=[set the resulting package name]:name' \
178178
'1:path:_directories'
179179
;;

src/etc/cargo.bashcomp.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ _cargo()
2828
fi
2929
done
3030

31-
local vcs='git hg none pijul fossil'
31+
local vcs='git hg none pijul fossil rcs'
3232
local color='auto always never'
3333
local msg_format='human json short'
3434

tests/testsuite/cargo_init/help/stdout.term.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/testsuite/cargo_new/help/stdout.term.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/testsuite/new.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ fn simple_hg() {
131131
cargo_process("build").cwd(&paths::root().join("foo")).run();
132132
}
133133

134+
#[cargo_test(requires = "rcs")]
135+
fn simple_rcs() {
136+
cargo_process("new --lib foo --vcs rcs").run();
137+
138+
assert!(paths::root().is_dir());
139+
assert!(paths::root().join("foo/RCS").is_dir());
140+
assert!(paths::root().join("foo/RCS/Cargo.toml,v").is_file());
141+
assert!(paths::root().join("foo/Cargo.toml").is_file());
142+
assert!(paths::root().join("foo/src/RCS").is_dir());
143+
assert!(paths::root().join("foo/src/RCS/lib.rs,v").is_file());
144+
assert!(paths::root().join("foo/src/lib.rs").is_file());
145+
146+
cargo_process("build").cwd(&paths::root().join("foo")).run();
147+
}
148+
134149
#[cargo_test]
135150
fn no_argument() {
136151
cargo_process("new")

0 commit comments

Comments
 (0)