Ticket #18259: quickindex-array.diff

File quickindex-array.diff, 14.1 KB (added by jmroot (Joshua Root), 15 years ago)
  • src/port/port.tcl

     
    690690            set installed_epoch     [lindex $i 5]
    691691
    692692            # Get info about the port from the index
    693             if {[catch {set res [mportsearch $portname no exact]} result]} {
     693            if {[catch {set res [mportlookup $portname]} result]} {
    694694                global errorInfo
    695695                ui_debug "$errorInfo"
    696                 fatal "search for portname $portname failed: $result"
     696                fatal "lookup of portname $portname failed: $result"
    697697            }
    698698            if {[llength $res] < 2} {
    699699                if {[macports::ui_isset ports_debug]} {
     
    13611361        # otherwise try to map the portname to a url
    13621362        if {$porturl eq ""} {
    13631363        # Verify the portname, getting portinfo to map to a porturl
    1364             if {[catch {mportsearch $portname no exact} result]} {
     1364            if {[catch {mportlookup $portname} result]} {
    13651365                ui_debug "$::errorInfo"
    1366                 break_softcontinue "search for portname $portname failed: $result" 1 status
     1366                break_softcontinue "lookup of portname $portname failed: $result" 1 status
    13671367            }
    13681368            if {[llength $result] < 2} {
    13691369                break_softcontinue "Port $portname not found" 1 status
    13701370            }
    1371             set found [expr [llength $result] / 2]
    1372             if {$found > 1} {
    1373                 ui_warn "Found $found port $portname definitions, displaying first one."
    1374             }
    13751371            array unset portinfo
    13761372            array set portinfo [lindex $result 1]
    13771373            set porturl $portinfo(porturl)
     
    17071703
    17081704    foreachport $portlist {
    17091705        if {$porturl eq ""} {
    1710             # Search for the port.
    1711             if {[catch {mportsearch $portname no exact} result]} {
     1706            # Look up the port.
     1707            if {[catch {mportlookup $portname} result]} {
    17121708                ui_debug $::errorInfo
    1713                 break_softcontinue "The search for '$portname' failed: $result" \
     1709                break_softcontinue "The lookup of '$portname' failed: $result" \
    17141710                                1 status
    17151711            }
    17161712            if {[llength $result] < 2} {
     
    21772173            set installed_epoch [lindex $i 5]
    21782174
    21792175            # Get info about the port from the index
    2180             if {[catch {set res [mportsearch $portname no exact]} result]} {
     2176            if {[catch {set res [mportlookup $portname]} result]} {
    21812177                global errorInfo
    21822178                ui_debug "$errorInfo"
    21832179                break_softcontinue "search for portname $portname failed: $result" 1 status
     
    22862282    }
    22872283    foreachport $portlist {
    22882284        if {$porturl eq ""} {
    2289             # search for port
    2290             if {[catch {mportsearch $portname no exact} result]} {
     2285            # look up port
     2286            if {[catch {mportlookup $portname} result]} {
    22912287                global errorInfo
    22922288                ui_debug "$errorInfo"
    2293                 break_softcontinue "search for portname $portname failed: $result" 1 status
     2289                break_softcontinue "lookup of portname $portname failed: $result" 1 status
    22942290            }
    22952291            if {[llength $result] < 2} {
    22962292                break_softcontinue "Port $portname not found" 1 status
     
    26032599        if {$porturl == ""} {
    26042600       
    26052601            # Verify the portname, getting portinfo to map to a porturl
    2606             if {[catch {set res [mportsearch $portname no exact]} result]} {
     2602            if {[catch {set res [mportlookup $portname]} result]} {
    26072603                global errorInfo
    26082604                ui_debug "$errorInfo"
    2609                 break_softcontinue "search for portname $portname failed: $result" 1 status
     2605                break_softcontinue "lookup of portname $portname failed: $result" 1 status
    26102606            }
    26112607            if {[llength $res] < 2} {
    26122608                break_softcontinue "Port $portname not found" 1 status
     
    27602756        # otherwise try to map the portname to a url
    27612757        if {$porturl == ""} {
    27622758            # Verify the portname, getting portinfo to map to a porturl
    2763             if {[catch {set res [mportsearch $portname no exact]} result]} {
     2759            if {[catch {set res [mportlookup $portname]} result]} {
    27642760                global errorInfo
    27652761                ui_debug "$errorInfo"
    2766                 break_softcontinue "search for portname $portname failed: $result" 1 status
     2762                break_softcontinue "lookup of portname $portname failed: $result" 1 status
    27672763            }
    27682764            if {[llength $res] < 2} {
    27692765                break_softcontinue "Port $portname not found" 1 status
  • src/port/portindex.tcl

     
    141141mporttraverse pindex $directory
    142142close $fd
    143143file rename -force $tempportindex [file join $outdir PortIndex]
     144mports_generate_quickindex [file join $outdir PortIndex]
    144145puts "\nTotal number of ports parsed:\t$stats(total)\
    145146      \nPorts successfully parsed:\t[expr $stats(total) - $stats(failed)]\t\
    146147      \nPorts failed:\t\t\t$stats(failed)\n"
  • src/macports1.0/macports.tcl

     
    710710            unsetenv $envkey
    711711        }
    712712    }
     713   
     714    # load the quick index
     715    _mports_load_quickindex
    713716}
    714717
    715718proc macports::worker_init {workername portpath porturl portbuildpath options variations} {
     
    16911694    return $matches
    16921695}
    16931696
     1697# Returns the PortInfo for a single named port. The info comes from the
     1698# PortIndex, and name matching is case-insensitive. Unlike mportsearch, only
     1699# the first match is returned, but the return format is otherwise identical.
     1700# The advantage is that mportlookup is much faster than mportsearch, due to
     1701# the use of the quick index.
     1702proc mportlookup {name} {
     1703    global macports::portdbpath macports::sources
     1704   
     1705    set sourceno 0
     1706    set matches [list]
     1707    foreach source $sources {
     1708        set source [lindex $source 0]
     1709        if {[macports::getprotocol $source] != "mports"} {
     1710            global macports::quick_index
     1711            if {![info exists quick_index($sourceno,[string tolower $name])]} {
     1712                incr sourceno 1
     1713                continue
     1714            }
     1715            # The quick index is keyed on the port name, and provides the
     1716            # offset in the main PortIndex where the given port's PortInfo
     1717            # line can be found.
     1718            set offset $quick_index($sourceno,[string tolower $name])
     1719            incr sourceno 1
     1720            if {[catch {set fd [open [macports::getindex $source] r]} result]} {
     1721                ui_warn "Can't open index file for source: $source"
     1722            } else {
     1723                try {
     1724                    seek $fd $offset
     1725                    gets $fd line
     1726                    set name [lindex $line 0]
     1727                    set len [lindex $line 1]
     1728                    set line [read $fd $len]
     1729                       
     1730                    array set portinfo $line
     1731
     1732                    switch -regexp -- [macports::getprotocol ${source}] {
     1733                        {^rsync$} {
     1734                            # Rsync files are local
     1735                            set source_url "file://[macports::getsourcepath $source]"
     1736                        }
     1737                        {^https?$|^ftp$} {
     1738                            if {[_source_is_snapshot $source filename extension]} {
     1739                                # daily snapshot tarball
     1740                                set source_url "file://[macports::getsourcepath $source]"
     1741                             } else {
     1742                                # default action
     1743                                set source_url $source
     1744                             }
     1745                        }
     1746                        default {
     1747                            set source_url $source
     1748                        }
     1749                    }
     1750                    if {[info exists portinfo(portarchive)]} {
     1751                        set porturl ${source_url}/$portinfo(portarchive)
     1752                    } elseif {[info exists portinfo(portdir)]} {
     1753                        set porturl ${source_url}/$portinfo(portdir)
     1754                    }
     1755                    if {[info exists porturl]} {
     1756                        lappend line porturl $porturl
     1757                        ui_debug "Found port in $porturl"
     1758                    } else {
     1759                        ui_debug "Found port info: $line"
     1760                    }
     1761                    lappend matches $name
     1762                    lappend matches $line
     1763                    close $fd
     1764                    break
     1765                } catch {*} {
     1766                    ui_warn "It looks like your PortIndex file may be corrupt."
     1767                    throw
     1768                } finally {
     1769                    catch {close $fd}
     1770                }
     1771            }
     1772        } else {
     1773            array set attrs [list name $name]
     1774            set res [macports::index::search $macports::portdbpath $source [array get attrs]]
     1775            if {[llength $res] > 0} {
     1776                eval lappend matches $res
     1777                break
     1778            }
     1779        }
     1780    }
     1781
     1782    return $matches
     1783}
     1784
     1785# Loads PortIndex.quick from each source into the quick_index, generating
     1786# it first if necessary.
     1787proc _mports_load_quickindex {args} {
     1788    global macports::sources macports::quick_index
     1789   
     1790    set sourceno 0
     1791    foreach source $sources {
     1792        unset -nocomplain quicklist
     1793        # chop off any tags
     1794        set source [lindex $source 0]
     1795        set index [macports::getindex $source]
     1796        if {![file exists ${index}.quick] || [file mtime ${index}] > [file mtime ${index}.quick]} {
     1797            # stale or nonexistent quick index file, so generate a new one
     1798            if {[catch {set quicklist [mports_generate_quickindex ${index}]}]} {
     1799                continue
     1800            }
     1801        }
     1802        # only need to read the quick index file if we didn't just update it
     1803        if {![info exists quicklist]} {
     1804            if {[catch {set fd [open ${index}.quick r]} result]} {
     1805                ui_warn "Can't open quick index file for source: $source"
     1806                continue
     1807            } else {
     1808                set quicklist [read $fd]
     1809                close $fd
     1810            }
     1811        }
     1812        foreach entry [split $quicklist "\n"] {
     1813            set quick_index($sourceno,[lindex $entry 0]) [lindex $entry 1]
     1814        }
     1815        incr sourceno 1
     1816    }
     1817    if {!$sourceno} {
     1818        return -code error "No index(es) found! Have you synced your source indexes?"
     1819    }
     1820}
     1821
     1822proc mports_generate_quickindex {index} {
     1823    if {[catch {set indexfd [open ${index} r]} result] || [catch {set quickfd [open ${index}.quick w]} result]} {
     1824        ui_warn "Can't open index file: $index"
     1825        return -code error
     1826    } else {
     1827        try {
     1828            set offset [tell $indexfd]
     1829            set quicklist ""
     1830            while {[gets $indexfd line] >= 0} {
     1831                if {[llength $line] != 2} {
     1832                    continue
     1833                }
     1834                set name [lindex $line 0]
     1835                append quicklist "[string tolower $name] ${offset}\n"
     1836
     1837                set len [lindex $line 1]
     1838                seek $indexfd $len current
     1839                set offset [tell $indexfd]
     1840            }
     1841            puts -nonewline $quickfd $quicklist
     1842        } catch {*} {
     1843            ui_warn "It looks like your PortIndex file may be corrupt."
     1844            throw
     1845        } finally {
     1846            close $indexfd
     1847            close $quickfd
     1848        }
     1849    }
     1850    if {[info exists quicklist]} {
     1851        return $quicklist
     1852    } else {
     1853        ui_warn "Failed to generate quick index for: $index"
     1854        return -code error
     1855    }
     1856}
     1857
    16941858proc mportinfo {mport} {
    16951859    set workername [ditem_key $mport workername]
    16961860    return [$workername eval array get PortInfo]
     
    17891953        set dep_portname [lindex [split $depspec :] end]
    17901954       
    17911955        # Find the porturl
    1792         if {[catch {set res [mportsearch $dep_portname false exact]} error]} {
     1956        if {[catch {set res [mportlookup $dep_portname]} error]} {
    17931957            global errorInfo
    17941958            ui_debug "$errorInfo"
    1795             ui_error "Internal error: port search failed: $error"
     1959            ui_error "Internal error: port lookup failed: $error"
    17961960            return 1
    17971961        }
    17981962       
    1799         unset -nocomplain porturl
    1800         foreach {name array} $res {
    1801             array set portinfo $array
    1802             if {[info exists portinfo(porturl)]} {
    1803                 set porturl $portinfo(porturl)
    1804                 break
    1805             }
    1806         }
    1807 
    1808         if {![info exists porturl]} {
     1963        array unset portinfo
     1964        array set portinfo [lindex $res 1]
     1965        if {[info exists portinfo(porturl)]} {
     1966            set porturl $portinfo(porturl)
     1967        } else {
    18091968            ui_error "Dependency '$dep_portname' not found."
    18101969            return 1
    18111970        }
     
    19742133    }
    19752134
    19762135    # check if the port is in tree
    1977     if {[catch {mportsearch $portname false exact} result]} {
     2136    if {[catch {mportlookup $portname} result]} {
    19782137        global errorInfo
    19792138        ui_debug "$errorInfo"
    1980         ui_error "port search failed: $result"
     2139        ui_error "port lookup failed: $result"
    19812140        return 1
    19822141    }
    19832142    # argh! port doesnt exist!
  • portmgr/jobs/PortIndexRegen.sh

     
    127127echo "" >> $COMMIT_MSG
    128128grep Failed $FAILURE_LOG >> $COMMIT_MSG
    129129{ cd ${SRCTREE}/dports/ && \
    130     $SVN --config-dir $SVN_CONFIG_DIR commit -F $COMMIT_MSG PortIndex > $FAILURE_LOG 2>&1 ; } \
     130    $SVN --config-dir $SVN_CONFIG_DIR commit -F $COMMIT_MSG PortIndex PortIndex.quick > $FAILURE_LOG 2>&1 ; } \
    131131    || { echo "SVN commit failed." >> $FAILURE_LOG ; bail ; }
    132132
    133133# At this point the index was committed successfuly, so we cleanup before we exit.