[116450] trunk/base/src/registry2.0

cal at macports.org cal at macports.org
Sat Jan 25 08:59:12 PST 2014


Revision: 116450
          https://trac.macports.org/changeset/116450
Author:   cal at macports.org
Date:     2014-01-25 08:59:12 -0800 (Sat, 25 Jan 2014)
Log Message:
-----------
registry2.0: Tcl cleanup, from a patch by Gustaf Neumann
 - removed numeric comparisons where not necessary
 - braced expressions to allow for bytecode compilation
 - removed unneeded calls to expr

Modified Paths:
--------------
    trunk/base/src/registry2.0/portimage.tcl
    trunk/base/src/registry2.0/portuninstall.tcl
    trunk/base/src/registry2.0/receipt_flat.tcl
    trunk/base/src/registry2.0/receipt_sqlite.tcl
    trunk/base/src/registry2.0/registry.tcl
    trunk/base/src/registry2.0/registry_util.tcl

Modified: trunk/base/src/registry2.0/portimage.tcl
===================================================================
--- trunk/base/src/registry2.0/portimage.tcl	2014-01-25 16:57:17 UTC (rev 116449)
+++ trunk/base/src/registry2.0/portimage.tcl	2014-01-25 16:59:12 UTC (rev 116450)
@@ -66,7 +66,7 @@
 
 # takes a composite version spec rather than separate version,revision,variants
 proc activate_composite {name {v ""} {optionslist ""}} {
-    if {$v == ""} {
+    if {$v eq ""} {
         return [activate $name "" "" 0 $optionslist]
     } elseif {[registry::decode_spec $v version revision variants]} {
         return [activate $name $version $revision $variants $optionslist]
@@ -107,19 +107,19 @@
         # if another version of this port is active, deactivate it first
         set current [registry::entry installed $name]
         foreach i $current {
-            if { ![string equal $specifier "[$i version]_[$i revision][$i variants]"] } {
+            if { $specifier ne "[$i version]_[$i revision][$i variants]" } {
                 lappend todeactivate $i
             }
         }
 
         # this shouldn't be possible
-        if { ![string equal [$requested installtype] "image"] } {
+        if { [$requested installtype] ne "image" } {
             return -code error "Image error: ${name} @${specifier} not installed as an image."
         }
         if {![::file isfile $location]} {
             return -code error "Image error: Can't find image file $location"
         }
-        if { [string equal [$requested state] "installed"] } {
+        if {[$requested state] eq "installed"} {
             return -code error "Image error: ${name} @${specifier} is already active."
         }
     }
@@ -137,7 +137,7 @@
 
 # takes a composite version spec rather than separate version,revision,variants
 proc deactivate_composite {name {v ""} {optionslist ""}} {
-    if {$v == ""} {
+    if {$v eq ""} {
         return [deactivate $name "" "" 0 $optionslist]
     } elseif {[registry::decode_spec $v version revision variants]} {
         return [deactivate $name $version $revision $variants $optionslist]
@@ -162,7 +162,7 @@
         set registry_open yes
     }
 
-    if { [string equal $name ""] } {
+    if {$name eq ""} {
         throw registry::image-error "Registry error: Please specify the name of the port."
     }
     set ilist [registry::entry installed $name]
@@ -175,10 +175,10 @@
     set name [$requested name]
     set specifier "[$requested version]_[$requested revision][$requested variants]"
 
-    if {$version != "" && ($version != [$requested version] ||
-        ($revision != "" && ($revision != [$requested revision] || $variants != [$requested variants])))} {
+    if {$version ne "" && ($version != [$requested version] ||
+        ($revision ne "" && ($revision != [$requested revision] || $variants != [$requested variants])))} {
         set v $version
-        if {$revision != ""} {
+        if {$revision ne ""} {
             append v _${revision}${variants}
         }
         return -code error "Active version of $name is not $v but ${specifier}."
@@ -186,11 +186,11 @@
 
     ui_msg "$UI_PREFIX [format [msgcat::mc "Deactivating %s @%s"] $name $specifier]"
 
-    if { ![string equal [$requested installtype] "image"] } {
+    if { [$requested installtype] ne "image" } {
         return -code error "Image error: ${name} @${specifier} not installed as an image."
     }
     # this shouldn't be possible
-    if { [$requested state] != "installed" } {
+    if { [$requested state] ne "installed" } {
         return -code error "Image error: ${name} @${specifier} is not active."
     }
 
@@ -207,12 +207,12 @@
 
     set searchkeys $name
     set composite_spec ""
-    if {$version != ""} {
+    if {$version ne ""} {
         lappend searchkeys $version
         set composite_spec $version
         # restriction imposed by underlying registry API (see entry.c):
         # if a revision is specified, so must variants be
-        if {$revision != ""} {
+        if {$revision ne ""} {
             lappend searchkeys $revision $variants
             append composite_spec _${revision}${variants}
         }
@@ -226,7 +226,7 @@
             set iversion [$i version]
             set irevision [$i revision]
             set ivariants [$i variants]
-            if { [$i state] == "installed" } {
+            if { [$i state] eq "installed" } {
                 ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s_%s%s (active)"] $iname $iversion $irevision $ivariants]"
             } else {
                 ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s_%s%s"] $iname $iversion $irevision $ivariants]"
@@ -236,7 +236,7 @@
     } elseif { [llength $ilist] == 1 } {
         return [lindex $ilist 0]
     }
-    if {$composite_spec != ""} {
+    if {$composite_spec ne ""} {
         set composite_spec " @${composite_spec}"
     }
     throw registry::invalid "Registry error: ${name}${composite_spec} is not installed."
@@ -469,7 +469,7 @@
                     }
                 }
 
-                if {$owner != "replaced"} {
+                if {$owner ne "replaced"} {
                     if { [string is true -strict $force] } {
                         # if we're forcing the activation, then we move any existing
                         # files to a backup file, both in the filesystem and in the
@@ -559,7 +559,7 @@
         }
         # reactivate deactivated ports
         foreach entry [array names todeactivate] {
-            if {[$entry state] == "imaged" && ($noexec || ![registry::run_target $entry activate ""])} {
+            if {[$entry state] eq "imaged" && ($noexec || ![registry::run_target $entry activate ""])} {
                 activate [$entry name] [$entry version] [$entry revision] [$entry variants] [list ports_activate_no-exec $noexec]
             }
         }
@@ -580,10 +580,10 @@
         ui_debug "$dstfile does not exist"
         return
     }
-    if { $filetype == "link" } {
+    if { $filetype eq "link" } {
         ui_debug "deactivating link: $dstfile"
         file delete -- $dstfile
-    } elseif { $filetype == "directory" } {
+    } elseif { $filetype eq "directory" } {
         # 0 item means empty.
         if { [llength [readdir $dstfile]] == 0 } {
             variable precious_dirs
@@ -606,7 +606,7 @@
     set files [list]
 
     foreach file $imagefiles {
-        if { [::file exists $file] || (![catch {::file type $file}] && [::file type $file] == "link") } {
+        if { [::file exists $file] || (![catch {::file type $file}] && [::file type $file] eq "link") } {
             # Normalize the file path to avoid removing the intermediate
             # symlinks (remove the empty directories instead)
             # Remark: paths in the registry may be not normalized.

Modified: trunk/base/src/registry2.0/portuninstall.tcl
===================================================================
--- trunk/base/src/registry2.0/portuninstall.tcl	2014-01-25 16:57:17 UTC (rev 116449)
+++ trunk/base/src/registry2.0/portuninstall.tcl	2014-01-25 16:59:12 UTC (rev 116450)
@@ -43,7 +43,7 @@
 
 # takes a composite version spec rather than separate version,revision,variants
 proc uninstall_composite {portname {v ""} {optionslist ""}} {
-    if {$v == ""} {
+    if {$v eq ""} {
         return [uninstall $portname "" "" 0 $optionslist]
     } elseif {[registry::decode_spec $v version revision variants]} {
         return [uninstall $portname $version $revision $variants $optionslist]
@@ -75,12 +75,12 @@
 
     set searchkeys $portname
     set composite_spec ""
-    if {$version != ""} {
+    if {$version ne ""} {
         lappend searchkeys $version
         set composite_spec $version
         # restriction imposed by underlying registry API (see entry.c):
         # if a revision is specified, so must variants be
-        if {$revision != ""} {
+        if {$revision ne ""} {
             lappend searchkeys $revision $variants
             append composite_spec _${revision}${variants}
         }
@@ -92,7 +92,7 @@
         ui_msg "$UI_PREFIX [msgcat::mc "The following versions of $portname are currently installed:"]"
         foreach i [portlist_sortint $ilist] {
             set ispec "[$i version]_[$i revision][$i variants]"
-            if { [string equal [$i state] installed] } {
+            if {[$i state] eq "installed"} {
                 ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s (active)"] [$i name] $ispec]"
             } else {
                 ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s"] [$i name] $ispec]"
@@ -106,7 +106,7 @@
         set variants [$port variants]
         set composite_spec "${version}_${revision}${variants}"
     } else {
-        if {$composite_spec != ""} {
+        if {$composite_spec ne ""} {
             set composite_spec " @${composite_spec}"
         }
         throw registry::invalid "Registry error: ${portname}${composite_spec} not registered as installed"
@@ -122,7 +122,7 @@
         }
         foreach depport [$port dependents] {
             # make sure it's still installed, since a previous dep uninstall may have removed it
-            if {[registry::entry exists $depport] && ([$depport state] == "imaged" || [$depport state] == "installed")} {
+            if {[registry::entry exists $depport] && ([$depport state] eq "imaged" || [$depport state] eq "installed")} {
                 if {[info exists options(ports_uninstall_no-exec)] || ![registry::run_target $depport uninstall $optionslist]} {
                     registry_uninstall::uninstall [$depport name] [$depport version] [$depport revision] [$depport variants] $optionslist
                 }
@@ -137,7 +137,7 @@
         registry::check_dependents $port ${uninstall.force} "uninstall"
     }
     # if it's active, deactivate it
-    if { [string equal [$port state] installed] } {
+    if {[$port state] eq "installed"} {
         if {[info exists options(ports_dryrun)] && [string is true -strict $options(ports_dryrun)]} {
             ui_msg "For $portname @${composite_spec}: skipping deactivate (dry run)"
         } else {

Modified: trunk/base/src/registry2.0/receipt_flat.tcl
===================================================================
--- trunk/base/src/registry2.0/receipt_flat.tcl	2014-01-25 16:57:17 UTC (rev 116449)
+++ trunk/base/src/registry2.0/receipt_flat.tcl	2014-01-25 16:59:12 UTC (rev 116450)
@@ -88,7 +88,7 @@
     }
 
     # Might as well bail out early if no file to match
-    if {![string length $matchfile]} {
+    if {$matchfile eq ""} {
 		return ""
     }
 
@@ -117,8 +117,8 @@
 	if { ![::file isdirectory $receipt_path] } {
 		set receipt_file [get_head_entry_receipt_path $name $version]
 		
-		if {![string length $receipt_file]} {
-			if { $version != "" } {
+		if {$receipt_file eq ""} {
+			if { $version ne "" } {
 				return -code error "Registry error: ${name} @${version}_${revision}${variants} not registered as installed."
 			} else {
 				return -code error "Registry error: ${name} not registered as installed."
@@ -126,13 +126,13 @@
 		}
 		
 		# Extract the version from the path.
-		if { $version == "" } {
+		if { $version eq "" } {
 			set theFileName [::file tail $receipt_file]
 			regexp "^$name-(.*)\$" $theFileName match version
 		}
 	} else {
 		# If version wasn't specified, find out the version number.
-		if { $version == "" } {
+		if { $version eq "" } {
 			# xxx: We really should have had the 
 			# version given to us.  How should we handle this?
 			set x [glob -nocomplain -directory ${receipt_path} *]
@@ -451,9 +451,9 @@
 
 	set query_path [::file join ${macports::registry.path} receipts]
 	
-	if { $name == "" } {
+	if { $name eq "" } {
 		set query_path [::file join ${query_path} *]
-		if { $version == "" } {
+		if { $version eq "" } {
 			set query_path [::file join ${query_path} *]
 		}
 		# [PG] Huh?
@@ -472,7 +472,7 @@
 	        }
 	    }
 		set query_path [::file join ${query_path} ${name}]
-		if { $version != "" } {
+		if { $version ne "" } {
 			set query_path [::file join ${query_path} ${version}]
 		} else {
 			set query_path [::file join ${query_path} *]
@@ -495,7 +495,7 @@
 	}
 
 	# append the ports in old HEAD format.
-	if { $name == "" } {
+	if { $name eq "" } {
 		set query_path [::file join ${macports::registry.path} receipts *]
 	} else {
 		set query_path [::file join ${macports::registry.path} receipts ${name}-*]
@@ -506,7 +506,7 @@
 
     	# Remark: these regexes do not always work.
    		set theName ""
-    	if { $name == "" } {
+    	if { $name eq "" } {
 			regexp {^(.*)-(.*)$} $theFileName match theName version
     	} else {
 			regexp "^($name)-(.*)\$" $theFileName match theName version
@@ -662,7 +662,7 @@
 
 	open_file_map
 
-	if { [::file type $file] == "link" } {
+	if { [::file type $file] eq "link" } {
 		ui_debug "Adding link to file_map: $file for: $port"
 	} else {
 		ui_debug "Adding file to file_map: $file for: $port"
@@ -684,7 +684,7 @@
 
 	foreach f $files {
 		set file [lindex $f 0]
-		if { [::file type $file] == "link" } {
+		if { [::file type $file] eq "link" } {
 			ui_debug "Adding link to file_map: $file for: $port"
 		} else {
 			ui_debug "Adding file to file_map: $file for: $port"
@@ -828,7 +828,7 @@
     set dep_map $new_map
     
     set newlen [llength $dep_map]
-    set diff [expr $oldlen - $newlen]
+    set diff [expr {$oldlen - $newlen}]
     ui_debug "New dep_map has $newlen entries"
     ui_info "Removed $diff duplicate entries from the dependency map"
 }

Modified: trunk/base/src/registry2.0/receipt_sqlite.tcl
===================================================================
--- trunk/base/src/registry2.0/receipt_sqlite.tcl	2014-01-25 16:57:17 UTC (rev 116449)
+++ trunk/base/src/registry2.0/receipt_sqlite.tcl	2014-01-25 16:59:12 UTC (rev 116450)
@@ -44,7 +44,7 @@
 
 # return list of active ports, or active version of port 'name' if specified
 proc active {name} {
-    if {$name != ""} {
+    if {$name ne ""} {
         set ports [registry::entry installed $name]
     } else {
         set ports [registry::entry installed]
@@ -87,7 +87,7 @@
 #
 proc file_registered {file} {
     set port [registry::entry owner $file]
-	if {$port != ""} {
+	if {$port ne ""} {
 		return [$port name]
 	} else {
 		return 0
@@ -164,9 +164,9 @@
 # version for example, so we don't attempt to split up the composite version
 # into its components, we just compare the whole thing.
 proc installed {{name ""} {version ""}} {
-	if { $name == "" && $version == "" } {
+	if { $name eq "" && $version eq "" } {
 	    set ports [registry::entry imaged]
-	} elseif { $name != "" && $version == ""} {
+	} elseif { $name ne "" && $version eq ""} {
 	    set ports [registry::entry imaged $name]
 	} else {
 	    set ports {}
@@ -197,7 +197,7 @@
 	set rlist [list]
 	set searchcmd "registry::entry search"
     foreach key {name version revision} {
-        if {[set $key] != ""} {
+        if {[set $key] ne ""} {
             append searchcmd " $key [set $key]"
         }
     }
@@ -221,7 +221,7 @@
 	set rlist [list]
 	set searchcmd "registry::entry search"
     foreach key {name version revision} {
-        if {[set $key] != ""} {
+        if {[set $key] ne ""} {
             append searchcmd " $key [set $key]"
         }
     }
@@ -251,9 +251,9 @@
         $regref location $props(location)
         $regref state $props(state)
         $regref installtype $props(installtype)
-        if {$props(installtype) == "image"} {
+        if {$props(installtype) eq "image"} {
             $regref map $props(imagefiles)
-            if {$props(state) == "installed"} {
+            if {$props(state) eq "installed"} {
                 if {[llength $props(imagefiles)] != [llength $props(files)]} {
                     # deal with this mess, just drop the extras...
                     set i 0

Modified: trunk/base/src/registry2.0/registry.tcl
===================================================================
--- trunk/base/src/registry2.0/registry.tcl	2014-01-25 16:57:17 UTC (rev 116449)
+++ trunk/base/src/registry2.0/registry.tcl	2014-01-25 16:59:12 UTC (rev 116450)
@@ -156,10 +156,10 @@
     }
     
     if { [llength $rlist] < 1 } {
-        if { $name == "" } {
+        if { $name eq "" } {
             return -code error "Registry error: No ports registered as installed."
         } else {
-            if { $version == "" } {
+            if { $version eq "" } {
                 return -code error "Registry error: $name not registered as installed."
             } else {
                 return -code error "Registry error: $name $version not registered as installed."
@@ -196,7 +196,7 @@
     }
 	
 	if { [llength $rlist] < 1 } {
-		if { $name == "" } {
+		if { $name eq "" } {
 			return -code error "Registry error: No ports registered as active."
 		} else {
 			return -code error "Registry error: $name not registered as installed & active."
@@ -320,7 +320,7 @@
     # (we won't store the md5 of the target of links since it's meaningless
     # and $statvar(mode) tells us that links are links).
     if {![catch {file lstat $fname statvar}]} {
-	if {[::file isfile $fname] && [::file type $fname] != "link"} {
+	if {[::file isfile $fname] && [::file type $fname] ne "link"} {
 	    if {[catch {md5 file $fname} md5sum] == 0} {
 		# Create a line that matches md5(1)'s output
 		# for backwards compatibility
@@ -346,7 +346,7 @@
 
 	set rval [list]
 	foreach file $flist {
-		if {[string index $file 0] != "/"} {
+		if {[string index $file 0] ne "/"} {
 			set file [::file join $prefix $file]
 		}
 		lappend rval [fileinfo_for_file $file]
@@ -405,10 +405,10 @@
         set lockfd [::open $lockpath w]
     }
     if {[catch {flock $lockfd -exclusive -noblock} result]} {
-        if {$result == "EAGAIN"} {
+        if {$result eq "EAGAIN"} {
             ui_msg "Waiting for lock on $lockpath"
             flock $lockfd -exclusive
-        } elseif {$result == "EOPNOTSUPP"} {
+        } elseif {$result eq "EOPNOTSUPP"} {
             # Locking not supported, just return
             ui_debug "flock not supported, not locking registry"
         } else {
@@ -466,7 +466,7 @@
         foreach f $contents {
             set fullpath [lindex $f 0]
             # strip image dir from start
-            if {[string range $fullpath 0 [expr $idlen - 1]] == $location} {
+            if {[string range $fullpath 0 $idlen-1] == $location} {
                 set path [string range $fullpath $idlen [string length $fullpath]]
             } else {
                 set path $fullpath

Modified: trunk/base/src/registry2.0/registry_util.tcl
===================================================================
--- trunk/base/src/registry2.0/registry_util.tcl	2014-01-25 16:57:17 UTC (rev 116449)
+++ trunk/base/src/registry2.0/registry_util.tcl	2014-01-25 16:59:12 UTC (rev 116450)
@@ -63,14 +63,14 @@
 ## @param [in] force if true, continue even if there are dependents
 proc check_dependents {port force {action "uninstall/deactivate"}} {
     global UI_PREFIX
-    if {[$port state] == "installed" || [llength [registry::entry imaged [$port name]]] == 1} {
+    if {[$port state] eq "installed" || [llength [registry::entry imaged [$port name]]] == 1} {
         # Check if any installed ports depend on this one
         set deplist [$port dependents]
-        if {$action == "deactivate"} {
+        if {$action eq "deactivate"} {
             set active_deplist {}
             # Check if any active ports depend on this one
             foreach p $deplist {
-                if {[$p state] == "installed"} {
+                if {[$p state] eq "installed"} {
                     lappend active_deplist $p
                 }
             }
@@ -94,7 +94,7 @@
 ## @return   true if successful, false otherwise
 proc run_target {port target options} {
     set portspec "[$port name] @[$port version]_[$port revision][$port variants]"
-    if {[$port portfile] == ""} {
+    if {[$port portfile] eq ""} {
         ui_debug "no portfile in registry for $portspec"
         return 0
     }
@@ -107,12 +107,12 @@
             ui_warn "Failed to execute portfile from registry for $portspec"
             switch $target {
                 activate {
-                    if {[$port state] == "installed"} {
+                    if {[$port state] eq "installed"} {
                         return 1
                     }
                 }
                 deactivate {
-                    if {[$port state] == "imaged"} {
+                    if {[$port state] eq "imaged"} {
                         return 1
                     }
                 }
@@ -124,7 +124,7 @@
             }
         } else {
             global macports::keeplogs
-            if {(![info exists keeplogs] || !$keeplogs) && $target != "activate"} {
+            if {(![info exists keeplogs] || !$keeplogs) && $target ne "activate"} {
                 catch {mportexec $mport clean}
             }
             mportclose_installed $mport
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20140125/2bd3cc5b/attachment-0001.html>


More information about the macports-changes mailing list