From 4c51208b6b5b8b1f9e25b26fa936efebdea4c21a Mon Sep 17 00:00:00 2001 From: Stricted Date: Sat, 9 Nov 2013 21:20:05 +0100 Subject: [PATCH] update git class --- git.class.php | 50 +++++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/git.class.php b/git.class.php index edfcd78..96fbf5c 100644 --- a/git.class.php +++ b/git.class.php @@ -17,7 +17,13 @@ * along with this program. If not, see . */ class git { - /** + protected $repo; + + public function __construct ($repo) { + $this->repo = $repo; + } + + /* * parse all commits from repo * * @param string $repo @@ -25,10 +31,10 @@ class git { * @param string $branch * @return array */ - public function get_commits ($repo, $count = -1, $branch = "master") { + public function get_commits ($count = -1, $branch = "master") { $data = array(); if(!$data) { - $cmd = "git --git-dir=".$repo." rev-list --header --max-count=".$count." ".$branch." "; + $cmd = "git --git-dir=".$this->repo." rev-list --header --max-count=".$count." ".$branch." "; $rev_list = shell_exec($cmd); foreach(explode("\000", $rev_list) as $rev) { $commit = array(); @@ -67,44 +73,44 @@ class git { return $data; } - /** + /* * get latest commit hash * * @param string $repo * @param string $branch * @raturn string */ - public function get_hash ($repo, $branch = "master") { - $hash = shell_exec('git --git-dir='.$repo.' rev-list -n 1 --pretty="format:%h" --header '.$branch.' | grep "^[0-9a-f]*$"'); + public function get_hash ($branch = "master") { + $hash = shell_exec('git --git-dir='.$this->repo.' rev-list -n 1 --pretty="format:%h" --header '.$branch.' | grep "^[0-9a-f]*$"'); $hash = str_replace("\r","",str_replace("\n","",$hash)); return $hash; } - /** + /* * get commit count * * @param string $repo * @param string $branch * @raturn string */ - public function get_count ($repo, $branch = "master") { - $count = shell_exec('git --git-dir='.$repo.' rev-list --oneline --first-parent --header '.$branch.' | wc -l | sed "s/[ \t]//g"'); + public function get_count ($branch = "master") { + $count = shell_exec('git --git-dir='.$this->repo.' rev-list --oneline --first-parent --header '.$branch.' | wc -l | sed "s/[ \t]//g"'); $count = str_replace("\r","",str_replace("\n","",$count)); return $count; } - /** + /* * get commit version * * @param string $repo * @param string $branch * @raturn string */ - public function get_version ($repo, $branch = "master") { - return "git-".$this->get_count($repo, $branch)."-".$this->get_hash($repo, $branch); + public function get_version ($branch = "master") { + return "git-".$this->get_count($this->repo, $branch)."-".$this->get_hash($repo, $branch); } - /** + /* * get commit age * * @param string $last_change @@ -165,21 +171,11 @@ class git { return $age_class; } - /** - * get repo list from projects.list file - * - * @param string $path - * @raturn array + /* + * pull current repo */ - public function get_repos ($path) { - $repo_list = file_get_contents($path); - $repo_list = explode("\n", $repo_list); - $data = array(); - foreach($repo_list as $id => $repo) { - $test = explode(" ",$repo); - $data[] = $test[0]; - } - return $data; + public function pull () { + shell_exec("git --git-dir=".$this->repo." pull"); } } ?> \ No newline at end of file -- 2.20.1