Skip to content

Commit f2854f1

Browse files
jyn514Joshua Nelson
authored and
Joshua Nelson
committed
Feature-gate consistency check
This brings down compile times by two seconds on my local machine.
1 parent 622b341 commit f2854f1

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ exclude = [
1515
".rustwide-docker",
1616
]
1717

18+
[features]
19+
consistency_check = ["crates-index"]
20+
1821
[dependencies]
1922
log = "0.4"
2023
regex = "1"
2124
structopt = "0.3"
22-
crates-index = "0.15.1"
25+
crates-index = { version = "0.15.1", optional = true }
2326
crates-index-diff = "7.1.1"
2427
reqwest = { version = "0.10.6", features = ["blocking", "json"] } # TODO: Remove blocking when async is ready
2528
semver = { version = "0.9", features = ["serde"] }

src/bin/cratesfyi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ enum DatabaseSubcommand {
404404
},
405405

406406
/// Compares the database with the index and resolves inconsistencies
407+
#[cfg(feature = "consistency_check")]
407408
Synchronize {
408409
/// Don't actually resolve the inconsistencies, just log them
409410
#[structopt(long)]
@@ -455,6 +456,7 @@ impl DatabaseSubcommand {
455456
.context("failed to delete the crate")?,
456457
Self::Blacklist { command } => command.handle_args(ctx)?,
457458

459+
#[cfg(feature = "consistency_check")]
458460
Self::Synchronize { dry_run } => {
459461
docs_rs::utils::consistency::run_check(&mut *ctx.conn()?, &*ctx.index()?, dry_run)?;
460462
}

src/index/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ use std::{path::PathBuf, process::Command};
22

33
use url::Url;
44

5-
use self::{api::Api, crates::Crates};
5+
use self::api::Api;
66
use crate::error::Result;
77
use failure::ResultExt;
88

99
pub(crate) mod api;
10+
#[cfg(feature = "consistency_check")]
1011
mod crates;
1112

1213
pub struct Index {
@@ -83,15 +84,16 @@ impl Index {
8384
Ok(diff)
8485
}
8586

86-
pub(crate) fn crates(&self) -> Result<Crates> {
87+
#[cfg(feature = "consistency_check")]
88+
pub(crate) fn crates(&self) -> Result<crates::Crates> {
8789
// First ensure the index is up to date, peeking will pull the latest changes without
8890
// affecting anything else.
8991
log::debug!("Updating index");
9092
self.diff()?.peek_changes()?;
9193
// It'd be nice to use `crates_index` directly for interacting with the index, but it
9294
// doesn't support bare repositories. So we use its `Crate` type but walk the index
9395
// ourselves.
94-
Ok(Crates::new(git2::Repository::open(&self.path)?))
96+
Ok(crates::Crates::new(git2::Repository::open(&self.path)?))
9597
}
9698

9799
pub fn api(&self) -> &Api {

src/utils/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub(crate) use self::rustc_version::parse_rustc_version;
1414
pub(crate) use self::cargo_metadata::{Dependency, Target};
1515

1616
mod cargo_metadata;
17+
#[cfg(feature = "consistency_check")]
1718
pub mod consistency;
1819
mod copy;
1920
mod daemon;

0 commit comments

Comments
 (0)