From 9cf235cb3f69202646bf236ef2afad6440f7fd34 Mon Sep 17 00:00:00 2001 From: larshp Date: Sat, 2 Jul 2016 13:09:25 +0000 Subject: [PATCH] done, everything moved from top, close #210 split is not perfect, but will do for now, we can split into more includes in the future --- src/zabapgit.prog.abap | 268 +----------------------- src/zabapgit_app.prog.abap | 35 ++++ src/zabapgit_app.prog.xml | 48 +++++ src/zabapgit_definitions.prog.abap | 134 ++++++++++++ src/zabapgit_definitions.prog.xml | 48 +++++ src/zabapgit_stage.prog.abap | 313 ++++++++--------------------- src/zabapgit_stage_impl.prog.abap | 246 +++++++++++++++++++++++ src/zabapgit_stage_impl.prog.xml | 48 +++++ 8 files changed, 645 insertions(+), 495 deletions(-) create mode 100644 src/zabapgit_app.prog.abap create mode 100644 src/zabapgit_app.prog.xml create mode 100644 src/zabapgit_definitions.prog.abap create mode 100644 src/zabapgit_definitions.prog.xml create mode 100644 src/zabapgit_stage_impl.prog.abap create mode 100644 src/zabapgit_stage_impl.prog.xml diff --git a/src/zabapgit.prog.abap b/src/zabapgit.prog.abap index 5c5177b9e..347eb1193 100644 --- a/src/zabapgit.prog.abap +++ b/src/zabapgit.prog.abap @@ -3,7 +3,7 @@ REPORT zabapgit LINE-SIZE 100. * See http://www.abapgit.org CONSTANTS: gc_xml_version TYPE string VALUE 'v1.0.0', "#EC NOTEXT - gc_abap_version TYPE string VALUE 'v1.12.6'. "#EC NOTEXT + gc_abap_version TYPE string VALUE 'v1.12.7'. "#EC NOTEXT ******************************************************************************** * The MIT License (MIT) @@ -29,286 +29,28 @@ CONSTANTS: gc_xml_version TYPE string VALUE 'v1.0.0', "#EC NOTEXT * SOFTWARE. ******************************************************************************** -TYPE-POOLS seop. - -TYPES: ty_type TYPE c LENGTH 6, - ty_bitbyte TYPE c LENGTH 8, - ty_sha1 TYPE c LENGTH 40. - -TYPES: BEGIN OF ty_file, - path TYPE string, - filename TYPE string, - data TYPE xstring, - END OF ty_file. -TYPES: ty_files_tt TYPE STANDARD TABLE OF ty_file WITH DEFAULT KEY. - -TYPES: ty_string_tt TYPE STANDARD TABLE OF string WITH DEFAULT KEY. -TYPES: tt_w3urls TYPE STANDARD TABLE OF w3url WITH DEFAULT KEY. - -TYPES: BEGIN OF ty_comment, - username TYPE string, - email TYPE string, - comment TYPE string, - END OF ty_comment. - -TYPES: BEGIN OF ty_item, - obj_type TYPE tadir-object, - obj_name TYPE tadir-obj_name, - END OF ty_item. - -TYPES: BEGIN OF ty_file_item, - file TYPE ty_file, - item TYPE ty_item, - END OF ty_file_item. -TYPES: ty_files_item_tt TYPE STANDARD TABLE OF ty_file_item WITH DEFAULT KEY. - -TYPES: BEGIN OF ty_metadata, - class TYPE string, - version TYPE string, - late_deser TYPE string, - END OF ty_metadata. - -TYPES: BEGIN OF ty_web_asset, - url TYPE w3url, - content TYPE string, - END OF ty_web_asset. -TYPES tt_web_assets TYPE STANDARD TABLE OF ty_web_asset WITH DEFAULT KEY. - -TYPES: BEGIN OF ty_repo_file, - path TYPE string, - filename TYPE string, - is_changed TYPE abap_bool, - END OF ty_repo_file. -TYPES tt_repo_files TYPE STANDARD TABLE OF ty_repo_file WITH DEFAULT KEY. - -CONSTANTS: BEGIN OF gc_type, - commit TYPE ty_type VALUE 'commit', "#EC NOTEXT - tree TYPE ty_type VALUE 'tree', "#EC NOTEXT - ref_d TYPE ty_type VALUE 'ref_d', "#EC NOTEXT - blob TYPE ty_type VALUE 'blob', "#EC NOTEXT - END OF gc_type. - -TYPES: ty_chmod TYPE c LENGTH 6. - -TYPES: BEGIN OF ty_object, - sha1 TYPE ty_sha1, - type TYPE ty_type, - data TYPE xstring, - END OF ty_object. -TYPES: ty_objects_tt TYPE STANDARD TABLE OF ty_object WITH DEFAULT KEY. - -TYPES: BEGIN OF ty_tadir, - pgmid TYPE tadir-pgmid, - object TYPE tadir-object, - obj_name TYPE tadir-obj_name, - devclass TYPE tadir-devclass, - korrnum TYPE tadir-korrnum, - path TYPE string, - END OF ty_tadir. -TYPES: ty_tadir_tt TYPE STANDARD TABLE OF ty_tadir WITH DEFAULT KEY. - -TYPES: BEGIN OF ty_result, - obj_type TYPE tadir-object, - obj_name TYPE tadir-obj_name, - match TYPE sap_bool, - filename TYPE string, - package TYPE devclass, - path TYPE string, - END OF ty_result. -TYPES: ty_results_tt TYPE STANDARD TABLE OF ty_result WITH DEFAULT KEY. - -CONSTANTS: BEGIN OF gc_chmod, - file TYPE ty_chmod VALUE '100644', - executable TYPE ty_chmod VALUE '100755', - dir TYPE ty_chmod VALUE '40000 ', - END OF gc_chmod. - -CONSTANTS: BEGIN OF gc_event_state, - not_handled VALUE 0, - re_render VALUE 1, - new_page VALUE 2, - go_back VALUE 3, - no_more_act VALUE 4, - new_page_w_bookmark VALUE 5, - go_back_to_bookmark VALUE 6, - END OF gc_event_state. - -CONSTANTS: BEGIN OF gc_html_opt, - emphas TYPE c VALUE 'E', - cancel TYPE c VALUE 'C', - END OF gc_html_opt. - -CONSTANTS: BEGIN OF gc_action_type, - sapevent TYPE c VALUE 'E', - url TYPE c VALUE 'U', - onclick TYPE c VALUE 'C', - END OF gc_action_type. - -CONSTANTS: gc_newline TYPE abap_char1 VALUE cl_abap_char_utilities=>newline. - -CONSTANTS: gc_english TYPE spras VALUE 'E'. - -CONSTANTS: gc_abapgit_homepage TYPE string VALUE 'http://www.abapgit.org'. - -CONSTANTS: gc_root_dir TYPE string VALUE '/', - gc_dot_abapgit TYPE string VALUE '.abapgit.xml'. - -DEFINE _raise. - RAISE EXCEPTION TYPE lcx_exception - EXPORTING - iv_text = &1. "#EC NOTEXT -END-OF-DEFINITION. - -****************** - SELECTION-SCREEN BEGIN OF SCREEN 1001. * dummy for triggering screen SELECTION-SCREEN END OF SCREEN 1001. -****************** +INCLUDE zabapgit_definitions. INCLUDE zabapgit_exceptions. INCLUDE zabapgit_zlib. INCLUDE zabapgit_util. INCLUDE zabapgit_xml. - CLASS lcl_gui DEFINITION DEFERRED. CLASS lcl_persistence_user DEFINITION DEFERRED. CLASS lcl_repo_srv DEFINITION DEFERRED. CLASS lcl_persistence_db DEFINITION DEFERRED. - -*----------------------------------------------------------------------* -* CLASS lcl_app DEFINITION -*----------------------------------------------------------------------* -CLASS lcl_app DEFINITION FINAL. - PUBLIC SECTION. - - CLASS-METHODS run - RAISING lcx_exception. - - CLASS-METHODS gui - RETURNING VALUE(ro_gui) TYPE REF TO lcl_gui - RAISING lcx_exception. - - CLASS-METHODS user - IMPORTING iv_user TYPE xubname DEFAULT sy-uname - RETURNING VALUE(ro_user) TYPE REF TO lcl_persistence_user - RAISING lcx_exception. - - CLASS-METHODS repo_srv - RETURNING VALUE(ro_repo_srv) TYPE REF TO lcl_repo_srv. - - CLASS-METHODS db - RETURNING VALUE(ro_db) TYPE REF TO lcl_persistence_db. - - PRIVATE SECTION. - CLASS-DATA: go_gui TYPE REF TO lcl_gui, - go_current_user TYPE REF TO lcl_persistence_user, - go_db TYPE REF TO lcl_persistence_db, - go_repo_srv TYPE REF TO lcl_repo_srv. - -ENDCLASS. "lcl_app - +INCLUDE zabapgit_app. INCLUDE zabapgit_persistence. INCLUDE zabapgit_html. INCLUDE zabapgit_dot_abapgit. INCLUDE zabapgit_sap_package. - CLASS lcl_repo_online DEFINITION DEFERRED. - -*----------------------------------------------------------------------* -* CLASS lcl_stage DEFINITION -*----------------------------------------------------------------------* -CLASS lcl_stage DEFINITION FINAL CREATE PRIVATE FRIENDS lcl_repo_srv. - - PUBLIC SECTION. - TYPES: ty_method TYPE c LENGTH 1. - - CONSTANTS: BEGIN OF c_method, - add TYPE ty_method VALUE 'A', - rm TYPE ty_method VALUE 'R', - ignore TYPE ty_method VALUE 'I', - END OF c_method. - - CONSTANTS: BEGIN OF c_wftype, - local TYPE char1 VALUE 'L', - remote TYPE char1 VALUE 'R', - END OF c_wftype. - - TYPES: BEGIN OF ty_stage, - file TYPE ty_file, - method TYPE ty_method, - END OF ty_stage. - - TYPES: ty_stage_tt TYPE SORTED TABLE OF ty_stage - WITH UNIQUE KEY file-path file-filename. - - TYPES: BEGIN OF ty_work_file, - type TYPE char1, - file TYPE ty_file, - END OF ty_work_file. - - DATA mv_repo_key TYPE lcl_persistence_db=>ty_value READ-ONLY. - DATA mv_local_cnt TYPE i READ-ONLY. - DATA mt_workarea TYPE STANDARD TABLE OF ty_work_file READ-ONLY. - - CLASS-METHODS method_description - IMPORTING iv_method TYPE ty_method - RETURNING VALUE(rv_description) TYPE string - RAISING lcx_exception. - - METHODS constructor - IMPORTING iv_repo_key TYPE lcl_persistence_db=>ty_value - RAISING lcx_exception. - - METHODS update_and_add_dot_abapgit - IMPORTING iv_data TYPE ty_file-data - RAISING lcx_exception. - - METHODS: - add - IMPORTING iv_path TYPE ty_file-path - iv_filename TYPE ty_file-filename - RAISING lcx_exception, - reset - IMPORTING iv_path TYPE ty_file-path - iv_filename TYPE ty_file-filename - RAISING lcx_exception, - rm - IMPORTING iv_path TYPE ty_file-path - iv_filename TYPE ty_file-filename - RAISING lcx_exception, - ignore - IMPORTING iv_path TYPE ty_file-path - iv_filename TYPE ty_file-filename - RAISING lcx_exception, - lookup - IMPORTING iv_path TYPE ty_file-path - iv_filename TYPE ty_file-filename - RETURNING VALUE(rv_method) TYPE ty_method, - count - RETURNING VALUE(rv_count) TYPE i, - get_all - RETURNING VALUE(rt_stage) TYPE ty_stage_tt. - - PRIVATE SECTION. - DATA: mt_stage TYPE ty_stage_tt. - - METHODS append - IMPORTING iv_path TYPE ty_file-path - iv_filename TYPE ty_file-filename - iv_method TYPE ty_method - RAISING lcx_exception. - - METHODS find_work_file - IMPORTING iv_path TYPE ty_file-path - iv_filename TYPE ty_file-filename - RETURNING VALUE(rs_file) TYPE ty_file - RAISING lcx_exception. - -ENDCLASS. "lcl_stage DEFINITION - -INCLUDE zabapgit_repo. INCLUDE zabapgit_stage. +INCLUDE zabapgit_repo. +INCLUDE zabapgit_stage_impl. INCLUDE zabapgit_git. INCLUDE zabapgit_objects. INCLUDE zabapgit_tadir. diff --git a/src/zabapgit_app.prog.abap b/src/zabapgit_app.prog.abap new file mode 100644 index 000000000..0588a81f1 --- /dev/null +++ b/src/zabapgit_app.prog.abap @@ -0,0 +1,35 @@ +*&---------------------------------------------------------------------* +*& Include ZABAPGIT_APP +*&---------------------------------------------------------------------* + +*----------------------------------------------------------------------* +* CLASS lcl_app DEFINITION +*----------------------------------------------------------------------* +CLASS lcl_app DEFINITION FINAL. + PUBLIC SECTION. + + CLASS-METHODS run + RAISING lcx_exception. + + CLASS-METHODS gui + RETURNING VALUE(ro_gui) TYPE REF TO lcl_gui + RAISING lcx_exception. + + CLASS-METHODS user + IMPORTING iv_user TYPE xubname DEFAULT sy-uname + RETURNING VALUE(ro_user) TYPE REF TO lcl_persistence_user + RAISING lcx_exception. + + CLASS-METHODS repo_srv + RETURNING VALUE(ro_repo_srv) TYPE REF TO lcl_repo_srv. + + CLASS-METHODS db + RETURNING VALUE(ro_db) TYPE REF TO lcl_persistence_db. + + PRIVATE SECTION. + CLASS-DATA: go_gui TYPE REF TO lcl_gui, + go_current_user TYPE REF TO lcl_persistence_user, + go_db TYPE REF TO lcl_persistence_db, + go_repo_srv TYPE REF TO lcl_repo_srv. + +ENDCLASS. "lcl_app \ No newline at end of file diff --git a/src/zabapgit_app.prog.xml b/src/zabapgit_app.prog.xml new file mode 100644 index 000000000..bdb2a00f4 --- /dev/null +++ b/src/zabapgit_app.prog.xml @@ -0,0 +1,48 @@ + + + + + + ZABAPGIT_APP + A + + + X + + + + + + I + + + + 0000-00-00 + + 0000-00-00 + + + + + E + + + 0000-00-00 + + 0000-00-00 + + + X + + + + R + + Include ZABAPGIT_APP + 20 + + + + + + diff --git a/src/zabapgit_definitions.prog.abap b/src/zabapgit_definitions.prog.abap new file mode 100644 index 000000000..ad1761f36 --- /dev/null +++ b/src/zabapgit_definitions.prog.abap @@ -0,0 +1,134 @@ +*&---------------------------------------------------------------------* +*& Include ZABAPGIT_DEFINITIONS +*&---------------------------------------------------------------------* + + +TYPE-POOLS seop. + +TYPES: ty_type TYPE c LENGTH 6, + ty_bitbyte TYPE c LENGTH 8, + ty_sha1 TYPE c LENGTH 40. + +TYPES: BEGIN OF ty_file, + path TYPE string, + filename TYPE string, + data TYPE xstring, + END OF ty_file. +TYPES: ty_files_tt TYPE STANDARD TABLE OF ty_file WITH DEFAULT KEY. + +TYPES: ty_string_tt TYPE STANDARD TABLE OF string WITH DEFAULT KEY. +TYPES: tt_w3urls TYPE STANDARD TABLE OF w3url WITH DEFAULT KEY. + +TYPES: BEGIN OF ty_comment, + username TYPE string, + email TYPE string, + comment TYPE string, + END OF ty_comment. + +TYPES: BEGIN OF ty_item, + obj_type TYPE tadir-object, + obj_name TYPE tadir-obj_name, + END OF ty_item. + +TYPES: BEGIN OF ty_file_item, + file TYPE ty_file, + item TYPE ty_item, + END OF ty_file_item. +TYPES: ty_files_item_tt TYPE STANDARD TABLE OF ty_file_item WITH DEFAULT KEY. + +TYPES: BEGIN OF ty_metadata, + class TYPE string, + version TYPE string, + late_deser TYPE string, + END OF ty_metadata. + +TYPES: BEGIN OF ty_web_asset, + url TYPE w3url, + content TYPE string, + END OF ty_web_asset. +TYPES tt_web_assets TYPE STANDARD TABLE OF ty_web_asset WITH DEFAULT KEY. + +TYPES: BEGIN OF ty_repo_file, + path TYPE string, + filename TYPE string, + is_changed TYPE abap_bool, + END OF ty_repo_file. +TYPES tt_repo_files TYPE STANDARD TABLE OF ty_repo_file WITH DEFAULT KEY. + +CONSTANTS: BEGIN OF gc_type, + commit TYPE ty_type VALUE 'commit', "#EC NOTEXT + tree TYPE ty_type VALUE 'tree', "#EC NOTEXT + ref_d TYPE ty_type VALUE 'ref_d', "#EC NOTEXT + blob TYPE ty_type VALUE 'blob', "#EC NOTEXT + END OF gc_type. + +TYPES: ty_chmod TYPE c LENGTH 6. + +TYPES: BEGIN OF ty_object, + sha1 TYPE ty_sha1, + type TYPE ty_type, + data TYPE xstring, + END OF ty_object. +TYPES: ty_objects_tt TYPE STANDARD TABLE OF ty_object WITH DEFAULT KEY. + +TYPES: BEGIN OF ty_tadir, + pgmid TYPE tadir-pgmid, + object TYPE tadir-object, + obj_name TYPE tadir-obj_name, + devclass TYPE tadir-devclass, + korrnum TYPE tadir-korrnum, + path TYPE string, + END OF ty_tadir. +TYPES: ty_tadir_tt TYPE STANDARD TABLE OF ty_tadir WITH DEFAULT KEY. + +TYPES: BEGIN OF ty_result, + obj_type TYPE tadir-object, + obj_name TYPE tadir-obj_name, + match TYPE sap_bool, + filename TYPE string, + package TYPE devclass, + path TYPE string, + END OF ty_result. +TYPES: ty_results_tt TYPE STANDARD TABLE OF ty_result WITH DEFAULT KEY. + +CONSTANTS: BEGIN OF gc_chmod, + file TYPE ty_chmod VALUE '100644', + executable TYPE ty_chmod VALUE '100755', + dir TYPE ty_chmod VALUE '40000 ', + END OF gc_chmod. + +CONSTANTS: BEGIN OF gc_event_state, + not_handled VALUE 0, + re_render VALUE 1, + new_page VALUE 2, + go_back VALUE 3, + no_more_act VALUE 4, + new_page_w_bookmark VALUE 5, + go_back_to_bookmark VALUE 6, + END OF gc_event_state. + +CONSTANTS: BEGIN OF gc_html_opt, + emphas TYPE c VALUE 'E', + cancel TYPE c VALUE 'C', + END OF gc_html_opt. + +CONSTANTS: BEGIN OF gc_action_type, + sapevent TYPE c VALUE 'E', + url TYPE c VALUE 'U', + onclick TYPE c VALUE 'C', + END OF gc_action_type. + +CONSTANTS: gc_newline TYPE abap_char1 VALUE cl_abap_char_utilities=>newline. + +CONSTANTS: gc_english TYPE spras VALUE 'E'. + +CONSTANTS: gc_abapgit_homepage TYPE string VALUE 'http://www.abapgit.org'. + +CONSTANTS: gc_root_dir TYPE string VALUE '/', + gc_dot_abapgit TYPE string VALUE '.abapgit.xml'. + +DEFINE _raise. + RAISE EXCEPTION TYPE lcx_exception + EXPORTING + iv_text = &1. "#EC NOTEXT +END-OF-DEFINITION. \ No newline at end of file diff --git a/src/zabapgit_definitions.prog.xml b/src/zabapgit_definitions.prog.xml new file mode 100644 index 000000000..6ed0ef3cc --- /dev/null +++ b/src/zabapgit_definitions.prog.xml @@ -0,0 +1,48 @@ + + + + + + ZABAPGIT_DEFINITIONS + A + + + X + + + + + + I + + + + 0000-00-00 + + 0000-00-00 + + + + + E + + + 0000-00-00 + + 0000-00-00 + + + X + + + + R + + Include ZABAPGIT_DEFINITIONS + 28 + + + + + + diff --git a/src/zabapgit_stage.prog.abap b/src/zabapgit_stage.prog.abap index 7a4bc0a61..5088ec881 100644 --- a/src/zabapgit_stage.prog.abap +++ b/src/zabapgit_stage.prog.abap @@ -2,245 +2,94 @@ *& Include ZABAPGIT_STAGE *&---------------------------------------------------------------------* -CLASS lcl_stage_logic DEFINITION FINAL. +*----------------------------------------------------------------------* +* CLASS lcl_stage DEFINITION +*----------------------------------------------------------------------* +CLASS lcl_stage DEFINITION FINAL CREATE PRIVATE FRIENDS lcl_repo_srv. PUBLIC SECTION. - TYPES: BEGIN OF ty_stage_files, - local TYPE ty_files_item_tt, - remote TYPE ty_files_tt, - END OF ty_stage_files. + TYPES: ty_method TYPE c LENGTH 1. - CLASS-METHODS: - get - IMPORTING io_repo TYPE REF TO lcl_repo_online - RETURNING VALUE(rs_files) TYPE ty_stage_files + CONSTANTS: BEGIN OF c_method, + add TYPE ty_method VALUE 'A', + rm TYPE ty_method VALUE 'R', + ignore TYPE ty_method VALUE 'I', + END OF c_method. + + CONSTANTS: BEGIN OF c_wftype, + local TYPE char1 VALUE 'L', + remote TYPE char1 VALUE 'R', + END OF c_wftype. + + TYPES: BEGIN OF ty_stage, + file TYPE ty_file, + method TYPE ty_method, + END OF ty_stage. + + TYPES: ty_stage_tt TYPE SORTED TABLE OF ty_stage + WITH UNIQUE KEY file-path file-filename. + + TYPES: BEGIN OF ty_work_file, + type TYPE char1, + file TYPE ty_file, + END OF ty_work_file. + + DATA mv_repo_key TYPE lcl_persistence_db=>ty_value READ-ONLY. + DATA mv_local_cnt TYPE i READ-ONLY. + DATA mt_workarea TYPE STANDARD TABLE OF ty_work_file READ-ONLY. + + CLASS-METHODS method_description + IMPORTING iv_method TYPE ty_method + RETURNING VALUE(rv_description) TYPE string + RAISING lcx_exception. + + METHODS constructor + IMPORTING iv_repo_key TYPE lcl_persistence_db=>ty_value + RAISING lcx_exception. + + METHODS update_and_add_dot_abapgit + IMPORTING iv_data TYPE ty_file-data + RAISING lcx_exception. + + METHODS: + add + IMPORTING iv_path TYPE ty_file-path + iv_filename TYPE ty_file-filename RAISING lcx_exception, + reset + IMPORTING iv_path TYPE ty_file-path + iv_filename TYPE ty_file-filename + RAISING lcx_exception, + rm + IMPORTING iv_path TYPE ty_file-path + iv_filename TYPE ty_file-filename + RAISING lcx_exception, + ignore + IMPORTING iv_path TYPE ty_file-path + iv_filename TYPE ty_file-filename + RAISING lcx_exception, + lookup + IMPORTING iv_path TYPE ty_file-path + iv_filename TYPE ty_file-filename + RETURNING VALUE(rv_method) TYPE ty_method, count - IMPORTING io_repo TYPE REF TO lcl_repo_online - RETURNING VALUE(rv_count) TYPE i - RAISING lcx_exception. + RETURNING VALUE(rv_count) TYPE i, + get_all + RETURNING VALUE(rt_stage) TYPE ty_stage_tt. PRIVATE SECTION. - CLASS-METHODS: - remove_ignored - IMPORTING io_repo TYPE REF TO lcl_repo_online - CHANGING cs_files TYPE ty_stage_files, - remove_identical - CHANGING cs_files TYPE ty_stage_files. + DATA: mt_stage TYPE ty_stage_tt. -ENDCLASS. + METHODS append + IMPORTING iv_path TYPE ty_file-path + iv_filename TYPE ty_file-filename + iv_method TYPE ty_method + RAISING lcx_exception. -CLASS lcl_stage_logic IMPLEMENTATION. + METHODS find_work_file + IMPORTING iv_path TYPE ty_file-path + iv_filename TYPE ty_file-filename + RETURNING VALUE(rs_file) TYPE ty_file + RAISING lcx_exception. - METHOD get. - rs_files-local = io_repo->get_files_local( ). - rs_files-remote = io_repo->get_files_remote( ). - remove_identical( CHANGING cs_files = rs_files ). - remove_ignored( EXPORTING io_repo = io_repo - CHANGING cs_files = rs_files ). - ENDMETHOD. - - METHOD count. - - DATA: ls_files TYPE ty_stage_files. - - ls_files = get( io_repo ). - - rv_count = lines( ls_files-remote ) + lines( ls_files-local ). - - ENDMETHOD. - - METHOD remove_ignored. - - DATA: lv_index TYPE i. - - FIELD-SYMBOLS: LIKE LINE OF cs_files-remote. - - - LOOP AT cs_files-remote ASSIGNING . - lv_index = sy-tabix. - - IF io_repo->get_dot_abapgit( )->is_ignored( - iv_path = -path - iv_filename = -filename ) = abap_true. - DELETE cs_files-remote INDEX lv_index. - ENDIF. - ENDLOOP. - - ENDMETHOD. - - METHOD remove_identical. - - DATA: lv_index TYPE i, - ls_remote LIKE LINE OF cs_files-remote. - - FIELD-SYMBOLS: LIKE LINE OF cs_files-local. - - - LOOP AT cs_files-local ASSIGNING . - lv_index = sy-tabix. - - READ TABLE cs_files-remote INTO ls_remote - WITH KEY path = -file-path - filename = -file-filename. - IF sy-subrc = 0. - DELETE cs_files-remote INDEX sy-tabix. - IF ls_remote-data = -file-data. - DELETE cs_files-local INDEX lv_index. - ENDIF. - ENDIF. - ENDLOOP. - - ENDMETHOD. - -ENDCLASS. - -CLASS lcl_stage IMPLEMENTATION. - - METHOD constructor. - DATA: ls_files TYPE lcl_stage_logic=>ty_stage_files, - lo_repo TYPE REF TO lcl_repo_online, - ls_work_file LIKE LINE OF mt_workarea. - - FIELD-SYMBOLS: LIKE LINE OF ls_files-local, - LIKE LINE OF ls_files-remote. - - mv_repo_key = iv_repo_key. - lo_repo ?= lcl_app=>repo_srv( )->get( iv_repo_key ). - ls_files = lcl_stage_logic=>get( lo_repo ). - - " Unify structures - LOOP AT ls_files-local ASSIGNING . - ls_work_file-type = c_wftype-local. - ls_work_file-file = -file. - APPEND ls_work_file TO mt_workarea. - mv_local_cnt = mv_local_cnt + 1. - ENDLOOP. - - LOOP AT ls_files-remote ASSIGNING . - ls_work_file-type = c_wftype-remote. - ls_work_file-file = . - APPEND ls_work_file TO mt_workarea. - ENDLOOP. - - ENDMETHOD. "constructor - - METHOD lookup. - DATA ls_stage LIKE LINE OF mt_stage. - - READ TABLE mt_stage INTO ls_stage - WITH KEY file-path = iv_path - file-filename = iv_filename. - IF sy-subrc = 0. - rv_method = ls_stage-method. - ENDIF. - - ENDMETHOD. "lookup - - METHOD get_all. - rt_stage = mt_stage. - ENDMETHOD. "get_all - - METHOD append. - - DATA: ls_stage LIKE LINE OF mt_stage, - ls_file TYPE ty_file. - - FIELD-SYMBOLS: LIKE LINE OF mt_stage. - - ls_file = find_work_file( iv_path = iv_path iv_filename = iv_filename ). - - READ TABLE mt_stage WITH KEY - file-path = ls_file-path - file-filename = ls_file-filename - ASSIGNING . - IF sy-subrc = 0. - -file-data = ls_file-data. - -method = iv_method. - ELSE. - ls_stage-file = ls_file. - ls_stage-method = iv_method. - INSERT ls_stage INTO TABLE mt_stage. - ENDIF. - - ENDMETHOD. "append - - METHOD method_description. - - CASE iv_method. - WHEN c_method-add. - rv_description = 'add'. - WHEN c_method-rm. - rv_description = 'rm'. - WHEN c_method-ignore. - rv_description = 'ignore' ##NO_TEXT. - WHEN OTHERS. - _raise 'unknown staging method type'. - ENDCASE. - - ENDMETHOD. "method_description - - METHOD add. - append( iv_path = iv_path - iv_filename = iv_filename - iv_method = c_method-add ). - ENDMETHOD. "add - - METHOD reset. - DELETE mt_stage WHERE file-path = iv_path - AND file-filename = iv_filename. - ASSERT sy-subrc = 0. - ENDMETHOD. "reset - - METHOD rm. - append( iv_path = iv_path - iv_filename = iv_filename - iv_method = c_method-rm ). - ENDMETHOD. "rm - - METHOD ignore. - append( iv_path = iv_path - iv_filename = iv_filename - iv_method = c_method-ignore ). - ENDMETHOD. "ignore - - METHOD count. - rv_count = lines( mt_stage ). - ENDMETHOD. "count - - METHOD find_work_file. - DATA ls_work_file LIKE LINE OF mt_workarea. - - READ TABLE mt_workarea INTO ls_work_file - WITH KEY file-path = iv_path - file-filename = iv_filename. - IF sy-subrc = 0. - rs_file = ls_work_file-file. - ELSE. - _raise 'File not found in workarea'. - ENDIF. - - ENDMETHOD. "check_work_file_exists - - METHOD update_and_add_dot_abapgit. - - FIELD-SYMBOLS LIKE LINE OF mt_workarea. - - READ TABLE mt_workarea ASSIGNING - WITH KEY file-path = gc_root_dir - file-filename = gc_dot_abapgit. - IF sy-subrc <> 0. - APPEND INITIAL LINE TO mt_workarea ASSIGNING . - -type = c_wftype-local. - -file-path = gc_root_dir. - -file-filename = gc_dot_abapgit. - ENDIF. - - -file-data = iv_data. - - add( iv_path = gc_root_dir - iv_filename = gc_dot_abapgit ). - - ENDMETHOD. "update_and_add_dot_abapgit - -ENDCLASS. \ No newline at end of file +ENDCLASS. "lcl_stage DEFINITION \ No newline at end of file diff --git a/src/zabapgit_stage_impl.prog.abap b/src/zabapgit_stage_impl.prog.abap new file mode 100644 index 000000000..9792791e8 --- /dev/null +++ b/src/zabapgit_stage_impl.prog.abap @@ -0,0 +1,246 @@ +*&---------------------------------------------------------------------* +*& Include ZABAPGIT_STAGE_IMPL +*&---------------------------------------------------------------------* + +CLASS lcl_stage_logic DEFINITION FINAL. + + PUBLIC SECTION. + TYPES: BEGIN OF ty_stage_files, + local TYPE ty_files_item_tt, + remote TYPE ty_files_tt, + END OF ty_stage_files. + + CLASS-METHODS: + get + IMPORTING io_repo TYPE REF TO lcl_repo_online + RETURNING VALUE(rs_files) TYPE ty_stage_files + RAISING lcx_exception, + count + IMPORTING io_repo TYPE REF TO lcl_repo_online + RETURNING VALUE(rv_count) TYPE i + RAISING lcx_exception. + + PRIVATE SECTION. + CLASS-METHODS: + remove_ignored + IMPORTING io_repo TYPE REF TO lcl_repo_online + CHANGING cs_files TYPE ty_stage_files, + remove_identical + CHANGING cs_files TYPE ty_stage_files. + +ENDCLASS. + +CLASS lcl_stage_logic IMPLEMENTATION. + + METHOD get. + rs_files-local = io_repo->get_files_local( ). + rs_files-remote = io_repo->get_files_remote( ). + remove_identical( CHANGING cs_files = rs_files ). + remove_ignored( EXPORTING io_repo = io_repo + CHANGING cs_files = rs_files ). + ENDMETHOD. + + METHOD count. + + DATA: ls_files TYPE ty_stage_files. + + ls_files = get( io_repo ). + + rv_count = lines( ls_files-remote ) + lines( ls_files-local ). + + ENDMETHOD. + + METHOD remove_ignored. + + DATA: lv_index TYPE i. + + FIELD-SYMBOLS: LIKE LINE OF cs_files-remote. + + + LOOP AT cs_files-remote ASSIGNING . + lv_index = sy-tabix. + + IF io_repo->get_dot_abapgit( )->is_ignored( + iv_path = -path + iv_filename = -filename ) = abap_true. + DELETE cs_files-remote INDEX lv_index. + ENDIF. + ENDLOOP. + + ENDMETHOD. + + METHOD remove_identical. + + DATA: lv_index TYPE i, + ls_remote LIKE LINE OF cs_files-remote. + + FIELD-SYMBOLS: LIKE LINE OF cs_files-local. + + + LOOP AT cs_files-local ASSIGNING . + lv_index = sy-tabix. + + READ TABLE cs_files-remote INTO ls_remote + WITH KEY path = -file-path + filename = -file-filename. + IF sy-subrc = 0. + DELETE cs_files-remote INDEX sy-tabix. + IF ls_remote-data = -file-data. + DELETE cs_files-local INDEX lv_index. + ENDIF. + ENDIF. + ENDLOOP. + + ENDMETHOD. + +ENDCLASS. + +CLASS lcl_stage IMPLEMENTATION. + + METHOD constructor. + DATA: ls_files TYPE lcl_stage_logic=>ty_stage_files, + lo_repo TYPE REF TO lcl_repo_online, + ls_work_file LIKE LINE OF mt_workarea. + + FIELD-SYMBOLS: LIKE LINE OF ls_files-local, + LIKE LINE OF ls_files-remote. + + mv_repo_key = iv_repo_key. + lo_repo ?= lcl_app=>repo_srv( )->get( iv_repo_key ). + ls_files = lcl_stage_logic=>get( lo_repo ). + + " Unify structures + LOOP AT ls_files-local ASSIGNING . + ls_work_file-type = c_wftype-local. + ls_work_file-file = -file. + APPEND ls_work_file TO mt_workarea. + mv_local_cnt = mv_local_cnt + 1. + ENDLOOP. + + LOOP AT ls_files-remote ASSIGNING . + ls_work_file-type = c_wftype-remote. + ls_work_file-file = . + APPEND ls_work_file TO mt_workarea. + ENDLOOP. + + ENDMETHOD. "constructor + + METHOD lookup. + DATA ls_stage LIKE LINE OF mt_stage. + + READ TABLE mt_stage INTO ls_stage + WITH KEY file-path = iv_path + file-filename = iv_filename. + IF sy-subrc = 0. + rv_method = ls_stage-method. + ENDIF. + + ENDMETHOD. "lookup + + METHOD get_all. + rt_stage = mt_stage. + ENDMETHOD. "get_all + + METHOD append. + + DATA: ls_stage LIKE LINE OF mt_stage, + ls_file TYPE ty_file. + + FIELD-SYMBOLS: LIKE LINE OF mt_stage. + + ls_file = find_work_file( iv_path = iv_path iv_filename = iv_filename ). + + READ TABLE mt_stage WITH KEY + file-path = ls_file-path + file-filename = ls_file-filename + ASSIGNING . + IF sy-subrc = 0. + -file-data = ls_file-data. + -method = iv_method. + ELSE. + ls_stage-file = ls_file. + ls_stage-method = iv_method. + INSERT ls_stage INTO TABLE mt_stage. + ENDIF. + + ENDMETHOD. "append + + METHOD method_description. + + CASE iv_method. + WHEN c_method-add. + rv_description = 'add'. + WHEN c_method-rm. + rv_description = 'rm'. + WHEN c_method-ignore. + rv_description = 'ignore' ##NO_TEXT. + WHEN OTHERS. + _raise 'unknown staging method type'. + ENDCASE. + + ENDMETHOD. "method_description + + METHOD add. + append( iv_path = iv_path + iv_filename = iv_filename + iv_method = c_method-add ). + ENDMETHOD. "add + + METHOD reset. + DELETE mt_stage WHERE file-path = iv_path + AND file-filename = iv_filename. + ASSERT sy-subrc = 0. + ENDMETHOD. "reset + + METHOD rm. + append( iv_path = iv_path + iv_filename = iv_filename + iv_method = c_method-rm ). + ENDMETHOD. "rm + + METHOD ignore. + append( iv_path = iv_path + iv_filename = iv_filename + iv_method = c_method-ignore ). + ENDMETHOD. "ignore + + METHOD count. + rv_count = lines( mt_stage ). + ENDMETHOD. "count + + METHOD find_work_file. + DATA ls_work_file LIKE LINE OF mt_workarea. + + READ TABLE mt_workarea INTO ls_work_file + WITH KEY file-path = iv_path + file-filename = iv_filename. + IF sy-subrc = 0. + rs_file = ls_work_file-file. + ELSE. + _raise 'File not found in workarea'. + ENDIF. + + ENDMETHOD. "check_work_file_exists + + METHOD update_and_add_dot_abapgit. + + FIELD-SYMBOLS LIKE LINE OF mt_workarea. + + READ TABLE mt_workarea ASSIGNING + WITH KEY file-path = gc_root_dir + file-filename = gc_dot_abapgit. + IF sy-subrc <> 0. + APPEND INITIAL LINE TO mt_workarea ASSIGNING . + -type = c_wftype-local. + -file-path = gc_root_dir. + -file-filename = gc_dot_abapgit. + ENDIF. + + -file-data = iv_data. + + add( iv_path = gc_root_dir + iv_filename = gc_dot_abapgit ). + + ENDMETHOD. "update_and_add_dot_abapgit + +ENDCLASS. \ No newline at end of file diff --git a/src/zabapgit_stage_impl.prog.xml b/src/zabapgit_stage_impl.prog.xml new file mode 100644 index 000000000..34bcb28dd --- /dev/null +++ b/src/zabapgit_stage_impl.prog.xml @@ -0,0 +1,48 @@ + + + + + + ZABAPGIT_STAGE_IMPL + A + + + X + + + + + + I + + + + 0000-00-00 + + 0000-00-00 + + + + + E + + + 0000-00-00 + + 0000-00-00 + + + X + + + + R + + Include ZABAPGIT_STAGE_IMPL + 27 + + + + + +