login/commits: git show of hash parameter
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 15 Jan 2021 09:24:40 +0000 (10:24 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 27 Apr 2021 00:48:25 +0000 (02:48 +0200)
Link overview to further details, currently unformatted.

login/commits/index.php [new file with mode: 0644]
widget/login/commits.php

diff --git a/login/commits/index.php b/login/commits/index.php
new file mode 100644 (file)
index 0000000..c53bf39
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+if (!$User->admin('edit')) {
+       require '403.inc.html';
+       return;
+}
+
+$hash = ltrim($Page->path, '/');
+if (!$hash) {
+       return TRUE;
+}
+
+print "<h2>Wijzigingen in $hash</h2>\n";
+
+$gitcmd = "git show ".$hash;
+$log = popen($gitcmd, 'r');
+if (!$log or strpos(fgets($log), "commit $hash") !== 0) {
+       $Page->place['warn'] = "Kon inhoud niet ophalen met <code>$gitcmd</code>";
+       return;
+}
+
+print '<pre>';
+while ( $line = fgets($log) ) {
+       print htmlspecialchars($line);
+}
+print "</pre>\n";
+
+pclose($log);
+return;
index 18447a7091a006fec841496f87474aa71aaf022a..2060a33158775b434ce2003a4e542769114334bd 100644 (file)
@@ -4,8 +4,9 @@ if (!function_exists('popen')) {
        return;
 }
 
+$baseurl = 'login/commits';
 $pagesize = intval(@$Page->place['n'] ?: @$_GET['n']) ?: 20;
-$gitcmd = "git log -n $pagesize --pretty='%at\t%an\t%s'";
+$gitcmd = "git log -n $pagesize --pretty='%h\t%at\t%an\t%s'";
 
 if ( $offset = intval(@$_GET['start']) ) {
        $gitcmd .= " --skip=$offset";
@@ -15,12 +16,16 @@ if ( $log = popen($gitcmd, 'r') ) {
        $lines = 0;
        print "<ul>\n";
        while ( $line = fgets($log) ) {
-               list ($atime, $author, $message) = explode("\t", $line, 3);
+               list ($id, $atime, $author, $message) = explode("\t", $line, 4);
                list ($author) = explode(' ', $author); # first name only
-               printf('<li>%s <small class="date">%s • %s</small></li>'."\n",
-                       htmlspecialchars($message),
+               $html = htmlspecialchars(rtrim($message));
+               $html .= sprintf(' <small class="date">%s • %s</small>',
                        htmlspecialchars($author), strftime('%F %H:%M', $atime)
                );
+               $html = sprintf('<a href="%s">%s</a>',
+                       "/$baseurl/$id", $html
+               );
+               print "<li>$html</li>\n";
                $lines++;
        }
        print "</ul>\n\n";
@@ -29,6 +34,6 @@ if ( $log = popen($gitcmd, 'r') ) {
        $limit = $offset + $lines + 1; # assume one more
        print $Page->widget('nav', [
                'start' => $offset, 'n' => $pagesize, 'total' => $limit,
-               'link' => $Page->link != 'login/commits' ? 'login/commits' : '',
+               'link' => $Page->link == $baseurl ? NULL : $baseurl,
        ]);
 }