Skip to content

Commit e36a3e0

Browse files
committed
Smaller diffs
1 parent 9b46a60 commit e36a3e0

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

.github/scripts/diffPrefixes.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php declare(strict_types = 1);
22

3+
use Nette\Utils\Strings;
34
use SebastianBergmann\Diff\Differ;
45

56
require_once __DIR__ . '/../../vendor/autoload.php';
@@ -20,7 +21,7 @@
2021
}
2122

2223
$diffLines = explode("\n", file_get_contents($diffFile));
23-
$differ = new Differ(new \SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder(''));
24+
$differ = new Differ(new \SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder('', true));
2425
$isDifferent = false;
2526
foreach ($diffLines as $diffLine) {
2627
$operation = $diffLine[0];
@@ -48,7 +49,20 @@
4849
$isDifferent = true;
4950

5051
echo "$path:\n";
51-
foreach (explode("\n", $stringDiff) as $line) {
52+
$startLine = 1;
53+
$startContext = 1;
54+
foreach (explode("\n", $stringDiff) as $i => $line) {
55+
$matches = Strings::match($line, '/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@/');
56+
if ($matches !== null) {
57+
$startLine = (int) $matches[1];
58+
$startContext = (int) $matches[2];
59+
continue;
60+
}
61+
62+
if ($lineNumber < $startLine || $lineNumber > ($startLine + $startContext)) {
63+
continue;
64+
}
65+
5266
if (str_starts_with($line, '+')) {
5367
echo "\033[32m$line\033[0m\n";
5468
} elseif (str_starts_with($line, '-')) {

0 commit comments

Comments
 (0)