From de8618af320f5b8f4f5a8538b5e7b558b4ebf284 Mon Sep 17 00:00:00 2001 From: Sdfraga Date: Fri, 29 Mar 2019 07:10:23 +0100 Subject: [PATCH] Fixing Page Branch Overview Hierarchy (#2594) * Divide determine_branch for simplicity * Separate Branches and Commits * Sort branches by Commit Time * Fixing abaplint errors --- src/zcl_abapgit_branch_overview.clas.abap | 50 ++++++++++++++++++----- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/zcl_abapgit_branch_overview.clas.abap b/src/zcl_abapgit_branch_overview.clas.abap index a1a176f55..7714e44bc 100644 --- a/src/zcl_abapgit_branch_overview.clas.abap +++ b/src/zcl_abapgit_branch_overview.clas.abap @@ -75,7 +75,7 @@ ENDCLASS. -CLASS ZCL_ABAPGIT_BRANCH_OVERVIEW IMPLEMENTATION. +CLASS zcl_abapgit_branch_overview IMPLEMENTATION. METHOD constructor. @@ -103,15 +103,23 @@ CLASS ZCL_ABAPGIT_BRANCH_OVERVIEW IMPLEMENTATION. CONSTANTS: lc_head TYPE string VALUE 'HEAD'. - DATA: lv_name TYPE string. + TYPES: BEGIN OF ty_branch_with_time, + time TYPE string, + name TYPE string, + sha1 TYPE zif_abapgit_definitions=>ty_sha1, + END OF ty_branch_with_time. - FIELD-SYMBOLS: LIKE LINE OF mt_branches, - LIKE LINE OF mt_branches, - LIKE LINE OF mt_commits, - LIKE LINE OF -create. + DATA: lt_branches_sorted_by_time TYPE SORTED TABLE OF ty_branch_with_time WITH NON-UNIQUE KEY time, + ls_branches_with_time TYPE ty_branch_with_time. + + FIELD-SYMBOLS: LIKE LINE OF mt_branches, + LIKE LINE OF lt_branches_sorted_by_time, + LIKE LINE OF mt_branches, + LIKE LINE OF mt_commits, + LIKE LINE OF -create. -* exchange HEAD, and make sure the branch determination starts with the HEAD branch +* Exchange HEAD, and make sure the branch determination starts with the HEAD branch READ TABLE mt_branches ASSIGNING WITH KEY name = lc_head. ASSERT sy-subrc = 0. LOOP AT mt_branches ASSIGNING @@ -121,17 +129,39 @@ CLASS ZCL_ABAPGIT_BRANCH_OVERVIEW IMPLEMENTATION. EXIT. ENDLOOP. +* Sort Branches by Commit Time LOOP AT mt_branches ASSIGNING . - lv_name = -name+11. + READ TABLE mt_commits ASSIGNING WITH KEY sha1 = -sha1. + IF sy-subrc = 0. + + ls_branches_with_time-name = -name+11. + ls_branches_with_time-sha1 = -sha1. + + IF -is_head = abap_true. + ls_branches_with_time-time = '0000000000'. "Force HEAD to be the first one + ELSE. + ls_branches_with_time-time = -time. + ENDIF. + + INSERT ls_branches_with_time INTO TABLE lt_branches_sorted_by_time. + CLEAR ls_branches_with_time. + + ENDIF. + ENDLOOP. + + + LOOP AT lt_branches_sorted_by_time ASSIGNING . + + READ TABLE mt_commits ASSIGNING WITH KEY sha1 = -sha1. ASSERT sy-subrc = 0. DO. IF -branch IS INITIAL. - -branch = lv_name. + -branch = -name. ELSE. APPEND INITIAL LINE TO -create ASSIGNING . - -name = lv_name. + -name = -name. -parent = -branch. EXIT. ENDIF.