From 3501b185202e1a3362ec8356db35f408d00bfc10 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Mon, 21 Jul 2008 11:05:37 -0600 Subject: [PATCH] Fix bugs involving command line invocation, DateTime construction and log() * Current working directory was not set properly with WScript.Shell * Numerous errors in Unix process code fixed; it now works * DateTime requires an '@' prepended to Unix timestamp * Git_Repo->log() was passing the wrong parameter to array_merge() Signed-off-by: Edward Z. Yang --- library/Git.php | 15 +++++++-------- library/Git/Commit.php | 2 +- library/Git/Repo.php | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/library/Git.php b/library/Git.php index eb440bd..5548646 100644 --- a/library/Git.php +++ b/library/Git.php @@ -68,6 +68,7 @@ class Git */ public function execute($command, $istream = null, $options = array()) { if (is_array($command)) $command = implode(' ', $command); + //var_dump($command); $options = array_merge(array( 'withKeepCwd' => false, 'withExtendedOutput' => false, @@ -82,14 +83,12 @@ class Git if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { // Windows dependent code, stolen from PHPT $com = new COM('WScript.Shell'); - $old = getcwd(); - chdir($cwd); // :HACK: Determine the proper way to pass cwd to COM + $com->CurrentDirectory = $cwd; $proc = $com->Exec($command); if (!is_null($istream)) $proc->StdIn->Write($istream); $stdout = $proc->StdOut->ReadAll(); $stderr = $proc->StdErr->ReadAll(); $status = $proc->ExitCode; - chdir($old); } else { // untested! Also stolen from PHPT // this seems needlessly complicated @@ -101,18 +100,18 @@ class Git ); $pipes = array(); $proc = proc_open($command, $pipes_template, $pipes); - fwrite($pipes[0], $this->istream); + fwrite($pipes[0], $istream); fclose($pipes[0]); + $stderr = $stdout = ''; while (true) { - $read = array($this->_pipes[1]); + $read = array($pipes[1]); $except = $write = null; $n = stream_select($read, $write, $except, 30); - $stderr = $stdout = ''; if ($n === 0) { throw new Git_Exception('Process timed out'); } elseif ($n > 0) { - $errLine = fread($this->_pipes[2], 8192); - $outLine = fread($this->_pipes[1], 8192); + $errLine = fread($pipes[2], 8192); + $outLine = fread($pipes[1], 8192); $stderr .= $errLine; $stdout .= $outLine; if ($errLine === '' && $outLine === '') { diff --git a/library/Git/Commit.php b/library/Git/Commit.php index a559b7a..91a43db 100644 --- a/library/Git/Commit.php +++ b/library/Git/Commit.php @@ -112,7 +112,7 @@ class Git_Commit { public static function actor($line) { preg_match('/^.+? (.*) (\d+) .*$/', $line, $matches); list($x, $actor, $epoch) = $matches; - return array(Git_Actor::fromString($actor), new DateTime($epoch)); + return array(Git_Actor::fromString($actor), new DateTime('@' . $epoch)); } } diff --git a/library/Git/Repo.php b/library/Git/Repo.php index 0429af2..7553084 100644 --- a/library/Git/Repo.php +++ b/library/Git/Repo.php @@ -101,14 +101,14 @@ class Git_Repo { public function log($commit = 'master', $path = array(), $kwargs = array()) { $options = array_merge(array('pretty' => 'raw'), $kwargs); if ($path) { - $arg = array($commit, '--', $path); + $arg = array_merge(array($commit, '--'), $path); } else { $arg = array($commit); } // This call is kinda weird, I know, but otherwise we have // to do user_func_call_array. Perhaps we should patch __call // to work with numeric arrays? A thought... - $commits = $this->git->__call('log', array_merge($path, array($options))); + $commits = $this->git->__call('log', array_merge($arg, array($options))); return Git_Commit::listFromString($this, $commits); } -- 2.11.4.GIT