From a409adfaaf218a70d42492f33e1bc17459d157a6 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 18 Jul 2008 23:15:55 -0400 Subject: [PATCH] Fix up Git_Repo->log() to actually work. Fix some minor code bugs. Also fix up logic errors in commit log parsing. Finally, setup sample script. Signed-off-by: Edward Z. Yang --- .gitignore | 1 + library/Git.php | 6 +++++- library/Git/Commit.php | 9 ++++++--- library/Git/Repo.php | 2 +- sample.php | 11 +++++++++++ test-settings.sample.php | 9 +++++++++ tests/GitTest.php | 4 ++-- 7 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 .gitignore create mode 100644 sample.php create mode 100644 test-settings.sample.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd8ce44 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +test-settings.php diff --git a/library/Git.php b/library/Git.php index 5571f2e..4e3cdcd 100644 --- a/library/Git.php +++ b/library/Git.php @@ -73,8 +73,12 @@ class Git public function __call($method, $raw_args) { // split out "kwargs" (to be converted to options) from regular // "args" (which get inserted normally) - $kwargs = $raw_args[0]; $args = array(); + $kwargs = array(); + foreach ($raw_args as $raw) { + if (is_array($raw)) $kwargs = $raw; + else $args[] = $raw; + } for ($i = 0; isset($kwargs[$i]); $i++) { $args[] = $kwargs[$i]; unset($kwargs[$i]); diff --git a/library/Git/Commit.php b/library/Git/Commit.php index 1bd8fcf..967feb6 100644 --- a/library/Git/Commit.php +++ b/library/Git/Commit.php @@ -59,20 +59,23 @@ class Git_Commit { */ public static function listFromString($repo, $text) { $lines = explode("\n", $text); - for ($i = 0, $c = count($lines); $i < $c; $i++) { + foreach ($lines as $k => $v) if (trim($v) === '') unset($lines[$k]); + $lines = array_values($lines); + + for ($i = 0, $c = count($lines); $i < $c;) { $id = self::_l($lines, $i, true); $tree = self::_l($lines, $i, true); $parents = array(); - while ($lines && strncmp($lines[$i], 'parent', 6) === 0) { + while ($i < $c && strncmp($lines[$i], 'parent', 6) === 0) { $parents[] = self::_l($lines, $i, true); } list($author, $authoredDate) = self::actor(self::_l($lines, $i)); list($committer, $committedDate) = self::actor(self::_l($lines, $i)); $messages = array(); - while ($lines && strncmp($lines[$i], ' ', 4) === 0) { + while ($i < $c && strncmp($lines[$i], ' ', 4) === 0) { $messages[] = trim(self::_l($lines, $i)); } diff --git a/library/Git/Repo.php b/library/Git/Repo.php index 9f60088..8c380dc 100644 --- a/library/Git/Repo.php +++ b/library/Git/Repo.php @@ -69,7 +69,7 @@ class Git_Repo { $arg = array($commit); } $commits = $this->git->log($path, $options); - return Commit::listFromString($commits); + return Git_Commit::listFromString($this, $commits); } // public function diff($a, $b, $paths = array()) { diff --git a/sample.php b/sample.php new file mode 100644 index 0000000..9b834e0 --- /dev/null +++ b/sample.php @@ -0,0 +1,11 @@ +log()); diff --git a/test-settings.sample.php b/test-settings.sample.php new file mode 100644 index 0000000..ba19ae5 --- /dev/null +++ b/test-settings.sample.php @@ -0,0 +1,9 @@ +__construct('dir'); - $git->expectOnce('execute', array('git --git-dir=dir cherry-pick -s --no-commit f533ebca')); + $git->expectOnce('execute', array('git --git-dir=dir cherry-pick -s f533ebca --no-commit')); $git->setReturnValue('execute', $expect = 'Result'); - $result = $git->cherryPick(array('--no-commit', 's' => true, 'f533ebca')); + $result = $git->cherryPick('f533ebca', array('--no-commit', 's' => true)); $this->assertIdentical($result, $expect); } -- 2.11.4.GIT