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; |
Jeff King | 42dcbb7 | 2012-06-02 15:01:12 -0400 | [diff] [blame] | 6 | |
| 7 | const char *git_user_agent(void) |
| 8 | { |
| 9 | static const char *agent = NULL; |
| 10 | |
| 11 | if (!agent) { |
| 12 | agent = getenv("GIT_USER_AGENT"); |
| 13 | if (!agent) |
| 14 | agent = GIT_USER_AGENT; |
| 15 | } |
| 16 | |
| 17 | return agent; |
| 18 | } |
Jeff King | ff5effd | 2012-08-03 12:19:16 -0400 | [diff] [blame] | 19 | |
| 20 | const char *git_user_agent_sanitized(void) |
| 21 | { |
| 22 | static const char *agent = NULL; |
| 23 | |
| 24 | if (!agent) { |
| 25 | struct strbuf buf = STRBUF_INIT; |
| 26 | int i; |
| 27 | |
| 28 | strbuf_addstr(&buf, git_user_agent()); |
| 29 | strbuf_trim(&buf); |
| 30 | for (i = 0; i < buf.len; i++) { |
| 31 | if (buf.buf[i] <= 32 || buf.buf[i] >= 127) |
| 32 | buf.buf[i] = '.'; |
| 33 | } |
| 34 | agent = buf.buf; |
| 35 | } |
| 36 | |
| 37 | return agent; |
| 38 | } |