From bc74f7459dd66878a546127a62fc2c574966460d Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 11 Jul 2024 17:25:23 -0500 Subject: [PATCH 1/2] Add support for diff.rs to `cargo vet diff` --- book/src/how-it-works.md | 4 ++-- src/cli.rs | 14 ++++++++++--- src/main.rs | 22 ++++++++++++++------ tests/snapshots/test_cli__markdown-help.snap | 2 +- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/book/src/how-it-works.md b/book/src/how-it-works.md index 02fae5fc..820049c0 100644 --- a/book/src/how-it-works.md +++ b/book/src/how-it-works.md @@ -68,8 +68,8 @@ themselves, and cargo-vet streamlines this process. Often someone will have already audited a different version of the same crate, in which case cargo-vet computes the relevant diffs and identifies the smallest one[^1]. After walking the developer through the process of determining what to audit, it then presents -the relevant artifacts for inspection, either locally or on -[Sourcegraph](https://sourcegraph.com). +the relevant artifacts for inspection, either locally, on +[Sourcegraph](https://sourcegraph.com), or on [diff.rs](https://diff.rs). Cargo-vet minimizes developer friction by storing audits in-tree. This means that developers don’t need to navigate or authenticate with an external system. diff --git a/src/cli.rs b/src/cli.rs index d3b3a248..83ea068a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -466,7 +466,7 @@ pub struct InspectArgs { pub version: VetVersion, /// How to inspect the source #[clap(long, action, default_value = "sourcegraph")] - pub mode: FetchMode, + pub mode: InspectFetchMode, } /// Emits a diff of the two versions @@ -483,7 +483,7 @@ pub struct DiffArgs { pub version2: VetVersion, /// How to inspect the source #[clap(long, action, default_value = "sourcegraph")] - pub mode: FetchMode, + pub mode: DiffFetchMode, } /// Certifies a package as audited @@ -773,11 +773,19 @@ pub enum Verbose { } #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)] -pub enum FetchMode { +pub enum InspectFetchMode { Local, Sourcegraph, } +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)] +pub enum DiffFetchMode { + Local, + Sourcegraph, + #[clap(name = "diff.rs")] + DiffRs, +} + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)] pub enum OutputFormat { /// Print output in a human-readable form. diff --git a/src/main.rs b/src/main.rs index 229da420..96e1bd53 100644 --- a/src/main.rs +++ b/src/main.rs @@ -569,7 +569,7 @@ fn cmd_inspect( version: version.clone(), }); - if sub_args.mode == FetchMode::Sourcegraph && version.git_rev.is_none() { + if sub_args.mode == InspectFetchMode::Sourcegraph && version.git_rev.is_none() { let url = format!("https://sourcegraph.com/crates/{package}@v{version}"); tokio::runtime::Handle::current() .block_on(prompt_criteria_eulas( @@ -2052,13 +2052,23 @@ fn cmd_diff(out: &Arc, cfg: &Config, sub_args: &DiffArgs) -> Result<(), version2: version2.clone(), }); - if sub_args.mode == FetchMode::Sourcegraph - && version1.git_rev.is_none() + if matches!( + sub_args.mode, + DiffFetchMode::Sourcegraph | DiffFetchMode::DiffRs + ) && version1.git_rev.is_none() && version2.git_rev.is_none() { - let url = format!( - "https://sourcegraph.com/crates/{package}/-/compare/v{version1}...v{version2}?visible=7000" - ); + let url = match sub_args.mode { + DiffFetchMode::Sourcegraph => { + format!( + "https://sourcegraph.com/crates/{package}/-/compare/v{version1}...v{version2}?visible=7000" + ) + } + DiffFetchMode::DiffRs => { + format!("https://diff.rs/{package}/{version1}/{version2}/") + } + DiffFetchMode::Local => unreachable!(), + }; tokio::runtime::Handle::current() .block_on(prompt_criteria_eulas( out, diff --git a/tests/snapshots/test_cli__markdown-help.snap b/tests/snapshots/test_cli__markdown-help.snap index ba8c8a9f..8e4dfeb2 100644 --- a/tests/snapshots/test_cli__markdown-help.snap +++ b/tests/snapshots/test_cli__markdown-help.snap @@ -313,7 +313,7 @@ The target version to diff How to inspect the source \[default: sourcegraph] -\[possible values: local, sourcegraph] +\[possible values: local, sourcegraph, diff.rs] #### `-h, --help` Print help information From 5a61b3e8eb7196254c50135a9fbf6d9a3a5238a8 Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Thu, 18 Jul 2024 16:05:37 -0400 Subject: [PATCH 2/2] Update src/main.rs --- src/main.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 96e1bd53..ae204d0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2052,10 +2052,8 @@ fn cmd_diff(out: &Arc, cfg: &Config, sub_args: &DiffArgs) -> Result<(), version2: version2.clone(), }); - if matches!( - sub_args.mode, - DiffFetchMode::Sourcegraph | DiffFetchMode::DiffRs - ) && version1.git_rev.is_none() + if sub_args.mode != FetchMode::Local + && version1.git_rev.is_none() && version2.git_rev.is_none() { let url = match sub_args.mode {