Skip to content

add rcs support to cargo-new|init #15518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/cargo-test-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-test-macro"
version = "0.4.3"
version = "0.4.4"
edition.workspace = true
rust-version = "1.86" # MSRV:1
license.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion crates/cargo-test-macro/src/lib.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for being interested in this! I am sorry to tell you that this might be postponed at this moment 😞. Please read this comment for the team's thought on adding new VCS support. In short,

  • We currently not accept adding any new VCS support.
  • It's unclear what it means to “have VCS support built-in” in Cargo.
  • We are interested in making VCS support more extensible, such as leveraging tooling from VCS itself or working on Cargo templates.

Also, per the contributor guide, it is encouraged to start from an issue first before submitting a pull request, so we can avoid the situation like this. Sorry again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@worr would you mind turning this into an issue? And we'll can link them holistically.

Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ fn check_command(command_path: &Path, args: &[&str]) -> bool {
// environments like Docker. Consider installing it if Cargo
// gains more hg support, but otherwise it isn't critical.
// * lldb is not pre-installed on Ubuntu and Windows, so skip.
if is_ci() && !matches!(command_name.as_str(), "hg" | "lldb") {
// * rcs is not installed on GitHub runners nor on Windows, skip.
if is_ci() && !matches!(command_name.as_str(), "hg" | "lldb" | "rcs") {
panic!("expected command `{command_name}` to be somewhere in PATH: {e}",);
}
return false;
Expand Down
22 changes: 19 additions & 3 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::core::{Edition, Shell, Workspace};
use crate::util::errors::CargoResult;
use crate::util::important_paths::find_root_manifest_for_wd;
use crate::util::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo};
use crate::util::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo, RcsRepo};
use crate::util::{restricted_names, GlobalContext};
use anyhow::{anyhow, Context as _};
use cargo_util::paths::{self, write_atomic};
Expand All @@ -22,6 +22,7 @@ pub enum VersionControl {
Hg,
Pijul,
Fossil,
Rcs,
NoVcs,
}

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

if path.join("RCS").exists() {
version_control = Some(VersionControl::Rcs);
num_detected_vcses += 1;
}

// if none exists, maybe create git, like in `cargo new`

if num_detected_vcses > 1 {
anyhow::bail!(
"more than one of .hg, .git, .pijul, .fossil configurations \
"more than one of .hg, .git, .pijul, .fossil, RCS configurations \
found and the ignore file can't be filled in as \
a result. specify --vcs to override detection"
);
Expand Down Expand Up @@ -688,7 +695,7 @@ fn write_ignore_file(base_path: &Path, list: &IgnoreList, vcs: VersionControl) -
base_path.join(".fossil-settings/ignore-glob"),
base_path.join(".fossil-settings/clean-glob"),
],
VersionControl::NoVcs => return Ok(()),
VersionControl::Rcs | VersionControl::NoVcs => return Ok(()),
} {
let ignore: String = match paths::open(&fp_ignore) {
Err(err) => match err.downcast_ref::<std::io::Error>() {
Expand Down Expand Up @@ -731,6 +738,11 @@ fn init_vcs(path: &Path, vcs: VersionControl, gctx: &GlobalContext) -> CargoResu
FossilRepo::init(path, gctx.cwd())?;
}
}
VersionControl::Rcs => {
if !path.join("RCS").exists() {
RcsRepo::init(path, gctx.cwd())?;
}
}
VersionControl::NoVcs => {
paths::create_dir_all(path)?;
}
Expand Down Expand Up @@ -914,6 +926,10 @@ mod tests {
);
}

if vcs == VersionControl::Rcs {
RcsRepo::late_init(path)?;
}

gctx.shell().note(
"see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html",
)?;
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ pub trait CommandExt: Sized {
a global configuration.",
)
.value_name("VCS")
.value_parser(["git", "hg", "pijul", "fossil", "none"]),
.value_parser(["git", "hg", "pijul", "fossil", "rcs", "none"]),
)
._arg(
flag("bin", "Use a binary (application) template [default]")
Expand Down Expand Up @@ -906,6 +906,7 @@ Run `{cmd}` to see possible targets."
"hg" => VersionControl::Hg,
"pijul" => VersionControl::Pijul,
"fossil" => VersionControl::Fossil,
"rcs" => VersionControl::Rcs,
"none" => VersionControl::NoVcs,
vcs => panic!("Impossible vcs: {:?}", vcs),
});
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 @@ -22,7 +22,7 @@ pub use self::progress::{Progress, ProgressStyle};
pub use self::queue::Queue;
pub use self::rustc::Rustc;
pub use self::semver_ext::{OptVersionReq, VersionExt};
pub use self::vcs::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo};
pub use self::vcs::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo, RcsRepo};
pub use self::workspace::{
add_path_args, path_args, print_available_benches, print_available_binaries,
print_available_examples, print_available_packages, print_available_tests,
Expand Down
46 changes: 45 additions & 1 deletion src/cargo/util/vcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ pub fn existing_vcs_repo(path: &Path, cwd: &Path) -> bool {
}
}

in_git_repo(path, cwd) || HgRepo::discover(path, cwd).is_ok()
in_git_repo(path, cwd)
|| HgRepo::discover(path, cwd).is_ok()
|| RcsRepo::discover(path, cwd).is_ok()
}

pub struct HgRepo;
pub struct GitRepo;
pub struct PijulRepo;
pub struct FossilRepo;
pub struct RcsRepo;

impl GitRepo {
pub fn init(path: &Path, _: &Path) -> CargoResult<GitRepo> {
Expand Down Expand Up @@ -102,3 +105,44 @@ impl FossilRepo {
Ok(FossilRepo)
}
}

impl RcsRepo {
pub fn init(path: &Path, _cwd: &Path) -> CargoResult<RcsRepo> {
paths::create_dir_all(path.join("RCS"))?;
Ok(RcsRepo)
}

pub fn late_init(path: &Path) -> CargoResult<()> {
for entry in walkdir::WalkDir::new(path)
.into_iter()
.filter_entry(|e| e.file_name() != "RCS")
.filter_map(|e| e.ok())
{
let p = entry.path();
if p.is_file() {
if let Some(parent) = p.parent() {
ProcessBuilder::new("ci")
.cwd(parent)
.arg("-i")
.arg("-l")
.arg("-q")
.arg("-t-''")
.arg(entry.file_name())
.exec()?;
}
} else if p.is_dir() {
paths::create_dir_all(p.join("RCS"))?;
}
}

Ok(())
}

pub fn discover(path: &Path, _cwd: &Path) -> CargoResult<RcsRepo> {
ProcessBuilder::new("rlog")
.cwd(&path)
.arg("Cargo.toml")
.exec_with_output()?;
Ok(RcsRepo {})
}
}
4 changes: 2 additions & 2 deletions src/doc/man/generated_txt/cargo-init.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ OPTIONS

--vcs vcs
Initialize a new VCS repository for the given version control system
(git, hg, pijul, or fossil) or do not initialize any version control
at all (none). If not specified, defaults to git or the
(git, hg, pijul, fossil, or rcs) or do not initialize any version
control at all (none). If not specified, defaults to git or the
configuration value cargo-new.vcs, or none if already inside a VCS
repository.

Expand Down
4 changes: 2 additions & 2 deletions src/doc/man/generated_txt/cargo-new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ OPTIONS

--vcs vcs
Initialize a new VCS repository for the given version control system
(git, hg, pijul, or fossil) or do not initialize any version control
at all (none). If not specified, defaults to git or the
(git, hg, pijul, fossil, or rcs) or do not initialize any version
control at all (none). If not specified, defaults to git or the
configuration value cargo-new.vcs, or none if already inside a VCS
repository.

Expand Down
2 changes: 1 addition & 1 deletion src/doc/man/includes/options-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Set the package name. Defaults to the directory name.

{{#option "`--vcs` _vcs_" }}
Initialize a new VCS repository for the given version control system (git,
hg, pijul, or fossil) or do not initialize any version control at all
hg, pijul, fossil, or rcs) or do not initialize any version control at all
(none). If not specified, defaults to `git` or the configuration value
`cargo-new.vcs`, or `none` if already inside a VCS repository.
{{/option}}
Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/commands/cargo-init.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Possible values: 2015, 2018, 2021, 2024</dd>

<dt class="option-term" id="option-cargo-init---vcs"><a class="option-anchor" href="#option-cargo-init---vcs"></a><code>--vcs</code> <em>vcs</em></dt>
<dd class="option-desc">Initialize a new VCS repository for the given version control system (git,
hg, pijul, or fossil) or do not initialize any version control at all
hg, pijul, fossil, or rcs) or do not initialize any version control at all
(none). If not specified, defaults to <code>git</code> or the configuration value
<code>cargo-new.vcs</code>, or <code>none</code> if already inside a VCS repository.</dd>

Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/commands/cargo-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Possible values: 2015, 2018, 2021, 2024</dd>

<dt class="option-term" id="option-cargo-new---vcs"><a class="option-anchor" href="#option-cargo-new---vcs"></a><code>--vcs</code> <em>vcs</em></dt>
<dd class="option-desc">Initialize a new VCS repository for the given version control system (git,
hg, pijul, or fossil) or do not initialize any version control at all
hg, pijul, fossil, or rcs) or do not initialize any version control at all
(none). If not specified, defaults to <code>git</code> or the configuration value
<code>cargo-new.vcs</code>, or <code>none</code> if already inside a VCS repository.</dd>

Expand Down
6 changes: 3 additions & 3 deletions src/doc/src/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ frequency = 'always' # when to display a notification about a future incompat re
auto-clean-frequency = "1 day" # How often to perform automatic cache cleaning

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

[http]
debug = false # HTTP debugging
Expand Down Expand Up @@ -625,8 +625,8 @@ This option is deprecated and unused.
* Environment: `CARGO_CARGO_NEW_VCS`

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

### `[env]`
Expand Down
2 changes: 1 addition & 1 deletion src/etc/_cargo
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ _cargo() {
_arguments -s -S $common $registry \
'--lib[use library template]' \
'--edition=[specify edition to set for the crate generated]:edition:(2015 2018 2021)' \
'--vcs=[initialize a new repo with a given VCS]:vcs:(git hg pijul fossil none)' \
'--vcs=[initialize a new repo with a given VCS]:vcs:(git hg pijul fossil rcs none)' \
'--name=[set the resulting package name]:name' \
'1:path:_directories'
;;
Expand Down
2 changes: 1 addition & 1 deletion src/etc/cargo.bashcomp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ _cargo()
fi
done

local vcs='git hg none pijul fossil'
local vcs='git hg none pijul fossil rcs'
local color='auto always never'
local msg_format='human json short'

Expand Down
2 changes: 1 addition & 1 deletion src/etc/man/cargo-init.1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Set the package name. Defaults to the directory name.
\fB\-\-vcs\fR \fIvcs\fR
.RS 4
Initialize a new VCS repository for the given version control system (git,
hg, pijul, or fossil) or do not initialize any version control at all
hg, pijul, fossil, or rcs) or do not initialize any version control at all
(none). If not specified, defaults to \fBgit\fR or the configuration value
\fBcargo\-new.vcs\fR, or \fBnone\fR if already inside a VCS repository.
.RE
Expand Down
2 changes: 1 addition & 1 deletion src/etc/man/cargo-new.1
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Set the package name. Defaults to the directory name.
\fB\-\-vcs\fR \fIvcs\fR
.RS 4
Initialize a new VCS repository for the given version control system (git,
hg, pijul, or fossil) or do not initialize any version control at all
hg, pijul, fossil, or rcs) or do not initialize any version control at all
(none). If not specified, defaults to \fBgit\fR or the configuration value
\fBcargo\-new.vcs\fR, or \fBnone\fR if already inside a VCS repository.
.RE
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_init/help/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_new/help/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions tests/testsuite/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ fn simple_hg() {
cargo_process("build").cwd(&paths::root().join("foo")).run();
}

#[cargo_test(requires = "rcs")]
fn simple_rcs() {
cargo_process("new --lib foo --vcs rcs").run();

assert!(paths::root().is_dir());
assert!(paths::root().join("foo/RCS").is_dir());
assert!(paths::root().join("foo/RCS/Cargo.toml,v").is_file());
assert!(paths::root().join("foo/Cargo.toml").is_file());
assert!(paths::root().join("foo/src/RCS").is_dir());
assert!(paths::root().join("foo/src/RCS/lib.rs,v").is_file());
assert!(paths::root().join("foo/src/lib.rs").is_file());

cargo_process("build").cwd(&paths::root().join("foo")).run();
}

#[cargo_test]
fn no_argument() {
cargo_process("new")
Expand Down