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 | impl ChangeLog { | 39 | impl ChangeLog { |
| 40 | pub fn for_package_with_write_lock<'a>( | 40 | pub fn for_package_with_write_lock<'meta>( |
| 41 | package: &'a Package, | 41 | package: &'meta Package, |
| 42 | history: &commit::History, | 42 | history: &commit::History, |
| 43 | ctx: &'a crate::Context, | 43 | ctx: &crate::git::ContextRef<'meta, '_>, |
| 44 | selection: segment::Selection, | 44 | selection: segment::Selection, |
| 45 | ) -> anyhow::Result<Outcome> { | 45 | ) -> anyhow::Result<Outcome> { |
| 46 | let mut generated = ChangeLog::from_history_segments( | 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>( | 88 | pub fn for_crate_by_name_with_write_lock<'meta>( |
| 89 | package: &'a Package, | 89 | package: &'meta Package, |
| 90 | history: &commit::History, | 90 | history: &commit::History, |
| 91 | ctx: &'a crate::Context, | 91 | ctx: &crate::git::ContextRef<'meta, '_>, |
| 92 | selection: segment::Selection, | 92 | selection: segment::Selection, |
| 93 | ) -> anyhow::Result<(Outcome, &'a Package)> { | 93 | ) -> anyhow::Result<(Outcome, &'meta Package)> { |
| 94 | let out = Self::for_package_with_write_lock(package, history, ctx, selection)?; | 94 | let out = Self::for_package_with_write_lock(package, history, ctx, selection)?; |
| 95 | Ok((out, package)) | 95 | Ok((out, package)) |
| 96 | } | 96 | } |
| @@ -25,14 +25,17 @@ pub fn changelog(opts: Options, crates: Vec<String>) -> anyhow::Result<()> { · 24 unmodified lines | |||
| 25 | let ctx = crate::Context::new(crates.clone(), force_history_segmentation, bump_spec, bump_spec)?; | 25 | let ctx = crate::Context::new(crates.clone(), force_history_segmentation, bump_spec, bump_spec)?; |
| 26 | let crates: Vec<_> = { | 26 | let crates: Vec<_> = { |
| 27 | let add_production_crates = true; | 27 | let add_production_crates = true; |
| 28 | let bump_only_when_needed = true; | 28 | let bump_when_needed = true; |
| 29 | let isolate_dependencies_from_breaking_changes = true; | 29 | let isolate_dependencies_from_breaking_changes = true; |
| 30 | crate::traverse::dependencies( | 30 | crate::traverse::dependencies( |
| 31 | &ctx, | 31 | &ctx, |
| 32 | add_production_crates, | 32 | &ctx.meta, |
| 33 | bump_only_when_needed, | 33 | crate::traverse::Options { |
| 34 | isolate_dependencies_from_breaking_changes, | 34 | add_production_crates, |
| 35 | dependencies, | 35 | bump_when_needed, |
| 36 | isolate_dependencies_from_breaking_changes, | ||
| 37 | traverse_graph: dependencies, | ||
| 38 | }, | ||
| 36 | )? | 39 | )? |
| 37 | .into_iter() | 40 | .into_iter() |
| 38 | .filter_map(|d| match d.mode { | 41 | .filter_map(|d| match d.mode { |
| @@ -1,7 +1,9 @@ | |||
| 1 | use std::collections::BTreeMap; | 1 | use std::collections::BTreeMap; |
| 2 | 2 | ||
| 3 | use anyhow::bail; | 3 | use anyhow::bail; |
| 4 | use cargo_metadata::Metadata; | ||
| 4 | 5 | ||
| 6 | use crate::traverse::Dependency; | ||
| 5 | use crate::{ | 7 | use crate::{ |
| 6 | changelog, | 8 | changelog, |
| 7 | changelog::{write::Linkables, Section}, | 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 | Ok(()) | 85 | Ok(()) |
| 84 | } | 86 | } |
| 85 | 87 | ||
| 86 | fn release_depth_first(ctx: Context, options: Options) -> anyhow::Result<()> { | 88 | impl From<Options> for crate::traverse::Options { |
| 87 | let Options { | 89 | fn from(opts: Options) -> Self { |
| 88 | bump_when_needed, | 90 | Self { |
| 89 | dry_run, | 91 | add_production_crates: opts.allow_auto_publish_of_stable_crates, |
| 90 | allow_auto_publish_of_stable_crates, | 92 | bump_when_needed: opts.bump_when_needed, |
| 91 | dependencies: traverse_dependencies, | 93 | isolate_dependencies_from_breaking_changes: opts.isolate_dependencies_from_breaking_changes, |
| 92 | verbose, | 94 | traverse_graph: opts.dependencies, |
| 93 | isolate_dependencies_from_breaking_changes, | 95 | } |
| 94 | .. | 96 | } |
| 95 | } = options; | 97 | } |
| 98 | |||
| 99 | fn release_depth_first(mut ctx: Context, opts: Options) -> anyhow::Result<()> { | ||
| 100 | let Options { verbose, dry_run, .. } = opts; | ||
| 96 | let crates = { | 101 | let crates = { |
| 97 | crate::traverse::dependencies( | 102 | crate::traverse::dependencies((&ctx.base).into(), opts.into()) |
| 98 | &ctx.base, | 103 | .and_then(|crates| assure_crates_index_is_uptodate(crates, &mut ctx.base, opts.into())) |
| 99 | allow_auto_publish_of_stable_crates, | 104 | .and_then(|crates| present_and_validate_dependencies(&crates, &ctx, verbose, dry_run).map(|_| 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))? | ||
| 105 | }; | 105 | }; |
| 106 | 106 | ||
| 107 | assure_working_tree_is_unchanged(options)?; | 107 | assure_working_tree_is_unchanged(opts)?; |
| 108 | perform_release(&ctx, options, &crates)?; | 108 | perform_release(&ctx, opts, &crates)?; |
| 109 | 109 | ||
| 110 | Ok(()) | 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 | fn present_and_validate_dependencies( | 131 | fn present_and_validate_dependencies( |
| 114 | crates: &[traverse::Dependency<'_>], | 132 | crates: &[traverse::Dependency<'_>], |
| 115 | ctx: &Context, | 133 | ctx: &Context, |
| @@ -6,7 +6,8 @@ use std::{ · 5 unmodified lines | |||
| 6 | }; | 6 | }; |
| 7 | 7 | ||
| 8 | use anyhow::bail; | 8 | use anyhow::bail; |
| 9 | use cargo_metadata::Package; | 9 | use cargo_metadata::camino::Utf8Path; |
| 10 | use cargo_metadata::{Metadata, Package}; | ||
| 10 | use git_repository as git; | 11 | use git_repository as git; |
| 11 | use git_repository::{ | 12 | use git_repository::{ |
| 12 | bstr::ByteSlice, | 13 | bstr::ByteSlice, |
| @@ -14,12 +15,12 @@ use git_repository::{ · 1 unmodified line | |||
| 14 | prelude::{CacheAccessExt, ObjectAccessExt, ObjectIdExt, ReferenceAccessExt, ReferenceExt}, | 15 | prelude::{CacheAccessExt, ObjectAccessExt, ObjectIdExt, ReferenceAccessExt, ReferenceExt}, |
| 15 | }; | 16 | }; |
| 16 | 17 | ||
| 18 | use crate::git::ContextRef; | ||
| 17 | use crate::{ | 19 | use crate::{ |
| 18 | commit, | 20 | commit, |
| 19 | commit::history::{Item, Segment}, | 21 | commit::history::{Item, Segment}, |
| 20 | git::strip_tag_path, | 22 | git::strip_tag_path, |
| 21 | utils::{component_to_bytes, is_tag_name, is_tag_version, tag_prefix}, | 23 | utils::{component_to_bytes, is_tag_name, is_tag_version, tag_prefix}, |
| 22 | Context, | ||
| 23 | }; | 24 | }; |
| 24 | 25 | ||
| 25 | pub enum SegmentScope { | 26 | pub enum SegmentScope { |
| @@ -99,7 +100,7 @@ pub fn collect(repo: &git::Easy) -> anyhow::Result<Option<commit::History>> { · 73 unmodified lines | |||
| 99 | /// Return the head reference followed by all tags affecting `crate_name` as per our tag name rules, ordered by ancestry. | 100 | /// Return the head reference followed by all tags affecting `crate_name` as per our tag name rules, ordered by ancestry. |
| 100 | pub fn crate_ref_segments<'h>( | 101 | pub fn crate_ref_segments<'h>( |
| 101 | package: &Package, | 102 | package: &Package, |
| 102 | ctx: &crate::Context, | 103 | ctx: &ContextRef<'_, '_>, |
| 103 | history: &'h commit::History, | 104 | history: &'h commit::History, |
| 104 | scope: SegmentScope, | 105 | scope: SegmentScope, |
| 105 | ) -> anyhow::Result<Vec<commit::history::Segment<'h>>> { | 106 | ) -> anyhow::Result<Vec<commit::history::Segment<'h>>> { |
| @@ -206,7 +207,7 @@ enum Filter<'a> { · 100 unmodified lines | |||
| 206 | } | 207 | } |
| 207 | 208 | ||
| 208 | fn add_item_if_package_changed<'a>( | 209 | fn add_item_if_package_changed<'a>( |
| 209 | ctx: &Context, | 210 | ctx: &ContextRef<'_, '_>, |
| 210 | segment: &mut Segment<'a>, | 211 | segment: &mut Segment<'a>, |
| 211 | filter: &Filter<'_>, | 212 | filter: &Filter<'_>, |
| 212 | item: &'a Item, | 213 | item: &'a Item, |
| @@ -1,7 +1,7 @@ | |||
| 1 | use std::{convert::TryInto, process::Command}; | 1 | use std::{convert::TryInto, process::Command}; |
| 2 | 2 | ||
| 3 | use anyhow::{anyhow, bail}; | 3 | use anyhow::{anyhow, bail}; |
| 4 | use cargo_metadata::{camino::Utf8Path, Package}; | 4 | use cargo_metadata::{camino::Utf8Path, Metadata, Package}; |
| 5 | use git_repository as git; | 5 | use git_repository as git; |
| 6 | use git_repository::{ | 6 | use git_repository::{ |
| 7 | bstr::{BStr, ByteSlice}, | 7 | bstr::{BStr, ByteSlice}, |
| @@ -14,13 +14,49 @@ use crate::utils::{component_to_bytes, tag_name}; · 6 unmodified lines | |||
| 14 | 14 | ||
| 15 | pub mod history; | 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 | #[derive(Clone, Debug)] | 50 | #[derive(Clone, Debug)] |
| 18 | pub enum PackageChangeKind { | 51 | pub enum PackageChangeKind { |
| 19 | Untagged { wanted_tag_name: String }, | 52 | Untagged { wanted_tag_name: String }, |
| 20 | ChangedOrNew, | 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 | let version_tag_name = tag_name(package, &package.version, &ctx.repo); | 60 | let version_tag_name = tag_name(package, &package.version, &ctx.repo); |
| 25 | let mut tag_ref = match ctx.repo.try_find_reference(&version_tag_name)? { | 61 | let mut tag_ref = match ctx.repo.try_find_reference(&version_tag_name)? { |
| 26 | None => { | 62 | None => { |
| @@ -1,6 +1,6 @@ | |||
| 1 | use std::collections::BTreeSet; | 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 | use crate::{ | 5 | use crate::{ |
| 6 | git, | 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 | #[derive(Clone, Debug)] | 155 | #[derive(Clone, Debug)] |
| 131 | pub struct Dependency<'meta> { | 156 | pub struct Dependency<'meta> { |
| 132 | pub package: &'meta Package, | 157 | pub package: &'meta Package, |
| @@ -134,13 +159,15 @@ pub struct Dependency<'meta> { · 1 unmodified line | |||
| 134 | pub mode: dependency::Mode, | 159 | pub mode: dependency::Mode, |
| 135 | } | 160 | } |
| 136 | 161 | ||
| 137 | pub fn dependencies( | 162 | pub fn dependencies<'meta>( |
| 138 | ctx: &crate::Context, | 163 | ctx: &ContextRef<'meta, '_>, |
| 139 | allow_auto_publish_of_stable_crates: bool, | 164 | Options { |
| 140 | bump_when_needed: bool, | 165 | add_production_crates, |
| 141 | isolate_dependencies_from_breaking_changes: bool, | 166 | bump_when_needed, |
| 142 | traverse_graph: bool, | 167 | isolate_dependencies_from_breaking_changes, |
| 143 | ) -> anyhow::Result<Vec<Dependency<'_>>> { | 168 | traverse_graph, |
| 169 | }: Options, | ||
| 170 | ) -> anyhow::Result<Vec<Dependency<'meta>>> { | ||
| 144 | let mut seen = BTreeSet::new(); | 171 | let mut seen = BTreeSet::new(); |
| 145 | let mut crates = Vec::new(); | 172 | let mut crates = Vec::new(); |
| 146 | for crate_name in &ctx.crate_names { | 173 | for crate_name in &ctx.crate_names { |
| @@ -155,12 +182,12 @@ pub fn dependencies( · 8 unmodified lines | |||
| 155 | &mut seen, | 182 | &mut seen, |
| 156 | &mut crates_this_round, | 183 | &mut crates_this_round, |
| 157 | package, | 184 | package, |
| 158 | allow_auto_publish_of_stable_crates, | 185 | add_production_crates, |
| 159 | bump_when_needed, | 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 | Some(user_package_change) => { | 191 | Some(user_package_change) => { |
| 165 | crates_this_round.push(Dependency { | 192 | crates_this_round.push(Dependency { |
| 166 | package, | 193 | package, |
| @@ -169,7 +196,7 @@ pub fn dependencies( · 2 unmodified lines | |||
| 169 | dependency::Mode::ToBePublished { | 196 | dependency::Mode::ToBePublished { |
| 170 | adjustment: VersionAdjustment::Changed { | 197 | adjustment: VersionAdjustment::Changed { |
| 171 | change: user_package_change, | 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 | } else { | 202 | } else { |
| @@ -196,17 +223,12 @@ pub fn dependencies( · 20 unmodified lines | |||
| 196 | } | 223 | } |
| 197 | 224 | ||
| 198 | if isolate_dependencies_from_breaking_changes { | 225 | if isolate_dependencies_from_breaking_changes { |
| 199 | forward_propagate_breaking_changes_for_publishing( | 226 | forward_propagate_breaking_changes_for_publishing(ctx, &mut crates, bump_when_needed, add_production_crates)?; |
| 200 | ctx, | ||
| 201 | &mut crates, | ||
| 202 | bump_when_needed, | ||
| 203 | allow_auto_publish_of_stable_crates, | ||
| 204 | )?; | ||
| 205 | forward_propagate_breaking_changes_for_manifest_updates( | 227 | forward_propagate_breaking_changes_for_manifest_updates( |
| 206 | ctx, | 228 | ctx, |
| 207 | &mut crates, | 229 | &mut crates, |
| 208 | bump_when_needed, | 230 | bump_when_needed, |
| 209 | allow_auto_publish_of_stable_crates, | 231 | add_production_crates, |
| 210 | )?; | 232 | )?; |
| 211 | } | 233 | } |
| 212 | crates.extend(find_workspace_crates_depending_on_adjusted_crates(ctx, &crates)); | 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 | fn forward_propagate_breaking_changes_for_manifest_updates<'meta>( | 250 | fn forward_propagate_breaking_changes_for_manifest_updates<'meta>( |
| 229 | ctx: &'meta Context, | 251 | ctx: &ContextRef<'meta, '_>, |
| 230 | crates: &mut Vec<Dependency<'meta>>, | 252 | crates: &mut Vec<Dependency<'meta>>, |
| 231 | bump_when_needed: bool, | 253 | bump_when_needed: bool, |
| 232 | allow_auto_publish_of_stable_crates: bool, | 254 | allow_auto_publish_of_stable_crates: bool, |
| @@ -323,9 +345,9 @@ fn package_may_be_published(p: &Package) -> bool { · 90 unmodified lines | |||
| 323 | p.publish.is_none() | 345 | p.publish.is_none() |
| 324 | } | 346 | } |
| 325 | 347 | ||
| 326 | fn forward_propagate_breaking_changes_for_publishing( | 348 | fn forward_propagate_breaking_changes_for_publishing<'meta>( |
| 327 | ctx: &Context, | 349 | ctx: &ContextRef<'meta, '_>, |
| 328 | mut crates: &mut Vec<Dependency<'_>>, | 350 | mut crates: &mut Vec<Dependency<'meta>>, |
| 329 | bump_when_needed: bool, | 351 | bump_when_needed: bool, |
| 330 | allow_auto_publish_of_stable_crates: bool, | 352 | allow_auto_publish_of_stable_crates: bool, |
| 331 | ) -> anyhow::Result<()> { | 353 | ) -> anyhow::Result<()> { |
| @@ -378,7 +400,7 @@ impl EditForPublish { · 46 unmodified lines | |||
| 378 | fn apply( | 400 | fn apply( |
| 379 | self, | 401 | self, |
| 380 | crates: &mut [Dependency<'_>], | 402 | crates: &mut [Dependency<'_>], |
| 381 | ctx: &Context, | 403 | ctx: &ContextRef<'_, '_>, |
| 382 | bump_when_needed: bool, | 404 | bump_when_needed: bool, |
| 383 | allow_auto_publish_of_stable_crates: bool, | 405 | allow_auto_publish_of_stable_crates: bool, |
| 384 | ) -> anyhow::Result<()> { | 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 | let breaking_spec = is_pre_release_version(&package.version) | 451 | let breaking_spec = is_pre_release_version(&package.version) |
| 430 | .then(|| BumpSpec::Minor) | 452 | .then(|| BumpSpec::Minor) |
| 431 | .unwrap_or(BumpSpec::Major); | 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 | fn make_breaking(adjustment: &mut VersionAdjustment, breaking_bump: version::Bump, breaking_crate_names: Vec<String>) { | 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 | fn depth_first_traversal<'meta>( | 517 | fn depth_first_traversal<'meta>( |
| 496 | ctx: &'meta crate::Context, | 518 | ctx: &ContextRef<'_, 'meta>, |
| 497 | seen: &mut BTreeSet<&'meta PackageId>, | 519 | seen: &mut BTreeSet<&'meta PackageId>, |
| 498 | crates: &mut Vec<Dependency<'meta>>, | 520 | crates: &mut Vec<Dependency<'meta>>, |
| 499 | root: &Package, | 521 | root: &Package, |
| @@ -519,7 +541,7 @@ fn depth_first_traversal<'meta>( · 19 unmodified lines | |||
| 519 | bump_when_needed, | 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 | Some(change) => { | 545 | Some(change) => { |
| 524 | if is_pre_release_version(&workspace_dependency.version) || allow_auto_publish_of_stable_crates { | 546 | if is_pre_release_version(&workspace_dependency.version) || allow_auto_publish_of_stable_crates { |
| 525 | Dependency { | 547 | Dependency { |
| @@ -528,7 +550,7 @@ fn depth_first_traversal<'meta>( · 2 unmodified lines | |||
| 528 | mode: dependency::Mode::ToBePublished { | 550 | mode: dependency::Mode::ToBePublished { |
| 529 | adjustment: VersionAdjustment::Changed { | 551 | adjustment: VersionAdjustment::Changed { |
| 530 | change, | 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 | fn find_workspace_crates_depending_on_adjusted_crates<'meta>( | 581 | fn find_workspace_crates_depending_on_adjusted_crates<'meta>( |
| 560 | ctx: &'meta Context, | 582 | ctx: &ContextRef<'meta, '_>, |
| 561 | crates: &[Dependency<'_>], | 583 | crates: &[Dependency<'_>], |
| 562 | ) -> Vec<Dependency<'meta>> { | 584 | ) -> Vec<Dependency<'meta>> { |
| 563 | ctx.meta | 585 | ctx.meta |
| @@ -1,7 +1,28 @@ | |||
| 1 | use cargo_metadata::camino::Utf8Path; | ||
| 1 | use cargo_metadata::Package; | 2 | use cargo_metadata::Package; |
| 2 | use semver::{Prerelease, Version}; | 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 | #[derive(Copy, Clone)] | 27 | #[derive(Copy, Clone)] |
| 7 | pub enum BumpSpec { | 28 | pub enum BumpSpec { |
| @@ -25,7 +46,7 @@ impl std::fmt::Display for BumpSpec { · 17 unmodified lines | |||
| 25 | } | 46 | } |
| 26 | 47 | ||
| 27 | #[allow(clippy::ptr_arg)] | 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 | if ctx.crate_names.contains(name) { | 50 | if ctx.crate_names.contains(name) { |
| 30 | ctx.bump | 51 | ctx.bump |
| 31 | } else { | 52 | } else { |
| @@ -79,7 +100,7 @@ impl Bump { · 47 unmodified lines | |||
| 79 | pub(crate) fn bump_package_with_spec( | 100 | pub(crate) fn bump_package_with_spec( |
| 80 | package: &Package, | 101 | package: &Package, |
| 81 | bump_spec: BumpSpec, | 102 | bump_spec: BumpSpec, |
| 82 | ctx: &Context, | 103 | ctx: &ContextRef<'_>, |
| 83 | bump_when_needed: bool, | 104 | bump_when_needed: bool, |
| 84 | ) -> anyhow::Result<Bump> { | 105 | ) -> anyhow::Result<Bump> { |
| 85 | let mut v = package.version.clone(); | 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 | let bump_spec = select_publishee_bump_spec(&package.name, ctx); | 193 | let bump_spec = select_publishee_bump_spec(&package.name, ctx); |
| 173 | bump_package_with_spec(package, bump_spec, ctx, bump_when_needed) | 194 | bump_package_with_spec(package, bump_spec, ctx, bump_when_needed) |
| 174 | } | 195 | } |