Browse Source

repo.php: new repository type 'git'

master
parent
commit
fd349d1d5f
  1. 1
      modulekit.php
  2. 3
      repo.php
  3. 47
      src/RepositoryGit.php

1
modulekit.php

@ -17,6 +17,7 @@ $include = array(
'src/wikipedia.php',
'src/ImageLoader.php',
'src/RepositoryDir.php',
'src/RepositoryGit.php',
),
'css' => array(
'style.css',

3
repo.php

@ -15,6 +15,9 @@ if (!isset($repositories)) {
function getRepo ($repoId, $repoData) {
switch (array_key_exists('type', $repoData) ? $repoData['type'] : 'dir') {
case 'git':
$repo = new RepositoryGit($repoId, $repoData);
break;
default:
$repo = new RepositoryDir($repoId, $repoData);
}

47
src/RepositoryGit.php

@ -0,0 +1,47 @@
<?php
class RepositoryGit {
function __construct ($id, $def) {
$this->def = $def;
$this->path = $def['path'];
}
function info () {
$ret = array();
foreach (array('name') as $k) {
if (array_key_exists($k, $this->def)) {
$ret[$k] = $this->def[$k];
}
}
return $ret;
}
function newestTimestamp () {
$ts = (int)shell_exec("cd " . escapeShellArg($this->path) . "; git log -1 --pretty=format:%ct");
return $ts;
}
function data () {
$data = array();
$d = popen("cd " . escapeShellArg($this->path) . "; git ls-tree HEAD", "r");
while ($r = fgets($d)) {
if (preg_match("/^[0-9]{6} blob [0-9a-f]{40}\t(([0-9a-zA-Z_\-]+)\.json)$/", $r, $m)) {
$f = $m[1];
$id = $m[2];
if ($f === 'package.json') {
continue;
}
$d1 = json_decode(shell_exec("cd " . escapeShellArg($this->path) . "; git show HEAD:" . escapeShellArg($f)), true);
$data[$id] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const'))));
}
}
pclose($d);
return $data;
}
}
Loading…
Cancel
Save