Skip to content

Commit

Permalink
Remove redundant logic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
schneems committed Sep 23, 2024
1 parent 2de1c3e commit 7110b13
Showing 1 changed file with 38 additions and 42 deletions.
80 changes: 38 additions & 42 deletions buildpacks/ruby/src/layers/ruby_install_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,50 +166,46 @@ impl TryFrom<MetadataV1> for MetadataV2 {
}

fn metadata_diff(old: &Metadata, metadata: &Metadata) -> Option<Vec<String>> {
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)
}
}

Expand Down

0 comments on commit 7110b13

Please sign in to comment.