|
13 | 13 | use crate::core::compiler::{CompileKind, RustcTargetData};
|
14 | 14 | use crate::core::registry::PackageRegistry;
|
15 | 15 | use crate::core::resolver::features::{FeatureResolver, ForceAllTargets, ResolvedFeatures};
|
16 |
| -use crate::core::resolver::{self, HasDevUnits, Resolve, ResolveOpts}; |
| 16 | +use crate::core::resolver::{self, HasDevUnits, Resolve, ResolveOpts, ResolveVersion}; |
17 | 17 | use crate::core::summary::Summary;
|
18 | 18 | use crate::core::Feature;
|
19 |
| -use crate::core::{PackageId, PackageIdSpec, PackageSet, Source, SourceId, Workspace}; |
| 19 | +use crate::core::{ |
| 20 | + GitReference, PackageId, PackageIdSpec, PackageSet, Source, SourceId, Workspace, |
| 21 | +}; |
20 | 22 | use crate::ops;
|
21 | 23 | use crate::sources::PathSource;
|
22 | 24 | use crate::util::errors::{CargoResult, CargoResultExt};
|
@@ -597,7 +599,31 @@ fn register_previous_locks(
|
597 | 599 | .deps_not_replaced(node)
|
598 | 600 | .map(|p| p.0)
|
599 | 601 | .filter(keep)
|
600 |
| - .collect(); |
| 602 | + .collect::<Vec<_>>(); |
| 603 | + |
| 604 | + // In the v2 lockfile format and prior the `branch=master` dependency |
| 605 | + // directive was serialized the same way as the no-branch-listed |
| 606 | + // directive. Nowadays in Cargo, however, these two directives are |
| 607 | + // considered distinct and are no longer represented the same way. To |
| 608 | + // maintain compatibility with older lock files we register locked nodes |
| 609 | + // for *both* the master branch and the default branch. |
| 610 | + // |
| 611 | + // Note that this is only applicable for loading older resolves now at |
| 612 | + // this point. All new lock files are encoded as v3-or-later, so this is |
| 613 | + // just compat for loading an old lock file successfully. |
| 614 | + if resolve.version() <= ResolveVersion::V2 { |
| 615 | + let source = node.source_id(); |
| 616 | + if let Some(GitReference::DefaultBranch) = source.git_reference() { |
| 617 | + let new_source = |
| 618 | + SourceId::for_git(source.url(), GitReference::Branch("master".to_string())) |
| 619 | + .unwrap() |
| 620 | + .with_precise(source.precise().map(|s| s.to_string())); |
| 621 | + |
| 622 | + let node = node.with_source_id(new_source); |
| 623 | + registry.register_lock(node, deps.clone()); |
| 624 | + } |
| 625 | + } |
| 626 | + |
601 | 627 | registry.register_lock(node, deps);
|
602 | 628 | }
|
603 | 629 |
|
|
0 commit comments