Skip to content

Commit cb63310

Browse files
fredrikfossslouken
authored andcommitted
cmake: add reftable ref storage support to GetGitRevisionDescription
The script assumed Git's traditional loose refs or packed-refs format. When cloning with extensions.refstorage=reftable, neither .git/refs/* nor .git/packed-refs exist, causing cmake configuration to fail. Fall back to git rev-parse when file-based ref lookup fails.
1 parent cb287ed commit cb63310

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

cmake/GetGitRevisionDescription.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,22 @@ function(get_git_head_revision _refspecvar _hashvar)
164164
"${GIT_DATA}/grabRef.cmake" @ONLY)
165165
include("${GIT_DATA}/grabRef.cmake")
166166

167+
# Fallback for reftable or other storage formats
168+
if(NOT HEAD_HASH OR HEAD_HASH STREQUAL "")
169+
find_package(Git QUIET)
170+
if(GIT_FOUND)
171+
execute_process(
172+
COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD
173+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
174+
RESULT_VARIABLE res
175+
OUTPUT_VARIABLE HEAD_HASH
176+
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
177+
if(NOT res EQUAL 0)
178+
set(HEAD_HASH "")
179+
endif()
180+
endif()
181+
endif()
182+
167183
set(${_refspecvar}
168184
"${HEAD_REF}"
169185
PARENT_SCOPE)

cmake/GetGitRevisionDescription.cmake.in

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,21 @@ if(HEAD_CONTENTS MATCHES "ref")
2525
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
2626
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
2727
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
28-
else()
28+
elseif(EXISTS "@GIT_DIR@/packed-refs")
2929
configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
3030
file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
3131
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
3232
set(HEAD_HASH "${CMAKE_MATCH_1}")
3333
endif()
34+
elseif(EXISTS "@GIT_DIR@/reftable/tables.list")
35+
configure_file("@GIT_DIR@/reftable/tables.list" "@GIT_DATA@/reftable-tables.list" COPYONLY)
3436
endif()
3537
else()
3638
# detached HEAD
3739
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
3840
endif()
3941

40-
if(NOT HEAD_HASH)
42+
if(NOT HEAD_HASH AND EXISTS "@GIT_DATA@/head-ref")
4143
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
4244
string(STRIP "${HEAD_HASH}" HEAD_HASH)
4345
endif()

0 commit comments

Comments
 (0)