Skip to content

Commit 9d1c6a7

Browse files
committed
Simplify git_package/pkg handling
1 parent d2b2775 commit 9d1c6a7

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

src/cargo/ops/cargo_install.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,14 @@ fn install_one(
263263
}
264264
};
265265

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

273275
let mut td_opt = None;
274276
let mut needs_cleanup = false;
@@ -286,10 +288,6 @@ fn install_one(
286288
ws.set_target_dir(target_dir);
287289
}
288290

289-
let pkg = git_package
290-
.as_ref()
291-
.map_or_else(|| ws.current(), |pkg| Ok(pkg))?;
292-
293291
if from_cwd {
294292
if pkg.manifest().edition() == Edition::Edition2015 {
295293
config.shell().warn(
@@ -317,7 +315,7 @@ fn install_one(
317315

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

352-
config.shell().status("Installing", pkg)?;
350+
config.shell().status("Installing", &pkg)?;
353351

354352
check_yanked_install(&ws)?;
355353

@@ -390,7 +388,7 @@ fn install_one(
390388
} else {
391389
let tracker = InstallTracker::load(config, root)?;
392390
let (_freshness, duplicates) =
393-
tracker.check_upgrade(&dst, pkg, force, opts, &target, &rustc.verbose_version)?;
391+
tracker.check_upgrade(&dst, &pkg, force, opts, &target, &rustc.verbose_version)?;
394392
(Some(tracker), duplicates)
395393
};
396394

@@ -453,15 +451,15 @@ fn install_one(
453451

454452
if let Some(mut tracker) = tracker {
455453
tracker.mark_installed(
456-
pkg,
454+
&pkg,
457455
&successful_bins,
458456
vers.map(|s| s.to_string()),
459457
opts,
460458
&target,
461459
&rustc.verbose_version,
462460
);
463461

464-
if let Err(e) = remove_orphaned_bins(&ws, &mut tracker, &duplicates, pkg, &dst) {
462+
if let Err(e) = remove_orphaned_bins(&ws, &mut tracker, &duplicates, &pkg, &dst) {
465463
// Don't hard error on remove.
466464
config
467465
.shell()
@@ -588,11 +586,7 @@ fn make_ws_rustc_target<'cfg>(
588586
source_id: &SourceId,
589587
pkg: Package,
590588
) -> CargoResult<(Workspace<'cfg>, Rustc, String)> {
591-
let mut ws = if source_id.is_git() {
592-
// Don't use ws.current() in order to keep the package source as a git source so that
593-
// install tracking uses the correct source.
594-
Workspace::new(pkg.manifest_path(), config)?
595-
} else if source_id.is_path() {
589+
let mut ws = if source_id.is_git() || source_id.is_path() {
596590
Workspace::new(pkg.manifest_path(), config)?
597591
} else {
598592
Workspace::ephemeral(pkg, config, None, false)?

0 commit comments

Comments
 (0)