Skip to content

Commit 9d8d51d

Browse files
committed
Merge branch 'jk/version-string'
Teaches git native protocol agents to show software version over the wire. * jk/version-string: http: get default user-agent from git_user_agent version: add git_user_agent function move git_version_string into version.c
2 parents 2b022f6 + 745c7c8 commit 9d8d51d

File tree

8 files changed

+46
-9
lines changed

8 files changed

+46
-9
lines changed

Makefile

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ all::
296296
# the diff algorithm. It gives a nice speedup if your processor has
297297
# fast unaligned word loads. Does NOT work on big-endian systems!
298298
# 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)".
299302

300303
GIT-VERSION-FILE: FORCE
301304
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -799,6 +802,7 @@ LIB_OBJS += usage.o
799802
LIB_OBJS += userdiff.o
800803
LIB_OBJS += utf8.o
801804
LIB_OBJS += varint.o
805+
LIB_OBJS += version.o
802806
LIB_OBJS += walker.o
803807
LIB_OBJS += wrapper.o
804808
LIB_OBJS += write_or_die.o
@@ -904,6 +908,8 @@ BUILTIN_OBJS += builtin/write-tree.o
904908
GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
905909
EXTLIBS =
906910

911+
GIT_USER_AGENT = git/$(GIT_VERSION)
912+
907913
#
908914
# Platform specific tweaks
909915
#
@@ -1915,6 +1921,11 @@ SHELL_PATH_CQ_SQ = $(subst ','\'',$(SHELL_PATH_CQ))
19151921
BASIC_CFLAGS += -DSHELL_PATH='$(SHELL_PATH_CQ_SQ)'
19161922
endif
19171923

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+
19181929
ALL_CFLAGS += $(BASIC_CFLAGS)
19191930
ALL_LDFLAGS += $(BASIC_LDFLAGS)
19201931

@@ -1962,7 +1973,7 @@ strip: $(PROGRAMS) git$X
19621973
$(STRIP) $(STRIP_OPTS) $(PROGRAMS) git$X
19631974

19641975
git.o: common-cmds.h
1965-
git.sp git.s git.o: EXTRA_CPPFLAGS = -DGIT_VERSION='"$(GIT_VERSION)"' \
1976+
git.sp git.s git.o: EXTRA_CPPFLAGS = \
19661977
'-DGIT_HTML_PATH="$(htmldir_SQ)"' \
19671978
'-DGIT_MAN_PATH="$(mandir_SQ)"' \
19681979
'-DGIT_INFO_PATH="$(infodir_SQ)"'
@@ -1979,6 +1990,9 @@ builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
19791990
'-DGIT_MAN_PATH="$(mandir_SQ)"' \
19801991
'-DGIT_INFO_PATH="$(infodir_SQ)"'
19811992

1993+
version.sp version.s version.o: EXTRA_CPPFLAGS = \
1994+
'-DGIT_VERSION="$(GIT_VERSION)"'
1995+
19821996
$(BUILT_INS): git$X
19831997
$(QUIET_BUILT_IN)$(RM) $@ && \
19841998
ln git$X $@ 2>/dev/null || \
@@ -1996,6 +2010,7 @@ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
19962010
-e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
19972011
-e 's|@@DIFF@@|$(DIFF_SQ)|' \
19982012
-e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
2013+
-e 's|@@GIT_USER_AGENT@@|$(GIT_USER_AGENT_SQ)|g' \
19992014
-e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' \
20002015
-e 's/@@NO_CURL@@/$(NO_CURL)/g' \
20012016
-e 's/@@USE_GETTEXT_SCHEME@@/$(USE_GETTEXT_SCHEME)/g' \
@@ -2089,7 +2104,7 @@ configure: configure.ac
20892104
$(RM) $<+
20902105

20912106
# These can record GIT_VERSION
2092-
git.o git.spec http.o \
2107+
version.o git.spec \
20932108
$(patsubst %.sh,%,$(SCRIPT_SH)) \
20942109
$(patsubst %.perl,%,$(SCRIPT_PERL)) \
20952110
: GIT-VERSION-FILE
@@ -2259,9 +2274,6 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \
22592274
gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \
22602275
-DGIT_LOCALE_PATH='"$(localedir_SQ)"'
22612276

2262-
http.sp http.s http.o: EXTRA_CPPFLAGS = \
2263-
-DGIT_HTTP_USER_AGENT='"git/$(GIT_VERSION)"'
2264-
22652277
ifdef NO_EXPAT
22662278
http-walker.sp http-walker.s http-walker.o: EXTRA_CPPFLAGS = -DNO_EXPAT
22672279
endif

builtin.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#define DEFAULT_MERGE_LOG_LEN 20
1111

12-
extern const char git_version_string[];
1312
extern const char git_usage_string[];
1413
extern const char git_more_info_string[];
1514

builtin/log.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "parse-options.h"
2222
#include "branch.h"
2323
#include "streaming.h"
24+
#include "version.h"
2425

2526
/* Set a default date-time format for git log ("log.date" config variable) */
2627
static const char *default_date_mode = NULL;

git.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,6 @@ static int handle_alias(int *argcp, const char ***argv)
256256
return ret;
257257
}
258258

259-
const char git_version_string[] = GIT_VERSION;
260-
261259
#define RUN_SETUP (1<<0)
262260
#define RUN_SETUP_GENTLY (1<<1)
263261
#define USE_PAGER (1<<2)

help.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "common-cmds.h"
77
#include "string-list.h"
88
#include "column.h"
9+
#include "version.h"
910

1011
void add_cmdname(struct cmdnames *cmds, const char *name, int len)
1112
{

http.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "run-command.h"
55
#include "url.h"
66
#include "credential.h"
7+
#include "version.h"
78

89
int active_requests;
910
int http_is_verbose;
@@ -299,7 +300,7 @@ static CURL *get_curl_handle(void)
299300
curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
300301

301302
curl_easy_setopt(result, CURLOPT_USERAGENT,
302-
user_agent ? user_agent : GIT_HTTP_USER_AGENT);
303+
user_agent ? user_agent : git_user_agent());
303304

304305
if (curl_ftp_no_epsv)
305306
curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);

version.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "git-compat-util.h"
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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef VERSION_H
2+
#define VERSION_H
3+
4+
extern const char git_version_string[];
5+
6+
const char *git_user_agent(void);
7+
8+
#endif /* VERSION_H */

0 commit comments

Comments
 (0)