From 447d8f8b01a9a2fef1d540718960f248683e7bd9 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Fri, 9 Oct 2026 19:04:22 +0200 Subject: [PATCH] GitInfo: a source tree without its own git history builds, reporting commit "unknown" The commit is already re-stamped on every build (JFJochGitInfo runs GitInfoStamp.cmake with cmake -P; configure_file rewrites GitInfo.cpp only when the value changed). What was missing is the case with no git: a downloaded tarball left the SHA empty, and one unpacked inside some other repository would have reported that repository's HEAD. The stamp now asks git only when the source directory is itself the top of a work tree, and otherwise records commit "unknown" beside the version from VERSION. The reflection files' git description drops its trailing date when there is none. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01SVmAWnzCmRKAXVUCdc4iNi --- common/GitInfoStamp.cmake | 18 ++++++++++++++++++ image_analysis/WriteReflections.cpp | 7 ++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/common/GitInfoStamp.cmake b/common/GitInfoStamp.cmake index f2c9ce138..148993a98 100644 --- a/common/GitInfoStamp.cmake +++ b/common/GitInfoStamp.cmake @@ -4,7 +4,22 @@ # reported a hash seventeen commits stale. configure_file leaves the output untouched when nothing # changed, so this costs a recompile only when HEAD moves. Also included at configure time, so the # file exists for the generator and the SHA prints with the configure output. +# A source tree that is not a git checkout of its own - a downloaded tarball, perhaps unpacked inside +# some other repository - has no commit to report: the version from VERSION stands alone and the +# commit reads "unknown", and the build goes on. +SET(GIT_SHA1 "") +SET(GIT_DATE "") if (GIT_EXECUTABLE) + EXECUTE_PROCESS(COMMAND "${GIT_EXECUTABLE}" rev-parse --show-toplevel + WORKING_DIRECTORY "${GITINFO_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_TOPLEVEL + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + if (GIT_TOPLEVEL) + FILE(REAL_PATH "${GIT_TOPLEVEL}" GIT_TOPLEVEL) + endif () + FILE(REAL_PATH "${GITINFO_SOURCE_DIR}" GITINFO_SOURCE_REAL) +endif () +if (GIT_EXECUTABLE AND GIT_TOPLEVEL STREQUAL GITINFO_SOURCE_REAL) # --dirty: a build from uncommitted changes says so in the hash itself EXECUTE_PROCESS(COMMAND "${GIT_EXECUTABLE}" describe --match=NeVeRmAtCh --always --abbrev=8 --dirty @@ -17,4 +32,7 @@ if (GIT_EXECUTABLE) OUTPUT_VARIABLE GIT_DATE ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) endif () +if (NOT GIT_SHA1) + SET(GIT_SHA1 "unknown") +endif () CONFIGURE_FILE("${GITINFO_TEMPLATE}" "${GITINFO_OUTPUT}" @ONLY) diff --git a/image_analysis/WriteReflections.cpp b/image_analysis/WriteReflections.cpp index 7b49f877a..fba15332c 100644 --- a/image_analysis/WriteReflections.cpp +++ b/image_analysis/WriteReflections.cpp @@ -110,9 +110,10 @@ std::string IsoDate(const std::string ×tamp) { return timestamp.substr(0, 10); } -// The commit this build was made from, with its date; empty when the build does not know it. +// The commit this build was made from, with its date where the build knows it ("unknown" for a source +// tree without git history). std::string GitDescription() { - return jfjoch_git_sha1().empty() ? std::string() : jfjoch_git_sha1() + " " + jfjoch_git_date(); + return jfjoch_git_date().empty() ? jfjoch_git_sha1() : jfjoch_git_sha1() + " " + jfjoch_git_date(); } // The MTZ HISTORY records saying where a file came from, after the one naming the program: the @@ -284,7 +285,7 @@ void WriteMmcifReflections(const std::vector &reflections, // Rugnux integrated the images (data reduction) and scaled and merged them (data scaling), the // two rows the wwPDB asks a data-processing program to be named under; the description is the // commit the build was made from. - const std::string software_description = CifStr(GitDescription().empty() ? "" : "git " + GitDescription()); + const std::string software_description = CifStr("git " + GitDescription()); out << "loop_\n"; out << "_software.pdbx_ordinal\n"; out << "_software.name\n";