<?php
/*
* Copyright (C) 2008, 2009 Patrik Fimml
* Copyright (c) 2023 Daniel Marschall
*
* This file is part of glip.
*
* glip is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
* glip is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with glip. If not, see <http://www.gnu.org/licenses/>.
*/
namespace ViaThinkSoft\Glip;
class GitCommit extends GitObject
{
/**
* @brief (string) The tree referenced by this commit, as binary sha1
* string.
*/
public $tree;
/**
* @brief (array of string) Parent commits of this commit, as binary sha1
* strings.
*/
public $parents;
/**
* @brief (GitCommitStamp) The author of this commit.
*/
public $author;
/**
* @brief (GitCommitStamp) The committer of this commit.
*/
public $committer;
/**
* @brief (string) Commit summary, i.e. the first line of the commit message.
*/
public $summary;
/**
* @brief (string) Everything after the first line of the commit message.
*/
public $detail;
public $history;
public function __construct($repo) {
parent::__construct($repo, Git::OBJ_COMMIT);
}
public function _unserialize($data) {
if (!isset($meta[$parts[0]]))
$meta[$parts[0]] = array($parts[1]);
else
$meta[$parts[0]][] = $parts[1];
}
$this->tree = pack('H40', $meta['tree'][0]);
return pack('H40', $hex);
}, $meta['parent']);
$this->author = new GitCommitStamp;
$this->committer = new GitCommitStamp;
$this->detail = implode("\n", $lines);
$this->history = null;
}
public function _serialize() {
$s = '';
foreach ($this->parents as $parent)
$s .= "\n" . $this->summary . "\n" . $this->detail;
return $s;
}
/**
* @brief Get commit history in topological order.
*
* @returns (array of GitCommit)
*/
public function getHistory() {
if ($this->history)
return $this->history;
/* count incoming edges */
foreach ($commit->parents as $parent) {
if (!isset($inc[$parent])) {
$inc[$parent] = 1;
$queue[] = $this->repo->getObject($parent);
} else
$inc[$parent]++;
}
}
while (($commit = array_pop($queue)) !== null) {
foreach ($commit->parents as $parent) {
if (--$inc[$parent] == 0)
$queue[] = $this->repo->getObject($parent);
}
}
$this->history = $r;
return $r;
}
/**
* @brief Get the tree referenced by this commit.
*
* @returns GitTree The GitTree referenced by this commit.
*/
public function getTree() {
return $this->repo->getObject($this->tree);
}
/**
* @copybrief GitTree::find()
*
* This is a convenience function calling GitTree::find() on the commit's
* tree.
*
* @copydetails GitTree::find()
*/
public function find($path) {
return $this->getTree()->find($path);
}
static public function treeDiff($a, $b) {
return GitTree::treeDiff($a ? $a->getTree() : null, $b ? $b->getTree() : null);
}
}