Skip to content

Commit 1994af6

Browse files
ericktgraydon
authored andcommitted
---
yaml --- r: 22078 b: refs/heads/snap-stage3 c: 49d00b2 h: refs/heads/master v: v3
1 parent 6bedb10 commit 1994af6

File tree

4 files changed

+820
-528
lines changed

4 files changed

+820
-528
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: e430a699f2c60890d9b86069fd0c68a70ece7120
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: a1ab7d3cba6c753cd1c838f99fabf029e4c1d035
4+
refs/heads/snap-stage3: 49d00b2f22576e7043a27f444804f563100212fe
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/cargo/cargo.rs

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use syntax::diagnostic;
1111

1212
use result::{Ok, Err};
1313
use io::WriterUtil;
14+
use send_map::linear::LinearMap;
1415
use std::{map, json, tempfile, term, sort, getopts};
1516
use map::HashMap;
1617
use to_str::to_str;
@@ -400,7 +401,7 @@ fn need_dir(s: &Path) {
400401
}
401402
}
402403

403-
fn valid_pkg_name(s: ~str) -> bool {
404+
fn valid_pkg_name(s: &str) -> bool {
404405
fn is_valid_digit(c: char) -> bool {
405406
('0' <= c && c <= '9') ||
406407
('a' <= c && c <= 'z') ||
@@ -412,27 +413,27 @@ fn valid_pkg_name(s: ~str) -> bool {
412413
s.all(is_valid_digit)
413414
}
414415

415-
fn parse_source(name: ~str, j: json::Json) -> @Source {
416+
fn parse_source(name: ~str, j: &json::Json) -> @Source {
416417
if !valid_pkg_name(name) {
417418
fail fmt!("'%s' is an invalid source name", name);
418419
}
419420

420-
match j {
421-
json::Dict(j) => {
422-
let mut url = match j.find(~"url") {
423-
Some(json::String(u)) => *u,
421+
match *j {
422+
json::Object(j) => {
423+
let mut url = match j.find(&~"url") {
424+
Some(json::String(u)) => u,
424425
_ => fail ~"needed 'url' field in source"
425426
};
426-
let method = match j.find(~"method") {
427-
Some(json::String(u)) => *u,
427+
let method = match j.find(&~"method") {
428+
Some(json::String(u)) => u,
428429
_ => assume_source_method(url)
429430
};
430-
let key = match j.find(~"key") {
431-
Some(json::String(u)) => Some(*u),
431+
let key = match j.find(&~"key") {
432+
Some(json::String(u)) => Some(u),
432433
_ => None
433434
};
434-
let keyfp = match j.find(~"keyfp") {
435-
Some(json::String(u)) => Some(*u),
435+
let keyfp = match j.find(&~"keyfp") {
436+
Some(json::String(u)) => Some(u),
436437
_ => None
437438
};
438439
if method == ~"file" {
@@ -454,88 +455,88 @@ fn try_parse_sources(filename: &Path, sources: map::HashMap<~str, @Source>) {
454455
if !os::path_exists(filename) { return; }
455456
let c = io::read_whole_file_str(filename);
456457
match json::from_str(c.get()) {
457-
Ok(json::Dict(j)) => {
458-
for j.each |k, v| {
459-
sources.insert(k, parse_source(k, v));
460-
debug!("source: %s", k);
458+
Ok(json::Object(j)) => {
459+
for j.each |k, v| {
460+
sources.insert(copy *k, parse_source(*k, v));
461+
debug!("source: %s", *k);
461462
}
462463
}
463464
Ok(_) => fail ~"malformed sources.json",
464465
Err(e) => fail fmt!("%s:%s", filename.to_str(), e.to_str())
465466
}
466467
}
467468

468-
fn load_one_source_package(src: @Source, p: map::HashMap<~str, json::Json>) {
469-
let name = match p.find(~"name") {
469+
fn load_one_source_package(src: @Source, p: &json::Object) {
470+
let name = match p.find(&~"name") {
470471
Some(json::String(n)) => {
471-
if !valid_pkg_name(*n) {
472+
if !valid_pkg_name(n) {
472473
warn(~"malformed source json: "
473-
+ src.name + ~", '" + *n + ~"'"+
474+
+ src.name + ~", '" + n + ~"'"+
474475
~" is an invalid name (alphanumeric, underscores and" +
475476
~" dashes only)");
476477
return;
477478
}
478-
*n
479+
n
479480
}
480481
_ => {
481482
warn(~"malformed source json: " + src.name + ~" (missing name)");
482483
return;
483484
}
484485
};
485486

486-
let uuid = match p.find(~"uuid") {
487+
let uuid = match p.find(&~"uuid") {
487488
Some(json::String(n)) => {
488-
if !is_uuid(*n) {
489+
if !is_uuid(n) {
489490
warn(~"malformed source json: "
490-
+ src.name + ~", '" + *n + ~"'"+
491+
+ src.name + ~", '" + n + ~"'"+
491492
~" is an invalid uuid");
492493
return;
493494
}
494-
*n
495+
n
495496
}
496497
_ => {
497498
warn(~"malformed source json: " + src.name + ~" (missing uuid)");
498499
return;
499500
}
500501
};
501502

502-
let url = match p.find(~"url") {
503-
Some(json::String(n)) => *n,
503+
let url = match p.find(&~"url") {
504+
Some(json::String(n)) => n,
504505
_ => {
505506
warn(~"malformed source json: " + src.name + ~" (missing url)");
506507
return;
507508
}
508509
};
509510

510-
let method = match p.find(~"method") {
511-
Some(json::String(n)) => *n,
511+
let method = match p.find(&~"method") {
512+
Some(json::String(n)) => n,
512513
_ => {
513514
warn(~"malformed source json: "
514515
+ src.name + ~" (missing method)");
515516
return;
516517
}
517518
};
518519

519-
let reference = match p.find(~"ref") {
520-
Some(json::String(n)) => Some(*n),
520+
let reference = match p.find(&~"ref") {
521+
Some(json::String(n)) => Some(n),
521522
_ => None
522523
};
523524
524525
let mut tags = ~[];
525-
match p.find(~"tags") {
526+
match p.find(&~"tags") {
526527
Some(json::List(js)) => {
527-
for (*js).each |j| {
528+
for js.each |j| {
528529
match *j {
529-
json::String(j) => vec::grow(tags, 1u, *j),
530+
json::String(j) => vec::grow(tags, 1u, j),
530531
_ => ()
531532
}
532533
}
533534
}
534535
_ => ()
535536
}
536537

537-
let description = match p.find(~"description") {
538-
Some(json::String(n)) => *n,
538+
let description = match p.find(&~"description") {
539+
Some(json::String(n)) => n,
539540
_ => {
540541
warn(~"malformed source json: " + src.name
541542
+ ~" (missing description)");
@@ -573,8 +574,8 @@ fn load_source_info(c: &Cargo, src: @Source) {
573574
if !os::path_exists(&srcfile) { return; }
574575
let srcstr = io::read_whole_file_str(&srcfile);
575576
match json::from_str(srcstr.get()) {
576-
Ok(json::Dict(s)) => {
577-
let o = parse_source(src.name, json::Dict(s));
577+
Ok(ref json @ json::Object(_)) => {
578+
let o = parse_source(src.name, json);
578579

579580
src.key = o.key;
580581
src.keyfp = o.keyfp;
@@ -596,9 +597,9 @@ fn load_source_packages(c: &Cargo, src: @Source) {
596597
let pkgstr = io::read_whole_file_str(&pkgfile);
597598
match json::from_str(pkgstr.get()) {
598599
Ok(json::List(js)) => {
599-
for (*js).each |j| {
600+
for js.each |j| {
600601
match *j {
601-
json::Dict(p) => {
602+
json::Object(p) => {
602603
load_one_source_package(src, p);
603604
}
604605
_ => {
@@ -663,11 +664,11 @@ fn configure(opts: Options) -> Cargo {
663664

664665
let p = get_cargo_dir().get();
665666

666-
let sources = map::HashMap();
667+
let sources = HashMap();
667668
try_parse_sources(&home.push("sources.json"), sources);
668669
try_parse_sources(&home.push("local-sources.json"), sources);
669670

670-
let dep_cache = map::HashMap();
671+
let dep_cache = HashMap();
671672

672673
let mut c = Cargo {
673674
pgp: pgp::supported(),
@@ -707,10 +708,10 @@ fn configure(opts: Options) -> Cargo {
707708
c
708709
}
709710

710-
fn for_each_package(c: &Cargo, b: fn(s: @Source, p: Package)) {
711+
fn for_each_package(c: &Cargo, b: fn(s: @Source, p: &Package)) {
711712
for c.sources.each_value |v| {
712713
for v.packages.each |p| {
713-
b(v, *p);
714+
b(v, p);
714715
}
715716
}
716717
}
@@ -876,7 +877,7 @@ fn install_package(c: &Cargo, src: ~str, wd: &Path, pkg: Package) {
876877
match method {
877878
~"git" => install_git(c, wd, url, copy pkg.reference),
878879
~"file" => install_file(c, wd, &Path(url)),
879-
~"curl" => install_curl(c, wd, copy url),
880+
~"curl" => install_curl(c, wd, url),
880881
_ => ()
881882
}
882883
}
@@ -895,7 +896,7 @@ fn install_uuid(c: &Cargo, wd: &Path, uuid: ~str) {
895896
let mut ps = ~[];
896897
for_each_package(c, |s, p| {
897898
if p.uuid == uuid {
898-
vec::grow(ps, 1u, (s.name, copy p));
899+
vec::push(ps, (s.name, copy *p));
899900
}
900901
});
901902
if vec::len(ps) == 1u {
@@ -919,7 +920,7 @@ fn install_named(c: &Cargo, wd: &Path, name: ~str) {
919920
let mut ps = ~[];
920921
for_each_package(c, |s, p| {
921922
if p.name == name {
922-
vec::grow(ps, 1u, (s.name, copy p));
923+
vec::push(ps, (s.name, copy *p));
923924
}
924925
});
925926
if vec::len(ps) == 1u {
@@ -1477,7 +1478,7 @@ fn cmd_init(c: &Cargo) {
14771478
info(fmt!("initialized .cargo in %s", c.root.to_str()));
14781479
}
14791480

1480-
fn print_pkg(s: @Source, p: Package) {
1481+
fn print_pkg(s: @Source, p: &Package) {
14811482
let mut m = s.name + ~"/" + p.name + ~" (" + p.uuid + ~")";
14821483
if vec::len(p.tags) > 0u {
14831484
m = m + ~" [" + str::connect(p.tags, ~", ") + ~"]";
@@ -1572,7 +1573,7 @@ fn dump_cache(c: &Cargo) {
15721573
need_dir(&c.root);
15731574

15741575
let out = c.root.push("cache.json");
1575-
let _root = json::Dict(map::HashMap());
1576+
let _root = json::Object(~LinearMap());
15761577

15771578
if os::path_exists(&out) {
15781579
copy_warn(&out, &c.root.push("cache.json.old"));
@@ -1593,33 +1594,31 @@ fn dump_sources(c: &Cargo) {
15931594

15941595
match io::buffered_file_writer(&out) {
15951596
result::Ok(writer) => {
1596-
let hash = map::HashMap();
1597-
let root = json::Dict(hash);
1597+
let mut hash = ~LinearMap();
15981598

1599-
for c.sources.each |k, v| {
1600-
let chash = map::HashMap();
1601-
let child = json::Dict(chash);
1599+
for c.sources.each |k, v| {
1600+
let mut chash = ~LinearMap();
16021601

1603-
chash.insert(~"url", json::String(@v.url));
1604-
chash.insert(~"method", json::String(@v.method));
1602+
chash.insert(~"url", json::String(v.url));
1603+
chash.insert(~"method", json::String(v.method));
16051604

16061605
match copy v.key {
16071606
Some(key) => {
1608-
chash.insert(~"key", json::String(@key));
1607+
chash.insert(~"key", json::String(copy key));
16091608
}
16101609
_ => ()
16111610
}
16121611
match copy v.keyfp {
16131612
Some(keyfp) => {
1614-
chash.insert(~"keyfp", json::String(@keyfp));
1613+
chash.insert(~"keyfp", json::String(copy keyfp));
16151614
}
16161615
_ => ()
16171616
}
16181617

1619-
hash.insert(k, child);
1618+
hash.insert(copy k, json::Object(chash));
16201619
}
16211620

1622-
writer.write_str(json::to_str(root));
1621+
json::to_writer(writer, &json::Object(hash))
16231622
}
16241623
result::Err(e) => {
16251624
error(fmt!("could not dump sources: %s", e));

0 commit comments

Comments
 (0)