Skip to content

Commit

Permalink
Simplify git_package/pkg handling
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion committed May 2, 2020
1 parent d2b2775 commit 9d1c6a7
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,14 @@ fn install_one(
}
};

let git_package = if source_id.is_git() {
Some(pkg.clone())
let (mut ws, rustc, target) = make_ws_rustc_target(config, opts, &source_id, pkg.clone())?;
let pkg = if source_id.is_git() {
// Don't use ws.current() in order to keep the package source as a git source so that
// install tracking uses the correct source.
pkg
} else {
None
ws.current()?.clone()
};
let (mut ws, rustc, target) = make_ws_rustc_target(config, opts, &source_id, pkg)?;

let mut td_opt = None;
let mut needs_cleanup = false;
Expand All @@ -286,10 +288,6 @@ fn install_one(
ws.set_target_dir(target_dir);
}

let pkg = git_package
.as_ref()
.map_or_else(|| ws.current(), |pkg| Ok(pkg))?;

if from_cwd {
if pkg.manifest().edition() == Edition::Edition2015 {
config.shell().warn(
Expand Down Expand Up @@ -317,7 +315,7 @@ fn install_one(

// Helper for --no-track flag to make sure it doesn't overwrite anything.
let no_track_duplicates = || -> CargoResult<BTreeMap<String, Option<PackageId>>> {
let duplicates: BTreeMap<String, Option<PackageId>> = exe_names(pkg, &opts.filter)
let duplicates: BTreeMap<String, Option<PackageId>> = exe_names(&pkg, &opts.filter)
.into_iter()
.filter(|name| dst.join(name).exists())
.map(|name| (name, None))
Expand Down Expand Up @@ -349,7 +347,7 @@ fn install_one(
}
}

config.shell().status("Installing", pkg)?;
config.shell().status("Installing", &pkg)?;

check_yanked_install(&ws)?;

Expand Down Expand Up @@ -390,7 +388,7 @@ fn install_one(
} else {
let tracker = InstallTracker::load(config, root)?;
let (_freshness, duplicates) =
tracker.check_upgrade(&dst, pkg, force, opts, &target, &rustc.verbose_version)?;
tracker.check_upgrade(&dst, &pkg, force, opts, &target, &rustc.verbose_version)?;
(Some(tracker), duplicates)
};

Expand Down Expand Up @@ -453,15 +451,15 @@ fn install_one(

if let Some(mut tracker) = tracker {
tracker.mark_installed(
pkg,
&pkg,
&successful_bins,
vers.map(|s| s.to_string()),
opts,
&target,
&rustc.verbose_version,
);

if let Err(e) = remove_orphaned_bins(&ws, &mut tracker, &duplicates, pkg, &dst) {
if let Err(e) = remove_orphaned_bins(&ws, &mut tracker, &duplicates, &pkg, &dst) {
// Don't hard error on remove.
config
.shell()
Expand Down Expand Up @@ -588,11 +586,7 @@ fn make_ws_rustc_target<'cfg>(
source_id: &SourceId,
pkg: Package,
) -> CargoResult<(Workspace<'cfg>, Rustc, String)> {
let mut ws = if source_id.is_git() {
// Don't use ws.current() in order to keep the package source as a git source so that
// install tracking uses the correct source.
Workspace::new(pkg.manifest_path(), config)?
} else if source_id.is_path() {
let mut ws = if source_id.is_git() || source_id.is_path() {
Workspace::new(pkg.manifest_path(), config)?
} else {
Workspace::ephemeral(pkg, config, None, false)?
Expand Down

0 comments on commit 9d1c6a7

Please sign in to comment.