Even though it could work, it's too complicated.
Unified · Split
| @@ -37,10 +37,10 @@ pub struct Outcome { · 36 unmodified lines | ||
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | impl ChangeLog { |
| 40 | − pub fn for_package_with_write_lock<'a>( | |
| 41 | − package: &'a Package, | |
| 40 | + pub fn for_package_with_write_lock<'meta>( | |
| 41 | + package: &'meta Package, | |
| 42 | 42 | history: &commit::History, |
| 43 | − ctx: &'a crate::Context, | |
| 43 | + ctx: &crate::git::ContextRef<'meta, '_>, | |
| 44 | 44 | selection: segment::Selection, |
| 45 | 45 | ) -> anyhow::Result<Outcome> { |
| 46 | 46 | let mut generated = ChangeLog::from_history_segments( |
| @@ -85,12 +85,12 @@ impl ChangeLog { · 38 unmodified lines | ||
| 85 | 85 | }) |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | − pub fn for_crate_by_name_with_write_lock<'a>( | |
| 89 | − package: &'a Package, | |
| 88 | + pub fn for_crate_by_name_with_write_lock<'meta>( | |
| 89 | + package: &'meta Package, | |
| 90 | 90 | history: &commit::History, |
| 91 | − ctx: &'a crate::Context, | |
| 91 | + ctx: &crate::git::ContextRef<'meta, '_>, | |
| 92 | 92 | selection: segment::Selection, |
| 93 | − ) -> anyhow::Result<(Outcome, &'a Package)> { | |
| 93 | + ) -> anyhow::Result<(Outcome, &'meta Package)> { | |
| 94 | 94 | let out = Self::for_package_with_write_lock(package, history, ctx, selection)?; |
| 95 | 95 | Ok((out, package)) |
| 96 | 96 | } |
| @@ -25,14 +25,17 @@ pub fn changelog(opts: Options, crates: Vec<String>) -> anyhow::Result<()> { · 24 unmodified lines | ||
| 25 | 25 | let ctx = crate::Context::new(crates.clone(), force_history_segmentation, bump_spec, bump_spec)?; |
| 26 | 26 | let crates: Vec<_> = { |
| 27 | 27 | let add_production_crates = true; |
| 28 | − let bump_only_when_needed = true; | |
| 28 | + let bump_when_needed = true; | |
| 29 | 29 | let isolate_dependencies_from_breaking_changes = true; |
| 30 | 30 | crate::traverse::dependencies( |
| 31 | 31 | &ctx, |
| 32 | − add_production_crates, | |
| 33 | − bump_only_when_needed, | |
| 34 | − isolate_dependencies_from_breaking_changes, | |
| 35 | − dependencies, | |
| 32 | + &ctx.meta, | |
| 33 | + crate::traverse::Options { | |
| 34 | + add_production_crates, | |
| 35 | + bump_when_needed, | |
| 36 | + isolate_dependencies_from_breaking_changes, | |
| 37 | + traverse_graph: dependencies, | |
| 38 | + }, | |
| 36 | 39 | )? |
| 37 | 40 | .into_iter() |
| 38 | 41 | .filter_map(|d| match d.mode { |
| @@ -1,7 +1,9 @@ | ||
| 1 | 1 | use std::collections::BTreeMap; |
| 2 | 2 | |
| 3 | 3 | use anyhow::bail; |
| 4 | +use cargo_metadata::Metadata; | |
| 4 | 5 | |
| 6 | +use crate::traverse::Dependency; | |
| 5 | 7 | use crate::{ |
| 6 | 8 | changelog, |
| 7 | 9 | changelog::{write::Linkables, Section}, |
| @@ -83,33 +85,49 @@ pub fn release(opts: Options, crates: Vec<String>, bump: BumpSpec, bump_dependen · 75 unmodified lines | ||
| 83 | 85 | Ok(()) |
| 84 | 86 | } |
| 85 | 87 | |
| 86 | −fn release_depth_first(ctx: Context, options: Options) -> anyhow::Result<()> { | |
| 87 | − let Options { | |
| 88 | − bump_when_needed, | |
| 89 | − dry_run, | |
| 90 | − allow_auto_publish_of_stable_crates, | |
| 91 | − dependencies: traverse_dependencies, | |
| 92 | − verbose, | |
| 93 | − isolate_dependencies_from_breaking_changes, | |
| 94 | − .. | |
| 95 | − } = options; | |
| 88 | +impl From<Options> for crate::traverse::Options { | |
| 89 | + fn from(opts: Options) -> Self { | |
| 90 | + Self { | |
| 91 | + add_production_crates: opts.allow_auto_publish_of_stable_crates, | |
| 92 | + bump_when_needed: opts.bump_when_needed, | |
| 93 | + isolate_dependencies_from_breaking_changes: opts.isolate_dependencies_from_breaking_changes, | |
| 94 | + traverse_graph: opts.dependencies, | |
| 95 | + } | |
| 96 | + } | |
| 97 | +} | |
| 98 | + | |
| 99 | +fn release_depth_first(mut ctx: Context, opts: Options) -> anyhow::Result<()> { | |
| 100 | + let Options { verbose, dry_run, .. } = opts; | |
| 96 | 101 | let crates = { |
| 97 | − crate::traverse::dependencies( | |
| 98 | − &ctx.base, | |
| 99 | − allow_auto_publish_of_stable_crates, | |
| 100 | − bump_when_needed, | |
| 101 | − isolate_dependencies_from_breaking_changes, | |
| 102 | − traverse_dependencies, | |
| 103 | − ) | |
| 104 | − .and_then(|deps| present_and_validate_dependencies(&deps, &ctx, verbose, dry_run).map(|_| deps))? | |
| 102 | + crate::traverse::dependencies((&ctx.base).into(), opts.into()) | |
| 103 | + .and_then(|crates| assure_crates_index_is_uptodate(crates, &mut ctx.base, opts.into())) | |
| 104 | + .and_then(|crates| present_and_validate_dependencies(&crates, &ctx, verbose, dry_run).map(|_| crates))? | |
| 105 | 105 | }; |
| 106 | 106 | |
| 107 | − assure_working_tree_is_unchanged(options)?; | |
| 108 | − perform_release(&ctx, options, &crates)?; | |
| 107 | + assure_working_tree_is_unchanged(opts)?; | |
| 108 | + perform_release(&ctx, opts, &crates)?; | |
| 109 | 109 | |
| 110 | 110 | Ok(()) |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | +fn assure_crates_index_is_uptodate<'meta>( | |
| 114 | + crates: Vec<Dependency<'meta>>, | |
| 115 | + ctx: &mut crate::Context, | |
| 116 | + opts: crate::traverse::Options, | |
| 117 | +) -> anyhow::Result<Vec<Dependency<'meta>>> { | |
| 118 | + if let Some(dep) = crates | |
| 119 | + .iter() | |
| 120 | + .filter_map(|d| d.mode.version_adjustment_bump().map(|b| (d, b))) | |
| 121 | + .find_map(|(d, b)| (b.next_release <= d.package.version).then(|| d)) | |
| 122 | + { | |
| 123 | + log::warn!("Crate '{}' computed version not greater than the current package version. Updating crates index to assure correct results", dep.package.name); | |
| 124 | + ctx.crates_index.update()?; | |
| 125 | + crate::traverse::dependencies((&ctx.base).into(), opts) | |
| 126 | + } else { | |
| 127 | + Ok(crates) | |
| 128 | + } | |
| 129 | +} | |
| 130 | + | |
| 113 | 131 | fn present_and_validate_dependencies( |
| 114 | 132 | crates: &[traverse::Dependency<'_>], |
| 115 | 133 | ctx: &Context, |
| @@ -6,7 +6,8 @@ use std::{ · 5 unmodified lines | ||
| 6 | 6 | }; |
| 7 | 7 | |
| 8 | 8 | use anyhow::bail; |
| 9 | −use cargo_metadata::Package; | |
| 9 | +use cargo_metadata::camino::Utf8Path; | |
| 10 | +use cargo_metadata::{Metadata, Package}; | |
| 10 | 11 | use git_repository as git; |
| 11 | 12 | use git_repository::{ |
| 12 | 13 | bstr::ByteSlice, |
| @@ -14,12 +15,12 @@ use git_repository::{ · 1 unmodified line | ||
| 14 | 15 | prelude::{CacheAccessExt, ObjectAccessExt, ObjectIdExt, ReferenceAccessExt, ReferenceExt}, |
| 15 | 16 | }; |
| 16 | 17 | |
| 18 | +use crate::git::ContextRef; | |
| 17 | 19 | use crate::{ |
| 18 | 20 | commit, |
| 19 | 21 | commit::history::{Item, Segment}, |
| 20 | 22 | git::strip_tag_path, |
| 21 | 23 | utils::{component_to_bytes, is_tag_name, is_tag_version, tag_prefix}, |
| 22 | − Context, | |
| 23 | 24 | }; |
| 24 | 25 | |
| 25 | 26 | pub enum SegmentScope { |
| @@ -99,7 +100,7 @@ pub fn collect(repo: &git::Easy) -> anyhow::Result<Option<commit::History>> { · 73 unmodified lines | ||
| 99 | 100 | /// Return the head reference followed by all tags affecting `crate_name` as per our tag name rules, ordered by ancestry. |
| 100 | 101 | pub fn crate_ref_segments<'h>( |
| 101 | 102 | package: &Package, |
| 102 | − ctx: &crate::Context, | |
| 103 | + ctx: &ContextRef<'_, '_>, | |
| 103 | 104 | history: &'h commit::History, |
| 104 | 105 | scope: SegmentScope, |
| 105 | 106 | ) -> anyhow::Result<Vec<commit::history::Segment<'h>>> { |
| @@ -206,7 +207,7 @@ enum Filter<'a> { · 100 unmodified lines | ||
| 206 | 207 | } |
| 207 | 208 | |
| 208 | 209 | fn add_item_if_package_changed<'a>( |
| 209 | − ctx: &Context, | |
| 210 | + ctx: &ContextRef<'_, '_>, | |
| 210 | 211 | segment: &mut Segment<'a>, |
| 211 | 212 | filter: &Filter<'_>, |
| 212 | 213 | item: &'a Item, |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | use std::{convert::TryInto, process::Command}; |
| 2 | 2 | |
| 3 | 3 | use anyhow::{anyhow, bail}; |
| 4 | −use cargo_metadata::{camino::Utf8Path, Package}; | |
| 4 | +use cargo_metadata::{camino::Utf8Path, Metadata, Package}; | |
| 5 | 5 | use git_repository as git; |
| 6 | 6 | use git_repository::{ |
| 7 | 7 | bstr::{BStr, ByteSlice}, |
| @@ -14,13 +14,49 @@ use crate::utils::{component_to_bytes, tag_name}; · 6 unmodified lines | ||
| 14 | 14 | |
| 15 | 15 | pub mod history; |
| 16 | 16 | |
| 17 | +pub struct ContextRef<'meta, 'a> { | |
| 18 | + pub meta: &'meta Metadata, | |
| 19 | + pub repo: &'a git::Easy, | |
| 20 | + pub root: &'a Utf8Path, | |
| 21 | +} | |
| 22 | + | |
| 23 | +impl<'meta, 'a> From<&crate::Context> for ContextRef<'meta, 'a> { | |
| 24 | + fn from(v: &crate::Context) -> Self { | |
| 25 | + Self { | |
| 26 | + meta: &v.meta, | |
| 27 | + repo: &v.repo, | |
| 28 | + root: &v.root, | |
| 29 | + } | |
| 30 | + } | |
| 31 | +} | |
| 32 | + | |
| 33 | +impl<'meta, 'a> ContextRef<'meta, 'a> { | |
| 34 | + pub(crate) fn repo_relative_path<'b>(&self, p: &'b Package) -> Option<&'b Utf8Path> { | |
| 35 | + let dir = p | |
| 36 | + .manifest_path | |
| 37 | + .parent() | |
| 38 | + .expect("parent of a file is always present") | |
| 39 | + .strip_prefix(&self.root) | |
| 40 | + .expect("workspace members are releative to the root directory"); | |
| 41 | + | |
| 42 | + if dir.as_os_str().is_empty() { | |
| 43 | + None | |
| 44 | + } else { | |
| 45 | + dir.into() | |
| 46 | + } | |
| 47 | + } | |
| 48 | +} | |
| 49 | + | |
| 17 | 50 | #[derive(Clone, Debug)] |
| 18 | 51 | pub enum PackageChangeKind { |
| 19 | 52 | Untagged { wanted_tag_name: String }, |
| 20 | 53 | ChangedOrNew, |
| 21 | 54 | } |
| 22 | 55 | |
| 23 | −pub fn change_since_last_release(package: &Package, ctx: &crate::Context) -> anyhow::Result<Option<PackageChangeKind>> { | |
| 56 | +pub fn change_since_last_release( | |
| 57 | + package: &Package, | |
| 58 | + ctx: &ContextRef<'_, '_>, | |
| 59 | +) -> anyhow::Result<Option<PackageChangeKind>> { | |
| 24 | 60 | let version_tag_name = tag_name(package, &package.version, &ctx.repo); |
| 25 | 61 | let mut tag_ref = match ctx.repo.try_find_reference(&version_tag_name)? { |
| 26 | 62 | None => { |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | use std::collections::BTreeSet; |
| 2 | 2 | |
| 3 | −use cargo_metadata::{DependencyKind, Package, PackageId}; | |
| 3 | +use cargo_metadata::{DependencyKind, Metadata, Package, PackageId}; | |
| 4 | 4 | |
| 5 | 5 | use crate::{ |
| 6 | 6 | git, |
| @@ -127,6 +127,31 @@ pub mod dependency { · 120 unmodified lines | ||
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | +pub struct Options { | |
| 131 | + pub add_production_crates: bool, | |
| 132 | + pub bump_when_needed: bool, | |
| 133 | + pub isolate_dependencies_from_breaking_changes: bool, | |
| 134 | + pub traverse_graph: bool, | |
| 135 | +} | |
| 136 | + | |
| 137 | +pub struct ContextRef<'meta, 'a> { | |
| 138 | + meta: &'meta Metadata, | |
| 139 | + crate_names: &'a [String], | |
| 140 | + git: crate::git::ContextRef<'meta, 'a>, | |
| 141 | + version: crate::version::ContextRef<'a>, | |
| 142 | +} | |
| 143 | + | |
| 144 | +impl<'meta, 'a> From<&crate::Context> for ContextRef<'meta, 'a> { | |
| 145 | + fn from(v: &Context) -> Self { | |
| 146 | + Self { | |
| 147 | + meta: &v.meta, | |
| 148 | + crate_names: &v.crate_names, | |
| 149 | + git: v.into(), | |
| 150 | + version: v.into(), | |
| 151 | + } | |
| 152 | + } | |
| 153 | +} | |
| 154 | + | |
| 130 | 155 | #[derive(Clone, Debug)] |
| 131 | 156 | pub struct Dependency<'meta> { |
| 132 | 157 | pub package: &'meta Package, |
| @@ -134,13 +159,15 @@ pub struct Dependency<'meta> { · 1 unmodified line | ||
| 134 | 159 | pub mode: dependency::Mode, |
| 135 | 160 | } |
| 136 | 161 | |
| 137 | −pub fn dependencies( | |
| 138 | − ctx: &crate::Context, | |
| 139 | − allow_auto_publish_of_stable_crates: bool, | |
| 140 | − bump_when_needed: bool, | |
| 141 | − isolate_dependencies_from_breaking_changes: bool, | |
| 142 | − traverse_graph: bool, | |
| 143 | −) -> anyhow::Result<Vec<Dependency<'_>>> { | |
| 162 | +pub fn dependencies<'meta>( | |
| 163 | + ctx: &ContextRef<'meta, '_>, | |
| 164 | + Options { | |
| 165 | + add_production_crates, | |
| 166 | + bump_when_needed, | |
| 167 | + isolate_dependencies_from_breaking_changes, | |
| 168 | + traverse_graph, | |
| 169 | + }: Options, | |
| 170 | +) -> anyhow::Result<Vec<Dependency<'meta>>> { | |
| 144 | 171 | let mut seen = BTreeSet::new(); |
| 145 | 172 | let mut crates = Vec::new(); |
| 146 | 173 | for crate_name in &ctx.crate_names { |
| @@ -155,12 +182,12 @@ pub fn dependencies( · 8 unmodified lines | ||
| 155 | 182 | &mut seen, |
| 156 | 183 | &mut crates_this_round, |
| 157 | 184 | package, |
| 158 | − allow_auto_publish_of_stable_crates, | |
| 185 | + add_production_crates, | |
| 159 | 186 | bump_when_needed, |
| 160 | 187 | )?; |
| 161 | 188 | } |
| 162 | 189 | |
| 163 | − match git::change_since_last_release(package, ctx)? { | |
| 190 | + match git::change_since_last_release(package, &ctx.git)? { | |
| 164 | 191 | Some(user_package_change) => { |
| 165 | 192 | crates_this_round.push(Dependency { |
| 166 | 193 | package, |
| @@ -169,7 +196,7 @@ pub fn dependencies( · 2 unmodified lines | ||
| 169 | 196 | dependency::Mode::ToBePublished { |
| 170 | 197 | adjustment: VersionAdjustment::Changed { |
| 171 | 198 | change: user_package_change, |
| 172 | − bump: version::bump_package(package, ctx, bump_when_needed)?, | |
| 199 | + bump: version::bump_package(package, &ctx.version, bump_when_needed)?, | |
| 173 | 200 | }, |
| 174 | 201 | } |
| 175 | 202 | } else { |
| @@ -196,17 +223,12 @@ pub fn dependencies( · 20 unmodified lines | ||
| 196 | 223 | } |
| 197 | 224 | |
| 198 | 225 | if isolate_dependencies_from_breaking_changes { |
| 199 | − forward_propagate_breaking_changes_for_publishing( | |
| 200 | − ctx, | |
| 201 | − &mut crates, | |
| 202 | − bump_when_needed, | |
| 203 | − allow_auto_publish_of_stable_crates, | |
| 204 | − )?; | |
| 226 | + forward_propagate_breaking_changes_for_publishing(ctx, &mut crates, bump_when_needed, add_production_crates)?; | |
| 205 | 227 | forward_propagate_breaking_changes_for_manifest_updates( |
| 206 | 228 | ctx, |
| 207 | 229 | &mut crates, |
| 208 | 230 | bump_when_needed, |
| 209 | − allow_auto_publish_of_stable_crates, | |
| 231 | + add_production_crates, | |
| 210 | 232 | )?; |
| 211 | 233 | } |
| 212 | 234 | crates.extend(find_workspace_crates_depending_on_adjusted_crates(ctx, &crates)); |
| @@ -226,7 +248,7 @@ fn merge_crates<'meta>(dest: &mut Vec<Dependency<'meta>>, src: Vec<Dependency<'m · 13 unmodified lines | ||
| 226 | 248 | } |
| 227 | 249 | |
| 228 | 250 | fn forward_propagate_breaking_changes_for_manifest_updates<'meta>( |
| 229 | − ctx: &'meta Context, | |
| 251 | + ctx: &ContextRef<'meta, '_>, | |
| 230 | 252 | crates: &mut Vec<Dependency<'meta>>, |
| 231 | 253 | bump_when_needed: bool, |
| 232 | 254 | allow_auto_publish_of_stable_crates: bool, |
| @@ -323,9 +345,9 @@ fn package_may_be_published(p: &Package) -> bool { · 90 unmodified lines | ||
| 323 | 345 | p.publish.is_none() |
| 324 | 346 | } |
| 325 | 347 | |
| 326 | −fn forward_propagate_breaking_changes_for_publishing( | |
| 327 | − ctx: &Context, | |
| 328 | − mut crates: &mut Vec<Dependency<'_>>, | |
| 348 | +fn forward_propagate_breaking_changes_for_publishing<'meta>( | |
| 349 | + ctx: &ContextRef<'meta, '_>, | |
| 350 | + mut crates: &mut Vec<Dependency<'meta>>, | |
| 329 | 351 | bump_when_needed: bool, |
| 330 | 352 | allow_auto_publish_of_stable_crates: bool, |
| 331 | 353 | ) -> anyhow::Result<()> { |
| @@ -378,7 +400,7 @@ impl EditForPublish { · 46 unmodified lines | ||
| 378 | 400 | fn apply( |
| 379 | 401 | self, |
| 380 | 402 | crates: &mut [Dependency<'_>], |
| 381 | − ctx: &Context, | |
| 403 | + ctx: &ContextRef<'_, '_>, | |
| 382 | 404 | bump_when_needed: bool, |
| 383 | 405 | allow_auto_publish_of_stable_crates: bool, |
| 384 | 406 | ) -> anyhow::Result<()> { |
| @@ -425,11 +447,11 @@ impl EditForPublish { · 40 unmodified lines | ||
| 425 | 447 | } |
| 426 | 448 | } |
| 427 | 449 | |
| 428 | −fn breaking_version_bump(ctx: &Context, package: &Package, bump_when_needed: bool) -> anyhow::Result<Bump> { | |
| 450 | +fn breaking_version_bump(ctx: &ContextRef<'_, '_>, package: &Package, bump_when_needed: bool) -> anyhow::Result<Bump> { | |
| 429 | 451 | let breaking_spec = is_pre_release_version(&package.version) |
| 430 | 452 | .then(|| BumpSpec::Minor) |
| 431 | 453 | .unwrap_or(BumpSpec::Major); |
| 432 | − version::bump_package_with_spec(package, breaking_spec, ctx, bump_when_needed) | |
| 454 | + version::bump_package_with_spec(package, breaking_spec, &ctx.version, bump_when_needed) | |
| 433 | 455 | } |
| 434 | 456 | |
| 435 | 457 | fn make_breaking(adjustment: &mut VersionAdjustment, breaking_bump: version::Bump, breaking_crate_names: Vec<String>) { |
| @@ -493,7 +515,7 @@ fn find_safety_bump_edits_backwards_from_crates_for_publish( · 57 unmodified lines | ||
| 493 | 515 | } |
| 494 | 516 | |
| 495 | 517 | fn depth_first_traversal<'meta>( |
| 496 | − ctx: &'meta crate::Context, | |
| 518 | + ctx: &ContextRef<'_, 'meta>, | |
| 497 | 519 | seen: &mut BTreeSet<&'meta PackageId>, |
| 498 | 520 | crates: &mut Vec<Dependency<'meta>>, |
| 499 | 521 | root: &Package, |
| @@ -519,7 +541,7 @@ fn depth_first_traversal<'meta>( · 19 unmodified lines | ||
| 519 | 541 | bump_when_needed, |
| 520 | 542 | )?; |
| 521 | 543 | |
| 522 | − crates.push(match git::change_since_last_release(workspace_dependency, ctx)? { | |
| 544 | + crates.push(match git::change_since_last_release(workspace_dependency, &ctx.git)? { | |
| 523 | 545 | Some(change) => { |
| 524 | 546 | if is_pre_release_version(&workspace_dependency.version) || allow_auto_publish_of_stable_crates { |
| 525 | 547 | Dependency { |
| @@ -528,7 +550,7 @@ fn depth_first_traversal<'meta>( · 2 unmodified lines | ||
| 528 | 550 | mode: dependency::Mode::ToBePublished { |
| 529 | 551 | adjustment: VersionAdjustment::Changed { |
| 530 | 552 | change, |
| 531 | − bump: version::bump_package(workspace_dependency, ctx, bump_when_needed)?, | |
| 553 | + bump: version::bump_package(workspace_dependency, &ctx.version, bump_when_needed)?, | |
| 532 | 554 | }, |
| 533 | 555 | }, |
| 534 | 556 | } |
| @@ -557,7 +579,7 @@ fn depth_first_traversal<'meta>( · 22 unmodified lines | ||
| 557 | 579 | } |
| 558 | 580 | |
| 559 | 581 | fn find_workspace_crates_depending_on_adjusted_crates<'meta>( |
| 560 | − ctx: &'meta Context, | |
| 582 | + ctx: &ContextRef<'meta, '_>, | |
| 561 | 583 | crates: &[Dependency<'_>], |
| 562 | 584 | ) -> Vec<Dependency<'meta>> { |
| 563 | 585 | ctx.meta |
| @@ -1,7 +1,28 @@ | ||
| 1 | +use cargo_metadata::camino::Utf8Path; | |
| 1 | 2 | use cargo_metadata::Package; |
| 2 | 3 | use semver::{Prerelease, Version}; |
| 3 | 4 | |
| 4 | −use crate::Context; | |
| 5 | +pub struct ContextRef<'a> { | |
| 6 | + pub crate_names: &'a [String], | |
| 7 | + pub root: &'a Utf8Path, | |
| 8 | + pub crates_index: &'a crates_index::Index, | |
| 9 | + pub history: Option<&'a crate::commit::History>, | |
| 10 | + pub bump: BumpSpec, | |
| 11 | + pub bump_dependencies: BumpSpec, | |
| 12 | +} | |
| 13 | + | |
| 14 | +impl<'a> From<&crate::Context> for ContextRef<'a> { | |
| 15 | + fn from(v: &crate::Context) -> Self { | |
| 16 | + Self { | |
| 17 | + crate_names: &v.crate_names, | |
| 18 | + root: &v.root, | |
| 19 | + crates_index: &v.crates_index, | |
| 20 | + history: v.history.as_ref(), | |
| 21 | + bump: v.bump, | |
| 22 | + bump_dependencies: v.bump_dependencies, | |
| 23 | + } | |
| 24 | + } | |
| 25 | +} | |
| 5 | 26 | |
| 6 | 27 | #[derive(Copy, Clone)] |
| 7 | 28 | pub enum BumpSpec { |
| @@ -25,7 +46,7 @@ impl std::fmt::Display for BumpSpec { · 17 unmodified lines | ||
| 25 | 46 | } |
| 26 | 47 | |
| 27 | 48 | #[allow(clippy::ptr_arg)] |
| 28 | −pub(crate) fn select_publishee_bump_spec(name: &String, ctx: &Context) -> BumpSpec { | |
| 49 | +pub(crate) fn select_publishee_bump_spec(name: &String, ctx: &ContextRef<'_>) -> BumpSpec { | |
| 29 | 50 | if ctx.crate_names.contains(name) { |
| 30 | 51 | ctx.bump |
| 31 | 52 | } else { |
| @@ -79,7 +100,7 @@ impl Bump { · 47 unmodified lines | ||
| 79 | 100 | pub(crate) fn bump_package_with_spec( |
| 80 | 101 | package: &Package, |
| 81 | 102 | bump_spec: BumpSpec, |
| 82 | − ctx: &Context, | |
| 103 | + ctx: &ContextRef<'_>, | |
| 83 | 104 | bump_when_needed: bool, |
| 84 | 105 | ) -> anyhow::Result<Bump> { |
| 85 | 106 | let mut v = package.version.clone(); |
| @@ -168,7 +189,7 @@ pub(crate) fn bump_package_with_spec( · 82 unmodified lines | ||
| 168 | 189 | }) |
| 169 | 190 | } |
| 170 | 191 | |
| 171 | −pub(crate) fn bump_package(package: &Package, ctx: &Context, bump_when_needed: bool) -> anyhow::Result<Bump> { | |
| 192 | +pub(crate) fn bump_package(package: &Package, ctx: &ContextRef<'_>, bump_when_needed: bool) -> anyhow::Result<Bump> { | |
| 172 | 193 | let bump_spec = select_publishee_bump_spec(&package.name, ctx); |
| 173 | 194 | bump_package_with_spec(package, bump_spec, ctx, bump_when_needed) |
| 174 | 195 | } |