From 1b593e1ea4d2af0f6444d9a7788d5d99abd6fde5 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 11 Jan 2020 23:36:56 +0000 Subject: Squashed 'third_party/git/' content from commit cb71568594 git-subtree-dir: third_party/git git-subtree-split: cb715685942260375e1eb8153b0768a376e4ece7 --- version.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 version.c (limited to 'version.c') diff --git a/version.c b/version.c new file mode 100644 index 000000000000..41b718c29e1b --- /dev/null +++ b/version.c @@ -0,0 +1,39 @@ +#include "git-compat-util.h" +#include "version.h" +#include "strbuf.h" + +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; + int i; + + strbuf_addstr(&buf, git_user_agent()); + strbuf_trim(&buf); + for (i = 0; i < buf.len; i++) { + if (buf.buf[i] <= 32 || buf.buf[i] >= 127) + buf.buf[i] = '.'; + } + agent = buf.buf; + } + + return agent; +} -- cgit 1.4.1