Fix up Git_Repo->log() to actually work.
[phpgit.git] / library / Git / Repo.php
blob8c380dc776931fcc4fd3666ba072e8b7f490a251
1 <?php
3 /**
4 * Represents a Git repository, and allows access to history, snapshots,
5 * commits, et cetera.
6 */
7 class Git_Repo {
9 const DAEMON_EXPORT_FILE = 'git-daemon-export-ok';
11 /**
12 * Path to this repository.
14 protected $path;
16 /**
17 * Whether or not this is a bare repository.
19 protected $bare;
21 /**
22 * Interface to Git itself.
24 protected $git;
26 /**
27 * @param $path Path to the repository (either working copy or bare)
29 public function __construct($path) {
30 $path = realpath($path);
31 if (file_exists($p = $path . Git::S . '.git')) {
32 $this->path = $p;
33 $this->bare = false;
34 } elseif (file_exists($path) && strlen($path) >= 4 && substr($path, -4) == '.git') {
35 $this->path = $path;
36 $this->bare = true;
37 } elseif (!file_exists($path)) {
38 throw new Git_Exception_InvalidRepository();
40 $this->git = new Git($this->path);
43 // * means will implement soon
45 // public function description() {
46 // * public function heads() {
47 // * public function branches() {return $this->heads();}
48 // public function tags() {
49 // * public function commits($start, $max_count, $skip) {
50 // public function commitsBetween($frm, $to) {
51 // public function commitsSince($start = 'master', $since) {
52 // public function commitCount($start = 'master') {
53 // * public function commit($id) {
54 // public function commitDeltasFrom($other_repo, $ref = 'master', $other_ref = 'master') {
55 // * public function tree($treeish = 'master', $paths = array()) {
56 // * public function blob($id) {
58 /**
59 * Returns the commit log for a treeish entity.
60 * @param $commit Commit to get log of, or commit range like begin..end
61 * @param $path Path (or paths) to get logs for
62 * @param $kwargs Extra arguments, see Git->transformArgs()
64 public function log($commit = 'master', $path = null, $kwargs = array()) {
65 $options = array_merge(array('pretty' => 'raw'), $kwargs);
66 if ($path) {
67 $arg = array($commit, '--', $path);
68 } else {
69 $arg = array($commit);
71 $commits = $this->git->log($path, $options);
72 return Git_Commit::listFromString($this, $commits);
75 // public function diff($a, $b, $paths = array()) {
76 // public function commitDiff($commit) {
77 // public static function initBare($path, $kwargs) {
78 // public static function forkBare($path, $kwargs) {
79 // public function archiveTar($treeish = 'master', $prefix = null) {
80 // public function archiveTarGz($treeish = 'master', $prefix = null) {
81 // public function enableDaemonServe() {
82 // public function disableDaemonServe() {
83 // ? private function _getAlternates() {
84 // ? private function _setAlternates() {
86 public function __toString() {
87 return '(Git_Repo "'. $this->path .'")';