Skip to content

Commit

Permalink
Refactored chunk of tribits_generate_single_repo_version_string for r…
Browse files Browse the repository at this point in the history
…euse (#597)

Moved git commit info functionality of tribits_generate_single_repo_version_string to
a seperate helper function named tribites_generate_commit_info_string. The core functionality and
output is the same. This is in prep for reuse of that functionality inside of the original
tribits_generate_single_repo_version string.
  • Loading branch information
achauphan committed Jan 11, 2024
1 parent f312470 commit dce52b6
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,35 @@ function(tribits_git_repo_sha1 gitRepoDir gitRepoSha1Out)
endfunction()


# Run the git log command to get the version info for a git repo
#
function(tribits_generate_single_repo_version_string gitRepoDir
repoVersionStringOut
)

tribits_assert_git_executable()

# A) Get the basic version info.

# Run git log to generate a string containing commit sha1, author, date, email
# and the commit summary

function(tribits_generate_commit_info_string gitRepoDir
commitInfoStringOut
)

# A) Get commit hash, author, date, and email

execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%h [%ad] <%ae>"
WORKING_DIRECTORY ${gitRepoDir}
RESULT_VARIABLE gitCmndRtn
OUTPUT_VARIABLE gitCmndOutput
OUTPUT_VARIABLE gitCmndOut
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE
)

if (NOT gitCmndRtn STREQUAL 0)
message(FATAL_ERROR "ERROR, ${GIT_EXECUTABLE} command returned ${gitCmndRtn}!=0"
" with output '${gitCmndOutput}' for repo ${gitRepoDir}!")
" for SHA1 of repo ${gitRepoDir}!")
set(gitVersionLine "Error, could not get version info!")
else()
set(gitVersionLine "${gitCmndOutput}")
set(gitVersionLine "${gitCmndOut}")
endif()

# B) Get the first 80 chars of the summary message for more info

execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%s
COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%s"
WORKING_DIRECTORY ${gitRepoDir}
RESULT_VARIABLE gitCmndRtn
OUTPUT_VARIABLE gitCmndOutput
Expand All @@ -143,15 +142,34 @@ function(tribits_generate_single_repo_version_string gitRepoDir

if (NOT gitCmndRtn STREQUAL 0)
message(FATAL_ERROR "ERROR, ${GIT_EXECUTABLE} command returned ${gitCmndRtn}!=0"
" for extra repo ${gitRepoDir}!")
" for SHA1 of repo ${gitRepoDir}!")
set(gitSummaryStr "Error, could not get version summary!")
else()
set(maxSummaryLen 80)
string(SUBSTRING "${gitCmndOutput}" 0 ${maxSummaryLen} gitSummaryStr)
endif()

set(${repoVersionStringOut}
set(${commitInfoStringOut}
"${gitVersionLine}\n${gitSummaryStr}" PARENT_SCOPE)
endfunction()



# Run the git log command to get the version info for a git repo
#
function(tribits_generate_single_repo_version_string gitRepoDir
repoVersionStringOut
)

tribits_assert_git_executable()

# A) Get HEAD commit's info

tribits_generate_commit_info_string(
${gitRepoDir}
headCommitInfoString)

set(${repoVersionStringOut} "${headCommitInfoString}" PARENT_SCOPE)

endfunction()
# NOTE: Above, it is fine if ${maxSummaryLen} > len(${gitCmndOutput}) as
Expand Down

0 comments on commit dce52b6

Please sign in to comment.