File status refactoring, part 1 (#6114)

Co-authored-by: Marc Bernard <59966492+mbtools@users.noreply.github.com>
Co-authored-by: Lars Hvam <larshp@hotmail.com>
This commit is contained in:
Alexander Tsybulsky 2023-03-02 18:55:22 +02:00 committed by GitHub
parent 7ff6b9684b
commit 6fad60afb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 275 additions and 169 deletions

View File

@ -1,7 +1,7 @@
CLASS zcl_abapgit_file_status DEFINITION CLASS zcl_abapgit_file_status DEFINITION
PUBLIC PUBLIC
FINAL FINAL
CREATE PUBLIC . CREATE PRIVATE .
PUBLIC SECTION. PUBLIC SECTION.
@ -13,13 +13,19 @@ CLASS zcl_abapgit_file_status DEFINITION
VALUE(rt_results) TYPE zif_abapgit_definitions=>ty_results_tt VALUE(rt_results) TYPE zif_abapgit_definitions=>ty_results_tt
RAISING RAISING
zcx_abapgit_exception . zcx_abapgit_exception .
METHODS constructor
IMPORTING
!iv_root_package TYPE devclass
!io_dot TYPE REF TO zcl_abapgit_dot_abapgit.
PROTECTED SECTION. PROTECTED SECTION.
PRIVATE SECTION. PRIVATE SECTION.
DATA mv_root_package TYPE devclass.
DATA mo_dot TYPE REF TO zcl_abapgit_dot_abapgit.
CLASS-METHODS calculate_status METHODS calculate_status
IMPORTING IMPORTING
!iv_devclass TYPE devclass
!io_dot TYPE REF TO zcl_abapgit_dot_abapgit
!it_local TYPE zif_abapgit_definitions=>ty_files_item_tt !it_local TYPE zif_abapgit_definitions=>ty_files_item_tt
!it_remote TYPE zif_abapgit_git_definitions=>ty_files_tt !it_remote TYPE zif_abapgit_git_definitions=>ty_files_tt
!it_cur_state TYPE zif_abapgit_git_definitions=>ty_file_signatures_tt !it_cur_state TYPE zif_abapgit_git_definitions=>ty_file_signatures_tt
@ -27,9 +33,8 @@ CLASS zcl_abapgit_file_status DEFINITION
VALUE(rt_results) TYPE zif_abapgit_definitions=>ty_results_tt VALUE(rt_results) TYPE zif_abapgit_definitions=>ty_results_tt
RAISING RAISING
zcx_abapgit_exception . zcx_abapgit_exception .
CLASS-METHODS process_local METHODS process_local
IMPORTING IMPORTING
!io_dot TYPE REF TO zcl_abapgit_dot_abapgit
!it_local TYPE zif_abapgit_definitions=>ty_files_item_tt !it_local TYPE zif_abapgit_definitions=>ty_files_item_tt
!it_state_idx TYPE zif_abapgit_git_definitions=>ty_file_signatures_ts !it_state_idx TYPE zif_abapgit_git_definitions=>ty_file_signatures_ts
CHANGING CHANGING
@ -38,33 +43,27 @@ CLASS zcl_abapgit_file_status DEFINITION
!ct_results TYPE zif_abapgit_definitions=>ty_results_tt !ct_results TYPE zif_abapgit_definitions=>ty_results_tt
RAISING RAISING
zcx_abapgit_exception . zcx_abapgit_exception .
CLASS-METHODS process_items METHODS process_items
IMPORTING IMPORTING
!iv_devclass TYPE devclass !it_unprocessed_remote TYPE zif_abapgit_git_definitions=>ty_files_tt
!io_dot TYPE REF TO zcl_abapgit_dot_abapgit
!it_remote TYPE zif_abapgit_git_definitions=>ty_files_tt
CHANGING CHANGING
!ct_items TYPE zif_abapgit_definitions=>ty_items_tt !ct_items TYPE zif_abapgit_definitions=>ty_items_tt
RAISING RAISING
zcx_abapgit_exception . zcx_abapgit_exception .
CLASS-METHODS process_remote METHODS process_remote
IMPORTING IMPORTING
!iv_devclass TYPE devclass
!io_dot TYPE REF TO zcl_abapgit_dot_abapgit
!it_local TYPE zif_abapgit_definitions=>ty_files_item_tt !it_local TYPE zif_abapgit_definitions=>ty_files_item_tt
!it_remote TYPE zif_abapgit_git_definitions=>ty_files_tt !it_unprocessed_remote TYPE zif_abapgit_git_definitions=>ty_files_tt
!it_state_idx TYPE zif_abapgit_git_definitions=>ty_file_signatures_ts !it_state_idx TYPE zif_abapgit_git_definitions=>ty_file_signatures_ts
!it_items_idx TYPE zif_abapgit_definitions=>ty_items_ts !it_items_idx TYPE zif_abapgit_definitions=>ty_items_ts
CHANGING CHANGING
!ct_results TYPE zif_abapgit_definitions=>ty_results_tt !ct_results TYPE zif_abapgit_definitions=>ty_results_tt
RAISING RAISING
zcx_abapgit_exception . zcx_abapgit_exception .
CLASS-METHODS run_checks METHODS run_checks
IMPORTING IMPORTING
!ii_log TYPE REF TO zif_abapgit_log !ii_log TYPE REF TO zif_abapgit_log
!it_results TYPE zif_abapgit_definitions=>ty_results_tt !it_results TYPE zif_abapgit_definitions=>ty_results_tt
!io_dot TYPE REF TO zcl_abapgit_dot_abapgit
!iv_top TYPE devclass
RAISING RAISING
zcx_abapgit_exception . zcx_abapgit_exception .
CLASS-METHODS build_existing CLASS-METHODS build_existing
@ -79,13 +78,11 @@ CLASS zcl_abapgit_file_status DEFINITION
!is_local TYPE zif_abapgit_definitions=>ty_file_item !is_local TYPE zif_abapgit_definitions=>ty_file_item
RETURNING RETURNING
VALUE(rs_result) TYPE zif_abapgit_definitions=>ty_result . VALUE(rs_result) TYPE zif_abapgit_definitions=>ty_result .
CLASS-METHODS build_new_remote METHODS build_new_remote
IMPORTING IMPORTING
!iv_devclass TYPE devclass
!io_dot TYPE REF TO zcl_abapgit_dot_abapgit
!is_remote TYPE zif_abapgit_git_definitions=>ty_file !is_remote TYPE zif_abapgit_git_definitions=>ty_file
!it_items TYPE zif_abapgit_definitions=>ty_items_ts !it_items_idx TYPE zif_abapgit_definitions=>ty_items_ts
!it_state TYPE zif_abapgit_git_definitions=>ty_file_signatures_ts !it_state_idx TYPE zif_abapgit_git_definitions=>ty_file_signatures_ts
RETURNING RETURNING
VALUE(rs_result) TYPE zif_abapgit_definitions=>ty_result VALUE(rs_result) TYPE zif_abapgit_definitions=>ty_result
RAISING RAISING
@ -137,16 +134,29 @@ CLASS zcl_abapgit_file_status DEFINITION
!it_results TYPE zif_abapgit_definitions=>ty_results_tt !it_results TYPE zif_abapgit_definitions=>ty_results_tt
RAISING RAISING
zcx_abapgit_exception . zcx_abapgit_exception .
CLASS-METHODS check_local_remote_consistency
IMPORTING
!is_local TYPE zif_abapgit_definitions=>ty_file_item
!is_remote TYPE zif_abapgit_git_definitions=>ty_file
RAISING
zcx_abapgit_exception .
CLASS-METHODS ensure_state
IMPORTING
!it_local TYPE zif_abapgit_definitions=>ty_files_item_tt
!it_cur_state TYPE zif_abapgit_git_definitions=>ty_file_signatures_tt
RETURNING
VALUE(rt_state) TYPE zif_abapgit_git_definitions=>ty_file_signatures_tt.
ENDCLASS. ENDCLASS.
CLASS zcl_abapgit_file_status IMPLEMENTATION. CLASS ZCL_ABAPGIT_FILE_STATUS IMPLEMENTATION.
METHOD build_existing. METHOD build_existing.
DATA: ls_file_sig LIKE LINE OF it_state. DATA ls_file_sig LIKE LINE OF it_state.
" Item " Item
rs_result-obj_type = is_local-item-obj_type. rs_result-obj_type = is_local-item-obj_type.
@ -158,15 +168,16 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
rs_result-path = is_local-file-path. rs_result-path = is_local-file-path.
rs_result-filename = is_local-file-filename. rs_result-filename = is_local-file-filename.
IF is_local-file-sha1 = is_remote-sha1. rs_result-match = boolc( is_local-file-sha1 = is_remote-sha1 ).
rs_result-match = abap_true. IF rs_result-match = abap_true.
RETURN. RETURN.
ENDIF. ENDIF.
" Match against current state " Match against current state
READ TABLE it_state INTO ls_file_sig READ TABLE it_state INTO ls_file_sig
WITH KEY path = is_local-file-path WITH KEY
filename = is_local-file-filename path = is_local-file-path
filename = is_local-file-filename
BINARY SEARCH. BINARY SEARCH.
IF sy-subrc = 0. IF sy-subrc = 0.
@ -176,18 +187,13 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
IF ls_file_sig-sha1 <> is_remote-sha1. IF ls_file_sig-sha1 <> is_remote-sha1.
rs_result-rstate = zif_abapgit_definitions=>c_state-modified. rs_result-rstate = zif_abapgit_definitions=>c_state-modified.
ENDIF. ENDIF.
rs_result-match = boolc( rs_result-lstate IS INITIAL
AND rs_result-rstate IS INITIAL ).
ELSE. ELSE.
" This is a strange situation. As both local and remote exist " This is a strange situation. As both local and remote exist
" the state should also be present. Maybe this is a first run of the code. " the state should also be present. Maybe this is a first run of the code.
" In this case just compare hashes directly and mark both changed " In this case just compare hashes directly and mark both changed
" the user will presumably decide what to do after checking the actual diff " the user will presumably decide what to do after checking the actual diff
rs_result-match = boolc( is_local-file-sha1 = is_remote-sha1 ). rs_result-lstate = zif_abapgit_definitions=>c_state-modified.
IF rs_result-match = abap_false. rs_result-rstate = zif_abapgit_definitions=>c_state-modified.
rs_result-lstate = zif_abapgit_definitions=>c_state-modified.
rs_result-rstate = zif_abapgit_definitions=>c_state-modified.
ENDIF.
ENDIF. ENDIF.
ENDMETHOD. ENDMETHOD.
@ -214,8 +220,8 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
METHOD build_new_remote. METHOD build_new_remote.
DATA: ls_item LIKE LINE OF it_items, DATA ls_item LIKE LINE OF it_items_idx.
ls_file_sig LIKE LINE OF it_state. DATA ls_file_sig LIKE LINE OF it_state_idx.
" Common and default part " Common and default part
rs_result-path = is_remote-path. rs_result-path = is_remote-path.
@ -227,15 +233,16 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
EXPORTING EXPORTING
iv_filename = is_remote-filename iv_filename = is_remote-filename
iv_path = is_remote-path iv_path = is_remote-path
iv_devclass = iv_devclass iv_devclass = mv_root_package
io_dot = io_dot io_dot = mo_dot
IMPORTING IMPORTING
es_item = ls_item ). es_item = ls_item ).
" Check if in item index + get package " Check if in item index + get package
READ TABLE it_items INTO ls_item READ TABLE it_items_idx INTO ls_item
WITH KEY obj_type = ls_item-obj_type obj_name = ls_item-obj_name WITH KEY
BINARY SEARCH. obj_type = ls_item-obj_type
obj_name = ls_item-obj_name.
IF sy-subrc = 0. IF sy-subrc = 0.
@ -245,9 +252,10 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
rs_result-package = ls_item-devclass. rs_result-package = ls_item-devclass.
rs_result-srcsystem = sy-sysid. rs_result-srcsystem = sy-sysid.
READ TABLE it_state INTO ls_file_sig READ TABLE it_state_idx INTO ls_file_sig
WITH KEY path = is_remote-path filename = is_remote-filename WITH KEY
BINARY SEARCH. path = is_remote-path
filename = is_remote-filename.
" Existing file but from another package " Existing file but from another package
" was not added during local file proc as was not in tadir for repo package " was not added during local file proc as was not in tadir for repo package
@ -261,7 +269,7 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
" Item is in state and in cache but with no package - it was deleted " Item is in state and in cache but with no package - it was deleted
" OR devclass is the same as repo package (see #532) " OR devclass is the same as repo package (see #532)
IF ls_item-devclass IS INITIAL OR ls_item-devclass = iv_devclass. IF ls_item-devclass IS INITIAL OR ls_item-devclass = mv_root_package.
rs_result-match = abap_false. rs_result-match = abap_false.
rs_result-lstate = zif_abapgit_definitions=>c_state-deleted. rs_result-lstate = zif_abapgit_definitions=>c_state-deleted.
ENDIF. ENDIF.
@ -277,49 +285,50 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
METHOD calculate_status. METHOD calculate_status.
DATA: DATA:
lt_remote LIKE it_remote, lt_remote LIKE it_remote,
lt_items TYPE zif_abapgit_definitions=>ty_items_tt, lt_items TYPE zif_abapgit_definitions=>ty_items_tt,
lt_items_idx TYPE zif_abapgit_definitions=>ty_items_ts, " Sorted by obj_type+obj_name lt_items_by_obj TYPE zif_abapgit_definitions=>ty_items_ts, " Sorted by obj_type+obj_name
lt_state_idx TYPE zif_abapgit_git_definitions=>ty_file_signatures_ts. " Sorted by path+filename lt_state_by_file TYPE zif_abapgit_git_definitions=>ty_file_signatures_ts. " Sorted by path+filename
lt_state_idx = it_cur_state. " Force sort it lt_state_by_file = ensure_state( " Index by file
it_cur_state = it_cur_state
lt_remote = it_remote. it_local = it_local ).
SORT lt_remote BY path filename. lt_remote = it_remote.
" Process local files and new local files " Process local files and new local files
process_local( process_local(
EXPORTING EXPORTING
io_dot = io_dot
it_local = it_local it_local = it_local
it_state_idx = lt_state_idx it_state_idx = lt_state_by_file
CHANGING CHANGING
ct_remote = lt_remote ct_remote = lt_remote
ct_items = lt_items ct_items = lt_items
ct_results = rt_results ). ct_results = rt_results ).
" Complete item index for unmarked remote files " Remove processed remotes (with cleared SHA1)
process_items( DELETE lt_remote WHERE sha1 IS INITIAL.
EXPORTING
iv_devclass = iv_devclass
io_dot = io_dot
it_remote = lt_remote
CHANGING
ct_items = lt_items ).
lt_items_idx = lt_items. " Self protection + UNIQUE records assertion " Complete item index for unmarked remote files
process_items( " TODO: rename ?
EXPORTING
it_unprocessed_remote = lt_remote
CHANGING
ct_items = lt_items ).
" The item list was not unique by now, just collected as "mention" list
SORT lt_items DESCENDING. " Default key - type, name, pkg, ...
DELETE ADJACENT DUPLICATES FROM lt_items COMPARING obj_type obj_name devclass.
lt_items_by_obj = lt_items.
" Process new remote files (marked above with empty SHA1) " Process new remote files (marked above with empty SHA1)
process_remote( process_remote(
EXPORTING EXPORTING
iv_devclass = iv_devclass it_local = it_local
io_dot = io_dot it_unprocessed_remote = lt_remote
it_local = it_local it_state_idx = lt_state_by_file
it_remote = lt_remote it_items_idx = lt_items_by_obj
it_state_idx = lt_state_idx
it_items_idx = lt_items_idx
CHANGING CHANGING
ct_results = rt_results ). ct_results = rt_results ).
SORT rt_results BY SORT rt_results BY
obj_type ASCENDING obj_type ASCENDING
@ -376,6 +385,21 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
ENDMETHOD. ENDMETHOD.
METHOD check_local_remote_consistency.
IF is_remote-sha1 IS INITIAL.
IF is_local-file-filename = zcl_abapgit_filename_logic=>c_package_file.
zcx_abapgit_exception=>raise(
|Package name conflict { is_local-item-obj_type } { is_local-item-obj_name }. | &&
|Rename package or use FULL folder logic| ).
ELSE.
zcx_abapgit_exception=>raise(
|Checksum conflict { is_local-item-obj_type } { is_local-item-obj_name }. | &&
|Please create an issue on Github| ).
ENDIF.
ENDIF.
ENDMETHOD.
METHOD check_multiple_files. METHOD check_multiple_files.
DATA: DATA:
@ -526,6 +550,31 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
ENDMETHOD. ENDMETHOD.
METHOD constructor.
mv_root_package = iv_root_package.
mo_dot = io_dot.
ENDMETHOD.
METHOD ensure_state.
FIELD-SYMBOLS <ls_state> LIKE LINE OF rt_state.
FIELD-SYMBOLS <ls_local> LIKE LINE OF it_local.
IF lines( it_cur_state ) = 0.
" Empty state is usually not expected. Maybe for new repos.
" In this case suppose the local state is unchanged
LOOP AT it_local ASSIGNING <ls_local>.
APPEND INITIAL LINE TO rt_state ASSIGNING <ls_state>.
MOVE-CORRESPONDING <ls_local>-file TO <ls_state>.
ENDLOOP.
ELSE.
rt_state = it_cur_state.
ENDIF.
ENDMETHOD.
METHOD get_object_package. METHOD get_object_package.
DATA: lv_name TYPE devclass, DATA: lv_name TYPE devclass,
li_package TYPE REF TO zif_abapgit_sap_package. li_package TYPE REF TO zif_abapgit_sap_package.
@ -551,18 +600,18 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
lv_is_xml TYPE abap_bool, lv_is_xml TYPE abap_bool,
lv_is_json TYPE abap_bool, lv_is_json TYPE abap_bool,
lv_sub_fetched TYPE abap_bool, lv_sub_fetched TYPE abap_bool,
lt_sub_packages TYPE zif_abapgit_sap_package=>ty_devclass_tt. lt_sub_packages TYPE SORTED TABLE OF devclass WITH UNIQUE KEY table_line.
FIELD-SYMBOLS <ls_remote> LIKE LINE OF it_remote. FIELD-SYMBOLS <ls_remote> LIKE LINE OF it_unprocessed_remote.
LOOP AT it_remote ASSIGNING <ls_remote> WHERE sha1 IS NOT INITIAL. LOOP AT it_unprocessed_remote ASSIGNING <ls_remote>.
zcl_abapgit_filename_logic=>file_to_object( zcl_abapgit_filename_logic=>file_to_object(
EXPORTING EXPORTING
iv_filename = <ls_remote>-filename iv_filename = <ls_remote>-filename
iv_path = <ls_remote>-path iv_path = <ls_remote>-path
io_dot = io_dot io_dot = mo_dot
iv_devclass = iv_devclass iv_devclass = mv_root_package
IMPORTING IMPORTING
es_item = ls_item es_item = ls_item
ev_is_xml = lv_is_xml ev_is_xml = lv_is_xml
@ -574,17 +623,15 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
iv_object = ls_item-obj_type iv_object = ls_item-obj_type
iv_obj_name = ls_item-obj_name ). iv_obj_name = ls_item-obj_name ).
IF NOT ls_item-devclass IS INITIAL AND iv_devclass <> ls_item-devclass. IF ls_item-devclass IS NOT INITIAL AND mv_root_package <> ls_item-devclass.
IF lv_sub_fetched = abap_false. IF lv_sub_fetched = abap_false.
lt_sub_packages = zcl_abapgit_factory=>get_sap_package( iv_devclass )->list_subpackages( ). lt_sub_packages = zcl_abapgit_factory=>get_sap_package( mv_root_package )->list_subpackages( ).
lv_sub_fetched = abap_true. lv_sub_fetched = abap_true.
SORT lt_sub_packages BY table_line. "Optimize Read Access
ENDIF. ENDIF.
" Make sure the package is under the repo main package " Make sure the package is under the repo main package
READ TABLE lt_sub_packages TRANSPORTING NO FIELDS READ TABLE lt_sub_packages TRANSPORTING NO FIELDS
WITH KEY table_line = ls_item-devclass WITH KEY table_line = ls_item-devclass.
BINARY SEARCH.
IF sy-subrc <> 0 AND ls_item-obj_type = 'DEVC'. IF sy-subrc <> 0 AND ls_item-obj_type = 'DEVC'.
CLEAR ls_item-devclass. CLEAR ls_item-devclass.
ENDIF. ENDIF.
@ -593,16 +640,11 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
APPEND ls_item TO ct_items. APPEND ls_item TO ct_items.
ENDLOOP. ENDLOOP.
SORT ct_items DESCENDING. " Default key - type, name, pkg, inactive
DELETE ADJACENT DUPLICATES FROM ct_items COMPARING obj_type obj_name devclass.
ENDMETHOD. ENDMETHOD.
METHOD process_local. METHOD process_local.
DATA lv_msg TYPE string.
FIELD-SYMBOLS: FIELD-SYMBOLS:
<ls_remote> LIKE LINE OF ct_remote, <ls_remote> LIKE LINE OF ct_remote,
<ls_result> LIKE LINE OF ct_results, <ls_result> LIKE LINE OF ct_results,
@ -611,36 +653,34 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
LOOP AT it_local ASSIGNING <ls_local>. LOOP AT it_local ASSIGNING <ls_local>.
" Skip ignored files " Skip ignored files
IF io_dot->is_ignored( iv_path = <ls_local>-file-path CHECK mo_dot->is_ignored(
iv_filename = <ls_local>-file-filename ) = abap_true. iv_path = <ls_local>-file-path
CONTINUE. iv_filename = <ls_local>-file-filename ) = abap_false.
IF <ls_local>-item IS NOT INITIAL.
" Collect for item index
APPEND <ls_local>-item TO ct_items.
ENDIF. ENDIF.
APPEND INITIAL LINE TO ct_results ASSIGNING <ls_result>. APPEND INITIAL LINE TO ct_results ASSIGNING <ls_result>.
IF <ls_local>-item IS NOT INITIAL. <ls_result>-inactive = <ls_local>-item-inactive.
APPEND <ls_local>-item TO ct_items. " Collect for item index
ENDIF.
" Find a match in remote
READ TABLE ct_remote ASSIGNING <ls_remote> READ TABLE ct_remote ASSIGNING <ls_remote>
WITH KEY path = <ls_local>-file-path filename = <ls_local>-file-filename WITH KEY file_path
BINARY SEARCH. COMPONENTS
IF sy-subrc = 0. " Exist local and remote path = <ls_local>-file-path
filename = <ls_local>-file-filename.
IF sy-subrc = 0. " Both local and remote exist
check_local_remote_consistency(
is_local = <ls_local>
is_remote = <ls_remote> ).
<ls_result> = build_existing( <ls_result> = build_existing(
is_local = <ls_local> is_local = <ls_local>
is_remote = <ls_remote> is_remote = <ls_remote>
it_state = it_state_idx ). it_state = it_state_idx ).
IF <ls_remote>-sha1 IS INITIAL.
IF <ls_local>-file-filename = zcl_abapgit_filename_logic=>c_package_file.
lv_msg = |Package name conflict { <ls_local>-item-obj_type } { <ls_local>-item-obj_name }. | &&
|Rename package or use FULL folder logic|.
ELSE.
lv_msg = |Checksum conflict { <ls_local>-item-obj_type } { <ls_local>-item-obj_name }. | &&
|Please create an issue on Github|.
ENDIF.
zcx_abapgit_exception=>raise( lv_msg ).
ENDIF.
CLEAR <ls_remote>-sha1. " Mark as processed CLEAR <ls_remote>-sha1. " Mark as processed
ELSE. " Only L exists ELSE. " Only local exists
<ls_result> = build_new_local( <ls_local> ). <ls_result> = build_new_local( <ls_local> ).
" Check if same file exists in different location " Check if same file exists in different location
READ TABLE ct_remote ASSIGNING <ls_remote> READ TABLE ct_remote ASSIGNING <ls_remote>
@ -651,8 +691,9 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
ELSEIF sy-subrc = 4. ELSEIF sy-subrc = 4.
" Check if file existed before and was deleted remotely " Check if file existed before and was deleted remotely
READ TABLE it_state_idx ASSIGNING <ls_state> READ TABLE it_state_idx ASSIGNING <ls_state>
WITH KEY path = <ls_local>-file-path filename = <ls_local>-file-filename WITH KEY
BINARY SEARCH. path = <ls_local>-file-path
filename = <ls_local>-file-filename.
IF sy-subrc = 0. IF sy-subrc = 0.
IF <ls_local>-file-sha1 = <ls_state>-sha1. IF <ls_local>-file-sha1 = <ls_state>-sha1.
<ls_result>-lstate = zif_abapgit_definitions=>c_state-unchanged. <ls_result>-lstate = zif_abapgit_definitions=>c_state-unchanged.
@ -663,7 +704,6 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
ENDIF. ENDIF.
ENDIF. ENDIF.
ENDIF. ENDIF.
<ls_result>-inactive = <ls_local>-item-inactive.
ENDLOOP. ENDLOOP.
ENDMETHOD. ENDMETHOD.
@ -672,19 +712,18 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
METHOD process_remote. METHOD process_remote.
FIELD-SYMBOLS: FIELD-SYMBOLS:
<ls_remote> LIKE LINE OF it_remote, <ls_remote> LIKE LINE OF it_unprocessed_remote,
<ls_result> LIKE LINE OF ct_results, <ls_result> LIKE LINE OF ct_results,
<ls_local> LIKE LINE OF it_local. <ls_local> LIKE LINE OF it_local.
LOOP AT it_remote ASSIGNING <ls_remote> WHERE sha1 IS NOT INITIAL. LOOP AT it_unprocessed_remote ASSIGNING <ls_remote>.
APPEND INITIAL LINE TO ct_results ASSIGNING <ls_result>. APPEND INITIAL LINE TO ct_results ASSIGNING <ls_result>.
<ls_result> = build_new_remote( <ls_result> = build_new_remote(
iv_devclass = iv_devclass
io_dot = io_dot
is_remote = <ls_remote> is_remote = <ls_remote>
it_items = it_items_idx it_items_idx = it_items_idx
it_state = it_state_idx ). it_state_idx = it_state_idx ).
" Check if same file exists in different location (not for generic package files) " Check if same file exists in different location (not for generic package files)
READ TABLE it_local ASSIGNING <ls_local> READ TABLE it_local ASSIGNING <ls_local>
@ -699,10 +738,11 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
ELSE. ELSE.
" Check if file existed before and was deleted locally " Check if file existed before and was deleted locally
READ TABLE it_state_idx TRANSPORTING NO FIELDS READ TABLE it_state_idx TRANSPORTING NO FIELDS
WITH KEY path = <ls_remote>-path filename = <ls_remote>-filename WITH KEY
BINARY SEARCH. path = <ls_remote>-path
filename = <ls_remote>-filename.
IF sy-subrc = 0. IF sy-subrc = 0.
<ls_result>-match = abap_false. <ls_result>-match = abap_false.
<ls_result>-lstate = zif_abapgit_definitions=>c_state-deleted. <ls_result>-lstate = zif_abapgit_definitions=>c_state-deleted.
ENDIF. ENDIF.
ENDIF. ENDIF.
@ -732,14 +772,14 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
check_package_sub_package( check_package_sub_package(
ii_log = ii_log ii_log = ii_log
it_results = it_results it_results = it_results
iv_top = iv_top ). iv_top = mv_root_package ).
" Check that objects are created in package corresponding to folder " Check that objects are created in package corresponding to folder
check_package_folder( check_package_folder(
ii_log = ii_log ii_log = ii_log
it_results = it_results it_results = it_results
io_dot = io_dot io_dot = mo_dot
iv_top = iv_top ). iv_top = mv_root_package ).
" Check for multiple files with same filename " Check for multiple files with same filename
check_multiple_files( check_multiple_files(
@ -759,6 +799,7 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
DATA lt_local TYPE zif_abapgit_definitions=>ty_files_item_tt. DATA lt_local TYPE zif_abapgit_definitions=>ty_files_item_tt.
DATA lt_remote TYPE zif_abapgit_git_definitions=>ty_files_tt. DATA lt_remote TYPE zif_abapgit_git_definitions=>ty_files_tt.
DATA li_exit TYPE REF TO zif_abapgit_exit. DATA li_exit TYPE REF TO zif_abapgit_exit.
DATA lo_instance TYPE REF TO zcl_abapgit_file_status.
lt_local = io_repo->get_files_local( ii_log = ii_log ). lt_local = io_repo->get_files_local( ii_log = ii_log ).
@ -780,18 +821,19 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
ct_local = lt_local ct_local = lt_local
ct_remote = lt_remote ). ct_remote = lt_remote ).
rt_results = calculate_status( CREATE OBJECT lo_instance
iv_devclass = io_repo->get_package( ) EXPORTING
io_dot = io_repo->get_dot_abapgit( ) iv_root_package = io_repo->get_package( )
io_dot = io_repo->get_dot_abapgit( ).
rt_results = lo_instance->calculate_status(
it_local = lt_local it_local = lt_local
it_remote = lt_remote it_remote = lt_remote
it_cur_state = io_repo->zif_abapgit_repo~checksums( )->get_checksums_per_file( ) ). it_cur_state = io_repo->zif_abapgit_repo~checksums( )->get_checksums_per_file( ) ).
run_checks( lo_instance->run_checks(
ii_log = ii_log ii_log = ii_log
it_results = rt_results it_results = rt_results ).
io_dot = io_repo->get_dot_abapgit( )
iv_top = io_repo->get_package( ) ).
ENDMETHOD. ENDMETHOD.
ENDCLASS. ENDCLASS.

View File

@ -38,6 +38,7 @@ CLASS ltcl_run_checks DEFINITION FOR TESTING RISK LEVEL HARMLESS
PRIVATE SECTION. PRIVATE SECTION.
DATA: mt_results TYPE zif_abapgit_definitions=>ty_results_tt, DATA: mt_results TYPE zif_abapgit_definitions=>ty_results_tt,
mo_instance TYPE REF TO zcl_abapgit_file_status,
mo_dot TYPE REF TO zcl_abapgit_dot_abapgit, mo_dot TYPE REF TO zcl_abapgit_dot_abapgit,
mi_log TYPE REF TO zif_abapgit_log. mi_log TYPE REF TO zif_abapgit_log.
@ -150,6 +151,11 @@ CLASS ltcl_run_checks IMPLEMENTATION.
zcl_abapgit_injector=>set_sap_package( iv_package = '$MAIN_SUB' zcl_abapgit_injector=>set_sap_package( iv_package = '$MAIN_SUB'
ii_sap_package = me ). ii_sap_package = me ).
CREATE OBJECT mo_instance
EXPORTING
iv_root_package = '$Z$'
io_dot = mo_dot.
ENDMETHOD. ENDMETHOD.
METHOD positive. METHOD positive.
@ -191,12 +197,9 @@ CLASS ltcl_run_checks IMPLEMENTATION.
iv_path = '/' iv_path = '/'
iv_filename = 'zdoma2.doma.xml' ). iv_filename = 'zdoma2.doma.xml' ).
mo_instance->run_checks(
zcl_abapgit_file_status=>run_checks(
ii_log = mi_log ii_log = mi_log
it_results = mt_results it_results = mt_results ).
io_dot = mo_dot
iv_top = '$Z$' ).
cl_abap_unit_assert=>assert_equals( cl_abap_unit_assert=>assert_equals(
act = mi_log->count( ) act = mi_log->count( )
@ -243,11 +246,9 @@ CLASS ltcl_run_checks IMPLEMENTATION.
iv_path = '/' iv_path = '/'
iv_filename = 'zdoma2.doma.xml' ). iv_filename = 'zdoma2.doma.xml' ).
zcl_abapgit_file_status=>run_checks( mo_instance->run_checks(
ii_log = mi_log ii_log = mi_log
it_results = mt_results it_results = mt_results ).
io_dot = mo_dot
iv_top = '$Z$' ).
" This one is not pure - incorrect path also triggers path vs package check " This one is not pure - incorrect path also triggers path vs package check
cl_abap_unit_assert=>assert_equals( cl_abap_unit_assert=>assert_equals(
@ -299,11 +300,9 @@ CLASS ltcl_run_checks IMPLEMENTATION.
iv_path = '/' iv_path = '/'
iv_filename = '$$zdoma2.doma.xml' ). iv_filename = '$$zdoma2.doma.xml' ).
zcl_abapgit_file_status=>run_checks( mo_instance->run_checks(
ii_log = mi_log ii_log = mi_log
it_results = mt_results it_results = mt_results ).
io_dot = mo_dot
iv_top = '$Z$' ).
cl_abap_unit_assert=>assert_equals( cl_abap_unit_assert=>assert_equals(
act = mi_log->count( ) act = mi_log->count( )
@ -354,11 +353,9 @@ CLASS ltcl_run_checks IMPLEMENTATION.
iv_path = '/' iv_path = '/'
iv_filename = '$$zdoma1.doma.xml' ). iv_filename = '$$zdoma1.doma.xml' ).
zcl_abapgit_file_status=>run_checks( mo_instance->run_checks(
ii_log = mi_log ii_log = mi_log
it_results = mt_results it_results = mt_results ).
io_dot = mo_dot
iv_top = '$Z$' ).
cl_abap_unit_assert=>assert_equals( cl_abap_unit_assert=>assert_equals(
act = mi_log->count( ) act = mi_log->count( )
@ -400,11 +397,9 @@ CLASS ltcl_run_checks IMPLEMENTATION.
iv_path = '/' iv_path = '/'
iv_filename = '' ). iv_filename = '' ).
zcl_abapgit_file_status=>run_checks( mo_instance->run_checks(
ii_log = mi_log ii_log = mi_log
it_results = mt_results it_results = mt_results ).
io_dot = mo_dot
iv_top = '$Z$' ).
cl_abap_unit_assert=>assert_equals( cl_abap_unit_assert=>assert_equals(
act = mi_log->count( ) act = mi_log->count( )
@ -479,11 +474,9 @@ CLASS ltcl_run_checks IMPLEMENTATION.
iv_filename = 'zdoma1.doma.xml' iv_filename = 'zdoma1.doma.xml'
iv_packmove = 'X' ). iv_packmove = 'X' ).
zcl_abapgit_file_status=>run_checks( mo_instance->run_checks(
ii_log = mi_log ii_log = mi_log
it_results = mt_results it_results = mt_results ).
io_dot = mo_dot
iv_top = '$Z$' ).
" Three files, but only two msg (for two changed objects) " Three files, but only two msg (for two changed objects)
cl_abap_unit_assert=>assert_equals( cl_abap_unit_assert=>assert_equals(
@ -508,11 +501,14 @@ CLASS ltcl_run_checks IMPLEMENTATION.
iv_path = '/' iv_path = '/'
iv_filename = '#notexist#zclass1.clas.xml' ). iv_filename = '#notexist#zclass1.clas.xml' ).
zcl_abapgit_file_status=>run_checks( CREATE OBJECT mo_instance
EXPORTING
iv_root_package = '/NOTEXIST/Z'
io_dot = mo_dot.
mo_instance->run_checks(
ii_log = mi_log ii_log = mi_log
it_results = mt_results it_results = mt_results ).
io_dot = mo_dot
iv_top = '/NOTEXIST/Z' ).
cl_abap_unit_assert=>assert_equals( cl_abap_unit_assert=>assert_equals(
act = mi_log->count( ) act = mi_log->count( )
@ -544,11 +540,14 @@ CLASS ltcl_run_checks IMPLEMENTATION.
iv_path = '' iv_path = ''
iv_filename = 'package.devc.xml' ). iv_filename = 'package.devc.xml' ).
zcl_abapgit_file_status=>run_checks( CREATE OBJECT mo_instance
EXPORTING
iv_root_package = '$MAIN'
io_dot = mo_dot.
mo_instance->run_checks(
ii_log = mi_log ii_log = mi_log
it_results = mt_results it_results = mt_results ).
io_dot = mo_dot
iv_top = '$MAIN' ).
cl_abap_unit_assert=>assert_equals( cl_abap_unit_assert=>assert_equals(
act = mi_log->count( ) act = mi_log->count( )
@ -749,16 +748,19 @@ CLASS ltcl_status_helper IMPLEMENTATION.
METHOD run. METHOD run.
DATA: lt_results TYPE zif_abapgit_definitions=>ty_results_tt, DATA: lt_results TYPE zif_abapgit_definitions=>ty_results_tt,
lo_dot TYPE REF TO zcl_abapgit_dot_abapgit. lo_instance TYPE REF TO zcl_abapgit_file_status,
lo_dot TYPE REF TO zcl_abapgit_dot_abapgit.
lo_dot = zcl_abapgit_dot_abapgit=>build_default( ). lo_dot = zcl_abapgit_dot_abapgit=>build_default( ).
lo_dot->set_starting_folder( '/' ). " assumed by unit tests lo_dot->set_starting_folder( '/' ). " assumed by unit tests
lt_results = zcl_abapgit_file_status=>calculate_status( CREATE OBJECT lo_instance
iv_devclass = iv_devclass EXPORTING
io_dot = lo_dot iv_root_package = iv_devclass
io_dot = lo_dot.
lt_results = lo_instance->calculate_status(
it_local = mt_local it_local = mt_local
it_remote = mt_remote it_remote = mt_remote
it_cur_state = mt_state ). it_cur_state = mt_state ).
@ -893,6 +895,8 @@ CLASS ltcl_calculate_status IMPLEMENTATION.
METHOD diff. METHOD diff.
" Modified both
CREATE OBJECT mo_helper.
mo_helper->add_local( mo_helper->add_local(
iv_obj_type = 'DOMA' iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA1' iv_obj_name = '$$ZDOMA1'
@ -903,6 +907,10 @@ CLASS ltcl_calculate_status IMPLEMENTATION.
iv_filename = '$$zdoma1.doma.xml' iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '54321' ). iv_sha1 = '54321' ).
mo_helper->add_state(
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = 'xxx' ).
mo_result = mo_helper->run( ). mo_result = mo_helper->run( ).
mo_result->assert_lines( 1 ). mo_result->assert_lines( 1 ).
@ -915,6 +923,62 @@ CLASS ltcl_calculate_status IMPLEMENTATION.
act = mo_result->get_line( 1 )-rstate act = mo_result->get_line( 1 )-rstate
exp = zif_abapgit_definitions=>c_state-modified ). exp = zif_abapgit_definitions=>c_state-modified ).
" Modified local only
CREATE OBJECT mo_helper.
mo_helper->add_local(
iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA1'
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '12345' ).
mo_helper->add_remote(
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '54321' ).
mo_helper->add_state(
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '54321' ).
mo_result = mo_helper->run( ).
mo_result->assert_lines( 1 ).
cl_abap_unit_assert=>assert_equals(
act = mo_result->get_line( 1 )-lstate
exp = zif_abapgit_definitions=>c_state-modified ).
cl_abap_unit_assert=>assert_equals(
act = mo_result->get_line( 1 )-rstate
exp = zif_abapgit_definitions=>c_state-unchanged ).
" Modified remote only
CREATE OBJECT mo_helper.
mo_helper->add_local(
iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA1'
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '12345' ).
mo_helper->add_remote(
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '54321' ).
mo_helper->add_state(
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '12345' ).
mo_result = mo_helper->run( ).
mo_result->assert_lines( 1 ).
cl_abap_unit_assert=>assert_equals(
act = mo_result->get_line( 1 )-lstate
exp = zif_abapgit_definitions=>c_state-unchanged ).
cl_abap_unit_assert=>assert_equals(
act = mo_result->get_line( 1 )-rstate
exp = zif_abapgit_definitions=>c_state-modified ).
ENDMETHOD. ENDMETHOD.
METHOD local_outside_main. METHOD local_outside_main.