Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1a836eb

Browse files
committedJan 2, 2022
Extract cargo-registry-index package
1 parent 6290908 commit 1a836eb

File tree

13 files changed

+62
-26
lines changed

13 files changed

+62
-26
lines changed
 

Diff for: ‎Cargo.lock

+16-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ rustdoc-args = [
3131
[dependencies]
3232
anyhow = "=1.0.52"
3333
base64 = "=0.13.0"
34+
cargo-registry-index = { path = "cargo-registry-index" }
3435
cargo-registry-markdown = { path = "cargo-registry-markdown" }
3536
cargo-registry-s3 = { path = "cargo-registry-s3" }
3637
chrono = { version = "=0.4.19", features = ["serde"] }
@@ -56,7 +57,6 @@ dotenv = "=0.15.0"
5657
flate2 = "=1.0.22"
5758
futures-channel = { version = "=0.3.19", default-features = false }
5859
futures-util = "=0.3.19"
59-
git2 = "=0.13.25"
6060
hex = "=0.4.3"
6161
http = "=0.2.6"
6262
hyper = { version = "=0.14.16", features = ["client", "http1"] }
@@ -89,6 +89,7 @@ tracing-subscriber = "=0.2.25"
8989
url = "=2.2.2"
9090

9191
[dev-dependencies]
92+
cargo-registry-index = { path = "cargo-registry-index", features = ["testing"] }
9293
claim = "=0.5.0"
9394
conduit-test = "=0.10.0"
9495
hyper-tls = "=0.5.0"

Diff for: ‎cargo-registry-index/Cargo.toml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "cargo-registry-index"
3+
version = "0.0.0"
4+
license = "MIT OR Apache-2.0"
5+
repository = "https://github.com/rust-lang/crates.io"
6+
description = "crates.io package index utilities"
7+
edition = "2018"
8+
resolver = "2"
9+
10+
[lib]
11+
path = "lib.rs"
12+
13+
[features]
14+
testing = ["serde_json"]
15+
16+
[dependencies]
17+
anyhow = "=1.0.52"
18+
base64 = "=0.13.0"
19+
dotenv = "=0.15.0"
20+
git2 = "=0.13.25"
21+
serde = { version = "=1.0.133", features = ["derive"] }
22+
swirl = { git = "https://github.com/sgrif/swirl.git", rev = "e87cf37" }
23+
tempfile = "=3.2.0"
24+
url = "=2.2.2"
25+
serde_json = { version = "=1.0.74", optional = true }

Diff for: ‎src/git.rs renamed to ‎cargo-registry-index/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#[macro_use]
2+
extern crate serde;
3+
4+
#[cfg(feature = "testing")]
5+
pub mod testing;
6+
17
use anyhow::{anyhow, Context};
28
use std::collections::HashMap;
39
use std::io::Write;

Diff for: ‎src/tests/git.rs renamed to ‎cargo-registry-index/testing.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ impl UpstreamIndex {
2525
}
2626

2727
/// Obtain a list of crates from the index HEAD
28-
pub fn crates_from_index_head(
29-
&self,
30-
crate_name: &str,
31-
) -> anyhow::Result<Vec<cargo_registry::git::Crate>> {
28+
pub fn crates_from_index_head(&self, crate_name: &str) -> anyhow::Result<Vec<crate::Crate>> {
3229
let repo = &self.repository;
3330

34-
let path = cargo_registry::git::Repository::relative_index_file(crate_name);
31+
let path = crate::Repository::relative_index_file(crate_name);
3532

3633
let head = repo.head()?;
3734
let tree = head.peel_to_tree()?;

Diff for: ‎src/background_jobs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::sync::{Arc, Mutex, MutexGuard, PoisonError};
55
use swirl::PerformError;
66

77
use crate::db::{DieselPool, DieselPooledConn, PoolError};
8-
use crate::git::Repository;
98
use crate::uploaders::Uploader;
9+
use cargo_registry_index::Repository;
1010

1111
impl<'a> swirl::db::BorrowedConnection<'a> for DieselPool {
1212
type Connection = DieselPooledConn<'a>;

Diff for: ‎src/bin/background-worker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#![warn(clippy::all, rust_2018_idioms)]
1414

1515
use cargo_registry::config;
16-
use cargo_registry::git::{Repository, RepositoryConfig};
1716
use cargo_registry::{background_jobs::*, db};
17+
use cargo_registry_index::{Repository, RepositoryConfig};
1818
use diesel::r2d2;
1919
use reqwest::blocking::Client;
2020
use std::sync::{Arc, Mutex};

Diff for: ‎src/controllers/krate/publish.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::sync::Arc;
99
use swirl::Job;
1010

1111
use crate::controllers::cargo_prelude::*;
12-
use crate::git;
1312
use crate::models::{
1413
insert_version_owner_action, Badge, Category, Crate, DependencyKind, Keyword, NewCrate,
1514
NewVersion, Rights, VersionAction,
@@ -227,7 +226,7 @@ pub fn publish(req: &mut dyn RequestExt) -> EndpointResult {
227226
};
228227

229228
// Register this crate in our local git repo.
230-
let git_crate = git::Crate {
229+
let git_crate = cargo_registry_index::Crate {
231230
name: name.0,
232231
vers: vers.to_string(),
233232
cksum: hex_cksum,
@@ -310,7 +309,7 @@ pub fn add_dependencies(
310309
conn: &PgConnection,
311310
deps: &[EncodableCrateDependency],
312311
target_version_id: i32,
313-
) -> AppResult<Vec<git::Dependency>> {
312+
) -> AppResult<Vec<cargo_registry_index::Dependency>> {
314313
use self::dependencies::dsl::*;
315314
use diesel::insert_into;
316315

@@ -345,7 +344,7 @@ pub fn add_dependencies(
345344
};
346345

347346
Ok((
348-
git::Dependency {
347+
cargo_registry_index::Dependency {
349348
name,
350349
req: dep.version_req.to_string(),
351350
features: dep.features.iter().map(|s| s.0.to_string()).collect(),

Diff for: ‎src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ pub mod config;
4040
pub mod db;
4141
mod downloads_counter;
4242
pub mod email;
43-
pub mod git;
4443
pub mod github;
4544
pub mod metrics;
4645
pub mod middleware;

Diff for: ‎src/models/dependency.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use diesel::deserialize::{self, FromSql};
22
use diesel::pg::Pg;
33
use diesel::sql_types::Integer;
44

5-
use crate::git::DependencyKind as IndexDependencyKind;
65
use crate::models::{Crate, Version};
76
use crate::schema::*;
7+
use cargo_registry_index::DependencyKind as IndexDependencyKind;
88

99
#[derive(Identifiable, Associations, Debug, Queryable, QueryableByName)]
1010
#[belongs_to(Version)]

Diff for: ‎src/tests/all.rs

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ mod builders;
3737
mod categories;
3838
mod category;
3939
mod dump_db;
40-
mod git;
4140
mod keyword;
4241
mod krate;
4342
mod metrics;

Diff for: ‎src/tests/util/test_app.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
use super::{MockAnonymousUser, MockCookieUser, MockTokenUser};
2-
use crate::git::UpstreamIndex;
32
use crate::record;
43
use crate::util::{chaosproxy::ChaosProxy, fresh_schema::FreshSchema};
54
use cargo_registry::config;
6-
use cargo_registry::{
7-
background_jobs::Environment,
8-
db::DieselPool,
9-
git::{Credentials, RepositoryConfig},
10-
App, Emails,
11-
};
5+
use cargo_registry::{background_jobs::Environment, db::DieselPool, App, Emails};
6+
use cargo_registry_index::testing::UpstreamIndex;
7+
use cargo_registry_index::{Credentials, Repository as WorkerRepository, RepositoryConfig};
128
use std::{rc::Rc, sync::Arc, time::Duration};
139

14-
use cargo_registry::git::Repository as WorkerRepository;
1510
use diesel::PgConnection;
1611
use reqwest::{blocking::Client, Proxy};
1712
use std::collections::HashSet;
@@ -133,7 +128,7 @@ impl TestApp {
133128
}
134129

135130
/// Obtain a list of crates from the index HEAD
136-
pub fn crates_from_index_head(&self, crate_name: &str) -> Vec<cargo_registry::git::Crate> {
131+
pub fn crates_from_index_head(&self, crate_name: &str) -> Vec<cargo_registry_index::Crate> {
137132
self.upstream_index()
138133
.crates_from_index_head(crate_name)
139134
.unwrap()

Diff for: ‎src/worker/git.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::background_jobs::Environment;
2-
use crate::git::Crate;
32
use crate::schema;
43
use anyhow::Context;
4+
use cargo_registry_index::Crate;
55
use chrono::Utc;
66
use diesel::prelude::*;
77
use std::fs::{self, OpenOptions};

0 commit comments

Comments
 (0)
Please sign in to comment.