[107206] branches/gsoc11-statistics/base

snc at macports.org snc at macports.org
Fri Jun 21 12:46:52 PDT 2013


Revision: 107206
          https://trac.macports.org/changeset/107206
Author:   snc at macports.org
Date:     2013-06-21 12:46:52 -0700 (Fri, 21 Jun 2013)
Log Message:
-----------
gsoc11-statistics/base: rebase ^/trunk/base

Modified Paths:
--------------
    branches/gsoc11-statistics/base/ChangeLog
    branches/gsoc11-statistics/base/config/macports_version
    branches/gsoc11-statistics/base/configure
    branches/gsoc11-statistics/base/configure.ac
    branches/gsoc11-statistics/base/doc/archive_sites.conf
    branches/gsoc11-statistics/base/doc/exampleport/Portfile
    branches/gsoc11-statistics/base/doc/macports.conf.in
    branches/gsoc11-statistics/base/doc/port.1
    branches/gsoc11-statistics/base/doc/pubkeys.conf.in
    branches/gsoc11-statistics/base/doc/sources.conf
    branches/gsoc11-statistics/base/doc/variants.conf
    branches/gsoc11-statistics/base/src/darwintracelib1.0/darwintrace.c
    branches/gsoc11-statistics/base/src/macports1.0/macports.tcl
    branches/gsoc11-statistics/base/src/package1.0/portarchivefetch.tcl
    branches/gsoc11-statistics/base/src/package1.0/portdmg.tcl
    branches/gsoc11-statistics/base/src/package1.0/portdpkg.tcl
    branches/gsoc11-statistics/base/src/package1.0/portmdmg.tcl
    branches/gsoc11-statistics/base/src/package1.0/portmpkg.tcl
    branches/gsoc11-statistics/base/src/package1.0/portpkg.tcl
    branches/gsoc11-statistics/base/src/package1.0/portrpm.tcl
    branches/gsoc11-statistics/base/src/package1.0/portsrpm.tcl
    branches/gsoc11-statistics/base/src/package1.0/portunarchive.tcl
    branches/gsoc11-statistics/base/src/pextlib1.0/system.c
    branches/gsoc11-statistics/base/src/pextlib1.0/tracelib.c
    branches/gsoc11-statistics/base/src/port/port-help.tcl
    branches/gsoc11-statistics/base/src/port/port.tcl
    branches/gsoc11-statistics/base/src/port1.0/fetch_common.tcl
    branches/gsoc11-statistics/base/src/port1.0/portactivate.tcl
    branches/gsoc11-statistics/base/src/port1.0/portbuild.tcl
    branches/gsoc11-statistics/base/src/port1.0/portchecksum.tcl
    branches/gsoc11-statistics/base/src/port1.0/portclean.tcl
    branches/gsoc11-statistics/base/src/port1.0/portconfigure.tcl
    branches/gsoc11-statistics/base/src/port1.0/portdeactivate.tcl
    branches/gsoc11-statistics/base/src/port1.0/portdestroot.tcl
    branches/gsoc11-statistics/base/src/port1.0/portdistcheck.tcl
    branches/gsoc11-statistics/base/src/port1.0/portfetch.tcl
    branches/gsoc11-statistics/base/src/port1.0/portinstall.tcl
    branches/gsoc11-statistics/base/src/port1.0/portlivecheck.tcl
    branches/gsoc11-statistics/base/src/port1.0/portsandbox.tcl
    branches/gsoc11-statistics/base/src/port1.0/portstartupitem.tcl
    branches/gsoc11-statistics/base/src/port1.0/porttrace.tcl
    branches/gsoc11-statistics/base/src/port1.0/portutil.tcl
    branches/gsoc11-statistics/base/tests/test/trace/Makefile
    branches/gsoc11-statistics/base/tests/test/xcodeversion/Portfile

Property Changed:
----------------
    branches/gsoc11-statistics/base/


Property changes on: branches/gsoc11-statistics/base
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base:37343-46937
/branches/gsoc09-logging/base:51231-60371
/branches/gsoc11-rev-upgrade/base:78828-88375
/branches/universal-sanity/base:51872-52323
/branches/variant-descs-14482/base:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base:78736-105813
/users/perry/base-bugs_and_notes:45682-46060
/users/perry/base-select:44044-44692
   + /branches/gsoc08-privileges/base:37343-46937
/branches/gsoc09-logging/base:51231-60371
/branches/gsoc11-rev-upgrade/base:78828-88375
/branches/universal-sanity/base:51872-52323
/branches/variant-descs-14482/base:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base:78736-107205
/users/perry/base-bugs_and_notes:45682-46060
/users/perry/base-select:44044-44692

Modified: branches/gsoc11-statistics/base/ChangeLog
===================================================================
--- branches/gsoc11-statistics/base/ChangeLog	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/ChangeLog	2013-06-21 19:46:52 UTC (rev 107206)
@@ -4,15 +4,36 @@
 ###
 
 Release 2.2.0 (unreleased)
+    - Fixed ports sometimes being incorrectly cleaned after the unarchive
+      target is run with newer archives. (jmr in r106717)
+
+    - When rebuilding an installed port, fixed the old copy being removed
+      before the new copy has been built. (jmr in r106668)
+
+    - Support deleting selected files and directories before creating a pkg.
+      (blair in r105575)
+
     - Remove unsupported xpkg package type, xar-based format with XML.
       (afb in r105002)
 
+    - Support pattern matching in compiler.blacklist.
+      (larryv in r104174, r104178)
+
+    - Workaround for some OS commands hanging on 10.8 when started from a root
+      login shell. (#34221, jeremyhu in r104118)
+
+    - TMPDIR is now set to ${workpath}/.tmp while building ports, to avoid
+      problems with using /tmp. (#37834, ryandesign in r103518)
+
     - Remove unimplemented 'port submit', remove XAR source packages.
       (cal in r103400)
 
-    - Remove dependency_libs information from libtool libraries (.la).
-      (#38010, jmr in r102945)
+    - Remove dependency_libs information from libtool libraries (.la) in order
+      to prevent overlinking. (#38010, jmr in r102945)
 
+    - Setting configure.compiler will now automatically add a dependency if
+      the chosen compiler is provided by a port. (#32542, cal in r102932)
+
     - Add 'port space --total' which displays the grand total only.
       (raimue in r102248)
 
@@ -23,12 +44,14 @@
 
     - Fixes bringing trace mode back to a working state. Improvements to reduce
       the number of builds trace mode breaks.
-      (cal in r100071-100073, r100077, r100126, r100221)
+      (cal in r100071-100073, r100077, r100126, r100221, r106710)
 
     - Began using sandbox-exec(1) on 10.5+ to prevent commands executed using
       the 'system' procedure from writing files outside of the build directory
       and selected other locations like /tmp. (jmr in r98156, r98193, etc.)
 
+    - Added ability to sync ports tree with git (jeremyhu in r92410)
+
 Release 2.1.3 (2013-01-31 by jmr)
     - Fixed a bug where a certain order of starting and aborting a build,
       running selfupdate and continuing a build would resume building although

Modified: branches/gsoc11-statistics/base/config/macports_version
===================================================================
--- branches/gsoc11-statistics/base/config/macports_version	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/config/macports_version	2013-06-21 19:46:52 UTC (rev 107206)
@@ -1 +1 @@
-2.1.99
+2.2.99

Modified: branches/gsoc11-statistics/base/configure
===================================================================
--- branches/gsoc11-statistics/base/configure	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/configure	2013-06-21 19:46:52 UTC (rev 107206)
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for MacPorts 2.1.99.
+# Generated by GNU Autoconf 2.69 for MacPorts 2.2.99.
 #
 # Report bugs to <macports-dev at lists.macosforge.org>.
 #
@@ -580,8 +580,8 @@
 # Identity of this package.
 PACKAGE_NAME='MacPorts'
 PACKAGE_TARNAME='macports'
-PACKAGE_VERSION='2.1.99'
-PACKAGE_STRING='MacPorts 2.1.99'
+PACKAGE_VERSION='2.2.99'
+PACKAGE_STRING='MacPorts 2.2.99'
 PACKAGE_BUGREPORT='macports-dev at lists.macosforge.org'
 PACKAGE_URL=''
 
@@ -638,7 +638,6 @@
 SHLIB_CFLAGS
 SHLIB_LD
 STLIB_LD
-PATHCONF
 INCLUDES
 subdirs
 SQLITE3_TCL_DIR
@@ -1414,7 +1413,7 @@
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures MacPorts 2.1.99 to adapt to many kinds of systems.
+\`configure' configures MacPorts 2.2.99 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1480,7 +1479,7 @@
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of MacPorts 2.1.99:";;
+     short | recursive ) echo "Configuration of MacPorts 2.2.99:";;
    esac
   cat <<\_ACEOF
 
@@ -1626,7 +1625,7 @@
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-MacPorts configure 2.1.99
+MacPorts configure 2.2.99
 generated by GNU Autoconf 2.69
 
 Copyright (C) 2012 Free Software Foundation, Inc.
@@ -2295,7 +2294,7 @@
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by MacPorts $as_me 2.1.99, which was
+It was created by MacPorts $as_me 2.2.99, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   $ $0 $@
@@ -2790,7 +2789,7 @@
 # Read in the MacPorts version from the base/config/macports_version file
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking MacPorts version" >&5
 $as_echo_n "checking MacPorts version... " >&6; }
-MACPORTS_VERSION=2.1.99
+MACPORTS_VERSION=2.2.99
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MACPORTS_VERSION" >&5
 $as_echo "$MACPORTS_VERSION" >&6; }
 
@@ -2956,7 +2955,7 @@
     as_fn_error $? "This version of Mac OS X is not supported
                   Please upgrade at http://store.apple.com/" "$LINENO" 5
     ;;
-  10.4.[0-9]|10.4.10|10.5.[0-7]|10.6.[0-7]|10.7.[0-4]|10.8.[0-1])
+  10.4.[0-9]|10.4.10|10.5.[0-7]|10.6.[0-7]|10.7.[0-4]|10.8.[0-3])
     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: This version of Mac OS X is out of date" >&5
 $as_echo "$as_me: WARNING: This version of Mac OS X is out of date" >&2;}
     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Please run Software Update to update it" >&5
@@ -10073,7 +10072,6 @@
 
 
 
-
 # misc variables that need to be expanded for substitution into tcl
 
 oldprefix=$prefix
@@ -10626,7 +10624,7 @@
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by MacPorts $as_me 2.1.99, which was
+This file was extended by MacPorts $as_me 2.2.99, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -10688,7 +10686,7 @@
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-MacPorts config.status 2.1.99
+MacPorts config.status 2.2.99
 configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
 

Modified: branches/gsoc11-statistics/base/configure.ac
===================================================================
--- branches/gsoc11-statistics/base/configure.ac	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/configure.ac	2013-06-21 19:46:52 UTC (rev 107206)
@@ -32,7 +32,7 @@
     AC_MSG_ERROR([This version of Mac OS X is not supported
                   Please upgrade at http://store.apple.com/])
     ;;
-  10.4.[[0-9]]|10.4.10|10.5.[[0-7]]|10.6.[[0-7]]|10.7.[[0-4]]|10.8.[[0-1]])
+  10.4.[[0-9]]|10.4.10|10.5.[[0-7]]|10.6.[[0-7]]|10.7.[[0-4]]|10.8.[[0-3]])
     AC_MSG_WARN([This version of Mac OS X is out of date])
     AC_MSG_WARN([Please run Software Update to update it])
     ;;

Modified: branches/gsoc11-statistics/base/doc/archive_sites.conf
===================================================================
--- branches/gsoc11-statistics/base/doc/archive_sites.conf	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/doc/archive_sites.conf	2013-06-21 19:46:52 UTC (rev 107206)
@@ -1,27 +1,44 @@
-# Configuration for (binary) archive sources.
 # $Id$
 
-# Each entry is started by a name line. The only required values are name and
-# urls. Other fields are type, prefix, applications_dir and frameworks_dir,
-# which have the usual default values:
-#    type tbz2
-#    prefix /opt/local
-#    applications_dir /Applications/MacPorts
-#    frameworks_dir ${prefix}/Library/Frameworks
+# MacPorts configuration file for binary archive sources.
+
+# Each source entry consists of one or more fields.
 #
-# type can be any of: tgz, tar, tbz, tbz2, tlz, txz, xar, zip, cpgz, cpio
-# Note that some types require a corresponding tool to be installed, and
-# entries with an unsupported type will not be used.
+#   name: A name for the archive source. This field always starts a new
+#       entry. Required.
+#
+#   urls: A space- or tab-delimited list of the source's URLs. Defaults
+#       to an empty list.
+#
+#   type: The filetype of the archives; valid values are "cpgz", "cpio",
+#       "tar", "tbz", "tbz2", "tgz", "tlz", "txz", "xar", and "zip".
+#       MacPorts handles each archive type with an appropriate external
+#       executable; if it cannot find such an executable, or if the
+#       specified type is invalid, the source is not used. Defaults to
+#       "tbz2".
+#
+#   prefix: The prefix of the MacPorts installation used to create the
+#       source's archives. This must match the value of "prefix" set in
+#       macports.conf, or the source is not used. Defaults to
+#       "/opt/local".
+#
+#   applications_dir: The applications directory of the MacPorts
+#       installation used to create the source's archives. This must
+#       match the value of "applications_dir" set in macports.conf, or
+#       the source is not used. Defaults to "/Applications/MacPorts".
+#
+#   frameworks_dir: The frameworks directory of the MacPorts
+#       installation used to create the source's archives. This must
+#       match the value of "frameworks_dir" set in macports.conf, or the
+#       source is not used. Defaults to "[prefix]/Library/Frameworks".
 
-# Example:
-#name                mysource
-#urls                http://example.com/ ftp://ftp.example.org/
-#type                tbz2
-#prefix              /opt/mysource
-#applications_dir    /opt/mysource/Applications
-#frameworks_dir      /opt/mysource/Library/Frameworks
+# Example source:
+#name               	My Source
+#urls               	http://example.com/ ftp://ftp.example.com/packages/
+#type               	zip
+#prefix             	/opt/mysource
+#applications_dir   	/opt/mysource/Applications
 
-# If you want to disable use of the archive sites listed in the ports tree,
-# you could do this:
-#name                macports_archives
-#urls
+# To disable the default archive source, uncomment the following dummy
+# entry; it will shadow the one from the ports tree.
+#name               	macports_archives

Modified: branches/gsoc11-statistics/base/doc/exampleport/Portfile
===================================================================
--- branches/gsoc11-statistics/base/doc/exampleport/Portfile	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/doc/exampleport/Portfile	2013-06-21 19:46:52 UTC (rev 107206)
@@ -7,88 +7,88 @@
 # PortSystem <version>
 # where version is the version of the ports system your port relies upon.
 # This can NOT be commented out.
-PortSystem 1.0
+PortSystem          1.0
 
 # The name of the port
-name		glib2
+name                glib2
 
 # Its version information
-version	      2.12.11
+version             2.12.11
 
 # Supported and tested platforms
-platforms	darwin
+platforms           darwin
 
 # Categories and identifying keywords
-categories	devel
+categories          devel
 
 # Email address(es) of the port's Maintainer(s)
-maintainers	ryandesign at macports.org
+maintainers ryandesign at macports.org
 
 # A short description of this port
-description	Library with data structure functions and other constructs
+description         Library with data structure functions and other constructs
 
 # A long description, with more details
-long_description      Glib is a library which includes support routines for \
-		      C, such as lists, trees, hashes, memory allocation, and \
-		      many other things.
+long_description    Glib is a library which includes support routines for \
+                    C, such as lists, trees, hashes, memory allocation, and \
+                    many other things.
 
 # Homepage for the port:
-homepage	http://www.gtk.org/
+homepage            http://www.gtk.org/
 
 # Master download sites for port's distribution file(s)
-master_sites	ftp://ftp.gtk.org/pub/glib/2.12 \
-		gnome:sources/glib/2.12
+master_sites        ftp://ftp.gtk.org/pub/glib/2.12 \
+                    gnome:sources/glib/2.12
 
 # Name of the distribution file, minus extract suffix (see below)
-distname	glib-${version}
+distname            glib-${version}
 
 # (Optional) Explicitly set suffix (default: .tar.gz)
-#extract.suffix	.tar.bz2
+#extract.suffix      .tar.bz2
 
 # (Optional) Use bzip2 instead of gzip for uncompressing distribution file
-use_bzip2	yes
+use_bzip2           yes
 
 # List of checksums for files to be fetched
 # <file name> <checksum type> <checksum>
-checksums	${distname}${extract.suffix} md5 077a9917b673a9a0bc63f351786dde24 \
-		${distname}${extract.suffix} sha1 02d344295ddaeafeec6bc6824b71e12bbf1b0394 \
-		${distname}${extract.suffix} rmd160 8680d27e630643e6653d88537907d06e3ba6e91a
+checksums   ${distname}${extract.suffix} md5 077a9917b673a9a0bc63f351786dde24 \
+        ${distname}${extract.suffix} sha1 02d344295ddaeafeec6bc6824b71e12bbf1b0394 \
+        ${distname}${extract.suffix} rmd160 8680d27e630643e6653d88537907d06e3ba6e91a
 
 # Any patches which should be applied after extracting this port.  These
-
 # should go in the files/ subdirectory of the port.
-patchfiles	patch-glib-2.0.pc.in patch-glib__gutils.c
+patchfiles          patch-glib-2.0.pc.in \
+                    patch-glib__gutils.c
 
 # Dependencies are defined by three settings:
-#    depends_lib:	installed at build time and at install time
-#    depends_run:	installed at install time
-#    depends_build:	installed at build time
+#    depends_lib:   installed at build time and at install time
+#    depends_run:   installed at install time
+#    depends_build: installed at build time
 #
 #    These options accept a list of depspecs. Depspecs are ':' delimited three
 #    value lists of type:match:portname. The following types are supported:
 #
-#	lib	- The lib type requires the match argument in the
-#		    format <libraryname>.<major version>
-#	bin	- The bin type requires the match argument to be the full
-#		    executable name
-#	<path>  - If a full path is specified as the type, the math argument
-#		    must be a complete regexp.
-#	portname must be the name of a valid port to build and install
-#	if the depspec is not matched.
-#	An alternative dependency depspec is the port:<portname> syntax,
-#	used when you want to insure the given dependency is satisfied
-#	exclusively by MacPorts.
-depends_build	    port:pkgconfig
-depends_lib	    port:gettext
+#   lib - The lib type requires the match argument in the
+#           format <libraryname>.<major version>
+#   bin - The bin type requires the match argument to be the full
+#           executable name
+#   <path>  - If a full path is specified as the type, the math argument
+#           must be a complete regexp.
+#   portname must be the name of a valid port to build and install
+#   if the depspec is not matched.
+#   An alternative dependency depspec is the port:<portname> syntax,
+#   used when you want to insure the given dependency is satisfied
+#   exclusively by MacPorts.
+depends_build       port:pkgconfig
+depends_lib         port:gettext
 
 # The type of configuration script this port uses.
-#configure.type     gnu
+#configure.type      gnu
 
 # A list of configuration time arguments you might want to pass to the configure script:
-configure.args   --mandir=${prefix}/share/man
+configure.args      --mandir=${prefix}/share/man
 
 # The directory name of the subdirectory of work/ where this port extracts
-#worksrcdir	glib
+#worksrcdir          glib
 
 # Alternative ways to build the port, packed as 'variants'
 variant puredarwin { depends_run bin:perl:perl5.8 }

Modified: branches/gsoc11-statistics/base/doc/macports.conf.in
===================================================================
--- branches/gsoc11-statistics/base/doc/macports.conf.in	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/doc/macports.conf.in	2013-06-21 19:46:52 UTC (rev 107206)
@@ -1,157 +1,167 @@
-# MacPorts system wide configuration file
 # $Id$
 
-# Set the directory in which to install ports. Must match where MacPorts itself is installed.
-prefix			@prefix_expanded@
+# MacPorts system-wide configuration file.
+# Commented-out values are defaults unless otherwise noted.
 
-# Set the user to run MacPorts compiles, etc as when privileges are dropped during an install
-#macportsuser		@RUNUSR@
+# Directory under which MacPorts should install ports. This must be
+# where MacPorts itself is installed.
+prefix              	@prefix_expanded@
 
-# Where to store MacPorts working data
-portdbpath		@localstatedir_expanded@/macports
+# User to run operations as when MacPorts drops privileges.
+#macportsuser       	@RUNUSR@
 
-# PATH settings that are used for external tools (configure, make, etc.) while
-# installing ports. The default paths are given in the example; it need not be
-# uncommented.  Customizing binpath is unsupported and is intended for
-# advanced users only.
-#binpath		@prefix_expanded@/bin:@prefix_expanded@/sbin:/bin:/sbin:/usr/bin:/usr/sbin
+# Directory for MacPorts working data.
+portdbpath          	@localstatedir_expanded@/macports
 
-# Directory containing Xcode Tools (default is to ask xcode-select)
-#developer_dir		@DEVELOPER_DIR@
+# Colon-delimited list of directories to search for external tools
+# (make(1), pkg-config(1), etc.). While installing ports, MacPorts uses
+# this list for PATH. Changing this setting is intended for advanced
+# users only and is unsupported.
+#binpath            	@prefix_expanded@/bin:@prefix_expanded@/sbin:/bin:/sbin:/usr/bin:/usr/sbin
 
-# Path to PackageMaker.app
-# It may be necessary to set this with Xcode >= 4.3, as that version
-# requires PackageMaker to be installed manually from the Auxiliary Tools for
-# Xcode disk image. The default is /Applications/PackageMaker.app with Xcode
-# 4.3 and ${developer_dir}/Applications/Utilities/PackageMaker.app with older
-# versions.
-#packagemaker_path /Applications/PackageMaker.app
+# Directory containing Xcode Tools. By default, MacPorts determines this
+# using xcode-select(1).
+#developer_dir      	@DEVELOPER_DIR@
 
-# Directory containing Applications from ports.
-applications_dir	@MPAPPLICATIONSDIR@
+# Location of PackageMaker. Defaults to
+# "${developer_dir}/Applications/Utilities/PackageMaker.app" with Xcode
+# 4.2 and earlier and "/Applications/PackageMaker.app" with 4.3 and later.
+#packagemaker_path  	/Applications/PackageMaker.app
 
-# Directory containing Frameworks from ports.
-frameworks_dir		@MPFRAMEWORKSDIR@
+# Directory for application bundles installed by ports.
+applications_dir    	@MPAPPLICATIONSDIR@
 
-# Where to find the sources list.
-sources_conf		@MPCONFIGDIR_EXPANDED@/sources.conf
+# Directory for frameworks installed by ports.
+frameworks_dir      	@MPFRAMEWORKSDIR@
 
-# Where to find global variants definition file (optional)
-variants_conf		@MPCONFIGDIR_EXPANDED@/variants.conf
+# Location of the MacPorts sources list.
+sources_conf        	@MPCONFIGDIR_EXPANDED@/sources.conf
 
-# When to build ports from source. Default is 'ifneeded', which downloads an
-# archive if available or builds from source otherwise. 'always' has the same
-# effect as -s on the command line, and 'never' is likewise the same as -b.
-#buildfromsource	ifneeded
+# Location of the MacPorts global variants definition file. Optional.
+variants_conf       	@MPCONFIGDIR_EXPANDED@/variants.conf
 
-# Type of archives to use for port images
-#
-# Supported types: tgz, tar, tbz, tbz2 (default), tlz, txz, xar, zip, cpgz, cpio
-#portarchivetype	tbz2
+# When MacPorts should build ports from source.
+# - ifneeded: Download binary archives if available; build from source
+#   otherwise.
+# - always: Always build from source; never try fetching archives.
+# - never: Never build from source; try fetching archives and abort if
+#   unavailable.
+#buildfromsource    	ifneeded
 
-# CPU architecture to compile for. Defaults to i386 or ppc on Mac OS X 10.5
-# and earlier, depending on the CPU type detected at runtime. On Mac OS X 10.6
-# the default is x86_64 if the CPU supports it, i386 otherwise.
-#build_arch		i386
+# Type of archive to use for port images. Supported types are cpgz,
+# cpio, tar, tbz, tbz2, tgz, tlz, txz, xar, zip.
+#portarchivetype    	tbz2
 
-# CPU architectures to use for Universal Binaries (+universal variant)
-universal_archs		@UNIVERSAL_ARCHS@
+# CPU architecture to target. Supported values are "ppc", "ppc64",
+# "i386", and "x86_64". Defaults to:
+# - OS X 10.5 and earlier: "ppc" on PowerPC, otherwise "i386".
+# - OS X 10.6 and later: "x86_64" on Intel 64, otherwise "i386".
+#build_arch         	i386
 
-# Use ccache (C/C++ compiler cache) - see http://ccache.samba.org/
-#configureccache	no
+# Space-delimited list of CPU architectures to target when building
+# universal. Defaults to "i386 ppc" on OS X 10.5 and earlier and
+# "x64_64 i386" on OS X 10.6 and later.
+universal_archs     	@UNIVERSAL_ARCHS@
 
-# Location where ccache stores its files
-#ccache_dir		@localstatedir_expanded@/macports/build/.ccache
+# Use ccache, a compiler cache for C, C++, Objective-C, and
+# Objective-C++. (See http://ccache.samba.org.) The "ccache" executable
+# must exist in one of the directories in binpath.
+#configureccache    	no
 
-# Maximum size ccache may use.
-# Use 'G', 'M', or 'K' suffix for giga-, mega- or kilobytes.
-#ccache_size		2G
+# Directory for ccache's cached compiler output.
+#ccache_dir         	@localstatedir_expanded@/macports/build/.ccache
 
-# Use distcc (distributed compiler) - see http://distcc.samba.org/
-#configuredistcc	no
+# Maximum size of files stored in ccache's cache. Append "G", "M", or
+# "K" for gigabytes, megabytes, or kilobytes.
+#ccache_size        	2G
 
-# Use pipes rather than intermediate files when compiling C/C++/etc
-#configurepipe		yes
+# Use distcc, a distributed compiler for C, C++, Objective-C, and
+# Objective-C++. (See http://distcc.org.) The "distcc" executable must
+# exist in one of the directories in binpath.
+#configuredistcc    	no
 
-# Lowered scheduling priority (0-20) to use for make when building ports
-#buildnicevalue		0
+# Use pipes rather than temporary files for communication between the
+# various stages of C, C++, Objective-C, and Objective-C++ compilation.
+#configurepipe      	yes
 
-# Number of simultaneous make jobs (commands) to use when building ports. This
-# value may be set to 0 so the number of simultaneous make jobs will be set to
-# the number of CPU cores that are automatically detected, or the number of GB
-# of physical memory plus one, whichever is less.
-#buildmakejobs		0
+# Lowered scheduling priority to use for commands run during configure,
+# build, and destroot. Accepted values are 0 (normal priority) through
+# 20 (lowest priority).
+#buildnicevalue     	0
 
-# umask value to use when a port installs its files
-#destroot_umask		022
+# Number of simultaneous make(1) jobs to use when building ports. If set
+# to 0, the number of jobs will be the lesser of:
+# - number of automatically-detected CPU cores
+# - gigabytes of physical memory + 1
+#buildmakejobs      	0
 
-# Set whether to automatically execute "clean" after "install" of ports
-#portautoclean		yes
+# umask value to use when a port installs its files.
+#destroot_umask     	022
 
-# Set to yes if you don't want logs to be deleted after successful builds
-#keeplogs		no
+# Automatically execute "clean" after "install" of ports.
+#portautoclean      	yes
 
-# Rsync server to fetch MacPorts sources from. Note that this is only used
-# for selfupdate. The source(s) for the ports tree are set in sources.conf.
-# Known mirrors at time of writing (see https://trac.macports.org/wiki/Mirrors
-# for the current list):
-#   rsync.macports.org        - California, USA (master)
-#   trd.no.rsync.macports.org - Trondheim, Norway
-#rsync_server		rsync.macports.org
+# Keep logs after successful installations.
+#keeplogs           	no
 
-# Rsync directory from which to pull the base/ component (infrastructure) of MacPorts
-# If this points to a .tar file, a signed .rmd160 must exist next to it
-# on the server and will be used to verify its integrity.
-#rsync_dir		release/tarballs/base.tar
+# The rsync server for fetching MacPorts base during selfupdate. This
+# setting is NOT used when downloading the ports tree; the sources for
+# the ports tree are set in sources.conf. See
+# https://trac.macports.org/wiki/Mirrors#MacPortsSource for a list of
+# available servers.
+#rsync_server       	rsync.macports.org
 
-# Rsync options
-#rsync_options		-rtzv --delete-after
+# Location of MacPorts base sources on rsync_server. If this references
+# a .tar file, a signed .rmd160 file must exist in the same directory
+# and will be used to verify its integrity. See
+# https://trac.macports.org/wiki/Mirrors#MacPortsSource to find the
+# correct rsync_dir for a particular rsync_server.
+#rsync_dir          	release/tarballs/base.tar
 
-# Options for generated startup items
-# startupitem_type may be "default", "systemstarter", "launchd", or "none";
-# if the option is empty or "default" then a startupitem type appropriate
-# to the platform will be chosen. Mac OS X 10.4 Tiger and above will default to
-# launchd, while older Mac OS X systems will default to systemstarter. If
-# option "none" is chosen, port startupitems are ignored and no startupitems
-# are installed.
-#startupitem_type	default
+# Options to pass to rsync when fetching MacPorts base and the ports tree.
+#rsync_options      	-rtzv --delete-after
 
-# Option to install symlinks into /Library/LaunchAgents or /Library/LaunchDaemons
-# startupitem_install may be empty, "yes" or "no";
-# if the option is NOT "no" then a symlink for the startupitem will be created in
-# the appropriate system directory.
+# Type of generated StartupItems.
+# - launchd: Create StartupItems for use with launchd.
+# - systemstarter: Create StartupItems for use with SystemStarter.
+# - rcng: Create StartupItems for use with the rc.d system.
+# - default: Create StartupItems for launchd on OS X and for rc.d on
+#   other platforms.
+# - none: Disable creation of StartupItems.
+#startupitem_type   	default
+
+# Create system-level symlinks to generated StartupItems. If set to
+# "no", symlinks will not be created; otherwise, symlinks will be placed
+# in /Library/LaunchDaemons or /Library/LaunchAgents as appropriate.
 #startupitem_install	yes
 
-# Extra environment variables to keep. Any variables listed here are added
-# to the list of variables that are not removed from the environment used
-# while processing ports. As with binpath, setting extra_env is intended for
-# advanced users and is unsupported.
-# extra_env		KEEP_THIS THIS_TOO
+# Extra environment variables to keep. MacPorts sanitizes its
+# environment while processing ports, keeping:
+# - DISPLAY
+# - DYLD_FALLBACK_FRAMEWORK_PATH, DYLD_FALLBACK_LIBRARY_PATH,
+#   DYLD_FRAMEWORK_PATH, DYLD_INSERT_LIBRARIES, DYLD_LIBRARY_PATH
+# - JAVA_HOME
+# - ARCHIVE_SITE_LOCAL, MASTER_SITE_LOCAL, PATCH_SITE_LOCAL
+# - PORTSRC
+# - ALL_PROXY, FTP_PROXY, http_proxy, HTTPS_PROXY, NO_PROXY, RSYNC_PROXY
+# - GROUP, USER
+# - COLUMNS, LINES
+# Variables listed in extra_env are added to this list. This has no
+# default value; setting it is intended for advanced users and is
+# unsupported. (Note that sudo(8) sanitizes its environment on OS X 10.5
+# and later, so it may have to be configured to pass the desired
+# variables to MacPorts.)
+#extra_env          	KEEP_THIS THIS_TOO
 
-# Proxy support
-# Precedence is: env, macports.conf, System Preferences
-# That is, if it's set in the environment, that will be used instead of
-# anything here or in System Preferences.  Setting proxy_override_env to yes
-# will cause any proxies set here (or in System Preferences if set there but
-# not here) to override what's in the environment.
-# Note that System Preferences doesn't have an rsync proxy definition.
-# Also note, on 10.5, sudo will clear many environment variables including
-# those for proxy support.
-# Equivalent environment variables: http_proxy, HTTPS_PROXY, FTP_PROXY,
-# RSYNC_PROXY, NO_PROXY
-#
-#proxy_override_env	yes
-# HTTP proxy:
-#proxy_http		hostname:12345
-# HTTPS proxy:
-#proxy_https		hostname:12345
-# FTP proxy:
-#proxy_ftp		hostname:12345
-# rsync proxy:
-#proxy_rsync		hostname:12345
-# hosts not to go through the proxy (comma-separated, applies to HTTP, HTTPS,
-# and FTP, but not rsync):
-#proxy_skip            internal1, internal2, internal3
+# Override proxy-related environment variables. By default, MacPorts
+# takes proxy settings from the environment, from the proxy_* options
+# below, and from Network Preferences, in that order. If this is set to
+# "yes", MacPorts uses proxy_*, then Network Preferences, then the
+# environment. (Note that Network Preferences does not have a setting
+# for rsync proxies. Also note that sudo(8) sanitizes its environment on
+# OS X 10.5 and later, so it may have to be configured to pass desired
+# variables to MacPorts.)
+#proxy_override_env 	no
 
 # Options for MacPorts usage statistics collection
 # If you would like to participate change this value to yes
@@ -164,37 +174,37 @@
 # Unique identifier for usage statistics
 stats_id	@STATS_UUID@
 
-# Options 'host_blacklist' and 'preferred_hosts', used for indicating
-# space separated lists of download hosts that should not be used or
-# should be used preferentially, respectively. These override the usual
-# ping time check.
-#host_blacklist     badhost1.org badhost2.org
-#preferred_hosts    preferredhost1.org preferredhost2.org
+# Proxies. These have no default values. The analagous environment
+# variables are "http_proxy", "HTTPS_PROXY", "FTP_PROXY", and
+# "RSYNC_PROXY".
+#proxy_http         	proxy1:12345
+#proxy_https        	proxy2:67890
+#proxy_ftp          	proxy3:02139
+#proxy_rsync        	proxy4:11377
 
-# Set whether to automatically run rev-upgrade after upgrading ports
-#revupgrade_autorun yes
-# Option controlling action taken by rev-upgrade, which checks for broken
-# linking and can rebuild affected ports. Possible values are
-#'rebuild' (default) or 'report'.
-#revupgrade_mode	rebuild
+# Comma-delimited list of hosts that MacPorts should not access through
+# the HTTP, HTTPS, and FTP proxies. This does not apply to rsync, and it
+# has no default value.
+#proxy_skip         	host1, host2, host3
 
-# When creating a pkg, specify the files and/or directories in
-# ${prefix} to delete after the unarchive stage and before the
-# pkg is created.  If not set, nothing is deleted.
-#
-# Because mpkg's are built from pkg's, any mpkg's will also have
-# the specified files and/or directories omitted.
-#
-# For example
-#
-#   pkg_post_unarchive_deletions include share/doc share/man
-#
-# will delete ${prefix}/include, ${prefix}/share/doc and
-# ${prefix}/share/man.
-#
-# This feature is useful when one wants to shrink the size of the
-# pkg's and mpkg's for deployment to Macs that will not be used
-# for development.  One large mpkg was observed to shrink from
-# 504 MB to 271 MB.
-#
-#pkg_post_unarchive_deletions include share/doc share/man
+# Space-delimited lists of download hosts that MacPorts should not use
+# and that MacPorts should prefer, respectively, overriding the usual
+# ping time checks. These have no default values.
+#host_blacklist     	badhost1 badhost2
+#preferred_hosts    	preferredhost1 preferredhost2
+
+# Whether MacPorts should automatically run rev-upgrade after upgrading
+# ports.
+#revupgrade_autorun 	yes
+
+# Whether rev-upgrade should automatically rebuild ports with broken
+# linking or merely report the breakage. Supported values are "report"
+# and "rebuild".
+#revupgrade_mode    	rebuild
+
+# Space-delimited list of files and directories to delete after the
+# unarchive stage and before creating a pkg. Paths are interpreted
+# relative to prefix, and there is no default value. This is useful for
+# removing unnecessary files and directories prior to pkg or mpkg
+# deployment.
+#pkg_post_unarchive_deletions	include share/doc share/man

Modified: branches/gsoc11-statistics/base/doc/port.1
===================================================================
--- branches/gsoc11-statistics/base/doc/port.1	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/doc/port.1	2013-06-21 19:46:52 UTC (rev 107206)
@@ -522,15 +522,27 @@
 This is the default when no flag is given.
 To remove the distribution files (tarballs, etc), specify
 .Fl -dist .
-To remove the work files, distribution files and logs, pass
+To remove any archives of a port that remain in the temporary download directory, pass
+.Fl -archive .
+(This does not remove archives from the installed location.)
+To remove the log files for a port, pass
+.Fl -logs .
+To remove the work files, distribution files, temporary archives and logs, pass
 .Fl -all .
-To remove log files for certain port, pass
-.Fl -logs .
 For example:
 .Pp
 .Dl "port clean --dist vim"
 .Dl "port clean --logs vim"
 .Pp
+To remove only certain version(s) of a port's temporary archives (
+.Ar version
+is any valid UNIX glob pattern), you can use:
+.Pp
+.Dl "port clean --archive vim 6.2.114"
+.Pp
+or:
+.Pp
+.Dl "port clean --archive vim '6.*'"
 .Ss log
 Parses and shows log files for
 .Ar portname .

Modified: branches/gsoc11-statistics/base/doc/pubkeys.conf.in
===================================================================
--- branches/gsoc11-statistics/base/doc/pubkeys.conf.in	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/doc/pubkeys.conf.in	2013-06-21 19:46:52 UTC (rev 107206)
@@ -1,10 +1,15 @@
-# Downloaded archives will only be used if they can be verified by a public
-# key listed here. Use full paths, one per line.
+# $Id$
 
+# MacPorts system-wide public key configuration file.
+
+# Downloaded archives will only be used if they can be verified by one
+# of the public keys listed here. Use absolute paths, one per line.
+
 @prefix_expanded@/share/macports/macports-pubkey.pem
 
-# To distribute archives of your own, you need a key pair generated like so:
-# openssl genrsa -des3 -out privkey.pem 2048
-# openssl rsa -in privkey.pem -pubout -out pubkey.pem
-# Then sign the archives like this:
-# openssl dgst -ripemd160 -sign privkey.pem -out archive.tbz2.rmd160 archive.tbz2
+# To distribute archives of your own, generate a key pair:
+#   openssl genrsa -des3 -out privkey.pem 2048
+#   openssl rsa -in privkey.pem -pubout -out pubkey.pem
+#
+# And sign the archives:
+#   openssl dgst -ripemd160 -sign privkey.pem -out archive.tbz2.rmd160 archive.tbz2

Modified: branches/gsoc11-statistics/base/doc/sources.conf
===================================================================
--- branches/gsoc11-statistics/base/doc/sources.conf	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/doc/sources.conf	2013-06-21 19:46:52 UTC (rev 107206)
@@ -1,31 +1,32 @@
-#  MacPorts system wide sources configuration file
-#  $Id$
+# $Id$
 
-#  To setup a local ports repository, insert a "file://" entry following
-#  the example below that points to your local ports directory:
-#  Example: file:///Users/landonf/misc/MacPorts/ports
+# MacPorts system-wide configuration file for ports tree sources.
+#
+# To change how MacPorts fetches base, see rsync_server and rsync_dir in
+# macports.conf.
 
-#  The default MacPorts repository should always be tagged [default]
-#  for proper functionality of various resources (port groups, mirror
-#  sites, etc).  If you switch it from the rsync:// URL, be sure to keep
-#  it tagged [default].
+# To add a local source, add a "file://" entry.
+#
+#   Example: file:///Users/landonf/misc/MacPorts/ports
+#
+# To prevent a source from synchronizing when `port sync` is used,
+# append "[nosync]" at the end.
+#
+#   Example: file:///Users/landonf/misc/MacPorts/ports [nosync]
+#
+# Note that MacPorts parses source URLs in order; when a port appears in
+# multiple sources, it installs the first occurrence. For local sources
+# to shadow remote ones, "file://" URLs must come before other URLs.
 
-#  To prevent a source from synchronizing when `port sync` is used,
-#  append [nosync] at the end as shown in this example:
-#  Example: file:///Users/landonf/misc/MacPorts/ports [nosync]
+# A list of rsync mirrors is available at
+# https://trac.macports.org/wiki/Mirrors#Portfiles.
+#
+# If an "rsync://" URL points to a .tar file, a signed .rmd160 file must
+# exist in the same directory on the server and will be used to verify
+# its integrity.
+#
+# For proper functionality of various resources (port groups, mirror
+# sites, etc.), the primary MacPorts source must always be tagged
+# "[default]", even if switched from the default "rsync://" URL.
 
-#  NOTE: The port command parses source URLs in order and installs the
-#        first occurrance when a port appears in multiple repositories.
-#        So keep "file://" URLs above other URL types.
-
-
-#  To get the ports tree from the master MacPorts server in California, USA use:
-#      rsync://rsync.macports.org/release/ports/
-#  To get it from the mirror in Trondheim, Norway use:
-#      rsync://trd.no.rsync.macports.org/release/ports/
-#  A current list of mirrors is available at https://trac.macports.org/wiki/Mirrors
-
-# If an rsync URL points to a .tar file, a signed .rmd160 must exist next to
-# it on the server and will be used to verify its integrity.
-
 rsync://rsync.macports.org/release/tarballs/ports.tar [default]

Modified: branches/gsoc11-statistics/base/doc/variants.conf
===================================================================
--- branches/gsoc11-statistics/base/doc/variants.conf	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/doc/variants.conf	2013-06-21 19:46:52 UTC (rev 107206)
@@ -1,9 +1,15 @@
-# To specify global variants to use for all port builds,
-# customize this file to list variant settings you want.
+# $Id$
+
+# MacPorts system-wide global variants configuration file.
+
+# Any variants listed here are applied to all port builds. As on the
+# command line, variants may be either enabled (+) or disabled (-), and
+# unsupported variants are simply ignored.
 #
-# Any variants specified here that are not supported by
-# a port will just be ignored. Multiple variants can be
-# specified per line, or one per line is also allowed.
+# Each line must be a space- or tab-delimited list of zero or more
+# variants.
 #
 # Example:
-# +ipv6 +no_x11
+#   -x11 +no_x11 +quartz
+#   +gcc48
+#   +universal

Modified: branches/gsoc11-statistics/base/src/darwintracelib1.0/darwintrace.c
===================================================================
--- branches/gsoc11-statistics/base/src/darwintracelib1.0/darwintrace.c	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/darwintracelib1.0/darwintrace.c	2013-06-21 19:46:52 UTC (rev 107206)
@@ -2,6 +2,7 @@
  * Copyright (c) 2005 Apple Inc. All rights reserved.
  * Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
  * All rights reserved.
+ * Copyright (c) 2006-2013 The MacPorts Project
  *
  * $Id$
  *
@@ -594,9 +595,11 @@
  * return 1 if path (once normalized) is in sandbox or redirected, 0 otherwise.
  */
 __attribute__((always_inline))
-inline int __darwintrace_is_in_sandbox(const char* path, char * newpath) {
+static inline int __darwintrace_is_in_sandbox(const char* path, char * newpath) {
 	char *t, *p, *_;
+	char *strpos, *normpos;
 	char lpath[MAXPATHLEN];
+	char normalizedpath[MAXPATHLEN];
 	
 	__darwintrace_setup();
 	
@@ -613,13 +616,49 @@
 		strcat(lpath, "/");
 		strcat(lpath, path);
 	}
-
 	p = lpath;
 
+	normalizedpath[0] = '\0';
+	strpos = p + 1;
+	normpos = normalizedpath;
+	for (;;) {
+		char *curpos = strsep(&strpos, "/");
+		if (curpos == NULL) {
+			/* reached the end of the path */
+			break;
+		} else if (*curpos == '\0') {
+			/* empty entry, ignore */
+			continue;
+		} else if (strcmp(curpos, ".") == 0) {
+			/* no-op directory, ignore */
+			continue;
+		} else if (strcmp(curpos, "..") == 0) {
+			/* walk up one directory */
+			char *lastSep = strrchr(normalizedpath, '/');
+			if (lastSep == NULL) {
+				/* path is completely empty */
+				normpos = normalizedpath;
+				*normpos = '\0';
+				continue;
+			}
+			/* remove last component by overwriting the slash with \0, update normpos */
+			*lastSep = '\0';
+			normpos = lastSep;
+		}
+		/* default case: standard path, copy */
+		strcat(normpos, "/");
+		normpos++;
+		strcat(normpos, curpos);
+		debug_printf("path %s, processing entry %s, normalized %s\n", path, curpos, normalizedpath);
+	}
+	if (*normalizedpath == '\0') {
+		strcat(normalizedpath, "/");
+	}
+
 	for (t = filemap; *t;) {
 		char state;
 		
-		if (__darwintrace_strbeginswith(p, t)) {
+		if (__darwintrace_strbeginswith(normalizedpath, t)) {
 			/* move t to the integer describing how to handle this match */
 			t += strlen(t) + 1;
 			switch (*t) {
@@ -637,11 +676,11 @@
 					if (_[-1] != '/') {
 						*_ = '/';
 					}
-					strcpy(_, p);
+					strcpy(_, normalizedpath);
 					return 1;
 				case 2:
 					/* ask the socket whether this file is OK */
-					return ask_for_dependency(p);
+					return ask_for_dependency(normalizedpath);
 				default:
 					fprintf(stderr, "darwintrace: error: unexpected byte in file map: `%x'\n", *t);
 					abort();
@@ -674,7 +713,7 @@
 		t++;
 	}
 
-	__darwintrace_log_op("sandbox_violation", path, 0);
+	__darwintrace_log_op("sandbox_violation", normalizedpath, 0);
 	return 0;
 }
 

Modified: branches/gsoc11-statistics/base/src/macports1.0/macports.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/macports1.0/macports.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/macports1.0/macports.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -6,7 +6,7 @@
 # Copyright (c) 2004 - 2005 Paul Guyot, <pguyot at kallisys.net>.
 # Copyright (c) 2004 - 2006 Ole Guldberg Jensen <olegb at opendarwin.org>.
 # Copyright (c) 2004 - 2005 Robert Shaw <rshaw at opendarwin.org>
-# Copyright (c) 2004 - 2012 The MacPorts Project
+# Copyright (c) 2004 - 2013 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -39,7 +39,7 @@
 package require macports_util 1.0
 
 namespace eval macports {
-    namespace export bootstrap_options user_options portinterp_options open_mports ui_priorities port_phases 
+    namespace export bootstrap_options user_options portinterp_options open_mports ui_priorities port_phases
     variable bootstrap_options "\
         portdbpath libpath binpath auto_path extra_env sources_conf prefix portdbformat \
         portarchivetype portautoclean \
@@ -50,9 +50,9 @@
         macportsuser proxy_override_env proxy_http proxy_https proxy_ftp proxy_rsync proxy_skip \
         master_site_local patch_site_local archive_site_local buildfromsource stats_participate stats_url stats_id \
         revupgrade_autorun revupgrade_mode revupgrade_check_id_loadcmds \
-        host_blacklist preferred_hosts\
+        host_blacklist preferred_hosts sandbox_enable \
         packagemaker_path default_compilers pkg_post_unarchive_deletions"
-    variable user_options ""
+    variable user_options {}
     variable portinterp_options "\
         portdbpath porturl portpath portbuildpath auto_path prefix prefix_frozen portsharepath \
         registry.path registry.format user_home \
@@ -61,7 +61,7 @@
         configureccache ccache_dir ccache_size configuredistcc configurepipe buildnicevalue buildmakejobs \
         applications_dir current_phase frameworks_dir developer_dir universal_archs build_arch \
         os_arch os_endian os_version os_major os_platform macosx_version macosx_deployment_target \
-        packagemaker_path default_compilers \
+        packagemaker_path default_compilers sandbox_enable \
         pkg_post_unarchive_deletions $user_options"
 
     # deferred options are only computed when needed.
@@ -73,7 +73,7 @@
 
     variable ui_priorities "error warn msg notice info debug any"
     variable port_phases "any fetch checksum"
-    variable current_phase "main"
+    variable current_phase main
 
     variable ui_prefix "---> "
 }
@@ -100,7 +100,7 @@
 # ui_options accessor
 proc macports::ui_isset {val} {
     if {[info exists macports::ui_options($val)]} {
-        if {$macports::ui_options($val) == "yes"} {
+        if {$macports::ui_options($val) eq "yes"} {
             return 1
         }
     }
@@ -111,7 +111,7 @@
 # global_options accessor
 proc macports::global_option_isset {val} {
     if {[info exists macports::global_options($val)]} {
-        if {$macports::global_options($val) == "yes"} {
+        if {$macports::global_options($val) eq "yes"} {
             return 1
         }
     }
@@ -130,7 +130,7 @@
     }
     # Add our log-channel to all already initialized channels
     foreach key [array names channels] {
-        set macports::channels($key) [concat $macports::channels($key) "debuglog"]
+        set macports::channels($key) [concat $macports::channels($key) debuglog]
     }
     return 0
 }
@@ -144,13 +144,13 @@
 
     set logname [macports::getportlogpath $portpath $portname]
     file mkdir $logname
-    set logname [file join $logname "main.log"]
+    set logname [file join $logname main.log]
 
     set ::debuglogname $logname
 
     # Truncate the file if already exists
     set ::debuglog [open $::debuglogname w]
-    puts $::debuglog "version:1"
+    puts $::debuglog version:1
 }
 proc macports::push_log {mport} {
     global ::logstack ::logenabled ::debuglog ::debuglogname
@@ -174,6 +174,7 @@
         lappend ::logstack [list $::debuglog $::debuglogname]
     }
 }
+
 proc macports::pop_log {} {
     global ::logenabled ::logstack ::debuglog ::debuglogname
     if {![info exists ::logenabled]} {
@@ -196,7 +197,7 @@
 proc set_phase {phase} {
     global macports::current_phase
     set macports::current_phase $phase
-    if {$phase != "main"} {
+    if {$phase ne "main"} {
         set cur_time [clock format [clock seconds] -format  {%+}]
         ui_debug "$phase phase started at $cur_time"
     }
@@ -205,23 +206,23 @@
 proc ui_message {priority prefix phase args} {
     global macports::channels ::debuglog macports::current_phase
     foreach chan $macports::channels($priority) {
-        if {[info exists ::debuglog] && ($chan == "debuglog")} {
+        if {[info exists ::debuglog] && ($chan eq "debuglog")} {
             set chan $::debuglog
             if {[info exists macports::current_phase]} {
                 set phase $macports::current_phase
             }
-            set strprefix ":$priority:$phase "
-            if {[lindex $args 0] == "-nonewline"} {
-                puts -nonewline $chan "$strprefix[lindex $args 1]"
+            set strprefix ":${priority}:$phase "
+            if {[lindex $args 0] eq "-nonewline"} {
+                puts -nonewline $chan $strprefix[lindex $args 1]
             } else {
-                puts $chan "$strprefix[lindex $args 0]"
+                puts $chan $strprefix[lindex $args 0]
             }
- 
+
         } else {
-            if {[lindex $args 0] == "-nonewline"} {
-                puts -nonewline $chan "$prefix[lindex $args 1]"
+            if {[lindex $args 0] eq "-nonewline"} {
+                puts -nonewline $chan $prefix[lindex $args 1]
             } else {
-                puts $chan "$prefix[lindex $args 0]"
+                puts $chan $prefix[lindex $args 0]
             }
         }
     }
@@ -235,10 +236,10 @@
     } else {
         set channels($priority) $default_channel
     }
-    
+
     # if some priority initialized after log file is being created
     if {[info exists ::debuglog]} {
-        set channels($priority) [concat $channels($priority) "debuglog"]
+        set channels($priority) [concat $channels($priority) debuglog]
     }
     # Simplify ui_$priority.
     try {
@@ -250,16 +251,16 @@
     try {
         eval ::ui_init $priority $prefix $channels($priority) $args
     } catch * {
-        interp alias {} ui_$priority {} ui_message $priority $prefix ""
+        interp alias {} ui_$priority {} ui_message $priority $prefix {}
         foreach phase $phases {
-            interp alias {} ui_${priority}_${phase} {} ui_message $priority $prefix $phase
+            interp alias {} ui_${priority}_$phase {} ui_message $priority $prefix $phase
         }
     }
 }
 
 # Default implementation of ui_prefix
 proc macports::ui_prefix_default {priority} {
-    switch $priority {
+    switch -- $priority {
         debug {
             return "DEBUG: "
         }
@@ -270,7 +271,7 @@
             return "Warning: "
         }
         default {
-            return ""
+            return {}
         }
     }
 }
@@ -280,17 +281,17 @@
 # ui_options(ports_verbose) - If set, output info messages (ui_info)
 # ui_options(ports_quiet) - If set, don't output "standard messages"
 proc macports::ui_channels_default {priority} {
-    switch $priority {
+    switch -- $priority {
         debug {
             if {[ui_isset ports_debug]} {
-                return {stderr}
+                return stderr
             } else {
                 return {}
             }
         }
         info {
             if {[ui_isset ports_verbose]} {
-                return {stdout}
+                return stdout
             } else {
                 return {}
             }
@@ -299,18 +300,18 @@
             if {[ui_isset ports_quiet]} {
                 return {}
             } else {
-                return {stdout}
+                return stdout
             }
         }
         msg {
-            return {stdout}
+            return stdout
         }
         warn -
         error {
-            return {stderr}
+            return stderr
         }
         default {
-            return {stdout}
+            return stdout
         }
     }
 }
@@ -331,14 +332,14 @@
 
 # find a binary either in a path defined at MacPorts' configuration time
 # or in the PATH environment variable through macports::binaryInPath (fallback)
-proc macports::findBinary {prog {autoconf_hint ""}} {
-    if {${autoconf_hint} != "" && [file executable ${autoconf_hint}]} {
-        return ${autoconf_hint}
+proc macports::findBinary {prog {autoconf_hint {}}} {
+    if {$autoconf_hint ne {} && [file executable $autoconf_hint]} {
+        return $autoconf_hint
     } else {
-        if {[catch {set cmd_path [macports::binaryInPath ${prog}]} result] == 0} {
-            return ${cmd_path}
+        if {[catch {set cmd_path [macports::binaryInPath $prog]} result] == 0} {
+            return $cmd_path
         } else {
-            return -code error "${result} or at its MacPorts configuration time location, did you move it?"
+            return -code error "$result or at its MacPorts configuration time location, did you move it?"
         }
     }
 }
@@ -358,13 +359,12 @@
 # deferred option processing
 proc macports::getoption {name} {
     global macports::$name
-    return [expr $$name]
+    return [set $name]
 }
 
 # deferred and on-need extraction of xcodeversion and xcodebuildcmd.
 proc macports::setxcodeinfo {name1 name2 op} {
-    global macports::xcodeversion
-    global macports::xcodebuildcmd
+    global macports::xcodeversion macports::xcodebuildcmd
 
     trace remove variable macports::xcodeversion read macports::setxcodeinfo
     trace remove variable macports::xcodebuildcmd read macports::setxcodeinfo
@@ -372,51 +372,51 @@
     if {![catch {findBinary xcodebuild $macports::autoconf::xcodebuild_path} xcodebuild]} {
         if {![info exists xcodeversion]} {
             # Determine xcode version
-            set macports::xcodeversion "2.0orlower"
+            set macports::xcodeversion 2.0orlower
             if {[catch {set xcodebuildversion [exec -- $xcodebuild -version 2> /dev/null]}] == 0} {
                 if {[regexp {Xcode ([0-9.]+)} $xcodebuildversion - xcode_v] == 1} {
                     set macports::xcodeversion $xcode_v
                 } elseif {[regexp "DevToolsCore-(.*);" $xcodebuildversion - devtoolscore_v] == 1} {
                     if {$devtoolscore_v >= 1809.0} {
-                        set macports::xcodeversion "3.2.6"
+                        set macports::xcodeversion 3.2.6
                     } elseif {$devtoolscore_v >= 1204.0} {
-                        set macports::xcodeversion "3.1.4"
+                        set macports::xcodeversion 3.1.4
                     } elseif {$devtoolscore_v >= 1100.0} {
-                        set macports::xcodeversion "3.1"
+                        set macports::xcodeversion 3.1
                     } elseif {$devtoolscore_v >= 921.0} {
-                        set macports::xcodeversion "3.0"
+                        set macports::xcodeversion 3.0
                     } elseif {$devtoolscore_v >= 798.0} {
-                        set macports::xcodeversion "2.5"
+                        set macports::xcodeversion 2.5
                     } elseif {$devtoolscore_v >= 762.0} {
-                        set macports::xcodeversion "2.4.1"
+                        set macports::xcodeversion 2.4.1
                     } elseif {$devtoolscore_v >= 757.0} {
-                        set macports::xcodeversion "2.4"
+                        set macports::xcodeversion 2.4
                     } elseif {$devtoolscore_v > 650.0} {
                         # XXX find actual version corresponding to 2.3
-                        set macports::xcodeversion "2.3"
+                        set macports::xcodeversion 2.3
                     } elseif {$devtoolscore_v >= 650.0} {
-                        set macports::xcodeversion "2.2.1"
+                        set macports::xcodeversion 2.2.1
                     } elseif {$devtoolscore_v > 620.0} {
                         # XXX find actual version corresponding to 2.2
-                        set macports::xcodeversion "2.2"
+                        set macports::xcodeversion 2.2
                     } elseif {$devtoolscore_v >= 620.0} {
-                        set macports::xcodeversion "2.1"
+                        set macports::xcodeversion 2.1
                     }
                 }
             } else {
                 ui_warn "xcodebuild exists but failed to execute"
-                set macports::xcodeversion "none"
+                set macports::xcodeversion none
             }
         }
         if {![info exists xcodebuildcmd]} {
-            set macports::xcodebuildcmd "$xcodebuild"
+            set macports::xcodebuildcmd $xcodebuild
         }
     } else {
         if {![info exists xcodeversion]} {
-            set macports::xcodeversion "none"
+            set macports::xcodeversion none
         }
         if {![info exists xcodebuildcmd]} {
-            set macports::xcodebuildcmd "none"
+            set macports::xcodebuildcmd none
         }
     }
 }
@@ -458,7 +458,7 @@
     global macports::developer_dir macports::os_major macports::xcodeversion
 
     trace remove variable macports::developer_dir read macports::set_developer_dir
-    
+
     # Look for xcodeselect, and make sure it has a valid value
     if {![catch {findBinary xcode-select $macports::autoconf::xcode_select_path} xcodeselect]} {
 
@@ -471,21 +471,21 @@
         }
 
         # The directory from xcode-select isn't correct.
-        
+
         # Ask mdfind where Xcode is and make some suggestions for the user,
         # searching by bundle identifier for various Xcode versions (3.x and 4.x)
         set installed_xcodes {}
         if {![catch {findBinary mdfind $macports::autoconf::mdfind_path} mdfind]} {
             set installed_xcodes [exec $mdfind "kMDItemCFBundleIdentifier == 'com.apple.Xcode' || kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'"]
         }
-        
+
         # In case mdfind metadata wasn't complete, also look in two well-known locations for Xcode.app
         foreach app {/Applications/Xcode.app /Developer/Applications/Xcode.app} {
             if {[file isdirectory $app]} {
                 lappend installed_xcodes $app
             }
         }
-        
+
         # Form a list of unique xcode installations
         set installed_xcodes [lsort -unique $installed_xcodes]
 
@@ -497,20 +497,20 @@
             ui_error "Please use xcode-select to select an Xcode installation:"
             foreach xcode $installed_xcodes {
                 set vers [exec $mdls -raw -name kMDItemVersion $xcode]
-                if {$vers == "(null)"} { set vers "unknown" }
-                if {[_is_valid_developer_dir "${xcode}/Contents/Developer"]} {
+                if {$vers eq "(null)"} {set vers unknown}
+                if {[_is_valid_developer_dir ${xcode}/Contents/Developer]} {
                     # Though xcode-select shipped with xcode 4.3 supports and encourages
                     # direct use of the app path, older xcode-select does not.
                     # Specify the Contents/Developer directory if it exists
-                    ui_error "    sudo xcode-select -switch ${xcode}/Contents/Developer # version ${vers}"
+                    ui_error "    sudo xcode-select -switch ${xcode}/Contents/Developer # version $vers"
                 } elseif {[vercmp $vers 4.3] >= 0} {
                     # Future proofing: fall back to the app-path only for xcode >= 4.3, since Contents/Developer doesn't exist
-                    ui_error "    sudo xcode-select -switch ${xcode} # version ${vers}"
-                } elseif {[_is_valid_developer_dir "${xcode}/../.."]} {
+                    ui_error "    sudo xcode-select -switch $xcode # version $vers"
+                } elseif {[_is_valid_developer_dir ${xcode}/../..]} {
                     # Older xcode (< 4.3) is below the developer directory
-                    ui_error "    sudo xcode-select -switch [file normalize ${xcode}/../..] # version ${vers}"
+                    ui_error "    sudo xcode-select -switch [file normalize ${xcode}/../..] # version $vers"
                 } else {
-                    ui_error "    # malformed Xcode at ${xcode}, version ${vers}"
+                    ui_error "    # malformed Xcode at ${xcode}, version $vers"
                 }
             }
         } else {
@@ -522,9 +522,9 @@
 
     # Try the default
     if {$os_major >= 11 && [vercmp $xcodeversion 4.3] >= 0} {
-        set devdir "/Applications/Xcode.app/Contents/Developer"
+        set devdir /Applications/Xcode.app/Contents/Developer
     } else {
-        set devdir "/Developer"
+        set devdir /Developer
     }
 
     set macports::developer_dir $devdir
@@ -540,7 +540,7 @@
 
     # Verify that the directory has some key subdirectories
     foreach subdir {Library usr} {
-        if {![file isdirectory "${dir}/${subdir}"]} {
+        if {![file isdirectory ${dir}/$subdir]} {
             return 0
         }
     }
@@ -551,95 +551,87 @@
 
 
 proc mportinit {{up_ui_options {}} {up_options {}} {up_variations {}}} {
-    if {$up_ui_options eq ""} {
+    if {$up_ui_options eq {}} {
         array set macports::ui_options {}
     } else {
         upvar $up_ui_options temp_ui_options
         array set macports::ui_options [array get temp_ui_options]
     }
-    if {$up_options eq ""} {
+    if {$up_options eq {}} {
         array set macports::global_options {}
     } else {
         upvar $up_options temp_options
         array set macports::global_options [array get temp_options]
     }
-    if {$up_variations eq ""} {
+    if {$up_variations eq {}} {
         array set variations {}
     } else {
         upvar $up_variations variations
     }
 
     # Initialize ui_*
-    foreach priority ${macports::ui_priorities} {
+    foreach priority $macports::ui_priorities {
         macports::ui_init $priority
     }
 
-    global auto_path env tcl_platform
-    global macports::autoconf::macports_conf_path
-    global macports::macports_user_dir
-    global macports::bootstrap_options
-    global macports::user_options
-    global macports::extra_env
-    global macports::portconf
-    global macports::portdbpath
-    global macports::portsharepath
-    global macports::registry.format
-    global macports::registry.path
-    global macports::sources
-    global macports::sources_default
-    global macports::sources_conf
-    global macports::destroot_umask
-    global macports::libpath
-    global macports::prefix
-    global macports::macportsuser
-    global macports::prefix_frozen
-    global macports::rsync_dir
-    global macports::rsync_options
-    global macports::rsync_server
-    global macports::variants_conf
-    global macports::stats_participate
-    global macports::stats_url
-    global macports::stats_id
-    global macports::xcodebuildcmd
-    global macports::xcodeversion
-    global macports::gccversion
-    global macports::configureccache
-    global macports::ccache_dir
-    global macports::ccache_size
-    global macports::configuredistcc
-    global macports::configurepipe
-    global macports::buildnicevalue
-    global macports::buildmakejobs
-    global macports::universal_archs
-    global macports::build_arch
-    global macports::os_arch
-    global macports::os_endian
-    global macports::os_version
-    global macports::os_major
-    global macports::os_platform
-    global macports::macosx_version
-    global macports::macosx_deployment_target
-    global macports::archivefetch_pubkeys
-    global macports::ping_cache
-    global macports::host_blacklisted
-    global macports::host_preferred
+    global auto_path env tcl_platform \
+        macports::autoconf::macports_conf_path \
+        macports::macports_user_dir \
+        macports::bootstrap_options \
+        macports::user_options \
+        macports::portconf \
+        macports::portsharepath \
+        macports::registry.format \
+        macports::registry.path \
+        macports::sources \
+        macports::sources_default \
+        macports::destroot_umask \
+        macports::libpath \
+        macports::prefix \
+        macports::macportsuser \
+        macports::prefix_frozen \
+        macports::xcodebuildcmd \
+        macports::xcodeversion \
+        macports::configureccache \
+        macports::ccache_dir \
+        macports::ccache_size \
+        macports::configuredistcc \
+        macports::configurepipe \
+        macports::buildnicevalue \
+        macports::buildmakejobs \
+        macports::universal_archs \
+        macports::build_arch \
+        macports::os_arch \
+        macports::os_endian \
+        macports::os_version \
+        macports::os_major \
+        macports::os_platform \
+        macports::macosx_version \
+        macports::macosx_deployment_target \
+        macports::archivefetch_pubkeys \
+        macports::ping_cache \
+        macports::host_blacklisted \
+        macports::host_preferred \
+        macports::stats_participate \
+        macports::stats_url \
+        macports::stats_id
 
     # Set the system encoding to utf-8
     encoding system utf-8
 
     # set up platform info variables
     set os_arch $tcl_platform(machine)
-    if {$os_arch == "Power Macintosh"} { set os_arch "powerpc" }
-    if {$os_arch == "i586" || $os_arch == "i686" || $os_arch == "x86_64"} { set os_arch "i386" }
+    if {$os_arch eq "Power Macintosh"} {set os_arch "powerpc"}
+    if {$os_arch eq "i586" || $os_arch eq "i686" || $os_arch eq "x86_64"} {set os_arch "i386"}
     set os_version $tcl_platform(osVersion)
     set os_major [lindex [split $os_version .] 0]
     set os_platform [string tolower $tcl_platform(os)]
     # Remove trailing "Endian"
     set os_endian [string range $tcl_platform(byteOrder) 0 end-6]
     set macosx_version {}
-    if {$os_platform == "darwin"} {
+    if {$os_platform eq "darwin"} {
         # This will probably break when Apple changes versioning
-        set macosx_version [expr 10.0 + ($os_major - 4) / 10.0]
+        set macosx_version [expr {10.0 + ($os_major - 4) / 10.0}]
     }
 
     # Ensure that the macports user directory (i.e. ~/.macports) exists if HOME is defined.
@@ -647,32 +639,32 @@
     if {[info exists env(HOME)]} {
         set macports::user_home $env(HOME)
         set macports::macports_user_dir [file normalize $macports::autoconf::macports_user_dir]
-    } elseif {[info exists env(SUDO_USER)] && $os_platform == "darwin"} {
+    } elseif {[info exists env(SUDO_USER)] && $os_platform eq "darwin"} {
         set macports::user_home [exec dscl -q . -read /Users/$env(SUDO_USER) NFSHomeDirectory | cut -d ' ' -f 2]
-        set macports::macports_user_dir [file join ${macports::user_home} [string range $macports::autoconf::macports_user_dir 2 end]]
-    } elseif {[exec id -u] != 0 && $os_platform == "darwin"} {
+        set macports::macports_user_dir [file join $macports::user_home [string range $macports::autoconf::macports_user_dir 2 end]]
+    } elseif {[exec id -u] != 0 && $os_platform eq "darwin"} {
         set macports::user_home [exec dscl -q . -read /Users/[exec id -un] NFSHomeDirectory | cut -d ' ' -f 2]
-        set macports::macports_user_dir [file join ${macports::user_home} [string range $macports::autoconf::macports_user_dir 2 end]]
+        set macports::macports_user_dir [file join $macports::user_home [string range $macports::autoconf::macports_user_dir 2 end]]
     } else {
         # Otherwise define the user directory as a directory that will never exist
-        set macports::macports_user_dir "/dev/null/NO_HOME_DIR"
-        set macports::user_home "/dev/null/NO_HOME_DIR"
+        set macports::macports_user_dir /dev/null/NO_HOME_DIR
+        set macports::user_home /dev/null/NO_HOME_DIR
     }
 
     # Configure the search path for configuration files
-    set conf_files ""
-    lappend conf_files "${macports_conf_path}/macports.conf"
-    if { [file isdirectory $macports_user_dir] } {
-        lappend conf_files "${macports_user_dir}/macports.conf"
+    set conf_files {}
+    lappend conf_files ${macports_conf_path}/macports.conf
+    if {[file isdirectory $macports_user_dir]} {
+        lappend conf_files ${macports_user_dir}/macports.conf
     }
     if {[info exists env(PORTSRC)]} {
         set PORTSRC $env(PORTSRC)
-        lappend conf_files ${PORTSRC}
+        lappend conf_files $PORTSRC
     }
 
     # Process all configuration files we find on conf_files list
     foreach file $conf_files {
-        if [file exists $file] {
+        if {[file exists $file]} {
             set portconf $file
             set fd [open $file r]
             while {[gets $fd line] >= 0} {
@@ -688,8 +680,8 @@
     }
 
     # Process per-user only settings
-    set per_user "${macports_user_dir}/user.conf"
-    if [file exists $per_user] {
+    set per_user ${macports_user_dir}/user.conf
+    if {[file exists $per_user]} {
         set fd [open $per_user r]
         while {[gets $fd line] >= 0} {
             if {[regexp {^(\w+)([ \t]+(.*))?$} $line match option ignore val] == 1} {
@@ -715,7 +707,7 @@
                     if {[lsearch -exact [list nosync default] $flag] == -1} {
                         ui_warn "$sources_conf source '$line' specifies invalid flag '$flag'"
                     }
-                    if {$flag == "default"} {
+                    if {$flag eq "default"} {
                         if {[info exists sources_default]} {
                             ui_warn "More than one default port source is defined."
                         }
@@ -733,20 +725,20 @@
     # [macports::getportresourcepath] fails when the first source doesn't
     # contain _resources.
     if {![info exists sources_default]} {
-        ui_warn "No default port source specified in $sources_conf, using last source as default"
+        ui_warn "No default port source specified in ${sources_conf}, using last source as default"
         set sources_default [lindex $sources end]
     }
 
     if {![info exists sources]} {
         if {[file isdirectory ports]} {
-            set sources "file://[pwd]/ports"
+            set sources file://[pwd]/ports
         } else {
             return -code error "No sources defined in $sources_conf"
         }
     }
 
     if {[info exists variants_conf]} {
-        if {[file exist $variants_conf]} {
+        if {[file exists $variants_conf]} {
             set fd [open $variants_conf r]
             while {[gets $fd line] >= 0} {
                 set line [string trimright $line]
@@ -772,8 +764,8 @@
 
     # pubkeys.conf
     set macports::archivefetch_pubkeys {}
-    if {[file isfile [file join ${macports_conf_path} pubkeys.conf]]} {
-        set fd [open [file join ${macports_conf_path} pubkeys.conf] r]
+    if {[file isfile [file join $macports_conf_path pubkeys.conf]]} {
+        set fd [open [file join $macports_conf_path pubkeys.conf] r]
         while {[gets $fd line] >= 0} {
             set line [string trim $line]
             if {![regexp {^[\ \t]*#.*$|^$} $line]} {
@@ -803,7 +795,7 @@
 
     # Format for receipts; currently only "sqlite" is allowed
     # could previously be "flat", so we switch that to sqlite
-    if {![info exists portdbformat] || $portdbformat == "flat" || $portdbformat == "sqlite"} {
+    if {![info exists portdbformat] || $portdbformat eq "flat" || $portdbformat eq "sqlite"} {
         set registry.format receipt_sqlite
     } else {
         return -code error "unknown registry format '$portdbformat' set in macports.conf"
@@ -811,29 +803,29 @@
 
     # Autoclean mode, whether to automatically call clean after "install"
     if {![info exists portautoclean]} {
-        set macports::portautoclean "yes"
+        set macports::portautoclean yes
         global macports::portautoclean
     }
     # whether to keep logs after successful builds
     if {![info exists keeplogs]} {
-        set macports::keeplogs "no"
+        set macports::keeplogs no
         global macports::keeplogs
     }
-   
+
     # Check command line override for autoclean
     if {[info exists macports::global_options(ports_autoclean)]} {
-        if {![string equal $macports::global_options(ports_autoclean) $portautoclean]} {
+        if {$macports::global_options(ports_autoclean) ne $portautoclean} {
             set macports::portautoclean $macports::global_options(ports_autoclean)
         }
     }
     # Trace mode, whether to use darwintrace to debug ports.
     if {![info exists porttrace]} {
-        set macports::porttrace "no"
+        set macports::porttrace no
         global macports::porttrace
     }
     # Check command line override for trace
     if {[info exists macports::global_options(ports_trace)]} {
-        if {![string equal $macports::global_options(ports_trace) $porttrace]} {
+        if {$macports::global_options(ports_trace) ne $porttrace} {
             set macports::porttrace $macports::global_options(ports_trace)
         }
     }
@@ -841,14 +833,14 @@
     if {![info exists macports::global_options(ports_binary_only)]
         && ![info exists macports::global_options(ports_source_only)]
         && [info exists macports::buildfromsource]} {
-        if {${macports::buildfromsource} == "never"} {
+        if {$macports::buildfromsource eq "never"} {
             set macports::global_options(ports_binary_only) yes
             set temp_options(ports_binary_only) yes
-        } elseif {${macports::buildfromsource} == "always"} {
+        } elseif {$macports::buildfromsource eq "always"} {
             set macports::global_options(ports_source_only) yes
             set temp_options(ports_source_only) yes
-        } elseif {${macports::buildfromsource} != "ifneeded"} {
-            ui_warn "'buildfromsource' set to unknown value '${macports::buildfromsource}', using 'ifneeded' instead"
+        } elseif {$macports::buildfromsource ne "ifneeded"} {
+            ui_warn "'buildfromsource' set to unknown value '$macports::buildfromsource', using 'ifneeded' instead"
         }
     }
 
@@ -862,11 +854,11 @@
 
     # Export verbosity.
     if {![info exists portverbose]} {
-        set macports::portverbose "no"
+        set macports::portverbose no
         global macports::portverbose
     }
     if {[info exists macports::ui_options(ports_verbose)]} {
-        if {![string equal $macports::ui_options(ports_verbose) $portverbose]} {
+        if {$macports::ui_options(ports_verbose) ne $portverbose} {
             set macports::portverbose $macports::ui_options(ports_verbose)
         }
     }
@@ -875,23 +867,23 @@
     # CPIO, XAR, etc.)
     global macports::portarchivetype
     if {![info exists portarchivetype]} {
-        set macports::portarchivetype "tbz2"
+        set macports::portarchivetype tbz2
     } else {
         set macports::portarchivetype [lindex $portarchivetype 0]
     }
 
     # Set rync options
     if {![info exists rsync_server]} {
+        global macports::rsync_server
         set macports::rsync_server rsync.macports.org
-        global macports::rsync_server
     }
     if {![info exists rsync_dir]} {
+        global macports::rsync_dir
         set macports::rsync_dir release/tarballs/base.tar
-        global macports::rsync_dir
     }
     if {![info exists rsync_options]} {
+        global macports::rsync_options
         set rsync_options "-rtzv --delete-after"
-        global macports::rsync_options
     }
 
     set portsharepath ${prefix}/share/macports
@@ -900,18 +892,18 @@
     }
 
     if {![info exists libpath]} {
-        set libpath "${prefix}/share/macports/Tcl"
+        set libpath ${prefix}/share/macports/Tcl
     }
 
     if {![info exists binpath]} {
-        set env(PATH) "${prefix}/bin:${prefix}/sbin:/bin:/sbin:/usr/bin:/usr/sbin"
+        set env(PATH) ${prefix}/bin:${prefix}/sbin:/bin:/sbin:/usr/bin:/usr/sbin
     } else {
-        set env(PATH) "$binpath"
+        set env(PATH) $binpath
     }
 
     # Set startupitem default type (can be overridden by portfile)
     if {![info exists macports::startupitem_type]} {
-        set macports::startupitem_type "default"
+        set macports::startupitem_type default
     }
 
     # Set whether startupitems are symlinked into system directories
@@ -932,7 +924,7 @@
         set macports::ccache_dir [file join $portdbpath build .ccache]
     }
     if {![info exists macports::ccache_size]} {
-        set macports::ccache_size "2G"
+        set macports::ccache_size 2G
     }
     if {![info exists macports::configuredistcc]} {
         set macports::configuredistcc no
@@ -964,10 +956,10 @@
     } elseif {[llength $macports::universal_archs] < 2} {
         ui_warn "invalid universal_archs configured (should contain at least 2 archs)"
     }
-    
+
     # Default arch to build for
     if {![info exists macports::build_arch]} {
-        if {$os_platform == "darwin"} {
+        if {$os_platform eq "darwin"} {
             if {$os_major >= 10} {
                 if {[sysctl hw.cpu64bit_capable] == 1} {
                     set macports::build_arch x86_64
@@ -975,14 +967,14 @@
                     set macports::build_arch i386
                 }
             } else {
-                if {$os_arch == "powerpc"} {
+                if {$os_arch eq "powerpc"} {
                     set macports::build_arch ppc
                 } else {
                     set macports::build_arch i386
                 }
             }
         } else {
-            set macports::build_arch ""
+            set macports::build_arch {}
         }
     } else {
         set macports::build_arch [lindex $macports::build_arch 0]
@@ -996,14 +988,18 @@
         set macports::revupgrade_autorun yes
     }
     if {![info exists macports::revupgrade_mode]} {
-        set macports::revupgrade_mode "rebuild"
+        set macports::revupgrade_mode rebuild
     }
     if {![info exists macports::global_options(ports_rev-upgrade_id-loadcmd-check)]
          && [info exists macports::revupgrade_check_id_loadcmds]} {
-        set macports::global_options(ports_rev-upgrade_id-loadcmd-check) ${macports::revupgrade_check_id_loadcmds}
-        set temp_options(ports_rev-upgrade_id-loadcmd-check) ${macports::revupgrade_check_id_loadcmds}
+        set macports::global_options(ports_rev-upgrade_id-loadcmd-check) $macports::revupgrade_check_id_loadcmds
+        set temp_options(ports_rev-upgrade_id-loadcmd-check) $macports::revupgrade_check_id_loadcmds
     }
 
+    if {![info exists macports::sandbox_enable]} {
+        set macports::sandbox_enable yes
+    }
+
     # make tools we run operate in UTF-8 mode
     set env(LANG) en_US.UTF-8
 
@@ -1019,7 +1015,7 @@
         COLUMNS LINES
     }
     if {[info exists extra_env]} {
-        set keepenvkeys [concat ${keepenvkeys} ${extra_env}]
+        set keepenvkeys [concat $keepenvkeys $extra_env]
     }
 
     if {[file isdirectory $libpath]} {
@@ -1039,9 +1035,9 @@
 
     # don't keep unusable TMPDIR/TMP values
     foreach var {TMP TMPDIR} {
-        if {[info exists env($var)] && [file writable $env($var)] && 
-            ([getuid] != 0 || $macportsuser == "root" ||
-             [file attributes $env($var) -owner] == $macportsuser)} {
+        if {[info exists env($var)] && [file writable $env($var)] &&
+            ([getuid] != 0 || $macportsuser eq "root" ||
+             [file attributes $env($var) -owner] eq $macportsuser)} {
             lappend keepenvkeys $var
         }
     }
@@ -1054,7 +1050,7 @@
     }
 
     # unset environment an extra time, to work around bugs in Leopard Tcl
-    if {$macosx_version == "10.5"} {
+    if {$macosx_version eq "10.5"} {
         foreach envkey $env_names {
             if {[lsearch -exact $keepenvkeys $envkey] == -1} {
                 unsetenv $envkey
@@ -1075,20 +1071,20 @@
     }
 
     if {![info exists developer_dir]} {
-        if {$os_platform == "darwin"} {
+        if {$os_platform eq "darwin"} {
             trace add variable macports::developer_dir read macports::set_developer_dir
         } else {
-            set macports::developer_dir ""
+            set macports::developer_dir {}
         }
     } else {
-        if {$os_platform == "darwin" && ![file isdirectory $developer_dir]} {
+        if {$os_platform eq "darwin" && ![file isdirectory $developer_dir]} {
             ui_warn "Your developer_dir setting in macports.conf points to a non-existing directory.\
                 Since this is known to cause problems, please correct the setting or comment it and let\
                 macports auto-discover the correct path."
         }
     }
 
-    if {[getuid] == 0 && $os_major >= 11 && $os_platform == "darwin" && 
+    if {[getuid] == 0 && $os_major >= 11 && $os_platform eq "darwin" &&
             [file isfile "${macports::user_home}/Library/Preferences/com.apple.dt.Xcode.plist"]} {
         macports::copy_xcode_plist $env(HOME)
     }
@@ -1099,49 +1095,49 @@
     }
 
     if {[info exists master_site_local] && ![info exists env(MASTER_SITE_LOCAL)]} {
-        set env(MASTER_SITE_LOCAL) "$master_site_local"
+        set env(MASTER_SITE_LOCAL) $master_site_local
     }
     if {[info exists patch_site_local] && ![info exists env(PATCH_SITE_LOCAL)]} {
-        set env(PATCH_SITE_LOCAL) "$patch_site_local"
+        set env(PATCH_SITE_LOCAL) $patch_site_local
     }
     if {[info exists archive_site_local] && ![info exists env(ARCHIVE_SITE_LOCAL)]} {
-        set env(ARCHIVE_SITE_LOCAL) "$archive_site_local"
+        set env(ARCHIVE_SITE_LOCAL) $archive_site_local
     }
 
     # Proxy handling (done this late since Pextlib is needed)
-    if {![info exists proxy_override_env] } {
-        set proxy_override_env "no"
+    if {![info exists proxy_override_env]} {
+        set proxy_override_env no
     }
     if {[catch {array set sysConfProxies [get_systemconfiguration_proxies]} result]} {
         return -code error "Unable to get proxy configuration from system: $result"
     }
-    if {![info exists env(http_proxy)] || $proxy_override_env == "yes" } {
+    if {![info exists env(http_proxy)] || $proxy_override_env eq "yes"} {
         if {[info exists proxy_http]} {
             set env(http_proxy) $proxy_http
         } elseif {[info exists sysConfProxies(proxy_http)]} {
             set env(http_proxy) $sysConfProxies(proxy_http)
         }
     }
-    if {![info exists env(HTTPS_PROXY)] || $proxy_override_env == "yes" } {
+    if {![info exists env(HTTPS_PROXY)] || $proxy_override_env eq "yes"} {
         if {[info exists proxy_https]} {
             set env(HTTPS_PROXY) $proxy_https
         } elseif {[info exists sysConfProxies(proxy_https)]} {
             set env(HTTPS_PROXY) $sysConfProxies(proxy_https)
         }
     }
-    if {![info exists env(FTP_PROXY)] || $proxy_override_env == "yes" } {
+    if {![info exists env(FTP_PROXY)] || $proxy_override_env eq "yes"} {
         if {[info exists proxy_ftp]} {
             set env(FTP_PROXY) $proxy_ftp
         } elseif {[info exists sysConfProxies(proxy_ftp)]} {
             set env(FTP_PROXY) $sysConfProxies(proxy_ftp)
         }
     }
-    if {![info exists env(RSYNC_PROXY)] || $proxy_override_env == "yes" } {
+    if {![info exists env(RSYNC_PROXY)] || $proxy_override_env eq "yes"} {
         if {[info exists proxy_rsync]} {
             set env(RSYNC_PROXY) $proxy_rsync
         }
     }
-    if {![info exists env(NO_PROXY)] || $proxy_override_env == "yes" } {
+    if {![info exists env(NO_PROXY)] || $proxy_override_env eq "yes"} {
         if {[info exists proxy_skip]} {
             set env(NO_PROXY) $proxy_skip
         } elseif {[info exists sysConfProxies(proxy_skip)]} {
@@ -1150,22 +1146,22 @@
     }
 
     # add ccache to environment
-    set env(CCACHE_DIR) ${macports::ccache_dir}
+    set env(CCACHE_DIR) $macports::ccache_dir
 
     # load cached ping times
     if {[catch {
         set pingfile [open ${macports::portdbpath}/pingtimes r]
         array set macports::ping_cache [gets $pingfile]
         close $pingfile
-    }]} { array set macports::ping_cache {} }
+    }]} {array set macports::ping_cache {}}
     # set up arrays of blacklisted and preferred hosts
     if {[info exists macports::host_blacklist]} {
-        foreach host ${macports::host_blacklist} {
+        foreach host $macports::host_blacklist {
             set macports::host_blacklisted($host) 1
         }
     }
     if {[info exists macports::preferred_hosts]} {
-        foreach host ${macports::preferred_hosts} {
+        foreach host $macports::preferred_hosts {
             set macports::host_preferred($host) 1
         }
     }
@@ -1174,10 +1170,10 @@
     _mports_load_quickindex
 
     if {![info exists macports::ui_options(ports_no_old_index_warning)]} {
-        set default_source_url [lindex ${sources_default} 0]
-        if {[macports::getprotocol $default_source_url] == "file" || [macports::getprotocol $default_source_url] == "rsync"} {
+        set default_source_url [lindex $sources_default 0]
+        if {[macports::getprotocol $default_source_url] eq "file" || [macports::getprotocol $default_source_url] eq "rsync"} {
             set default_portindex [macports::getindex $default_source_url]
-            if {[file exists $default_portindex] && [expr [clock seconds] - [file mtime $default_portindex]] > 1209600} {
+            if {[file exists $default_portindex] && [clock seconds] - [file mtime $default_portindex] > 1209600} {
                 ui_warn "port definitions are more than two weeks old, consider updating them by running 'port selfupdate'."
             }
         }
@@ -1194,7 +1190,7 @@
     if {$db_exists == 0 && [file exists ${registry.path}/receipts] && [file writable $db_path]} {
         ui_warn "Converting your registry to sqlite format, this might take a while..."
         if {[catch {registry::convert_to_sqlite}]} {
-            ui_debug "$::errorInfo"
+            ui_debug $::errorInfo
             file delete -force $db_path
             error "Failed to convert your registry to sqlite!"
         } else {
@@ -1207,11 +1203,11 @@
 proc mportshutdown {} {
     # save ping times
     global macports::ping_cache macports::portdbpath
-    if {[file writable ${macports::portdbpath}]} {
+    if {[file writable $macports::portdbpath]} {
         catch {
             foreach host [array names ping_cache] {
                 # don't save expired entries
-                if {[expr [clock seconds] - [lindex $ping_cache($host) 1]] < 86400} {
+                if {[clock seconds] - [lindex $ping_cache($host) 1] < 86400} {
                     lappend pinglist_fresh $host $ping_cache($host)
                 }
             }
@@ -1231,16 +1227,16 @@
     set target_dir "${target_homedir}/Library/Preferences"
     file delete -force "${target_dir}/com.apple.dt.Xcode.plist"
     if {[file isfile $user_plist]} {
-        if {![file isdirectory "${target_dir}"]} {
-            if {[catch {file mkdir "${target_dir}"} result]} {
+        if {![file isdirectory $target_dir]} {
+            if {[catch {file mkdir $target_dir} result]} {
                 ui_warn "Failed to create Library/Preferences in ${target_homedir}: $result"
                 return
             }
         }
-        if {[file writable ${target_dir}] && [catch {
-            ui_debug "Copying $user_plist to ${target_dir}"
+        if {[file writable $target_dir] && [catch {
+            ui_debug "Copying $user_plist to $target_dir"
             file copy -force $user_plist $target_dir
-            file attributes "${target_dir}/com.apple.dt.Xcode.plist" -owner $macportsuser -permissions 0644
+            file attributes ${target_dir}/com.apple.dt.Xcode.plist -owner $macportsuser -permissions 0644
         } result]} {
             ui_warn "Failed to copy com.apple.dt.Xcode.plist to ${target_dir}: $result"
         }
@@ -1279,17 +1275,17 @@
     $workername alias set_phase set_phase
 
     # instantiate the UI call-backs
-    foreach priority ${macports::ui_priorities} {
+    foreach priority $macports::ui_priorities {
         $workername alias ui_$priority ui_$priority
-        foreach phase ${macports::port_phases} {
-            $workername alias ui_${priority}_${phase} ui_${priority}_${phase}
+        foreach phase $macports::port_phases {
+            $workername alias ui_${priority}_$phase ui_${priority}_$phase
         }
- 
+
     }
 
     $workername alias ui_prefix ui_prefix
     $workername alias ui_channels ui_channels
-    
+
     $workername alias ui_warn_once ui_warn_once
 
     # Export some utility functions defined here.
@@ -1413,10 +1409,10 @@
     switch -- $suffix {
         .tbz -
         .tbz2 {
-            return "-j"
+            return -j
         }
         .tgz {
-            return "-z"
+            return -z
         }
         .txz {
             return "--use-compress-program [findBinary xz {}] -"
@@ -1425,7 +1421,7 @@
             return "--use-compress-program [findBinary lzma {}] -"
         }
         default {
-            return "-"
+            return -
         }
     }
 }
@@ -1450,16 +1446,16 @@
     # check if this is a binary archive or just the port dir
     set tarcmd [findBinary tar $macports::autoconf::tar_path]
     set tarflags [get_tar_flags [file extension $fetchfile]]
-    set qflag ${macports::autoconf::tar_q}
+    set qflag $macports::autoconf::tar_q
     set cmdline "$tarcmd ${tarflags}${qflag}xOf \"$fetchfile\" +CONTENTS"
-    ui_debug "$cmdline"
+    ui_debug $cmdline
     if {![catch {set contents [eval exec $cmdline]}]} {
         set binary 1
         ui_debug "getting port name from binary archive"
         # get the portname from the contents file
-        foreach line [split $contents "\n"] {
-            if {[lindex $line 0] == "@name"} {
-                # actually ${name}-${version}_${revision}
+        foreach line [split $contents \n] {
+            if {[lindex $line 0] eq "@name"} {
+                # actually ${name}-${version}_$revision
                 set portname [lindex $line 1]
             }
         }
@@ -1478,7 +1474,7 @@
     } else {
         set cmdline "$tarcmd ${tarflags}xf \"$fetchfile\""
     }
-    ui_debug "$cmdline"
+    ui_debug $cmdline
     if {[catch {eval exec $cmdline} result]} {
         return -code error "Port extract failed: $result"
     }
@@ -1489,7 +1485,7 @@
 
 proc macports::getprotocol {url} {
     if {[regexp {(?x)([^:]+)://.+} $url match protocol] == 1} {
-        return ${protocol}
+        return $protocol
     } else {
         return -code error "Can't parse url $url"
     }
@@ -1499,12 +1495,12 @@
 # I've added the destdir parameter.  This is the location a remotely
 # fetched port will be downloaded to (currently only applies to
 # mports:// sources).
-proc macports::getportdir {url {destdir "."}} {
+proc macports::getportdir {url {destdir .}} {
     global macports::extracted_portdirs
     set protocol [macports::getprotocol $url]
-    switch ${protocol} {
+    switch -- $protocol {
         file {
-            set path [file normalize [string range $url [expr [string length $protocol] + 3] end]]
+            set path [file normalize [string range $url [expr {[string length $protocol] + 3}] end]]
             if {![file isfile $path]} {
                 return $path
             } else {
@@ -1542,12 +1538,12 @@
 # @param path path in _resources we are interested in
 # @param fallback fall back to the default source tree
 # @return path to the _resources directory or the path to the fallback
-proc macports::getportresourcepath {url {path ""} {fallback yes}} {
+proc macports::getportresourcepath {url {path {}} {fallback yes}} {
     global macports::sources_default
 
     set protocol [getprotocol $url]
 
-    switch -- ${protocol} {
+    switch -- $protocol {
         file {
             set proposedpath [file normalize [file join [getportdir $url] .. ..]]
         }
@@ -1559,7 +1555,7 @@
     # append requested path
     set proposedpath [file join $proposedpath _resources $path]
 
-    if {$fallback == "yes" && ![file exists $proposedpath]} {
+    if {$fallback eq "yes" && ![file exists $proposedpath]} {
         return [getdefaultportresourcepath $path]
     }
 
@@ -1571,11 +1567,11 @@
 #
 # @param path path in _resources we are interested in
 # @return path to the _resources directory of the default source
-proc macports::getdefaultportresourcepath {{path ""}} {
+proc macports::getdefaultportresourcepath {{path {}}} {
     global macports::sources_default
 
-    set default_source_url [lindex ${sources_default} 0]
-    if {[getprotocol $default_source_url] == "file"} {
+    set default_source_url [lindex $sources_default 0]
+    if {[getprotocol $default_source_url] eq "file"} {
         set proposedpath [getportdir $default_source_url]
     } else {
         set proposedpath [getsourcepath $default_source_url]
@@ -1594,17 +1590,17 @@
 # of this function should be treated as an opaque handle to a
 # MacPorts Portfile.
 
-proc mportopen {porturl {options ""} {variations ""} {nocache ""}} {
+proc mportopen {porturl {options {}} {variations {}} {nocache {}}} {
     global macports::portdbpath macports::portconf macports::open_mports auto_path
 
     # Look for an already-open MPort with the same URL.
     # if found, return the existing reference and bump the refcount.
-    if {$nocache != ""} {
+    if {$nocache ne {}} {
         set mport {}
     } else {
         set mport [dlist_match_multi $macports::open_mports [list porturl $porturl variations $variations options $options]]
     }
-    if {$mport != {}} {
+    if {$mport ne {}} {
         # just in case more than one somehow matches
         set mport [lindex $mport 0]
         set refcnt [ditem_key $mport refcnt]
@@ -1617,7 +1613,7 @@
     if {[info exists options_array(portdir)]} {
         set portdir $options_array(portdir)
     } else {
-        set portdir ""
+        set portdir {}
     }
 
     set portpath [macports::getportdir $porturl $portdir]
@@ -1664,24 +1660,24 @@
 proc mportopen_installed {name version revision variants options} {
     global macports::registry.path
     set regref [lindex [registry::entry imaged $name $version $revision $variants] 0]
-    set portfile_dir [file join ${registry.path} registry portfiles $name "${version}_${revision}${variants}"]
+    set portfile_dir [file join ${registry.path} registry portfiles $name ${version}_${revision}$variants]
     file mkdir $portfile_dir
-    set fd [open "${portfile_dir}/Portfile" w]
+    set fd [open ${portfile_dir}/Portfile w]
     puts $fd [$regref portfile]
     close $fd
-    file mtime "${portfile_dir}/Portfile" [$regref date]
+    file mtime ${portfile_dir}/Portfile [$regref date]
 
     set variations {}
     set minusvariant [lrange [split [$regref negated_variants] -] 1 end]
     set plusvariant [lrange [split [$regref variants] +] 1 end]
     foreach v $plusvariant {
-        lappend variations $v "+"
+        lappend variations $v +
     }
     foreach v $minusvariant {
-        lappend variations $v "-"
+        lappend variations $v -
     }
     lappend options subport $name
-    return [mportopen "file://${portfile_dir}/" $options $variations]
+    return [mportopen file://${portfile_dir}/ $options $variations]
 }
 
 # mportclose_installed
@@ -1693,7 +1689,7 @@
     }
     mportclose $mport
     set portfiles_dir [file join ${registry.path} registry portfiles $subport]
-    set portfile [file join $portfiles_dir "${version}_${revision}${portvariants}" Portfile]
+    set portfile [file join $portfiles_dir ${version}_${revision}$portvariants Portfile]
     file delete -force $portfile [file dirname $portfile]
     if {[llength [glob -nocomplain -directory $portfiles_dir *]] == 0} {
         file delete -force $portfiles_dir
@@ -1722,12 +1718,12 @@
     foreach category [lsort -increasing -unique [readdir $root]] {
         set pathToCategory [file join $root $category]
         # process the category dirs but not _resources
-        if {[file isdirectory $pathToCategory] && [string index [file tail $pathToCategory] 0] != "_"} {
+        if {[file isdirectory $pathToCategory] && [string index [file tail $pathToCategory] 0] ne "_"} {
             # Iterate on port directories.
             foreach port [lsort -increasing -unique [readdir $pathToCategory]] {
                 set pathToPort [file join $pathToCategory $port]
                 if {[file isdirectory $pathToPort] &&
-                  [file exists [file join $pathToPort "Portfile"]]} {
+                  [file exists [file join $pathToPort Portfile]]} {
                     # Call the function.
                     $func [file join $category $port]
 
@@ -1777,7 +1773,7 @@
         if {$found} {
             return [file join $path $filename]
         } else {
-            return ""
+            return {}
         }
     } else {
         return $found
@@ -1791,20 +1787,20 @@
 proc _mportinstalled {mport} {
     # Check for the presence of the port in the registry
     set workername [ditem_key $mport workername]
-    return [$workername eval registry_exists_for_name \${subport}]
+    return [$workername eval registry_exists_for_name \$subport]
 }
 
 # Determine if a port is active
 proc _mportactive {mport} {
     set workername [ditem_key $mport workername]
-    if {![catch {set reslist [$workername eval registry_active \${subport}]}] && [llength $reslist] > 0} {
+    if {![catch {set reslist [$workername eval registry_active \$subport]}] && [llength $reslist] > 0} {
         set i [lindex $reslist 0]
         set name [lindex $i 0]
         set version [lindex $i 1]
         set revision [lindex $i 2]
         set variants [lindex $i 3]
         array set portinfo [mportinfo $mport]
-        if {$name == $portinfo(name) && $version == $portinfo(version)
+        if {$name eq $portinfo(name) && $version == $portinfo(version)
             && $revision == $portinfo(revision) && $variants == $portinfo(canonical_active_variants)} {
             return 1
         }
@@ -1817,7 +1813,7 @@
     if {[catch {set reslist [registry::active $portname]}]} {
         return 0
     } else {
-        return [expr [llength $reslist] > 0]
+        return [expr {[llength $reslist] > 0}]
     }
 }
 
@@ -1841,11 +1837,11 @@
         ui_debug "Didn't find receipt, going to depspec regex for: $portname"
         set workername [ditem_key $mport workername]
         set type [lindex [split $depspec :] 0]
-        switch $type {
-            lib { return [$workername eval _libtest $depspec] }
-            bin { return [$workername eval _bintest $depspec] }
-            path { return [$workername eval _pathtest $depspec] }
-            port { return 0 }
+        switch -- $type {
+            lib {return [$workername eval _libtest $depspec]}
+            bin {return [$workername eval _bintest $depspec]}
+            path {return [$workername eval _pathtest $depspec]}
+            port {return 0}
             default {return -code error "unknown depspec type: $type"}
         }
         return 0
@@ -1867,7 +1863,7 @@
         [llength $portinfo(conflicts)] > 0} {
         ui_debug "Checking for conflicts against [_mportkey $mport subport]"
         foreach conflictport $portinfo(conflicts) {
-            if {[_mportispresent $mport port:${conflictport}]} {
+            if {[_mportispresent $mport port:$conflictport]} {
                 lappend conflictlist $conflictport
             }
         }
@@ -1875,14 +1871,14 @@
         ui_debug "[_mportkey $mport subport] has no conflicts"
     }
 
-    if {[llength ${conflictlist}] != 0} {
+    if {[llength $conflictlist] != 0} {
         if {[macports::global_option_isset ports_force]} {
-            ui_warn "Force option set; installing $portinfo(name) despite conflicts with: ${conflictlist}"
+            ui_warn "Force option set; installing $portinfo(name) despite conflicts with: $conflictlist"
         } else {
             if {![macports::ui_isset ports_debug]} {
-                ui_msg ""
+                ui_msg {}
             }
-            return -code error "Can't install $portinfo(name) because conflicting ports are installed: ${conflictlist}"
+            return -code error "Can't install $portinfo(name) because conflicting ports are installed: $conflictlist"
         }
     }
 }
@@ -1899,7 +1895,7 @@
         ![catch {$workername eval check_supported_archs} result] && $result == 0 &&
         ![catch {$workername eval eval_targets $target} result] && $result == 0} {
         # If auto-clean mode, clean-up after dependency install
-        if {[string equal ${macports::portautoclean} "yes"]} {
+        if {$macports::portautoclean eq "yes"} {
             # Make sure we are back in the port path before clean
             # otherwise if the current directory had been changed to
             # inside the port,  the next port may fail when trying to
@@ -1917,7 +1913,7 @@
         # An error occurred.
         global ::logenabled ::debuglogname
         ui_error "Failed to install $portname"
-        ui_debug "$::errorInfo"
+        ui_debug $::errorInfo
         if {[info exists ::logenabled] && $::logenabled && [info exists ::debuglogname]} {
             ui_notice "Please see the log file for port $portname for details:\n    $::debuglogname"
         }
@@ -1938,7 +1934,7 @@
         return 1
     }
     set portname [_mportkey $mport subport]
-    if {$target != "clean"} {
+    if {$target ne "clean"} {
         macports::push_log $mport
     }
 
@@ -1961,9 +1957,9 @@
     if {[macports::_target_needs_deps $target] && [macports::_mport_has_deptypes $mport [macports::_deptypes_for_target $target $workername]]} {
         registry::exclusive_lock
         # see if we actually need to build this port
-        if {($target != "activate" && $target != "install") ||
+        if {($target ne "activate" && $target ne "install") ||
             ![$workername eval registry_exists \$subport \$version \$revision \$portvariants]} {
-    
+
             # upgrade dependencies that are already installed
             if {![macports::global_option_isset ports_nodeps]} {
                 macports::_upgrade_mport_deps $mport $target
@@ -1973,13 +1969,13 @@
         ui_msg -nonewline "$macports::ui_prefix Computing dependencies for [_mportkey $mport subport]"
         if {[macports::ui_isset ports_debug]} {
             # play nice with debug messages
-            ui_msg ""
+            ui_msg {}
         }
         if {[mportdepends $mport $target] != 0} {
             return 1
         }
         if {![macports::ui_isset ports_debug]} {
-            ui_msg ""
+            ui_msg {}
         }
 
         # Select out the dependents along the critical path,
@@ -1987,7 +1983,7 @@
         set dlist [dlist_append_dependents $macports::open_mports $mport {}]
 
         dlist_delete dlist $mport
-        
+
         # print the dep list
         if {[llength $dlist] > 0} {
             set depstring "$macports::ui_prefix Dependencies to be installed:"
@@ -1998,11 +1994,11 @@
         }
 
         # install them
-        set result [dlist_eval $dlist _mportactive [list _mportexec "activate"]]
+        set result [dlist_eval $dlist _mportactive [list _mportexec activate]]
 
         registry::exclusive_unlock
 
-        if {$result != {}} {
+        if {$result ne {}} {
             set errstring "The following dependencies were not installed:"
             foreach ditem $result {
                 append errstring " [ditem_key $ditem provides]"
@@ -2020,13 +2016,13 @@
         }
     } else {
         # No dependencies, but we still need to check for conflicts.
-        if {$target == "" || $target == "install" || $target == "activate"} {
+        if {$target eq {} || $target eq "install" || $target eq "activate"} {
             _mporterrorifconflictsinstalled $mport
         }
     }
 
     set clean 0
-    if {[string equal ${macports::portautoclean} "yes"] && ([string equal $target "install"] || [string equal $target "activate"])} {
+    if {$macports::portautoclean eq "yes" && ($target eq "install" || $target eq "activate")} {
         # If we're doing an install, check if we should clean after
         set clean 1
     }
@@ -2041,7 +2037,7 @@
         catch {cd $portpath}
         $workername eval eval_targets clean
     }
-    
+
     global ::logenabled ::debuglogname
     if {[info exists ::logenabled] && $::logenabled && [info exists ::debuglogname]} {
         if {$result != 0} {
@@ -2072,13 +2068,13 @@
         }
         foreach depspec $portinfo($deptype) {
             set dep_portname [$workername eval _get_dep_port $depspec]
-            if {$dep_portname != "" && ![info exists depscache(port:$dep_portname)] && [$test $dep_portname]} {
+            if {$dep_portname ne {} && ![info exists depscache(port:$dep_portname)] && [$test $dep_portname]} {
                 set variants {}
-    
+
                 # check that the dep has the required archs
                 set active_archs [_get_registry_archs $dep_portname]
-                if {$deptype != "depends_fetch" && $deptype != "depends_extract"
-                    && $active_archs != "" && $active_archs != "noarch" && $required_archs != "noarch"
+                if {$deptype ne "depends_fetch" && $deptype ne "depends_extract"
+                    && $active_archs ne {} && $active_archs ne "noarch" && $required_archs ne "noarch"
                     && [lsearch -exact $depends_skip_archcheck $dep_portname] == -1} {
                     set missing {}
                     foreach arch $required_archs {
@@ -2130,8 +2126,8 @@
                         }
                     }
                 }
-    
-                set status [macports::upgrade $dep_portname "port:$dep_portname" $variants $options depscache]
+
+                set status [macports::upgrade $dep_portname port:$dep_portname $variants $options depscache]
                 # status 2 means the port was not found in the index
                 if {$status != 0 && $status != 2 && ![macports::ui_isset ports_processall]} {
                     return -code error "upgrade $dep_portname failed"
@@ -2148,7 +2144,7 @@
     set regref [registry::open_entry [lindex $i 0] [lindex $i 1] [lindex $i 2] [lindex $i 3] [lindex $i 5]]
     set archs [registry::property_retrieve $regref archs]
     if {$archs == 0} {
-        set archs ""
+        set archs {}
     }
     return $archs
 }
@@ -2172,7 +2168,7 @@
 #
 # @param url source URL to check
 # @return a list containing filename and extension or an empty list
-proc _source_is_snapshot {url {filename ""} {extension ""}} {
+proc _source_is_snapshot {url {filename {}} {extension {}}} {
     upvar $filename myfilename
     upvar $extension myextension
 
@@ -2186,14 +2182,14 @@
     return 0
 }
 
-proc macports::getportbuildpath {id {portname ""}} {
+proc macports::getportbuildpath {id {portname {}}} {
     global macports::portdbpath
     regsub {://} $id {.} port_path
     regsub -all {/} $port_path {_} port_path
     return [file join $portdbpath build $port_path $portname]
 }
 
-proc macports::getportlogpath {id {portname ""}} {
+proc macports::getportlogpath {id {portname {}}} {
     global macports::portdbpath
     regsub {://} $id {.} port_path
     regsub -all {/} $port_path {_} port_path
@@ -2204,13 +2200,13 @@
     return [file join $portbuildpath work]
 }
 
-proc macports::getportworkpath_from_portdir {portpath {portname ""}} {
+proc macports::getportworkpath_from_portdir {portpath {portname {}}} {
     return [macports::getportworkpath_from_buildpath [macports::getportbuildpath $portpath $portname]]
 }
 
 proc macports::getindex {source} {
     # Special case file:// sources
-    if {[macports::getprotocol $source] == "file"} {
+    if {[macports::getprotocol $source] eq "file"} {
         return [file join [macports::getportdir $source] PortIndex]
     }
 
@@ -2218,9 +2214,9 @@
 }
 
 proc mportsync {{optionslist {}}} {
-    global macports::sources macports::portdbpath macports::rsync_options tcl_platform
-    global macports::portverbose
-    global macports::autoconf::rsync_path macports::autoconf::tar_path macports::autoconf::openssl_path
+    global macports::sources macports::portdbpath macports::rsync_options \
+           tcl_platform macports::portverbose macports::autoconf::rsync_path \
+           macports::autoconf::tar_path macports::autoconf::openssl_path
     array set options $optionslist
     if {[info exists options(no_reindex)]} {
         upvar $options(needed_portindex_var) any_needed_portindex
@@ -2241,12 +2237,12 @@
         switch -regexp -- [macports::getprotocol $source] {
             {^file$} {
                 set portdir [macports::getportdir $source]
-                set svn_cmd ""
+                set svn_cmd {}
                 catch {set svn_cmd [macports::findBinary svn]}
-                set git_cmd ""
+                set git_cmd {}
                 catch {set git_cmd [macports::findBinary git]}
-                if {$svn_cmd != "" && ([file exists $portdir/.svn] || ![catch {exec $svn_cmd info $portdir > /dev/null 2>@1}])} {
-                    set svn_commandline "$svn_cmd update --non-interactive ${portdir}"
+                if {$svn_cmd ne {} && ([file exists ${portdir}/.svn] || ![catch {exec $svn_cmd info $portdir > /dev/null 2>@1}])} {
+                    set svn_commandline "$svn_cmd update --non-interactive $portdir"
                     ui_debug $svn_commandline
                     if {
                         [catch {
@@ -2264,12 +2260,12 @@
                             }
                         }]
                     } {
-                        ui_debug "$::errorInfo"
+                        ui_debug $::errorInfo
                         ui_error "Synchronization of the local ports tree failed doing an svn update"
                         incr numfailed
                         continue
                     }
-                } elseif {$git_cmd != "" && [file exists $portdir/.git]} {
+                } elseif {$git_cmd ne {} && [file exists ${portdir}/.git]} {
                     set git_commandline "pushd $portdir ; $git_cmd pull --rebase ; popd"
                     ui_debug $git_commandline
                     if {
@@ -2288,7 +2284,7 @@
                             }
                         }]
                     } {
-                        ui_debug "$::errorInfo"
+                        ui_debug $::errorInfo
                         ui_error "Synchronization of the local ports tree failed doing a git pull --rebase"
                         incr numfailed
                         continue
@@ -2307,19 +2303,19 @@
                 file mkdir $destdir
 
                 if {$is_tarball} {
-                    set exclude_option ""
+                    set exclude_option {}
                     # need to do a few things before replacing the ports tree in this case
                     set destdir [file dirname $destdir]
                 } else {
                     # Keep rsync happy with a trailing slash
-                    if {[string index $source end] != "/"} {
-                        append source "/"
+                    if {[string index $source end] ne "/"} {
+                        append source /
                     }
                     # don't sync PortIndex yet; we grab the platform specific one afterwards
-                    set exclude_option "'--exclude=/PortIndex*'"
+                    set exclude_option '--exclude=/PortIndex*'
                 }
                 # Do rsync fetch
-                set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} ${exclude_option} ${source} ${destdir}"
+                set rsync_commandline "$macports::autoconf::rsync_path $rsync_options $exclude_option $source $destdir"
                 ui_debug $rsync_commandline
                 if {[catch {system $rsync_commandline}]} {
                     ui_error "Synchronization of the local ports tree failed doing rsync"
@@ -2330,18 +2326,18 @@
                 if {$is_tarball} {
                     # verify signature for tarball
                     global macports::archivefetch_pubkeys
-                    set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} ${exclude_option} ${source}.rmd160 ${destdir}"
+                    set rsync_commandline "$macports::autoconf::rsync_path $rsync_options $exclude_option ${source}.rmd160 $destdir"
                     ui_debug $rsync_commandline
                     if {[catch {system $rsync_commandline}]} {
                         ui_error "Synchronization of the ports tree signature failed doing rsync"
                         incr numfailed
                         continue
                     }
-                    set tarball "${destdir}/[file tail $source]"
-                    set signature "${tarball}.rmd160"
+                    set tarball ${destdir}/[file tail $source]
+                    set signature ${tarball}.rmd160
                     set openssl [macports::findBinary openssl $macports::autoconf::openssl_path]
                     set verified 0
-                    foreach pubkey ${macports::archivefetch_pubkeys} {
+                    foreach pubkey $macports::archivefetch_pubkeys {
                         if {![catch {exec $openssl dgst -ripemd160 -verify $pubkey -signature $signature $tarball} result]} {
                             set verified 1
                             ui_debug "successful verification with key $pubkey"
@@ -2360,7 +2356,7 @@
                     # extract tarball and move into place
                     set tar [macports::findBinary tar $macports::autoconf::tar_path]
                     file mkdir ${destdir}/tmp
-                    set tar_cmd "$tar -C ${destdir}/tmp -xf ${tarball}"
+                    set tar_cmd "$tar -C ${destdir}/tmp -xf $tarball"
                     ui_debug $tar_cmd
                     if {[catch {system $tar_cmd}]} {
                         ui_error "Failed to extract ports tree from tarball!"
@@ -2382,16 +2378,16 @@
 
                 set needs_portindex 1
                 # now sync the index if the local file is missing or older than a day
-                if {![file isfile $indexfile] || [expr [clock seconds] - [file mtime $indexfile]] > 86400
+                if {![file isfile $indexfile] || [clock seconds] - [file mtime $indexfile] > 86400
                       || [info exists options(no_reindex)]} {
                     if {$is_tarball} {
                         # chop ports.tar off the end
                         set index_source [string range $source 0 end-[string length [file tail $source]]]
                     } else {
-                        set index_source $source 
+                        set index_source $source
                     }
                     set remote_indexfile "${index_source}PortIndex_${macports::os_platform}_${macports::os_major}_${macports::os_arch}/PortIndex"
-                    set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} $remote_indexfile ${destdir}"
+                    set rsync_commandline "$macports::autoconf::rsync_path $rsync_options $remote_indexfile $destdir"
                     ui_debug $rsync_commandline
                     if {[catch {system $rsync_commandline}]} {
                         ui_debug "Synchronization of the PortIndex failed doing rsync"
@@ -2402,10 +2398,10 @@
                             set ok 0
                             set needs_portindex 1
                             # verify signature for PortIndex
-                            set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} ${remote_indexfile}.rmd160 ${destdir}"
+                            set rsync_commandline "$macports::autoconf::rsync_path $rsync_options ${remote_indexfile}.rmd160 $destdir"
                             ui_debug $rsync_commandline
                             if {![catch {system $rsync_commandline}]} {
-                                foreach pubkey ${macports::archivefetch_pubkeys} {
+                                foreach pubkey $macports::archivefetch_pubkeys {
                                     if {![catch {exec $openssl dgst -ripemd160 -verify $pubkey -signature ${destdir}/PortIndex.rmd160 ${destdir}/PortIndex} result]} {
                                         set ok 1
                                         set needs_portindex 0
@@ -2446,7 +2442,7 @@
                         }
                     }
 
-                    if {(![info exists options(ports_force)] || $options(ports_force) != "yes") && $updated <= 0} {
+                    if {(![info exists options(ports_force)] || $options(ports_force) ne "yes") && $updated <= 0} {
                         ui_info "No updates for $source"
                         continue
                     }
@@ -2454,8 +2450,8 @@
                     file mkdir $destdir
 
                     set verboseflag {}
-                    if {$macports::portverbose == "yes"} {
-                        set verboseflag "-v"
+                    if {$macports::portverbose eq "yes"} {
+                        set verboseflag -v
                     }
 
                     if {[catch {eval curl fetch $verboseflag {$source} {$tarpath}} error]} {
@@ -2465,17 +2461,17 @@
                     }
 
                     set extflag {}
-                    switch $extension {
+                    switch -- $extension {
                         {tar.gz} {
-                            set extflag "-z"
+                            set extflag -z
                         }
                         {tar.bz2} {
-                            set extflag "-j"
+                            set extflag -j
                         }
                     }
 
                     set tar [macports::findBinary tar $macports::autoconf::tar_path]
-                    if { [catch { system "cd $destdir/.. && $tar ${verboseflag} ${extflag} -xf $filename" } error] } {
+                    if {[catch {system "cd ${destdir}/.. && $tar $verboseflag $extflag -xf $filename"} error]} {
                         ui_error "Extracting $source failed ($error)"
                         incr numfailed
                         continue
@@ -2486,8 +2482,8 @@
                     }
 
                     set platindex "PortIndex_${macports::os_platform}_${macports::os_major}_${macports::os_arch}/PortIndex"
-                    if {[file isfile ${destdir}/${platindex}] && [file isfile ${destdir}/${platindex}.quick]} {
-                        file rename -force "${destdir}/${platindex}" "${destdir}/${platindex}.quick" $destdir
+                    if {[file isfile ${destdir}/$platindex] && [file isfile ${destdir}/${platindex}.quick]} {
+                        file rename -force ${destdir}/$platindex ${destdir}/${platindex}.quick $destdir
                     }
 
                     file delete $tarpath
@@ -2503,7 +2499,7 @@
                 ui_warn "Unknown synchronization protocol for $source"
             }
         }
-        
+
         if {$needs_portindex} {
             set any_needed_portindex 1
             if {![info exists options(no_reindex)]} {
@@ -2529,13 +2525,13 @@
 proc mportsearch {pattern {case_sensitive yes} {matchstyle regexp} {field name}} {
     global macports::portdbpath macports::sources
     set matches [list]
-    set easy [expr { $field == "name" }]
+    set easy [expr {$field eq "name"}]
 
     set found 0
     foreach source $sources {
         set source [lindex $source 0]
         set protocol [macports::getprotocol $source]
-        if {$protocol == "mports"} {
+        if {$protocol eq "mports"} {
             set res [macports::index::search $macports::portdbpath $source [list name $pattern]]
             eval lappend matches $res
         } else {
@@ -2558,16 +2554,16 @@
                             set target $portinfo($field)
                         }
 
-                        switch $matchstyle {
+                        switch -- $matchstyle {
                             exact {
-                                set matchres [expr 0 == ( {$case_sensitive == "yes"} ? [string compare $pattern $target] : [string compare -nocase $pattern $target] )]
+                                set matchres [expr {0 == ($case_sensitive eq "yes" ? [string compare $pattern $target] : [string compare -nocase $pattern $target])}]
                             }
                             glob {
-                                set matchres [expr {$case_sensitive == "yes"} ? [string match $pattern $target] : [string match -nocase $pattern $target]]
+                                set matchres [expr {$case_sensitive eq "yes" ? [string match $pattern $target] : [string match -nocase $pattern $target]}]
                             }
                             regexp -
                             default {
-                                set matchres [expr {$case_sensitive == "yes"} ? [regexp -- $pattern $target] : [regexp -nocase -- $pattern $target]]
+                                set matchres [expr {$case_sensitive eq "yes" ? [regexp -- $pattern $target] : [regexp -nocase -- $pattern $target]}]
                             }
                         }
 
@@ -2575,17 +2571,17 @@
                             if {$easy} {
                                 array set portinfo $line
                             }
-                            switch $protocol {
+                            switch -- $protocol {
                                 rsync {
                                     # Rsync files are local
-                                    set source_url "file://[macports::getsourcepath $source]"
+                                    set source_url file://[macports::getsourcepath $source]
                                 }
                                 https -
                                 http -
                                 ftp {
                                     if {[_source_is_snapshot $source filename extension]} {
                                         # daily snapshot tarball
-                                        set source_url "file://[macports::getsourcepath $source]"
+                                        set source_url file://[macports::getsourcepath $source]
                                     } else {
                                         # default action
                                         set source_url $source
@@ -2610,7 +2606,7 @@
                             lappend matches $line
                         }
                     }
-                } catch {*} {
+                } catch * {
                     ui_warn "It looks like your PortIndex file for $source may be corrupt."
                     throw
                 } finally {
@@ -2639,16 +2635,16 @@
     foreach source $sources {
         set source [lindex $source 0]
         set protocol [macports::getprotocol $source]
-        if {$protocol != "mports"} {
+        if {$protocol ne "mports"} {
             global macports::quick_index
-            if {![info exists quick_index($sourceno,[string tolower $name])]} {
+            if {![info exists quick_index(${sourceno},[string tolower $name])]} {
                 incr sourceno 1
                 continue
             }
             # The quick index is keyed on the port name, and provides the
             # offset in the main PortIndex where the given port's PortInfo
             # line can be found.
-            set offset $quick_index($sourceno,[string tolower $name])
+            set offset $quick_index(${sourceno},[string tolower $name])
             incr sourceno 1
             if {[catch {set fd [open [macports::getindex $source] r]} result]} {
                 ui_warn "Can't open index file for source: $source"
@@ -2662,15 +2658,15 @@
 
                     array set portinfo $line
 
-                    switch $protocol {
+                    switch -- $protocol {
                         rsync {
-                            set source_url "file://[macports::getsourcepath $source]"
+                            set source_url file://[macports::getsourcepath $source]
                         }
                         https -
                         http -
                         ftp {
                             if {[_source_is_snapshot $source filename extension]} {
-                                set source_url "file://[macports::getsourcepath $source]"
+                                set source_url file://[macports::getsourcepath $source]
                              } else {
                                 set source_url $source
                              }
@@ -2691,7 +2687,7 @@
                     lappend matches $line
                     close $fd
                     set fd -1
-                } catch {*} {
+                } catch * {
                     ui_warn "It looks like your PortIndex file for $source may be corrupt."
                 } finally {
                     if {$fd != -1} {
@@ -2723,7 +2719,7 @@
     foreach source $sources {
         set source [lindex $source 0]
         set protocol [macports::getprotocol $source]
-        if {$protocol != "mports"} {
+        if {$protocol ne "mports"} {
             if {![catch {set fd [open [macports::getindex $source] r]} result]} {
                 try {
                     incr found 1
@@ -2735,15 +2731,15 @@
 
                         array set portinfo $line
 
-                        switch $protocol {
+                        switch -- $protocol {
                             rsync {
-                                set source_url "file://[macports::getsourcepath $source]"
+                                set source_url file://[macports::getsourcepath $source]
                             }
                             https -
                             http -
                             ftp {
                                 if {[_source_is_snapshot $source filename extension]} {
-                                    set source_url "file://[macports::getsourcepath $source]"
+                                    set source_url file://[macports::getsourcepath $source]
                                 } else {
                                     set source_url $source
                                 }
@@ -2762,7 +2758,7 @@
                         }
                         lappend matches $name $line
                     }
-                } catch {*} {
+                } catch * {
                     ui_warn "It looks like your PortIndex file for $source may be corrupt."
                     throw
                 } finally {
@@ -2797,13 +2793,13 @@
         # chop off any tags
         set source [lindex $source 0]
         set index [macports::getindex $source]
-        if {![file exists ${index}]} {
+        if {![file exists $index]} {
             incr sourceno
             continue
         }
         if {![file exists ${index}.quick]} {
             ui_warn "No quick index file found, attempting to generate one for source: $source"
-            if {[catch {set quicklist [mports_generate_quickindex ${index}]}]} {
+            if {[catch {set quicklist [mports_generate_quickindex $index]}]} {
                 incr sourceno
                 continue
             }
@@ -2819,8 +2815,8 @@
                 close $fd
             }
         }
-        foreach entry [split $quicklist "\n"] {
-            set quick_index($sourceno,[lindex $entry 0]) [lindex $entry 1]
+        foreach entry [split $quicklist \n] {
+            set quick_index(${sourceno},[lindex $entry 0]) [lindex $entry 1]
         }
         incr sourceno 1
     }
@@ -2830,26 +2826,26 @@
 }
 
 proc mports_generate_quickindex {index} {
-    if {[catch {set indexfd [open ${index} r]} result] || [catch {set quickfd [open ${index}.quick w]} result]} {
+    if {[catch {set indexfd [open $index r]} result] || [catch {set quickfd [open ${index}.quick w]} result]} {
         ui_warn "Can't open index file: $index"
         return -code error
     } else {
         try {
             set offset [tell $indexfd]
-            set quicklist ""
+            set quicklist {}
             while {[gets $indexfd line] >= 0} {
                 if {[llength $line] != 2} {
                     continue
                 }
                 set name [lindex $line 0]
-                append quicklist "[string tolower $name] ${offset}\n"
+                append quicklist "[string tolower $name] $offset\n"
 
                 set len [lindex $line 1]
                 read $indexfd $len
                 set offset [tell $indexfd]
             }
             puts -nonewline $quickfd $quicklist
-        } catch {*} {
+        } catch * {
             ui_warn "It looks like your PortIndex file $index may be corrupt."
             throw
         } finally {
@@ -2895,7 +2891,7 @@
 
 proc _mportkey {mport key} {
     set workername [ditem_key $mport workername]
-    return [$workername eval "return \$${key}"]
+    return [$workername eval "return \$$key"]
 }
 
 # mportdepends builds the list of mports which the given port depends on.
@@ -2913,7 +2909,7 @@
 #                  dependencies ports.
 # accDeps -> accumulator for recursive calls
 # return 0 if everything was ok, an non zero integer otherwise.
-proc mportdepends {mport {target ""} {recurseDeps 1} {skipSatisfied 1} {accDeps 0}} {
+proc mportdepends {mport {target {}} {recurseDeps 1} {skipSatisfied 1} {accDeps 0}} {
 
     array set portinfo [mportinfo $mport]
     if {$accDeps} {
@@ -2924,11 +2920,11 @@
 
     # progress indicator
     if {![macports::ui_isset ports_debug]} {
-        ui_info -nonewline "."
+        ui_info -nonewline .
         flush stdout
     }
-    
-    if {$target == "" || $target == "install" || $target == "activate"} {
+
+    if {$target eq {} || $target eq "install" || $target eq "activate"} {
         _mporterrorifconflictsinstalled $mport
     }
 
@@ -2957,7 +2953,7 @@
             # get the portname that satisfies the depspec
             set dep_portname [$workername eval _get_dep_port $depspec]
             # skip port/archs combos we've already seen, and ones with the same port but less archs than ones we've seen (or noarch)
-            set seenkey "${dep_portname},[join $required_archs ,]"
+            set seenkey ${dep_portname},[join $required_archs ,]
             set seen 0
             if {[info exists port_seen($seenkey)]} {
                 set seen 1
@@ -2966,7 +2962,7 @@
                 set nrequired [llength $required_archs]
                 foreach key $prev_seenkeys {
                     set key_archs [lrange [split $key ,] 1 end]
-                    if {$key_archs == "noarch" || $required_archs == "noarch" || [llength $key_archs] > $nrequired} {
+                    if {$key_archs eq "noarch" || $required_archs eq "noarch" || [llength $key_archs] > $nrequired} {
                         set seen 1
                         set seenkey $key
                         break
@@ -2980,17 +2976,17 @@
                 }
                 continue
             }
-            
+
             # Is that dependency satisfied or this port installed?
             # If we don't skip or if it is not, add it to the list.
             set present [_mportispresent $mport $depspec]
 
-            if {!$skipSatisfied && $dep_portname == ""} {
+            if {!$skipSatisfied && $dep_portname eq {}} {
                 set dep_portname [lindex [split $depspec :] end]
             }
 
             set check_archs 0
-            if {$dep_portname != "" && $deptype != "depends_fetch" && $deptype != "depends_extract" && [lsearch -exact $depends_skip_archcheck $dep_portname] == -1} {
+            if {$dep_portname ne {} && $deptype ne "depends_fetch" && $deptype ne "depends_extract" && [lsearch -exact $depends_skip_archcheck $dep_portname] == -1} {
                 set check_archs 1
             }
 
@@ -3003,8 +2999,8 @@
                 # Find the porturl
                 if {[catch {set res [mportlookup $dep_portname]} error]} {
                     global errorInfo
-                    ui_msg ""
-                    ui_debug "$errorInfo"
+                    ui_msg {}
+                    ui_debug $errorInfo
                     ui_error "Internal error: port lookup failed: $error"
                     return 1
                 }
@@ -3013,7 +3009,7 @@
                 array set dep_portinfo [lindex $res 1]
                 if {![info exists dep_portinfo(porturl)]} {
                     if {![macports::ui_isset ports_debug]} {
-                        ui_msg ""
+                        ui_msg {}
                     }
                     ui_error "Dependency '$dep_portname' not found."
                     return 1
@@ -3027,7 +3023,7 @@
                 # because mportexec only closes each open mport once.
                 set depport [dlist_match_multi $macports::open_mports [list porturl $dep_portinfo(porturl) options $dep_options]]
 
-                if {$depport == {}} {
+                if {$depport eq {}} {
                     # We haven't opened this one yet.
                     set depport [mportopen $dep_portinfo(porturl) $dep_options $variations]
                 }
@@ -3046,7 +3042,7 @@
                 if {[info exists dep_portinfo(variants)] && [lsearch -exact $dep_portinfo(variants) universal] != -1} {
                     # a universal variant is offered
                     set has_universal 1
-                    if {![info exists variation_array(universal)] || $variation_array(universal) != "+"} {
+                    if {![info exists variation_array(universal)] || $variation_array(universal) ne "+"} {
                         set variation_array(universal) +
                         # try again with +universal
                         set depport [mportopen $dep_portinfo(porturl) $dep_options [array get variation_array]]
@@ -3068,11 +3064,11 @@
                 }
 
                 # Append the sub-port's provides to the port's requirements list.
-                set depport_provides "[ditem_key $depport provides]"
+                set depport_provides [ditem_key $depport provides]
                 ditem_append_unique $mport requires $depport_provides
                 # record actual archs we ended up getting
                 set port_seen(${dep_portname},[join [macports::_mport_archs $depport] ,]) $depport_provides
-            } elseif {$present && $dep_portname != ""} {
+            } elseif {$present && $dep_portname ne {}} {
                 # record actual installed archs
                 set port_seen(${dep_portname},[join [macports::_active_archs $dep_portname] ,]) 0
             }
@@ -3083,7 +3079,7 @@
     if {$recurseDeps} {
         foreach depport $depPorts {
             # Sub ports should be installed (all dependencies must be satisfied).
-            set res [mportdepends $depport "" $recurseDeps $skipSatisfied 1]
+            set res [mportdepends $depport {} $recurseDeps $skipSatisfied 1]
             if {$res != 0} {
                 return $res
             }
@@ -3095,11 +3091,11 @@
 
 # check if the given mport can support dependents with the given archs
 proc macports::_mport_supports_archs {mport required_archs} {
-    if {$required_archs == "noarch"} {
+    if {$required_archs eq "noarch"} {
         return 1
     }
     set provided_archs [_mport_archs $mport]
-    if {$provided_archs == "noarch"} {
+    if {$provided_archs eq "noarch"} {
         return 1
     }
     foreach arch $required_archs {
@@ -3118,14 +3114,14 @@
 
 # check if the active version of a port supports the given archs
 proc macports::_active_supports_archs {portname required_archs} {
-    if {$required_archs == "noarch"} {
+    if {$required_archs eq "noarch"} {
         return 1
     }
     if {[catch {registry::active $portname}]} {
         return 0
     }
     set provided_archs [_active_archs $portname]
-    if {$provided_archs == "noarch" || $provided_archs == "" || $provided_archs == 0} {
+    if {$provided_archs eq "noarch" || $provided_archs eq {} || $provided_archs == 0} {
         return 1
     }
     foreach arch $required_archs {
@@ -3139,7 +3135,7 @@
 # get the archs for a given active port
 proc macports::_active_archs {portname} {
     if {[catch {set ilist [registry::active $portname]}]} {
-        return ""
+        return {}
     }
     set i [lindex $ilist 0]
     set regref [registry::open_entry $portname [lindex $i 1] [lindex $i 2] [lindex $i 3] [lindex $i 5]]
@@ -3150,10 +3146,10 @@
 proc macports::_explain_arch_mismatch {port dep required_archs supported_archs has_universal} {
     global macports::universal_archs
     if {![macports::ui_isset ports_debug]} {
-        ui_msg ""
+        ui_msg {}
     }
     ui_error "Cannot install $port for the arch(s) '$required_archs' because"
-    if {$supported_archs != ""} {
+    if {$supported_archs ne {}} {
         foreach arch $required_archs {
             if {[lsearch -exact $supported_archs $arch] == -1} {
                 ui_error "its dependency $dep only supports the arch(s) '$supported_archs'."
@@ -3180,7 +3176,7 @@
 proc macports::_mport_has_deptypes {mport deptypes} {
     array set portinfo [mportinfo $mport]
     foreach type $deptypes {
-        if {[info exists portinfo($type)] && $portinfo($type) != ""} {
+        if {[info exists portinfo($type)] && $portinfo($type) ne {}} {
             return 1
         }
     }
@@ -3207,23 +3203,23 @@
         mpkg -
         rpm -
         dpkg -
-        srpm { return 1 }
-        default { return 0 }
+        srpm {return 1}
+        default {return 0}
     }
 }
 
 # Determine dependency types required for target
 proc macports::_deptypes_for_target {target workername} {
-    switch $target {
+    switch -- $target {
         fetch       -
-        checksum    { return "depends_fetch" }
+        checksum    {return depends_fetch}
         extract     -
-        patch       { return "depends_fetch depends_extract" }
+        patch       {return "depends_fetch depends_extract"}
         configure   -
-        build       { return "depends_fetch depends_extract depends_build depends_lib" }
+        build       {return "depends_fetch depends_extract depends_build depends_lib"}
         test        -
         srpm        -
-        destroot    { return "depends_fetch depends_extract depends_build depends_lib depends_run" }
+        destroot    {return "depends_fetch depends_extract depends_build depends_lib depends_run"}
         dmg         -
         pkg         -
         mdmg        -
@@ -3239,7 +3235,7 @@
         }
         install     -
         activate    -
-        ""          {
+        {}          {
             if {[global_option_isset ports_binary_only] ||
                 [$workername eval registry_exists \$subport \$version \$revision \$portvariants]
                 || (![global_option_isset ports_source_only] && [$workername eval _archive_available])} {
@@ -3249,32 +3245,33 @@
             }
         }
     }
-    return ""
+    return {}
 }
 
 # selfupdate procedure
-proc macports::selfupdate {{optionslist {}} {updatestatusvar ""}} {
-    global macports::prefix macports::portdbpath macports::libpath macports::rsync_server macports::rsync_dir macports::rsync_options
-    global macports::autoconf::macports_version macports::autoconf::rsync_path tcl_platform
-    global macports::autoconf::openssl_path macports::autoconf::tar_path
+proc macports::selfupdate {{optionslist {}} {updatestatusvar {}}} {
+    global macports::prefix macports::portdbpath macports::libpath \
+           macports::rsync_server macports::rsync_dir macports::rsync_options \
+           macports::autoconf::macports_version macports::autoconf::rsync_path \
+           tcl_platform macports::autoconf::openssl_path macports::autoconf::tar_path
     array set options $optionslist
-    
+
     # variable that indicates whether we actually updated base
-    if {$updatestatusvar != ""} {
+    if {$updatestatusvar ne {}} {
         upvar $updatestatusvar updatestatus
         set updatestatus no
     }
 
     # are we syncing a tarball? (implies detached signature)
     set is_tarball 0
-    if {[string range ${rsync_dir} end-3 end] == ".tar"} {
+    if {[string range $rsync_dir end-3 end] eq ".tar"} {
         set is_tarball 1
-        set mp_source_path [file join $portdbpath sources ${rsync_server} [file dirname ${rsync_dir}]]
+        set mp_source_path [file join $portdbpath sources $rsync_server [file dirname $rsync_dir]]
     } else {
-        if {[string index $rsync_dir end] != "/"} {
-            append rsync_dir "/"
+        if {[string index $rsync_dir end] ne "/"} {
+            append rsync_dir /
         }
-        set mp_source_path [file join $portdbpath sources ${rsync_server} ${rsync_dir}]
+        set mp_source_path [file join $portdbpath sources $rsync_server $rsync_dir]
     }
     # create the path to the to be downloaded sources if it doesn't exist
     if {![file exists $mp_source_path]} {
@@ -3284,21 +3281,21 @@
 
     # sync the MacPorts sources
     ui_msg "$macports::ui_prefix Updating MacPorts base sources using rsync"
-    if { [catch { system "$rsync_path $rsync_options rsync://${rsync_server}/${rsync_dir} $mp_source_path" } result ] } {
+    if {[catch {system "$rsync_path $rsync_options rsync://${rsync_server}/$rsync_dir $mp_source_path"} result]} {
        return -code error "Error synchronizing MacPorts sources: $result"
     }
 
     if {$is_tarball} {
         # verify signature for tarball
         global macports::archivefetch_pubkeys
-        if { [catch { system "$rsync_path $rsync_options rsync://${rsync_server}/${rsync_dir}.rmd160 $mp_source_path" } result ] } {
+        if {[catch {system "$rsync_path $rsync_options rsync://${rsync_server}/${rsync_dir}.rmd160 $mp_source_path"} result]} {
             return -code error "Error synchronizing MacPorts source signature: $result"
         }
         set openssl [findBinary openssl $macports::autoconf::openssl_path]
-        set tarball "${mp_source_path}/[file tail $rsync_dir]"
-        set signature "${tarball}.rmd160"
+        set tarball ${mp_source_path}/[file tail $rsync_dir]
+        set signature ${tarball}.rmd160
         set verified 0
-        foreach pubkey ${macports::archivefetch_pubkeys} {
+        foreach pubkey $macports::archivefetch_pubkeys {
             if {![catch {exec $openssl dgst -ripemd160 -verify $pubkey -signature $signature $tarball} result]} {
                 set verified 1
                 ui_debug "successful verification with key $pubkey"
@@ -3311,11 +3308,11 @@
         if {!$verified} {
             return -code error "Failed to verify signature for MacPorts source!"
         }
-        
+
         # extract tarball and move into place
         set tar [macports::findBinary tar $macports::autoconf::tar_path]
         file mkdir ${mp_source_path}/tmp
-        set tar_cmd "$tar -C ${mp_source_path}/tmp -xf ${tarball}"
+        set tar_cmd "$tar -C ${mp_source_path}/tmp -xf $tarball"
         ui_debug $tar_cmd
         if {[catch {system $tar_cmd}]} {
             return -code error "Failed to extract MacPorts sources from tarball!"
@@ -3330,7 +3327,7 @@
     # echo current MacPorts version
     ui_msg "MacPorts base version $macports::autoconf::macports_version installed,"
 
-    if { [info exists options(ports_force)] && $options(ports_force) == "yes" } {
+    if {[info exists options(ports_force)] && $options(ports_force) eq "yes"} {
         set use_the_force_luke yes
         ui_debug "Forcing a rebuild and reinstallation of MacPorts"
     } else {
@@ -3355,9 +3352,9 @@
     set comp [vercmp $macports_version_new $macports::autoconf::macports_version]
 
     # syncing ports tree.
-    if {![info exists options(ports_selfupdate_nosync)] || $options(ports_selfupdate_nosync) != "yes"} {
+    if {![info exists options(ports_selfupdate_nosync)] || $options(ports_selfupdate_nosync) ne "yes"} {
         if {$comp > 0} {
-            # updated portfiles potentially need new base to parse - tell sync to try to 
+            # updated portfiles potentially need new base to parse - tell sync to try to
             # use prefabricated PortIndex files and signal if it couldn't
             lappend optionslist no_reindex 1 needed_portindex_var needed_portindex
         }
@@ -3366,24 +3363,24 @@
         }
     }
 
-    if {$use_the_force_luke == "yes" || $comp > 0} {
-        if {[info exists options(ports_dryrun)] && $options(ports_dryrun) == "yes"} {
+    if {$use_the_force_luke eq "yes" || $comp > 0} {
+        if {[info exists options(ports_dryrun)] && $options(ports_dryrun) eq "yes"} {
             ui_msg "$macports::ui_prefix MacPorts base is outdated, selfupdate would install $macports_version_new (dry run)"
         } else {
             ui_msg "$macports::ui_prefix MacPorts base is outdated, installing new version $macports_version_new"
 
             # get installation user/group and permissions
-            set owner [file attributes ${prefix} -owner]
-            set group [file attributes ${prefix} -group]
-            set perms [string range [file attributes ${prefix} -permissions] end-3 end]
-            if {$tcl_platform(user) != "root" && ![string equal $tcl_platform(user) $owner]} {
-                return -code error "User $tcl_platform(user) does not own ${prefix} - try using sudo"
+            set owner [file attributes $prefix -owner]
+            set group [file attributes $prefix -group]
+            set perms [string range [file attributes $prefix -permissions] end-3 end]
+            if {$tcl_platform(user) ne "root" && $tcl_platform(user) ne $owner} {
+                return -code error "User $tcl_platform(user) does not own $prefix - try using sudo"
             }
             ui_debug "Permissions OK"
 
             # where to install a link to our macports1.0 tcl package
             set mp_tclpackage_path [file join $portdbpath .tclpackage]
-            if { [file exists $mp_tclpackage_path]} {
+            if {[file exists $mp_tclpackage_path]} {
                 set fd [open $mp_tclpackage_path r]
                 gets $fd tclpackage
                 close $fd
@@ -3393,26 +3390,26 @@
 
             set configure_args "--prefix=$prefix --with-tclpackage=$tclpackage --with-install-user=$owner --with-install-group=$group --with-directory-mode=$perms"
             # too many users have an incompatible readline in /usr/local, see ticket #10651
-            if {$tcl_platform(os) != "Darwin" || $prefix == "/usr/local"
-                || ([glob -nocomplain "/usr/local/lib/lib{readline,history}*"] == "" && [glob -nocomplain "/usr/local/include/readline/*.h"] == "")} {
+            if {$tcl_platform(os) ne "Darwin" || $prefix eq "/usr/local"
+                || ([glob -nocomplain /usr/local/lib/lib{readline,history}*] eq {} && [glob -nocomplain /usr/local/include/readline/*.h] eq {})} {
                 append configure_args " --enable-readline"
             } else {
                 ui_warn "Disabling readline support due to readline in /usr/local"
             }
 
-            if {$prefix == "/usr/local" || $prefix == "/usr"} {
+            if {$prefix eq "/usr/local" || $prefix eq "/usr"} {
                 append configure_args " --with-unsupported-prefix"
             }
 
             # Choose a sane compiler
-            set cc_arg ""
-            if {$::macports::os_platform == "darwin"} {
+            set cc_arg {}
+            if {$::macports::os_platform eq "darwin"} {
                 set cc_arg "CC=/usr/bin/cc OBJC=/usr/bin/cc "
             }
 
             # do the actual configure, build and installation of new base
-            ui_msg "Installing new MacPorts release in $prefix as $owner:$group; permissions $perms; Tcl-Package in $tclpackage\n"
-            if { [catch { system "cd $mp_source_path && ${cc_arg}./configure $configure_args && make SELFUPDATING=1 && make install SELFUPDATING=1" } result] } {
+            ui_msg "Installing new MacPorts release in $prefix as ${owner}:${group}; permissions ${perms}; Tcl-Package in $tclpackage\n"
+            if {[catch {system "cd $mp_source_path && ${cc_arg}./configure $configure_args && make SELFUPDATING=1 && make install SELFUPDATING=1"} result]} {
                 return -code error "Error installing new MacPorts base: $result"
             }
             if {[info exists updatestatus]} {
@@ -3428,11 +3425,11 @@
     # set the MacPorts sources to the right owner
     set sources_owner [file attributes [file join $portdbpath sources/] -owner]
     ui_debug "Setting MacPorts sources ownership to $sources_owner"
-    if { [catch { exec [findBinary chown $macports::autoconf::chown_path] -R $sources_owner [file join $portdbpath sources/] } result] } {
-        return -code error "Couldn't change permissions of the MacPorts sources at $mp_source_path to $sources_owner: $result"
+    if {[catch {exec [findBinary chown $macports::autoconf::chown_path] -R $sources_owner [file join $portdbpath sources/]} result]} {
+        return -code error "Couldn't change permissions of the MacPorts sources at $mp_source_path to ${sources_owner}: $result"
     }
 
-    if {![info exists options(ports_selfupdate_nosync)] || $options(ports_selfupdate_nosync) != "yes"} {
+    if {![info exists options(ports_selfupdate_nosync)] || $options(ports_selfupdate_nosync) ne "yes"} {
         if {[info exists needed_portindex]} {
             ui_msg "Not all sources could be fully synced using the old version of MacPorts."
             ui_msg "Please run selfupdate again now that MacPorts base has been updated."
@@ -3451,13 +3448,13 @@
 #   1 = general failure
 #   2 = port name not found in index
 #   3 = port not installed
-proc macports::upgrade {portname dspec variationslist optionslist {depscachename ""}} {
+proc macports::upgrade {portname dspec variationslist optionslist {depscachename {}}} {
     # only installed ports can be upgraded
     if {![registry::entry_exists_for_name $portname]} {
         ui_error "$portname is not installed"
         return 3
     }
-    if {![string match "" $depscachename]} {
+    if {$depscachename ne {}} {
         upvar $depscachename depscache
     } else {
         array set depscache {}
@@ -3468,10 +3465,10 @@
         set macports::global_options(ports_nodeps) yes
         set orig_nodeps no
     }
-    
+
     # run the actual upgrade
     set status [macports::_upgrade $portname $dspec $variationslist $optionslist depscache]
-    
+
     if {!$orig_nodeps} {
         unset -nocomplain macports::global_options(ports_nodeps)
     }
@@ -3480,11 +3477,11 @@
 }
 
 # main internal upgrade procedure
-proc macports::_upgrade {portname dspec variationslist optionslist {depscachename ""}} {
+proc macports::_upgrade {portname dspec variationslist optionslist {depscachename {}}} {
     global macports::global_variations
     array set options $optionslist
 
-    if {![string match "" $depscachename]} {
+    if {$depscachename ne {}} {
         upvar $depscachename depscache
     }
 
@@ -3507,12 +3504,12 @@
     # check if the port is in tree
     if {[catch {mportlookup $portname} result]} {
         global errorInfo
-        ui_debug "$errorInfo"
+        ui_debug $errorInfo
         ui_error "port lookup failed: $result"
         return 1
     }
     # argh! port doesnt exist!
-    if {$result == ""} {
+    if {$result eq {}} {
         ui_warn "No port $portname found in the index."
         return 2
     }
@@ -3523,15 +3520,15 @@
     set options(subport) $portname
 
     set ilist {}
-    if { [catch {set ilist [registry::installed $portname ""]} result] } {
-        if {$result == "Registry error: $portname not registered as installed." } {
+    if {[catch {set ilist [registry::installed $portname {}]} result]} {
+        if {$result eq "Registry error: $portname not registered as installed."} {
             ui_debug "$portname is *not* installed by MacPorts"
 
             # We need to pass _mportispresent a reference to the mport that is
             # actually declaring the dependency on the one we're checking for.
             # We got here via _upgrade_dependencies, so we grab it from 2 levels up.
-            upvar 2 workername parentworker
-            if {![_mportispresent $parentworker $dspec ] } {
+            upvar 2 mport parentmport
+            if {![_mportispresent $parentmport $dspec]} {
                 # open porthandle
                 set porturl $portinfo(porturl)
                 if {![info exists porturl]} {
@@ -3540,38 +3537,38 @@
                 # Grab the variations from the parent
                 upvar 2 variations variations
 
-                if {[catch {set workername [mportopen $porturl [array get options] [array get variations]]} result]} {
+                if {[catch {set mport [mportopen $porturl [array get options] [array get variations]]} result]} {
                     global errorInfo
-                    ui_debug "$errorInfo"
+                    ui_debug $errorInfo
                     ui_error "Unable to open port: $result"
                     return 1
                 }
                 # While we're at it, update the portinfo
                 array unset portinfo
-                array set portinfo [mportinfo $workername]
-                
+                array set portinfo [mportinfo $mport]
+
                 # upgrade its dependencies first
                 set status [_upgrade_dependencies portinfo depscache variationslist options]
                 if {$status != 0 && $status != 2 && ![ui_isset ports_processall]} {
-                    catch {mportclose $workername}
+                    catch {mportclose $mport}
                     return $status
                 }
                 # now install it
-                if {[catch {set result [mportexec $workername activate]} result]} {
+                if {[catch {set result [mportexec $mport activate]} result]} {
                     global errorInfo
-                    ui_debug "$errorInfo"
+                    ui_debug $errorInfo
                     ui_error "Unable to exec port: $result"
-                    catch {mportclose $workername}
+                    catch {mportclose $mport}
                     return 1
                 }
                 if {$result > 0} {
                     ui_error "Problem while installing $portname"
-                    catch {mportclose $workername}
+                    catch {mportclose $mport}
                     return $result
                 }
                 # we just installed it, so mark it done in the cache
-                set depscache(port:${portname}) 1
-                mportclose $workername
+                set depscache(port:$portname) 1
+                mportclose $mport
             } else {
                 # dependency is satisfied by something other than the named port
                 ui_debug "$portname not installed, soft dependency satisfied"
@@ -3587,17 +3584,17 @@
         }
     } else {
         # we'll now take care of upgrading it, so we can add it to the cache
-        set depscache(port:${portname}) 1
+        set depscache(port:$portname) 1
     }
-    
+
     # set version_in_tree and revision_in_tree
     if {![info exists portinfo(version)]} {
-        ui_error "Invalid port entry for $portname, missing version"
+        ui_error "Invalid port entry for ${portname}, missing version"
         return 1
     }
-    set version_in_tree "$portinfo(version)"
-    set revision_in_tree "$portinfo(revision)"
-    set epoch_in_tree "$portinfo(epoch)"
+    set version_in_tree $portinfo(version)
+    set revision_in_tree $portinfo(revision)
+    set epoch_in_tree $portinfo(epoch)
 
     # find latest version installed and active version (if any)
     set anyactive no
@@ -3607,7 +3604,7 @@
         set version [lindex $i 1]
         set revision [lindex $i 2]
         set epoch [lindex $i 5]
-        if { $version_installed == {} || ($epoch > $epoch_installed && $version != $version_installed) ||
+        if {$version_installed eq {} || ($epoch > $epoch_installed && $version != $version_installed) ||
                 ($epoch >= $epoch_installed && [vercmp $version $version_installed] > 0)
                 || ($epoch >= $epoch_installed
                     && [vercmp $version $version_installed] == 0
@@ -3630,10 +3627,10 @@
 
     # output version numbers
     ui_debug "epoch: in tree: $epoch_in_tree installed: $epoch_installed"
-    ui_debug "$portname ${version_in_tree}_${revision_in_tree} exists in the ports tree"
-    ui_debug "$portname ${version_installed}_${revision_installed} $variant_installed is the latest installed"
+    ui_debug "$portname ${version_in_tree}_$revision_in_tree exists in the ports tree"
+    ui_debug "$portname ${version_installed}_$revision_installed $variant_installed is the latest installed"
     if {$anyactive} {
-        ui_debug "$portname ${version_active}_${revision_active} $variant_active is active"
+        ui_debug "$portname ${version_active}_$revision_active $variant_active is active"
         # save existing variant for later use
         set oldvariant $variant_active
         set regref [registry::open_entry $portname $version_active $revision_active $variant_active $epoch_active]
@@ -3663,23 +3660,23 @@
     # upgrade; while variations gets existing variants and global variations
     # merged in later on, so it applies only to this port's upgrade
     array set variations $variationslist
-    
+
     set globalvarlist [array get macports::global_variations]
 
     set minusvariant [lrange [split $oldnegatedvariant -] 1 end]
     set plusvariant [lrange [split $oldvariant +] 1 end]
-    ui_debug "Merging existing variants '${oldvariant}${oldnegatedvariant}' into variants"
+    ui_debug "Merging existing variants '${oldvariant}$oldnegatedvariant' into variants"
     set oldvariantlist [list]
     foreach v $plusvariant {
-        lappend oldvariantlist $v "+"
+        lappend oldvariantlist $v +
     }
     foreach v $minusvariant {
-        lappend oldvariantlist $v "-"
+        lappend oldvariantlist $v -
     }
 
     # merge in the old variants
     foreach {variation value} $oldvariantlist {
-        if { ![info exists variations($variation)]} {
+        if {![info exists variations($variation)]} {
             set variations($variation) $value
         }
     }
@@ -3687,24 +3684,24 @@
     # Now merge in the global (i.e. variants.conf) variations.
     # We wait until now so that existing variants for this port
     # override global variations
-    foreach { variation value } $globalvarlist {
-        if { ![info exists variations($variation)] } {
+    foreach {variation value} $globalvarlist {
+        if {![info exists variations($variation)]} {
             set variations($variation) $value
         }
     }
 
     ui_debug "new fully merged portvariants: [array get variations]"
-    
+
     # at this point we need to check if a different port will be replacing this one
     if {[info exists portinfo(replaced_by)] && ![info exists options(ports_upgrade_no-replace)]} {
         ui_msg "$macports::ui_prefix $portname is replaced by $portinfo(replaced_by)"
         if {[catch {mportlookup $portinfo(replaced_by)} result]} {
             global errorInfo
-            ui_debug "$errorInfo"
+            ui_debug $errorInfo
             ui_error "port lookup failed: $result"
             return 1
         }
-        if {$result == ""} {
+        if {$result eq {}} {
             ui_error "No port $portinfo(replaced_by) found."
             return 1
         }
@@ -3716,7 +3713,7 @@
         if {![info exists porturl]} {
             set porturl file://./
         }
-        set depscache(port:${newname}) 1
+        set depscache(port:$newname) 1
     } else {
         set newname $portname
     }
@@ -3725,38 +3722,38 @@
     set interp_options(ports_requested) $requestedflag
     set interp_options(subport) $newname
 
-    if {[catch {set workername [mportopen $porturl [array get interp_options] [array get variations]]} result]} {
+    if {[catch {set mport [mportopen $porturl [array get interp_options] [array get variations]]} result]} {
         global errorInfo
-        ui_debug "$errorInfo"
+        ui_debug $errorInfo
         ui_error "Unable to open port: $result"
         return 1
     }
     array unset interp_options
 
     array unset portinfo
-    array set portinfo [mportinfo $workername]
-    set version_in_tree "$portinfo(version)"
-    set revision_in_tree "$portinfo(revision)"
-    set epoch_in_tree "$portinfo(epoch)"
+    array set portinfo [mportinfo $mport]
+    set version_in_tree $portinfo(version)
+    set revision_in_tree $portinfo(revision)
+    set epoch_in_tree $portinfo(epoch)
 
     set build_override 0
     set will_install yes
     # check installed version against version in ports
-    if { ( [vercmp $version_installed $version_in_tree] > 0
+    if {([vercmp $version_installed $version_in_tree] > 0
             || ([vercmp $version_installed $version_in_tree] == 0
-                && [vercmp $revision_installed $revision_in_tree] >= 0 ))
-        && ![info exists options(ports_upgrade_force)] } {
-        if {$portname != $newname} { 
+                && [vercmp $revision_installed $revision_in_tree] >= 0))
+        && ![info exists options(ports_upgrade_force)]} {
+        if {$portname ne $newname} {
             ui_debug "ignoring versions, installing replacement port"
-        } elseif { $epoch_installed < $epoch_in_tree } {
+        } elseif {$epoch_installed < $epoch_in_tree && $version_installed != $version_in_tree} {
             set build_override 1
             ui_debug "epoch override ... upgrading!"
         } elseif {[info exists options(ports_upgrade_enforce-variants)] && $options(ports_upgrade_enforce-variants) eq "yes"
                   && [info exists portinfo(canonical_active_variants)] && $portinfo(canonical_active_variants) != $oldvariant} {
             ui_debug "variant override ... upgrading!"
-        } elseif {$os_platform_installed != "" && $os_major_installed != "" && $os_platform_installed != 0
-                  && ([_mportkey $workername "{os.platform}"] != $os_platform_installed
-                  || [_mportkey $workername "{os.major}"] != $os_major_installed)} {
+        } elseif {$os_platform_installed ne {} && $os_major_installed ne {} && $os_platform_installed != 0
+                  && ([_mportkey $mport "{os.platform}"] != $os_platform_installed
+                  || [_mportkey $mport "{os.major}"] != $os_major_installed)} {
             ui_debug "platform mismatch ... upgrading!"
             set build_override 1
         } elseif {$is_revupgrade_second_run} {
@@ -3769,12 +3766,12 @@
         } else {
             if {[info exists portinfo(canonical_active_variants)] && $portinfo(canonical_active_variants) != $oldvariant} {
                 if {[llength $variationslist] > 0} {
-                    ui_warn "Skipping upgrade since $portname ${version_installed}_${revision_installed} >= $portname ${version_in_tree}_${revision_in_tree}, even though installed variants \"$oldvariant\" do not match \"$portinfo(canonical_active_variants)\". Use 'upgrade --enforce-variants' to switch to the requested variants."
+                    ui_warn "Skipping upgrade since $portname ${version_installed}_$revision_installed >= $portname ${version_in_tree}_${revision_in_tree}, even though installed variants \"$oldvariant\" do not match \"$portinfo(canonical_active_variants)\". Use 'upgrade --enforce-variants' to switch to the requested variants."
                 } else {
-                    ui_debug "Skipping upgrade since $portname ${version_installed}_${revision_installed} >= $portname ${version_in_tree}_${revision_in_tree}, even though installed variants \"$oldvariant\" do not match \"$portinfo(canonical_active_variants)\"."
+                    ui_debug "Skipping upgrade since $portname ${version_installed}_$revision_installed >= $portname ${version_in_tree}_${revision_in_tree}, even though installed variants \"$oldvariant\" do not match \"$portinfo(canonical_active_variants)\"."
                 }
             } else {
-                ui_debug "No need to upgrade! $portname ${version_installed}_${revision_installed} >= $portname ${version_in_tree}_${revision_in_tree}"
+                ui_debug "No need to upgrade! $portname ${version_installed}_$revision_installed >= $portname ${version_in_tree}_$revision_in_tree"
             }
             set will_install no
         }
@@ -3793,9 +3790,9 @@
     # first upgrade dependencies
     if {![info exists options(ports_nodeps)] && !$is_revupgrade} {
         # the last arg is because we might have to build from source if a rebuild is being forced
-        set status [_upgrade_dependencies portinfo depscache variationslist options [expr $will_build && $already_installed]]
+        set status [_upgrade_dependencies portinfo depscache variationslist options [expr {$will_build && $already_installed}]]
         if {$status != 0 && $status != 2 && ![ui_isset ports_processall]} {
-            catch {mportclose $workername}
+            catch {mportclose $mport}
             return $status
         }
     } else {
@@ -3815,32 +3812,65 @@
                 set deplist [registry::list_dependents $portname $version_installed $revision_installed $variant_installed]
             }
 
-            if { [llength deplist] > 0 } {
+            if {[llength deplist] > 0} {
                 foreach dep $deplist {
                     set mpname [lindex $dep 2]
-                    if {![llength [array get depscache port:${mpname}]]} {
-                        set status [macports::_upgrade $mpname port:${mpname} $variationslist [array get options] depscache]
+                    if {![llength [array get depscache port:$mpname]]} {
+                        set status [macports::_upgrade $mpname port:$mpname $variationslist [array get options] depscache]
                         if {$status != 0 && $status != 2 && ![ui_isset ports_processall]} {
-                            catch {mportclose $workername}
+                            catch {mportclose $mport}
                             return $status
                         }
                     }
                 }
             }
         }
-        mportclose $workername
+        mportclose $mport
         return 0
     }
 
     if {$will_build} {
-        # install version_in_tree (but don't activate yet)
-        if {[catch {set result [mportexec $workername install]} result] || $result != 0} {
-            if {[info exists ::errorInfo]} {
-                ui_debug "$::errorInfo"
+        if {$already_installed
+            && ([info exists options(ports_upgrade_force)] || $build_override == 1)} {
+            # Tell archivefetch/unarchive not to use the installed archive, i.e. a
+            # fresh one will be either fetched or built locally.
+            # Ideally this would be done in the interp_options when we mportopen,
+            # but we don't know if we want to do this at that point.
+            set workername [ditem_key $mport workername]
+            $workername eval "set force_archive_refresh yes"
+
+            # run archivefetch and destroot for version_in_tree
+            # doing this instead of just running install ensures that we have the
+            # new copy ready but not yet installed, so we can safely uninstall the
+            # existing one.
+            if {[catch {set result [mportexec $mport archivefetch]} result] || $result != 0} {
+                if {[info exists ::errorInfo]} {
+                    ui_debug $::errorInfo
+                }
+                ui_error "Unable to upgrade port: $result"
+                catch {mportclose $mport}
+                return 1
             }
-            ui_error "Unable to upgrade port: $result"
-            catch {mportclose $workername}
-            return 1
+            # the following is a noop if archivefetch found an archive
+            if {[catch {set result [mportexec $mport destroot]} result] || $result != 0} {
+                if {[info exists ::errorInfo]} {
+                    ui_debug $::errorInfo
+                }
+                ui_error "Unable to upgrade port: $result"
+                catch {mportclose $mport}
+                return 1
+            }
+        } else {
+            # Normal non-forced case
+            # install version_in_tree (but don't activate yet)
+            if {[catch {set result [mportexec $mport install]} result] || $result != 0} {
+                if {[info exists ::errorInfo]} {
+                    ui_debug $::errorInfo
+                }
+                ui_error "Unable to upgrade port: $result"
+                catch {mportclose $mport}
+                return 1
+            }
         }
     }
 
@@ -3858,33 +3888,33 @@
         } elseif {![registry::run_target $newregref uninstall [array get options]]
                   && [catch {registry_uninstall::uninstall $newname $version_in_tree $revision_in_tree $portinfo(canonical_active_variants) [array get options]} result]} {
             global errorInfo
-            ui_debug "$errorInfo"
+            ui_debug $errorInfo
             ui_error "Uninstall $newname ${version_in_tree}_${revision_in_tree}$portinfo(canonical_active_variants) failed: $result"
-            catch {mportclose $workername}
+            catch {mportclose $mport}
             return 1
         }
         if {!$force_cur} {
             unset options(ports_force)
         }
         if {$anyactive && $version_in_tree == $version_active && $revision_in_tree == $revision_active
-            && $portinfo(canonical_active_variants) == $variant_active && $portname == $newname} {
+            && $portinfo(canonical_active_variants) == $variant_active && $portname eq $newname} {
             set anyactive no
         }
     }
-    if {$anyactive && $portname != $newname} {
+    if {$anyactive && $portname ne $newname} {
         # replaced_by in effect, deactivate the old port
         # we have to force the deactivate in case of dependents
         set force_cur [info exists options(ports_force)]
         set options(ports_force) yes
         if {$is_dryrun eq "yes"} {
-            ui_msg "Skipping deactivate $portname @${version_active}_${revision_active}${variant_active} (dry run)"
+            ui_msg "Skipping deactivate $portname @${version_active}_${revision_active}$variant_active (dry run)"
         } elseif {![catch {registry::active $portname}] &&
                   ![registry::run_target $regref deactivate [array get options]]
                   && [catch {portimage::deactivate $portname $version_active $revision_active $variant_active [array get options]} result]} {
             global errorInfo
-            ui_debug "$errorInfo"
-            ui_error "Deactivating $portname @${version_active}_${revision_active}${variant_active} failed: $result"
-            catch {mportclose $workername}
+            ui_debug $errorInfo
+            ui_error "Deactivating $portname @${version_active}_${revision_active}$variant_active failed: $result"
+            catch {mportclose $mport}
             return 1
         }
         if {!$force_cur} {
@@ -3892,7 +3922,7 @@
         }
         set anyactive no
     }
-    if {[info exists options(port_uninstall_old)] && $portname == $newname} {
+    if {[info exists options(port_uninstall_old)] && $portname eq $newname} {
         # uninstalling now could fail due to dependents when not forced,
         # because the new version is not installed
         set uninstall_later yes
@@ -3900,14 +3930,14 @@
 
     if {$is_dryrun eq "yes"} {
         if {$anyactive} {
-            ui_msg "Skipping deactivate $portname @${version_active}_${revision_active}${variant_active} (dry run)"
+            ui_msg "Skipping deactivate $portname @${version_active}_${revision_active}$variant_active (dry run)"
         }
         ui_msg "Skipping activate $newname @${version_in_tree}_${revision_in_tree}$portinfo(canonical_active_variants) (dry run)"
-    } elseif {[catch {set result [mportexec $workername activate]} result]} {
+    } elseif {[catch {set result [mportexec $mport activate]} result]} {
         global errorInfo
-        ui_debug "$errorInfo"
+        ui_debug $errorInfo
         ui_error "Couldn't activate $newname ${version_in_tree}_${revision_in_tree}$portinfo(canonical_active_variants): $result"
-        catch {mportclose $workername}
+        catch {mportclose $mport}
         return 1
     }
 
@@ -3917,7 +3947,7 @@
         set options(ports_nodeps) 1
 
         registry::open_dep_map
-        if {$portname != $newname} {
+        if {$portname ne $newname} {
             set deplist [registry::list_dependents $newname $version_in_tree $revision_in_tree $portinfo(canonical_active_variants)]
         } else {
             set deplist [list]
@@ -3928,13 +3958,13 @@
             set deplist [concat $deplist [registry::list_dependents $portname $version_installed $revision_installed $variant_installed]]
         }
 
-        if { [llength deplist] > 0 } {
+        if {[llength deplist] > 0} {
             foreach dep $deplist {
                 set mpname [lindex $dep 2]
-                if {![llength [array get depscache port:${mpname}]]} {
-                    set status [macports::_upgrade $mpname port:${mpname} $variationslist [array get options] depscache]
+                if {![llength [array get depscache port:$mpname]]} {
+                    set status [macports::_upgrade $mpname port:$mpname $variationslist [array get options] depscache]
                     if {$status != 0 && $status != 2 && ![ui_isset ports_processall]} {
-                        catch {mportclose $workername}
+                        catch {mportclose $mport}
                         return $status
                     }
                 }
@@ -3942,27 +3972,27 @@
         }
     }
 
-    if {[info exists uninstall_later] && $uninstall_later == yes} {
+    if {[info exists uninstall_later] && $uninstall_later eq yes} {
         foreach i $ilist {
             set version [lindex $i 1]
             set revision [lindex $i 2]
             set variant [lindex $i 3]
-            if {$version == $version_in_tree && $revision == $revision_in_tree && $variant == $portinfo(canonical_active_variants) && $portname == $newname} {
+            if {$version == $version_in_tree && $revision == $revision_in_tree && $variant == $portinfo(canonical_active_variants) && $portname eq $newname} {
                 continue
             }
             set epoch [lindex $i 5]
-            ui_debug "Uninstalling $portname ${version}_${revision}${variant}"
+            ui_debug "Uninstalling $portname ${version}_${revision}$variant"
             set regref [registry::open_entry $portname $version $revision $variant $epoch]
             if {$is_dryrun eq "yes"} {
-                ui_msg "Skipping uninstall $portname @${version}_${revision}${variant} (dry run)"
+                ui_msg "Skipping uninstall $portname @${version}_${revision}$variant (dry run)"
             } elseif {![registry::run_target $regref uninstall $optionslist]
                       && [catch {registry_uninstall::uninstall $portname $version $revision $variant $optionslist} result]} {
                 global errorInfo
-                ui_debug "$errorInfo"
+                ui_debug $errorInfo
                 # replaced_by can mean that we try to uninstall all versions of the old port, so handle errors due to dependents
-                if {$result != "Please uninstall the ports that depend on $portname first." && ![ui_isset ports_processall]} {
-                    ui_error "Uninstall $portname @${version}_${revision}${variant} failed: $result"
-                    catch {mportclose $workername}
+                if {$result ne "Please uninstall the ports that depend on $portname first." && ![ui_isset ports_processall]} {
+                    ui_error "Uninstall $portname @${version}_${revision}$variant failed: $result"
+                    catch {mportclose $mport}
                     return 1
                 }
             }
@@ -3970,7 +4000,7 @@
     }
 
     # close the port handle
-    mportclose $workername
+    mportclose $mport
     return 0
 }
 
@@ -3981,7 +4011,7 @@
     upvar $portinfoname portinfo $depscachename depscache \
           $variationslistname variationslist \
           $optionsname options
-    upvar workername parentworker
+    upvar mport parentmport
 
     # If we're following dependents, we only want to follow this port's
     # dependents, not those of all its dependencies. Otherwise, we would
@@ -3995,21 +4025,21 @@
     set saved_do_dependents [info exists options(ports_do_dependents)]
     unset -nocomplain options(ports_do_dependents)
 
-    set parent_interp [ditem_key $parentworker workername]
+    set parentworker [ditem_key $parentmport workername]
     # each required dep type is upgraded
     if {$build_needed && ![global_option_isset ports_binary_only]} {
-        set dtypes [_deptypes_for_target destroot $parent_interp]
+        set dtypes [_deptypes_for_target destroot $parentworker]
     } else {
-        set dtypes [_deptypes_for_target install $parent_interp]
+        set dtypes [_deptypes_for_target install $parentworker]
     }
 
     set status 0
     foreach dtype $dtypes {
         if {[info exists portinfo($dtype)]} {
             foreach i $portinfo($dtype) {
-                set d [$parent_interp eval _get_dep_port $i]
-                if {![llength [array get depscache port:${d}]] && ![llength [array get depscache $i]]} {
-                    if {$d != ""} {
+                set d [$parentworker eval _get_dep_port $i]
+                if {![llength [array get depscache port:$d]] && ![llength [array get depscache $i]]} {
+                    if {$d ne {}} {
                         set dspec port:$d
                     } else {
                         set dspec $i
@@ -4032,13 +4062,13 @@
 # mportselect
 #   * command: The only valid commands are list, set and show
 #   * group: This argument should correspond to a directory under
-#            $macports::prefix/etc/select.
+#            ${macports::prefix}/etc/select.
 #   * version: This argument is only used by the 'set' command.
 # On error mportselect returns with the code 'error'.
-proc mportselect {command group {version ""}} {
+proc mportselect {command group {version {}}} {
     ui_debug "mportselect \[$command] \[$group] \[$version]"
 
-    set conf_path "$macports::prefix/etc/select/$group"
+    set conf_path ${macports::prefix}/etc/select/$group
     if {![file isdirectory $conf_path]} {
         return -code error "The specified group '$group' does not exist."
     }
@@ -4047,8 +4077,8 @@
         list {
             if {[catch {set versions [glob -directory $conf_path *]} result]} {
                 global errorInfo
-                ui_debug "$result: $errorInfo"
-                return -code error [concat "No configurations associated " \
+                ui_debug "${result}: $errorInfo"
+                return -code error [concat "No configurations associated" \
                                            "with '$group' were found."]
             }
 
@@ -4065,25 +4095,25 @@
             return [lsort $lversions]
         }
         set {
-            # Use $conf_path/$version to read in sources.
-            if {$version == "" || $version == "base" || $version == "current"
-                    || [catch {set src_file [open "$conf_path/$version"]} result]} {
+            # Use ${conf_path}/$version to read in sources.
+            if {$version eq {} || $version eq "base" || $version eq "current"
+                    || [catch {set src_file [open "${conf_path}/$version"]} result]} {
                 global errorInfo
-                ui_debug "$result: $errorInfo"
+                ui_debug "${result}: $errorInfo"
                 return -code error "The specified version '$version' is not valid."
             }
             set srcs [split [read -nonewline $src_file] "\n"]
             close $src_file
 
-            # Use $conf_path/base to read in targets.
-            if {[catch {set tgt_file [open "$conf_path/base"]} result]} {
+            # Use ${conf_path}/base to read in targets.
+            if {[catch {set tgt_file [open ${conf_path}/base]} result]} {
                 global errorInfo
-                ui_debug "$result: $errorInfo"
-                return -code error [concat "The configuration file " \
-                                           "'$conf_path/base' could not be " \
+                ui_debug "${result}: $errorInfo"
+                return -code error [concat "The configuration file" \
+                                           "'${conf_path}/base' could not be" \
                                            "opened."]
             }
-            set tgts [split [read -nonewline $tgt_file] "\n"]
+            set tgts [split [read -nonewline $tgt_file] \n]
             close $tgt_file
 
             # Iterate through the configuration files executing the specified
@@ -4115,11 +4145,11 @@
                         ui_debug "ln -sf $src $tgt"
                     }
                 }
-                set i [expr $i+1]
+                incr i
             }
 
             # Update the selected version.
-            set selected_version "$conf_path/current"
+            set selected_version ${conf_path}/current
             if {[file exists $selected_version]} {
                 file delete $selected_version
             }
@@ -4127,10 +4157,10 @@
             return
         }
         show {
-            set selected_version "$conf_path/current"
+            set selected_version ${conf_path}/current
 
             if {![file exists $selected_version]} {
-                return "none"
+                return none
             } else {
                 return [file readlink $selected_version]
             }
@@ -4147,19 +4177,19 @@
     if {[info exists env(TMPDIR)]} {
         return $env(TMPDIR)
     } else {
-        return "/tmp"
+        return /tmp
     }
 }
 
 # check if the system we're on can run code of the given architecture
 proc macports::arch_runnable {arch} {
     global macports::os_major macports::os_arch macports::os_platform
-    if {${macports::os_platform} == "darwin"} {
-        if {${macports::os_major} >= 11 && [string first "ppc" $arch] == 0} {
+    if {$macports::os_platform eq "darwin"} {
+        if {$macports::os_major >= 11 && [string first "ppc" $arch] == 0} {
             return no
-        } elseif {${macports::os_arch} == "i386" && $arch == "ppc64"} {
+        } elseif {$macports::os_arch eq "i386" && $arch eq "ppc64"} {
             return no
-        } elseif {${macports::os_major} <= 8 && $arch == "x86_64"} {
+        } elseif {$macports::os_major <= 8 && $arch eq "x86_64"} {
             return no
         }
     }
@@ -4182,7 +4212,7 @@
 
     set files [registry::file search active 1 binary -null]
     set files_count [llength $files]
-    set fancy_output [expr ![macports::ui_isset ports_debug] && [isatty stdout]]
+    set fancy_output [expr {![macports::ui_isset ports_debug] && [isatty stdout]}]
     if {$files_count > 0} {
         registry::write {
             try {
@@ -4191,18 +4221,18 @@
                 foreach f $files {
                     if {$fancy_output} {
                         if {$files_count < 10000 || $i % 10 == 1 || $i == $files_count} {
-                            ui_msg -nonewline "\r$macports::ui_prefix Updating database of binaries: [expr ($i * 1000 / $files_count) / 10.0]%"
+                            ui_msg -nonewline "\r$macports::ui_prefix Updating database of binaries: [expr {($i * 1000 / $files_count) / 10.0}]%"
                             flush stdout
                         }
                     }
                     set fpath [$f actual_path]
-                    ui_debug "Updating binary flag for file $i of $files_count: $fpath"
+                    ui_debug "Updating binary flag for file $i of ${files_count}: $fpath"
                     incr i
 
                     if {0 != [catch {$f binary [fileIsBinary $fpath]} fileIsBinaryError]} {
                         # handle errors (e.g. file not found, permission denied) gracefully
                         if {$fancy_output} {
-                            ui_msg ""
+                            ui_msg {}
                         }
                         ui_warn "Error determining file type of `$fpath': $fileIsBinaryError"
                         ui_warn "A file belonging to the `[[registry::entry owner $fpath] name]' port is missing or unreadable. Consider reinstalling it."
@@ -4213,7 +4243,7 @@
                 throw
             }
         }
-        ui_msg ""
+        ui_msg {}
     }
 
     set broken_files {};
@@ -4222,7 +4252,7 @@
     if {$binary_count > 0} {
         ui_msg -nonewline "$macports::ui_prefix Scanning binaries for linking errors"
         set handle [machista::create_handle]
-        if {$handle == "NULL"} {
+        if {$handle eq "NULL"} {
             error "Error creating libmachista handle"
         }
         array unset files_warned_about
@@ -4232,12 +4262,12 @@
         foreach b $binaries {
             if {$fancy_output} {
                 if {$binary_count < 10000 || $i % 10 == 1 || $i == $binary_count} {
-                    ui_msg -nonewline "\r$macports::ui_prefix Scanning binaries for linking errors: [expr ($i * 1000 / $binary_count) / 10.0]%"
+                    ui_msg -nonewline "\r$macports::ui_prefix Scanning binaries for linking errors: [expr {($i * 1000 / $binary_count) / 10.0}]%"
                     flush stdout
                 }
             }
             set bpath [$b actual_path]
-            #ui_debug "$i/$binary_count: $bpath"
+            #ui_debug "${i}/${binary_count}: $bpath"
             incr i
 
             set resultlist [machista::parse_file $handle $bpath]
@@ -4251,7 +4281,7 @@
                     #ui_debug "Error parsing file ${bpath}: [machista::strerror $returncode]"
                 } else {
                     if {$fancy_output} {
-                        ui_msg ""
+                        ui_msg {}
                     }
                     ui_warn "Error parsing file ${bpath}: [machista::strerror $returncode]"
                 }
@@ -4259,51 +4289,51 @@
             }
 
             set architecture [$result cget -mt_archs]
-            while {$architecture != "NULL"} {
-                if {[info exists options(ports_rev-upgrade_id-loadcmd-check)] && $options(ports_rev-upgrade_id-loadcmd-check) == "yes"} {
-                    if {[$architecture cget -mat_install_name] != "NULL" && [$architecture cget -mat_install_name] != ""} {
+            while {$architecture ne "NULL"} {
+                if {[info exists options(ports_rev-upgrade_id-loadcmd-check)] && $options(ports_rev-upgrade_id-loadcmd-check) eq "yes"} {
+                    if {[$architecture cget -mat_install_name] ne "NULL" && [$architecture cget -mat_install_name] ne {}} {
                         # check if this lib's install name actually refers to this file itself
                         # if this is not the case software linking against this library might have erroneous load commands
                         if {0 == [catch {set idloadcmdpath [revupgrade_handle_special_paths $bpath [$architecture cget -mat_install_name]]}]} {
-                            if {[string index $idloadcmdpath 0] != "/"} {
+                            if {[string index $idloadcmdpath 0] ne "/"} {
                                 set port [registry::entry owner $bpath]
-                                if {$port != ""} {
+                                if {$port ne {}} {
                                     set portname [$port name]
                                 } else {
-                                    set portname "<unknown-port>"
+                                    set portname <unknown-port>
                                 }
                                 if {$fancy_output} {
-                                    ui_msg ""
+                                    ui_msg {}
                                 }
                                 ui_warn "ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] (belonging to port $portname) contains relative path"
                             } elseif {![file exists $idloadcmdpath]} {
                                 set port [registry::entry owner $bpath]
-                                if {$port != ""} {
+                                if {$port ne {}} {
                                     set portname [$port name]
                                 } else {
-                                    set portname "<unknown-port>"
+                                    set portname <unknown-port>
                                 }
                                 if {$fancy_output} {
-                                    ui_msg ""
+                                    ui_msg {}
                                 }
                                 ui_warn "ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to non-existant file $idloadcmdpath"
                                 ui_warn "This is probably a bug in the $portname port and might cause problems in libraries linking against this file"
                             } else {
-    
+
                                 set hash_this [sha256 file $bpath]
                                 set hash_idloadcmd [sha256 file $idloadcmdpath]
-    
-                                if {$hash_this != $hash_idloadcmd} {
+
+                                if {$hash_this ne $hash_idloadcmd} {
                                     set port [registry::entry owner $bpath]
-                                    if {$port != ""} {
+                                    if {$port ne {}} {
                                         set portname [$port name]
                                     } else {
-                                        set portname "<unknown-port>"
+                                        set portname <unknown-port>
                                     }
                                     if {$fancy_output} {
-                                        ui_msg ""
+                                        ui_msg {}
                                     }
-                                    ui_warn "ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to file $idloadcmdpath, which is a different file"
+                                    ui_warn "ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to file ${idloadcmdpath}, which is a different file"
                                     ui_warn "This is probably a bug in the $portname port and might cause problems in libraries linking against this file"
                                 }
                             }
@@ -4320,7 +4350,7 @@
 
                 set loadcommand [$architecture cget -mat_loadcmds]
 
-                while {$loadcommand != "NULL"} {
+                while {$loadcommand ne "NULL"} {
                     if {0 != [catch {set filepath [revupgrade_handle_special_paths $bpath [$loadcommand cget -mlt_install_name]]}]} {
                         set loadcommand [$loadcommand cget -next]
                         continue;
@@ -4333,9 +4363,9 @@
                     if {$libreturncode != $machista::SUCCESS} {
                         if {![info exists files_warned_about($filepath)]} {
                             if {[macports::ui_isset ports_verbose]} {
-                                ui_msg ""
+                                ui_msg {}
                             }
-                            ui_info "Could not open $filepath: [machista::strerror $libreturncode] (referenced from $bpath)"
+                            ui_info "Could not open ${filepath}: [machista::strerror $libreturncode] (referenced from $bpath)"
                             set files_warned_about($filepath) yes
                         }
                         if {$libreturncode == $machista::EFILE} {
@@ -4348,15 +4378,15 @@
 
                     set libarchitecture [$libresult cget -mt_archs]
                     set libarch_found false;
-                    while {$libarchitecture != "NULL"} {
-                        if {[$architecture cget -mat_arch] != [$libarchitecture cget -mat_arch]} {
+                    while {$libarchitecture ne "NULL"} {
+                        if {[$architecture cget -mat_arch] ne [$libarchitecture cget -mat_arch]} {
                             set libarchitecture [$libarchitecture cget -next]
                             continue;
                         }
 
-                        if {[$loadcommand cget -mlt_version] != [$libarchitecture cget -mat_version] && [$loadcommand cget -mlt_comp_version] > [$libarchitecture cget -mat_comp_version]} {
+                        if {[$loadcommand cget -mlt_version] ne [$libarchitecture cget -mat_version] && [$loadcommand cget -mlt_comp_version] > [$libarchitecture cget -mat_comp_version]} {
                             if {[macports::ui_isset ports_verbose]} {
-                                ui_msg ""
+                                ui_msg {}
                             }
                             ui_info "Incompatible library version: $bpath requires version [machista::format_dylib_version [$loadcommand cget -mlt_comp_version]] or later, but $filepath provides version [machista::format_dylib_version [$libarchitecture cget -mat_comp_version]]"
                             ui_debug "Marking $bpath as broken"
@@ -4367,7 +4397,7 @@
                         break;
                     }
 
-                    if {$libarch_found == false} {
+                    if {$libarch_found eq false} {
                         ui_debug "Missing architecture [machista::get_arch_name [$architecture cget -mat_arch]] in file $filepath"
                         if {[path_is_in_prefix $filepath]} {
                             ui_debug "Marking $bpath as broken"
@@ -4383,7 +4413,7 @@
                 set architecture [$architecture cget -next]
             }
         }
-        ui_msg ""
+        ui_msg {}
 
         machista::destroy_handle $handle
 
@@ -4396,7 +4426,7 @@
         set broken_files [lsort -unique $broken_files]
         foreach file $broken_files {
             set port [registry::entry owner $file]
-            if {$port != ""} {
+            if {$port ne {}} {
                 lappend broken_ports $port
                 lappend broken_files_by_port($port) $file
             } else {
@@ -4405,13 +4435,13 @@
         }
         set broken_ports [lsort -unique $broken_ports]
 
-        if {${macports::revupgrade_mode} == "rebuild"} {
+        if {$macports::revupgrade_mode eq "rebuild"} {
             # don't try to rebuild ports that don't exist in the tree
             set temp_broken_ports {}
             foreach port $broken_ports {
                 set portname [$port name]
                 if {[catch {mportlookup $portname} result]} {
-                    ui_debug "$::errorInfo"
+                    ui_debug $::errorInfo
                     error "lookup of portname $portname failed: $result"
                 }
                 if {[llength $result] >= 2} {
@@ -4443,7 +4473,7 @@
                 if {$fancy_output} {
                     ui_error "Please run port -d -y rev-upgrade and use the output to report a bug."
                 }
-                error "Port $portname still broken after rebuilding [expr $broken_port_counts($portname) - 1] time(s)"
+                error "Port $portname still broken after rebuilding [expr {$broken_port_counts($portname) - 1}] time(s)"
             } elseif {$broken_port_counts($portname) > 1 && [global_option_isset ports_binary_only]} {
                 error "Port $portname still broken after reinstalling -- can't rebuild due to binary-only mode"
             }
@@ -4451,7 +4481,7 @@
         }
         unset temp_broken_ports
 
-        if {${macports::revupgrade_mode} != "rebuild"} {
+        if {$macports::revupgrade_mode ne "rebuild"} {
             ui_msg "$macports::ui_prefix Found [llength $broken_ports] broken port(s):"
             foreach port $broken_ports {
                 ui_msg "     [$port name] @[$port version] [$port variants][$port negated_variants]"
@@ -4504,7 +4534,7 @@
                     set index [lsearch -exact $unsorted_ports $port]
                     set unsorted_ports [lreplace $unsorted_ports $index $index]
 
-                    # remove edges 
+                    # remove edges
                     foreach target $revadjlist($port) {
                         set index [lsearch -exact $adjlist($target) $port]
                         set adjlist($target) [lreplace $adjlist($target) $index $index]
@@ -4543,7 +4573,7 @@
             set portname [$port name]
             if {![info exists depscache(port:$portname)]} {
                 # set rev-upgrade options and nodeps if this is not the first run
-                set my_options(ports_revupgrade) "yes"
+                set my_options(ports_revupgrade) yes
                 unset -nocomplain my_options(ports_nodeps)
                 unset -nocomplain my_options(ports_revupgrade_second_run)
                 if {$broken_port_counts($portname) > 1} {
@@ -4554,7 +4584,7 @@
                 }
 
                 # call macports::upgrade with ports_revupgrade option to rebuild the port
-                set status [macports::upgrade $portname "port:$portname" \
+                set status [macports::upgrade $portname port:$portname \
                     {} [array get my_options] depscache]
                 ui_debug "Rebuilding port $portname finished with status $status"
                 if {$status != 0} {
@@ -4563,7 +4593,7 @@
             }
         }
 
-        if {[info exists options(ports_dryrun)] && $options(ports_dryrun) == "yes"} {
+        if {[info exists options(ports_dryrun)] && $options(ports_dryrun) eq "yes"} {
             ui_warn "If this was no dry run, rev-upgrade would now run the checks again to find unresolved and newly created problems"
             return 0
         }
@@ -4596,18 +4626,18 @@
 proc macports::revupgrade_handle_special_paths {fname path} {
     set corrected_path $path
 
-    set loaderpath_idx [string first "@loader_path" $corrected_path]
+    set loaderpath_idx [string first @loader_path $corrected_path]
     if {$loaderpath_idx != -1} {
-        set corrected_path [string replace $corrected_path $loaderpath_idx $loaderpath_idx+11 [file dirname $fname]]
+        set corrected_path [string replace $corrected_path $loaderpath_idx ${loaderpath_idx}+11 [file dirname $fname]]
     }
 
-    set executablepath_idx [string first "@executable_path" $corrected_path]
+    set executablepath_idx [string first @executable_path $corrected_path]
     if {$executablepath_idx != -1} {
         ui_debug "Ignoring loadcommand containing @executable_path in $fname"
         error "@executable_path in loadcommand"
     }
 
-    set rpath_idx [string first "@rpath" $corrected_path]
+    set rpath_idx [string first @rpath $corrected_path]
     if {$rpath_idx != -1} {
         ui_debug "Ignoring loadcommand containing @rpath in $fname"
         error "@rpath in loadcommand"
@@ -4640,7 +4670,7 @@
             lappend adjlist($dep) [lindex $stack 0]
             # make this port the new last broken port by prepending it to the stack
             set stack [linsert $stack 0 $dep]
-            
+
             set is_broken_port true
         }
         if {![info exists visited($dep)]} {
@@ -4663,7 +4693,7 @@
         return 1
     } elseif {[info exists ping_cache($host)]} {
         # expire entries after 1 day
-        if {[expr [clock seconds] - [lindex $ping_cache($host) 1]] <= 86400} {
+        if {[clock seconds] - [lindex $ping_cache($host) 1] <= 86400} {
             return [lindex $ping_cache($host) 0]
         }
     }
@@ -4683,19 +4713,19 @@
         set archive_sites_conf_values {}
         set all_names {}
         array set defaults {applications_dir /Applications/MacPorts prefix /opt/local type tbz2}
-        set conf_file "${macports_conf_path}/archive_sites.conf"
+        set conf_file ${macports_conf_path}/archive_sites.conf
         set conf_options {applications_dir frameworks_dir name prefix type urls}
         if {[file isfile $conf_file]} {
             set fd [open $conf_file r]
             while {[gets $fd line] >= 0} {
                 if {[regexp {^(\w+)([ \t]+(.*))?$} $line match option ignore val] == 1} {
                     if {[lsearch -exact $conf_options $option] >= 0} {
-                        if {$option == "name"} {
+                        if {$option eq "name"} {
                             set cur_name $val
                             lappend all_names $val
                         } elseif {[info exists cur_name]} {
                             set trimmedval [string trim $val]
-                            if {$option == "urls"} {
+                            if {$option eq "urls"} {
                                 set processed_urls {}
                                 foreach url $trimmedval {
                                     lappend processed_urls ${url}:nosubdir
@@ -4730,8 +4760,8 @@
                 }
                 if {![info exists sites($cur_name)]} {
                     ui_warn "archive_sites.conf: no urls set for $cur_name"
-                    set sites($cur_name) ""
-                    lappend archive_sites_conf_values portfetch::mirror_sites::sites($cur_name) ""
+                    set sites($cur_name) {}
+                    lappend archive_sites_conf_values portfetch::mirror_sites::sites($cur_name) {}
                 }
             }
         }

Modified: branches/gsoc11-statistics/base/src/package1.0/portarchivefetch.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portarchivefetch.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/package1.0/portarchivefetch.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -2,7 +2,7 @@
 # $Id$
 #
 # Copyright (c) 2002 - 2003 Apple Inc.
-# Copyright (c) 2004 - 2012 The MacPorts Project
+# Copyright (c) 2004 - 2013 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -93,7 +93,8 @@
         if {$missing} {
             continue
         }
-        if {$portfetch::mirror_sites::archive_prefix($site) == $prefix &&
+        if {$portfetch::mirror_sites::sites($site) ne {} &&
+            $portfetch::mirror_sites::archive_prefix($site) == $prefix &&
             $portfetch::mirror_sites::archive_frameworks_dir($site) == $frameworks_dir &&
             $portfetch::mirror_sites::archive_applications_dir($site) == $applications_dir &&
             ![catch {archiveTypeIsSupported $portfetch::mirror_sites::archive_type($site)}]} {
@@ -152,10 +153,10 @@
 # Perform a standard fetch, assembling fetch urls from
 # the listed url variable and associated archive file
 proc portarchivefetch::fetchfiles {args} {
-    global archivefetch.fulldestpath UI_PREFIX
-    global archivefetch.user archivefetch.password archivefetch.use_epsv \
-           archivefetch.ignore_sslcert
-    global portverbose ports_binary_only
+    global archivefetch.fulldestpath UI_PREFIX \
+           archivefetch.user archivefetch.password archivefetch.use_epsv \
+           archivefetch.ignore_sslcert \
+           portverbose ports_binary_only
     variable archivefetch_urls
     variable ::portfetch::urlmap
 

Modified: branches/gsoc11-statistics/base/src/package1.0/portdmg.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portdmg.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/package1.0/portdmg.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -57,8 +57,8 @@
 }
 
 proc portdmg::package_dmg {portname portversion portrevision} {
-    global UI_PREFIX package.destpath portpath
-    global os.platform os.arch os.version os.major
+    global UI_PREFIX package.destpath portpath \
+           os.platform os.arch os.version os.major
 
     if {[expr (${portrevision} > 0)]} {
         set imagename "${portname}-${portversion}-${portrevision}"

Modified: branches/gsoc11-statistics/base/src/package1.0/portdpkg.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portdpkg.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/package1.0/portdpkg.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -44,8 +44,8 @@
 }
 
 # Options
-options dpkg.asroot
-options package.destpath
+options dpkg.asroot \
+        package.destpath
 
 # Set up defaults
 default dpkg.asroot yes

Modified: branches/gsoc11-statistics/base/src/package1.0/portmdmg.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portmdmg.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/package1.0/portmdmg.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -2,7 +2,7 @@
 # portmdmg.tcl
 # $Id$
 #
-# Copyright (c) 2005, 2007-2011 The MacPorts Project
+# Copyright (c) 2005, 2007-2013 The MacPorts Project
 # Copyright (c) 2003-2004 Apple Inc.
 # All rights reserved.
 #
@@ -57,8 +57,8 @@
 }
 
 proc portmdmg::package_mdmg {portname portepoch portversion portrevision} {
-    global UI_PREFIX package.destpath portpath
-    global os.platform os.arch os.version os.major
+    global UI_PREFIX package.destpath portpath \
+           os.platform os.arch os.version os.major
 
     if {[expr (${portrevision} > 0)]} {
         set imagename "${portname}-${portversion}-${portrevision}"

Modified: branches/gsoc11-statistics/base/src/package1.0/portmpkg.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portmpkg.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/package1.0/portmpkg.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -2,7 +2,7 @@
 # portmpkg.tcl
 # $Id$
 #
-# Copyright (c) 2005, 2007 - 2012 The MacPorts Project
+# Copyright (c) 2005, 2007 - 2013 The MacPorts Project
 # Copyright (c) 2002 - 2004 Apple Inc.
 # All rights reserved.
 #

Modified: branches/gsoc11-statistics/base/src/package1.0/portpkg.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portpkg.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/package1.0/portpkg.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -2,7 +2,7 @@
 # portpkg.tcl
 # $Id$
 #
-# Copyright (c) 2005, 2007 - 2012 The MacPorts Project
+# Copyright (c) 2005, 2007 - 2013 The MacPorts Project
 # Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #

Modified: branches/gsoc11-statistics/base/src/package1.0/portrpm.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portrpm.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/package1.0/portrpm.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -2,7 +2,7 @@
 # portrpm.tcl
 # $Id$
 #
-# Copyright (c) 2005 - 2007, 2009 - 2011 The MacPorts Project
+# Copyright (c) 2005 - 2007, 2009 - 2011, 2013 The MacPorts Project
 # Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
@@ -43,8 +43,8 @@
 }
 
 # Options
-options rpm.asroot
-options package.destpath
+options rpm.asroot \
+        package.destpath
 
 # Set up defaults
 default rpm.asroot yes
@@ -63,8 +63,10 @@
 }
 
 proc portrpm::rpm_pkg {portname portversion portrevision} {
-    global UI_PREFIX rpm.asroot package.destpath portdbpath destpath workpath prefix categories maintainers description long_description homepage epoch portpath
-	global os.platform os.arch os.version os.major supported_archs configure.build_arch license
+    global UI_PREFIX rpm.asroot package.destpath portdbpath destpath workpath \
+           prefix categories maintainers description long_description \
+           homepage epoch portpath os.platform os.arch os.version os.major \
+           supported_archs configure.build_arch license
 
     set rpmdestpath ""
     if {![string equal ${package.destpath} ${workpath}] && ![string equal ${package.destpath} ""]} {

Modified: branches/gsoc11-statistics/base/src/package1.0/portsrpm.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portsrpm.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/package1.0/portsrpm.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -2,7 +2,7 @@
 # portsrpm.tcl
 # $Id$
 #
-# Copyright (c) 2007, 2009, 2011 The MacPorts Project
+# Copyright (c) 2007, 2009, 2011, 2013 The MacPorts Project
 # Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
@@ -59,8 +59,10 @@
 }
 
 proc portsrpm::srpm_pkg {portname portversion portrevision} {
-    global UI_PREFIX package.destpath portdbpath destpath workpath distpath prefix categories maintainers description long_description homepage epoch portpath distfiles
-	global os.platform os.arch os.version os.major
+    global UI_PREFIX package.destpath portdbpath destpath workpath distpath \
+           prefix categories maintainers description long_description \
+           homepage epoch portpath distfiles os.platform os.arch os.version \
+           os.major
 
     set fetch_urls {}
     portfetch::checkfiles fetch_urls

Modified: branches/gsoc11-statistics/base/src/package1.0/portunarchive.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portunarchive.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/package1.0/portunarchive.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -278,6 +278,7 @@
         file copy -force $plus_state $statefile
         file mtime $statefile [clock seconds]
         chownAsRoot $statefile
+        update_statefile checksum [sha256 file [option portpath]/Portfile] $statefile
         set newstate 1
     } else {
         # fake it

Modified: branches/gsoc11-statistics/base/src/pextlib1.0/system.c
===================================================================
--- branches/gsoc11-statistics/base/src/pextlib1.0/system.c	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/pextlib1.0/system.c	2013-06-21 19:46:52 UTC (rev 107206)
@@ -80,11 +80,11 @@
 static int check_sandboxing(Tcl_Interp *interp, char **sandbox_exec_path, char **profilestr)
 {
     Tcl_Obj *tcl_result;
-    int supported;
+    int active;
     int len;
 
-    tcl_result = Tcl_GetVar2Ex(interp, "portsandbox_supported", NULL, TCL_GLOBAL_ONLY);
-    if (!tcl_result || Tcl_GetBooleanFromObj(interp, tcl_result, &supported) != TCL_OK || !supported) {
+    tcl_result = Tcl_GetVar2Ex(interp, "portsandbox_active", NULL, TCL_GLOBAL_ONLY);
+    if (!tcl_result || Tcl_GetBooleanFromObj(interp, tcl_result, &active) != TCL_OK || !active) {
         return 0;
     }
 

Modified: branches/gsoc11-statistics/base/src/pextlib1.0/tracelib.c
===================================================================
--- branches/gsoc11-statistics/base/src/pextlib1.0/tracelib.c	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/pextlib1.0/tracelib.c	2013-06-21 19:46:52 UTC (rev 107206)
@@ -2,7 +2,8 @@
  * tracelib.c
  * $Id$
  *
- * Copyright (c) 2007 Eugene Pimenov (GSoC), The MacPorts Project.
+ * Copyright (c) 2007-2008 Eugene Pimenov (GSoC)
+ * Copyright (c) 2008-2010, 2012-2013 The MacPorts Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

Modified: branches/gsoc11-statistics/base/src/port/port-help.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port/port-help.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port/port-help.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -42,6 +42,7 @@
 set porthelp(clean) {
 Removes files associated with the given ports
 
+--archive     Removes temporary archives
 --dist        Removes downloaded distfiles
 --logs        Removes log files
 --work        Removes work directory (default)

Modified: branches/gsoc11-statistics/base/src/port/port.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port/port.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port/port.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -5,7 +5,7 @@
 # port.tcl
 # $Id$
 #
-# Copyright (c) 2004-2012 The MacPorts Project
+# Copyright (c) 2004-2013 The MacPorts Project
 # Copyright (c) 2004 Robert Shaw <rshaw at opendarwin.org>
 # Copyright (c) 2002-2003 Apple Inc.
 # All rights reserved.
@@ -3945,8 +3945,7 @@
 
 proc action_portcmds { action portlist opts } {
     # Operations on the port's directory and Portfile
-    global env boot_env
-    global current_portdir
+    global env boot_env current_portdir
 
     array set local_options $opts
     
@@ -4464,7 +4463,7 @@
     install     {no-rev-upgrade unrequested}
     uninstall   {follow-dependents follow-dependencies no-exec}
     variants    {index}
-    clean       {all dist work logs}
+    clean       {all archive dist work logs}
     mirror      {new}
     lint        {nitpick}
     select      {list set show}
@@ -4662,9 +4661,9 @@
 }
 
 proc process_cmd { argv } {
-    global cmd_argc cmd_argv cmd_argn
-    global global_options global_options_base private_options ui_options
-    global current_portdir
+    global cmd_argc cmd_argv cmd_argn \
+           global_options global_options_base private_options ui_options \
+           current_portdir
     set cmd_argv $argv
     set cmd_argc [llength $argv]
     set cmd_argn 0
@@ -4797,8 +4796,7 @@
 
 # return text action beginning with $text
 proc complete_action { text state } {   
-    global action_array
-    global complete_choices complete_position
+    global action_array complete_choices complete_position
 
     if {$state == 0} {
         set complete_position 0
@@ -4989,17 +4987,15 @@
 # We do this here to save it in the boot_env, in case we determined it manually
 term_init_size
 
+global env boot_env argv0 cmdname argc argv cmd_argc cmd_argv cmd_argn \
+       current_portdir global_options_base exit_status
+
 # Save off a copy of the environment before mportinit monkeys with it
-global env boot_env
 array set boot_env [array get env]
 
-global argv0
-global cmdname
 set cmdname [file tail $argv0]
 
 # Setp cmd_argv to match argv
-global argc argv
-global cmd_argc cmd_argv cmd_argn
 set cmd_argv $argv
 set cmd_argc $argc
 set cmd_argn 0
@@ -5044,16 +5040,13 @@
 }
 
 # Set up some global state for our code
-global current_portdir
 set current_portdir [pwd]
 
 # Freeze global_options into global_options_base; global_options
 # will be reset to global_options_base prior to processing each command.
-global global_options_base
 set global_options_base [array get global_options]
 
 # First process any remaining args as action(s)
-global exit_status
 set exit_status 0
 if { [llength $remaining_args] > 0 } {
 

Modified: branches/gsoc11-statistics/base/src/port1.0/fetch_common.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/fetch_common.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port1.0/fetch_common.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -2,7 +2,7 @@
 # $Id$
 #
 # Copyright (c) 2002 - 2003 Apple Inc.
-# Copyright (c) 2004 - 2012 The MacPorts Project
+# Copyright (c) 2004 - 2013 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -84,8 +84,8 @@
 # For a given mirror site type, e.g. "gnu" or "x11", check to see if there's a
 # pre-registered set of sites, and if so, return them.
 proc portfetch::mirror_sites {mirrors tag subdir mirrorfile} {
-    global UI_PREFIX name dist_subdir
-    global global_mirror_site fallback_mirror_site
+    global UI_PREFIX name dist_subdir \
+           global_mirror_site fallback_mirror_site
 
     if {[file exists $mirrorfile]} {
         source $mirrorfile
@@ -343,6 +343,6 @@
 proc portfetch::check_dns {} {
     # check_broken_dns returns true at most once, so we don't have to worry about spamming this message
     if {[check_broken_dns]} {
-        ui_warn "Your DNS server(s) incorrectly claim to know the address of nonexistent hosts. This may cause checksum mismatches for some ports."
+        ui_warn "Your DNS servers incorrectly claim to know the address of nonexistent hosts. This may cause checksum mismatches for some ports."
     }
 }

Modified: branches/gsoc11-statistics/base/src/port1.0/portactivate.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portactivate.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port1.0/portactivate.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -59,7 +59,7 @@
 }
 
 proc portactivate::activate_main {args} {
-    global env subport version revision portvariants user_options PortInfo
+    global env subport version revision portvariants user_options PortInfo startupitem.autostart UI_PREFIX
 
     registry_activate $subport $version $revision $portvariants [array get user_options]
 
@@ -97,5 +97,13 @@
         ui_notice ""
     }
 
+    if {[tbool startupitem.autostart]} {
+        ui_notice "$UI_PREFIX [format [msgcat::mc "Loading %s"] [option subport]]"
+        if {[eval_targets "load"]} {
+            ui_error [format [msgcat::mc "Failed to load %s"] [option subport]]
+            return 1
+        }
+    }
+
     return 0
 }

Modified: branches/gsoc11-statistics/base/src/port1.0/portbuild.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portbuild.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port1.0/portbuild.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -2,7 +2,7 @@
 # portbuild.tcl
 # $Id$
 #
-# Copyright (c) 2007 - 2012 The MacPorts Project
+# Copyright (c) 2007 - 2013 The MacPorts Project
 # Copyright (c) 2002 - 2004 Apple Inc.
 # All rights reserved.
 #
@@ -43,11 +43,11 @@
 }
 
 # define options
-options build.asroot
-options build.jobs
-options build.target
-options build.type
-options use_parallel_build
+options build.asroot \
+        build.jobs \
+        build.target \
+        build.type \
+        use_parallel_build
 commands build
 # defaults
 default build.asroot no
@@ -66,6 +66,10 @@
 # ${build.type} == bsd, ensures bsdmake is present by adding a bin:-style
 # dependency.
 proc portbuild::add_automatic_buildsystem_dependencies {} {
+    global build.type.add_deps
+    if {!${build.type.add_deps}} {
+        return
+    }
     if {[option build.type] == "bsd" && [option os.platform] == "darwin"} {
         ui_debug "build.type is BSD, adding bin:bsdmake:bsdmake build dependency"
         depends_build-delete bin:bsdmake:bsdmake
@@ -79,6 +83,9 @@
 }
 # Register the above procedure as a callback after Portfile evaluation
 port::register_callback portbuild::add_automatic_buildsystem_dependencies
+# and an option to turn it off if required
+options build.type.add_deps
+default build.type.add_deps yes
 
 proc portbuild::build_getmaketype {args} {
     if {[option build.type] == "default"} {

Modified: branches/gsoc11-statistics/base/src/port1.0/portchecksum.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portchecksum.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port1.0/portchecksum.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -200,8 +200,8 @@
 # Target main procedure. Verifies the checksums of all distfiles.
 #
 proc portchecksum::checksum_main {args} {
-    global UI_PREFIX all_dist_files checksum_types checksums_array portverbose checksum.skip
-    global usealtworkpath altprefix default_checksum_types
+    global UI_PREFIX all_dist_files checksum_types checksums_array portverbose checksum.skip \
+           usealtworkpath altprefix default_checksum_types
 
     # If no files have been downloaded, there is nothing to checksum.
     if {![info exists all_dist_files]} {

Modified: branches/gsoc11-statistics/base/src/port1.0/portclean.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portclean.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port1.0/portclean.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -1,8 +1,7 @@
 # -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
-# portclean.tcl
 # $Id$
 #
-# Copyright (c) 2005-2007, 2009-2011 The MacPorts Project
+# Copyright (c) 2005-2007, 2009-2011, 2013 The MacPorts Project
 # Copyright (c) 2004 Robert Shaw <rshaw at opendarwin.org>
 # Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
@@ -61,9 +60,8 @@
 }
 
 proc portclean::clean_main {args} {
-    global UI_PREFIX
-    global ports_clean_dist ports_clean_work ports_clean_logs
-    global ports_clean_all keeplogs usealtworkpath
+    global UI_PREFIX ports_clean_dist ports_clean_work ports_clean_logs \
+           ports_clean_archive ports_clean_all keeplogs usealtworkpath
 
     if {$usealtworkpath} {
         ui_warn "Only cleaning in ~/.macports; insufficient privileges for standard locations"
@@ -74,8 +72,16 @@
         ui_info "$UI_PREFIX [format [msgcat::mc "Removing distfiles for %s"] [option subport]]"
         clean_dist
     }
+    if {([info exists ports_clean_all] && $ports_clean_all == "yes" || \
+        [info exists ports_clean_archive] && $ports_clean_archive == "yes")
+        && !$usealtworkpath} {
+        ui_info "$UI_PREFIX [format [msgcat::mc "Removing temporary archives for %s"] [option subport]]"
+        clean_archive
+    }
     if {[info exists ports_clean_all] && $ports_clean_all == "yes" || \
         [info exists ports_clean_work] && $ports_clean_work == "yes" || \
+        [info exists ports_clean_archive] && $ports_clean_archive == "yes" || \
+        [info exists ports_clean_dist] && $ports_clean_dist == "yes" || \
         !([info exists ports_clean_logs] && $ports_clean_logs == "yes")} {
          ui_info "$UI_PREFIX [format [msgcat::mc "Removing work directory for %s"] [option subport]]"
          clean_work
@@ -259,3 +265,55 @@
     }           	
     return 0
 }
+
+proc portclean::clean_archive {args} {
+    global subport ports_version_glob portdbpath
+
+    # Define archive destination directory, target filename, regex for archive name
+    set archivepath [file join $portdbpath incoming]
+
+    if {[info exists ports_version_glob]} {
+        # Match all possible archive variants that match the version
+        # glob specified by the user.
+        set fileglob "$subport-[option ports_version_glob]*.*.*.*"
+    } else {
+        # Match all possible archives for this port.
+        set fileglob "$subport-*_*.*.*.*"
+    }
+
+    # Remove the archive files
+    set count 0
+    foreach dir [list $archivepath ${archivepath}/verified] {
+        set archivelist [glob -nocomplain -directory $dir $fileglob]
+        foreach path $archivelist {
+            # Make sure file is truly an archive file for this port, and not
+            # an accidental match with some other file that might exist. Also
+            # delete anything ending in .TMP since those are incomplete and
+            # thus can't be checked and aren't useful anyway.
+            set archivetype [string range [file extension $path] 1 end]
+            if {[file isfile $path] && ($archivetype == "TMP"
+                || [extract_archive_metadata $path $archivetype portname] == $subport)} {
+                ui_debug "Removing archive: $path"
+                if {[catch {delete $path} result]} {
+                    ui_debug "$::errorInfo"
+                    ui_error "$result"
+                }
+                if {[file isfile ${path}.rmd160]} {
+                    ui_debug "Removing archive signature: ${path}.rmd160"
+                    if {[catch {delete ${path}.rmd160} result]} {
+                        ui_debug "$::errorInfo"
+                        ui_error "$result"
+                    }
+                }
+                incr count
+            }
+        }
+    }
+    if {$count > 0} {
+        ui_debug "$count archive(s) removed."
+    } else {
+        ui_debug "No archives found to remove at $archivepath"
+    }
+
+    return 0
+}

Modified: branches/gsoc11-statistics/base/src/port1.0/portconfigure.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portconfigure.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port1.0/portconfigure.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -127,11 +127,11 @@
 default configure.march     {}
 default configure.mtune     {}
 # We could have debug/optimizations be global configurable at some point.
-options configure.optflags
-options configure.cflags configure.cxxflags configure.objcflags
-options configure.cppflags configure.ldflags configure.libs
-options configure.fflags configure.f90flags configure.fcflags
-options configure.classpath
+options configure.optflags \
+        configure.cflags configure.cxxflags configure.objcflags \
+        configure.cppflags configure.ldflags configure.libs \
+        configure.fflags configure.f90flags configure.fcflags \
+        configure.classpath
 # compiler flags section
 default configure.optflags  {-Os}
 default configure.cflags    {${configure.optflags}}
@@ -146,9 +146,9 @@
 default configure.classpath {}
 
 # tools section
-options configure.perl configure.python configure.ruby
-options configure.install configure.awk configure.bison
-options configure.pkg_config configure.pkg_config_path
+options configure.perl configure.python configure.ruby \
+        configure.install configure.awk configure.bison \
+        configure.pkg_config configure.pkg_config_path
 default configure.perl              {}
 default configure.python            {}
 default configure.ruby              {}
@@ -167,9 +167,9 @@
     default configure.${tool}_archflags  "\[portconfigure::configure_get_archflags $tool\]"
 }
 
-options configure.universal_archs configure.universal_args
-options configure.universal_cflags configure.universal_cxxflags
-options configure.universal_cppflags configure.universal_ldflags
+options configure.universal_archs configure.universal_args \
+        configure.universal_cflags configure.universal_cxxflags \
+        configure.universal_cppflags configure.universal_ldflags
 default configure.universal_archs       {[portconfigure::choose_supported_archs ${universal_archs}]}
 default configure.universal_args        {--disable-dependency-tracking}
 default configure.universal_cflags      {[portconfigure::configure_get_universal_cflags]}
@@ -590,8 +590,12 @@
 # Some of the compilers we use are provided by MacPorts itself; ensure we
 # automatically add a dependency when needed
 proc portconfigure::add_automatic_compiler_dependencies {} {
-    global configure.compiler
+    global configure.compiler configure.compiler.add_deps
 
+    if {!${configure.compiler.add_deps}} {
+        return
+    }
+
     # The default value requires substitution before use.
     set compiler [subst ${configure.compiler}]
     if {![compiler_is_port $compiler]} {
@@ -617,16 +621,19 @@
 }
 # Register the above procedure as a callback after Portfile evaluation
 port::register_callback portconfigure::add_automatic_compiler_dependencies
+# and an option to turn it off if required
+options configure.compiler.add_deps
+default configure.compiler.add_deps yes
 
 proc portconfigure::configure_main {args} {
     global [info globals]
-    global worksrcpath use_configure use_autoreconf use_autoconf use_automake use_xmkmf
-    global configure.env configure.pipe configure.libs configure.classpath configure.universal_args
-    global configure.perl configure.python configure.ruby configure.install configure.awk configure.bison
-    global configure.pkg_config configure.pkg_config_path
-    global configure.ccache configure.distcc configure.cpp configure.javac configure.sdkroot
-    global configure.march configure.mtune
-    global os.platform os.major
+    global worksrcpath use_configure use_autoreconf use_autoconf use_automake use_xmkmf \
+           configure.env configure.pipe configure.libs configure.classpath configure.universal_args \
+           configure.perl configure.python configure.ruby configure.install configure.awk configure.bison \
+           configure.pkg_config configure.pkg_config_path \
+           configure.ccache configure.distcc configure.cpp configure.javac configure.sdkroot \
+           configure.march configure.mtune \
+           os.platform os.major
     foreach tool {cc cxx objc f77 f90 fc ld} {
         global configure.${tool} configure.${tool}_archflags
     }

Modified: branches/gsoc11-statistics/base/src/port1.0/portdeactivate.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portdeactivate.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port1.0/portdeactivate.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -57,7 +57,15 @@
 }
 
 proc portdeactivate::deactivate_main {args} {
-    global subport version revision portvariants user_options
+    global subport version revision portvariants user_options startupitem.autostart UI_PREFIX
+
+    if {[tbool startupitem.autostart]} {
+        ui_notice "$UI_PREFIX [format [msgcat::mc "Unloading %s"] [option subport]]"
+        if {[eval_targets "unload"]} {
+            ui_warn [format [msgcat::mc "Failed to unload %s, continuing anyway."] [option subport]]
+        }
+    }
+
     registry_deactivate $subport $version $revision $portvariants [array get user_options]
     return 0
 }

Modified: branches/gsoc11-statistics/base/src/port1.0/portdestroot.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portdestroot.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port1.0/portdestroot.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 2002 - 2003 Apple Inc.
 # Copyright (c) 2004 - 2005 Robert Shaw <rshaw at opendarwin.org>
-# Copyright (c) 2004-2005, 2007-2012 The MacPorts Project
+# Copyright (c) 2004-2005, 2007-2013 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -47,13 +47,14 @@
 }
 
 # define options
-options destroot.target destroot.destdir destroot.clean destroot.keepdirs destroot.umask
-options destroot.violate_mtree destroot.asroot destroot.delete_la_files
-options startupitem.create startupitem.requires startupitem.init
-options startupitem.name startupitem.start startupitem.stop startupitem.restart
-options startupitem.type startupitem.executable
-options startupitem.pidfile startupitem.logfile startupitem.logevents startupitem.netchange
-options startupitem.uniquename startupitem.plist startupitem.location startupitem.install
+options destroot.target destroot.destdir destroot.clean destroot.keepdirs destroot.umask \
+        destroot.violate_mtree destroot.asroot destroot.delete_la_files \
+        startupitem.autostart startupitem.create startupitem.executable \
+        startupitem.init startupitem.install startupitem.location \
+        startupitem.logevents startupitem.logfile startupitem.name \
+        startupitem.netchange startupitem.pidfile startupitem.plist \
+        startupitem.requires startupitem.restart startupitem.start \
+        startupitem.stop startupitem.type startupitem.uniquename
 commands destroot
 
 # Set defaults
@@ -71,22 +72,23 @@
 default destroot.violate_mtree no
 default destroot.delete_la_files no
 
+default startupitem.autostart   no
+default startupitem.executable  ""
+default startupitem.init        ""
+default startupitem.install     {$system_options(startupitem_install)}
+default startupitem.location    LaunchDaemons
+default startupitem.logevents   no
+default startupitem.logfile     ""
 default startupitem.name        {${subport}}
-default startupitem.uniquename  {org.macports.${startupitem.name}}
+default startupitem.netchange   no
+default startupitem.pidfile     ""
 default startupitem.plist       {${startupitem.uniquename}.plist}
-default startupitem.location    LaunchDaemons
-default startupitem.init        ""
+default startupitem.requires    ""
+default startupitem.restart     ""
 default startupitem.start       ""
 default startupitem.stop        ""
-default startupitem.restart     ""
-default startupitem.requires    ""
-default startupitem.executable  ""
 default startupitem.type        {$system_options(startupitem_type)}
-default startupitem.pidfile     ""
-default startupitem.logfile     ""
-default startupitem.logevents   no
-default startupitem.netchange   no
-default startupitem.install     {$system_options(startupitem_install)}
+default startupitem.uniquename  {org.macports.${startupitem.name}}
 
 set_ui_prefix
 
@@ -102,9 +104,9 @@
 }
 
 proc portdestroot::destroot_start {args} {
-    global UI_PREFIX prefix subport porturl destroot os.platform destroot.clean portsharepath
-    global destroot.umask destroot.asroot euid egid
-    global applications_dir frameworks_dir
+    global UI_PREFIX prefix subport porturl destroot os.platform destroot.clean portsharepath \
+           destroot.umask destroot.asroot euid egid \
+           applications_dir frameworks_dir
     variable oldmask
 
     ui_notice "$UI_PREFIX [format [msgcat::mc "Staging %s into destroot"] ${subport}]"
@@ -149,9 +151,9 @@
 }
 
 proc portdestroot::destroot_finish {args} {
-    global UI_PREFIX destroot prefix subport startupitem.create destroot.violate_mtree
-    global applications_dir frameworks_dir destroot.keepdirs destroot.delete_la_files
-    global os.platform os.version
+    global UI_PREFIX destroot prefix subport startupitem.create destroot.violate_mtree \
+           applications_dir frameworks_dir destroot.keepdirs destroot.delete_la_files \
+           os.platform os.version
     variable oldmask
 
     # Create startup-scripts/items

Modified: branches/gsoc11-statistics/base/src/port1.0/portdistcheck.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portdistcheck.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port1.0/portdistcheck.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -53,10 +53,8 @@
 default distcheck.type moddate
 
 proc portdistcheck::distcheck_main {args} {
-    global distcheck.type
-    global fetch.type
-    global fetch.ignore_sslcert
-    global subport portpath
+    global distcheck.type fetch.type fetch.ignore_sslcert \
+           subport portpath
 
     set port_moddate [file mtime ${portpath}/Portfile]
 

Modified: branches/gsoc11-statistics/base/src/port1.0/portfetch.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portfetch.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port1.0/portfetch.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -323,9 +323,9 @@
 # Perform a CVS login and fetch, storing the CVS login
 # information in a custom .cvspass file
 proc portfetch::cvsfetch {args} {
-    global workpath cvs.env cvs.cmd cvs.args cvs.post_args
-    global cvs.root cvs.date cvs.tag cvs.method cvs.password
-    global patch_sites patchfiles filespath
+    global workpath cvs.env cvs.cmd cvs.args cvs.post_args \
+           cvs.root cvs.date cvs.tag cvs.method cvs.password
+           patch_sites patchfiles filespath
 
     set cvs.args "${cvs.method} ${cvs.args}"
     if {${cvs.method} == "export" && ![string length ${cvs.tag}] && ![string length ${cvs.date}]} {
@@ -420,8 +420,8 @@
 
 # Perform a git fetch
 proc portfetch::gitfetch {args} {
-    global worksrcpath patchfiles
-    global git.url git.branch git.sha1 git.cmd
+    global worksrcpath patchfiles \
+           git.url git.branch git.sha1 git.cmd
 
     set options "-q"
     if {[string length ${git.branch}] == 0} {
@@ -476,9 +476,9 @@
 # Perform a standard fetch, assembling fetch urls from
 # the listed url variable and associated distfile
 proc portfetch::fetchfiles {args} {
-    global distpath all_dist_files UI_PREFIX
-    global fetch.user fetch.password fetch.use_epsv fetch.ignore_sslcert fetch.remote_time
-    global fallback_mirror_site portverbose usealtworkpath altprefix
+    global distpath all_dist_files UI_PREFIX \
+           fetch.user fetch.password fetch.use_epsv fetch.ignore_sslcert fetch.remote_time \
+           fallback_mirror_site portverbose usealtworkpath altprefix
     variable fetch_urls
     variable urlmap
 

Modified: branches/gsoc11-statistics/base/src/port1.0/portinstall.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portinstall.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port1.0/portinstall.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -54,8 +54,8 @@
 set_ui_prefix
 
 proc portinstall::install_start {args} {
-    global UI_PREFIX subport version revision portvariants
-    global prefix registry_open registry.path
+    global UI_PREFIX subport version revision portvariants \
+           prefix registry_open registry.path
     ui_notice "$UI_PREFIX [format [msgcat::mc "Installing %s @%s_%s%s"] $subport $version $revision $portvariants]"
     
     # start gsoc08-privileges
@@ -76,24 +76,6 @@
     handle_add_users
 }
 
-# fake some info for a list of files to match the format
-# used for contents in the flat registry
-# This list is a 6-tuple of the form:
-# 0: file path
-# 1: uid
-# 2: gid
-# 3: mode
-# 4: size
-# 5: md5 checksum information
-proc portinstall::_fake_fileinfo_for_index {flist} {
-    global 
-	set rval [list]
-	foreach file $flist {
-		lappend rval [list $file [getuid] [getgid] 0644 0 "MD5 ($fname) NONE"]
-	}
-	return $rval
-}
-
 proc portinstall::create_archive {location archive.type} {
     global workpath destpath portpath subport version revision portvariants \
            epoch os.platform PortInfo installPlist \
@@ -317,60 +299,7 @@
 }
 
 proc portinstall::extract_contents {location type} {
-    set qflag ${portutil::autoconf::tar_q}
-    switch -- $type {
-        tbz -
-        tbz2 {
-            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xOj${qflag}f $location ./+CONTENTS]
-        }
-        tgz {
-            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xOz${qflag}f $location ./+CONTENTS]
-        }
-        tar {
-            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xO${qflag}f $location ./+CONTENTS]
-        }
-        txz {
-            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xO${qflag}f $location --use-compress-program [findBinary xz ""] ./+CONTENTS]
-        }
-        tlz {
-            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xO${qflag}f $location --use-compress-program [findBinary lzma ""] ./+CONTENTS]
-        }
-        xar {
-            system "cd ${workpath} && [findBinary xar ${portutil::autoconf::xar_path}] -xf $location +CONTENTS"
-            set twostep 1
-        }
-        zip {
-            set raw_contents [exec [findBinary unzip ${portutil::autoconf::unzip_path}] -p $location +CONTENTS]
-        }
-        cpgz {
-            system "cd ${workpath} && [findBinary pax ${portutil::autoconf::pax_path}] -rzf $location +CONTENTS"
-            set twostep 1
-        }
-        cpio {
-            system "cd ${workpath} && [findBinary pax ${portutil::autoconf::pax_path}] -rf $location +CONTENTS"
-            set twostep 1
-        }
-    }
-    if {[info exists twostep]} {
-        set fd [open "${workpath}/+CONTENTS"]
-        set raw_contents [read $fd]
-        close $fd
-    }
-    set contents {}
-    set ignore 0
-    set sep [file separator]
-    foreach line [split $raw_contents \n] {
-        if {$ignore} {
-            set ignore 0
-            continue
-        }
-        if {[string index $line 0] != "@"} {
-            lappend contents "${sep}${line}"
-        } elseif {$line == "@ignore"} {
-            set ignore 1
-        }
-    }
-    return $contents
+    return [extract_archive_metadata $location $type contents]
 }
 
 proc portinstall::install_main {args} {
@@ -454,32 +383,3 @@
     _cd $oldpwd
     return 0
 }
-
-# apparent usage of pkg_uninstall variable in the (flat) registry
-# the Portfile needs to define a procedure
-# proc pkg_uninstall {portname portver} {
-#     body of proc
-# }
-# which gets stored above in the receipt's pkg_uninstall property
-# this is then called by the portuninstall procedure
-# note that the portuninstall procedure is not called within
-# the context of the portfile so many usual port variables do not exist
-# e.g. destroot/workpath/filespath
- 
-# this procedure encodes the pkg_uninstall body so that it can be stored in the
-# the receipt file
-proc portinstall::proc_disasm {pname} {
-    set p "proc "
-    append p $pname " {"
-    set space ""
-    foreach arg [info args $pname] {
-        if {[info default $pname $arg value]} {
-            append p "$space{" [list $arg $value] "}"
-        } else {
-            append p $space $arg
-        }
-        set space " "
-    }
-    append p "} {" [string map { \n \\n } [info body $pname] ] " }"
-    return $p
-}

Modified: branches/gsoc11-statistics/base/src/port1.0/portlivecheck.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portlivecheck.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port1.0/portlivecheck.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -60,10 +60,10 @@
 default livecheck.ignore_sslcert yes
 
 proc portlivecheck::livecheck_main {args} {
-    global livecheck.url livecheck.type livecheck.md5 livecheck.regex livecheck.name livecheck.distname livecheck.version
-    global livecheck.ignore_sslcert
-    global homepage portpath workpath
-    global master_sites name subport distfiles
+    global livecheck.url livecheck.type livecheck.md5 livecheck.regex livecheck.name livecheck.distname livecheck.version \
+           livecheck.ignore_sslcert \
+           homepage portpath workpath \
+           master_sites name subport distfiles
 
     set updated 0
     set updated_version "unknown"

Modified: branches/gsoc11-statistics/base/src/port1.0/portsandbox.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portsandbox.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port1.0/portsandbox.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -1,7 +1,7 @@
 # -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
 # $Id$
 #
-# Copyright (c) 2012 The MacPorts Project
+# Copyright (c) 2012-2013 The MacPorts Project
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions are
@@ -33,8 +33,9 @@
 namespace eval portsandbox {
 }
 
-options portsandbox_supported portsandbox_profile
+options portsandbox_supported portsandbox_active portsandbox_profile
 default portsandbox_supported {[file executable $portutil::autoconf::sandbox_exec_path]}
+default portsandbox_active {[expr $portsandbox_supported && $sandbox_enable]}
 default portsandbox_profile {}
 
 # set up a suitable profile to pass to sandbox-exec, based on the target

Modified: branches/gsoc11-statistics/base/src/port1.0/portstartupitem.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portstartupitem.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port1.0/portstartupitem.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -64,6 +64,9 @@
 #       - for launchd, generate log messages inside daemondo
 #       - for systemstarter, generate log messages in our generated script
 #
+#   startupitem.autostart   yes/no
+#       Automatically load the startupitem after activating. Defaults to no.
+#
 
 package provide portstartupitem 1.0
 package require portutil 1.0
@@ -74,10 +77,10 @@
 set_ui_prefix
 
 proc portstartupitem::startupitem_create_rcng {args} {
-    global prefix destroot os.platform
-    global startupitem.name startupitem.requires
-    global startupitem.start startupitem.stop startupitem.restart
-    global startupitem.type
+    global prefix destroot os.platform \
+           startupitem.name startupitem.requires \
+           startupitem.start startupitem.stop startupitem.restart \
+           startupitem.type
 
     set scriptdir ${destroot}${prefix}/etc/rc.d
 
@@ -120,10 +123,11 @@
 }
 
 proc portstartupitem::startupitem_create_darwin_systemstarter {args} {
-    global UI_PREFIX prefix destroot destroot.keepdirs subport os.platform
-    global startupitem.name startupitem.requires startupitem.init
-    global startupitem.start startupitem.stop startupitem.restart startupitem.executable
-    global startupitem.pidfile startupitem.logfile startupitem.logevents
+    global UI_PREFIX prefix destroot destroot.keepdirs subport os.platform \
+           startupitem.name startupitem.requires startupitem.init \
+           startupitem.start startupitem.stop startupitem.restart startupitem.executable \
+           startupitem.pidfile startupitem.logfile startupitem.logevents \
+           startupitem.autostart
     
     set scriptdir ${prefix}/etc/startup
     
@@ -385,22 +389,30 @@
     close ${para}
     
     # Emit some information for the user
-    ui_notice "###########################################################"
-    ui_notice "# A startup item has been generated that will aid in"
-    ui_notice "# starting ${subport} with SystemStarter. It is disabled"
-    ui_notice "# by default. Add the following line to /etc/hostconfig"
-    ui_notice "# or ${prefix}/etc/rc.conf to start it at startup:"
-    ui_notice "#"
-    ui_notice "# ${uppername}=-YES-"
-    ui_notice "###########################################################"
+    if {[tbool startupitem.autostart]} {
+        ui_notice "###########################################################"
+        ui_notice "# A startup item has been generated that will aid in"
+        ui_notice "# starting ${subport} with SystemStarter. It will be"
+        ui_notice "# started automatically on activation."
+        ui_notice "###########################################################"
+    } else {
+        ui_notice "###########################################################"
+        ui_notice "# A startup item has been generated that will aid in"
+        ui_notice "# starting ${subport} with SystemStarter. It is disabled"
+        ui_notice "# by default. Add the following line to /etc/hostconfig"
+        ui_notice "# or ${prefix}/etc/rc.conf to start it at startup:"
+        ui_notice "#"
+        ui_notice "# ${uppername}=-YES-"
+        ui_notice "###########################################################"
+    }
 }
 
 proc portstartupitem::startupitem_create_darwin_launchd {args} {
-    global UI_PREFIX prefix destroot destroot.keepdirs subport macosx_deployment_target
-    global startupitem.name startupitem.uniquename startupitem.plist startupitem.location
-    global startupitem.init startupitem.start startupitem.stop startupitem.restart startupitem.executable
-    global startupitem.pidfile startupitem.logfile startupitem.logevents startupitem.netchange
-    global startupitem.install
+    global UI_PREFIX prefix destroot destroot.keepdirs subport macosx_deployment_target \
+           startupitem.name startupitem.uniquename startupitem.plist startupitem.location \
+           startupitem.init startupitem.start startupitem.stop startupitem.restart startupitem.executable \
+           startupitem.pidfile startupitem.logfile startupitem.logevents startupitem.netchange \
+           startupitem.install startupitem.autostart
 
     set scriptdir ${prefix}/etc/startup
     
@@ -621,19 +633,29 @@
     }
     
     # Emit some information for the user
-    ui_notice "###########################################################"
-    ui_notice "# A startup item has been generated that will aid in"
-    ui_notice "# starting ${subport} with launchd. It is disabled"
-    ui_notice "# by default. Execute the following command to start it,"
-    ui_notice "# and to cause it to launch at startup:"
-    ui_notice "#"
-    ui_notice "# sudo port load ${subport}"
-    ui_notice "###########################################################"
+    if {[tbool startupitem.autostart]} {
+        ui_notice "###########################################################"
+        ui_notice "# A startup item has been generated that will aid in"
+        ui_notice "# starting ${subport} with launchd. It will be enabled"
+        ui_notice "# automatically on activation. Execute the following"
+        ui_notice "# command to manually _disable_ it:"
+        ui_notice "#"
+        ui_notice "# sudo port unload ${subport}"
+        ui_notice "###########################################################"
+    } else {
+        ui_notice "###########################################################"
+        ui_notice "# A startup item has been generated that will aid in"
+        ui_notice "# starting ${subport} with launchd. It is disabled"
+        ui_notice "# by default. Execute the following command to start it,"
+        ui_notice "# and to cause it to launch at startup:"
+        ui_notice "#"
+        ui_notice "# sudo port load ${subport}"
+        ui_notice "###########################################################"
+    }
 }
 
 proc portstartupitem::startupitem_create {args} {
-    global UI_PREFIX
-    global startupitem.type os.platform
+    global UI_PREFIX startupitem.type os.platform
     
     set startupitem.type [string tolower ${startupitem.type}]
     

Modified: branches/gsoc11-statistics/base/src/port1.0/porttrace.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/porttrace.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port1.0/porttrace.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -233,8 +233,7 @@
 # Private.
 # Slave method to read a line from the trace.
 proc porttrace::slave_read_line {chan} {
-    global ports_list trace_filemap sandbox_violation_list workpath
-    global env
+    global ports_list trace_filemap sandbox_violation_list workpath env
 
     while 1 {
         # We should never get EOF, actually.

Modified: branches/gsoc11-statistics/base/src/port1.0/portutil.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portutil.tcl	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/src/port1.0/portutil.tcl	2013-06-21 19:46:52 UTC (rev 107206)
@@ -1,5 +1,4 @@
 # -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
-# portutil.tcl
 # $Id$
 #
 # Copyright (c) 2002-2003 Apple Inc.
@@ -258,8 +257,8 @@
 }
 
 ##
-# Mark an option as deprecate
-# If it is set or accessed, it will be mapped it to the new option
+# Mark an option as deprecated
+# If it is set or accessed, it will be mapped to the new option
 #
 # @param option name of the option
 # @param newoption name of a superseding option
@@ -915,7 +914,7 @@
 # reinplace
 # Provides "sed in place" functionality
 proc reinplace {args}  {
-    global env worksrcpath macosx_version
+    global env workpath worksrcpath macosx_version
     set extended 0
     set suppress 0
     set oldlocale_exists 0
@@ -962,12 +961,18 @@
     set pattern [lindex $args 0]
     set files [lrange $args 1 end]
 
+    if {[file isdirectory ${workpath}/.tmp]} {
+        set tempdir ${workpath}/.tmp
+    } else {
+        set tempdir /tmp
+    }
+
     foreach file $files {
         # if $file is an absolute path already, file join will just return the
         # absolute path, otherwise it is $dir/$file
         set file [file join $dir $file]
 
-        if {[catch {set tmpfile [mkstemp "/tmp/[file tail $file].sed.XXXXXXXX"]} error]} {
+        if {[catch {set tmpfile [mkstemp "${tempdir}/[file tail $file].sed.XXXXXXXX"]} error]} {
             global errorInfo
             ui_debug "$errorInfo"
             ui_error "reinplace: $error"
@@ -1828,6 +1833,25 @@
     flush $fd
 }
 
+# Change the value of an existing statefile key
+# caller must call open_statefile after this
+proc update_statefile {class name path} {
+    set fd [open $path r]
+    while {[gets $fd line] >= 0} {
+        if {[lindex $line 0] != "${class}:"} {
+            lappend lines $line
+        }
+    }
+    close $fd
+    # truncate
+    set fd [open $path w]
+    puts $fd "$class: $name"
+    foreach line $lines {
+        puts $fd $line
+    }
+    close $fd
+}
+
 ##
 # Check that recorded selection of variants match the current selection
 #
@@ -2207,8 +2231,7 @@
 }
 
 proc handle_default_variants {option action {value ""}} {
-    global PortInfo
-    global variations
+    global PortInfo variations
     switch -regex $action {
         set|append {
             # Retrieve the information associated with each variant.
@@ -2446,7 +2469,7 @@
 
 # return path to a downloaded or installed archive for this port
 proc find_portarchive_path {} {
-    global portdbpath subport version revision portvariants
+    global portdbpath subport version revision portvariants force_archive_refresh
     set installed 0
     if {[registry_exists $subport $version $revision $portvariants]} {
         set installed 1
@@ -2454,7 +2477,7 @@
     set archiverootname [file rootname [get_portimage_name]]
     foreach unarchive.type [supportedArchiveTypes] {
         set fullarchivename "${archiverootname}.${unarchive.type}"
-        if {$installed} {
+        if {$installed && ![tbool force_archive_refresh]} {
             set fullarchivepath [file join $portdbpath software $subport $fullarchivename]
         } else {
             set fullarchivepath [file join $portdbpath incoming/verified $fullarchivename]
@@ -2533,6 +2556,89 @@
     return -code error [format [msgcat::mc "Unsupported port archive type '%s': %s"] $type $errmsg]
 }
 
+# return the specified piece of metadata from the +CONTENTS file in the given archive
+proc extract_archive_metadata {archive_location archive_type metadata_type} {
+    set qflag ${portutil::autoconf::tar_q}
+    set raw_contents ""
+
+    switch -- $archive_type {
+        xar -
+        cpgz -
+        cpio {
+            set twostep 1
+            global workpath
+            if {[file isdirectory ${workpath}/.tmp]} {
+                set tempdir [mkdtemp ${workpath}/.tmp/portarchiveXXXXXXXX]
+            } else {
+                set tempdir [mkdtemp /tmp/portarchiveXXXXXXXX]
+            }
+        }
+    }
+
+    switch -- $archive_type {
+        tbz -
+        tbz2 {
+            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xOj${qflag}f $archive_location ./+CONTENTS]
+        }
+        tgz {
+            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xOz${qflag}f $archive_location ./+CONTENTS]
+        }
+        tar {
+            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xO${qflag}f $archive_location ./+CONTENTS]
+        }
+        txz {
+            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xO${qflag}f $archive_location --use-compress-program [findBinary xz ""] ./+CONTENTS]
+        }
+        tlz {
+            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xO${qflag}f $archive_location --use-compress-program [findBinary lzma ""] ./+CONTENTS]
+        }
+        xar {
+            system -W ${tempdir} "[findBinary xar ${portutil::autoconf::xar_path}] -xf $archive_location +CONTENTS"
+        }
+        zip {
+            set raw_contents [exec [findBinary unzip ${portutil::autoconf::unzip_path}] -p $archive_location +CONTENTS]
+        }
+        cpgz {
+            system -W ${tempdir} "[findBinary pax ${portutil::autoconf::pax_path}] -rzf $archive_location +CONTENTS"
+        }
+        cpio {
+            system -W ${tempdir} "[findBinary pax ${portutil::autoconf::pax_path}] -rf $archive_location +CONTENTS"
+        }
+    }
+    if {[info exists twostep]} {
+        set fd [open "${tempdir}/+CONTENTS"]
+        set raw_contents [read $fd]
+        close $fd
+        file delete -force $tempdir
+    }
+    if {$metadata_type == "contents"} {
+        set contents {}
+        set ignore 0
+        set sep [file separator]
+        foreach line [split $raw_contents \n] {
+            if {$ignore} {
+                set ignore 0
+                continue
+            }
+            if {[string index $line 0] != "@"} {
+                lappend contents "${sep}${line}"
+            } elseif {$line == "@ignore"} {
+                set ignore 1
+            }
+        }
+        return $contents
+    } elseif {$metadata_type == "portname"} {
+        foreach line [split $raw_contents \n] {
+            if {[lindex $line 0] == "@portname"} {
+                return [lindex $line 1]
+            }
+        }
+        return ""
+    } else {
+        return -code error "unknown metadata_type: $metadata_type"
+    }
+}
+
 #
 # merge function for universal builds
 #
@@ -2952,12 +3058,12 @@
             10.7 {
                 set min 4.1
                 set ok 4.1
-                set rec 4.5.2
+                set rec 4.6.2
             }
             default {
                 set min 4.4
                 set ok 4.4
-                set rec 4.5.2
+                set rec 4.6.2
             }
         }
         if {$xcodeversion == "none"} {

Modified: branches/gsoc11-statistics/base/tests/test/trace/Makefile
===================================================================
--- branches/gsoc11-statistics/base/tests/test/trace/Makefile	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/tests/test/trace/Makefile	2013-06-21 19:46:52 UTC (rev 107206)
@@ -17,7 +17,7 @@
 	@rm -f /tmp/hello-trace
 	@rm -f link-trace
 	@ln -s /usr/include/unistd.h /tmp/link-trace2
-	@PORTSRC=$(PORTSRC) $(bindir)/port -t test > output 2>&1 || (cat output; exit 1)
+	@-PORTSRC=$(PORTSRC) $(bindir)/port -t test > output 2>&1 || (cat output; exit 1)
 	@rm -f link-trace
 	@rm -f /tmp/link-trace2
 	@rm -f delete-trace

Modified: branches/gsoc11-statistics/base/tests/test/xcodeversion/Portfile
===================================================================
--- branches/gsoc11-statistics/base/tests/test/xcodeversion/Portfile	2013-06-21 15:36:38 UTC (rev 107205)
+++ branches/gsoc11-statistics/base/tests/test/xcodeversion/Portfile	2013-06-21 19:46:52 UTC (rev 107206)
@@ -21,7 +21,7 @@
 test {
     # rpm-vercomp is now deprecated, change it here too when removed
     # from all ports and base (but keep this test here, meanwhile...)
-    # rpm-vercomp removed from ports r89810, from base r89911
+    # rpm-vercomp removed from ports r89810, from base r89811
     if {$xcodeversion != "" && [vercmp $xcodeversion 2.1] >= 0} {
         ui_msg "xcodeversion >= 2.1"
     } else {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20130621/09d2ca95/attachment-0001.html>


More information about the macports-changes mailing list