login/commits: git show of hash parameter
[minimedit.git] / widget / login / commits.php
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,
        ]);
 }