Remove local SHA1 from online repository #1485, #1509 (#1666)

* Remove local SHA1 from online repository

In this commit we remove the local SHA1 and all its references from
ZCL_ABAPGIT_REPO_ONLINE. SHA1 is also removed from repo persistency.
SHA1 insn't needed anymore. All where-used places were either migrated to
remote_SHA1 or removed.

* reintroduce logic after push
This commit is contained in:
Christian Günter 2018-07-22 10:11:09 +02:00 committed by Lars Hvam
parent 45bb5c7405
commit 7ac8dc15b6
9 changed files with 20 additions and 87 deletions

View File

@ -27,7 +27,7 @@ CLASS zcl_abapgit_git_porcelain DEFINITION
IMPORTING IMPORTING
!io_repo TYPE REF TO zcl_abapgit_repo_online !io_repo TYPE REF TO zcl_abapgit_repo_online
!iv_name TYPE string !iv_name TYPE string
!iv_from TYPE zif_abapgit_definitions=>ty_sha1 iv_from TYPE zif_abapgit_definitions=>ty_sha1
RAISING RAISING
zcx_abapgit_exception . zcx_abapgit_exception .
CLASS-METHODS create_tag CLASS-METHODS create_tag
@ -198,8 +198,6 @@ CLASS zcl_abapgit_git_porcelain IMPLEMENTATION.
IF iv_name CS ` `. IF iv_name CS ` `.
zcx_abapgit_exception=>raise( 'Branch name cannot contain blank spaces' ). zcx_abapgit_exception=>raise( 'Branch name cannot contain blank spaces' ).
ELSEIF iv_from = ''.
zcx_abapgit_exception=>raise( 'New branch, "from" SHA1 empty' ).
ENDIF. ENDIF.
* "client MUST send an empty packfile" * "client MUST send an empty packfile"
@ -720,7 +718,7 @@ CLASS zcl_abapgit_git_porcelain IMPLEMENTATION.
zcl_abapgit_git_transport=>receive_pack( zcl_abapgit_git_transport=>receive_pack(
iv_url = io_repo->get_url( ) iv_url = io_repo->get_url( )
iv_old = c_zero iv_old = c_zero
iv_new = io_repo->get_sha1_local( ) iv_new = is_tag-sha1
iv_branch_name = is_tag-name iv_branch_name = is_tag-name
iv_pack = lv_pack ). iv_pack = lv_pack ).

View File

@ -10,12 +10,6 @@ CLASS zcl_abapgit_persistence_repo DEFINITION
VALUE(rt_repos) TYPE zif_abapgit_persistence=>tt_repo VALUE(rt_repos) TYPE zif_abapgit_persistence=>tt_repo
RAISING RAISING
zcx_abapgit_exception . zcx_abapgit_exception .
METHODS update_sha1
IMPORTING
!iv_key TYPE zif_abapgit_persistence=>ty_repo-key
!iv_branch_sha1 TYPE zif_abapgit_persistence=>ty_repo_xml-sha1
RAISING
zcx_abapgit_exception .
METHODS update_local_checksums METHODS update_local_checksums
IMPORTING IMPORTING
!iv_key TYPE zif_abapgit_persistence=>ty_repo-key !iv_key TYPE zif_abapgit_persistence=>ty_repo-key
@ -114,7 +108,7 @@ ENDCLASS.
CLASS ZCL_ABAPGIT_PERSISTENCE_REPO IMPLEMENTATION. CLASS zcl_abapgit_persistence_repo IMPLEMENTATION.
METHOD add. METHOD add.
@ -125,7 +119,6 @@ CLASS ZCL_ABAPGIT_PERSISTENCE_REPO IMPLEMENTATION.
ls_repo-url = iv_url. ls_repo-url = iv_url.
ls_repo-branch_name = iv_branch_name. ls_repo-branch_name = iv_branch_name.
ls_repo-sha1 = iv_branch.
ls_repo-package = iv_package. ls_repo-package = iv_package.
ls_repo-offline = iv_offline. ls_repo-offline = iv_offline.
ls_repo-created_by = sy-uname. ls_repo-created_by = sy-uname.
@ -424,31 +417,6 @@ CLASS ZCL_ABAPGIT_PERSISTENCE_REPO IMPLEMENTATION.
ENDMETHOD. "update_offline ENDMETHOD. "update_offline
METHOD update_sha1.
DATA: lt_content TYPE zif_abapgit_persistence=>tt_content,
ls_content LIKE LINE OF lt_content,
ls_repo TYPE zif_abapgit_persistence=>ty_repo.
ASSERT NOT iv_key IS INITIAL.
TRY.
ls_repo = read( iv_key ).
CATCH zcx_abapgit_not_found.
zcx_abapgit_exception=>raise( 'key not found' ).
ENDTRY.
ls_repo-sha1 = iv_branch_sha1.
ls_content-data_str = to_xml( ls_repo ).
mo_db->update( iv_type = zcl_abapgit_persistence_db=>c_type_repo
iv_value = iv_key
iv_data = ls_content-data_str ).
ENDMETHOD.
METHOD update_url. METHOD update_url.
DATA: lt_content TYPE zif_abapgit_persistence=>tt_content, DATA: lt_content TYPE zif_abapgit_persistence=>tt_content,

View File

@ -32,7 +32,6 @@ INTERFACE zif_abapgit_persistence PUBLIC.
TYPES: BEGIN OF ty_repo_xml, TYPES: BEGIN OF ty_repo_xml,
url TYPE string, url TYPE string,
branch_name TYPE string, branch_name TYPE string,
sha1 TYPE zif_abapgit_definitions=>ty_sha1,
package TYPE devclass, package TYPE devclass,
created_by TYPE xubname, created_by TYPE xubname,
created_at TYPE timestampl, created_at TYPE timestampl,

View File

@ -157,7 +157,7 @@ CLASS zcl_abapgit_gui_page_tag IMPLEMENTATION.
ro_html->add( render_text_input( iv_name = 'sha1' ro_html->add( render_text_input( iv_name = 'sha1'
iv_label = 'SHA1' iv_label = 'SHA1'
iv_value = mo_repo_online->get_sha1_local( ) ) ). iv_value = mo_repo_online->get_sha1_remote( ) ) ).
ro_html->add( render_text_input( iv_name = 'name' ro_html->add( render_text_input( iv_name = 'name'
iv_label = 'tag name' ) ). iv_label = 'tag name' ) ).

View File

@ -145,7 +145,7 @@ CLASS zcl_abapgit_services_git IMPLEMENTATION.
zcl_abapgit_git_porcelain=>create_branch( zcl_abapgit_git_porcelain=>create_branch(
io_repo = lo_repo io_repo = lo_repo
iv_name = lv_name iv_name = lv_name
iv_from = lo_repo->get_sha1_local( ) ). iv_from = lo_repo->get_sha1_remote( ) ).
" automatically switch to new branch " automatically switch to new branch
lo_repo->set_branch_name( lv_name ). lo_repo->set_branch_name( lv_name ).

View File

@ -114,7 +114,6 @@ CLASS zcl_abapgit_repo DEFINITION
METHODS set METHODS set
IMPORTING IMPORTING
!iv_sha1 TYPE zif_abapgit_definitions=>ty_sha1 OPTIONAL
!it_checksums TYPE zif_abapgit_persistence=>ty_local_checksum_tt OPTIONAL !it_checksums TYPE zif_abapgit_persistence=>ty_local_checksum_tt OPTIONAL
!iv_url TYPE zif_abapgit_persistence=>ty_repo-url OPTIONAL !iv_url TYPE zif_abapgit_persistence=>ty_repo-url OPTIONAL
!iv_branch_name TYPE zif_abapgit_persistence=>ty_repo-branch_name OPTIONAL !iv_branch_name TYPE zif_abapgit_persistence=>ty_repo-branch_name OPTIONAL
@ -457,8 +456,7 @@ CLASS zcl_abapgit_repo IMPLEMENTATION.
DATA: lo_persistence TYPE REF TO zcl_abapgit_persistence_repo. DATA: lo_persistence TYPE REF TO zcl_abapgit_persistence_repo.
ASSERT iv_sha1 IS SUPPLIED ASSERT it_checksums IS SUPPLIED
OR it_checksums IS SUPPLIED
OR iv_url IS SUPPLIED OR iv_url IS SUPPLIED
OR iv_branch_name IS SUPPLIED OR iv_branch_name IS SUPPLIED
OR iv_head_branch IS SUPPLIED OR iv_head_branch IS SUPPLIED
@ -468,13 +466,6 @@ CLASS zcl_abapgit_repo IMPLEMENTATION.
CREATE OBJECT lo_persistence. CREATE OBJECT lo_persistence.
IF iv_sha1 IS SUPPLIED.
lo_persistence->update_sha1(
iv_key = ms_data-key
iv_branch_sha1 = iv_sha1 ).
ms_data-sha1 = iv_sha1.
ENDIF.
IF it_checksums IS SUPPLIED. IF it_checksums IS SUPPLIED.
lo_persistence->update_local_checksums( lo_persistence->update_local_checksums(
iv_key = ms_data-key iv_key = ms_data-key

View File

@ -36,12 +36,9 @@ CLASS zcl_abapgit_repo_online DEFINITION
!iv_branch_name TYPE zif_abapgit_persistence=>ty_repo-branch_name !iv_branch_name TYPE zif_abapgit_persistence=>ty_repo-branch_name
RAISING RAISING
zcx_abapgit_exception . zcx_abapgit_exception .
METHODS get_sha1_local
RETURNING
VALUE(rv_sha1) TYPE zif_abapgit_persistence=>ty_repo-sha1 .
METHODS get_sha1_remote METHODS get_sha1_remote
RETURNING RETURNING
VALUE(rv_sha1) TYPE zif_abapgit_persistence=>ty_repo-sha1 VALUE(rv_sha1) TYPE zif_abapgit_definitions=>ty_sha1
RAISING RAISING
zcx_abapgit_exception . zcx_abapgit_exception .
METHODS get_objects METHODS get_objects
@ -137,7 +134,7 @@ CLASS zcl_abapgit_repo_online IMPLEMENTATION.
METHOD delete_initial_online_repo. METHOD delete_initial_online_repo.
IF me->is_offline( ) = abap_false AND me->get_sha1_local( ) IS INITIAL. IF me->is_offline( ) = abap_false AND me->get_sha1_remote( ) IS INITIAL.
zcl_abapgit_repo_srv=>get_instance( )->delete( me ). zcl_abapgit_repo_srv=>get_instance( )->delete( me ).
@ -156,8 +153,6 @@ CLASS zcl_abapgit_repo_online IMPLEMENTATION.
super->deserialize( is_checks ). super->deserialize( is_checks ).
set( iv_sha1 = mv_branch ).
reset_status( ). reset_status( ).
COMMIT WORK AND WAIT. COMMIT WORK AND WAIT.
@ -189,11 +184,6 @@ CLASS zcl_abapgit_repo_online IMPLEMENTATION.
ENDMETHOD. "get_objects ENDMETHOD. "get_objects
METHOD get_sha1_local.
rv_sha1 = ms_data-sha1.
ENDMETHOD. "get_sha1_local
METHOD get_sha1_remote. METHOD get_sha1_remote.
initialize( ). initialize( ).
@ -321,20 +311,15 @@ CLASS zcl_abapgit_repo_online IMPLEMENTATION.
IMPORTING ev_branch = lv_branch IMPORTING ev_branch = lv_branch
et_updated_files = lt_updated_files ). et_updated_files = lt_updated_files ).
IF io_stage->get_branch_sha1( ) = get_sha1_local( ). IF io_stage->get_branch_sha1( ) = get_sha1_remote( ).
* pushing to the branch currently represented by this repository object * pushing to the branch currently represented by this repository object mv_branch = lv_branch.
mv_branch = lv_branch. mv_branch = lv_branch.
set( iv_sha1 = lv_branch ).
ELSE. ELSE.
refresh( ). refresh( ).
ENDIF. ENDIF.
update_local_checksums( lt_updated_files ). update_local_checksums( lt_updated_files ).
IF zcl_abapgit_stage_logic=>count( me ) = 0.
set( iv_sha1 = lv_branch ).
ENDIF.
CLEAR: mv_code_inspector_successful. CLEAR: mv_code_inspector_successful.
ENDMETHOD. "push ENDMETHOD. "push
@ -342,20 +327,18 @@ CLASS zcl_abapgit_repo_online IMPLEMENTATION.
METHOD rebuild_local_checksums. "REMOTE METHOD rebuild_local_checksums. "REMOTE
DATA: lt_remote TYPE zif_abapgit_definitions=>ty_files_tt, DATA: lt_remote TYPE zif_abapgit_definitions=>ty_files_tt,
lt_local TYPE zif_abapgit_definitions=>ty_files_item_tt, lt_local TYPE zif_abapgit_definitions=>ty_files_item_tt,
ls_last_item TYPE zif_abapgit_definitions=>ty_item, ls_last_item TYPE zif_abapgit_definitions=>ty_item,
lv_branch_equal TYPE abap_bool, lt_checksums TYPE zif_abapgit_persistence=>ty_local_checksum_tt.
lt_checksums TYPE zif_abapgit_persistence=>ty_local_checksum_tt.
FIELD-SYMBOLS: <ls_checksum> LIKE LINE OF lt_checksums, FIELD-SYMBOLS: <ls_checksum> LIKE LINE OF lt_checksums,
<ls_file_sig> LIKE LINE OF <ls_checksum>-files, <ls_file_sig> LIKE LINE OF <ls_checksum>-files,
<ls_remote> LIKE LINE OF lt_remote, <ls_remote> LIKE LINE OF lt_remote,
<ls_local> LIKE LINE OF lt_local. <ls_local> LIKE LINE OF lt_local.
lt_remote = get_files_remote( ). lt_remote = get_files_remote( ).
lt_local = get_files_local( ). lt_local = get_files_local( ).
lv_branch_equal = boolc( get_sha1_remote( ) = get_sha1_local( ) ).
DELETE lt_local " Remove non-code related files except .abapgit DELETE lt_local " Remove non-code related files except .abapgit
WHERE item IS INITIAL WHERE item IS INITIAL
@ -383,7 +366,7 @@ CLASS zcl_abapgit_repo_online IMPLEMENTATION.
" If hashes are equal -> local sha1 is OK " If hashes are equal -> local sha1 is OK
" Else if R-branch is ahead -> assume changes were remote, state - local sha1 " Else if R-branch is ahead -> assume changes were remote, state - local sha1
" Else (branches equal) -> assume changes were local, state - remote sha1 " Else (branches equal) -> assume changes were local, state - remote sha1
IF <ls_local>-file-sha1 <> <ls_remote>-sha1 AND lv_branch_equal = abap_true. IF <ls_local>-file-sha1 <> <ls_remote>-sha1.
<ls_file_sig>-sha1 = <ls_remote>-sha1. <ls_file_sig>-sha1 = <ls_remote>-sha1.
ENDIF. ENDIF.
ENDLOOP. ENDLOOP.
@ -487,12 +470,7 @@ CLASS zcl_abapgit_repo_online IMPLEMENTATION.
mv_initialized = abap_false. mv_initialized = abap_false.
set( iv_url = iv_url set( iv_url = iv_url
iv_branch_name = iv_branch_name iv_branch_name = iv_branch_name
iv_head_branch = '' iv_head_branch = '' ).
iv_sha1 = '' ).
" If the SHA1 is empty, it's not possible to create tags or branches.
" Therefore we update the local SHA1 with the new remote SHA1
set( iv_sha1 = get_sha1_remote( ) ).
ENDMETHOD. "set_new_remote ENDMETHOD. "set_new_remote

View File

@ -310,7 +310,6 @@ CLASS zcl_abapgit_repo_srv IMPLEMENTATION.
lo_repo->set( lo_repo->set(
iv_url = zcl_abapgit_url=>name( lo_repo->ms_data-url ) iv_url = zcl_abapgit_url=>name( lo_repo->ms_data-url )
iv_branch_name = '' iv_branch_name = ''
iv_sha1 = ''
iv_head_branch = '' iv_head_branch = ''
iv_offline = abap_true ). iv_offline = abap_true ).
CREATE OBJECT <lo_repo> TYPE zcl_abapgit_repo_offline CREATE OBJECT <lo_repo> TYPE zcl_abapgit_repo_offline

View File

@ -33,7 +33,7 @@ ENDCLASS.
CLASS ZCL_ABAPGIT_TRANSPORT_2_BRANCH IMPLEMENTATION. CLASS zcl_abapgit_transport_2_branch IMPLEMENTATION.
METHOD create. METHOD create.
@ -79,7 +79,7 @@ CLASS ZCL_ABAPGIT_TRANSPORT_2_BRANCH IMPLEMENTATION.
zcl_abapgit_git_porcelain=>create_branch( zcl_abapgit_git_porcelain=>create_branch(
io_repo = io_repository io_repo = io_repository
iv_name = iv_branch_name iv_name = iv_branch_name
iv_from = io_repository->get_sha1_local( ) ). iv_from = io_repository->get_sha1_remote( ) ).
io_repository->set_branch_name( iv_branch_name ). io_repository->set_branch_name( iv_branch_name ).
CATCH zcx_abapgit_exception. CATCH zcx_abapgit_exception.