<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[119700] trunk/base/src/registry2.0/receipt_sqlite.tcl</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="https://trac.macports.org/changeset/119700">119700</a></dd>
<dt>Author</dt> <dd>cal@macports.org</dd>
<dt>Date</dt> <dd>2014-05-03 16:51:43 -0700 (Sat, 03 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>base: registry2.0/receipt_sqlite.tcl: Add API documentation, unify whitespace</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbasesrcregistry20receipt_sqlitetcl">trunk/base/src/registry2.0/receipt_sqlite.tcl</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbasesrcregistry20receipt_sqlitetcl"></a>
<div class="modfile"><h4>Modified: trunk/base/src/registry2.0/receipt_sqlite.tcl (119699 => 119700)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/base/src/registry2.0/receipt_sqlite.tcl        2014-05-03 23:47:40 UTC (rev 119699)
+++ trunk/base/src/registry2.0/receipt_sqlite.tcl        2014-05-03 23:51:43 UTC (rev 119700)
</span><span class="lines">@@ -41,8 +41,16 @@
</span><span class="cx"> # registry2.0 wrapper code that matches old receipt_flat interface
</span><span class="cx"> ##
</span><span class="cx"> namespace eval receipt_sqlite {
</span><del>-
-# return list of active ports, or active version of port 'name' if specified
</del><ins>+##
+# Return a list of active ports, or the active version of port \a name, if
+# specified.
+#
+# @param name
+#        Empty string to return a list of all ports or the name of a port to
+#        return only the active version of a single port.
+# @return A list of matching ports where each entry is a list of (name,
+#         version, revision, variants, 1 or 0 indicating whether a port's state
+#         is &quot;installed&quot;, epoch).
</ins><span class="cx"> proc active {name} {
</span><span class="cx">     if {$name ne &quot;&quot;} {
</span><span class="cx">         set ports [registry::entry installed $name]
</span><span class="lines">@@ -57,59 +65,94 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ##
</span><del>-# Open an existing entry and return a reference.
</del><ins>+# Open an existing entry in the registry uniquely identified by name, version,
+# revision, variants and epoch and return a reference.
+#
+# @param name
+#        The name of the port to be opened.
+# @param version
+#        The version of the port to be opened.
+# @param revision
+#        The revision of the port to be opened.
+# @param variants
+#        The canonical variant string of the port to be opened.
+# @param epoch
+#        The epoch of the port to be opened.
+# @return A reference to the requested port on success. Raises an error on
+#         failure (e.g. if the port isn't found or allocating the reference
+#         fails).
</ins><span class="cx"> proc open_entry {name version revision variants epoch} {
</span><span class="cx">     return [registry::entry open $name $version $revision $variants $epoch]
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-# Check to see if an entry exists
</del><ins>+##
+# Check whether a registry entry exists.
+#
+# @param name
+#        The name to be searched in the registry.
+# @param version
+#        The version to be searched in the registry.
+# @param revision
+#        The revision to be searched in the registry. Defaults to 0.
+# @param variants
+#        The canonical variant string to be searched in the registry. Defaults
+#        to an empty string.
+# @return 1, if the port exists, 0 otherwise.
</ins><span class="cx"> proc entry_exists {name version {revision 0} {variants &quot;&quot;}} {
</span><span class="cx">     if {![catch {set ports [registry::entry search name $name version $version revision $revision variants $variants]}] &amp;&amp; [llength $ports] &gt; 0} {
</span><span class="cx">         return 1
</span><span class="cx">     }
</span><del>-        return 0
</del><ins>+    return 0
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-# Check to see if an entry exists
</del><ins>+##
+# Check whether a registry entry with the given name exists.
+#
+# @param name
+#        The name to be searched in the registry.
+# @return 1 if a port with the given name exists in the registry, 0 otherwise.
</ins><span class="cx"> proc entry_exists_for_name {name} {
</span><del>-        if {![catch {set ports [registry::entry search name $name]}] &amp;&amp; [llength $ports] &gt; 0} {
-            return 1
-        }
-        return 0
</del><ins>+    if {![catch {set ports [registry::entry search name $name]}] &amp;&amp; [llength $ports] &gt; 0} {
+        return 1
+    }
+    return 0
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ##
</span><del>-# determine if a file is registered in the file map, and if it is,
-# get its port.
</del><ins>+# Determine if a file is registered in the file map, and if it is, get the name
+# of the port it is registered to.
</ins><span class="cx"> #
</span><del>-# - file        the file to test
-# returns 0 if the file is not registered, the name of the port otherwise.
-#
</del><ins>+# @param file
+#        The full path to the file to be tested.
+# @return 0 if the file is not registered to any port. The name of the port
+#         otherwise.
</ins><span class="cx"> proc file_registered {file} {
</span><span class="cx">     set port [registry::entry owner $file]
</span><del>-        if {$port ne &quot;&quot;} {
-                return [$port name]
-        } else {
-                return 0
-        }
</del><ins>+    if {$port ne &quot;&quot;} {
+        return [$port name]
+    } else {
+        return 0
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ##
</span><del>-# determine if a port is registered in the file map, and if it is,
-# get its installed (activated) files.
</del><ins>+# Determine if a port is registered in the file map, and if it is, get its
+# installed (activated) files.
</ins><span class="cx"> #
</span><del>-# - port        the port to test
-# returns 0 if the port is not registered, the list of its files otherwise.
</del><ins>+# @param name
+#        The name of the port to be tested.
+# @return 0 if no port with the given name is active. An empty string, if no
+#         port with the given name is active, but a port with the given name is
+#         imaged (i.e. installed, but inactive). A list of files if the given
+#         port is installed and active.
</ins><span class="cx"> proc port_registered {name} {
</span><del>-        if {![catch {set ports [registry::entry installed $name]}]
-            &amp;&amp; [llength $ports] &gt; 0} {
-            # should never return more than one port
-            set port [lindex $ports 0]
-                return [$port files]
-        } elseif {![catch {set ports [registry::entry imaged $name]}]
-            &amp;&amp; [llength $ports] &gt; 0} {
-            return &quot;&quot;
-        } else {
</del><ins>+    if {![catch {set ports [registry::entry installed $name]}] &amp;&amp; [llength $ports] &gt; 0} {
+        # should never return more than one port
+        set port [lindex $ports 0]
+        return [$port files]
+    } elseif {![catch {set ports [registry::entry imaged $name]}] &amp;&amp; [llength $ports] &gt; 0} {
+        return &quot;&quot;
+    } else {
</ins><span class="cx">         return 0
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="lines">@@ -117,8 +160,13 @@
</span><span class="cx"> ##
</span><span class="cx"> # Retrieve a property from a registry entry.
</span><span class="cx"> #
</span><del>-# ref                        reference to the entry.
-# property                key for the property to retrieve.
</del><ins>+# @param ref
+#        Reference to the registry entry.
+# @param property
+#        Name of the property to retrieve.
+# @return Return value depends on the property queried. Returns 0 if an error
+#         occured while trying to access the property (but note that 0 may be
+#         a perfectly valid value for the key you're querying).
</ins><span class="cx"> proc property_retrieve {ref property} {
</span><span class="cx">     switch $property {
</span><span class="cx">         active {
</span><span class="lines">@@ -137,9 +185,12 @@
</span><span class="cx"> ##
</span><span class="cx"> # Store a property in a registry entry.
</span><span class="cx"> #
</span><del>-# ref                        reference to the entry.
-# property                key for the property to set.
-# value         value to set it to.
</del><ins>+# @param ref
+#        Reference to the registry entry.
+# @param property
+#        Name of the property to set.
+# @param value
+#        New value for the given key in the reference.
</ins><span class="cx"> proc property_store {ref property value} {
</span><span class="cx">     switch $property {
</span><span class="cx">         active {
</span><span class="lines">@@ -155,54 +206,83 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-# Return installed ports
</del><ins>+##
+# Return all installed ports (active and inactive). Optionally filter by name
+# and version.
</ins><span class="cx"> #
</span><del>-# If version is &quot;&quot;, return all ports of that name.
-# Otherwise, return only ports that exactly match this version.
-# What we call version here is version_revision+variants.
-# The syntax for that can be ambiguous if there's an underscore and dash in
-# version for example, so we don't attempt to split up the composite version
-# into its components, we just compare the whole thing.
</del><ins>+# @param name
+#        The name of the port you're looking for. Defaults to an empty string,
+#        which will return all installed ports.
+# @param version
+#        A version string in either of the forms &quot;$version_$revision$variants&quot;
+#        or &quot;$version&quot;. Defaults to an empty string, which will return ports
+#        regardless of version constraints.
+# @return A list of ports in the form given by #active.
</ins><span class="cx"> proc installed {{name &quot;&quot;} {version &quot;&quot;}} {
</span><del>-        if { $name eq &quot;&quot; &amp;&amp; $version eq &quot;&quot; } {
-            set ports [registry::entry imaged]
-        } elseif { $name ne &quot;&quot; &amp;&amp; $version eq &quot;&quot;} {
-            set ports [registry::entry imaged $name]
-        } else {
-            set ports {}
-            set possible_ports [registry::entry imaged $name]
-            foreach p $possible_ports {
-                if {&quot;[$p version]_[$p revision][$p variants]&quot; == $version
-                    || [$p version] == $version} {
-                    lappend ports $p
-                }
-            }
-        }
</del><ins>+    # If version is &quot;&quot;, return all ports of that name. Otherwise, return only
+    # ports that exactly match this version. What we call version here is
+    # version_revision+variants.
+    # The syntax for that can be ambiguous if there's an underscore and dash in
+    # version for example, so we don't attempt to split up the composite
+    # version into its components, we just compare the whole thing.
+    if {$name eq &quot;&quot; &amp;&amp; $version eq &quot;&quot;} {
+        set ports [registry::entry imaged]
+    } elseif {$name ne &quot;&quot; &amp;&amp; $version eq &quot;&quot;} {
+        set ports [registry::entry imaged $name]
+    } else {
+        set ports {}
+        set possible_ports [registry::entry imaged $name]
+        foreach p $possible_ports {
+            if {&quot;[$p version]_[$p revision][$p variants]&quot; == $version || [$p version] == $version} {
+                lappend ports $p
+            }
+        }
+    }
</ins><span class="cx"> 
</span><span class="cx">     set rlist [list]
</span><span class="cx">     foreach port $ports {
</span><span class="cx">         lappend rlist [list [$port name] [$port version] [$port revision] [$port variants] [string equal [$port state] &quot;installed&quot;] [$port epoch]]
</span><span class="cx">     }
</span><del>-        return $rlist
</del><ins>+    return $rlist
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+##
+# Does nothing.
</ins><span class="cx"> proc close_file_map {args} {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+##
+# Does nothing.
</ins><span class="cx"> proc open_dep_map {args} {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-# List all the ports that this port depends on
</del><ins>+##
+# List all ports that a given port (identified by the parameters) depends on.
+# Each of the parameters can be passed as an empty string to ignore them in the
+# search. You should however at least specify name.
+#
+# @param name
+#        The name of the port of interest.
+# @param version
+#        The version of the port of interest.
+# @param revision
+#        The revision of the port of interest.
+# @param variants
+#        The canonical variants string of the port of interest.
+# @return A sorted list without duplicates where each entry is of the form
+#         (dependency, &quot;port&quot;, port), where dependency is the name of the
+#         dependency and port is the name of the port that matched the search
+#         criteria.
</ins><span class="cx"> proc list_depends {name version revision variants} {
</span><del>-        set rlist [list]
-        set searchkeys {}
</del><ins>+    set rlist [list]
+    set searchkeys {}
</ins><span class="cx">     foreach key {name version revision} {
</span><span class="cx">         if {[set $key] ne &quot;&quot;} {
</span><span class="cx">             lappend searchkeys $key [set $key]
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx">     if {$variants != 0} {
</span><del>-                lappend searchkeys &quot;variants&quot; $variants
</del><ins>+        lappend searchkeys &quot;variants&quot; $variants
</ins><span class="cx">     }
</span><span class="cx">     if {[catch {set ports [registry::entry search {*}$searchkeys]}]} {
</span><span class="cx">         set ports [list]
</span><span class="lines">@@ -212,21 +292,39 @@
</span><span class="cx">             lappend rlist [list [$dep name] port [$port name]]
</span><span class="cx">         }
</span><span class="cx">     }
</span><del>-        
-        return [lsort -unique $rlist]
</del><ins>+
+    return [lsort -unique $rlist]
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> # List all the ports that depend on this port
</span><ins>+##
+# List all ports that depend on a given port (identified by the parameters).
+# Each of the parameters can be passed as an empty string to ignore them in the
+# search. In practice, you'll always pass at least the name parameter
+# non-empty.
+#
+# @param name
+#        The name of the port of interest.
+# @param version
+#        The version of the port of interest.
+# @param revision
+#        The revision of the port of interest.
+# @param variants
+#        The canonical variants string of the port of interest.
+# @return A sorted list without duplicates where each entry is of the form
+#         (port, &quot;port&quot;, dependent), where dependent is the name of the
+#         dependent port and port is the name of the port that matched the
+#         search criteria.
</ins><span class="cx"> proc list_dependents {name version revision variants} {
</span><del>-        set rlist [list]
-        set searchkeys {}
</del><ins>+    set rlist [list]
+    set searchkeys {}
</ins><span class="cx">     foreach key {name version revision} {
</span><span class="cx">         if {[set $key] ne &quot;&quot;} {
</span><del>-                        lappend searchkeys $key [set $key]
</del><ins>+            lappend searchkeys $key [set $key]
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx">     if {$variants != 0} {
</span><del>-                lappend searchkeys &quot;variants&quot; $variants
</del><ins>+        lappend searchkeys &quot;variants&quot; $variants
</ins><span class="cx">     }
</span><span class="cx">     if {[catch {set ports [registry::entry search {*}$searchkeys]}]} {
</span><span class="cx">         set ports [list]
</span><span class="lines">@@ -237,11 +335,36 @@
</span><span class="cx">             lappend rlist [list [$port name] port [$dependent name]]
</span><span class="cx">         }
</span><span class="cx">     }
</span><del>-        
-        return [lsort -unique $rlist]
</del><ins>+
+    return [lsort -unique $rlist]
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-# adds a registry entry from a list of keys and values
</del><ins>+##
+# Add a new registry entry from a given list of keys of values. The list should
+# at least contain the keys
+#  \li \c name The name of the port
+#  \li \c epoch The epoch of the port
+#  \li \c version The version of the port
+#  \li \c revision The revision of the port
+#  \li \c variants The canonical variants string of the port
+#  \li \c date The date of installation of this port, probably the current date
+#      and time
+#  \li \c requested 0 or 1 depending on whether this port is a requested port
+#  \li \c location The absolute path to the binary archive of the port
+#  \li \c state The current state of the port, currently either &quot;imaged&quot; or
+#      &quot;installed&quot;
+#  \li \c installtype The type of installation of this port. For new ports,
+#      always &quot;image&quot;
+#  \li \c imagefiles A list of files installed by this port
+#  \li \c files A list of filenames as which the imagefiles should be activated
+#      if state is &quot;installed&quot;
+#  \li \c negated_variants The canonical representation of the negated variants
+#  \li \c os_platform The platform on which the port was installed
+#  \li \c os_major The major version of the OS on which the port was installed
+#  \li \c archs A list of architectures of this port
+#  \li \c depends A list of ports on which the new port depends
+#  \li \c portfile The Portfile used to install this port (note: actual
+#      contents, not the path!)
</ins><span class="cx"> proc create_entry_l {proplist} {
</span><span class="cx">     array set props $proplist
</span><span class="cx">     registry::write {
</span></span></pre>
</div>
</div>

</body>
</html>