From e4bb6ec3ef156d2dc78f541e536d6be6ebc241db Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Tue, 29 Oct 2024 05:35:01 +0100 Subject: [PATCH 1/2] update npm dependencies (#7067) --- package.json | 4 ++-- src/git/zcl_abapgit_git_pack.clas.abap | 10 +++++++--- ...zcl_abapgit_integration_gitv2.clas.testclasses.abap | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 97531acfb..8811523c1 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ ] }, "devDependencies": { - "@abaplint/cli": "^2.113.21", + "@abaplint/cli": "^2.113.31", "@abaplint/database-sqlite": "^2.10.20", "@abaplint/runtime": "^2.10.20", "express": "^4.21.1", @@ -31,6 +31,6 @@ "globals": "^15.11.0", "abapmerge": "^0.16.6", "c8": "^10.1.2", - "eslint": "^9.12.0" + "eslint": "^9.13.0" } } diff --git a/src/git/zcl_abapgit_git_pack.clas.abap b/src/git/zcl_abapgit_git_pack.clas.abap index cdea8850f..a8799b0e3 100644 --- a/src/git/zcl_abapgit_git_pack.clas.abap +++ b/src/git/zcl_abapgit_git_pack.clas.abap @@ -178,14 +178,18 @@ CLASS zcl_abapgit_git_pack IMPLEMENTATION. lv_data = iv_data. * header - IF NOT xstrlen( lv_data ) > 4 OR lv_data(4) <> c_pack_start. - zcx_abapgit_exception=>raise( |Unexpected pack header| ). + IF xstrlen( lv_data ) < 4. + zcx_abapgit_exception=>raise( |Unexpected pack header, short reply| ). + ENDIF. + + IF lv_data(4) <> c_pack_start. + zcx_abapgit_exception=>raise( |Unexpected pack header, { lv_data(4) }| ). ENDIF. lv_data = lv_data+4. * version IF lv_data(4) <> c_version. - zcx_abapgit_exception=>raise( |Version not supported| ). + zcx_abapgit_exception=>raise( |Version not supported, { lv_data(4) }| ). ENDIF. lv_data = lv_data+4. diff --git a/test/src/zcl_abapgit_integration_gitv2.clas.testclasses.abap b/test/src/zcl_abapgit_integration_gitv2.clas.testclasses.abap index 4f182595f..b8844d0ae 100644 --- a/test/src/zcl_abapgit_integration_gitv2.clas.testclasses.abap +++ b/test/src/zcl_abapgit_integration_gitv2.clas.testclasses.abap @@ -48,7 +48,8 @@ CLASS ltcl_test IMPLEMENTATION. DATA lt_objects TYPE zif_abapgit_definitions=>ty_objects_tt. DATA lt_sha1 TYPE zif_abapgit_git_definitions=>ty_sha1_tt. - INSERT '7bdd8f9f4c6bb0ece461b78c7b559957fad6c3ae' INTO TABLE lt_sha1. +* todo, given the sha1, this test might fail after a year? + INSERT 'e83a31ebafde4e8e7e80ca36662e42e8f20895c5' INTO TABLE lt_sha1. lt_objects = zcl_abapgit_git_factory=>get_v2_porcelain( )->commits_last_year( iv_url = 'https://github.com/abapGit/abapGit.git' From 57d785ac98b6a4b44b157dcd3f587725a75fad04 Mon Sep 17 00:00:00 2001 From: Marc Bernard <59966492+mbtools@users.noreply.github.com> Date: Tue, 29 Oct 2024 00:40:08 -0400 Subject: [PATCH 2/2] Show diffs in case of trailing spaces (#7062) Co-authored-by: Lars Hvam --- src/utils/zcl_abapgit_diff.clas.abap | 82 ++++++++++++++----- .../zcl_abapgit_diff.clas.testclasses.abap | 7 ++ 2 files changed, 67 insertions(+), 22 deletions(-) diff --git a/src/utils/zcl_abapgit_diff.clas.abap b/src/utils/zcl_abapgit_diff.clas.abap index 33f73e2b7..a3319f1eb 100644 --- a/src/utils/zcl_abapgit_diff.clas.abap +++ b/src/utils/zcl_abapgit_diff.clas.abap @@ -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: - LIKE LINE OF it_old, - LIKE LINE OF it_new, LIKE LINE OF lt_delta. " Note: Ignore case is for keywords, variables, types etc, but not for literals @@ -245,22 +249,9 @@ CLASS zcl_abapgit_diff IMPLEMENTATION. APPEND ls_diff TO rt_diff. ENDLOOP. ELSEIF sy-subrc = 2. - " Copy input... but it might not be identical - LOOP AT it_old ASSIGNING . - CLEAR ls_diff. - ls_diff-old_num = sy-tabix. - ls_diff-old = . - READ TABLE it_new ASSIGNING INDEX sy-tabix. - ASSERT sy-subrc = 0. - ls_diff-new_num = sy-tabix. - ls_diff-new = . - " SAP function ignores lines that contain only whitespace so we compare directly - IF ( mv_compare_mode = 1 OR mv_compare_mode = 3 ) AND <> AND - ( strlen( condense( ) ) = 0 OR strlen( condense( ) ) = 0 ). - ls_diff-result = zif_abapgit_definitions=>c_diff-update. - ENDIF. - APPEND ls_diff TO rt_diff. - ENDLOOP. + " 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. @@ -268,6 +259,53 @@ CLASS zcl_abapgit_diff IMPLEMENTATION. 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: + LIKE LINE OF it_old, + LIKE LINE OF it_new. + + LOOP AT it_old ASSIGNING . + CLEAR ls_diff. + ls_diff-old_num = sy-tabix. + ls_diff-old = . + READ TABLE it_new ASSIGNING INDEX sy-tabix. + IF sy-subrc <> 0. + EXIT. + ENDIF. + ls_diff-new_num = sy-tabix. + ls_diff-new = . + " SAP function ignores lines that contain only whitespace so we compare directly + " Also check if one line has trailing space(s) + IF ( mv_compare_mode = 1 OR mv_compare_mode = 3 ) AND <> . + + IF strlen( condense( ) ) = 0 OR strlen( condense( ) ) = 0. + + ls_diff-result = zif_abapgit_definitions=>c_diff-update. + + ELSEIF strlen( ) > 0 AND strlen( ) > 0. + + lv_last_new = substring( val = + off = strlen( ) - 1 ). + lv_last_old = substring( val = + off = strlen( ) - 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. + + ENDMETHOD. + + METHOD constructor. DATA: lt_new TYPE rswsourcet, @@ -287,8 +325,8 @@ CLASS zcl_abapgit_diff IMPLEMENTATION. IMPORTING et_new = lt_new et_old = lt_old ). - mt_diff = compute_and_render( it_new = lt_new - it_old = lt_old ). + mt_diff = compute_diff( it_new = lt_new + it_old = lt_old ). adjust_diff( ). diff --git a/src/utils/zcl_abapgit_diff.clas.testclasses.abap b/src/utils/zcl_abapgit_diff.clas.testclasses.abap index 074709fb7..2746a78ae 100644 --- a/src/utils/zcl_abapgit_diff.clas.testclasses.abap +++ b/src/utils/zcl_abapgit_diff.clas.testclasses.abap @@ -528,12 +528,14 @@ CLASS ltcl_diff IMPLEMENTATION. add_new( ` ` ). " one space add_new( ` ` ). " some spaces add_new( 'E' ). + add_new( 'X' ). " no trailing space add_old( 'A' ). add_old( ` ` ). " some spaces add_old( ` ` ). " two spaces add_old( `` ). " empty line add_old( 'E' ). + add_old( `X ` ). " some trailing space add_expected( iv_new_num = ' 1' iv_new = 'A' @@ -560,6 +562,11 @@ CLASS ltcl_diff IMPLEMENTATION. iv_result = zif_abapgit_definitions=>c_diff-unchanged iv_old_num = ' 5' iv_old = 'E' ). + add_expected( iv_new_num = ' 6' + iv_new = 'X' + iv_result = zif_abapgit_definitions=>c_diff-update + iv_old_num = ' 6' + iv_old = `X ` ). test( ).