Getting commits

The commit object in Git is provided as VersionControl_Git_Object_Commit.

There are some ways to get a list of VersionControl_Git_Object_Commit objects.

Use VersionControl_Git::getCommits()

You can get commits by calling VersionControl_Git::getCommits().

<?php
require_once 'VersionControl/Git.php';

$git = new VersionControl_Git('/path/to/repository');
var_dump($git->getCommits());
/*
results:

array(100) {
  [0]=>
  object(VersionControl_Git_Object_Commit)#3 (9) {
    :
  }
  [1]=>
  object(VersionControl_Git_Object_Commit)#6 (9) {
    :
  }

  :
*/

Calling without arguments, VersionControl_Git::getCommits() returns a list of a hundred VersionControl_Git_Object_Commit instances from master branch. You can specify branch name, commit object name, tag name, tree object name and an instance of VersionControl_Git_Object.

<?php
require_once 'VersionControl/Git.php';

$git = new VersionControl_Git('/path/to/repository');

// from master branch
$git->getCommits();

// specify stable branch
$git->getCommits('stable');

// specify object name
$git->getCommits('6c8284e4902c3adaf356adeed40d8bda715b73a0');

// specify tag name
$git->getCommits('v1.0');

// specify an instance of VersionControl_Git_Object
$commits $git->getCommits();
$git->getCommits($commits[0]);

You can specify the maximum number of commits by the second argument.

<?php
require_once 'VersionControl/Git.php';

$git = new VersionControl_Git('/path/to/repository');

// get 1000 commits from master branch
$git->getCommits('master'1000);

You can specify the starting point of fetching by the third argument.

<?php
require_once 'VersionControl/Git.php';

$git = new VersionControl_Git('/path/to/repository');

// get 100 commits from master branch (starting at 100 th commit)
$git->getCommits('master'100100);

Use VersionControl_Git_Util_RevListFetcher

The VersionControl_Git_Util_RevListFetcher is utility class for wrapping "git-rev-list" command. So you can use any feature of "git-rev-list" by this. VersionControl_Git::getCommits() provides by using VersionControl_Git_Util_RevListFetcher.

You can use VersionControl_Git_Util_RevListFetcher to specify your VersionControl_Git instance to the constructor

<?php
require_once 'VersionControl/Git.php';

$git = new VersionControl_Git('/path/to/repository');
$fetcher = new VersionControl_Git_Util_RevListFetcher($git);

The VersionControl_Git provides the getRevListFetcher() convenience method. Use this normally.

<?php
require_once 'VersionControl/Git.php';

$git = new VersionControl_Git('/path/to/repository');
$fetcher $git->getRevListFetcher();

After specifying target (branch name, commit name, tree name, etc) and options, you can get an array of VersionControl_Git_Object_Commit by calling the fetch() method.

<?php
require_once 'VersionControl/Git.php';

$git = new VersionControl_Git('/path/to/repository');
$result $git->getRevListFetcher()
    ->
target('master')
    ->
setOption('max-count'10)
    ->
setOption('grep''initial')
    ->
setOption('date''3 hours ago')
    ->
fetch();
    Поддержать сайт на родительском проекте КГБ