[m-rev.] for post-commit review: change hunks
Julien Fischer
jfischer at opturion.com
Sat Jun 29 01:39:21 AEST 2019
On Fri, 28 Jun 2019, Zoltan Somogyi wrote:
> For post-commit review by Julien.
> Compute change hunks from diff sequences.
...
> diff --git a/library/edit_seq.m b/library/edit_seq.m
> index dd606f689..1593889b2 100644
> --- a/library/edit_seq.m
> +++ b/library/edit_seq.m
...
> @@ -351,6 +432,156 @@ flush_deletes_inserts(!Deletes, !Inserts, !Diffs) :-
> !:Deletes = cord.init,
> !:Inserts = cord.init.
>
> +%---------------------------------------------------------------------------%
> +%---------------------------------------------------------------------------%
> +
> +find_change_hunks(ContextSize0, Diffs, CHunks) :-
> + % If our caller passes us an invalid ContextSize0, we replace it
> + % with the default context size 3.
> + % XXX Would programmers prefer us to throw an exception here?
I think so; whichever approach is chosen should be documented.
> + ( if ContextSize0 > 0 then
> + ContextSize = ContextSize0
> + else
> + ContextSize = 3
> + ),
> + find_change_hunks_loop(ContextSize, Diffs, 1, 1, [], RevCHunks),
> + list.reverse(RevCHunks, CHunks).
> +
...
> +
> +:- pred scan_change_hunk_diffs(int::in, list(diff(T))::in, list(diff(T))::out,
> + list(diff(T))::in, list(diff(T))::out,
> + int::in, int::out, int::in, int::out,
> + int::in, int::out, int::in, int::out) is det.
> +
> +scan_change_hunk_diffs(ContextSize, Diffs, LeftOverDiffs, !RevCHunkDiffs,
> + !NumDeleted, !NumInserted, !NumUnchanged, !NumContigUnchanged) :-
> + (
> + Diffs = [],
> + LeftOverDiffs = []
> + ;
> + Diffs = [HeadDiff | TailDiffs],
> + (
> + HeadDiff = unchanged(_),
> + ( if ContextSize =< !.NumContigUnchanged then
> + ( if
> + scan_joined_context(ContextSize, Diffs, AfterContextDiffs,
> + !RevCHunkDiffs, !NumUnchanged)
> + then
> + !:NumContigUnchanged = 0,
> + scan_change_hunk_diffs(ContextSize, AfterContextDiffs,
> + LeftOverDiffs,
> + !RevCHunkDiffs, !NumDeleted, !NumInserted,
> + !NumUnchanged, !NumContigUnchanged)
> + else
> + LeftOverDiffs = Diffs
> + )
> + else
> + !:RevCHunkDiffs = [HeadDiff | !.RevCHunkDiffs],
> + !:NumUnchanged = !.NumUnchanged + 1,
> + !:NumContigUnchanged = !.NumContigUnchanged + 1,
> + scan_change_hunk_diffs(ContextSize, TailDiffs, LeftOverDiffs,
> + !RevCHunkDiffs, !NumDeleted, !NumInserted,
> + !NumUnchanged, !NumContigUnchanged)
> + )
> + ;
> + HeadDiff = deleted(_),
> + !:RevCHunkDiffs = [HeadDiff | !.RevCHunkDiffs],
> + !:NumDeleted = !.NumDeleted + 1,
> + !:NumContigUnchanged = 0,
> + scan_change_hunk_diffs(ContextSize, TailDiffs, LeftOverDiffs,
> + !RevCHunkDiffs, !NumDeleted, !NumInserted,
> + !NumUnchanged, !NumContigUnchanged)
> + ;
> + HeadDiff = inserted(_),
> + !:RevCHunkDiffs = [HeadDiff | !.RevCHunkDiffs],
> + !:NumInserted = !.NumInserted + 1,
> + !:NumContigUnchanged = 0,
> + scan_change_hunk_diffs(ContextSize, TailDiffs, LeftOverDiffs,
> + !RevCHunkDiffs, !NumDeleted, !NumInserted,
> + !NumUnchanged, !NumContigUnchanged)
> + )
> + ).
> +
> + % If
That comment is perhaps a touch too concise.
> +:- pred scan_joined_context(int::in, list(diff(T))::in, list(diff(T))::out,
> + list(diff(T))::in, list(diff(T))::out, int::in, int::out) is semidet.
The diff is fine otherwise.
Julien.
More information about the reviews
mailing list