All files / src/git zcl_abapgit_git_add_patch.clas.abap

100% Statements 117/117
100% Branches 4/4
100% Functions 0/0
100% Lines 117/117

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 108 109 110 111 112 113 114 115 116 117 1181x 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 7x 7x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 7x 7x 2x 2x 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_git_add_patch DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC.
 
  PUBLIC SECTION.
 
    METHODS:
      constructor
        IMPORTING
          it_diff TYPE zif_abapgit_definitions=>ty_diffs_tt,
 
      get_patch
        RETURNING
          VALUE(rt_patch) TYPE string_table
        RAISING
          zcx_abapgit_exception,
 
      get_patch_binary
        RETURNING
          VALUE(rv_patch_binary) TYPE xstring
        RAISING
          zcx_abapgit_exception.
  PROTECTED SECTION.
  PRIVATE SECTION.
    DATA:
      mt_diff  TYPE zif_abapgit_definitions=>ty_diffs_tt,
      mt_patch TYPE string_table.
 
    METHODS:
      calculate_patch
        RETURNING
          VALUE(rt_patch) TYPE string_table
        RAISING
          zcx_abapgit_exception.
ENDCLASS.
 
 
 
CLASS ZCL_ABAPGIT_GIT_ADD_PATCH IMPLEMENTATION.
 
 
  METHOD calculate_patch.
 
    FIELD-SYMBOLS: <ls_diff> LIKE LINE OF mt_diff.
 
    LOOP AT mt_diff ASSIGNING <ls_diff>.
 
      CASE <ls_diff>-result.
        WHEN zif_abapgit_definitions=>c_diff-unchanged.
 
          INSERT <ls_diff>-old INTO TABLE rt_patch.
 
        WHEN zif_abapgit_definitions=>c_diff-insert.
 
          IF <ls_diff>-patch_flag = abap_true.
            INSERT <ls_diff>-new INTO TABLE rt_patch.
          ENDIF.
 
        WHEN zif_abapgit_definitions=>c_diff-delete.
 
          IF <ls_diff>-patch_flag = abap_false.
            INSERT <ls_diff>-old INTO TABLE rt_patch.
          ENDIF.
 
        WHEN zif_abapgit_definitions=>c_diff-update.
 
          IF <ls_diff>-patch_flag = abap_true.
            INSERT <ls_diff>-new INTO TABLE rt_patch.
          ELSE.
            INSERT <ls_diff>-old INTO TABLE rt_patch.
          ENDIF.
 
        WHEN OTHERS.
 
          zcx_abapgit_exception=>raise( |Unknown result| ).
 
      ENDCASE.
 
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD constructor.
 
    mt_diff = it_diff.
 
  ENDMETHOD.
 
 
  METHOD get_patch.
 
    IF mt_patch IS INITIAL.
      mt_patch = calculate_patch( ).
    ENDIF.
 
    rt_patch = mt_patch.
 
  ENDMETHOD.
 
 
  METHOD get_patch_binary.
 
    DATA: lv_string TYPE string.
 
    IF mt_patch IS INITIAL.
      mt_patch = calculate_patch( ).
    ENDIF.
 
    CONCATENATE LINES OF mt_patch INTO lv_string SEPARATED BY cl_abap_char_utilities=>newline.
    lv_string = lv_string && cl_abap_char_utilities=>newline.
 
    rv_patch_binary = zcl_abapgit_convert=>string_to_xstring_utf8( lv_string ).
 
  ENDMETHOD.
ENDCLASS.