Ticket #18259: quickindex-array.diff
File quickindex-array.diff, 14.1 KB (added by jmroot (Joshua Root), 16 years ago) |
---|
-
src/port/port.tcl
690 690 set installed_epoch [lindex $i 5] 691 691 692 692 # Get info about the port from the index 693 if {[catch {set res [mport search $portname no exact]} result]} {693 if {[catch {set res [mportlookup $portname]} result]} { 694 694 global errorInfo 695 695 ui_debug "$errorInfo" 696 fatal " search forportname $portname failed: $result"696 fatal "lookup of portname $portname failed: $result" 697 697 } 698 698 if {[llength $res] < 2} { 699 699 if {[macports::ui_isset ports_debug]} { … … 1361 1361 # otherwise try to map the portname to a url 1362 1362 if {$porturl eq ""} { 1363 1363 # Verify the portname, getting portinfo to map to a porturl 1364 if {[catch {mport search $portname no exact} result]} {1364 if {[catch {mportlookup $portname} result]} { 1365 1365 ui_debug "$::errorInfo" 1366 break_softcontinue " search forportname $portname failed: $result" 1 status1366 break_softcontinue "lookup of portname $portname failed: $result" 1 status 1367 1367 } 1368 1368 if {[llength $result] < 2} { 1369 1369 break_softcontinue "Port $portname not found" 1 status 1370 1370 } 1371 set found [expr [llength $result] / 2]1372 if {$found > 1} {1373 ui_warn "Found $found port $portname definitions, displaying first one."1374 }1375 1371 array unset portinfo 1376 1372 array set portinfo [lindex $result 1] 1377 1373 set porturl $portinfo(porturl) … … 1707 1703 1708 1704 foreachport $portlist { 1709 1705 if {$porturl eq ""} { 1710 # Search forthe port.1711 if {[catch {mport search $portname no exact} result]} {1706 # Look up the port. 1707 if {[catch {mportlookup $portname} result]} { 1712 1708 ui_debug $::errorInfo 1713 break_softcontinue "The search for'$portname' failed: $result" \1709 break_softcontinue "The lookup of '$portname' failed: $result" \ 1714 1710 1 status 1715 1711 } 1716 1712 if {[llength $result] < 2} { … … 2177 2173 set installed_epoch [lindex $i 5] 2178 2174 2179 2175 # Get info about the port from the index 2180 if {[catch {set res [mport search $portname no exact]} result]} {2176 if {[catch {set res [mportlookup $portname]} result]} { 2181 2177 global errorInfo 2182 2178 ui_debug "$errorInfo" 2183 2179 break_softcontinue "search for portname $portname failed: $result" 1 status … … 2286 2282 } 2287 2283 foreachport $portlist { 2288 2284 if {$porturl eq ""} { 2289 # search forport2290 if {[catch {mport search $portname no exact} result]} {2285 # look up port 2286 if {[catch {mportlookup $portname} result]} { 2291 2287 global errorInfo 2292 2288 ui_debug "$errorInfo" 2293 break_softcontinue " search forportname $portname failed: $result" 1 status2289 break_softcontinue "lookup of portname $portname failed: $result" 1 status 2294 2290 } 2295 2291 if {[llength $result] < 2} { 2296 2292 break_softcontinue "Port $portname not found" 1 status … … 2603 2599 if {$porturl == ""} { 2604 2600 2605 2601 # Verify the portname, getting portinfo to map to a porturl 2606 if {[catch {set res [mport search $portname no exact]} result]} {2602 if {[catch {set res [mportlookup $portname]} result]} { 2607 2603 global errorInfo 2608 2604 ui_debug "$errorInfo" 2609 break_softcontinue " search forportname $portname failed: $result" 1 status2605 break_softcontinue "lookup of portname $portname failed: $result" 1 status 2610 2606 } 2611 2607 if {[llength $res] < 2} { 2612 2608 break_softcontinue "Port $portname not found" 1 status … … 2760 2756 # otherwise try to map the portname to a url 2761 2757 if {$porturl == ""} { 2762 2758 # Verify the portname, getting portinfo to map to a porturl 2763 if {[catch {set res [mport search $portname no exact]} result]} {2759 if {[catch {set res [mportlookup $portname]} result]} { 2764 2760 global errorInfo 2765 2761 ui_debug "$errorInfo" 2766 break_softcontinue " search forportname $portname failed: $result" 1 status2762 break_softcontinue "lookup of portname $portname failed: $result" 1 status 2767 2763 } 2768 2764 if {[llength $res] < 2} { 2769 2765 break_softcontinue "Port $portname not found" 1 status -
src/port/portindex.tcl
141 141 mporttraverse pindex $directory 142 142 close $fd 143 143 file rename -force $tempportindex [file join $outdir PortIndex] 144 mports_generate_quickindex [file join $outdir PortIndex] 144 145 puts "\nTotal number of ports parsed:\t$stats(total)\ 145 146 \nPorts successfully parsed:\t[expr $stats(total) - $stats(failed)]\t\ 146 147 \nPorts failed:\t\t\t$stats(failed)\n" -
src/macports1.0/macports.tcl
710 710 unsetenv $envkey 711 711 } 712 712 } 713 714 # load the quick index 715 _mports_load_quickindex 713 716 } 714 717 715 718 proc macports::worker_init {workername portpath porturl portbuildpath options variations} { … … 1691 1694 return $matches 1692 1695 } 1693 1696 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. 1702 proc 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. 1787 proc _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 1822 proc 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 1694 1858 proc mportinfo {mport} { 1695 1859 set workername [ditem_key $mport workername] 1696 1860 return [$workername eval array get PortInfo] … … 1789 1953 set dep_portname [lindex [split $depspec :] end] 1790 1954 1791 1955 # Find the porturl 1792 if {[catch {set res [mport search $dep_portname false exact]} error]} {1956 if {[catch {set res [mportlookup $dep_portname]} error]} { 1793 1957 global errorInfo 1794 1958 ui_debug "$errorInfo" 1795 ui_error "Internal error: port searchfailed: $error"1959 ui_error "Internal error: port lookup failed: $error" 1796 1960 return 1 1797 1961 } 1798 1962 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 { 1809 1968 ui_error "Dependency '$dep_portname' not found." 1810 1969 return 1 1811 1970 } … … 1974 2133 } 1975 2134 1976 2135 # check if the port is in tree 1977 if {[catch {mport search $portname false exact} result]} {2136 if {[catch {mportlookup $portname} result]} { 1978 2137 global errorInfo 1979 2138 ui_debug "$errorInfo" 1980 ui_error "port searchfailed: $result"2139 ui_error "port lookup failed: $result" 1981 2140 return 1 1982 2141 } 1983 2142 # argh! port doesnt exist! -
portmgr/jobs/PortIndexRegen.sh
127 127 echo "" >> $COMMIT_MSG 128 128 grep Failed $FAILURE_LOG >> $COMMIT_MSG 129 129 { 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 ; } \ 131 131 || { echo "SVN commit failed." >> $FAILURE_LOG ; bail ; } 132 132 133 133 # At this point the index was committed successfuly, so we cleanup before we exit.