New Ticket     Wiki     Browse Source     Timeline     Roadmap     Ticket Reports     Search

Ticket #18259: quickindex.diff

File quickindex.diff, 11.8 KB (added by jmr@…, 3 years ago)
  • 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} { 
     
    21602156            set installed_epoch [lindex $i 5] 
    21612157 
    21622158            # Get info about the port from the index 
    2163             if {[catch {set res [mportsearch $portname no exact]} result]} { 
     2159            if {[catch {set res [mportlookup $portname]} result]} { 
    21642160                global errorInfo 
    21652161                ui_debug "$errorInfo" 
    21662162                break_softcontinue "search for portname $portname failed: $result" 1 status 
     
    22682264        return 1 
    22692265    } 
    22702266    foreachport $portlist { 
    2271         # search for port 
    2272         if {[catch {mportsearch $portname no exact} result]} { 
     2267        # look up port 
     2268        if {[catch {mportlookup $portname} result]} { 
    22732269            global errorInfo 
    22742270            ui_debug "$errorInfo" 
    2275             break_softcontinue "search for portname $portname failed: $result" 1 status 
     2271            break_softcontinue "lookup of portname $portname failed: $result" 1 status 
    22762272        } 
    22772273        if {[llength $result] < 2} { 
    22782274            break_softcontinue "Port $portname not found" 1 status 
     
    25822578        if {$porturl == ""} { 
    25832579         
    25842580            # Verify the portname, getting portinfo to map to a porturl 
    2585             if {[catch {set res [mportsearch $portname no exact]} result]} { 
     2581            if {[catch {set res [mportlookup $portname]} result]} { 
    25862582                global errorInfo 
    25872583                ui_debug "$errorInfo" 
    2588                 break_softcontinue "search for portname $portname failed: $result" 1 status 
     2584                break_softcontinue "lookup of portname $portname failed: $result" 1 status 
    25892585            } 
    25902586            if {[llength $res] < 2} { 
    25912587                break_softcontinue "Port $portname not found" 1 status 
     
    27392735        # otherwise try to map the portname to a url 
    27402736        if {$porturl == ""} { 
    27412737            # Verify the portname, getting portinfo to map to a porturl 
    2742             if {[catch {set res [mportsearch $portname no exact]} result]} { 
     2738            if {[catch {set res [mportlookup $portname]} result]} { 
    27432739                global errorInfo 
    27442740                ui_debug "$errorInfo" 
    2745                 break_softcontinue "search for portname $portname failed: $result" 1 status 
     2741                break_softcontinue "lookup of portname $portname failed: $result" 1 status 
    27462742            } 
    27472743            if {[llength $res] < 2} { 
    27482744                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 
     1660proc mportlookup {name} { 
     1661    global macports::portdbpath macports::sources macports::quick_indices macports::quick_offsets 
     1662     
     1663    set found 0 
     1664    set matches [list] 
     1665    foreach source $sources { 
     1666        set source [lindex $source 0] 
     1667        if {[macports::getprotocol $source] != "mports"} { 
     1668            set result [lsearch -sorted [lindex ${quick_indices} $found] [string tolower $name]] 
     1669            if {$result == -1} { 
     1670                continue 
     1671            } 
     1672            set offset [lindex [lindex ${quick_offsets} $found] $result] 
     1673            incr found 1 
     1674            if {[catch {set fd [open [macports::getindex $source] r]} result]} { 
     1675                ui_warn "Can't open index file for source: $source" 
     1676            } else { 
     1677                try { 
     1678                    seek $fd $offset 
     1679                    gets $fd line 
     1680                    set name [lindex $line 0] 
     1681                    set len [lindex $line 1] 
     1682                    set line [read $fd $len] 
     1683                         
     1684                    array set portinfo $line 
     1685 
     1686                    switch -regexp -- [macports::getprotocol ${source}] { 
     1687                        {^rsync$} { 
     1688                            # Rsync files are local 
     1689                            set source_url "file://[macports::getsourcepath $source]" 
     1690                        } 
     1691                        {^https?$|^ftp$} { 
     1692                            if {[_source_is_snapshot $source filename extension]} { 
     1693                                # daily snapshot tarball 
     1694                                set source_url "file://[macports::getsourcepath $source]" 
     1695                             } else { 
     1696                                # default action 
     1697                                set source_url $source 
     1698                             } 
     1699                        } 
     1700                        default { 
     1701                            set source_url $source 
     1702                        } 
     1703                    } 
     1704                    if {[info exists portinfo(portarchive)]} { 
     1705                        set porturl ${source_url}/$portinfo(portarchive) 
     1706                    } elseif {[info exists portinfo(portdir)]} { 
     1707                        set porturl ${source_url}/$portinfo(portdir) 
     1708                    } 
     1709                    if {[info exists porturl]} { 
     1710                        lappend line porturl $porturl 
     1711                        ui_debug "Found port in $porturl" 
     1712                    } else { 
     1713                        ui_debug "Found port info: $line" 
     1714                    } 
     1715                    lappend matches $name 
     1716                    lappend matches $line 
     1717                    close $fd 
     1718                    break 
     1719                } catch {*} { 
     1720                    ui_warn "It looks like your PortIndex file may be corrupt." 
     1721                    throw 
     1722                } finally { 
     1723                    catch {close $fd} 
     1724                } 
     1725            } 
     1726        } else { 
     1727            array set attrs [list name $name] 
     1728            set res [macports::index::search $macports::portdbpath $source [array get attrs]] 
     1729            if {[llength $res] > 0} { 
     1730                eval lappend matches $res 
     1731                break 
     1732            } 
     1733        } 
     1734    } 
     1735 
     1736    return $matches 
     1737} 
     1738 
     1739proc _mports_load_quickindex {args} { 
     1740    global macports::sources macports::quick_indices macports::quick_offsets 
     1741     
     1742    set found 0 
     1743    set quick_indices [list] 
     1744    set quick_offsets [list] 
     1745    foreach source $sources { 
     1746        set source [lindex $source 0] 
     1747        set index [macports::getindex $source] 
     1748        if {![file exists ${index}.quick] || [file mtime ${index}] > [file mtime ${index}.quick]} { 
     1749            if {[catch {set fd [open ${index} r]} result] || [catch {set quickfd [open ${index}.quick w]} result]} { 
     1750                ui_warn "Can't open index file for source: $source" 
     1751            } else { 
     1752                try { 
     1753                    set offset [tell $fd] 
     1754                    set quicklist [list] 
     1755                    while {[gets $fd line] >= 0} { 
     1756                        if {[llength $line] != 2} { 
     1757                            continue 
     1758                        } 
     1759                        set name [lindex $line 0] 
     1760                        lappend quicklist [list [string tolower $name] $offset] 
     1761                         
     1762                        set len [lindex $line 1] 
     1763                        seek $fd $len current 
     1764                        set offset [tell $fd] 
     1765                    } 
     1766                    puts $quickfd [lsort -index 0 $quicklist] 
     1767                } catch {*} { 
     1768                    ui_warn "It looks like your PortIndex file may be corrupt." 
     1769                    throw 
     1770                } finally { 
     1771                    close $fd 
     1772                    close $quickfd 
     1773                } 
     1774            } 
     1775        } 
     1776        # quick index should now exist 
     1777        if {[catch {set fd [open ${index}.quick r]} result]} { 
     1778            ui_warn "Can't open quick index file for source: $source" 
     1779        } else { 
     1780            incr found 1 
     1781            set quicklist [gets $fd] 
     1782            close $fd 
     1783            foreach l $quicklist { 
     1784                lappend this_indices [lindex $l 0] 
     1785                lappend this_offsets [lindex $l 1] 
     1786            } 
     1787            lappend quick_indices $this_indices 
     1788            lappend quick_offsets $this_offsets 
     1789        } 
     1790    } 
     1791    if {!$found} { 
     1792        return -code error "No index(es) found! Have you synced your source indexes?" 
     1793    } 
     1794} 
     1795 
    16571796proc mportinfo {mport} { 
    16581797    set workername [ditem_key $mport workername] 
    16591798    return [$workername eval array get PortInfo] 
     
    17561895        } 
    17571896         
    17581897        # Find the porturl 
    1759         if {[catch {set res [mportsearch $dep_portname false exact]} error]} { 
     1898        if {[catch {set res [mportlookup $dep_portname]} error]} { 
    17601899            global errorInfo 
    17611900            ui_debug "$errorInfo" 
    1762             ui_error "Internal error: port search failed: $error" 
     1901            ui_error "Internal error: port lookup failed: $error" 
    17631902            return 1 
    17641903        } 
    17651904         
    17661905        unset -nocomplain porturl 
    1767         foreach {name array} $res { 
    1768             array set portinfo $array 
    1769             if {[info exists portinfo(porturl)]} { 
    1770                 set porturl $portinfo(porturl) 
    1771                 break 
    1772             } 
     1906        array set portinfo [lindex $res 1] 
     1907        if {[info exists portinfo(porturl)]} { 
     1908            set porturl $portinfo(porturl) 
    17731909        } 
    17741910 
    17751911        if {![info exists porturl]} { 
     
    19382074    } 
    19392075 
    19402076    # check if the port is in tree 
    1941     if {[catch {mportsearch $portname false exact} result]} { 
     2077    if {[catch {mportlookup $portname} result]} { 
    19422078        global errorInfo 
    19432079        ui_debug "$errorInfo" 
    1944         ui_error "port search failed: $result" 
     2080        ui_error "port lookup failed: $result" 
    19452081        return 1 
    19462082    } 
    19472083    # argh! port doesnt exist!