version: add git_user_agent function
This is basically a fancy way of saying "git/$GIT_VERSION", except that it is overridable at build-time and through the environment. Which means that people who don't want to advertise their git version (for privacy or security reasons) can tweak it. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
816fb46be6
commit
42dcbb738b
11
Makefile
11
Makefile
@ -296,6 +296,9 @@ all::
|
|||||||
# the diff algorithm. It gives a nice speedup if your processor has
|
# the diff algorithm. It gives a nice speedup if your processor has
|
||||||
# fast unaligned word loads. Does NOT work on big-endian systems!
|
# fast unaligned word loads. Does NOT work on big-endian systems!
|
||||||
# Enabled by default on x86_64.
|
# Enabled by default on x86_64.
|
||||||
|
#
|
||||||
|
# Define GIT_USER_AGENT if you want to change how git identifies itself during
|
||||||
|
# network interactions. The default is "git/$(GIT_VERSION)".
|
||||||
|
|
||||||
GIT-VERSION-FILE: FORCE
|
GIT-VERSION-FILE: FORCE
|
||||||
@$(SHELL_PATH) ./GIT-VERSION-GEN
|
@$(SHELL_PATH) ./GIT-VERSION-GEN
|
||||||
@ -905,6 +908,8 @@ BUILTIN_OBJS += builtin/write-tree.o
|
|||||||
GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
|
GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
|
||||||
EXTLIBS =
|
EXTLIBS =
|
||||||
|
|
||||||
|
GIT_USER_AGENT = git/$(GIT_VERSION)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Platform specific tweaks
|
# Platform specific tweaks
|
||||||
#
|
#
|
||||||
@ -1916,6 +1921,11 @@ SHELL_PATH_CQ_SQ = $(subst ','\'',$(SHELL_PATH_CQ))
|
|||||||
BASIC_CFLAGS += -DSHELL_PATH='$(SHELL_PATH_CQ_SQ)'
|
BASIC_CFLAGS += -DSHELL_PATH='$(SHELL_PATH_CQ_SQ)'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
GIT_USER_AGENT_SQ = $(subst ','\'',$(GIT_USER_AGENT))
|
||||||
|
GIT_USER_AGENT_CQ = "$(subst ",\",$(subst \,\\,$(GIT_USER_AGENT)))"
|
||||||
|
GIT_USER_AGENT_CQ_SQ = $(subst ','\'',$(GIT_USER_AGENT_CQ))
|
||||||
|
BASIC_CFLAGS += -DGIT_USER_AGENT='$(GIT_USER_AGENT_CQ_SQ)'
|
||||||
|
|
||||||
ALL_CFLAGS += $(BASIC_CFLAGS)
|
ALL_CFLAGS += $(BASIC_CFLAGS)
|
||||||
ALL_LDFLAGS += $(BASIC_LDFLAGS)
|
ALL_LDFLAGS += $(BASIC_LDFLAGS)
|
||||||
|
|
||||||
@ -2000,6 +2010,7 @@ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
|
|||||||
-e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
|
-e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
|
||||||
-e 's|@@DIFF@@|$(DIFF_SQ)|' \
|
-e 's|@@DIFF@@|$(DIFF_SQ)|' \
|
||||||
-e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
|
-e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
|
||||||
|
-e 's|@@GIT_USER_AGENT@@|$(GIT_USER_AGENT_SQ)|g' \
|
||||||
-e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' \
|
-e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' \
|
||||||
-e 's/@@NO_CURL@@/$(NO_CURL)/g' \
|
-e 's/@@NO_CURL@@/$(NO_CURL)/g' \
|
||||||
-e 's/@@USE_GETTEXT_SCHEME@@/$(USE_GETTEXT_SCHEME)/g' \
|
-e 's/@@USE_GETTEXT_SCHEME@@/$(USE_GETTEXT_SCHEME)/g' \
|
||||||
|
13
version.c
13
version.c
@ -2,3 +2,16 @@
|
|||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
const char git_version_string[] = GIT_VERSION;
|
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;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user