00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 require_once('git_object.class.php');
00022 require_once('git_commit_stamp.class.php');
00023
00024 class GitCommit extends GitObject
00025 {
00030 public $tree;
00031
00036 public $parents;
00037
00041 public $author;
00042
00046 public $committer;
00047
00051 public $summary;
00052
00056 public $detail;
00057
00058 public function __construct($repo)
00059 {
00060 parent::__construct($repo, Git::OBJ_COMMIT);
00061 }
00062
00063 public function _unserialize($data)
00064 {
00065 $lines = explode("\n", $data);
00066 unset($data);
00067 $meta = array('parent' => array());
00068 while (($line = array_shift($lines)) != '')
00069 {
00070 $parts = explode(' ', $line, 2);
00071 if (!isset($meta[$parts[0]]))
00072 $meta[$parts[0]] = array($parts[1]);
00073 else
00074 $meta[$parts[0]][] = $parts[1];
00075 }
00076
00077 $this->tree = sha1_bin($meta['tree'][0]);
00078 $this->parents = array_map('sha1_bin', $meta['parent']);
00079 $this->author = new GitCommitStamp;
00080 $this->author->unserialize($meta['author'][0]);
00081 $this->committer = new GitCommitStamp;
00082 $this->committer->unserialize($meta['committer'][0]);
00083
00084 $this->summary = array_shift($lines);
00085 $this->detail = implode("\n", $lines);
00086
00087 $this->history = NULL;
00088 }
00089
00090 public function _serialize()
00091 {
00092 $s = '';
00093 $s .= sprintf("tree %s\n", sha1_hex($this->tree));
00094 foreach ($this->parents as $parent)
00095 $s .= sprintf("parent %s\n", sha1_hex($parent));
00096 $s .= sprintf("author %s\n", $this->author->serialize());
00097 $s .= sprintf("committer %s\n", $this->committer->serialize());
00098 $s .= "\n".$this->summary."\n".$this->detail;
00099 return $s;
00100 }
00101
00107 public function getHistory()
00108 {
00109 if ($this->history)
00110 return $this->history;
00111
00112
00113 $inc = array();
00114
00115 $queue = array($this);
00116 while (($commit = array_shift($queue)) !== NULL)
00117 {
00118 foreach ($commit->parents as $parent)
00119 {
00120 if (!isset($inc[$parent]))
00121 {
00122 $inc[$parent] = 1;
00123 $queue[] = $this->repo->getObject($parent);
00124 }
00125 else
00126 $inc[$parent]++;
00127 }
00128 }
00129
00130 $queue = array($this);
00131 $r = array();
00132 while (($commit = array_pop($queue)) !== NULL)
00133 {
00134 array_unshift($r, $commit);
00135 foreach ($commit->parents as $parent)
00136 {
00137 if (--$inc[$parent] == 0)
00138 $queue[] = $this->repo->getObject($parent);
00139 }
00140 }
00141
00142 $this->history = $r;
00143 return $r;
00144 }
00145
00151 public function getTree()
00152 {
00153 return $this->repo->getObject($this->tree);
00154 }
00155
00164 public function find($path)
00165 {
00166 return $this->getTree()->find($path);
00167 }
00168
00169 static public function treeDiff($a, $b)
00170 {
00171 return GitTree::treeDiff($a ? $a->getTree() : NULL, $b ? $b->getTree() : NULL);
00172 }
00173 };
00174 ?>