[137548] branches/gsoc15-dependency/base/src/macports1.0

ijackson at macports.org ijackson at macports.org
Sun Jun 14 01:09:38 PDT 2015


Revision: 137548
          https://trac.macports.org/changeset/137548
Author:   ijackson at macports.org
Date:     2015-06-14 01:09:38 -0700 (Sun, 14 Jun 2015)
Log Message:
-----------
Add if-else block in mportsearch to differntiate between 
libsolv search and builtin search.
Previously it was running libsolv search as well as
builtin search on passing -l option.
Now run only libsolv search on -l option, else 
use builtin search.
Pass more info to libsolv::search for further enhancements.

Modified Paths:
--------------
    branches/gsoc15-dependency/base/src/macports1.0/macports.tcl
    branches/gsoc15-dependency/base/src/macports1.0/macports_libsolv.tcl

Modified: branches/gsoc15-dependency/base/src/macports1.0/macports.tcl
===================================================================
--- branches/gsoc15-dependency/base/src/macports1.0/macports.tcl	2015-06-14 07:43:18 UTC (rev 137547)
+++ branches/gsoc15-dependency/base/src/macports1.0/macports.tcl	2015-06-14 08:09:38 UTC (rev 137548)
@@ -2739,109 +2739,114 @@
     set matches [list]
     set easy [expr {$field eq "name"}]
 
+    ## Use libsolv search if -l is passed
     if {[info exists macports::global_options(ports_depengine)]} {
         if {$macports::global_options(ports_depengine) eq "libsolv"} {
             macports::libsolv::create_pool
             # macports::libsolv::print
-            set search_res [macports::libsolv::search $pattern]
+            set search_res [macports::libsolv::search $pattern \
+            $case_sensitive $matchstyle]
         }
-    }
-    set found 0
-    foreach source $sources {
-        set source [lindex $source 0]
-        set protocol [macports::getprotocol $source]
-        if {[catch {set fd [open [macports::getindex $source] r]} result]} {
-            ui_warn "Can't open index file for source: $source"
-        } else {
-            try {
-                incr found 1
-                while {[gets $fd line] >= 0} {
-                    array unset portinfo
-                    set name [lindex $line 0]
-                    set len  [lindex $line 1]
-                    set line [read $fd $len]
+    } else {
+        ## Use builtin search algorithm.
+        set found 0
+        foreach source $sources {
+            set source [lindex $source 0]
+            set protocol [macports::getprotocol $source]
+            if {[catch {set fd [open [macports::getindex $source] r]} result]} {
+                ui_warn "Can't open index file for source: $source"
+            } else {
+                try {
+                    incr found 1
+                    while {[gets $fd line] >= 0} {
+                        array unset portinfo
+                        set name [lindex $line 0]
+                        set len  [lindex $line 1]
+                        set line [read $fd $len]
 
-                    if {$easy} {
-                        set target $name
-                    } else {
-                        array set portinfo $line
-                        if {![info exists portinfo($field)]} {
-                            continue
+                        if {$easy} {
+                            set target $name
+                        } else {
+                            array set portinfo $line
+                            if {![info exists portinfo($field)]} {
+                                continue
+                            }
+                            set target $portinfo($field)
                         }
-                        set target $portinfo($field)
-                    }
 
-                    switch -- $matchstyle {
-                        exact {
-                            if {$case_sensitive} {
-                                set compres [string compare $pattern $target]
-                            } else {
-                                set compres [string compare -nocase $pattern $target]
+                        switch -- $matchstyle {
+                            exact {
+                                if {$case_sensitive} {
+                                    set compres [string compare $pattern $target]
+                                } else {
+                                    set compres [string compare -nocase $pattern $target]
+                                }
+                                set matchres [expr {0 == $compres}]
                             }
-                            set matchres [expr {0 == $compres}]
-                        }
-                        glob {
-                            if {$case_sensitive} {
-                                set matchres [string match $pattern $target]
-                            } else {
-                                set matchres [string match -nocase $pattern $target]
+                            glob {
+                                if {$case_sensitive} {
+                                    set matchres [string match $pattern $target]
+                                } else {
+                                    set matchres [string match -nocase $pattern $target]
+                                }
                             }
-                        }
-                        regexp {
-                            if {$case_sensitive} {
-                                set matchres [regexp -- $pattern $target]
-                            } else {
-                                set matchres [regexp -nocase -- $pattern $target]
+                            regexp {
+                                if {$case_sensitive} {
+                                    set matchres [regexp -- $pattern $target]
+                                } else {
+                                    set matchres [regexp -nocase -- $pattern $target]
+                                }
                             }
+                            default {
+                                return -code error "mportsearch: Unsupported matching style: ${matchstyle}."
+                            }
                         }
-                        default {
-                            return -code error "mportsearch: Unsupported matching style: ${matchstyle}."
-                        }
-                    }
 
-                    if {$matchres == 1} {
-                        if {$easy} {
-                            array set portinfo $line
-                        }
-                        switch -- $protocol {
-                            rsync {
-                                # Rsync files are local
-                                set source_url file://[macports::getsourcepath $source]
+                        if {$matchres == 1} {
+                            if {$easy} {
+                                array set portinfo $line
                             }
-                            https -
-                            http -
-                            ftp {
-                                # daily snapshot tarball
-                                set source_url file://[macports::getsourcepath $source]
+                            switch -- $protocol {
+                                rsync {
+                                    # Rsync files are local
+                                    set source_url file://[macports::getsourcepath $source]
+                                }
+                                https -
+                                http -
+                                ftp {
+                                    # daily snapshot tarball
+                                    set source_url file://[macports::getsourcepath $source]
+                                }
+                                default {
+                                    set source_url $source
+                                }
                             }
-                            default {
-                                set source_url $source
+                            if {[info exists portinfo(portdir)]} {
+                                set porturl ${source_url}/$portinfo(portdir)
+                                lappend line porturl $porturl
+                                ui_debug "Found port in $porturl"
+                            } else {
+                                ui_debug "Found port info: $line"
                             }
+                            lappend matches $name
+                            lappend matches $line
                         }
-                        if {[info exists portinfo(portdir)]} {
-                            set porturl ${source_url}/$portinfo(portdir)
-                            lappend line porturl $porturl
-                            ui_debug "Found port in $porturl"
-                        } else {
-                            ui_debug "Found port info: $line"
-                        }
-                        lappend matches $name
-                        lappend matches $line
                     }
+                } catch * {
+                    ui_warn "It looks like your PortIndex file for $source may be corrupt."
+                    throw
+                } finally {
+                    close $fd
                 }
-            } catch * {
-                ui_warn "It looks like your PortIndex file for $source may be corrupt."
-                throw
-            } finally {
-                close $fd
             }
         }
+    
+        if {!$found} {
+            return -code error "No index(es) found! Have you synced your port definitions? Try running 'port selfupdate'."
+        }
+
+        return $matches
     }
-    if {!$found} {
-        return -code error "No index(es) found! Have you synced your port definitions? Try running 'port selfupdate'."
-    }
-
-    return $matches
 }
 
 ##

Modified: branches/gsoc15-dependency/base/src/macports1.0/macports_libsolv.tcl
===================================================================
--- branches/gsoc15-dependency/base/src/macports1.0/macports_libsolv.tcl	2015-06-14 07:43:18 UTC (rev 137547)
+++ branches/gsoc15-dependency/base/src/macports1.0/macports_libsolv.tcl	2015-06-14 08:09:38 UTC (rev 137548)
@@ -103,7 +103,7 @@
     #  To Do list:
     #  Add support for search options i.e. --exact, --case-sensitive, --glob, --regex.
     #  Return portinfo to mportsearch which will pass the info to port.tcl to print results.
-    proc search {pattern} {
+    proc search {pattern {case_sensitive yes} {matchstyle regexp}  } {
         variable pool
 
         set sel [$pool Selection]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20150614/83a05710/attachment.html>


More information about the macports-changes mailing list