| <?php |
| /******************************************************************************* |
| * Copyright (c) 2010, 2011 Eclipse Foundation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Wayne Beaton (Eclipse Foundation)- initial API and implementation |
| *******************************************************************************/ |
| error_reporting(E_ALL); |
| ini_set("display_errors", true); |
| |
| header("Content-type: text/plain"); |
| |
| require_once dirname(__FILE__) . '/../common/common-functions.inc'; |
| mustBeEclipseFoundationCaller(); |
| |
| if (!isset($_GET['repo'])) exit('# Path must be set.'); |
| |
| $repo = $_GET['repo']; |
| if (!preg_match('/^\/gitroot\//', $repo)) exit('# Invalid repository'); |
| |
| if (!file_exists($repo)) exit('# Repository does not exist.'); |
| if (!is_dir($repo)) exit('# Not a valid repository.'); |
| |
| require_once dirname(__FILE__) . '/../common/git-functions.inc'; |
| |
| class GitAuthorProcessor extends GitLogProcessor { |
| var $repo; |
| var $record; |
| |
| function __construct($repo) { |
| $this->repo = $repo; |
| } |
| |
| function startCommit($ref) { |
| $this->record = array('size' => 0); |
| } |
| |
| function data($ref, $key, $value) { |
| $this->record[$key] = $value; |
| } |
| |
| function file($ref, $filename, $filetype, $size) { |
| $this->record['size'] += $size; |
| } |
| |
| function endCommit($ref) { |
| $committer = $this->record['committer']; |
| $author = $this->record['author']; |
| |
| if ($committer == $author) return; |
| |
| $authorName = mysql_real_escape_string($this->record['authorName']); |
| $size = $this->record['size']; |
| $comment = mysql_real_escape_string($this->record['comment']); |
| $date = date('Y-m-d h:i:s', $this->record['date']); |
| |
| $sql = " |
| insert ignore into gitlogcache |
| (repo, ref, committer, author, authorName, size, comment, commitDate) |
| values ('$this->repo', '$ref', '$committer', '$author', '$authorName', $size, '$comment', '$date') |
| "; |
| |
| dashboard_sql($sql); |
| //fputcsv($this->out, array($ref,$committer,$author,$authorName,$size,$comment)); |
| } |
| } |
| |
| $sql = " |
| create table if not exists gitlogcache ( |
| repo varchar(128) not null, |
| ref varchar(40) not null, |
| committer varchar(50) not null, |
| author varchar(128) not null, |
| authorName varchar(128), |
| size int unsigned, |
| comment varchar(1024) not null, |
| commitDate datetime not null, |
| CONSTRAINT UNIQUE (repo, ref), |
| INDEX (repo), |
| INDEX (ref), |
| INDEX (commitDate)) ENGINE=InnoDB; |
| "; |
| dashboard_sql($sql); |
| |
| $sql = "select max(commitDate) as date from gitlogcache where repo='$repo'"; |
| $result = dashboard_sql($sql); |
| $row = mysql_fetch_assoc($result); |
| $date = $row['date']; |
| if ($date) { |
| $date = date('Y-m-d', strtotime($date)); |
| } else { |
| $date = '1984-07-16'; // The beginning of time |
| } |
| |
| $path = escapeshellcmd($repo); |
| $handle = popen("/usr/local/bin/git --git-dir=$path log --branches --numstat --format=fuller --since=$date", 'r'); |
| parseGitLog($handle, new GitAuthorProcessor($repo)); |
| pclose($handle); |
| |
| $out = fopen("php://output", 'w'); |
| $sql = "select ref, committer, author, authorName, size, comment from gitlogcache where repo='$repo'"; |
| $result = dashboard_sql($sql); |
| while ($row = mysql_fetch_assoc($result)) { |
| $ref = $row['ref']; |
| $committer = $row['committer']; |
| $author = $row['author']; |
| $authorName = $row['authorName']; |
| $size = $row['size']; |
| $comment = $row['comment']; |
| |
| fputcsv($out, array($ref,$committer,$author,$authorName,$size,$comment)); |
| } |
| fclose($out); |
| ?> |