From dce52b6df82f60f3814bc28706bd6812cb7e754a Mon Sep 17 00:00:00 2001 From: Anderson Chauphan Date: Thu, 11 Jan 2024 16:48:22 -0700 Subject: [PATCH] Refactored chunk of tribits_generate_single_repo_version_string for reuse (#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. --- .../TribitsGitRepoVersionInfo.cmake | 52 +++++++++++++------ 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index 80b82ed9f..36320b096 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -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 @@ -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