New Ticket     Wiki     Browse Source     Timeline     Roadmap     Ticket Reports     Search

Ticket #18259: quickindex-array-blb.diff

File quickindex-array-blb.diff, 12.8 KB (added by blb@…, 3 years ago)

New patch to fix issue with multiple repos

  • src/port/port.tcl

     
    684684            set installed_epoch     [lindex $i 5] 
    685685 
    686686            # Get info about the port from the index 
    687             if {[catch {set res [mportsearch $portname no exact]} result]} { 
     687            if {[catch {set res [mportlookup $portname]} result]} { 
    688688                global errorInfo 
    689689                ui_debug "$errorInfo" 
    690                 fatal "search for portname $portname failed: $result" 
     690                fatal "lookup of portname $portname failed: $result" 
    691691            } 
    692692            if {[llength $res] < 2} { 
    693693                if {[macports::ui_isset ports_debug]} { 
     
    13551355        # otherwise try to map the portname to a url 
    13561356        if {$porturl eq ""} { 
    13571357        # Verify the portname, getting portinfo to map to a porturl 
    1358             if {[catch {mportsearch $portname no exact} result]} { 
     1358            if {[catch {mportlookup $portname} result]} { 
    13591359                ui_debug "$::errorInfo" 
    1360                 break_softcontinue "search for portname $portname failed: $result" 1 status 
     1360                break_softcontinue "lookup of portname $portname failed: $result" 1 status 
    13611361            } 
    13621362            if {[llength $result] < 2} { 
    13631363                break_softcontinue "Port $portname not found" 1 status 
    13641364            } 
    1365             set found [expr [llength $result] / 2] 
    1366             if {$found > 1} { 
    1367                 ui_warn "Found $found port $portname definitions, displaying first one." 
    1368             } 
    13691365            array unset portinfo 
    13701366            array set portinfo [lindex $result 1] 
    13711367            set porturl $portinfo(porturl) 
     
    17001696    } 
    17011697 
    17021698    foreachport $portlist { 
    1703         # Search for the port. 
    1704         if {[catch {mportsearch $portname no exact} result]} { 
     1699        # Look up the port. 
     1700        if {[catch {mportlookup $portname} result]} { 
    17051701            ui_debug $::errorInfo 
    1706             break_softcontinue "The search for '$portname' failed: $result" \ 
     1702            break_softcontinue "The lookup of '$portname' failed: $result" \ 
    17071703                               1 status 
    17081704        } 
    17091705        if {[llength $result] < 2} { 
     
    21622158            set installed_epoch [lindex $i 5] 
    21632159 
    21642160            # Get info about the port from the index 
    2165             if {[catch {set res [mportsearch $portname no exact]} result]} { 
     2161            if {[catch {set res [mportlookup $portname]} result]} { 
    21662162                global errorInfo 
    21672163                ui_debug "$errorInfo" 
    21682164                break_softcontinue "search for portname $portname failed: $result" 1 status 
     
    22702266        return 1 
    22712267    } 
    22722268    foreachport $portlist { 
    2273         # search for port 
    2274         if {[catch {mportsearch $portname no exact} result]} { 
     2269        # look up port 
     2270        if {[catch {mportlookup $portname} result]} { 
    22752271            global errorInfo 
    22762272            ui_debug "$errorInfo" 
    2277             break_softcontinue "search for portname $portname failed: $result" 1 status 
     2273            break_softcontinue "lookup of portname $portname failed: $result" 1 status 
    22782274        } 
    22792275        if {[llength $result] < 2} { 
    22802276            break_softcontinue "Port $portname not found" 1 status 
     
    25842580        if {$porturl == ""} { 
    25852581         
    25862582            # Verify the portname, getting portinfo to map to a porturl 
    2587             if {[catch {set res [mportsearch $portname no exact]} result]} { 
     2583            if {[catch {set res [mportlookup $portname]} result]} { 
    25882584                global errorInfo 
    25892585                ui_debug "$errorInfo" 
    2590                 break_softcontinue "search for portname $portname failed: $result" 1 status 
     2586                break_softcontinue "lookup of portname $portname failed: $result" 1 status 
    25912587            } 
    25922588            if {[llength $res] < 2} { 
    25932589                break_softcontinue "Port $portname not found" 1 status 
     
    27412737        # otherwise try to map the portname to a url 
    27422738        if {$porturl == ""} { 
    27432739            # Verify the portname, getting portinfo to map to a porturl 
    2744             if {[catch {set res [mportsearch $portname no exact]} result]} { 
     2740            if {[catch {set res [mportlookup $portname]} result]} { 
    27452741                global errorInfo 
    27462742                ui_debug "$errorInfo" 
    2747                 break_softcontinue "search for portname $portname failed: $result" 1 status 
     2743                break_softcontinue "lookup of portname $portname failed: $result" 1 status 
    27482744            } 
    27492745            if {[llength $res] < 2} { 
    27502746                break_softcontinue "Port $portname not found" 1 status 
  • src/macports1.0/macports.tcl

     
    708708            unsetenv $envkey 
    709709        } 
    710710    } 
     711     
     712    # load the quick index 
     713    _mports_load_quickindex 
    711714} 
    712715 
    713716proc macports::worker_init {workername portpath porturl portbuildpath options variations} { 
     
    16541657    return $matches 
    16551658} 
    16561659 
     1660# Returns the PortInfo for a single named port. The info comes from the 
     1661# PortIndex, and name matching is case-insensitive. Unlike mportsearch, only 
     1662# the first match is returned, but the return format is otherwise identical. 
     1663# The advantage is that mportlookup is much faster than mportsearch, due to 
     1664# the use of the quick index. 
     1665proc mportlookup {name} { 
     1666    global macports::portdbpath macports::sources 
     1667     
     1668    set sourceno 0 
     1669    set matches [list] 
     1670    foreach source $sources { 
     1671        set source [lindex $source 0] 
     1672        if {[macports::getprotocol $source] != "mports"} { 
     1673            global macports::quick_index 
     1674            if {![info exists quick_index($sourceno,[string tolower $name])]} { 
     1675                incr sourceno 1 
     1676                continue 
     1677            } 
     1678            # The quick index is keyed on the port name, and provides the 
     1679            # offset in the main PortIndex where the given port's PortInfo 
     1680            # line can be found. 
     1681            set offset $quick_index($sourceno,[string tolower $name]) 
     1682            incr sourceno 1 
     1683            if {[catch {set fd [open [macports::getindex $source] r]} result]} { 
     1684                ui_warn "Can't open index file for source: $source" 
     1685            } else { 
     1686                try { 
     1687                    seek $fd $offset 
     1688                    gets $fd line 
     1689                    set name [lindex $line 0] 
     1690                    set len [lindex $line 1] 
     1691                    set line [read $fd $len] 
     1692                         
     1693                    array set portinfo $line 
     1694 
     1695                    switch -regexp -- [macports::getprotocol ${source}] { 
     1696                        {^rsync$} { 
     1697                            # Rsync files are local 
     1698                            set source_url "file://[macports::getsourcepath $source]" 
     1699                        } 
     1700                        {^https?$|^ftp$} { 
     1701                            if {[_source_is_snapshot $source filename extension]} { 
     1702                                # daily snapshot tarball 
     1703                                set source_url "file://[macports::getsourcepath $source]" 
     1704                             } else { 
     1705                                # default action 
     1706                                set source_url $source 
     1707                             } 
     1708                        } 
     1709                        default { 
     1710                            set source_url $source 
     1711                        } 
     1712                    } 
     1713                    if {[info exists portinfo(portarchive)]} { 
     1714                        set porturl ${source_url}/$portinfo(portarchive) 
     1715                    } elseif {[info exists portinfo(portdir)]} { 
     1716                        set porturl ${source_url}/$portinfo(portdir) 
     1717                    } 
     1718                    if {[info exists porturl]} { 
     1719                        lappend line porturl $porturl 
     1720                        ui_debug "Found port in $porturl" 
     1721                    } else { 
     1722                        ui_debug "Found port info: $line" 
     1723                    } 
     1724                    lappend matches $name 
     1725                    lappend matches $line 
     1726                    close $fd 
     1727                    break 
     1728                } catch {*} { 
     1729                    ui_warn "It looks like your PortIndex file may be corrupt." 
     1730                    throw 
     1731                } finally { 
     1732                    catch {close $fd} 
     1733                } 
     1734            } 
     1735        } else { 
     1736            array set attrs [list name $name] 
     1737            set res [macports::index::search $macports::portdbpath $source [array get attrs]] 
     1738            if {[llength $res] > 0} { 
     1739                eval lappend matches $res 
     1740                break 
     1741            } 
     1742        } 
     1743    } 
     1744 
     1745    return $matches 
     1746} 
     1747 
     1748# Loads PortIndex.quick from each source into the quick_index, generating 
     1749# it first if necessary. 
     1750proc _mports_load_quickindex {args} { 
     1751    global macports::sources macports::quick_index 
     1752     
     1753    set sourceno 0 
     1754    foreach source $sources { 
     1755        if {[info exists quicklist]} { 
     1756            unset quicklist 
     1757        } 
     1758        # chop off any tags 
     1759        set source [lindex $source 0] 
     1760        set index [macports::getindex $source] 
     1761        if {![file exists ${index}.quick] || [file mtime ${index}] > [file mtime ${index}.quick]} { 
     1762            # stale or nonexistent quick index file, so generate a new one 
     1763            if {[catch {set indexfd [open ${index} r]} result] || [catch {set quickfd [open ${index}.quick w]} result]} { 
     1764                ui_warn "Can't open index file for source: $source" 
     1765            } else { 
     1766                try { 
     1767                    set offset [tell $indexfd] 
     1768                    set quicklist [list] 
     1769                    while {[gets $indexfd line] >= 0} { 
     1770                        if {[llength $line] != 2} { 
     1771                            continue 
     1772                        } 
     1773                        set name [lindex $line 0] 
     1774                        lappend quicklist [list [string tolower $name] $offset] 
     1775                         
     1776                        set len [lindex $line 1] 
     1777                        seek $indexfd $len current 
     1778                        set offset [tell $indexfd] 
     1779                    } 
     1780                    set quicklist [lsort -index 0 $quicklist] 
     1781                    puts $quickfd $quicklist 
     1782                } catch {*} { 
     1783                    ui_warn "It looks like your PortIndex file may be corrupt." 
     1784                    throw 
     1785                } finally { 
     1786                    close $indexfd 
     1787                    close $quickfd 
     1788                } 
     1789            } 
     1790        } 
     1791        # only need to read the quick index file if we didn't just update it 
     1792        if {![info exists quicklist]} { 
     1793            if {[catch {set fd [open ${index}.quick r]} result]} { 
     1794                ui_warn "Can't open quick index file for source: $source" 
     1795                continue 
     1796            } else { 
     1797                set quicklist [gets $fd] 
     1798                close $fd 
     1799            } 
     1800        } 
     1801        foreach entry $quicklist { 
     1802            set quick_index($sourceno,[lindex $entry 0]) [lindex $entry 1] 
     1803        } 
     1804        incr sourceno 1 
     1805    } 
     1806    if {!$sourceno} { 
     1807        return -code error "No index(es) found! Have you synced your source indexes?" 
     1808    } 
     1809} 
     1810 
    16571811proc mportinfo {mport} { 
    16581812    set workername [ditem_key $mport workername] 
    16591813    return [$workername eval array get PortInfo] 
     
    17521906        set dep_portname [lindex [split $depspec :] end] 
    17531907         
    17541908        # Find the porturl 
    1755         if {[catch {set res [mportsearch $dep_portname false exact]} error]} { 
     1909        if {[catch {set res [mportlookup $dep_portname]} error]} { 
    17561910            global errorInfo 
    17571911            ui_debug "$errorInfo" 
    1758             ui_error "Internal error: port search failed: $error" 
     1912            ui_error "Internal error: port lookup failed: $error" 
    17591913            return 1 
    17601914        } 
    17611915         
    1762         unset -nocomplain porturl 
    1763         foreach {name array} $res { 
    1764             array set portinfo $array 
    1765             if {[info exists portinfo(porturl)]} { 
    1766                 set porturl $portinfo(porturl) 
    1767                 break 
    1768             } 
    1769         } 
    1770  
    1771         if {![info exists porturl]} { 
     1916        array unset portinfo 
     1917        array set portinfo [lindex $res 1] 
     1918        if {[info exists portinfo(porturl)]} { 
     1919            set porturl $portinfo(porturl) 
     1920        } else { 
    17721921            ui_error "Dependency '$dep_portname' not found." 
    17731922            return 1 
    17741923        } 
     
    19372086    } 
    19382087 
    19392088    # check if the port is in tree 
    1940     if {[catch {mportsearch $portname false exact} result]} { 
     2089    if {[catch {mportlookup $portname} result]} { 
    19412090        global errorInfo 
    19422091        ui_debug "$errorInfo" 
    1943         ui_error "port search failed: $result" 
     2092        ui_error "port lookup failed: $result" 
    19442093        return 1 
    19452094    } 
    19462095    # argh! port doesnt exist!