Ticket #18259: macports.tcl.diff

File macports.tcl.diff, 7.9 KB (added by blb@…, 15 years ago)

patch to base/src/macports1.0/macports.tcl

  • base/src/macports1.0/macports.tcl

    old new  
    15551555    mportsearch $pattern $case_sensitive $matchstyle $field
    15561556}
    15571557
    1558 proc mportsearch {pattern {case_sensitive yes} {matchstyle regexp} {field name}} {
    1559     global macports::portdbpath macports::sources
    1560     set matches [list]
    1561     set easy [expr { $field == "name" }]
    1562    
     1558proc mportsearch_load_portindex {} {
     1559    global macports::sources
     1560    global macports::mportsearch_portindex
    15631561    set found 0
    15641562    foreach source $sources {
    1565         set flags [lrange $source 1 end]
    1566         set source [lindex $source 0]
    1567         if {[macports::getprotocol $source] == "mports"} {
    1568             array set attrs [list name $pattern]
    1569             set res [macports::index::search $macports::portdbpath $source [array get attrs]]
    1570             eval lappend matches $res
    1571         } else {
    1572             if {[catch {set fd [open [macports::getindex $source] r]} result]} {
    1573                 ui_warn "Can't open index file for source: $source"
     1563        set sourceURL [lindex $source 0]
     1564        if {[macports::getprotocol $sourceURL] != "mports"} {
     1565            if {[catch {set fd [open [macports::getindex $sourceURL] r]} result]} {
     1566                ui_warn "Can't open index file for source $sourceURL"
    15741567            } else {
    15751568                try {
    15761569                    incr found 1
    15771570                    while {[gets $fd line] >= 0} {
    1578                         array unset portinfo
    15791571                        set name [lindex $line 0]
    15801572                        set len [lindex $line 1]
    15811573                        set line [read $fd $len]
    1582                        
    1583                         if {$easy} {
    1584                             set target $name
    1585                         } else {
    1586                             array set portinfo $line
    1587                             if {![info exists portinfo($field)]} continue
    1588                             set target $portinfo($field)
    1589                         }
    1590                        
    1591                         switch $matchstyle {
    1592                             exact {
    1593                                 set matchres [expr 0 == ( {$case_sensitive == "yes"} ? [string compare $pattern $target] : [string compare -nocase $pattern $target] )]
    1594                             }
    1595                             glob {
    1596                                 set matchres [expr {$case_sensitive == "yes"} ? [string match $pattern $target] : [string match -nocase $pattern $target]]
    1597                             }
    1598                             regexp -
    1599                             default {
    1600                                 set matchres [expr {$case_sensitive == "yes"} ? [regexp -- $pattern $target] : [regexp -nocase -- $pattern $target]]
    1601                             }
    1602                         }
    1603                        
    1604                         if {$matchres == 1} {
    1605                             if {$easy} {
    1606                                 array set portinfo $line
    1607                             }
    1608                             switch -regexp -- [macports::getprotocol ${source}] {
    1609                                 {^rsync$} {
    1610                                     # Rsync files are local
    1611                                     set source_url "file://[macports::getsourcepath $source]"
    1612                                 }
    1613                                 {^https?$|^ftp$} {
    1614                                     if {[_source_is_snapshot $source filename extension]} {
    1615                                         # daily snapshot tarball
    1616                                         set source_url "file://[macports::getsourcepath $source]"
    1617                                     } else {
    1618                                         # default action
    1619                                         set source_url $source
    1620                                     }
    1621                                 }
    1622                                 default {
    1623                                     set source_url $source
    1624                                 }
    1625                             }
    1626                             if {[info exists portinfo(portarchive)]} {
    1627                                 set porturl ${source_url}/$portinfo(portarchive)
    1628                             } elseif {[info exists portinfo(portdir)]} {
    1629                                 set porturl ${source_url}/$portinfo(portdir)
    1630                             }
    1631                             if {[info exists porturl]} {
    1632                                 lappend line porturl $porturl
    1633                                 ui_debug "Found port in $porturl"
    1634                             } else {
    1635                                 ui_debug "Found port info: $line"
    1636                             }
    1637                             lappend matches $name
    1638                             lappend matches $line
    1639                         }
     1574                        set macports::mportsearch_portindex([list $sourceURL $name]) $line
    16401575                    }
    16411576                } catch {*} {
    16421577                    ui_warn "It looks like your PortIndex file may be corrupt."
     
    16471582            }
    16481583        }
    16491584    }
     1585
    16501586    if {!$found} {
    16511587        return -code error "No index(es) found! Have you synced your source indexes?"
    16521588    }
     1589}
     1590
     1591proc mportsearch {pattern {case_sensitive yes} {matchstyle regexp} {field name}} {
     1592    global macports::mportsearch_portindex
     1593    if {![array exists macports::mportsearch_portindex]} {
     1594        mportsearch_load_portindex
     1595    }
     1596
     1597    set matches [list]
     1598    set easy [expr { $field == "name" }]
     1599   
     1600    foreach {port_url_and_name line} [array get macports::mportsearch_portindex] {
     1601        array unset portinfo
     1602        set source [lindex $port_url_and_name 0]
     1603        set name [lindex $port_url_and_name 1]
     1604        if {$easy} {
     1605            set target $name
     1606        } else {
     1607            array set portinfo $line
     1608            if {![info exists portinfo($field)]} continue
     1609            set target $portinfo($field)
     1610        }
     1611
     1612        switch $matchstyle {
     1613            exact {
     1614                set matchres [expr 0 == ( {$case_sensitive == "yes"} ? [string compare $pattern $target] : [string compare -nocase $pattern $target] )]
     1615            }
     1616            glob {
     1617                set matchres [expr {$case_sensitive == "yes"} ? [string match $pattern $target] : [string match -nocase $pattern $target]]
     1618            }
     1619            regexp -
     1620            default {
     1621                set matchres [expr {$case_sensitive == "yes"} ? [regexp -- $pattern $target] : [regexp -nocase -- $pattern $target]]
     1622            }
     1623        }
     1624       
     1625        if {$matchres == 1} {
     1626            if {$easy} {
     1627                array set portinfo $line
     1628            }
     1629            switch -regexp -- [macports::getprotocol ${source}] {
     1630                {^rsync$} {
     1631                    # Rsync files are local
     1632                    set source_url "file://[macports::getsourcepath $source]"
     1633                }
     1634                {^https?$|^ftp$} {
     1635                    if {[_source_is_snapshot $source filename extension]} {
     1636                        # daily snapshot tarball
     1637                        set source_url "file://[macports::getsourcepath $source]"
     1638                    } else {
     1639                        # default action
     1640                        set source_url $source
     1641                    }
     1642                }
     1643                default {
     1644                    set source_url $source
     1645                }
     1646            }
     1647            if {[info exists portinfo(portarchive)]} {
     1648                set porturl ${source_url}/$portinfo(portarchive)
     1649            } elseif {[info exists portinfo(portdir)]} {
     1650                set porturl ${source_url}/$portinfo(portdir)
     1651            }
     1652            if {[info exists porturl]} {
     1653                lappend line porturl $porturl
     1654                ui_debug "Found port in $porturl"
     1655            } else {
     1656                ui_debug "Found port info: $line"
     1657            }
     1658            lappend matches $name
     1659            lappend matches $line
     1660        }
     1661    }
    16531662
    16541663    return $matches
    16551664}