-
-
Notifications
You must be signed in to change notification settings - Fork 74
Description
If a file change reduces the contents of a file from many lines to just one (e.g. compiled JS), the $rangeNewCount variable is given an inappropriate value.
This is because the git diff header for a single-line file excludes the length as there is no context available, e.g.:
@@ -1,121 +1 @@
However, in DiffParser:107:
$rangeNewCount = isset($vars[4]) ? (int) $vars[4] : (int) $vars[2]; // @todo Ici, t'as pris un gros raccourci mon loulou(Nice TODO 😉)
Using $vars[2] here is basically using $rangeOldCount. So for the chunk header in the example above, $rangeNewCount => 121, which is incorrect as the diff format indicates that this will be a single line change.
What may be better in this case (imo) is to simply use the value 1, which would indicate more completely that this is a single line change and that there is no context other than the line of change:
$rangeNewCount = $vars[4] ?? 1;Aside
This same logic could apply to the $rangeOldCount too, where it could be excluded because it is a single line file with no context available. Consider:
@@ -1 +1 @@
However, for a single-line file where the change results in a single-line file, the DiffParser logic will continue to look correct, because everything ($rangeOldCount, $rangeNewStart, $rangeNewCount) will just say 1, but this is kind of 'by mistake'.
This would make $rangeOldCount => 0 (and thus $rangeNewCount => 0) which I believe is also incorrect.