<pre style='margin:0'>
Joshua Root (jmroot) pushed a commit to branch master
in repository macports-base.

</pre>
<p><a href="https://github.com/macports/macports-base/commit/916cfaa1a2d507a5840335ec5135c48f03172fe1">https://github.com/macports/macports-base/commit/916cfaa1a2d507a5840335ec5135c48f03172fe1</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit 916cfaa1a2d507a5840335ec5135c48f03172fe1
</span>Author: Joshua Root <jmr@macports.org>
AuthorDate: Fri Mar 8 03:05:42 2024 +1100

<span style='display:block; white-space:pre;color:#404040;'>    port.tcl: global cleanup
</span>---
 src/port/port.tcl | 239 ++++++++++++++++++++++++++++++++----------------------
 1 file changed, 140 insertions(+), 99 deletions(-)

<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/port/port.tcl b/src/port/port.tcl
</span><span style='display:block; white-space:pre;color:#808080;'>index 1e3b9ef9a..bb45583c9 100755
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/port/port.tcl
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/port/port.tcl
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -116,7 +116,8 @@ proc break_softcontinue { msg status name_status } {
</span> 
 # show the URL for the ticket reporting instructions
 proc print_tickets_url {args} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if {${macports::prefix} ne "/usr/local" && ${macports::prefix} ne "/usr"} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global macports::prefix
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {${prefix} ne "/usr/local" && ${prefix} ne "/usr"} {
</span>         set len [string length [macports::ui_prefix_default error]]
         ui_error [wrap "Follow https://guide.macports.org/#project.tickets if you believe there is a bug." -${len}]
     }
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -193,9 +194,10 @@ proc registry_installed {portname {portversion ""} {require_single yes} {only_ac
</span> # porturl and options if not set.
 proc add_to_portlist_with_defaults {listname portentry} {
     upvar $listname portlist
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global global_options
</span> 
     if {![dict exists $portentry options]} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        dict set portentry options [array get ::global_options]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        dict set portentry options [array get global_options]
</span>     }
     # If neither portname nor url is specified, then default to the current port
     if {(![dict exists $portentry url] || [dict get $portentry url] eq "")
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -421,10 +423,11 @@ proc wraplabel {label string maxlen {indent ""}} {
</span> # Port selection
 ##########################################
 proc unique_results_to_portlist {infos} {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global global_options
</span>     set unique [dict create]
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set opts [dict create {*}[array get ::global_options]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    set opts [dict create {*}[array get global_options]]
</span>     foreach {name portinfo} $infos {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        set portentry [entry_for_portlist [list url [dict get $portinfo porturl] name $name options $opts]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        set portentry [entry_for_portlist [dict create url [dict get $portinfo porturl] name $name options $opts]]
</span> 
         if {[dict exists $unique [dict get $portentry fullname]]} continue
         dict set unique [dict get $portentry fullname] $portentry
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -549,9 +552,10 @@ proc get_outdated_ports {} {
</span>         fatal "getting installed ports failed: $result"
     }
 
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global macports::cxx_stdlib macports::os_platform macports::os_major
</span>     # Now process the list, keeping only those ports that are outdated
     set results [list]
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if {${macports::cxx_stdlib} eq "libc++"} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {${cxx_stdlib} eq "libc++"} {
</span>         set wrong_stdlib libstdc++
     } else {
         set wrong_stdlib libc++
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -602,8 +606,8 @@ proc get_outdated_ports {} {
</span>         }
         if {$comp_result == 0} {
             if {([$i os_platform] ni [list any "" 0] && [$i os_major] ni [list "" 0]
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                && ([$i os_platform] ne ${macports::os_platform}
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                    || ([$i os_major] ne "any" && [$i os_major] != ${macports::os_major})))
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                && ([$i os_platform] ne ${os_platform}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    || ([$i os_major] ne "any" && [$i os_major] != ${os_major})))
</span>                 || ([$i cxx_stdlib_overridden] == 0 && [$i cxx_stdlib] eq $wrong_stdlib)} {
                 set comp_result -1
             }
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -727,16 +731,17 @@ proc get_dependent_ports {portname recursive} {
</span> 
 
 proc get_rdepends_ports {portname} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if {![info exists ::portDependenciesDict]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global portDependenciesDict
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {![info exists portDependenciesDict]} {
</span>         # make a dictionary of all the port names and their (reverse) dependencies
         # much faster to build this once than to call mportsearch thousands of times
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        set ::portDependenciesDict [dict create]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        set portDependenciesDict [dict create]
</span>         set deptypes [list depends_fetch depends_extract depends_patch depends_build depends_lib depends_run depends_test]
         foreach {pname pinfo} [mportlistall] {
             foreach dtype $deptypes {
                 if {[dict exists $pinfo $dtype]} {
                     foreach depspec [dict get $pinfo $dtype] {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                        dict lappend ::portDependenciesDict [string tolower [lindex [split $depspec :] end]] $pname
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        dict lappend portDependenciesDict [string tolower [lindex [split $depspec :] end]] $pname
</span>                     }
                 }
             }
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -748,8 +753,8 @@ proc get_rdepends_ports {portname} {
</span>     while {[llength $portList] > 0} {
         set aPort [lindex $portList end]
         set portList [lreplace ${portList}[set portList {}] end end]
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        if {[dict exists $::portDependenciesDict $aPort]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-            foreach possiblyNewPort [dict get $::portDependenciesDict $aPort] {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        if {[dict exists $portDependenciesDict $aPort]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            foreach possiblyNewPort [dict get $portDependenciesDict $aPort] {
</span>                 set lcport [string tolower $possiblyNewPort]
                 if {![info exists seen($lcport)]} {
                     set seen($lcport) 1
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -765,6 +770,7 @@ proc get_rdepends_ports {portname} {
</span> 
 
 proc get_dep_ports {portname recursive} {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global global_variations
</span>     # look up portname
     if {[catch {mportlookup $portname} result]} {
         ui_debug $::errorInfo
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -784,7 +790,7 @@ proc get_dep_ports {portname recursive} {
</span>     }
     lassign $result portname portinfo
     set porturl [dict get $portinfo porturl]
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set gvariations [dict create {*}[array get ::global_variations]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    set gvariations [dict create {*}[array get global_variations]]
</span> 
     # open portfile
     if {[catch {set mport [mportopen $porturl [dict create subport $portname] $gvariations]} result]} {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -875,6 +881,7 @@ proc get_dep_ports {portname recursive} {
</span> }
 
 proc get_subports {portname} {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global global_variations
</span>     # look up portname
     if {[catch {mportlookup $portname} result]} {
         ui_debug $::errorInfo
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -896,7 +903,7 @@ proc get_subports {portname} {
</span>     set porturl [dict get $portinfo porturl]
 
     # open portfile
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if {[catch {set mport [mportopen $porturl [dict create subport $portname] [array get ::global_variations]]} result]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {[catch {set mport [mportopen $porturl [dict create subport $portname] [array get global_variations]]} result]} {
</span>         ui_debug $::errorInfo
         if {[macports::ui_isset ports_processall]} {
             ui_error "Unable to open port $portname: $result"
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1252,8 +1259,9 @@ proc add_ports_to_portlist_with_defaults {listname ports {overrides ""}} {
</span>     upvar $listname portlist
 
     if {![dict exists $overrides options]} {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+        global global_options
</span>         set i 0
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        set opts [dict create {*}[array get ::global_options]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        set opts [dict create {*}[array get global_options]]
</span>         foreach port $ports {
             if {![dict exists $port options]} {
                 dict set port options $opts
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1372,9 +1380,10 @@ proc parsePortSpec { vername varname optname {remainder ""} } {
</span>     upvar $vername portversion
     upvar $varname portvariants
     upvar $optname portoptions
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global global_options
</span> 
     set portversion ""
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set portoptions [dict create {*}[array get ::global_options]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    set portoptions [dict create {*}[array get global_options]]
</span>     set portvariants ""
 
     # Parse port version/variants/options
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1447,10 +1456,11 @@ proc parsePortSpec { vername varname optname {remainder ""} } {
</span> ##########################################
 
 proc action_get_usage { action } {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if {[dict exists $::action_array $action]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global action_array cmd_opts_array
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {[dict exists $action_array $action]} {
</span>         set cmds ""
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        if {[dict exists $::cmd_opts_array $action]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-            foreach opt [dict get $::cmd_opts_array $action] {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        if {[dict exists $cmd_opts_array $action]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            foreach opt [dict get $cmd_opts_array $action] {
</span>                 if {[llength $opt] == 1} {
                     set name $opt
                     set optc 0
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1504,6 +1514,7 @@ proc action_usage { action portlist opts } {
</span> 
 
 proc action_help { action portlist opts } {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global macports::prefix
</span>     set manext ".gz"
     if {[llength $portlist] == 0} {
         set page "man1/port.1$manext"
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1525,7 +1536,7 @@ proc action_help { action portlist opts } {
</span>             # Try to find the manpage in sections 5 (configuration) and 7
             foreach section {5 7} {
                 set page_candidate "man${section}/${topic}.${section}${manext}"
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                set pagepath ${macports::prefix}/share/man/${page_candidate}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                set pagepath ${prefix}/share/man/${page_candidate}
</span>                 ui_debug "testing $pagepath..."
                 if {[file exists $pagepath]} {
                     set page $page_candidate
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1537,13 +1548,13 @@ proc action_help { action portlist opts } {
</span> 
     set pagepath ""
     if {$page ne ""} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        set pagepath ${macports::prefix}/share/man/$page
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        set pagepath ${prefix}/share/man/$page
</span>     }
     if {$page ne "" && ![file exists $pagepath]} {
         # command exists, but there doesn't seem to be a manpage for it; open
         # portundocumented.7
         set page "man7/portundocumented.7$manext"
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        set pagepath ${macports::prefix}/share/man/$page
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        set pagepath ${prefix}/share/man/$page
</span>     }
 
     if {$pagepath ne ""} {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1578,6 +1589,7 @@ proc action_log { action portlist opts } {
</span>     if {[require_portlist portlist]} {
         return 1
     }
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global global_options macports::ui_priorities
</span>     foreachport $portlist {
         # If we have a url, use that, since it's most specific
         # otherwise try to map the portname to a url
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1627,18 +1639,18 @@ proc action_log { action portlist opts } {
</span>             set data [read $fp]
             set data [split $data "\n"]
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-            if {[info exists ::global_options(ports_log_phase)]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                set phase $::global_options(ports_log_phase);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            if {[info exists global_options(ports_log_phase)]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                set phase $global_options(ports_log_phase);
</span>             } else {
                 set phase "\[a-z\]*"
             }
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-            if {[info exists ::global_options(ports_log_level)]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                set index [lsearch -exact ${macports::ui_priorities} $::global_options(ports_log_level)]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            if {[info exists global_options(ports_log_level)]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                set index [lsearch -exact ${ui_priorities} $global_options(ports_log_level)]
</span>                 if {$index == -1} {
                     set prefix ""
                 } else {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                    set prefix [join [lrange ${macports::ui_priorities} 0 $index] "|"]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    set prefix [join [lrange ${ui_priorities} 0 $index] "|"]
</span>                 }
             } else {
                 set prefix "\[a-z\]*"
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1666,7 +1678,8 @@ proc action_info { action portlist opts } {
</span>     }
 
     set separator ""
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set gvariations [dict create {*}[array get ::global_variations]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global global_variations global_options
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    set gvariations [dict create {*}[array get global_variations]]
</span>     foreachport $portlist {
         set index_only 0
         if {[dict exists $options ports_info_index] && [dict get $options ports_info_index]} {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1705,7 +1718,7 @@ proc action_info { action portlist opts } {
</span>             dict unset options subport
             set portinfo [dict merge $portinfo [mportinfo $mport]]
             mportclose $mport
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        } elseif {![info exists portinfo]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        } elseif {$portinfo eq ""} {
</span>             ui_warn "no PortIndex entry found for $portname"
             continue
         }
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1789,9 +1802,9 @@ proc action_info { action portlist opts } {
</span>             }
             # replace all occurrences of --depends with the expanded options
             while 1 {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                set order_pos [lsearch -exact $::global_options(options_${action}_order) ports_info_depends]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                set order_pos [lsearch -exact $global_options(options_${action}_order) ports_info_depends]
</span>                 if {$order_pos != -1} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                    set ::global_options(options_${action}_order) [lreplace $::global_options(options_${action}_order) \
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    set global_options(options_${action}_order) [lreplace $global_options(options_${action}_order) \
</span>                         $order_pos $order_pos {*}$all_depends_options]
                 } else {
                     break
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1839,7 +1852,7 @@ proc action_info { action portlist opts } {
</span>         set fields [list]
 
         # This contains all parameters in order given on command line
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        set opts_action $::global_options(options_${action}_order)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        set opts_action $global_options(options_${action}_order)
</span>         # Get the display fields in order provided on command line
         #  ::struct::set intersect does not keep order of items
         set opts_todo [list]
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1982,9 +1995,9 @@ proc action_info { action portlist opts } {
</span>                     if {[dict exists $variations $v]} {
                         # selected by command line, prefixed with +/-
                         set varmodifier [dict get $variations $v]
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                    } elseif {[info exists ::global_variations($v)]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    } elseif {[info exists global_variations($v)]} {
</span>                         # selected by variants.conf, prefixed with (+)/(-)
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                        set varmodifier "($::global_variations($v))"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        set varmodifier "($global_variations($v))"
</span>                         # Retrieve additional information from the new key.
                     } elseif {[dict exists $portinfo vinfo $v is_default]} {
                         set varmodifier "\[[dict get $portinfo vinfo $v is_default]]"
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2083,14 +2096,14 @@ proc action_location { action portlist opts } {
</span> 
 
 proc action_notes { action portlist opts } {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    global UI_PREFIX
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global UI_PREFIX global_variations
</span> 
     if {[require_portlist portlist]} {
         return 1
     }
 
     set status 0
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set gvariations [dict create {*}[array get ::global_variations]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    set gvariations [dict create {*}[array get global_variations]]
</span>     foreachport $portlist {
         if {$porturl eq ""} {
             # Look up the port.
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2405,7 +2418,8 @@ proc action_selfupdate { action portlist opts } {
</span>     if {[prefix_unwritable]} {
         return 1
     }
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set options [array get ::global_options]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global global_options
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    set options [array get global_options]
</span>     if {[dict exists $options ports_${action}_nosync] && [dict get $options ports_${action}_nosync] eq "yes"} {
         ui_warn "port selfupdate --nosync is deprecated, use --no-sync instead"
         dict set options ports_${action}_no-sync [dict get $options ports_${action}_nosync]
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2471,12 +2485,13 @@ proc action_reclaim { action portlist opts } {
</span>     if {[prefix_unwritable]} {
         return 1
     }
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global macports::revupgrade_autorun
</span> 
     set status [macports::reclaim_main $opts]
 
     if {$status == 0 &&
         ![dict exists $opts ports_upgrade_no-rev-upgrade] &&
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        ${macports::revupgrade_autorun}} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        ${revupgrade_autorun}} {
</span>         set status [action_revupgrade $action $portlist $opts]
     }
 
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2506,7 +2521,8 @@ proc action_upgrade { action portlist opts } {
</span>     if {$status != 0 && $status != 2 && $status != 3} {
         print_tickets_url
     } elseif {$status == 0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        if {![dict exists $opts ports_upgrade_no-rev-upgrade] && ${macports::revupgrade_autorun} && ![macports::global_option_isset ports_dryrun]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        global macports::revupgrade_autorun
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        if {![dict exists $opts ports_upgrade_no-rev-upgrade] && ${revupgrade_autorun} && ![macports::global_option_isset ports_dryrun]} {
</span>             set status [action_revupgrade $action $portlist $opts]
         }
     }
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2515,7 +2531,8 @@ proc action_upgrade { action portlist opts } {
</span> }
 
 proc action_revupgrade { action portlist opts } {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if {$macports::revupgrade_mode eq "rebuild" && [prefix_unwritable]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global macports::revupgrade_mode
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {$revupgrade_mode eq "rebuild" && [prefix_unwritable]} {
</span>         return 1
     }
     set status [macports::revupgrade $opts]
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2539,10 +2556,11 @@ proc action_version { action portlist opts } {
</span> 
 
 proc action_platform { action portlist opts } {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global macports::os_platform macports::os_major macports::os_arch
</span>     if {![macports::ui_isset ports_quiet]} {
         puts -nonewline "Platform: "
     }
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    puts "${macports::os_platform} ${macports::os_major} ${macports::os_arch}"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    puts "${os_platform} ${os_major} ${os_arch}"
</span>     return 0
 }
 
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2657,9 +2675,10 @@ proc action_deps { action portlist opts } {
</span>     if {[require_portlist portlist]} {
         return 1
     }
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global global_variations
</span>     set separator ""
     set labeldict [dict create depends_fetch Fetch depends_extract Extract depends_patch Patch depends_build Build depends_lib Library depends_run Runtime depends_test Test]
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set gvariations [dict create {*}[array get ::global_variations]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    set gvariations [dict create {*}[array get global_variations]]
</span> 
     foreachport $portlist {
         set deptypes [list]
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2939,11 +2958,12 @@ proc action_uninstall { action portlist opts } {
</span> 
 
 proc action_installed { action portlist opts } {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global private_options
</span>     set status 0
     set restrictedList 0
     set ilist [list]
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if { [llength $portlist] || (![info exists ::private_options(ports_no_args)] || $::private_options(ports_no_args) eq "no")} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if { [llength $portlist] || (![info exists private_options(ports_no_args)] || $private_options(ports_no_args) eq "no")} {
</span>         set restrictedList 1
         foreachport $portlist {
             set composite_version [composite_version $portversion $variations]
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2999,12 +3019,14 @@ proc action_installed { action portlist opts } {
</span> 
 
 proc action_outdated { action portlist opts } {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global private_options macports::cxx_stdlib macports::os_platform \
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+           macports::os_major
</span>     set status 0
 
     # If port names were supplied, limit ourselves to those ports, else check all installed ports
     set ilist [list]
     set restrictedList 0
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if { [llength $portlist] || (![info exists ::private_options(ports_no_args)] || $::private_options(ports_no_args) eq "no")} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if { [llength $portlist] || (![info exists private_options(ports_no_args)] || $private_options(ports_no_args) eq "no")} {
</span>         set restrictedList 1
         foreach portspec $portlist {
             set portname [dict get $portspec name]
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3022,7 +3044,7 @@ proc action_outdated { action portlist opts } {
</span> 
     set num_outdated 0
     if { [llength $ilist] > 0 } {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        if {${macports::cxx_stdlib} eq "libc++"} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        if {${cxx_stdlib} eq "libc++"} {
</span>             set wrong_stdlib libstdc++
         } else {
             set wrong_stdlib libc++
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3081,15 +3103,15 @@ proc action_outdated { action portlist opts } {
</span>                 set os_platform_installed [$i os_platform]
                 set os_major_installed [$i os_major]
                 if {$os_platform_installed ni [list any "" 0] && $os_major_installed ni [list "" 0]
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                    && ($os_platform_installed ne ${macports::os_platform}
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                        || ($os_major_installed ne "any" && $os_major_installed != ${macports::os_major}))} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    && ($os_platform_installed ne ${os_platform}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        || ($os_major_installed ne "any" && $os_major_installed != ${os_major}))} {
</span>                     set comp_result -1
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                    set reason { (platform $os_platform_installed $os_major_installed != ${macports::os_platform} ${macports::os_major})}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    set reason { (platform $os_platform_installed $os_major_installed != ${os_platform} ${os_major})}
</span>                 } else {
                     set cxx_stdlib_installed [$i cxx_stdlib]
                     if {[$i cxx_stdlib_overridden] == 0 && $cxx_stdlib_installed eq $wrong_stdlib} {
                         set comp_result -1
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                        set reason { (C++ stdlib $cxx_stdlib_installed != ${macports::cxx_stdlib})}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        set reason { (C++ stdlib $cxx_stdlib_installed != ${cxx_stdlib})}
</span>                     }
                 }
             }
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3138,10 +3160,11 @@ proc action_contents { action portlist opts } {
</span>     if {[require_portlist portlist]} {
         return 1
     }
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if {[info exists ::global_options(ports_contents_size)]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global global_options
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {[info exists global_options(ports_contents_size)]} {
</span>         set units {}
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        if {[info exists ::global_options(ports_contents_units)]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-            set units [complete_size_units $::global_options(ports_contents_units)]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        if {[info exists global_options(ports_contents_units)]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            set units [complete_size_units $global_options(ports_contents_units)]
</span>         }
         set outstring {[format "%12s $file" [filesize $file $units]]}
     } else {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3201,10 +3224,11 @@ proc complete_size_units {units} {
</span> # Show space used by the given ports' files
 proc action_space {action portlist opts} {
     require_portlist portlist
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global global_options
</span> 
     set units {}
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if {[info exists ::global_options(ports_space_units)]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-        set units [complete_size_units $::global_options(ports_space_units)]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {[info exists global_options(ports_space_units)]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        set units [complete_size_units $global_options(ports_space_units)]
</span>     }
     set spaceall 0.0
     foreachport $portlist {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3247,7 +3271,8 @@ proc action_variants { action portlist opts } {
</span>     if {[require_portlist portlist]} {
         return 1
     }
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set gvariations [dict create {*}[array get ::global_variations]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global global_variations
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    set gvariations [dict create {*}[array get global_variations]]
</span>     foreachport $portlist {
         set portinfo ""
         if {$porturl eq ""} {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3342,14 +3367,15 @@ proc action_variants { action portlist opts } {
</span> 
 
 proc action_search { action portlist opts } {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set status 0
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    if {![llength $portlist] && [info exists ::private_options(ports_no_args)] && $::private_options(ports_no_args) eq "yes"} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global global_options private_options
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {![llength $portlist] && [info exists private_options(ports_no_args)] && $private_options(ports_no_args) eq "yes"} {
</span>         ui_error "You must specify a search pattern"
         return 1
     }
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    set status 0
</span> 
     # Copy global options as we are going to modify the array
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set options [array get ::global_options]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    set options [dict create {*}[array get global_options]]
</span> 
     if {[dict exists $options ports_search_depends] && [dict get $options ports_search_depends] eq "yes"} {
         dict unset options ports_search_depends
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3485,8 +3511,8 @@ proc action_search { action portlist opts } {
</span>         if { !$portfound } {
             ui_notice "No match for $portname found"
         } elseif {[llength $res] > 1} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-            if {(![info exists ::global_options(ports_search_line)]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                    || $::global_options(ports_search_line) ne "yes")} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            if {(![info exists global_options(ports_search_line)]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    || $global_options(ports_search_line) ne "yes")} {
</span>                 ui_notice "\nFound [llength $res] ports."
             }
         }
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3499,10 +3525,11 @@ proc action_search { action portlist opts } {
</span> 
 
 proc action_list { action portlist opts } {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global private_options
</span>     set status 0
 
     # Default to list all ports if no portnames are supplied
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if { ![llength $portlist] && [info exists ::private_options(ports_no_args)] && $::private_options(ports_no_args) eq "yes"} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {![llength $portlist] && [info exists private_options(ports_no_args)] && $private_options(ports_no_args) eq "yes"} {
</span>         add_to_portlist_with_defaults portlist [dict create name "-all-"]
     }
 
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3538,8 +3565,9 @@ proc action_list { action portlist opts } {
</span> 
 
 proc action_echo { action portlist opts } {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global global_options
</span>     # Simply echo back the port specs given to this command
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set gopts [dict create {*}[array get ::global_options]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    set gopts [dict create {*}[array get global_options]]
</span>     foreachport $portlist {
         if {![macports::ui_isset ports_quiet]} {
             set opts [list]
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3722,8 +3750,9 @@ proc action_portcmds { action portlist opts } {
</span> 
 
 proc action_sync { action portlist opts } {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global global_options
</span>     set status 0
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if {[catch {mportsync [array get ::global_options]} result]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {[catch {mportsync [array get global_options]} result]} {
</span>         ui_debug $::errorInfo
         ui_msg "port sync failed: $result"
         set status 1
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3734,14 +3763,15 @@ proc action_sync { action portlist opts } {
</span> 
 
 proc action_target { action portlist opts } {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set status 0
</span>     if {[require_portlist portlist]} {
         return 1
     }
     if {($action eq "install" || $action eq "archive") && ![macports::global_option_isset ports_dryrun] && [prefix_unwritable]} {
         return 1
     }
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set gvariations [dict create {*}[array get ::global_variations]]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    set status 0
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global global_variations macports::ui_options
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    set gvariations [dict create {*}[array get global_variations]]
</span>     foreachport $portlist {
         set portinfo ""
         # If we have a url, use that, since it's most specific
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3801,8 +3831,8 @@ proc action_target { action portlist opts } {
</span>             }
             if {[dict exists $portinfo known_fail] && [string is true -strict [dict get $portinfo known_fail]]
                 && ![dict exists $options ports_install_allow-failing]} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                if {[info exists macports::ui_options(questions_yesno)]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                    set retvalue [$macports::ui_options(questions_yesno) "$portname is known to fail." "KnownFail" {} {n} 0 "Try to install anyway?"]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                if {[info exists ui_options(questions_yesno)]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    set retvalue [$ui_options(questions_yesno) "$portname is known to fail." "KnownFail" {} {n} 0 "Try to install anyway?"]
</span>                     if {$retvalue != 0} {
                         break_softcontinue "$portname is known to fail" 1 status
                     }
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3847,7 +3877,8 @@ proc action_target { action portlist opts } {
</span>     }
 
     if {$status == 0 && $action eq "install" && ![macports::global_option_isset ports_dryrun]} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        if {![dict exists $opts ports_nodeps] && ![dict exists $opts ports_install_no-rev-upgrade] && ${macports::revupgrade_autorun}} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        global macports::revupgrade_autorun
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        if {![dict exists $opts ports_nodeps] && ![dict exists $opts ports_install_no-rev-upgrade] && ${revupgrade_autorun}} {
</span>             set status [action_revupgrade $action $portlist $opts]
         }
     }
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3859,7 +3890,7 @@ proc action_target { action portlist opts } {
</span> proc action_mirror { action portlist opts } {
     global macports::portdbpath
     # handle --new option here so we only delete the db once
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set mirror_filemap_path [file join $macports::portdbpath distfiles_mirror.db]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    set mirror_filemap_path [file join $portdbpath distfiles_mirror.db]
</span>     if {[dict exists $opts ports_mirror_new]
         && [string is true -strict [dict get $opts ports_mirror_new]]
         && [file exists $mirror_filemap_path]} {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3880,13 +3911,15 @@ proc action_exit { action portlist opts } {
</span> # Command Parsing
 ##########################################
 proc moreargs {} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    return [expr {$::cmd_argn < $::cmd_argc}]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global cmd_argn cmd_argc
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    return [expr {$cmd_argn < $cmd_argc}]
</span> }
 
 
 proc lookahead {} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if {$::cmd_argn < $::cmd_argc} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-        return [lindex $::cmd_argv $::cmd_argn]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global cmd_argn cmd_argc cmd_argv
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {$cmd_argn < $cmd_argc} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        return [lindex $cmd_argv $cmd_argn]
</span>     } else {
         return _EOF_
     }
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -3894,7 +3927,8 @@ proc lookahead {} {
</span> 
 
 proc advance {} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    incr ::cmd_argn
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global cmd_argn
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    incr cmd_argn
</span> }
 
 
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -4015,25 +4049,27 @@ set shellmode_action_list [list cd exit quit]
</span> # Expand "action".
 # Returns a list of matching actions.
 proc find_action { action } {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if {![dict exists $::action_array $action]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global action_array action_list ui_options shellmode_action_list
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {![dict exists $action_array $action]} {
</span>         # list of actions that are valid for this mode
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        if {![info exists ::action_list]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-            if {![info exists ::ui_options(ports_commandfiles)]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                set ::action_list [lsearch -regexp -all -inline -not [dict keys $::action_array] ^[join $::shellmode_action_list {$|^}]$]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        if {![info exists action_list]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            if {![info exists ui_options(ports_commandfiles)]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                set action_list [lsearch -regexp -all -inline -not [dict keys $action_array] ^[join $shellmode_action_list {$|^}]$]
</span>             } else {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                set ::action_list [dict keys $::action_array]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                set action_list [dict keys $action_array]
</span>             }
         }
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        return [lsearch -glob -inline -all $::action_list [string tolower $action]*]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        return [lsearch -glob -inline -all $action_list [string tolower $action]*]
</span>     }
 
     return $action
 }
 
 proc get_action_proc { action } {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global action_array
</span>     set action_proc ""
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if {[dict exists $::action_array $action]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-        set action_proc [lindex [dict get $::action_array $action] 0]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {[dict exists $action_array $action]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        set action_proc [lindex [dict get $action_array $action] 0]
</span>     }
 
     return $action_proc
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -4046,9 +4082,10 @@ proc get_action_proc { action } {
</span> #   [ACTION_ARGS_STRINGS]  Expects some strings as text argument
 #   [ACTION_ARGS_PORTS]    Wants an expanded list of ports as text argument
 proc action_needs_portlist { action } {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global action_array
</span>     set ret 0
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if {[dict exists $::action_array $action]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-        set ret [lindex [dict get $::action_array $action] 1]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {[dict exists $action_array $action]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        set ret [lindex [dict get $action_array $action] 1]
</span>     }
 
     return $ret
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -4108,13 +4145,14 @@ proc cmd_option_matches {action option} {
</span>     # This could be so easy with lsearch -index,
     # but that's only available as of Tcl 8.5
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if {![dict exists $::cmd_opts_array $action]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global cmd_opts_array
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {![dict exists $cmd_opts_array $action]} {
</span>         return [list]
     }
 
     set result [list]
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    foreach item [dict get $::cmd_opts_array $action] {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    foreach item [dict get $cmd_opts_array $action] {
</span>         if {[llength $item] == 1} {
             set name $item
             set argc 0
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -4444,9 +4482,10 @@ proc process_cmd { argv } {
</span> 
 
 proc complete_portname { text state } {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+        global complete_position complete_choices
</span>     if {$state == 0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        set ::complete_position 0
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-        set ::complete_choices [list]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        set complete_position 0
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        set complete_choices [list]
</span> 
         # Build a list of ports with text as their prefix
         if {[catch {set res [mportsearch "${text}*" false glob]} result]} {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -4454,12 +4493,12 @@ proc complete_portname { text state } {
</span>             fatal "search for portname $text failed: $result"
         }
         foreach {name info} $res {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-            lappend ::complete_choices $name
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            lappend complete_choices $name
</span>         }
     }
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set word [lindex $::complete_choices $::complete_position]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    incr ::complete_position
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    set word [lindex $complete_choices $complete_position]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    incr complete_position
</span> 
     return $word
 }
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -4467,13 +4506,14 @@ proc complete_portname { text state } {
</span> 
 # return text action beginning with $text
 proc complete_action { text state } {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global complete_position complete_choices action_array
</span>     if {$state == 0} {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        set ::complete_position 0
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-        set ::complete_choices [dict keys $::action_array [string tolower $text]*]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        set complete_position 0
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        set complete_choices [dict keys $action_array [string tolower $text]*]
</span>     }
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set word [lindex $::complete_choices $::complete_position]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    incr ::complete_position
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    set word [lindex $complete_choices $complete_position]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    incr complete_position
</span> 
     return $word
 }
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -4502,6 +4542,7 @@ proc attempt_completion { text word start end } {
</span> 
 proc get_next_cmdline { in out use_readline prompt linename history_file } {
     upvar $linename line
<span style='display:block; white-space:pre;background:#e0ffe0;'>+    global macports::macports_user_dir
</span> 
     set line ""
     while { $line eq "" } {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -4527,8 +4568,8 @@ proc get_next_cmdline { in out use_readline prompt linename history_file } {
</span> 
         if { $use_readline && $line ne "" } {
             # Create macports user directory if it does not exist yet
<span style='display:block; white-space:pre;background:#ffe0e0;'>-            if {![file isdirectory $macports::macports_user_dir]} {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                file mkdir $macports::macports_user_dir
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            if {![file isdirectory $macports_user_dir]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                file mkdir macports_user_dir
</span> 
                 # Also write the history file if this is the case (this sets
                 # the cookie at the top of the file and perhaps other things)
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -4547,15 +4588,15 @@ proc get_next_cmdline { in out use_readline prompt linename history_file } {
</span> 
 
 proc process_command_file { in } {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    global current_portdir
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    global current_portdir macports::macports_user_dir
</span> 
     # Initialize readline
     set isstdin [expr {$in eq "stdin"}]
     set use_readline [expr {$isstdin && [readline init "port"]}]
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    set history_file [file normalize "${macports::macports_user_dir}/history"]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    set history_file [file normalize ${macports_user_dir}/history]
</span> 
     # Read readline history
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if {$use_readline && [file isdirectory $macports::macports_user_dir]} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if {$use_readline && [file isdirectory $macports_user_dir]} {
</span>         rl_history read $history_file
         rl_history stifle 100
     }
</pre><pre style='margin:0'>

</pre>