for_each_reflog_ent(): extract a helper to process a single entry
[gitweb.git] / version.c
index ca686538652300f26cd838ea40110480200f4c12..6106a8098c8a46575f9afae5da9909b5c196f754 100644 (file)
--- a/version.c
+++ b/version.c
@@ -1,4 +1,38 @@
 #include "git-compat-util.h"
 #include "version.h"
+#include "strbuf.h"
 
 const char git_version_string[] = GIT_VERSION;
+
+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;
+}