mirror of
https://github.com/git/git.git
synced 2025-02-06 10:03:06 +00:00
4771501c0a
To build the libgit-version library, Meson first generates `version-def.h` in the build directory. Then it compiles `version.c` into a library. During compilation, Meson tells to include both the build directory and the project root directory. However, when the user previously has compiled Git using Make, they will have a `version-def.h` file in project root directory as well. Because `version-def.h` is included in `version.c` using the #include directive with double quotes, some preprocessors will look for the header file in the same directory as the source file. This will cause compilation of `version.c` ran by Meson to include `version-def.h` previously made by Make, which might be out of date. To explicitly tell the preprocessor which `version-def.h` to use, pass the absolute path of this file as macro GIT_VERSION_H to the preprocessor using option `-D` and have `version.c` `#include GIT_VERSION_H`. To remain working with other build systems than Meson, include "version-def.h" if that macro is not defined. Co-authored-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Toon Claes <toon@iotcl.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
45 lines
802 B
C
45 lines
802 B
C
#include "git-compat-util.h"
|
|
#include "version.h"
|
|
#include "strbuf.h"
|
|
|
|
#ifndef GIT_VERSION_H
|
|
# include "version-def.h"
|
|
#else
|
|
# include GIT_VERSION_H
|
|
#endif
|
|
|
|
const char git_version_string[] = GIT_VERSION;
|
|
const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT;
|
|
|
|
const char *git_user_agent(void)
|
|
{
|
|
static const char *agent = NULL;
|
|
|
|
if (!agent) {
|
|
agent = getenv("GIT_USER_AGENT");
|
|
if (!agent)
|
|
agent = GIT_USER_AGENT;
|
|
}
|
|
|
|
return agent;
|
|
}
|
|
|
|
const char *git_user_agent_sanitized(void)
|
|
{
|
|
static const char *agent = NULL;
|
|
|
|
if (!agent) {
|
|
struct strbuf buf = STRBUF_INIT;
|
|
|
|
strbuf_addstr(&buf, git_user_agent());
|
|
strbuf_trim(&buf);
|
|
for (size_t i = 0; i < buf.len; i++) {
|
|
if (buf.buf[i] <= 32 || buf.buf[i] >= 127)
|
|
buf.buf[i] = '.';
|
|
}
|
|
agent = buf.buf;
|
|
}
|
|
|
|
return agent;
|
|
}
|