Show diffs in case of trailing spaces

This commit is contained in:
Marc Bernard 2024-10-21 16:16:35 +00:00
parent b1abcd8764
commit baaa2ccb48

View File

@ -75,7 +75,13 @@ CLASS zcl_abapgit_diff DEFINITION
METHODS create_regex_set
RETURNING
VALUE(rt_regex_set) TYPE ty_regexset_tt.
METHODS compute_and_render
METHODS compute_diff
IMPORTING
!it_new TYPE rswsourcet
!it_old TYPE rswsourcet
RETURNING
VALUE(rt_diff) TYPE zif_abapgit_definitions=>ty_diffs_tt.
METHODS compute_diff_extra
IMPORTING
!it_new TYPE rswsourcet
!it_old TYPE rswsourcet
@ -187,7 +193,7 @@ CLASS zcl_abapgit_diff IMPLEMENTATION.
ENDMETHOD.
METHOD compute_and_render.
METHOD compute_diff.
DATA:
lv_i TYPE i,
@ -195,8 +201,6 @@ CLASS zcl_abapgit_diff IMPLEMENTATION.
lt_delta TYPE STANDARD TABLE OF rsedcresul WITH DEFAULT KEY.
FIELD-SYMBOLS:
<ls_old> LIKE LINE OF it_old,
<ls_new> LIKE LINE OF it_new,
<ls_delta> LIKE LINE OF lt_delta.
" Note: Ignore case is for keywords, variables, types etc, but not for literals
@ -245,25 +249,59 @@ CLASS zcl_abapgit_diff IMPLEMENTATION.
APPEND ls_diff TO rt_diff.
ENDLOOP.
ELSEIF sy-subrc = 2.
" Copy input... but it might not be identical
" The function doesn't find all diffs...
rt_diff = compute_diff_extra( it_new = it_new
it_old = it_old ).
ELSE.
ASSERT 0 = 1. " incorrect function call
ENDIF.
ENDMETHOD.
METHOD compute_diff_extra.
DATA:
lv_last_new TYPE c LENGTH 1,
lv_last_old TYPE c LENGTH 1,
ls_diff LIKE LINE OF rt_diff.
FIELD-SYMBOLS:
<ls_old> LIKE LINE OF it_old,
<ls_new> LIKE LINE OF it_new.
LOOP AT it_old ASSIGNING <ls_old>.
CLEAR ls_diff.
ls_diff-old_num = sy-tabix.
ls_diff-old = <ls_old>.
READ TABLE it_new ASSIGNING <ls_new> INDEX sy-tabix.
ASSERT sy-subrc = 0.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ls_diff-new_num = sy-tabix.
ls_diff-new = <ls_new>.
" SAP function ignores lines that contain only whitespace so we compare directly
IF ( mv_compare_mode = 1 OR mv_compare_mode = 3 ) AND <ls_old> <> <ls_new> AND
( strlen( condense( <ls_old> ) ) = 0 OR strlen( condense( <ls_new> ) ) = 0 ).
" Also check if one line has trailing space(s)
IF ( mv_compare_mode = 1 OR mv_compare_mode = 3 ) AND <ls_old> <> <ls_new>.
IF strlen( condense( <ls_old> ) ) = 0 OR strlen( condense( <ls_new> ) ) = 0.
ls_diff-result = zif_abapgit_definitions=>c_diff-update.
ELSEIF strlen( <ls_old> ) > 0 AND strlen( <ls_new> ) > 0.
lv_last_new = substring( val = <ls_new>
off = strlen( <ls_new> ) - 1 ).
lv_last_old = substring( val = <ls_old>
off = strlen( <ls_old> ) - 1 ).
IF lv_last_new = space OR lv_last_old = space.
ls_diff-result = zif_abapgit_definitions=>c_diff-update.
ENDIF.
ENDIF.
ENDIF.
APPEND ls_diff TO rt_diff.
ENDLOOP.
ELSE.
ASSERT 0 = 1. " incorrect function call
ENDIF.
ENDMETHOD.
@ -287,7 +325,7 @@ CLASS zcl_abapgit_diff IMPLEMENTATION.
IMPORTING et_new = lt_new
et_old = lt_old ).
mt_diff = compute_and_render( it_new = lt_new
mt_diff = compute_diff( it_new = lt_new
it_old = lt_old ).
adjust_diff( ).