X-Git-Url: http://git.shiar.nl/minimedit.git/blobdiff_plain/fe92ec8f17c832c4a663aea399dc90a4c09ce6b1..95b037f55a21f6bd70c50801f5c6b0a23daee27c:/login/commits/index.php diff --git a/login/commits/index.php b/login/commits/index.php index 75ff7a5..dbd8cd9 100644 --- a/login/commits/index.php +++ b/login/commits/index.php @@ -1,2 +1,127 @@ admin('edit')) { + require '403.inc.html'; + return; +} + +$hash = ltrim($Page->path, '/'); +if (!$hash) { + return TRUE; +} + +$this->title = "Wijzigingen in ".strtoupper($hash); +print "

{$this->title}

\n"; + +$gitcmd = "git show " + . "--word-diff=porcelain --no-prefix --pretty='%H%n%at\t%an\t%w(0,0,1)%B' " + . escapeshellarg($hash); +$log = popen($gitcmd, 'r'); +if (!$log or strpos(fgets($log), $hash) !== 0) { + $Page->place['warn'] = "Kon inhoud niet ophalen met $gitcmd"; + return; +} + +# read metadata and commit message +list ($atime, $author, $msg) = explode("\t", fgets($log), 3); +while ( $line = fgets($log) ) { + if ($line == "\n") { + fgets($log); // assume another empty line + break; + } + $msg .= substr($line, 1); +} + +# commit head +print '

'; +printf('%s • %s', + htmlspecialchars($author), strftime('%F %H:%M', $atime) +); +print "\n".nl2br(htmlspecialchars($msg)); +print "

\n"; + +print ''; + +# body +$row = $ln = NULL; +$col = ['', '']; +print ''; +while ( $line = fgets($log) ) { + preg_match(isset($ln) ? '/^(\W|\S+ )(.*)/' : '/^(\S+ )(.*)/', $line, $part); + $body = htmlspecialchars($part[2]); + switch ($part[1]) { + case 'diff ': + # file start + if (preg_match('/^--git (.+) (.*)/', $part[2], $diffhead)) { + $row = "$diffhead[1]"; + if ($diffhead[1] !== $diffhead[2]) { + $row .= " → $diffhead[2]"; + } + } + else { + $row = '?'; + } + $ln = NULL; + break; + case '@@ ': + # chunk start + if (preg_match('/^[-](\d+)(?:,\d+)? [+](\d+)(?:,\d+)? @@/', $part[2], $diffstart)) { + array_shift($diffstart); + $ln = $diffstart; + } + else { + $ln = ['?', '?']; # unrecognised diff header + } + print ''."\n"; + break; + case '-': + $col[0] .= "$body"; + break; + case '+': + $col[1] .= "$body"; + break; + case ' ': + $col[0] .= $body; + $col[1] .= $body; + break; + case '~': + # part end + print ''; + foreach ($col as $i => $line) { + if (empty($line)) { + print '%s', + $ln[$i]++, + $col[0] == $col[1] ? '' : ' class="change"', + $line + ); + } + print "\n"; + $col = ['', '']; + break; + } +} +print "
'.$row.'
'; + continue; + } + printf('%s
\n"; +pclose($log); + +return;