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) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SVmAWnzCmRKAXVUCdc4iNi
This commit is contained in:
2026-10-09 19:04:22 +02:00
co-authored by Claude Opus 5.5
parent 4120b0daa8
commit 447d8f8b01
2 changed files with 22 additions and 3 deletions
+4 -3
View File
@@ -110,9 +110,10 @@ std::string IsoDate(const std::string &timestamp) {
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<MergedReflection> &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";