From b7b7fd1ee724b8831bb9a870efa76a26a8d080a8 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Wed, 31 Aug 2016 02:41:55 +0000 Subject: [PATCH] Adding support for ancient git (1.7.1) found on CentOS 6.8 - Recently added the BCD_VERSION which uses git rev-list --count HEAD command - Unfortunately git 1.7.1 doesn't have this, so I've added a fallback to manually counting the commits using some CMake magic --- Lib/CMake/buildinfo.cmake | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Lib/CMake/buildinfo.cmake b/Lib/CMake/buildinfo.cmake index 3a115c2..7eee884 100644 --- a/Lib/CMake/buildinfo.cmake +++ b/Lib/CMake/buildinfo.cmake @@ -80,8 +80,28 @@ execute_process ( COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD OUTPUT_VARIABLE Git_Commit_Number ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE res_var ) +#| Older versions of git (e.g. 1.7.1) dont' like rev-list --count +#| If there's an error, try again with a less efficient version +if ( NOT "${res_var}" STREQUAL "0" ) + execute_process ( COMMAND ${GIT_EXECUTABLE} log --pretty=oneline + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE Git_Log_Lines + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE res_var + ) + + # Now we do some CMake wizardry to split lines in the variable so we have a list called contents + string ( REGEX REPLACE ";" "\\\\;" contents "${Git_Log_Lines}" ) + string ( REGEX REPLACE "\n" ";" contents "${contents}" ) + + # Now we just have to measure the length of the list + list ( LENGTH contents Git_Commit_Number ) +endif () + + #| Origin URL execute_process ( COMMAND ${GIT_EXECUTABLE} config --get remote.origin.url WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}