[59836] trunk/base

jmr at macports.org jmr at macports.org
Fri Oct 23 13:58:57 PDT 2009


Revision: 59836
          http://trac.macports.org/changeset/59836
Author:   jmr at macports.org
Date:     2009-10-23 13:58:55 -0700 (Fri, 23 Oct 2009)
Log Message:
-----------
new mportlistall proc, various slight efficiency improvements

Modified Paths:
--------------
    trunk/base/portmgr/autosubmit.tcl
    trunk/base/portmgr/jobs/PortIndex2MySQL.tcl
    trunk/base/portmgr/packaging/dpkgall.tcl
    trunk/base/src/macports1.0/macports.tcl
    trunk/base/src/port/port.tcl

Modified: trunk/base/portmgr/autosubmit.tcl
===================================================================
--- trunk/base/portmgr/autosubmit.tcl	2009-10-23 19:53:49 UTC (rev 59835)
+++ trunk/base/portmgr/autosubmit.tcl	2009-10-23 20:58:55 UTC (rev 59836)
@@ -34,7 +34,7 @@
 proc submit_ports {} {
 	global prefix submit_options verbose
 
-	if {[catch {set res [mportsearch "^.*\$"]} result]} {
+	if {[catch {set res [mportlistall]} result]} {
 		puts "port search failed: $result"
 		exit 1
 	}

Modified: trunk/base/portmgr/jobs/PortIndex2MySQL.tcl
===================================================================
--- trunk/base/portmgr/jobs/PortIndex2MySQL.tcl	2009-10-23 19:53:49 UTC (rev 59835)
+++ trunk/base/portmgr/jobs/PortIndex2MySQL.tcl	2009-10-23 20:58:55 UTC (rev 59836)
@@ -230,7 +230,7 @@
 }
 
 # Load every port in the index through a search that matches everything.
-if {[catch {set ports [mportsearch ".+"]} errstr]} {
+if {[catch {set ports [mportlistall]} errstr]} {
     ui_error "${::errorInfo}"
     ui_error "port search failed: $errstr"
     cleanup sqlfile lockfile

Modified: trunk/base/portmgr/packaging/dpkgall.tcl
===================================================================
--- trunk/base/portmgr/packaging/dpkgall.tcl	2009-10-23 19:53:49 UTC (rev 59835)
+++ trunk/base/portmgr/packaging/dpkgall.tcl	2009-10-23 20:58:55 UTC (rev 59836)
@@ -347,7 +347,7 @@
 
 	# If no portlist file was specified, create a portlist that includes all ports
 	if {[llength $portlist] == 0 || "$buildall_flag" == "true"} {
-		set res [mportsearch {.*}]
+		set res [mportlistall]
 		foreach {name array} $res {
 			lappend portlist $name
 		}
@@ -757,7 +757,7 @@
 
 proc get_portinfo {port} {
 	set searchstring [regex_escape_portname $port]
-	set res [mportsearch "^${searchstring}\$"]
+	set res [mportlookup ${searchstring}]
 
 	if {[llength $res] < 2} {
 		return -code error "Port \"$port\" not found in index."

Modified: trunk/base/src/macports1.0/macports.tcl
===================================================================
--- trunk/base/src/macports1.0/macports.tcl	2009-10-23 19:53:49 UTC (rev 59835)
+++ trunk/base/src/macports1.0/macports.tcl	2009-10-23 20:58:55 UTC (rev 59836)
@@ -975,23 +975,22 @@
 # fetched port will be downloaded to (currently only applies to
 # mports:// sources).
 proc macports::getportdir {url {destdir "."}} {
-    if {[regexp {(?x)([^:]+)://(.+)} $url match protocol string] == 1} {
-        switch -regexp -- ${protocol} {
-            {^file$} {
-                return [file normalize $string]
-            }
-            {^mports$} {
-                return [macports::index::fetch_port $url $destdir]
-            }
-            {^https?$|^ftp$} {
-                return [macports::fetch_port $url]
-            }
-            default {
-                return -code error "Unsupported protocol $protocol"
-            }
+    set protocol [macports::getprotocol $url]
+    switch ${protocol} {
+        file {
+            return [file normalize [string range $url [expr [string length $protocol] + 3] end]]
         }
-    } else {
-        return -code error "Can't parse url $url"
+        mports {
+            return [macports::index::fetch_port $url $destdir]
+        }
+        https -
+        http -
+        ftp {
+            return [macports::fetch_port $url]
+        }
+        default {
+            return -code error "Unsupported protocol $protocol"
+        }
     }
 }
 
@@ -1753,11 +1752,10 @@
 
     set found 0
     foreach source $sources {
-        set flags [lrange $source 1 end]
         set source [lindex $source 0]
-        if {[macports::getprotocol $source] == "mports"} {
-            array set attrs [list name $pattern]
-            set res [macports::index::search $macports::portdbpath $source [array get attrs]]
+        set protocol [macports::getprotocol $source]
+        if {$protocol == "mports"} {
+            set res [macports::index::search $macports::portdbpath $source [list name $pattern]]
             eval lappend matches $res
         } else {
             if {[catch {set fd [open [macports::getindex $source] r]} result]} {
@@ -1796,12 +1794,14 @@
                             if {$easy} {
                                 array set portinfo $line
                             }
-                            switch -regexp -- [macports::getprotocol ${source}] {
-                                {^rsync$} {
+                            switch $protocol {
+                                rsync {
                                     # Rsync files are local
                                     set source_url "file://[macports::getsourcepath $source]"
                                 }
-                                {^https?$|^ftp$} {
+                                https -
+                                http -
+                                ftp {
                                     if {[_source_is_snapshot $source filename extension]} {
                                         # daily snapshot tarball
                                         set source_url "file://[macports::getsourcepath $source]"
@@ -1857,7 +1857,8 @@
     set matches [list]
     foreach source $sources {
         set source [lindex $source 0]
-        if {[macports::getprotocol $source] != "mports"} {
+        set protocol [macports::getprotocol $source]
+        if {$protocol != "mports"} {
             global macports::quick_index
             if {![info exists quick_index($sourceno,[string tolower $name])]} {
                 incr sourceno 1
@@ -1880,17 +1881,16 @@
 
                     array set portinfo $line
 
-                    switch -regexp -- [macports::getprotocol ${source}] {
-                        {^rsync$} {
-                            # Rsync files are local
+                    switch $protocol {
+                        rsync {
                             set source_url "file://[macports::getsourcepath $source]"
                         }
-                        {^https?$|^ftp$} {
+                        https -
+                        http -
+                        ftp {
                             if {[_source_is_snapshot $source filename extension]} {
-                                # daily snapshot tarball
                                 set source_url "file://[macports::getsourcepath $source]"
                              } else {
-                                # default action
                                 set source_url $source
                              }
                         }
@@ -1905,9 +1905,6 @@
                     }
                     if {[info exists porturl]} {
                         lappend line porturl $porturl
-                        ui_debug "Found port in $porturl"
-                    } else {
-                        ui_debug "Found port info: $line"
                     }
                     lappend matches $name
                     lappend matches $line
@@ -1925,8 +1922,7 @@
                 }
             }
         } else {
-            array set attrs [list name $name]
-            set res [macports::index::search $macports::portdbpath $source [array get attrs]]
+            set res [macports::index::search $macports::portdbpath $source [list name $name]]
             if {[llength $res] > 0} {
                 eval lappend matches $res
                 break
@@ -1937,6 +1933,76 @@
     return $matches
 }
 
+# Returns all ports in the indices. Faster than 'mportsearch .*'
+proc mportlistall {args} {
+    global macports::portdbpath macports::sources
+    set matches [list]
+
+    set found 0
+    foreach source $sources {
+        set source [lindex $source 0]
+        set protocol [macports::getprotocol $source]
+        if {$protocol != "mports"} {
+            if {![catch {set fd [open [macports::getindex $source] r]} result]} {
+                try {
+                    incr found 1
+                    while {[gets $fd line] >= 0} {
+                        array unset portinfo
+                        set name [lindex $line 0]
+                        set len [lindex $line 1]
+                        set line [read $fd $len]
+
+                        array set portinfo $line
+
+                        switch $protocol {
+                            rsync {
+                                set source_url "file://[macports::getsourcepath $source]"
+                            }
+                            https -
+                            http -
+                            ftp {
+                                if {[_source_is_snapshot $source filename extension]} {
+                                    set source_url "file://[macports::getsourcepath $source]"
+                                } else {
+                                    set source_url $source
+                                }
+                            }
+                            default {
+                                set source_url $source
+                            }
+                        }
+                        if {[info exists portinfo(portdir)]} {
+                            set porturl ${source_url}/$portinfo(portdir)
+                        } elseif {[info exists portinfo(portarchive)]} {
+                            set porturl ${source_url}/$portinfo(portarchive)
+                        }
+                        if {[info exists porturl]} {
+                            lappend line porturl $porturl
+                        }
+                        lappend matches $name $line
+                    }
+                } catch {*} {
+                    ui_warn "It looks like your PortIndex file for $source may be corrupt."
+                    throw
+                } finally {
+                    close $fd
+                }
+            } else {
+                ui_warn "Can't open index file for source: $source"
+            }
+        } else {
+            set res [macports::index::search $macports::portdbpath $source [list name .*]]
+            eval lappend matches $res
+        }
+    }
+    if {!$found} {
+        return -code error "No index(es) found! Have you synced your source indexes?"
+    }
+
+    return $matches
+}
+
+
 # Loads PortIndex.quick from each source into the quick_index, generating
 # it first if necessary.
 proc _mports_load_quickindex {args} {

Modified: trunk/base/src/port/port.tcl
===================================================================
--- trunk/base/src/port/port.tcl	2009-10-23 19:53:49 UTC (rev 59835)
+++ trunk/base/src/port/port.tcl	2009-10-23 20:58:55 UTC (rev 59836)
@@ -588,7 +588,19 @@
     global all_ports_cache
 
     if {![info exists all_ports_cache]} {
-        set all_ports_cache [get_matching_ports "*"]
+         if {[catch {set res [mportlistall]} result]} {
+            global errorInfo
+            ui_debug "$errorInfo"
+            fatal "listing all ports failed: $result"
+        }
+        set results {}
+        foreach {name info} $res {
+            array unset portinfo
+            array set portinfo $info
+            add_to_portlist results [list url $portinfo(porturl) name $name]
+        }
+
+        set all_ports_cache [portlist_sort $results]
     }
     return $all_ports_cache
 }
@@ -2616,16 +2628,19 @@
     
     foreachport $portlist {
         if {$portname == "-all-"} {
-            set search_string ".+"
+           if {[catch {set res [mportlistall]} result]} {
+                global errorInfo
+                ui_debug "$errorInfo"
+                break_softcontinue "listing all ports failed: $result" 1 status
+            }
         } else {
             set search_string [regex_pat_sanitize $portname]
+            if {[catch {set res [mportsearch ^$search_string\$ no]} result]} {
+                global errorInfo
+                ui_debug "$errorInfo"
+                break_softcontinue "search for portname $search_string failed: $result" 1 status
+            }
         }
-        
-        if {[catch {set res [mportsearch ^$search_string\$ no]} result]} {
-            global errorInfo
-            ui_debug "$errorInfo"
-            break_softcontinue "search for portname $search_string failed: $result" 1 status
-        }
 
         foreach {name array} $res {
             array unset portinfo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20091023/83559ed1/attachment-0001.html>


More information about the macports-changes mailing list