From a05d7179e2c38f375ab565fa6f6bfc47dc1d2dd6 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 8 Apr 2020 18:00:10 +0800 Subject: [PATCH] cmake: check $top_srcdir/.git directly in 0437adc33a8b83847ed36666971b5ea4d88a4901, we stop right before reaching $top_srcdir, but we should stop at its parent directory. in this change, instead of trying to be smart and to walk all the way up to the root directory or $top_srcdir, we just check $top_srcdir/.git directly, as we just know it's there or it does not exist at all. Signed-off-by: Kefu Chai --- cmake/modules/GetGitRevisionDescription.cmake | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/cmake/modules/GetGitRevisionDescription.cmake b/cmake/modules/GetGitRevisionDescription.cmake index 34106b64dbbba..fbe414856c461 100644 --- a/cmake/modules/GetGitRevisionDescription.cmake +++ b/cmake/modules/GetGitRevisionDescription.cmake @@ -40,20 +40,13 @@ set(__get_git_revision_description YES) get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) function(get_git_head_revision _refspecvar _hashvar) - set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") - set(GIT_DIR "${GIT_PARENT_DIR}/.git") - set(TOP_LEVEL_DIR "${CMAKE_SOURCE_DIR}") - while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories - set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") - get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) - if(GIT_PARENT_DIR STREQUAL TOP_LEVEL_DIR) - # We have reached the top of the source tree, we are not in git - set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) - set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) - return() - endif() - set(GIT_DIR "${GIT_PARENT_DIR}/.git") - endwhile() + set(GIT_DIR "${CMAKE_SOURCE_DIR}/.git") + if(NOT EXISTS "${GIT_DIR}") # .git dir not found + # We have reached the top of the source tree, we are not in git + set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) + set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) + return() + endif() # check if this is a submodule or git-worktree if(NOT IS_DIRECTORY ${GIT_DIR}) file(READ ${GIT_DIR} gitdirfile) -- 2.39.5