matteosister/GitElephant — pull request #4 by maff (2012-01-11 16:28:45+00:00)
Title: Commit logs

In order to build a git repository viewer it's important to be able to access the commit log. I changed the existing

Repository::getLog($obj [, $branch]) to Repository::getObjectLog(TreeObject $obj [, $branch [, $limit [, $offset]]]) and added a new method Repository::getLog([$ref = null [, $limit = 15 [, $offset = null]]]).

getObjectLog handles logs for TreeObjects while getLog is generic for refs (could maybe be summarized into one single method).

Other changes
--------------------

* Object/Log contains an array of commits (fetched from the log command) and implements \ArrayAccess, \Countable, \Iterator.
* Commit::message is no array but an instance of Object\Commit\Message (to be able to easily access the commit message in one line)

Examples
-------------

``` php
getLog();
$log = $repo->getLog('master', 5);
$log = $repo->getLog('v0.1', 5, 10);

$tree = $repo->getTree();
$log = $repo->getObjectLog($tree[0]);

echo $log->first()->getMessage();
echo $log->first()->getMessage()->toString();
echo $log->first()->getMessage()->getShortMessage();
echo $log->first()->getMessage()->getFullMessage();

echo $log[2]->getMessage();
echo $log->index(2)->getMessage();

echo $log->count();
echo count($log);

foreach ($log as $commit) {
echo $commit->getDatetimeAuthor()->format('c');
}
```