From 7110b136993e7400f21312d9b5f1d2275ef434a8 Mon Sep 17 00:00:00 2001 From: Schneems Date: Mon, 23 Sep 2024 14:57:47 -0500 Subject: [PATCH] Remove redundant logic The explicit check if the old and new metadata structs were equal isn't needed since I'm already comparing each individual element and have logic to return `None` if they're the same. --- .../ruby/src/layers/ruby_install_layer.rs | 80 +++++++++---------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/buildpacks/ruby/src/layers/ruby_install_layer.rs b/buildpacks/ruby/src/layers/ruby_install_layer.rs index 150c0ed..3e08f1c 100644 --- a/buildpacks/ruby/src/layers/ruby_install_layer.rs +++ b/buildpacks/ruby/src/layers/ruby_install_layer.rs @@ -166,50 +166,46 @@ impl TryFrom for MetadataV2 { } fn metadata_diff(old: &Metadata, metadata: &Metadata) -> Option> { - if old == metadata { + let mut differences = Vec::new(); + let Metadata { + distro_name, + distro_version, + cpu_architecture, + ruby_version, + } = old; + if ruby_version != &metadata.ruby_version { + differences.push(format!( + "Ruby version ({old} to {now})", + old = style::value(ruby_version.to_string()), + now = style::value(metadata.ruby_version.to_string()) + )); + } + if distro_name != &metadata.distro_name { + differences.push(format!( + "distro name ({old} to {now})", + old = style::value(distro_name), + now = style::value(&metadata.distro_name) + )); + } + if distro_version != &metadata.distro_version { + differences.push(format!( + "distro version ({old} to {now})", + old = style::value(distro_version), + now = style::value(&metadata.distro_version) + )); + } + if cpu_architecture != &metadata.cpu_architecture { + differences.push(format!( + "CPU architecture ({old} to {now})", + old = style::value(cpu_architecture), + now = style::value(&metadata.cpu_architecture) + )); + } + + if differences.is_empty() { None } else { - let mut differences = Vec::new(); - let Metadata { - distro_name, - distro_version, - cpu_architecture, - ruby_version, - } = old; - if ruby_version != &metadata.ruby_version { - differences.push(format!( - "Ruby version ({old} to {now})", - old = style::value(ruby_version.to_string()), - now = style::value(metadata.ruby_version.to_string()) - )); - } - if distro_name != &metadata.distro_name { - differences.push(format!( - "distro name ({old} to {now})", - old = style::value(distro_name), - now = style::value(&metadata.distro_name) - )); - } - if distro_version != &metadata.distro_version { - differences.push(format!( - "distro version ({old} to {now})", - old = style::value(distro_version), - now = style::value(&metadata.distro_version) - )); - } - if cpu_architecture != &metadata.cpu_architecture { - differences.push(format!( - "CPU architecture ({old} to {now})", - old = style::value(cpu_architecture), - now = style::value(&metadata.cpu_architecture) - )); - } - - if differences.is_empty() { - None - } else { - Some(differences) - } + Some(differences) } }