Jeff King | 816fb46 | 2012-06-02 14:51:42 -0400 | [diff] [blame] | 1 | #include "git-compat-util.h" |
| 2 | #include "version.h" |
Jeff King | ff5effd | 2012-08-03 12:19:16 -0400 | [diff] [blame] | 3 | #include "strbuf.h" |
Jeff King | 816fb46 | 2012-06-02 14:51:42 -0400 | [diff] [blame] | 4 | |
| 5 | const char git_version_string[] = GIT_VERSION; |
Johannes Schindelin | ed32b78 | 2017-12-15 00:34:38 +0100 | [diff] [blame] | 6 | const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT; |
Jeff King | 42dcbb7 | 2012-06-02 15:01:12 -0400 | [diff] [blame] | 7 | |
| 8 | const char *git_user_agent(void) |
| 9 | { |
| 10 | static const char *agent = NULL; |
| 11 | |
| 12 | if (!agent) { |
| 13 | agent = getenv("GIT_USER_AGENT"); |
| 14 | if (!agent) |
| 15 | agent = GIT_USER_AGENT; |
| 16 | } |
| 17 | |
| 18 | return agent; |
| 19 | } |
Jeff King | ff5effd | 2012-08-03 12:19:16 -0400 | [diff] [blame] | 20 | |
| 21 | const char *git_user_agent_sanitized(void) |
| 22 | { |
| 23 | static const char *agent = NULL; |
| 24 | |
| 25 | if (!agent) { |
| 26 | struct strbuf buf = STRBUF_INIT; |
| 27 | int i; |
| 28 | |
| 29 | strbuf_addstr(&buf, git_user_agent()); |
| 30 | strbuf_trim(&buf); |
| 31 | for (i = 0; i < buf.len; i++) { |
| 32 | if (buf.buf[i] <= 32 || buf.buf[i] >= 127) |
| 33 | buf.buf[i] = '.'; |
| 34 | } |
| 35 | agent = buf.buf; |
| 36 | } |
| 37 | |
| 38 | return agent; |
| 39 | } |