Skip to content

Commit 03d63ed

Browse files
committed
Debugging session for rust-lang#26.
1 parent 60881e9 commit 03d63ed

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/bin/cargo_semver.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ extern crate cargo;
55
extern crate crates_io;
66
extern crate env_logger;
77
extern crate getopts;
8+
#[macro_use]
9+
extern crate log;
810

911
use crates_io::{Crate, Registry};
1012

@@ -61,6 +63,8 @@ impl<'a> SourceInfo<'a> {
6163
let source_id = SourceId::crates_io(config)?;
6264
let source = source_id.load(config);
6365

66+
debug!("source id loaded: {:?}", source_id);
67+
6468
Ok(SourceInfo {
6569
id: source_id,
6670
source: source,
@@ -99,6 +103,7 @@ impl<'a> WorkInfo<'a> {
99103
// TODO: fall back to locally cached package instance, or better yet, search for it
100104
// first.
101105
let package_id = PackageId::new(info.name, info.version, &source.id)?;
106+
debug!("(remote) package id: {:?}", package_id);
102107
let package = source.source.download(&package_id)?;
103108
let workspace = Workspace::ephemeral(package.clone(), config, None, false)?;
104109

@@ -130,7 +135,7 @@ impl<'a> WorkInfo<'a> {
130135
/// and/or defaults, and dispatch the actual analysis.
131136
// TODO: possibly reduce the complexity by finding where some info can be taken from directly
132137
fn do_main(config: &Config, matches: &Matches) -> CargoResult<()> {
133-
fn parse_arg(opt: &str) -> CargoResult<(&str, &str)> {
138+
fn parse_arg(opt: &str) -> CargoResult<NameAndVersion> {
134139
let mut split = opt.split('-');
135140
let name = if let Some(n) = split.next() {
136141
n
@@ -147,29 +152,26 @@ fn do_main(config: &Config, matches: &Matches) -> CargoResult<()> {
147152
return Err("spec has to be of form `name-version`".into());
148153
}
149154

150-
Ok((name, version))
155+
Ok(NameAndVersion { name: name, version: version })
151156
}
152157

153158
let mut source = SourceInfo::new(config)?;
154159

155160
let current = if let Some(opt) = matches.opt_str("C") {
156-
let (name, version) = parse_arg(&opt)?;
157-
158-
let info = NameAndVersion { name: name, version: version };
159-
WorkInfo::remote(config, &mut source, info)?
161+
WorkInfo::remote(config, &mut source, parse_arg(&opt)?)?
160162
} else {
161163
WorkInfo::local(config, matches.opt_str("c").map(PathBuf::from))?
162164
};
163165

164166
let name = current.package.name().to_owned();
165167

166168
let (stable, stable_version) = if let Some(opt) = matches.opt_str("S") {
167-
let (name, version) = parse_arg(&opt)?;
169+
let info = parse_arg(&opt)?;
170+
let version = info.version.to_owned();
168171

169-
let info = NameAndVersion { name: name, version: version };
170172
let work_info = WorkInfo::remote(config, &mut source, info)?;
171173

172-
(work_info, version.to_owned())
174+
(work_info, version)
173175
} else if let Some(path) = matches.opt_str("s") {
174176
let work_info = WorkInfo::local(config, Some(PathBuf::from(path)))?;
175177
let version = format!("{}", work_info.package.version());

0 commit comments

Comments
 (0)