You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.9 KiB

  1. <?php
  2. class RepositoryGit extends RepositoryBase {
  3. function __construct ($id, $def) {
  4. parent::__construct($id, $def);
  5. $this->branch = $def['branch'] ?? 'HEAD';
  6. $this->branchEsc = escapeShellArg($this->branch);
  7. }
  8. function timestamp () {
  9. $ts = (int)shell_exec("cd " . escapeShellArg($this->path) . "; git log -1 {$this->branchEsc} --pretty=format:%ct");
  10. return $ts;
  11. }
  12. function data () {
  13. $data = parent::data();
  14. $d = popen("cd " . escapeShellArg($this->path) . "; git ls-tree {$this->branchEsc}", "r");
  15. while ($r = fgets($d)) {
  16. if (preg_match("/^[0-9]{6} blob [0-9a-f]{40}\t(([0-9a-zA-Z_\-]+)\.json)$/", $r, $m)) {
  17. $f = $m[1];
  18. $id = $m[2];
  19. if ($f === 'package.json') {
  20. continue;
  21. }
  22. $d1 = json_decode(shell_exec("cd " . escapeShellArg($this->path) . "; git show {$this->branchEsc}:" . escapeShellArg($f)), true);
  23. if (!$this->isCategory($d1)) {
  24. continue;
  25. }
  26. $data['categories'][$id] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const'))));
  27. }
  28. if (preg_match("/^[0-9]{6} blob [0-9a-f]{40}\t((detailsBody|popupBody)\.html)$/", $r, $m)) {
  29. $data['templates'][$m[2]] = shell_exec("cd " . escapeShellArg($this->path) . "; git show {$this->branchEsc}:" . escapeShellArg($m[1]));
  30. }
  31. }
  32. pclose($d);
  33. return $data;
  34. }
  35. function scandir($path="") {
  36. if ($path !== '' && substr($path, -1) !== '/') {
  37. $path .= '/';
  38. }
  39. $d = popen("cd " . escapeShellArg($this->path) . "; git ls-tree {$this->branchEsc} " . escapeShellArg($path), "r");
  40. $ret = array();
  41. while ($r = fgets($d)) {
  42. $ret[] = chop(substr($r, 53));
  43. }
  44. pclose($d);
  45. return $ret;
  46. }
  47. function file_get_contents ($file) {
  48. return shell_exec("cd " . escapeShellArg($this->path) . "; git show {$this->branchEsc}:" . escapeShellArg($file));
  49. }
  50. }