Files
git-mirror/version.c
Usman Akinyemi 0c124cba54 version: replace manual ASCII checks with isprint() for clarity
Since the isprint() function checks for printable characters, let's
replace the existing hardcoded ASCII checks with it. However, since
the original checks also handled spaces, we need to account for spaces
explicitly in the new check.

Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-02-18 09:05:12 -08:00

41 lines
769 B
C

#include "git-compat-util.h"
#include "version.h"
#include "version-def.h"
#include "strbuf.h"
#include "sane-ctype.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;
strbuf_addstr(&buf, git_user_agent());
strbuf_trim(&buf);
for (size_t i = 0; i < buf.len; i++) {
if (!isprint(buf.buf[i]) || buf.buf[i] == ' ')
buf.buf[i] = '.';
}
agent = buf.buf;
}
return agent;
}