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>
Jeff King committed
Jun 2, 2012 at 15:01 UTC
42dcbb738b47ab7e2b265ed981c9a4a7bda92f97
3 files changed
+26
Makefile
+11
@@ -296,6 +296,9 @@ all::
296
# the diff algorithm. It gives a nice speedup if your processor has
297
# fast unaligned word loads. Does NOT work on big-endian systems!
298
# Enabled by default on x86_64.
299
+#
300
+# Define GIT_USER_AGENT if you want to change how git identifies itself during
301
+# network interactions. The default is "git/$(GIT_VERSION)".
302
303
GIT-VERSION-FILE: FORCE
304
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -905,6 +908,8 @@ BUILTIN_OBJS += builtin/write-tree.o
908
GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
909
EXTLIBS =
910
911
+GIT_USER_AGENT = git/$(GIT_VERSION)
912
+
913
#
914
# Platform specific tweaks
915
#
@@ -1916,6 +1921,11 @@ SHELL_PATH_CQ_SQ = $(subst ','\'',$(SHELL_PATH_CQ))
1921
BASIC_CFLAGS += -DSHELL_PATH='$(SHELL_PATH_CQ_SQ)'
1922
endif
1923
1924
+GIT_USER_AGENT_SQ = $(subst ','\'',$(GIT_USER_AGENT))
1925
+GIT_USER_AGENT_CQ = "$(subst ",\",$(subst \,\\,$(GIT_USER_AGENT)))"
1926
+GIT_USER_AGENT_CQ_SQ = $(subst ','\'',$(GIT_USER_AGENT_CQ))
1927
+BASIC_CFLAGS += -DGIT_USER_AGENT='$(GIT_USER_AGENT_CQ_SQ)'
1928
+
1929
ALL_CFLAGS += $(BASIC_CFLAGS)
1930
ALL_LDFLAGS += $(BASIC_LDFLAGS)
1931
@@ -2000,6 +2010,7 @@ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
2010
-e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
2011
-e 's|@@DIFF@@|$(DIFF_SQ)|' \
2012
-e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
2013
+ -e 's|@@GIT_USER_AGENT@@|$(GIT_USER_AGENT_SQ)|g' \
2014
-e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' \
2015
-e 's/@@NO_CURL@@/$(NO_CURL)/g' \
2016
-e 's/@@USE_GETTEXT_SCHEME@@/$(USE_GETTEXT_SCHEME)/g' \
version.c
+13
@@ -2,3 +2,16 @@
2
#include "version.h"
3
4
const char git_version_string[] = GIT_VERSION;
5
+
6
+const char *git_user_agent(void)
7
+{
8
+ static const char *agent = NULL;
9
+
10
+ if (!agent) {
11
+ agent = getenv("GIT_USER_AGENT");
12
+ if (!agent)
13
+ agent = GIT_USER_AGENT;
14
+ }
15
+
16
+ return agent;
17
+}
version.h
+2
@@ -3,4 +3,6 @@
3
4
extern const char git_version_string[];
5
6
+const char *git_user_agent(void);
7
+
8
#endif /* VERSION_H */