All files / src/repo/stage zcl_abapgit_stage_logic.clas.abap

100% Statements 107/107
100% Branches 0/0
100% Functions 0/0
100% Lines 107/107

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 1081x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
CLASS zcl_abapgit_stage_logic DEFINITION
  PUBLIC
  CREATE PRIVATE
  GLOBAL FRIENDS zcl_abapgit_factory .
 
  PUBLIC SECTION.
 
    INTERFACES zif_abapgit_stage_logic .
  PROTECTED SECTION.
  PRIVATE SECTION.
    CLASS-METHODS:
      remove_ignored
        IMPORTING io_repo  TYPE REF TO zcl_abapgit_repo_online
        CHANGING  cs_files TYPE zif_abapgit_definitions=>ty_stage_files,
      remove_identical
        CHANGING cs_files TYPE zif_abapgit_definitions=>ty_stage_files.
 
ENDCLASS.
 
 
 
CLASS zcl_abapgit_stage_logic IMPLEMENTATION.
 
 
  METHOD remove_identical.
 
    DATA: lv_index  TYPE i,
          ls_remote LIKE LINE OF cs_files-remote.
 
    FIELD-SYMBOLS: <ls_local> LIKE LINE OF cs_files-local.
 
    SORT cs_files-remote BY path filename.
 
    LOOP AT cs_files-local ASSIGNING <ls_local>.
      lv_index = sy-tabix.
 
      READ TABLE cs_files-remote INTO ls_remote
        WITH KEY path = <ls_local>-file-path filename = <ls_local>-file-filename
        BINARY SEARCH.
      IF sy-subrc = 0.
        DELETE cs_files-remote INDEX sy-tabix.
        IF ls_remote-sha1 = <ls_local>-file-sha1.
          DELETE cs_files-local INDEX lv_index.
        ENDIF.
      ENDIF.
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD remove_ignored.
 
    DATA: lv_index TYPE i.
 
    FIELD-SYMBOLS: <ls_remote> LIKE LINE OF cs_files-remote,
                   <ls_local>  LIKE LINE OF cs_files-local.
 
 
    LOOP AT cs_files-remote ASSIGNING <ls_remote>.
      lv_index = sy-tabix.
 
      IF io_repo->get_dot_abapgit( )->is_ignored(
          iv_path     = <ls_remote>-path
          iv_filename = <ls_remote>-filename ) = abap_true.
        DELETE cs_files-remote INDEX lv_index.
      ELSEIF <ls_remote>-path = zif_abapgit_definitions=>c_root_dir
          AND <ls_remote>-filename = zif_abapgit_definitions=>c_dot_abapgit.
        " Remove .abapgit from remotes - it cannot be removed or ignored
        DELETE cs_files-remote INDEX lv_index.
      ENDIF.
 
    ENDLOOP.
 
    LOOP AT cs_files-local ASSIGNING <ls_local>.
      lv_index = sy-tabix.
 
      IF io_repo->get_dot_abapgit( )->is_ignored(
          iv_path     = <ls_local>-file-path
          iv_filename = <ls_local>-file-filename ) = abap_true.
        DELETE cs_files-local INDEX lv_index.
      ENDIF.
 
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_stage_logic~get.
 
    " Getting REMOTE before LOCAL is critical to ensure that DATA config is loaded first
    rs_files-remote = io_repo->get_files_remote( ii_obj_filter ).
 
    IF ii_obj_filter IS INITIAL.
      rs_files-local  = io_repo->get_files_local( ).
    ELSE.
      rs_files-local  = io_repo->get_files_local_filtered( ii_obj_filter ).
    ENDIF.
 
    rs_files-status = zcl_abapgit_repo_status=>calculate( ii_repo       = io_repo
                                                          ii_obj_filter = ii_obj_filter ).
 
    remove_identical( CHANGING cs_files = rs_files ).
    remove_ignored( EXPORTING io_repo  = io_repo
                    CHANGING  cs_files = rs_files ).
 
  ENDMETHOD.
ENDCLASS.