From 52360503b4bb17c9d77d65d07a9493306a7499de Mon Sep 17 00:00:00 2001 From: Ilias Dimopoulos Date: Tue, 3 Jun 2025 23:08:41 +0300 Subject: [PATCH 1/3] Skip third party unsupported headers. --- src/Gitonomy/Git/Parser/LogParser.php | 12 ++++++++ tests/Gitonomy/Git/Tests/LogTest.php | 43 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/Gitonomy/Git/Parser/LogParser.php b/src/Gitonomy/Git/Parser/LogParser.php index 53e5b16..324224d 100644 --- a/src/Gitonomy/Git/Parser/LogParser.php +++ b/src/Gitonomy/Git/Parser/LogParser.php @@ -51,6 +51,7 @@ protected function doParse() $this->consumeGPGSignature(); $this->consumeNewLine(); + $this->consumeUnsupportedLinesToNewLine(); if ($this->cursor < strlen($this->content)) { $this->consumeNewLine(); } @@ -76,4 +77,15 @@ protected function doParse() $this->log[] = $commit; } } + + protected function consumeUnsupportedLinesToNewLine() { + // Consume any unsupported lines that may appear in the log output. For + // example, gitbutler headers or other custom metadata but this should + // work regardless of the content. + while (!$this->isFinished() && substr($this->content, $this->cursor, 1) !== "\n") { + $this->consumeTo("\n"); + $this->consumeNewLine(); + } + } + } diff --git a/tests/Gitonomy/Git/Tests/LogTest.php b/tests/Gitonomy/Git/Tests/LogTest.php index 970e55c..b6cf50d 100644 --- a/tests/Gitonomy/Git/Tests/LogTest.php +++ b/tests/Gitonomy/Git/Tests/LogTest.php @@ -12,6 +12,8 @@ namespace Gitonomy\Git\Tests; +use Gitonomy\Git\Parser\LogParser; + class LogTest extends AbstractTest { /** @@ -91,4 +93,45 @@ public function testFirstMessageEmpty() $commits = $repository->getLog()->getCommits(); $this->assertCount(1, $commits); } + + public function testParsesCommitsWithAndWithoutGitButlerHeaders(): void + { + $logContent = << 1620000000 +0000 + committer John Doe 1620000000 +0000 + + First commit message + + commit 2222222222222222222222222222222222222222 + tree abcdefabcdefabcdefabcdefabcdefabcdefabcd + parent 1111111111111111111111111111111111111111 + author Jane Smith 1620003600 +0000 + committer Jane Smith 1620003600 +0000 + gitbutler-headers-version: 2 + gitbutler-change-id: a7bd485c-bae6-45b2-910f-163c78aace81 + + Commit with GitButler headers + + commit 3333333333333333333333333333333333333333 + tree abcdefabcdefabcdefabcdefabcdefabcdefabcd + author John Doe 1620007200 +0000 + committer Jane Smith 1620007200 +0000 + + Another commit without GitButler headers + + EOT; + + $parser = new LogParser(); + $parser->parse($logContent); + + $log = $parser->log; + $this->assertCount(3, $log); + + $this->assertEquals("First commit message\n", $log[0]['message']); + $this->assertEquals("Commit with GitButler headers\n", $log[1]['message']); + $this->assertEquals("Another commit without GitButler headers\n", $log[2]['message']); + } + } From d28ad22254b6958e25eb4ec55ff7e516febf09d2 Mon Sep 17 00:00:00 2001 From: Ilias Dimopoulos Date: Tue, 3 Jun 2025 23:24:10 +0300 Subject: [PATCH 2/3] Fix sniff remarks. --- src/Gitonomy/Git/Parser/LogParser.php | 3 ++- tests/Gitonomy/Git/Tests/LogTest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Gitonomy/Git/Parser/LogParser.php b/src/Gitonomy/Git/Parser/LogParser.php index 324224d..f90b969 100644 --- a/src/Gitonomy/Git/Parser/LogParser.php +++ b/src/Gitonomy/Git/Parser/LogParser.php @@ -78,7 +78,8 @@ protected function doParse() } } - protected function consumeUnsupportedLinesToNewLine() { + protected function consumeUnsupportedLinesToNewLine() + { // Consume any unsupported lines that may appear in the log output. For // example, gitbutler headers or other custom metadata but this should // work regardless of the content. diff --git a/tests/Gitonomy/Git/Tests/LogTest.php b/tests/Gitonomy/Git/Tests/LogTest.php index b6cf50d..1e7295e 100644 --- a/tests/Gitonomy/Git/Tests/LogTest.php +++ b/tests/Gitonomy/Git/Tests/LogTest.php @@ -96,7 +96,7 @@ public function testFirstMessageEmpty() public function testParsesCommitsWithAndWithoutGitButlerHeaders(): void { - $logContent = << 1620000000 +0000 From b62ae0c0ec3fdcc39cc8b1d0a1aadabecef2c45a Mon Sep 17 00:00:00 2001 From: Ilias Dimopoulos Date: Tue, 3 Jun 2025 23:50:19 +0300 Subject: [PATCH 3/3] Sniffs fix v2. --- src/Gitonomy/Git/Parser/LogParser.php | 1 - tests/Gitonomy/Git/Tests/LogTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Gitonomy/Git/Parser/LogParser.php b/src/Gitonomy/Git/Parser/LogParser.php index f90b969..67b8668 100644 --- a/src/Gitonomy/Git/Parser/LogParser.php +++ b/src/Gitonomy/Git/Parser/LogParser.php @@ -88,5 +88,4 @@ protected function consumeUnsupportedLinesToNewLine() $this->consumeNewLine(); } } - } diff --git a/tests/Gitonomy/Git/Tests/LogTest.php b/tests/Gitonomy/Git/Tests/LogTest.php index 1e7295e..a02184d 100644 --- a/tests/Gitonomy/Git/Tests/LogTest.php +++ b/tests/Gitonomy/Git/Tests/LogTest.php @@ -133,5 +133,4 @@ public function testParsesCommitsWithAndWithoutGitButlerHeaders(): void $this->assertEquals("Commit with GitButler headers\n", $log[1]['message']); $this->assertEquals("Another commit without GitButler headers\n", $log[2]['message']); } - }