mirror of
https://github.com/git/git.git
synced 2024-11-15 14:14:08 +01:00
ed32b788c0
In particular when local tags are used (or tags that are pushed to some fork) to build Git, it is very hard to figure out from which particular revision a particular Git executable was built. It gets worse when those tags are deleted, or even updated. Let's just report an exact, unabbreviated commit name in our build options. We need to be careful, though, to report when the current commit cannot be determined, e.g. when building from a tarball without any associated Git repository. This could be the case also when extracting Git's source code into an unrelated Git worktree. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
40 lines
718 B
C
40 lines
718 B
C
#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;
|
|
}
|