The fifth batch
[alt-git.git] / version.c
blob4786c4e0a54093ca947da27f8b712bd1ea351203
1 #include "git-compat-util.h"
2 #include "version.h"
3 #include "strbuf.h"
5 #ifndef GIT_VERSION_H
6 # include "version-def.h"
7 #else
8 # include GIT_VERSION_H
9 #endif
11 const char git_version_string[] = GIT_VERSION;
12 const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT;
14 const char *git_user_agent(void)
16 static const char *agent = NULL;
18 if (!agent) {
19 agent = getenv("GIT_USER_AGENT");
20 if (!agent)
21 agent = GIT_USER_AGENT;
24 return agent;
27 const char *git_user_agent_sanitized(void)
29 static const char *agent = NULL;
31 if (!agent) {
32 struct strbuf buf = STRBUF_INIT;
34 strbuf_addstr(&buf, git_user_agent());
35 strbuf_trim(&buf);
36 for (size_t i = 0; i < buf.len; i++) {
37 if (buf.buf[i] <= 32 || buf.buf[i] >= 127)
38 buf.buf[i] = '.';
40 agent = buf.buf;
43 return agent;