[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/2] xen/misra: diff-report.py: Fix UnifiedFormatParser change line registration



On Tue, 18 Jul 2023, Luca Fancellu wrote:
> Fix the line number on the registration of a 'remove' change type when
> consecutive 'remove' changes are registered.
> 
> Currently the algorithm registers consecutive 'remove' changes at the same
> line it encounter the first one, 'add' changes type are not affected by the
> bug.
> 
> Fixes: 1d7c45f895b6 ("xen/misra: diff-report.py: add report patching feature")
> Signed-off-by: Luca Fancellu <luca.fancellu@xxxxxxx>

Acked-by: Stefano Stabellini <sstabellini@xxxxxxxxxx>


> ---
>  .../xen_analysis/diff_tool/unified_format_parser.py        | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/scripts/xen_analysis/diff_tool/unified_format_parser.py 
> b/xen/scripts/xen_analysis/diff_tool/unified_format_parser.py
> index 8b3fbc318df7..6c506caeafce 100644
> --- a/xen/scripts/xen_analysis/diff_tool/unified_format_parser.py
> +++ b/xen/scripts/xen_analysis/diff_tool/unified_format_parser.py
> @@ -144,6 +144,7 @@ class UnifiedFormatParser(object):
>          file_linenum = 0
>          hunk_a_linemax = 0
>          hunk_b_linemax = 0
> +        consecutive_remove = 0
>          diff_elem = None
>          parse_state = ParserState.FIND_DIFF_HEADER
>          ChangeMode = ChangeSet.ChangeMode
> @@ -210,14 +211,18 @@ class UnifiedFormatParser(object):
>                  if (hunk_b_linemax > 0) and line.startswith("+"):
>                      diff_elem.add_change(file_linenum, ChangeType.ADD)
>                      hunk_b_linemax -= 1
> +                    consecutive_remove = 0
>                  elif (hunk_a_linemax > 0) and line.startswith("-"):
> -                    diff_elem.add_change(file_linenum, ChangeType.REMOVE)
> +                    diff_elem.add_change(file_linenum + consecutive_remove,
> +                                         ChangeType.REMOVE)
>                      hunk_a_linemax -= 1
>                      file_linenum -= 1
> +                    consecutive_remove += 1
>                  elif ((hunk_a_linemax + hunk_b_linemax) > 0) and \
>                          line.startswith(" "):
>                      hunk_a_linemax -= 1 if (hunk_a_linemax > 0) else 0
>                      hunk_b_linemax -= 1 if (hunk_b_linemax > 0) else 0
> +                    consecutive_remove = 0
>  
>                  if (hunk_a_linemax + hunk_b_linemax) <= 0:
>                      parse_state = ParserState.FIND_HUNK_OR_DIFF_HEADER
> -- 
> 2.34.1
> 



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.