Skip to content

Commit 64a2821

Browse files
committed
Update to rust master
1 parent 5781ede commit 64a2821

32 files changed

+423
-450
lines changed

Cargo.lock

Lines changed: 129 additions & 136 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ version = "0.1.0"
77
opt-level = 2
88

99
[lib]
10-
name = "cargo-registry"
10+
name = "cargo_registry"
1111
test = false
1212
doctest = false
1313

@@ -41,7 +41,7 @@ path = "src/tests/all.rs"
4141
[dependencies]
4242
s3 = { path = "src/s3" }
4343
migrate = { path = "src/migrate" }
44-
rand = "0.2"
44+
rand = "0.3"
4545
time = "0.1"
4646
git2 = "0.2"
4747
flate2 = "0.2"
@@ -53,8 +53,8 @@ r2d2_postgres = "0.8"
5353
openssl = "0.5"
5454
curl = "0.2"
5555
oauth2 = "0.1"
56-
log = "0.2"
57-
env_logger = "0.2"
56+
log = "0.3"
57+
env_logger = "0.3"
5858
rustc-serialize = "0.3"
5959

6060
conduit = "0.7"

RUSTVERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2015-03-23
1+
2015-03-26

src/app.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ pub struct AppMiddleware {
2929
impl App {
3030
pub fn new(config: &Config) -> App {
3131
let github = oauth2::Config::new(
32-
config.gh_client_id.as_slice(),
33-
config.gh_client_secret.as_slice(),
32+
&config.gh_client_id,
33+
&config.gh_client_secret,
3434
"https://github.com/login/oauth/authorize",
3535
"https://github.com/login/oauth/access_token",
3636
);
@@ -42,7 +42,7 @@ impl App {
4242

4343
let repo = git2::Repository::open(&config.git_repo_checkout).unwrap();
4444
return App {
45-
database: db::pool(config.db_url.as_slice(), db_config),
45+
database: db::pool(&config.db_url, db_config),
4646
github: github,
4747
bucket: s3::Bucket::new(config.s3_bucket.clone(),
4848
config.s3_region.clone(),
@@ -71,12 +71,12 @@ impl Middleware for AppMiddleware {
7171
}
7272
}
7373

74-
pub trait RequestApp<'a> {
75-
fn app(self) -> &'a Arc<App>;
74+
pub trait RequestApp {
75+
fn app(&self) -> &Arc<App>;
7676
}
7777

78-
impl<'a> RequestApp<'a> for &'a (Request + 'a) {
79-
fn app(self) -> &'a Arc<App> {
78+
impl<'a> RequestApp for Request + 'a {
79+
fn app(&self) -> &Arc<App> {
8080
self.extensions().find::<Arc<App>>()
8181
.expect("Missing app")
8282
}

src/bin/delete-crate.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
// cargo run --bin delete-crate crate-name
77

88
#![deny(warnings)]
9-
#![feature(core)]
109

1110
#[macro_use]
12-
extern crate "cargo-registry" as cargo_registry;
11+
extern crate cargo_registry;
1312
extern crate postgres;
1413
extern crate time;
1514

@@ -19,7 +18,7 @@ use std::io;
1918
use cargo_registry::Crate;
2019

2120
fn main() {
22-
let conn = postgres::Connection::connect(env("DATABASE_URL").as_slice(),
21+
let conn = postgres::Connection::connect(&env("DATABASE_URL")[..],
2322
&postgres::SslMode::None).unwrap();
2423
{
2524
let tx = conn.transaction().unwrap();
@@ -42,7 +41,7 @@ fn delete(tx: &postgres::Transaction) {
4241
Some(s) => s,
4342
};
4443

45-
let krate = Crate::find_by_name(tx, name.as_slice()).unwrap();
44+
let krate = Crate::find_by_name(tx, &name).unwrap();
4645
print!("Are you sure you want to delete {} ({}) [y/N]: ", name, krate.id);
4746
let mut line = String::new();
4847
io::stdin().read_line(&mut line).unwrap();

src/bin/delete-version.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
// cargo run --bin delete-version crate-name version-number
77

88
#![deny(warnings)]
9-
#![feature(core)]
109

11-
extern crate "cargo-registry" as cargo_registry;
10+
extern crate cargo_registry;
1211
extern crate postgres;
1312
extern crate time;
1413
extern crate semver;
@@ -19,7 +18,7 @@ use std::io;
1918
use cargo_registry::{Crate, Version};
2019

2120
fn main() {
22-
let conn = postgres::Connection::connect(env("DATABASE_URL").as_slice(),
21+
let conn = postgres::Connection::connect(&env("DATABASE_URL")[..],
2322
&postgres::SslMode::None).unwrap();
2423
{
2524
let tx = conn.transaction().unwrap();
@@ -47,7 +46,7 @@ fn delete(tx: &postgres::Transaction) {
4746
};
4847
let version = semver::Version::parse(&version).unwrap();
4948

50-
let krate = Crate::find_by_name(tx, name.as_slice()).unwrap();
49+
let krate = Crate::find_by_name(tx, &name).unwrap();
5150
let v = Version::find_by_num(tx, krate.id, &version).unwrap().unwrap();
5251
print!("Are you sure you want to delete {}#{} ({}) [y/N]: ", name, version,
5352
v.id);

src/bin/migrate.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![deny(warnings)]
22
#![feature(core)]
33

4-
extern crate "cargo-registry" as cargo_registry;
4+
extern crate cargo_registry;
55
extern crate migrate;
66
extern crate postgres;
77

@@ -13,7 +13,7 @@ use cargo_registry::krate::Crate;
1313
use cargo_registry::model::Model;
1414

1515
fn main() {
16-
let conn = postgres::Connection::connect(env("DATABASE_URL").as_slice(),
16+
let conn = postgres::Connection::connect(&env("DATABASE_URL")[..],
1717
&postgres::SslMode::None).unwrap();
1818
let migrations = migrations();
1919

@@ -74,10 +74,10 @@ fn migrations() -> Vec<Migration> {
7474
num VARCHAR NOT NULL
7575
"),
7676
Migration::run(20140924115329,
77-
format!("ALTER TABLE versions ADD CONSTRAINT \
78-
unique_num UNIQUE (package_id, num)"),
79-
format!("ALTER TABLE versions DROP CONSTRAINT \
80-
unique_num")),
77+
&format!("ALTER TABLE versions ADD CONSTRAINT \
78+
unique_num UNIQUE (package_id, num)"),
79+
&format!("ALTER TABLE versions DROP CONSTRAINT \
80+
unique_num")),
8181
Migration::add_table(20140924120803, "version_dependencies", "
8282
version_id INTEGER NOT NULL,
8383
depends_on_id INTEGER NOT NULL
@@ -466,7 +466,7 @@ fn migrations() -> Vec<Migration> {
466466
table = table, col = column, reference = references);
467467
let rm = format!("ALTER TABLE {table} DROP CONSTRAINT fk_{table}_{col}",
468468
table = table, col = column);
469-
Migration::run(id, add.as_slice(), rm.as_slice())
469+
Migration::run(id, &add, &rm)
470470
}
471471

472472
fn index(id: i64, table: &str, column: &str) -> Migration {
@@ -475,7 +475,7 @@ fn migrations() -> Vec<Migration> {
475475
table = table, column = column);
476476
let rm = format!("DROP INDEX index_{table}_{column}",
477477
table = table, column = column);
478-
Migration::run(id, add.as_slice(), rm.as_slice())
478+
Migration::run(id, &add, &rm)
479479
}
480480
}
481481

src/bin/populate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// cargo run --bin populate version_id1 version_id2 ...
66

77
#![deny(warnings)]
8-
#![feature(core, std_misc)]
8+
#![feature(std_misc)]
99

10-
extern crate "cargo-registry" as cargo_registry;
10+
extern crate cargo_registry;
1111
extern crate postgres;
1212
extern crate time;
1313
extern crate rand;
@@ -17,7 +17,7 @@ use std::time::Duration;
1717
use rand::{StdRng, Rng};
1818

1919
fn main() {
20-
let conn = postgres::Connection::connect(env("DATABASE_URL").as_slice(),
20+
let conn = postgres::Connection::connect(&env("DATABASE_URL")[..],
2121
&postgres::SslMode::None).unwrap();
2222
{
2323
let tx = conn.transaction().unwrap();

src/bin/server.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![deny(warnings)]
2-
#![feature(core)]
2+
#![feature(convert)]
33

4-
extern crate "cargo-registry" as cargo_registry;
5-
extern crate "conduit-middleware" as conduit_middleware;
4+
extern crate cargo_registry;
5+
extern crate conduit_middleware;
66
extern crate civet;
77
extern crate git2;
88
extern crate env_logger;
@@ -17,7 +17,7 @@ use std::sync::mpsc::channel;
1717
fn main() {
1818
env_logger::init().unwrap();
1919
let url = env("GIT_REPO_URL");
20-
let checkout = PathBuf::new(&env("GIT_REPO_CHECKOUT"));
20+
let checkout = PathBuf::from(env("GIT_REPO_CHECKOUT"));
2121

2222
let repo = match git2::Repository::open(&checkout) {
2323
Ok(r) => r,
@@ -28,7 +28,7 @@ fn main() {
2828
cb.credentials(cargo_registry::git::credentials);
2929
git2::build::RepoBuilder::new()
3030
.remote_callbacks(cb)
31-
.clone(url.as_slice(), &checkout).unwrap()
31+
.clone(&url, &checkout).unwrap()
3232
}
3333
};
3434
let mut cfg = repo.config().unwrap();

src/bin/update-downloads.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![deny(warnings)]
2-
#![feature(std_misc, core, old_io)]
2+
#![feature(std_misc, thread_sleep)]
33

4-
extern crate "cargo-registry" as cargo_registry;
4+
extern crate cargo_registry;
55
extern crate postgres;
66
extern crate semver;
77
extern crate time;
@@ -20,7 +20,7 @@ fn main() {
2020
== Some("daemon");
2121
let sleep = env::args().nth(2).map(|s| s.parse::<i64>().unwrap());
2222
loop {
23-
let conn = postgres::Connection::connect(env("DATABASE_URL").as_slice(),
23+
let conn = postgres::Connection::connect(&env("DATABASE_URL")[..],
2424
&postgres::SslMode::None).unwrap();
2525
{
2626
let tx = conn.transaction().unwrap();
@@ -32,7 +32,7 @@ fn main() {
3232
if daemon {
3333
#[allow(deprecated)]
3434
fn do_sleep(sleep: Option<i64>) {
35-
std::old_io::timer::sleep(Duration::seconds(sleep.unwrap()));
35+
std::thread::sleep(Duration::seconds(sleep.unwrap()));
3636
}
3737
do_sleep(sleep);
3838
} else {
@@ -142,7 +142,7 @@ mod test {
142142
use cargo_registry::{Version, Crate, User};
143143

144144
fn conn() -> postgres::Connection {
145-
postgres::Connection::connect(::env("TEST_DATABASE_URL").as_slice(),
145+
postgres::Connection::connect(&::env("TEST_DATABASE_URL")[..],
146146
&postgres::SslMode::None).unwrap()
147147
}
148148

src/db.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl Transaction {
8888
}
8989
let tx = self.tx.borrow();
9090
let tx: &'a pg::Transaction<'static> = tx.unwrap();
91-
Ok(tx as &Connection)
91+
Ok(tx)
9292
}
9393

9494
pub fn rollback(&self) { self.commit.set(false); }
@@ -120,44 +120,44 @@ impl Middleware for TransactionMiddleware {
120120
}
121121
}
122122

123-
pub trait RequestTransaction<'a> {
123+
pub trait RequestTransaction {
124124
/// Return the lazily initialized postgres connection for this request.
125125
///
126126
/// The connection will live for the lifetime of the request.
127-
fn db_conn(self) -> CargoResult<&'a pg::Connection>;
127+
fn db_conn(&self) -> CargoResult<&pg::Connection>;
128128

129129
/// Return the lazily initialized postgres transaction for this request.
130130
///
131131
/// The transaction will live for the duration of the request, and it will
132132
/// only be set to commit() if a successful response code of 200 is seen.
133-
fn tx(self) -> CargoResult<&'a (Connection + 'a)>;
133+
fn tx(&self) -> CargoResult<&Connection>;
134134

135135
/// Flag the transaction to not be committed
136-
fn rollback(self);
136+
fn rollback(&self);
137137
/// Flag this transaction to be committed
138-
fn commit(self);
138+
fn commit(&self);
139139
}
140140

141-
impl<'a> RequestTransaction<'a> for &'a (Request + 'a) {
142-
fn db_conn(self) -> CargoResult<&'a pg::Connection> {
141+
impl<'a> RequestTransaction for Request + 'a {
142+
fn db_conn(&self) -> CargoResult<&pg::Connection> {
143143
self.extensions().find::<Transaction>()
144144
.expect("Transaction not present in request")
145145
.conn()
146146
}
147147

148-
fn tx(self) -> CargoResult<&'a (Connection + 'a)> {
148+
fn tx(&self) -> CargoResult<&Connection> {
149149
self.extensions().find::<Transaction>()
150150
.expect("Transaction not present in request")
151151
.tx()
152152
}
153153

154-
fn rollback(self) {
154+
fn rollback(&self) {
155155
self.extensions().find::<Transaction>()
156156
.expect("Transaction not present in request")
157157
.rollback()
158158
}
159159

160-
fn commit(self) {
160+
fn commit(&self) {
161161
self.extensions().find::<Transaction>()
162162
.expect("Transaction not present in request")
163163
.commit()

src/dependency.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Dependency {
8484
req: req.to_string(),
8585
optional: optional,
8686
default_features: default_features,
87-
features: features.as_slice().connect(","),
87+
features: features.connect(","),
8888
target: target,
8989
kind: kind,
9090
}
@@ -100,10 +100,10 @@ impl Model for Dependency {
100100
id: row.get("id"),
101101
version_id: row.get("version_id"),
102102
crate_id: row.get("crate_id"),
103-
req: semver::VersionReq::parse(req.as_slice()).unwrap(),
103+
req: semver::VersionReq::parse(&req).unwrap(),
104104
optional: row.get("optional"),
105105
default_features: row.get("default_features"),
106-
features: features.as_slice().split(',').map(|s| s.to_string())
106+
features: features.split(',').map(|s| s.to_string())
107107
.collect(),
108108
target: row.get("target"),
109109
kind: FromPrimitive::from_i32(kind.unwrap_or(0)).unwrap(),

src/git.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn add_crate(app: &App, krate: &Crate) -> CargoResult<()> {
4949
let repo = app.git_repo.lock().unwrap();
5050
let repo = &*repo;
5151
let repo_path = repo.workdir().unwrap();
52-
let dst = index_file(&repo_path, krate.name.as_slice());
52+
let dst = index_file(&repo_path, &krate.name);
5353

5454
commit_and_push(repo, || {
5555
// Add the crate to its relevant file
@@ -128,8 +128,7 @@ fn commit_and_push<F>(repo: &git2::Repository, mut f: F) -> CargoResult<()>
128128
let head = try!(repo.head());
129129
let parent = try!(repo.find_commit(head.target().unwrap()));
130130
let sig = try!(repo.signature());
131-
try!(repo.commit(Some("HEAD"), &sig, &sig, msg.as_slice(),
132-
&tree, &[&parent]));
131+
try!(repo.commit(Some("HEAD"), &sig, &sig, &msg, &tree, &[&parent]));
133132

134133
// git push
135134
let mut callbacks = git2::RemoteCallbacks::new();
@@ -168,7 +167,7 @@ pub fn credentials(_user: &str, _user_from_url: Option<&str>,
168167
-> Result<git2::Cred, git2::Error> {
169168
match (env::var("GIT_HTTP_USER"), env::var("GIT_HTTP_PWD")) {
170169
(Ok(u), Ok(p)) => {
171-
git2::Cred::userpass_plaintext(u.as_slice(), p.as_slice())
170+
git2::Cred::userpass_plaintext(&u, &p)
172171
}
173172
_ => Err(git2::Error::from_str("no authentication set"))
174173
}

0 commit comments

Comments
 (0)