From 1c9a90571a6712dc59acafc9719cabb0599b904d Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Tue, 16 Jun 2026 23:16:55 +0200 Subject: parse multiline commit message --- index.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index fb64f51..0dc1f88 100644 --- a/index.php +++ b/index.php @@ -52,7 +52,7 @@ function parse_log(string $path): array { $proxy = md5(strval(microtime(true))); $process = proc_open( - "git -C \"{$path}\" log " . "--pretty=format:'{%n {$proxy}commit{$proxy}: {$proxy}%H{$proxy},%n {$proxy}author{$proxy}: {$proxy}%aN <%aE>{$proxy},%n {$proxy}date{$proxy}: {$proxy}%ad{$proxy},%n {$proxy}message{$proxy}: {$proxy}%s{$proxy}%n},'", + "git -C \"{$path}\" log " . "--pretty=format:'{{$proxy}commit{$proxy}: {$proxy}%H{$proxy}, {$proxy}author{$proxy}: {$proxy}%aN <%aE>{$proxy}, {$proxy}date{$proxy}: {$proxy}%ad{$proxy}, {$proxy}message{$proxy}: {$proxy}%B{$proxy}},'", [ ["pipe", "r"], ["pipe", "w"], @@ -62,7 +62,13 @@ function parse_log(string $path): array { ); $output = stream_get_contents($pipes[1]); - $string = str_replace(['"', $proxy], ['\\"', '"'], $output); + + // remove git-added newlines + $string = str_replace("},\n{", "},{", $output); + $string = rtrim($string, "\n"); + + $string = str_replace("\n", "\\n", $string); + $string = str_replace(['"', $proxy], ['\\"', '"'], $string); $string = "[" . rtrim($string, ",") . "]"; $json = json_decode($string, true); @@ -527,7 +533,7 @@ elseif (str_ends_with($url["path"], "/log")) { - +