Ticket #18259: quickindex-array-blb.diff
File quickindex-array-blb.diff, 12.8 KB (added by blb@…, 16 years ago) |
---|
-
src/port/port.tcl
684 684 set installed_epoch [lindex $i 5] 685 685 686 686 # Get info about the port from the index 687 if {[catch {set res [mport search $portname no exact]} result]} {687 if {[catch {set res [mportlookup $portname]} result]} { 688 688 global errorInfo 689 689 ui_debug "$errorInfo" 690 fatal " search forportname $portname failed: $result"690 fatal "lookup of portname $portname failed: $result" 691 691 } 692 692 if {[llength $res] < 2} { 693 693 if {[macports::ui_isset ports_debug]} { … … 1355 1355 # otherwise try to map the portname to a url 1356 1356 if {$porturl eq ""} { 1357 1357 # Verify the portname, getting portinfo to map to a porturl 1358 if {[catch {mport search $portname no exact} result]} {1358 if {[catch {mportlookup $portname} result]} { 1359 1359 ui_debug "$::errorInfo" 1360 break_softcontinue " search forportname $portname failed: $result" 1 status1360 break_softcontinue "lookup of portname $portname failed: $result" 1 status 1361 1361 } 1362 1362 if {[llength $result] < 2} { 1363 1363 break_softcontinue "Port $portname not found" 1 status 1364 1364 } 1365 set found [expr [llength $result] / 2]1366 if {$found > 1} {1367 ui_warn "Found $found port $portname definitions, displaying first one."1368 }1369 1365 array unset portinfo 1370 1366 array set portinfo [lindex $result 1] 1371 1367 set porturl $portinfo(porturl) … … 1700 1696 } 1701 1697 1702 1698 foreachport $portlist { 1703 # Search forthe port.1704 if {[catch {mport search $portname no exact} result]} {1699 # Look up the port. 1700 if {[catch {mportlookup $portname} result]} { 1705 1701 ui_debug $::errorInfo 1706 break_softcontinue "The search for'$portname' failed: $result" \1702 break_softcontinue "The lookup of '$portname' failed: $result" \ 1707 1703 1 status 1708 1704 } 1709 1705 if {[llength $result] < 2} { … … 2162 2158 set installed_epoch [lindex $i 5] 2163 2159 2164 2160 # Get info about the port from the index 2165 if {[catch {set res [mport search $portname no exact]} result]} {2161 if {[catch {set res [mportlookup $portname]} result]} { 2166 2162 global errorInfo 2167 2163 ui_debug "$errorInfo" 2168 2164 break_softcontinue "search for portname $portname failed: $result" 1 status … … 2270 2266 return 1 2271 2267 } 2272 2268 foreachport $portlist { 2273 # search forport2274 if {[catch {mport search $portname no exact} result]} {2269 # look up port 2270 if {[catch {mportlookup $portname} result]} { 2275 2271 global errorInfo 2276 2272 ui_debug "$errorInfo" 2277 break_softcontinue " search forportname $portname failed: $result" 1 status2273 break_softcontinue "lookup of portname $portname failed: $result" 1 status 2278 2274 } 2279 2275 if {[llength $result] < 2} { 2280 2276 break_softcontinue "Port $portname not found" 1 status … … 2584 2580 if {$porturl == ""} { 2585 2581 2586 2582 # Verify the portname, getting portinfo to map to a porturl 2587 if {[catch {set res [mport search $portname no exact]} result]} {2583 if {[catch {set res [mportlookup $portname]} result]} { 2588 2584 global errorInfo 2589 2585 ui_debug "$errorInfo" 2590 break_softcontinue " search forportname $portname failed: $result" 1 status2586 break_softcontinue "lookup of portname $portname failed: $result" 1 status 2591 2587 } 2592 2588 if {[llength $res] < 2} { 2593 2589 break_softcontinue "Port $portname not found" 1 status … … 2741 2737 # otherwise try to map the portname to a url 2742 2738 if {$porturl == ""} { 2743 2739 # Verify the portname, getting portinfo to map to a porturl 2744 if {[catch {set res [mport search $portname no exact]} result]} {2740 if {[catch {set res [mportlookup $portname]} result]} { 2745 2741 global errorInfo 2746 2742 ui_debug "$errorInfo" 2747 break_softcontinue " search forportname $portname failed: $result" 1 status2743 break_softcontinue "lookup of portname $portname failed: $result" 1 status 2748 2744 } 2749 2745 if {[llength $res] < 2} { 2750 2746 break_softcontinue "Port $portname not found" 1 status -
src/macports1.0/macports.tcl
708 708 unsetenv $envkey 709 709 } 710 710 } 711 712 # load the quick index 713 _mports_load_quickindex 711 714 } 712 715 713 716 proc macports::worker_init {workername portpath porturl portbuildpath options variations} { … … 1654 1657 return $matches 1655 1658 } 1656 1659 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. 1665 proc 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. 1750 proc _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 1657 1811 proc mportinfo {mport} { 1658 1812 set workername [ditem_key $mport workername] 1659 1813 return [$workername eval array get PortInfo] … … 1752 1906 set dep_portname [lindex [split $depspec :] end] 1753 1907 1754 1908 # Find the porturl 1755 if {[catch {set res [mport search $dep_portname false exact]} error]} {1909 if {[catch {set res [mportlookup $dep_portname]} error]} { 1756 1910 global errorInfo 1757 1911 ui_debug "$errorInfo" 1758 ui_error "Internal error: port searchfailed: $error"1912 ui_error "Internal error: port lookup failed: $error" 1759 1913 return 1 1760 1914 } 1761 1915 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 { 1772 1921 ui_error "Dependency '$dep_portname' not found." 1773 1922 return 1 1774 1923 } … … 1937 2086 } 1938 2087 1939 2088 # check if the port is in tree 1940 if {[catch {mport search $portname false exact} result]} {2089 if {[catch {mportlookup $portname} result]} { 1941 2090 global errorInfo 1942 2091 ui_debug "$errorInfo" 1943 ui_error "port searchfailed: $result"2092 ui_error "port lookup failed: $result" 1944 2093 return 1 1945 2094 } 1946 2095 # argh! port doesnt exist!