You've already forked macports-base
mirror of
https://github.com/macports/macports-base.git
synced 2026-07-12 18:18:43 -07:00
Use dict getwithdefault
This commit is contained in:
@@ -7192,8 +7192,8 @@ proc macports::compare_pingtimes {a b} {
|
||||
set a_parts [::uri::split $a]
|
||||
set b_parts [::uri::split $b]
|
||||
|
||||
set a_scheme [expr {[dict exists $a_parts scheme] ? [dict get $a_parts scheme] : {}}]
|
||||
set b_scheme [expr {[dict exists $b_parts scheme] ? [dict get $b_parts scheme] : {}}]
|
||||
set a_scheme [dict getwithdefault $a_parts scheme {}]
|
||||
set b_scheme [dict getwithdefault $b_parts scheme {}]
|
||||
# file:// can't be pinged and is assumed to be faster
|
||||
if {$a_scheme eq "file"} {
|
||||
return [expr {$b_scheme eq "file" ? 0 : -1}]
|
||||
|
||||
@@ -397,11 +397,7 @@ proc ditem_key {ditem args} {
|
||||
return $val
|
||||
} elseif {$nbargs == 1} {
|
||||
set key [lindex $args 0]
|
||||
if {[dict exists [set $ditem] $key]} {
|
||||
return [dict get [set $ditem] $key]
|
||||
} else {
|
||||
return {}
|
||||
}
|
||||
return [dict getwithdefault [set $ditem] $key {}]
|
||||
} elseif {[info exists $ditem]} {
|
||||
return [set $ditem]
|
||||
} else {
|
||||
|
||||
+10
-37
@@ -1896,28 +1896,20 @@ proc action_info { action portlist opts } {
|
||||
}
|
||||
} elseif {$opt eq "fullname"} {
|
||||
set inf "[dict get $portinfo name] @"
|
||||
append inf [composite_version [dict get $portinfo version] [expr {[dict exists $portinfo active_variants] ? [dict get $portinfo active_variants] : {}}]]
|
||||
append inf [composite_version [dict get $portinfo version] [dict getwithdefault $portinfo active_variants {}]]
|
||||
set ropt "fullname"
|
||||
} else {
|
||||
# Map from friendly name
|
||||
set ropt [map_friendly_field_names $opt]
|
||||
|
||||
# If there's no such info, move on
|
||||
if {![dict exists $portinfo $ropt]} {
|
||||
set inf ""
|
||||
} else {
|
||||
set inf [dict get $portinfo $ropt]
|
||||
}
|
||||
set inf [dict getwithdefault $portinfo $ropt {}]
|
||||
}
|
||||
|
||||
# Calculate field label
|
||||
set label ""
|
||||
if {$pretty_print} {
|
||||
if {[dict exists $pretty_label $ropt]} {
|
||||
set label [dict get $pretty_label $ropt]
|
||||
} else {
|
||||
set label $opt
|
||||
}
|
||||
set label [dict getwithdefault $pretty_label $ropt $opt]
|
||||
} elseif {$show_label} {
|
||||
set label "$opt: "
|
||||
}
|
||||
@@ -2880,11 +2872,7 @@ proc action_deps { action portlist opts } {
|
||||
|
||||
set version [dict get $portinfo version]
|
||||
set revision [dict get $portinfo revision]
|
||||
if {[dict exists $portinfo canonical_active_variants]} {
|
||||
set variants [dict get $portinfo canonical_active_variants]
|
||||
} else {
|
||||
set variants {}
|
||||
}
|
||||
set variants [dict getwithdefault $portinfo canonical_active_variants {}]
|
||||
|
||||
puts -nonewline $separator
|
||||
if {$action eq "deps"} {
|
||||
@@ -3204,15 +3192,9 @@ proc action_outdated { action portlist opts } {
|
||||
continue
|
||||
}
|
||||
set latest_version [dict get $portinfo version]
|
||||
set latest_revision 0
|
||||
if {[dict exists $portinfo revision] && [dict get $portinfo revision] > 0} {
|
||||
set latest_revision [dict get $portinfo revision]
|
||||
}
|
||||
set latest_revision [dict getwithdefault $portinfo revision 0]
|
||||
set latest_compound "${latest_version}_${latest_revision}"
|
||||
set latest_epoch 0
|
||||
if {[dict exists $portinfo epoch]} {
|
||||
set latest_epoch [dict get $portinfo epoch]
|
||||
}
|
||||
set latest_epoch [dict getwithdefault $portinfo epoch 0]
|
||||
|
||||
# Compare versions, first checking epoch, then version, then revision
|
||||
set epoch_comp_result [expr {$installed_epoch - $latest_epoch}]
|
||||
@@ -3689,14 +3671,9 @@ proc action_list { action portlist opts } {
|
||||
}
|
||||
|
||||
foreach {name portinfo} $res {
|
||||
set outdir ""
|
||||
if {[dict exists $portinfo portdir]} {
|
||||
set outdir [dict get $portinfo portdir]
|
||||
}
|
||||
if {[dict exists $portinfo version]} {
|
||||
set version [dict get $portinfo version]
|
||||
} else {
|
||||
set version {}
|
||||
set outdir [dict getwithdefault $portinfo portdir {}]
|
||||
set version [dict getwithdefault $portinfo version {}]
|
||||
if {$version eq {}} {
|
||||
ui_warn "required option 'version' is missing for $name"
|
||||
}
|
||||
puts [format "%-30s @%-14s %s" $name $version $outdir]
|
||||
@@ -3862,12 +3839,8 @@ proc action_portcmds { action portlist opts } {
|
||||
}
|
||||
|
||||
gohome {
|
||||
set homepage ""
|
||||
|
||||
# Get the homepage as read from PortIndex
|
||||
if {[dict exists $portinfo homepage]} {
|
||||
set homepage [dict get $portinfo homepage]
|
||||
}
|
||||
set homepage [dict getwithdefault $portinfo homepage {}]
|
||||
|
||||
# If not available, get the homepage for the port by opening the Portfile
|
||||
if {$homepage eq "" && ![catch {set ctx [mportopen $porturl]} result]} {
|
||||
|
||||
@@ -111,11 +111,7 @@ proc foreachport {portlist block} {
|
||||
set variations [dict get $portspec variants]
|
||||
set requested_variations [dict get $portspec requested_variants]
|
||||
set options [dict get $portspec options]
|
||||
if {[dict exists $portspec metadata]} {
|
||||
set portmetadata [dict get $portspec metadata]
|
||||
} else {
|
||||
set portmetadata ""
|
||||
}
|
||||
set portmetadata [dict getwithdefault $portspec metadata {}]
|
||||
}
|
||||
|
||||
# Invoke block
|
||||
|
||||
@@ -86,10 +86,7 @@ proc activate {name {version ""} {revision ""} {variants 0} {options ""}} {
|
||||
if {[dict exists $options ports_activate_no-exec]} {
|
||||
set noexec [dict get $options ports_activate_no-exec]
|
||||
}
|
||||
set rename_list [list]
|
||||
if {[dict exists $options portactivate_rename_files]} {
|
||||
set rename_list [dict get $options portactivate_rename_files]
|
||||
}
|
||||
set rename_list [dict getwithdefault $options portactivate_rename_files [list]]
|
||||
set todeactivate [list]
|
||||
|
||||
registry::read {
|
||||
@@ -767,11 +764,7 @@ proc _activate_contents {port {rename_list {}}} {
|
||||
throw registry::image-error $msg
|
||||
}
|
||||
}
|
||||
if {[dict exists $conflicts_path_to_port $file]} {
|
||||
set owner [dict get $conflicts_path_to_port $file]
|
||||
} else {
|
||||
set owner {}
|
||||
}
|
||||
set owner [dict getwithdefault $conflicts_path_to_port $file {}]
|
||||
if {$owner eq {} || ![dict exists $todeactivate $owner]} {
|
||||
if {$force} {
|
||||
# If we're forcing the activation, then we move any existing
|
||||
|
||||
@@ -138,11 +138,7 @@ proc uninstall {portname {version ""} {revision ""} {variants 0} {options ""}} {
|
||||
# don't want this set when calling registry::run_target
|
||||
dict unset options subport
|
||||
}
|
||||
if {[dict exists $options ports_force]} {
|
||||
set force [dict get $options ports_force]
|
||||
} else {
|
||||
set force no
|
||||
}
|
||||
set force [dict getwithdefault $options ports_force no]
|
||||
# if no-exec is set for uninstall, set for deactivate too
|
||||
if {[dict exists $options ports_uninstall_no-exec]} {
|
||||
dict set options ports_deactivate_no-exec [dict get $options ports_uninstall_no-exec]
|
||||
|
||||
Reference in New Issue
Block a user