All files / src/git zcl_abapgit_git_add_patch.clas.abap

100% Statements 138/138
100% Branches 12/12
100% Functions 2/2
100% Lines 138/138

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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 1391x 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 66x 66x 66x 34x 34x 34x 34x 10x 10x 9x 9x 10x 10x 10x 10x 3x 3x 10x 10x 66x 66x 7x 7x 4x 4x 66x 66x 66x 66x 66x 66x 66x 66x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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  
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,
 
      without_marker
        IMPORTING
          iv_line        TYPE string
        RETURNING
          VALUE(rv_line) TYPE string.
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 without_marker( <ls_diff>-old ) INTO TABLE rt_patch.
 
        WHEN zif_abapgit_definitions=>c_diff-insert.
 
          IF <ls_diff>-patch_flag = abap_true.
            INSERT without_marker( <ls_diff>-new ) INTO TABLE rt_patch.
          ENDIF.
 
        WHEN zif_abapgit_definitions=>c_diff-delete.
 
          IF <ls_diff>-patch_flag = abap_false.
            INSERT without_marker( <ls_diff>-old ) INTO TABLE rt_patch.
          ENDIF.
 
        WHEN zif_abapgit_definitions=>c_diff-update.
 
          IF <ls_diff>-patch_flag = abap_true.
            INSERT without_marker( <ls_diff>-new ) INTO TABLE rt_patch.
          ELSE.
            INSERT without_marker( <ls_diff>-old ) INTO TABLE rt_patch.
          ENDIF.
 
        WHEN OTHERS.
 
          zcx_abapgit_exception=>raise( |Unknown result| ).
 
      ENDCASE.
 
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD without_marker.
 
    " zcl_abapgit_diff_std appends a form feed to a last line without newline
    " when only the other side has one. It marks the diff, not the file
    DATA lv_length TYPE i.
 
    rv_line = iv_line.
    lv_length = strlen( rv_line ) - 1.
    IF lv_length >= 0 AND rv_line+lv_length(1) = cl_abap_char_utilities=>form_feed.
      rv_line = rv_line(lv_length).
    ENDIF.
 
  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.