Commits

Anonymous committed 5847c3a

* Fixed most remaining Code Sniff errors & warnings.

Comments (0)

Files changed (14)

Trunk/VersionControl/Hg.php

  * valid repository will raise an exception.
  *
  * PHP version 5
+ *
  * @category  VersionControl
  * @package   Hg
  * @author    Michael Gatto <mgatto@lisantra.com>

Trunk/VersionControl/Hg/Command/Abstract.php

      * Class constructors must be redefined in each Command parent class,
      * since it must have its dependencies for $hg injected.
      *
-     * @param mixed $params The options and arguments passed to the command
+     * @param mixed             $params Options passed to the command
+     * @param VersionControl_Hg $hg     Instance of the base object
      *
      * @return void
      */
            has no parameters */
         switch ($method) {
             case 'run': //the special method ending the fluent chain
-                /* run the command class' execute method */
+                /* run the command class' execute method
+                 * interface demands all command classes define this method
+                 */
                 return $this->execute($arguments);
-                //interface demands all command classes define this method
-                /*alternative:
-                 return call_user_func_array(array($command, 'execute'), $options);
-                 */
+
                 break;
             default:
                 /* must be the command or one of its fluent api functions */
                 if ( method_exists($this, $method) ) {
-                /* is it a method of the currently instantiated command? */
+                    /* is it a method of the currently instantiated command? */
                     return call_user_func_array(array($this, $method), $arguments);
                 } else {
-                /* an optional method is not defined in the command class */
+                    /* an optional method is not defined in the command class */
                     throw new VersionControl_Hg_Command_Exception(
                         "This method '{$method}' does not exist in this class"
                     );
      * Get a named options from the current list of options
      *
      * @param string $name The name of the option we are getting
+     *
+     * @return string
      */
-    public function getOption($name) {
+    public function getOption($name)
+    {
         $value = null;
 
         /* with 'files', sometimes it may not exist when called for */

Trunk/VersionControl/Hg/Command/Archive.php

     /**
      * Constructor
      *
-     * @param mixed $params are the data values passed to the command
+     * @param mixed             $params Data values passed to the command
+     * @param VersionControl_Hg $hg     Instance of the base object
      *
      * @return void
      */
     }
 
     /**
-     * (non-PHPdoc)
-     * @see VersionControl/Hg/Command/VersionControl_Hg_Command_Interface#execute($params)
+     * Execute the command and return the results.
+     *
+     * @param mixed             $params Options passed to the Log command
+     * @param VersionControl_Hg $hg     Instance of the base object
+     *
+     * @return string
      */
-    public function execute(array $params = null)
+    public function execute(array $params = null, VersionControl_Hg $hg)
     {
         /* take care of options passed in as such:
          * $hg->archive(array('revision' => 'tip', 'to' => realpath('../')));

Trunk/VersionControl/Hg/Command/Cat.php

 require_once 'Exception.php';
 
 /**
+ * Provides an output formatter
+ */
+require_once 'Output/Formatter.php';
+
+/**
  * Print the contents of a file from a specific revision
  *
  * Usage:
         'save' => null,
         'to' => null,
         'revision' => null,
+        'rev' => null,
         'output' => null,
     );
 
     /**
      * Constructor
      *
+     * @param mixed             $params One or more parameters to modify the command
      * @param VersionControl_Hg $hg     The base Hg instance
-     * @param mixed             $params One or more parameters to modify the command
      *
      * @return void
      */
-    public function __construct(VersionControl_Hg $hg, $params = null)
+    public function __construct($params = null, VersionControl_Hg $hg)
     {
         $this->hg = $hg;
 
 
         /* We handle the actual param handling here, since we only expect
          * 1 or more file names. */
-        if ( is_array($params) ) {
-            $this->addOption('files', join(' ', $params));
-        } elseif ( is_scalar($params) ) {
-            $this->addOption('files', $params);
-        } elseif ( is_null($params) ) {
+        if ( is_array($params[0]) ) {
+            $this->addOption('files', join(' ', $params[0]));
+        } elseif ( is_scalar($params[0]) ) {
+            $this->addOption('files', $params[0]);
+        } elseif ( is_null($params[0]) ) {
             //throw an exception
-        }
+        } /* Note: $params is always an array with key [0] since we use
+           * call_user_func_array() */
     }
 
     /**
             );
         }
 
-        /*return $this->parseOutput(
-            $this->output,
-            array('rev', 'branch', 'files', 'datetime', 'author', 'description'),
-            '##'
-        );*/
-
-        return $this->output;
+        return VersionControl_Hg_Command_Output_Formatter::toRaw($this->output);
     }
 
     /**

Trunk/VersionControl/Hg/Command/Clone.php

-<?php
-/**
- * Contains the definition of the VersionControl_Hg_Repository_Command_Clone
- * class
- *
- * PHP version 5
- *
- * @category   VersionControl
- * @package    Hg
- * @subpackage Command
- * @author     Michael Gatto <mgatto@lisantra.com>
- * @copyright  2011 Lisantra Technologies, LLC
- * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
- * @link       http://pear.php.net/package/VersionControl_Hg
- */
-
-/**
- * Provides the required interface for all commands
- */
-require_once 'Interface.php';
-
-/**
- * Provides base functionality common to all commands
- */
-require_once 'Abstract.php';
-
-/**
- * Provides Exceptions for commands (VersionControl_Hg_Command_Exception)
- */
-require_once 'Exception.php';
-
-/**
- * Clone a repository to a destination
- *
- * Usage:
- * <code>
- * $hg = new VersionControl_Hg('/path/to/repo');
- * $hg->clone('http://url/to/repo')->to('/path/to/clone')->run();
- * </code>
- *
- * NOTES
- * Should return the object representing the cloned repository as
- * type: VersionControl_Hg_Container_Repository.
- *
- * Should check if new location for cloned repo exists or not, and/or is
- * empty same as Init.php does.
- *
- * PHP version 5
- *
- * @category   VersionControl
- * @package    Hg
- * @subpackage Command
- * @author     Michael Gatto <mgatto@lisantra.com>
- * @copyright  2011 Lisantra Technologies, LLC
- * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
- * @link       http://pear.php.net/package/VersionControl_Hg
- */
-class VersionControl_Hg_Command_Clone
-    extends VersionControl_Hg_Command_Abstract
-        implements VersionControl_Hg_Command_Interface
-{
-   /**
-     * The name of the mercurial command implemented here
-     *
-     * @var string
-     */
-    protected $command = 'clone';
-
-    /**
-     * Required options for this specific command. These may not be required
-     * by Mercurial itself, but are required for the proper functioning of
-     * this package.
-     *
-     * @var mixed
-     */
-    protected $required_options = array(
-        'noninteractive' => null,
-        //'repository' => null,
-        'files' => null,
-    );
-
-    /**
-     * Permissable options.
-     *
-     * The actual option must be the key, while 'null' is a value here to
-     * accommodate the current implementation of setting options.
-     *
-     * @var mixed
-     */
-    protected $allowed_options = array(
-        /* --pull is used for safety since HG automatically uses hardlinks for
-         repo data, although on some fs's, its not safe (eg. AFS) */
-        'pull' => null,
-        'sparse' => null,
-        'rev' => null,
-        'branch' => null,
-    );
-
-    /**
-     * The path in which Mercurial will create the new repository
-     *
-     * @var string
-     */
-    protected $cloned_path;
-
-    /**
-     * Constructor
-     *
-     * This may be empty if
-     *
-     * @param mixed $params is one or more parameters to modify the command
-     *
-     * @return void
-     */
-    public function __construct($params = null, VersionControl_Hg $hg)
-    {
-        $this->hg = $hg;
-
-        /* check if a repository has been designated already or not */
-        $cloned_path = $this->hg->repository->getPath();
-
-        if ( empty($cloned_path) ) {
-            /* are the argument(s) correctly formed? */
-            if ( (array_key_exists(0, $params)) && (! empty($params[0])) ) {
-                /* if its an array, check for the 'repository' key */
-                if ( (is_array($params[0])) && (! array_key_exists('repository', $params[0])) ) {
-                    throw new VersionControl_Hg_Command_Exception(
-                        VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
-                        "The repository must be defined either at
-                         instantiation, as a string path arugment to clone()
-                         or as the 'repository' key in an array of options."
-                    );
-
-                    /* should always be called so we have a full array of valid options */
-                    $this->setOptions($params);
-                } elseif ( is_scalar($params[0])) {
-                    /* if scalar, we have to assume its a path */
-                    /* This is a psuedo-hack because init has no arugment prefix;
-                     * our current inmplementation of 'files' doesn't give one = cool! */
-                    $this->repository($params[0]);
-                }
-            }
-        } else {
-            /* should always be called so we have a full array of valid options */
-            $this->setOptions($params);
-        }
-    }
-
-    /**
-     * Execute the command and return the results.
-     *
-     * @param mixed $params The options passed to the Log command
-     *
-     * @return string
-     */
-    public function execute(array $params = null)
-    {
-        /* Validate */
-        $files = $this->getOption('files');
-        /* the destination of the cloned repo must be index 1 */
-        $cloned_path = $files[1];
-
-        if (! $this->directory_exists($cloned_path) ) {
-            /* kill any umasks. */
-            //@TODO remove since it causes problems on multithreaded servers
-            //umask(0);
-
-            //refuse bad fs names
-            //$except = array('\\', '/', ':', '*', '?', '"', '<', '>', '|');
-
-            //Please note that when specifying the recursive option the function returns false anyway if the directory already exists.
-            //Octal permissions are ignored on Windows
-            if (! mkdir($cloned_path, 0755, true) ) {
-                throw new VersionControl_Hg_Command_Exception(
-                    VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
-                    "PHP encountered an error while trying to create the
-                     directory '{$cloned_path}'. "
-                );
-            }
-
-            /* This works around some umask issues */
-            chmod($cloned_path, 0755);
-        } //clearstatcache()
-
-        if ( ! is_writable($cloned_path) ) {
-            throw new VersionControl_Hg_Command_Exception(
-                VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
-                "The directory '{$cloned_path}' is not writable, but must be. "
-            );
-        }
-
-        if ( ! $this->directory_is_empty($cloned_path) ) {
-            throw new VersionControl_Hg_Command_Exception(
-                VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
-                "The directory '{$cloned_path}' is not empty, but must be. "
-            );
-        }
-
-        /* take care of options passed into run() as such:
-         * $hg->clone('/path/')->run('verbose'));
-         */
-        if ( ! empty($params) ) {
-            $this->setOptions($params);
-        }
-
-        /* --noninteractive is required since issuing the command is
-         * unattended by nature of using this package.
-        */
-        $this->addOptions(
-            array(
-                'noninteractive' => null,
-            )
-        );
-
-        /* Despite its being so not variable, we need to set the command string
-         * only after manually setting options and other command-specific data */
-        $this->setCommandString();
-
-        /* no var assignment, since 2nd param holds output */
-        exec($this->command_string, $this->output, $this->status);
-
-        if ( $this->status !== 0 ) {
-            throw new VersionControl_Hg_Command_Exception(
-                VersionControl_Hg_Command_Exception::COMMANDLINE_ERROR
-            );
-        }
-        $repository = VersionControl_Hg_Container_Repository::getInstance();
-        $repository->setPath($cloned_path);
-
-        return $this->hg->repository;
-    }
-
-    /**
-     * Tells Mercurial to use the pull functionality to copy metadata.
-     */
-    public function pull() {
-        $this->addOption('pull', null);
-
-        /* For the fluent API */
-        return $this;
-    }
-
-    /**
-     * Tells Mercurial to not create a working copy.
-     */
-    public function sparse() {
-        $this->addOption('noupdate', null);
-
-        /* For the fluent API */
-        return $this;
-    }
-
-    /**
-     * Tells Mercurial to not create a working copy.
-     */
-    public function to($cloned_path) {
-        $files = $this->getOption('files');
-
-        /* the repository to clone MUST be the first files item */
-        $files[1] = $cloned_path;
-        $this->addOption('files', $files);
-
-        /* For the fluent API */
-        return $this;
-    }
-
-    /**
-     * Tells Mercurial to not create a working copy.
-     */
-    public function repository($path) {
-        $files = $this->getOption('files');
-
-        /* the repository to clone MUST be the first files item */
-        $files[0] = $path;
-        $this->addOption('files', $files);
-
-        /* For the fluent API */
-        return $this;
-    }
-
-    /**
-     * Confirm that the path exists
-     *
-     * @param string $cloned_path The path the repository should be created at
-     *
-     * @return boolean
-     */
-    protected function directory_exists($path)
-    {
-        $directory_exists = true;
-
-        if (! is_dir($path) ) {
-            //So, is it a file? Do we care?
-
-            $directory_exists = false;
-        }
-
-        /* for the fluent API */
-        return $directory_exists;
-    }
-
-    /**
-     * Confirm that the path exists
-     *
-     * @param string $cloned_path The path the repository should be created at
-     *
-     * @return boolean
-     */
-    protected function directory_is_empty($path)
-    {
-        $directory_is_empty = true;
-
-        $files_in_dir = scandir($path);
-
-        /* ccount for . and .. */
-        if ( count($files_in_dir) > 2 ) {
-            $directory_is_empty = false;
-        }
-
-        /* for the fluent API */
-        return $directory_is_empty;
-    }
-
-    /**
-     * Specifies the revision to restrict the clone operation to
-      *
-     * Usage:
-     * <code>$hg->clone()->revision(7)->run();</code>
-     * or
-     * <code>$hg->clone()->revision('cde1256adc443a3')->run();</code>
-     * or
-     * <code>$hg->clone(array('revision' => 7 ))->to('/path/to)->run();</code>
-     *
-     * @param string $revision is the optional revision to archive
-     *
-     * @return void
-     */
-    public function revision($revision = 'tip')
-    {
-        /* Technically, this shouldn't occur since 'tip' is default */
-        if ( empty($revision)) {
-            throw new VersionControl_Hg_Command_Exception(
-                VersionControl_Hg_Command_Exception::BAD_ARGUMENT
-            );
-        }
-
-        $this->addOption('rev', $revision);
-
-        /* for the fluent API */
-        return $this;
-    }
-
-}
+<?php
+/**
+ * Contains the definition of the VersionControl_Hg_Repository_Command_Clone
+ * class
+ *
+ * PHP version 5
+ *
+ * @category   VersionControl
+ * @package    Hg
+ * @subpackage Command
+ * @author     Michael Gatto <mgatto@lisantra.com>
+ * @copyright  2011 Lisantra Technologies, LLC
+ * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
+ * @link       http://pear.php.net/package/VersionControl_Hg
+ */
+
+/**
+ * Provides the required interface for all commands
+ */
+require_once 'Interface.php';
+
+/**
+ * Provides base functionality common to all commands
+ */
+require_once 'Abstract.php';
+
+/**
+ * Provides Exceptions for commands (VersionControl_Hg_Command_Exception)
+ */
+require_once 'Exception.php';
+
+/**
+ * Clone a repository to a destination
+ *
+ * Usage:
+ * <code>
+ * $hg = new VersionControl_Hg('/path/to/repo');
+ * $hg->clone('http://url/to/repo')->to('/path/to/clone')->run();
+ * </code>
+ *
+ * NOTES
+ * Should return the object representing the cloned repository as
+ * type: VersionControl_Hg_Container_Repository.
+ *
+ * Should check if new location for cloned repo exists or not, and/or is
+ * empty same as Init.php does.
+ *
+ * PHP version 5
+ *
+ * @category   VersionControl
+ * @package    Hg
+ * @subpackage Command
+ * @author     Michael Gatto <mgatto@lisantra.com>
+ * @copyright  2011 Lisantra Technologies, LLC
+ * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
+ * @link       http://pear.php.net/package/VersionControl_Hg
+ */
+class VersionControl_Hg_Command_Clone
+    extends VersionControl_Hg_Command_Abstract
+        implements VersionControl_Hg_Command_Interface
+{
+    /**
+     * The name of the mercurial command implemented here
+     *
+     * @var string
+     */
+    protected $command = 'clone';
+
+    /**
+     * Required options for this specific command. These may not be required
+     * by Mercurial itself, but are required for the proper functioning of
+     * this package.
+     *
+     * @var mixed
+     */
+    protected $required_options = array(
+        'noninteractive' => null,
+        //'repository' => null,
+        'files' => null,
+    );
+
+    /**
+     * Permissable options.
+     *
+     * The actual option must be the key, while 'null' is a value here to
+     * accommodate the current implementation of setting options.
+     *
+     * @var mixed
+     */
+    protected $allowed_options = array(
+        /* --pull is used for safety since HG automatically uses hardlinks for
+         repo data, although on some fs's, its not safe (eg. AFS) */
+        'pull' => null,
+        'sparse' => null,
+        'rev' => null,
+        'branch' => null,
+    );
+
+    /**
+     * The path in which Mercurial will create the new repository
+     *
+     * @var string
+     */
+    protected $cloned_path;
+
+    /**
+     * Constructor
+     *
+     * @param mixed             $params One or more parameters to the command
+     * @param VersionControl_Hg $hg     Instance of the base object
+     *
+     * @return void
+     */
+    public function __construct($params = null, VersionControl_Hg $hg)
+    {
+        $this->hg = $hg;
+
+        /* check if a repository has been designated already or not */
+        $cloned_path = $this->hg->repository->getPath();
+
+        if ( empty($cloned_path) ) {
+            /* are the argument(s) correctly formed? */
+            if ( (array_key_exists(0, $params)) && (! empty($params[0])) ) {
+                /* if its an array, check for the 'repository' key */
+                if ( (is_array($params[0]))
+                    && (! array_key_exists('repository', $params[0]))
+                ) {
+                    throw new VersionControl_Hg_Command_Exception(
+                        VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
+                        "The repository must be defined either at
+                         instantiation, as a string path arugment to clone()
+                         or as the 'repository' key in an array of options."
+                    );
+
+                    /* should always be called so we have a full array of
+                     * valid options */
+                    $this->setOptions($params);
+                } elseif ( is_scalar($params[0])) {
+                    /* if scalar, we have to assume its a path */
+                    /* This is a psuedo-hack because init has no arugment prefix;
+                     * our current inmplementation of 'files' doesn't give
+                     * one = cool! */
+                    $this->repository($params[0]);
+                }
+            }
+        } else {
+            /* should always be called so we have a full array of valid options */
+            $this->setOptions($params);
+        }
+    }
+
+    /**
+     * Execute the command and return the results.
+     *
+     * @param mixed             $params Options passed to the Log command
+     * @param VersionControl_Hg $hg     Instance of the base object
+     *
+     * @return string
+     */
+    public function execute(array $params = null, VersionControl_Hg $hg)
+    {
+        /* Validate */
+        $files = $this->getOption('files');
+        /* the destination of the cloned repo must be index 1 */
+        $cloned_path = $files[1];
+
+        if (! $this->directory_exists($cloned_path) ) {
+            /* kill any umasks. */
+            //@TODO remove since it causes problems on multithreaded servers
+            //umask(0);
+
+            //refuse bad fs names
+            //$except = array('\\', '/', ':', '*', '?', '"', '<', '>', '|');
+
+            //Please note that when specifying the recursive option the
+            // function returns false anyway if the directory already exists.
+            //Octal permissions are ignored on Windows
+            if (! mkdir($cloned_path, 0755, true) ) {
+                throw new VersionControl_Hg_Command_Exception(
+                    VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
+                    "PHP encountered an error while trying to create the
+                     directory '{$cloned_path}'. "
+                );
+            }
+
+            /* This works around some umask issues */
+            chmod($cloned_path, 0755);
+        } //clearstatcache()
+
+        if ( ! is_writable($cloned_path) ) {
+            throw new VersionControl_Hg_Command_Exception(
+                VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
+                "The directory '{$cloned_path}' is not writable, but must be. "
+            );
+        }
+
+        if ( ! $this->directory_is_empty($cloned_path) ) {
+            throw new VersionControl_Hg_Command_Exception(
+                VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
+                "The directory '{$cloned_path}' is not empty, but must be. "
+            );
+        }
+
+        /* take care of options passed into run() as such:
+         * $hg->clone('/path/')->run('verbose'));
+         */
+        if ( ! empty($params) ) {
+            $this->setOptions($params);
+        }
+
+        /* --noninteractive is required since issuing the command is
+         * unattended by nature of using this package.
+        */
+        $this->addOptions(
+            array(
+                'noninteractive' => null,
+            )
+        );
+
+        /* Despite its being so not variable, we need to set the command string
+         * only after manually setting options and other command-specific data */
+        $this->setCommandString();
+
+        /* no var assignment, since 2nd param holds output */
+        exec($this->command_string, $this->output, $this->status);
+
+        if ( $this->status !== 0 ) {
+            throw new VersionControl_Hg_Command_Exception(
+                VersionControl_Hg_Command_Exception::COMMANDLINE_ERROR
+            );
+        }
+        $repository = VersionControl_Hg_Container_Repository::getInstance();
+        $repository->setPath($cloned_path);
+
+        return $this->hg->repository;
+    }
+
+    /**
+     * Tells Mercurial to use the pull functionality to copy metadata.
+     *
+     * @return VersionControl_Hg_Command_Abstract
+     */
+    public function pull()
+    {
+        $this->addOption('pull', null);
+
+        /* For the fluent API */
+        return $this;
+    }
+
+    /**
+     * Tells Mercurial to not create a working copy.
+     *
+     * @return VersionControl_Hg_Command_Abstract
+     */
+    public function sparse()
+    {
+        $this->addOption('noupdate', null);
+
+        /* For the fluent API */
+        return $this;
+    }
+
+    /**
+     * Tells Mercurial to not create a working copy.
+     *
+     * @param string $path Destination of the clone operation
+     *
+     * @return VersionControl_Hg_Command_Abstract
+     */
+    public function to($path)
+    {
+        $files = $this->getOption('files');
+
+        /* the repository to clone MUST be the first files item */
+        $files[1] = $path;
+        $this->addOption('files', $files);
+
+        /* For the fluent API */
+        return $this;
+    }
+
+    /**
+     * Tells Mercurial to not create a working copy.
+     *
+     * @param string $path Destination of the clone operation
+     *
+     * @return VersionControl_Hg_Command_Abstract
+     */
+    public function repository($path)
+    {
+        $files = $this->getOption('files');
+
+        /* the repository to clone MUST be the first files item */
+        $files[0] = $path;
+        $this->addOption('files', $files);
+
+        /* For the fluent API */
+        return $this;
+    }
+
+    /**
+     * Confirm that the path exists
+     *
+     * @param string $path The path the repository should be created at
+     *
+     * @return boolean
+     */
+    protected function directory_exists($path)
+    {
+        $directory_exists = true;
+
+        if (! is_dir($path) ) {
+            //So, is it a file? Do we care?
+
+            $directory_exists = false;
+        }
+
+        /* for the fluent API */
+        return $directory_exists;
+    }
+
+    /**
+     * Confirm that the path exists
+     *
+     * @param string $path The path the repository should be created at
+     *
+     * @return boolean
+     */
+    protected function directory_is_empty($path)
+    {
+        $directory_is_empty = true;
+
+        $files_in_dir = scandir($path);
+
+        /* ccount for . and .. */
+        if ( count($files_in_dir) > 2 ) {
+            $directory_is_empty = false;
+        }
+
+        /* for the fluent API */
+        return $directory_is_empty;
+    }
+
+    /**
+     * Specifies the revision to restrict the clone operation to
+      *
+     * Usage:
+     * <code>$hg->clone()->revision(7)->run();</code>
+     * or
+     * <code>$hg->clone()->revision('cde1256adc443a3')->run();</code>
+     * or
+     * <code>$hg->clone(array('revision' => 7 ))->to('/path/to)->run();</code>
+     *
+     * @param string $revision is the optional revision to archive
+     *
+     * @return void
+     */
+    public function revision($revision = 'tip')
+    {
+        /* Technically, this shouldn't occur since 'tip' is default */
+        if ( empty($revision)) {
+            throw new VersionControl_Hg_Command_Exception(
+                VersionControl_Hg_Command_Exception::BAD_ARGUMENT
+            );
+        }
+
+        $this->addOption('rev', $revision);
+
+        /* for the fluent API */
+        return $this;
+    }
+
+}

Trunk/VersionControl/Hg/Command/Init.php

-<?php
-/**
- * Contains the definition of the VersionControl_Hg_Repository_Command_Init
- * class
- *
- * PHP version 5
- *
- * @category   VersionControl
- * @package    Hg
- * @subpackage Command
- * @author     Michael Gatto <mgatto@lisantra.com>
- * @copyright  2011 Lisantra Technologies, LLC
- * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
- * @link       http://pear.php.net/package/VersionControl_Hg
- */
-
-/**
- * Provides the required interface for all commands
- */
-require_once 'Interface.php';
-
-/**
- * Provides base functionality common to all commands
- */
-require_once 'Abstract.php';
-
-/**
- * Provides Exceptions for commands (VersionControl_Hg_Command_Exception)
- */
-require_once 'Exception.php';
-
-/**
- * Exports repository to a (optionally compressed) archive file.
- *
- * Usage:
- * <code>
- * $hg->init('path/to/new/repo')->run();
- * </code>
- *
- * PHP version 5
- *
- * @category   VersionControl
- * @package    Hg
- * @subpackage Command
- * @author     Michael Gatto <mgatto@lisantra.com>
- * @copyright  2011 Lisantra Technologies, LLC
- * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
- * @link       http://pear.php.net/package/VersionControl_Hg
- */
-class VersionControl_Hg_Command_Init
-    extends VersionControl_Hg_Command_Abstract
-        implements VersionControl_Hg_Command_Interface
-{
-    /**
-     * The name of the mercurial command implemented here
-     *
-     * @var string
-     */
-    protected $command = 'init';
-
-    /**
-     * The path in which Mercurial will create the new repository
-     *
-     * @var string
-     */
-    protected $path;
-
-    /**
-     * Required options this command needs
-     *
-     * destination is always variable
-     *
-     * @var mixed
-     */
-    protected $required_options = array(
-        'noninteractive' => null,
-        'files' => null,
-    );
-
-    /**
-     * Possible options this command may have
-     *
-     * None, so far.
-     *
-     * @var mixed
-     */
-    protected $allowed_options = array();
-
-    /**
-     * Constructor
-     *
-     * @param mixed $params are the data values passed to the command
-     *
-     * @return void
-     */
-    public function __construct($params = null, VersionControl_Hg $hg)
-    {
-        $this->hg = $hg;
-
-        /* check if a repository has been designated already or not */
-        $path = $this->hg->repository->getPath();
-
-        if ( empty($path) ) {
-            /* are the argument(s) correctly formed? */
-            if ( (array_key_exists(0, $params)) && (! empty($params[0])) ) {
-                /* if its an array, check for the 'repository' key */
-                if ( (is_array($params[0])) && (! array_key_exists('repository', $params[0])) ) {
-                    throw new VersionControl_Hg_Command_Exception(
-                        VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
-                        "The repository must be defined either at
-                         instantiation, as a string path arugment to clone()
-                         or as the 'repository' key in an array of options."
-                    );
-
-                    /* should always be called so we have a full array of valid options */
-                    $this->setOptions($params);
-                } elseif ( is_scalar($params[0])) {
-                    /* if scalar, we have to assume its a path */
-                    /* This is a psuedo-hack because init has no arugment prefix;
-                     * our current inmplementation of 'files' doesn't give one = cool! */
-                    $this->addOption('files', $params[0]);
-                }
-            }
-        } else {
-            /* should always be called so we have a full array of valid options */
-            $this->setOptions($params);
-        }
-    }
-
-    /**
-     *
-     * params are passed from run()
-     *
-     * (non-PHPdoc)
-     * @see VersionControl/Hg/Command/VersionControl_Hg_Command_Interface#execute($params)
-     */
-    public function execute(array $params = null)
-    {
-        /* Validate */
-        $path = $this->getOption('files');
-
-        if (! $this->directory_exists($path) ) {
-            /* kill any umasks. */
-            //@TODO remove since it causes problems on multithreaded servers
-            //umask(0);
-
-            //refuse bad fs names
-            //$except = array('\\', '/', ':', '*', '?', '"', '<', '>', '|');
-
-            //Please note that when specifying the recursive option the function returns false anyway if the directory already exists.
-            //Octal permissions are ignored on Windows
-            if (! mkdir($path, 0755, true) ) {
-                throw new VersionControl_Hg_Command_Exception(
-                    VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
-                    "PHP encountered an error while trying to create the
-                     directory '{$path}'. "
-                );
-            }
-
-            /* This works around some umask issues */
-            chmod($path, 0755);
-        } //clearstatcache()
-
-        if ( ! is_writable($path) ) {
-            throw new VersionControl_Hg_Command_Exception(
-                VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
-                "The directory '{$path}' is not writable, but must be. "
-            );
-        }
-
-        if ( ! $this->directory_is_empty($path) ) {
-            throw new VersionControl_Hg_Command_Exception(
-                VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
-                "The directory '{$path}' is not empty, but must be. "
-            );
-        }
-
-        /* take care of options passed in as such:
-         * $hg->init('/path/')->run('verbose'));
-         */
-        if ( ! empty($params) ) {
-            $this->setOptions($params);
-        }
-
-        /* --noninteractive is required since issuing the command is
-         * unattended by nature of using this package.
-        */
-        $this->addOptions(
-            array(
-                'noninteractive' => null,
-                //'repository' => $this->path,
-            )
-        );
-
-        /* Despite its being so not variable, we need to set the command string
-         * only after manually setting options and other command-specific data */
-        $this->setCommandString();
-
-        /* no var assignment, since 2nd param holds output */
-        exec($this->command_string, $this->output, $this->status);
-
-        if ( $this->status !== 0 ) {
-            throw new VersionControl_Hg_Command_Exception(
-                VersionControl_Hg_Command_Exception::COMMANDLINE_ERROR
-            );
-        }
-        $repository = VersionControl_Hg_Container_Repository::getInstance();
-        $repository->setPath($path);
-
-        return $this->hg->repository;
-    }
-
-    /**
-     * Confirm that the path exists
-     *
-     * @param string $path The path the repository should be created at
-     *
-     * @return boolean
-     */
-    protected function directory_exists($path)
-    {
-        $directory_exists = true;
-
-        if (! is_dir($path) ) {
-            //So, is it a file? Do we care?
-
-            $directory_exists = false;
-        }
-
-        /* for the fluent API */
-        return $directory_exists;
-    }
-
-    /**
-     * Confirm that the path exists
-     *
-     * @param string $path The path the repository should be created at
-     *
-     * @return boolean
-     */
-    protected function directory_is_empty($path)
-    {
-        $directory_is_empty = true;
-
-        $files_in_dir = scandir($path);
-
-        /* ccount for . and .. */
-        if ( count($files_in_dir) > 2 ) {
-            $directory_is_empty = false;
-        }
-
-        /* for the fluent API */
-        return $directory_is_empty;
-    }
-
-}
+<?php
+/**
+ * Contains the definition of the VersionControl_Hg_Repository_Command_Init
+ * class
+ *
+ * PHP version 5
+ *
+ * @category   VersionControl
+ * @package    Hg
+ * @subpackage Command
+ * @author     Michael Gatto <mgatto@lisantra.com>
+ * @copyright  2011 Lisantra Technologies, LLC
+ * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
+ * @link       http://pear.php.net/package/VersionControl_Hg
+ */
+
+/**
+ * Provides the required interface for all commands
+ */
+require_once 'Interface.php';
+
+/**
+ * Provides base functionality common to all commands
+ */
+require_once 'Abstract.php';
+
+/**
+ * Provides Exceptions for commands (VersionControl_Hg_Command_Exception)
+ */
+require_once 'Exception.php';
+
+/**
+ * Exports repository to a (optionally compressed) archive file.
+ *
+ * Usage:
+ * <code>
+ * $hg->init('path/to/new/repo')->run();
+ * </code>
+ *
+ * PHP version 5
+ *
+ * @category   VersionControl
+ * @package    Hg
+ * @subpackage Command
+ * @author     Michael Gatto <mgatto@lisantra.com>
+ * @copyright  2011 Lisantra Technologies, LLC
+ * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
+ * @link       http://pear.php.net/package/VersionControl_Hg
+ */
+class VersionControl_Hg_Command_Init
+    extends VersionControl_Hg_Command_Abstract
+        implements VersionControl_Hg_Command_Interface
+{
+    /**
+     * The name of the mercurial command implemented here
+     *
+     * @var string
+     */
+    protected $command = 'init';
+
+    /**
+     * The path in which Mercurial will create the new repository
+     *
+     * @var string
+     */
+    protected $path;
+
+    /**
+     * Required options this command needs
+     *
+     * destination is always variable
+     *
+     * @var mixed
+     */
+    protected $required_options = array(
+        'noninteractive' => null,
+        'files' => null,
+    );
+
+    /**
+     * Possible options this command may have
+     *
+     * None, so far.
+     *
+     * @var mixed
+     */
+    protected $allowed_options = array();
+
+    /**
+     * Constructor
+     *
+     * @param mixed             $params Data passed to the command
+     * @param VersionControl_Hg $hg     Instance of the base object
+     *
+     * @return void
+     */
+    public function __construct($params = null, VersionControl_Hg $hg)
+    {
+        $this->hg = $hg;
+
+        /* check if a repository has been designated already or not */
+        $path = $this->hg->repository->getPath();
+
+        if ( empty($path) ) {
+            /* are the argument(s) correctly formed? */
+            if ( (array_key_exists(0, $params))
+                && (! empty($params[0]))
+            ) {
+                /* if its an array, check for the 'repository' key */
+                if ( (is_array($params[0]))
+                    && (! array_key_exists('repository', $params[0]))
+                ) {
+                    throw new VersionControl_Hg_Command_Exception(
+                        VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
+                        "The repository must be defined either at
+                         instantiation, as a string path arugment to clone()
+                         or as the 'repository' key in an array of options."
+                    );
+
+                    /* should always be called so we have a full array of
+                     * valid options */
+                    $this->setOptions($params);
+                } elseif ( is_scalar($params[0])) {
+                    /* if scalar, we have to assume its a path */
+                    /* This is a psuedo-hack because init has no arugment prefix;
+                     * our current inmplementation of 'files' doesn't give
+                     * one = cool! */
+                    $this->addOption('files', $params[0]);
+                }
+            }
+        } else {
+            /* should always be called so we have a full array of valid options */
+            $this->setOptions($params);
+        }
+    }
+
+    /**
+     * Execute the command and return the results.
+     *
+     * @param mixed             $params Options passed to the Log command
+     * @param VersionControl_Hg $hg     Instance of the base object
+     *
+     * @return string
+     */
+    public function execute(array $params = null, VersionControl_Hg $hg)
+    {
+        /* Validate */
+        $path = $this->getOption('files');
+
+        if (! $this->directory_exists($path) ) {
+            /* kill any umasks. */
+            //@TODO remove since it causes problems on multithreaded servers
+            //umask(0);
+
+            //refuse bad fs names
+            //$except = array('\\', '/', ':', '*', '?', '"', '<', '>', '|');
+
+            //Please note that when specifying the recursive option the
+            // function returns false anyway if the directory already exists.
+            //Octal permissions are ignored on Windows
+            if (! mkdir($path, 0755, true) ) {
+                throw new VersionControl_Hg_Command_Exception(
+                    VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
+                    "PHP encountered an error while trying to create the
+                     directory '{$path}'. "
+                );
+            }
+
+            /* This works around some umask issues */
+            chmod($path, 0755);
+        } //clearstatcache()
+
+        if ( ! is_writable($path) ) {
+            throw new VersionControl_Hg_Command_Exception(
+                VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
+                "The directory '{$path}' is not writable, but must be. "
+            );
+        }
+
+        if ( ! $this->directory_is_empty($path) ) {
+            throw new VersionControl_Hg_Command_Exception(
+                VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
+                "The directory '{$path}' is not empty, but must be. "
+            );
+        }
+
+        /* take care of options passed in as such:
+         * $hg->init('/path/')->run('verbose'));
+         */
+        if ( ! empty($params) ) {
+            $this->setOptions($params);
+        }
+
+        /* --noninteractive is required since issuing the command is
+         * unattended by nature of using this package.
+        */
+        $this->addOptions(
+            array(
+                'noninteractive' => null,
+                //'repository' => $this->path,
+            )
+        );
+
+        /* Despite its being so not variable, we need to set the command string
+         * only after manually setting options and other command-specific data */
+        $this->setCommandString();
+
+        /* no var assignment, since 2nd param holds output */
+        exec($this->command_string, $this->output, $this->status);
+
+        if ( $this->status !== 0 ) {
+            throw new VersionControl_Hg_Command_Exception(
+                VersionControl_Hg_Command_Exception::COMMANDLINE_ERROR
+            );
+        }
+        $repository = VersionControl_Hg_Container_Repository::getInstance();
+        $repository->setPath($path);
+
+        return $this->hg->repository;
+    }
+
+    /**
+     * Confirm that the path exists
+     *
+     * @param string $path The path the repository should be created at
+     *
+     * @return boolean
+     */
+    protected function directory_exists($path)
+    {
+        $directory_exists = true;
+
+        if (! is_dir($path) ) {
+            //So, is it a file? Do we care?
+
+            $directory_exists = false;
+        }
+
+        /* for the fluent API */
+        return $directory_exists;
+    }
+
+    /**
+     * Confirm that the path exists
+     *
+     * @param string $path The path the repository should be created at
+     *
+     * @return boolean
+     */
+    protected function directory_is_empty($path)
+    {
+        $directory_is_empty = true;
+
+        $files_in_dir = scandir($path);
+
+        /* ccount for . and .. */
+        if ( count($files_in_dir) > 2 ) {
+            $directory_is_empty = false;
+        }
+
+        /* for the fluent API */
+        return $directory_is_empty;
+    }
+
+}

Trunk/VersionControl/Hg/Command/Interface.php

  *
  * PHP version 5
  *
- * @category    VersionControl
- * @package     Hg
- * @subpackage  command
- * @author      Michael Gatto <mgatto@lisantra.com>
- * @copyright   2011 Lisantra Technologies, LLC
- * @license     http://www.opensource.org/licenses/mit-license.html  MIT License
- * @link        http://pear.php.net/package/VersionControl_Hg
+ * @category   VersionControl
+ * @package    Hg
+ * @subpackage Command
+ * @author     Michael Gatto <mgatto@lisantra.com>
+ * @copyright  2011 Lisantra Technologies, LLC
+ * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
+ * @link       http://pear.php.net/package/VersionControl_Hg
  */
 
 /**
  *
  * PHP version 5
  *
- * @category    VersionControl
- * @package     Hg
- * @subpackage  Command
- * @author      Michael Gatto <mgatto@lisantra.com>
- * @copyright   2911 Lisantra Technologies, LLC
- * @license     http://www.opensource.org/licenses/mit-license.html  MIT License
- * @link        http://pear.php.net/package/VersionControl_Hg
+ * @category   VersionControl
+ * @package    Hg
+ * @subpackage Command
+ * @author     Michael Gatto <mgatto@lisantra.com>
+ * @copyright  2011 Lisantra Technologies, LLC
+ * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
+ * @link       http://pear.php.net/package/VersionControl_Hg
  */
 interface VersionControl_Hg_Command_Interface
 {
-    public function execute(array $options = null);
+    /**
+     * Main method encapsulating the logic to run the command
+     *
+     * @param mixed             $params Options passed to the Log command
+     * @param VersionControl_Hg $hg     Instance of the base object
+     *
+     * @return VersionControl_Hg_Command_Abstract
+     */
+    public function execute(array $params = null, VersionControl_Hg $hg);
 }

Trunk/VersionControl/Hg/Command/Log.php

  * @copyright  2011 Lisantra Technologies, LLC
  * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
  * @link       http://pear.php.net/package/VersionControl_Hg
+ * @filesource
  */
 
 /**
  * $hg->log()->excluding('**.php')->run();
  * </code>
  *
- * This displays nothing; excluding takes precedence. Remove excluding() to get only index.php:
+ * This displays nothing; excluding takes precedence. Remove excluding() to
+ * get only index.php:
  * <code>
  * $hg->log()->files(array('index.php'))->excluding('**.php')->run();
  * </code>
  *
- * Include specific files, which might not show up otherwise. Using this with files can lead to unexpected results:
+ * Include specific files, which might not show up otherwise. Using this with
+ * files can lead to unexpected results:
  * <code>
  * $hg->log()->including('**.php')->run();
  * </code>
  *
  * Patching and diffing options are not available in this class as they might
  * be when using the command line Mercurial client.
- * @see VersionControl_Hg_Command_Diff
  *
  * PHP version 5
  *
  * @copyright  2011 Lisantra Technologies, LLC
  * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
  * @link       http://pear.php.net/package/VersionControl_Hg
+ * @example    test_Log.php Some examples to use
  */
 class VersionControl_Hg_Command_Log
     extends VersionControl_Hg_Command_Abstract
     /**
      * Constructor
      *
-     * @param mixed $params One or more parameters to modify the command
+     * @param mixed             $params One or more parameters for the command
+     * @param VersionControl_Hg $hg     Instance of the base object
      *
      * @return void
      */
     }
 
     /**
-     * Execute the command and return the results
+     * Execute the command and return the results.
      *
-     * @param mixed $params The options passed to the Log command
+     * @param mixed             $params Options passed to the Log command
+     * @param VersionControl_Hg $hg     Instance of the base object
      *
      * @return string
      */
-    public function execute(array $params = null)
+    public function execute(array $params = null, VersionControl_Hg $hg)
     {
         /* take care of options passed in as such:
          * $hg->status(array('revision' => 3, 'all' => null));
     public function files(array $files)
     {
         $this->addOption('files', join(' ', $files));
-        return $this; //for the fluent API
+
+        /* for the fluent API */
+        return $this;
     }
 
     /**
     }
 
     /**
-     * Restricts the log to changesets only commited on $date
+     * Restricts the log to changesets only commited before $date
      *
      * Usage:
      * <code>
     }
 
     /**
-     * Restricts the log to changesets only commited on $date
+     * Restricts the log to changesets only commited after $date
      *
      * Usage:
      * <code>
     }
 
     /**
-     * Restricts log output to changesets between $from and $to
+     * Restricts log output to changesets between dates $from and $to
      *
      * Usage:
      * <code>$hg->log()->between('Dec 27, 2010', '2010-12-31')->run();</code>

Trunk/VersionControl/Hg/Command/Output/Formatter.php

-<?php
-/**
- * Contains the definition of the Output Formatter class
- *
- * PHP version 5
- *
- * @category    VersionControl
- * @package     Hg
- * @subpackage  Output
- * @author      Michael Gatto <mgatto@lisantra.com>
- * @copyright   2009 Lisantra Technologies, LLC
- * @license     http://www.opensource.org/licenses/mit-license.html  MIT License
- * @link        http://pear.php.net/package/VersionControl_Hg
- */
-
-/**
- * Format output
- *
- * PHP version 5
- *
- * @category    VersionControl
- * @package     Hg
- * @subpackage  Output
- * @author      Michael Gatto <mgatto@lisantra.com>
- * @copyright   2011 Lisantra Technologies, LLC
- * @license     http://www.opensource.org/licenses/mit-license.html  MIT License
- * @link        http://pear.php.net/package/VersionControl_Hg
- * @filesource
- */
-class VersionControl_Hg_Command_Output_Formatter
-{
-    /**
-     * Implemented output types.
-     *
-     * Array is the default, by nature of the code.
-     *
-     * @var mixed
-     */
-    public static $formats = array(
-        'json', 'serialize', 'raw', 'yaml', //xml
-    );
-
-    //Having run() return an VersionControl_Hg_Command_Output object
-    //might just be useful, sort of how PDO / Doctrine can...
-    //though we might be overengineering, just a wee tad bit.
-
-    /**
-     * Class constructor.
-     */
-    public function __construct() {}
-
-    /**
-     * Convert array to PHP JSON text format
-     *
-     * @param array $output is the passed-in, parsed output from the cli
-     */
-    public function toJson(array $output)
-    {
-        //output must be in UTF-8...
-        return json_encode($output);
-    }
-
-    /**
-     * Convert array to YAML text format
-     *
-     * @param array $output is the passed-in, parsed output from the cli
-     */
-    public function toYaml(array $output)
-    {
-        if ( ! extension_loaded('yaml') ) {
-            throw new VersionControl_Hg_Command_Exception(
-                VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
-                "The required PECL Yaml extension is not installed. "
-            );
-        }
-
-        return yaml_emit($output);
-    }
-
-    /**
-     * Convert array to raw text format
-     *
-     * @param array $output is the passed-in, parsed output from the cli
-     *
-     * @TODO Hmmm, why not get it before parsing??
-     */
-    public function toRaw(array $output) {
-        $raw = "";
-
-        foreach ( $output as $line ) {
-           $raw .= $line . PHP_EOL;
-        }
-
-        return $raw;
-    }
-
-    /**
-     * Convert array to PHP serialized text format
-     *
-     * @param array $output is the passed-in, parsed output from the cli
-     */
-    public function toSerialize(array $output) {
-        return serialize($output);
-    }
-
-    /**
-     * The main function for converting to an XML document.
-     * Pass in a multi dimensional array and this recrusively loops through
-     * and builds up an XML document.
-     *
-     * I borrowed this XML writing algorithm from somewhere, but now I forget.
-     *
-     * @param array $data
-     * @param string $rootNodeName - what you want the root node to be - defaultsto data.
-     * @param SimpleXMLElement $xml - should only be used recursively
-     *
-     * @return string XML
-     *
-     * @TODO This should probably be implemented in each command which can output to XML, since the vocabulary will be different in each case.
-     */
-    public static function toXML( $data, $rootNodeName = 'ResultSet', &$xml=null )
-    {
-        // turn off compatibility mode as simple xml throws a wobbly if you don't.
-        //if ( ini_get('zend.ze1_compatibility_mode') == 1 ) ini_set ( 'zend.ze1_compatibility_mode', 0 );
-        if ( is_null( $xml ) ) $xml = simplexml_load_string( "" );
-
-        // loop through the data passed in.
-        foreach( $data as $key => $value ) {
-
-            // no numeric keys in our xml please!
-            if ( is_numeric( $key ) ) {
-                $numeric = 1;
-                $key = $rootNodeName;
-            }
-
-            // delete any char not allowed in XML element names
-            $key = preg_replace('/[^a-z0-9\-\_\.\:]/i', '', $key);
-
-            // if there is another array found recrusively call this function
-            if ( is_array( $value ) ) {
-                $node = self::is_assoc( $value ) || $numeric ? $xml->addChild( $key ) : $xml;
-
-                // recrusive call.
-                if ( $numeric ) $key = 'anon';
-                self::toXml( $value, $key, $node );
-            } else {
-
-                // add single node.
-                $value = htmlentities( $value );
-                $xml->addChild( $key, $value );
-            }
-        }
-
-        // pass back as XML
-        return $xml->asXML();
-
-    // if you want the XML to be formatted, use the below instead to return the XML
-        //$doc = new DOMDocument('1.0');
-        //$doc->preserveWhiteSpace = false;
-        //$doc->loadXML( $xml->asXML() );
-        //$doc->formatOutput = true;
-        //return $doc->saveXML();
-    }
-
-    // determine if a variable is an associative array
-    public static function isAssoc( $array )
-    {
-        return (is_array($array) && 0 !== count(array_diff_key($array, array_keys(array_keys($array)))));
-    }
-}
+<?php
+/**
+ * Contains the definition of the Output Formatter class
+ *
+ * PHP version 5
+ *
+ * @category   VersionControl
+ * @package    Hg
+ * @subpackage Output
+ * @author     Michael Gatto <mgatto@lisantra.com>
+ * @copyright  2011 Lisantra Technologies, LLC
+ * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
+ * @link       http://pear.php.net/package/VersionControl_Hg
+ */
+
+/**
+ * Format output
+ *
+ * PHP version 5
+ *
+ * @category   VersionControl
+ * @package    Hg
+ * @subpackage Output
+ * @author     Michael Gatto <mgatto@lisantra.com>
+ * @copyright  2011 Lisantra Technologies, LLC
+ * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
+ * @link       http://pear.php.net/package/VersionControl_Hg
+ * @filesource
+ */
+class VersionControl_Hg_Command_Output_Formatter
+{
+    /**
+     * Implemented output types.
+     *
+     * Array is the default, by nature of the code.
+     *
+     * @var mixed
+     */
+    public static $formats = array(
+        'json', 'serialize', 'raw', 'yaml',
+    );
+
+    //Having run() return an VersionControl_Hg_Command_Output object
+    //might just be useful, sort of how PDO / Doctrine can...
+    //though we might be overengineering, just a wee tad bit.
+
+    /**
+     * Class constructor.
+     */
+    public function __construct()
+    {
+
+    }
+
+    /**
+     * Convert array to PHP JSON text format
+     *
+     * @param mixed $output The passed-in, parsed output from the cli
+     *
+     * @return string
+     */
+    public static function toJson(array $output)
+    {
+        /* output must be in UTF-8 */
+        return json_encode($output);
+    }
+
+    /**
+     * Convert array to YAML text format
+     *
+     * @param array $output The passed-in, parsed output from the cli
+     *
+     * @return string
+     */
+    public static function toYaml(array $output)
+    {
+        if ( ! extension_loaded('yaml') ) {
+            throw new VersionControl_Hg_Command_Exception(
+                VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
+                "The required PECL Yaml extension is not installed. "
+            );
+        }
+
+        return yaml_emit($output);
+    }
+
+    /**
+     * Convert array to raw text format
+     *
+     * @param array $output is the passed-in, parsed output from the cli
+     *
+     * @return string
+     */
+    public static function toRaw(array $output)
+    {
+        $raw = "";
+
+        foreach ( $output as $line ) {
+            $raw .= $line . PHP_EOL;
+        }
+
+        return $raw;
+    }
+
+    /**
+     * Convert array to PHP serialized text format
+     *
+     * @param array $output is the passed-in, parsed output from the cli
+     *
+     * @return string
+     */
+    public static function toSerialize(array $output)
+    {
+        return serialize($output);
+    }
+
+}

Trunk/VersionControl/Hg/Command/Pull.php

-<?php
-/**
- * Contains the definition of the VersionControl_Hg_Repository_Command_Pull
- * class
- *
- * PHP version 5
- *
- * @category   VersionControl
- * @package    Hg
- * @subpackage Command
- * @author     Michael Gatto <mgatto@lisantra.com>
- * @copyright  2011 Lisantra Technologies, LLC
- * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
- * @link       http://pear.php.net/package/VersionControl_Hg
- */
-
-/**
- * Provides the required interface for all commands
- */
-require_once 'Interface.php';
-
-/**
- * Provides base functionality common to all commands
- */
-require_once 'Abstract.php';
-
-/**
- * Provides Exceptions for commands (VersionControl_Hg_Command_Exception)
- */
-require_once 'Exception.php';
-
-/**
- * Pull changesets from a remote repository
- *
- * Usage:
- *
- * Basic usage, assuming .hgrc has a default pull url:
- * <code>
- * $hg = new VersionControl_Hg('/path/to/repo');
- * $array_of_pulled_changesets = $hg->pull()->run('verbose');
- * </code>
- *
- * With credentials:
- * <code>
- * $hg->pull()->from('/remote/repo')->username('A')->password('B')->run();
- * </code>
- * or
- * <code>
- * $hg->pull()->from()->using(array('username' => 'A', 'password' => 'B'))->run();
- * </code>
- *
- * Explcititly pull 'all' changesets (Default):
- * <code>$hg->pull('all')->from('/remote/repo')->run();</code>
- * or
- * <code>$hg->pull()->all()->from('/remote/repo')->run();</code>
- *
- * Pull a specific revision:
- * <code>$hg->pull(23)->from('/remote/repo')->run();</code>
- * or
- * <code>$hg->pull()->revision(23)->from('/remote/repo')->run();</code>
- * or, a multiple revisions:
- *
- * or, a range of contiguous revisions:
- *
- *
- * Update the working copy after a pull:
- * <code>$hg->pull()->from('/remote/repo')->update('working copy')->run();</code>
- * Also, you may use 'fetch' to pull and update at the same time.
- *
- * Pull a specific branch:
- * <code>$hg->pull()->branch('mine')->from('/remote/repo')->run();</code>
- *
- * Pull a specific bookmark:
- * <code>$hg->pull()->bookmark('earlier')->from('/remote/repo')->run();</code>
- *
- * Force a pull:
- * <code>$hg->pull()->force()->from('/remote/repo')->run();</code>
- *
- * Results: Should return a list of changes pulled. See cognate: incoming().
- *
- * PHP version 5
- *
- * @category   VersionControl
- * @package    Hg
- * @subpackage Command
- * @author     Michael Gatto <mgatto@lisantra.com>
- * @copyright  2011 Lisantra Technologies, LLC
- * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
- * @link       http://pear.php.net/package/VersionControl_Hg
- */
-class VersionControl_Hg_Command_Pull
-    extends VersionControl_Hg_Command_Abstract
-        implements VersionControl_Hg_Command_Interface
-{
-   /**
-     * The name of the mercurial command implemented here
-     *
-     * @var string
-     */
-    protected $command = 'pull';
-
-    /**
-     * Required options for this specific command. These may not be required
-     * by Mercurial itself, but are required for the proper functioning of
-     * this package.
-     *
-     * @var mixed
-     */
-    protected $required_options = array(
-        'noninteractive' => null,
-        'repository' => null,
-        'files' => null,
-    );
-
-    /**
-     * Permissable options.
-     *
-     * The actual option must be the key, while 'null' is a value here to
-     * accommodate the current implementation of setting options.
-     *
-     * @var mixed
-     */
-    protected $allowed_options = array(
-        'bookmark' => null,
-        'branch' => null,
-        'revision' => null,
-        'from' => null,
-        'username' => null,
-        'password' => null,
-        'all' => null,
-        'update' => null,
-        'force' => null,
-    );
-
-    /**
-     * Constructor
-     *
-     * @param mixed $params is one or more parameters to modify the command
-     *
-     * @return void
-     */
-    public function __construct($params = null, VersionControl_Hg $hg)
-    {
-        $this->hg = $hg;
-        /* a repository must have been set already */
-        $repository = $this->hg->repository->getPath();
-        if ( empty($repository) ) {
-            throw new VersionControl_Hg_Command_Exception(
-                VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
-                "The repository must be defined either at
-                 instantiation, as a string path arugment to clone()
-                 or as the 'reposi