Skip to content

Commit

Permalink
Simplified loop and changed to 1-based indexing (#597)
Browse files Browse the repository at this point in the history
Simplified foreach loop in tribits_generate_single_repo_version_string and changed
the parent indexing to be 1-based instead of 0-based.
  • Loading branch information
achauphan committed Jan 16, 2024
1 parent 852e651 commit f6b6442
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
8 changes: 4 additions & 4 deletions test/core/ExamplesUnitTests/TribitsHelloWorld_Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ tribits_add_advanced_test( TribitsHelloWorld_config_git_version_single_repo_two_
PASS_REGULAR_EXPRESSION_ALL
"a1234tgb .Thu Sep 21 19:19:18 2023 -0400. <[email protected]>"
"This is the HEAD commit summary line"
"Parent 0:"
"b5678aop .Thu Sep 20 19:19:18 2023 -0400. <[email protected]>"
"This is parent 0 commit summary line"
"Parent 1:"
"c9101hah .Thu Sep 19 19:19:18 2023 -0400. <[email protected]>"
"b5678aop .Thu Sep 20 19:19:18 2023 -0400. <[email protected]>"
"This is parent 1 commit summary line"
"Parent 2:"
"c9101hah .Thu Sep 19 19:19:18 2023 -0400. <[email protected]>"
"This is parent 2 commit summary line"
ALWAYS_FAIL_ON_NONZERO_RETURN

TEST_4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
*** Base Git Repo: TribitsHelloWorld
a1234tgb [Thu Sep 21 19:19:18 2023 -0400] <[email protected]>
This is the HEAD commit summary line
*** Parent 0:
b5678aop [Thu Sep 20 19:19:18 2023 -0400] <[email protected]>
This is parent 0 commit summary line
*** Parent 1:
c9101hah [Thu Sep 19 19:19:18 2023 -0400] <[email protected]>
b5678aop [Thu Sep 20 19:19:18 2023 -0400] <[email protected]>
This is parent 1 commit summary line
*** Parent 2:
c9101hah [Thu Sep 19 19:19:18 2023 -0400] <[email protected]>
This is parent 2 commit summary line
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ MOCK_PROGRAM_RETURN: 0
MOCK_PROGRAM_OUTPUT: b5678aop [Thu Sep 20 19:19:18 2023 -0400] <[email protected]>
MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s b5678aop
MOCK_PROGRAM_RETURN: 0
MOCK_PROGRAM_OUTPUT: This is parent 0 commit summary line
MOCK_PROGRAM_OUTPUT: This is parent 1 commit summary line
MOCK_PROGRAM_INPUT: log -1 --pretty=format:%h [%ad] <%ae> c9101hah
MOCK_PROGRAM_RETURN: 0
MOCK_PROGRAM_OUTPUT: c9101hah [Thu Sep 19 19:19:18 2023 -0400] <[email protected]>
MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s c9101hah
MOCK_PROGRAM_RETURN: 0
MOCK_PROGRAM_OUTPUT: This is parent 1 commit summary line
MOCK_PROGRAM_OUTPUT: This is parent 2 commit summary line
11 changes: 5 additions & 6 deletions tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -211,27 +211,26 @@ function(tribits_generate_single_repo_version_string gitRepoDir

if (headNumParents GREATER 1)

# Is there a better way??? Range is inclusive and does not accept expressions?!?
math(EXPR loopMax "${headNumParents}-1")
set(parentIdx 1) # Parent commit indexes are 1-based by git

foreach(index RANGE ${loopMax})
foreach(parentSha1 IN LISTS headParentList)

# C.1) Get parent commit info string

list(GET headParentList ${index} parentSha1)
tribits_generate_commit_info_string(
${gitRepoDir} ${parentSha1}
commitInfoString)

# C.2) Format parent string to be pretty in config output

string(APPEND outStringBuilder
"\n *** Parent ${index}:")
"\n *** Parent ${parentIdx}:")
string(REPLACE "\n" "\n "
commitInfoString "${commitInfoString}")
string(CONCAT outStringBuilder
"${outStringBuilder}" "\n ${commitInfoString}" )

math(EXPR parentIdx "${parentIdx}+1")

endforeach()

endif()
Expand Down

0 comments on commit f6b6442

Please sign in to comment.