* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class git {
- /**
+ protected $repo;
+
+ public function __construct ($repo) {
+ $this->repo = $repo;
+ }
+
+ /*
* parse all commits from repo
*
* @param string $repo
* @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();
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
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