1<?php
2
3require_once('config.inc.php');
4
5function run_git($command, $repo, $bare=false)
6{
7	$repo = str_replace('/', '', $repo);
8	$repo = str_replace('\\', '', $repo);
9	if (!$bare)
10	  $repo.='/.git';
11
12	$output = array();
13	$ret = 0;
14	$c = GIT_EXEC.' --git-dir='.ROOT_DIR.$repo.' '.$command;
15	exec($c, $output, $ret);
16	if ($ret != 0) {
17		//debug
18		echo($c);
19		die('git failed, is git path correct?');
20	}
21	return $output;
22}
23
24function git_get_log($repo, $limit = 10, $bare=false)
25{
26	$format = array('%H', '%at', '%an', '%s');
27	$params = implode(DELIMETER, $format);
28	$data = run_git('log --pretty=format:"'.$params.'" -'.$limit, $repo, $bare);
29	$result = array();
30	foreach($data as $line)
31	{
32		$columns = explode(DELIMETER, $line);
33		$row = array(
34			'commit' => $columns[0],
35			'timestamp' => $columns[1],
36			'author' => $columns[2],
37			'message' => $columns[3],
38		);
39		$result[] = $row;
40	}
41	return $result;
42}
43?>
44