]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: check $top_srcdir/.git directly 34466/head
authorKefu Chai <kchai@redhat.com>
Wed, 8 Apr 2020 10:00:10 +0000 (18:00 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 8 Apr 2020 10:03:37 +0000 (18:03 +0800)
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 <kchai@redhat.com>
cmake/modules/GetGitRevisionDescription.cmake

index 34106b64dbbbac84fdcdbdc1e9de53ed1bc73828..fbe414856c46114964451525358c4abc7b6440d1 100644 (file)
@@ -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)