mirror of
https://github.com/git/git.git
synced 2024-11-05 08:47:56 +01:00
ff5effdf45
Instead of having the client advertise a particular version number in the git protocol, we have managed extensions and backwards compatibility by having clients and servers advertise capabilities that they support. This is far more robust than having each side consult a table of known versions, and provides sufficient information for the protocol interaction to complete. However, it does not allow servers to keep statistics on which client versions are being used. This information is not necessary to complete the network request (the capabilities provide enough information for that), but it may be helpful to conduct a general survey of client versions in use. We already send the client version in the user-agent header for http requests; adding it here allows us to gather similar statistics for non-http requests. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
38 lines
651 B
C
38 lines
651 B
C
#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;
|
|
}
|