All files / src/ui/flow zcl_abapgit_flow_git.clas.abap

95.17% Statements 296/311
76% Branches 19/25
71.42% Functions 5/7
95.17% Lines 296/311

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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 3121x 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 8x 8x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x         4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 14x 14x 14x       14x 14x 8x 8x 8x     8x 14x 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 4x 4x 4x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 10x 10x 4x 4x 4x 6x 6x 6x 2x 2x 2x 4x 4x 4x 4x 4x 4x     4x 10x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 1x 1x  
CLASS zcl_abapgit_flow_git DEFINITION PUBLIC.
  PUBLIC SECTION.
* various git related methods
 
    CLASS-METHODS find_changes_in_git
      IMPORTING
        iv_url           TYPE string
        io_dot           TYPE REF TO zcl_abapgit_dot_abapgit
        iv_package       TYPE devclass
        it_branches      TYPE zif_abapgit_git_definitions=>ty_git_branch_list_tt
      EXPORTING
        et_main_expanded TYPE zif_abapgit_git_definitions=>ty_expanded_tt
      CHANGING
        ct_features      TYPE zif_abapgit_flow_logic=>ty_features
      RAISING
        zcx_abapgit_exception.
 
    CLASS-METHODS find_up_to_date
      IMPORTING
        it_branches TYPE zif_abapgit_git_definitions=>ty_git_branch_list_tt
        it_objects  TYPE zif_abapgit_definitions=>ty_objects_tt
      CHANGING
        ct_features TYPE zif_abapgit_flow_logic=>ty_features
      RAISING
        zcx_abapgit_exception.
 
  PRIVATE SECTION.
 
    TYPES ty_main_reachable TYPE HASHED TABLE OF zif_abapgit_git_definitions=>ty_sha1 WITH UNIQUE KEY table_line.
 
    CLASS-METHODS build_main_reachable
      IMPORTING
        it_branches       TYPE zif_abapgit_git_definitions=>ty_git_branch_list_tt
        it_objects        TYPE zif_abapgit_definitions=>ty_objects_tt
      EXPORTING
        ev_main_sha1      TYPE zif_abapgit_git_definitions=>ty_sha1
        et_main_reachable TYPE ty_main_reachable
      RAISING
        zcx_abapgit_exception.
 
    CLASS-METHODS find_branch_commits
      IMPORTING
        iv_branch_sha1         TYPE zif_abapgit_git_definitions=>ty_sha1
        it_objects             TYPE zif_abapgit_definitions=>ty_objects_tt
        it_main_reachable      TYPE ty_main_reachable
      EXPORTING
        ev_first_commit        TYPE zif_abapgit_git_definitions=>ty_sha1
        ev_latest_merge_commit TYPE zif_abapgit_git_definitions=>ty_sha1
      RAISING
        zcx_abapgit_exception.
 
    CLASS-METHODS map_files_to_objects
      IMPORTING
        it_files                  TYPE zif_abapgit_flow_logic=>ty_path_name_tt
        io_dot                    TYPE REF TO zcl_abapgit_dot_abapgit
        iv_package                TYPE devclass
      RETURNING
        VALUE(rt_changed_objects) TYPE zif_abapgit_definitions=>ty_items_ts
      RAISING
        zcx_abapgit_exception.
ENDCLASS.
 
CLASS zcl_abapgit_flow_git IMPLEMENTATION.
 
  METHOD find_changes_in_git.
 
    DATA ls_branch          LIKE LINE OF it_branches.
    DATA lt_sha1            TYPE zif_abapgit_git_definitions=>ty_sha1_tt.
    DATA lt_objects         TYPE zif_abapgit_definitions=>ty_objects_tt.
    DATA lv_starting_folder TYPE string.
    DATA ls_main            LIKE LINE OF it_branches.
    DATA li_find            TYPE REF TO lif_find_changes.
    DATA lv_previous        TYPE zif_abapgit_persistence=>ty_repo-key.
    DATA lt_commits         TYPE zif_abapgit_definitions=>ty_objects_tt.
 
    FIELD-SYMBOLS <ls_feature> LIKE LINE OF ct_features.
    FIELD-SYMBOLS <ls_commit> LIKE LINE OF lt_commits.
 
 
    CLEAR et_main_expanded.
 
*******************************
 
    LOOP AT it_branches INTO ls_branch WHERE is_head = abap_false.
      APPEND ls_branch-sha1 TO lt_sha1.
    ENDLOOP.
 
    lt_objects = zcl_abapgit_git_factory=>get_v2_porcelain( )->list_no_blobs_multi(
      iv_url  = iv_url
      it_sha1 = lt_sha1 ).
 
    lt_commits = zcl_abapgit_git_factory=>get_v2_porcelain( )->commits_last_days(
      iv_url  = iv_url
      iv_days = zif_abapgit_flow_logic=>c_commit_days
      it_sha1 = lt_sha1 ).
    LOOP AT lt_commits ASSIGNING <ls_commit>.
      INSERT <ls_commit> INTO TABLE lt_objects.
* ignore subrc, it might already be there
    ENDLOOP.
 
********************************
 
    lv_starting_folder = io_dot->get_starting_folder( ) && '*'.
 
    READ TABLE it_branches INTO ls_main WITH KEY display_name = zif_abapgit_flow_logic=>c_main.
    ASSERT sy-subrc = 0.
 
    lcl_walker=>initialize( lt_objects ).
    et_main_expanded = lcl_walker=>expand( ls_main-sha1 ).
    DELETE et_main_expanded WHERE path NP lv_starting_folder.
 
    find_up_to_date(
      EXPORTING
        it_branches = it_branches
        it_objects  = lt_objects
      CHANGING
        ct_features = ct_features ).
 
    LOOP AT ct_features ASSIGNING <ls_feature> WHERE branch-display_name <> zif_abapgit_flow_logic=>c_main.
      IF lv_previous IS INITIAL OR lv_previous <> <ls_feature>-repo-key.
        IF zcl_abapgit_flow_exit=>get_instance( )->get_settings( <ls_feature>-repo-key )-allow_not_up_to_date = abap_true.
          CREATE OBJECT li_find TYPE lcl_find_changes_new
            EXPORTING
              it_objects = lt_objects.
        ELSE.
          CREATE OBJECT li_find TYPE lcl_find_changes
            EXPORTING
              it_objects = lt_objects.
        ENDIF.
        lv_previous = <ls_feature>-repo-key.
      ENDIF.
 
      <ls_feature>-changed_files = li_find->find_changes(
        iv_main                = ls_main-sha1
        iv_branch              = <ls_feature>-branch-sha1
        iv_first_commit        = <ls_feature>-branch-first_commit
        iv_latest_merge_commit = <ls_feature>-branch-latest_merge_commit ).
 
      DELETE <ls_feature>-changed_files WHERE path NP lv_starting_folder.
 
      <ls_feature>-changed_objects = map_files_to_objects(
        io_dot     = io_dot
        iv_package = iv_package
        it_files   = <ls_feature>-changed_files ).
    ENDLOOP.
 
  ENDMETHOD.
 
  METHOD map_files_to_objects.
 
    DATA ls_item TYPE zif_abapgit_definitions=>ty_item.
 
    FIELD-SYMBOLS <ls_file> LIKE LINE OF it_files.
 
 
    LOOP AT it_files ASSIGNING <ls_file>.
      zcl_abapgit_filename_logic=>file_to_object(
        EXPORTING
          iv_filename = <ls_file>-filename
          iv_path     = <ls_file>-path
          iv_devclass = iv_package
          io_dot      = io_dot
        IMPORTING
          es_item     = ls_item ).
      INSERT ls_item INTO TABLE rt_changed_objects.
    ENDLOOP.
 
  ENDMETHOD.
 
  METHOD build_main_reachable.
 
    DATA lv_current TYPE zif_abapgit_git_definitions=>ty_sha1.
    DATA lo_visit   TYPE REF TO lcl_sha1_stack.
    DATA ls_main    LIKE LINE OF it_branches.
    DATA ls_commit  TYPE zcl_abapgit_git_pack=>ty_commit.
 
    FIELD-SYMBOLS <ls_commit> LIKE LINE OF it_objects.
 
 
    READ TABLE it_branches INTO ls_main WITH KEY display_name = zif_abapgit_flow_logic=>c_main.
    ASSERT sy-subrc = 0.
    ev_main_sha1 = ls_main-sha1.
 
    CREATE OBJECT lo_visit.
    lo_visit->clear( )->push( ev_main_sha1 ).
    WHILE lo_visit->size( ) > 0.
      lv_current = lo_visit->pop( ).
      INSERT lv_current INTO TABLE et_main_reachable.
      IF sy-subrc <> 0.
        " already visited
        CONTINUE.
      ENDIF.
      READ TABLE it_objects ASSIGNING <ls_commit> WITH TABLE KEY sha COMPONENTS sha1 = lv_current.
      IF sy-subrc = 0.
        ls_commit = zcl_abapgit_git_pack=>decode_commit( <ls_commit>-data ).
        lo_visit->push( ls_commit-parent ).
        IF ls_commit-parent2 IS NOT INITIAL.
          lo_visit->push( ls_commit-parent2 ).
        ENDIF.
      ENDIF.
    ENDWHILE.
 
  ENDMETHOD.
 
  METHOD find_branch_commits.
 
    DATA lv_current TYPE zif_abapgit_git_definitions=>ty_sha1.
    DATA lo_visit   TYPE REF TO lcl_sha1_stack.
    DATA ls_commit  TYPE zcl_abapgit_git_pack=>ty_commit.
 
    FIELD-SYMBOLS <ls_commit> LIKE LINE OF it_objects.
 
 
    CREATE OBJECT lo_visit.
 
    " find first commit and latest merge commit
    lo_visit->clear( )->push( iv_branch_sha1 ).
    WHILE lo_visit->size( ) > 0.
      lv_current = lo_visit->pop( ).
 
      READ TABLE it_objects ASSIGNING <ls_commit> WITH TABLE KEY sha COMPONENTS sha1 = lv_current.
      IF sy-subrc = 0.
        ls_commit = zcl_abapgit_git_pack=>decode_commit( <ls_commit>-data ).
        lo_visit->push( ls_commit-parent ).
 
        IF ls_commit-parent2 IS NOT INITIAL.
          IF ev_latest_merge_commit IS INITIAL.
            ev_latest_merge_commit = lv_current.
          ENDIF.
        ELSE.
          READ TABLE it_main_reachable WITH KEY table_line = ls_commit-parent TRANSPORTING NO FIELDS.
          IF sy-subrc = 0.
            ev_first_commit = lv_current.
            EXIT.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDWHILE.
 
  ENDMETHOD.
 
  METHOD find_up_to_date.
 
    DATA lv_current TYPE zif_abapgit_git_definitions=>ty_sha1.
    DATA lv_main    TYPE zif_abapgit_git_definitions=>ty_sha1.
    DATA lo_visit   TYPE REF TO lcl_sha1_stack.
    DATA ls_commit  TYPE zcl_abapgit_git_pack=>ty_commit.
 
    DATA lt_main_reachable TYPE ty_main_reachable.
 
    FIELD-SYMBOLS <ls_branch> LIKE LINE OF ct_features.
    FIELD-SYMBOLS <ls_commit> LIKE LINE OF it_objects.
 
 
    IF lines( it_branches ) = 1.
      " only main branch
      RETURN.
    ENDIF.
 
    build_main_reachable(
      EXPORTING
        it_branches       = it_branches
        it_objects        = it_objects
      IMPORTING
        ev_main_sha1      = lv_main
        et_main_reachable = lt_main_reachable ).
 
    CREATE OBJECT lo_visit.
 
    LOOP AT ct_features ASSIGNING <ls_branch>.
      <ls_branch>-branch-up_to_date = abap_undefined.
      lo_visit->clear( )->push( <ls_branch>-branch-sha1 ).
 
      " find up_to_date
      WHILE lo_visit->size( ) > 0.
        lv_current = lo_visit->pop( ).
        IF lv_current = lv_main.
          <ls_branch>-branch-up_to_date = abap_true.
          EXIT.
        ENDIF.
 
        READ TABLE lt_main_reachable WITH KEY table_line = lv_current TRANSPORTING NO FIELDS.
        IF sy-subrc = 0.
          <ls_branch>-branch-up_to_date = abap_false.
          EXIT.
        ENDIF.
 
        READ TABLE it_objects ASSIGNING <ls_commit> WITH TABLE KEY sha COMPONENTS sha1 = lv_current.
        IF sy-subrc = 0.
          ls_commit = zcl_abapgit_git_pack=>decode_commit( <ls_commit>-data ).
          lo_visit->push( ls_commit-parent ).
          IF ls_commit-parent2 IS NOT INITIAL.
            lo_visit->push( ls_commit-parent2 ).
          ENDIF.
        ENDIF.
      ENDWHILE.
 
      find_branch_commits(
        EXPORTING
          iv_branch_sha1    = <ls_branch>-branch-sha1
          it_objects        = it_objects
          it_main_reachable = lt_main_reachable
        IMPORTING
          ev_first_commit        = <ls_branch>-branch-first_commit
          ev_latest_merge_commit = <ls_branch>-branch-latest_merge_commit ).
 
    ENDLOOP.
 
  ENDMETHOD.
 
ENDCLASS.