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
This commit is contained in:
Junio C Hamano 2012-06-21 14:42:01 -07:00
commit 9d8d51d53b
8 changed files with 46 additions and 9 deletions

View File

@ -296,6 +296,9 @@ all::
# the diff algorithm. It gives a nice speedup if your processor has
# fast unaligned word loads. Does NOT work on big-endian systems!
# 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
@$(SHELL_PATH) ./GIT-VERSION-GEN
@ -799,6 +802,7 @@ LIB_OBJS += usage.o
LIB_OBJS += userdiff.o
LIB_OBJS += utf8.o
LIB_OBJS += varint.o
LIB_OBJS += version.o
LIB_OBJS += walker.o
LIB_OBJS += wrapper.o
LIB_OBJS += write_or_die.o
@ -904,6 +908,8 @@ BUILTIN_OBJS += builtin/write-tree.o
GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
EXTLIBS =
GIT_USER_AGENT = git/$(GIT_VERSION)
#
# Platform specific tweaks
#
@ -1915,6 +1921,11 @@ SHELL_PATH_CQ_SQ = $(subst ','\'',$(SHELL_PATH_CQ))
BASIC_CFLAGS += -DSHELL_PATH='$(SHELL_PATH_CQ_SQ)'
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_LDFLAGS += $(BASIC_LDFLAGS)
@ -1962,7 +1973,7 @@ strip: $(PROGRAMS) git$X
$(STRIP) $(STRIP_OPTS) $(PROGRAMS) git$X
git.o: common-cmds.h
git.sp git.s git.o: EXTRA_CPPFLAGS = -DGIT_VERSION='"$(GIT_VERSION)"' \
git.sp git.s git.o: EXTRA_CPPFLAGS = \
'-DGIT_HTML_PATH="$(htmldir_SQ)"' \
'-DGIT_MAN_PATH="$(mandir_SQ)"' \
'-DGIT_INFO_PATH="$(infodir_SQ)"'
@ -1979,6 +1990,9 @@ builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
'-DGIT_MAN_PATH="$(mandir_SQ)"' \
'-DGIT_INFO_PATH="$(infodir_SQ)"'
version.sp version.s version.o: EXTRA_CPPFLAGS = \
'-DGIT_VERSION="$(GIT_VERSION)"'
$(BUILT_INS): git$X
$(QUIET_BUILT_IN)$(RM) $@ && \
ln git$X $@ 2>/dev/null || \
@ -1996,6 +2010,7 @@ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
-e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
-e 's|@@DIFF@@|$(DIFF_SQ)|' \
-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/@@NO_CURL@@/$(NO_CURL)/g' \
-e 's/@@USE_GETTEXT_SCHEME@@/$(USE_GETTEXT_SCHEME)/g' \
@ -2089,7 +2104,7 @@ configure: configure.ac
$(RM) $<+
# These can record GIT_VERSION
git.o git.spec http.o \
version.o git.spec \
$(patsubst %.sh,%,$(SCRIPT_SH)) \
$(patsubst %.perl,%,$(SCRIPT_PERL)) \
: GIT-VERSION-FILE
@ -2259,9 +2274,6 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \
gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \
-DGIT_LOCALE_PATH='"$(localedir_SQ)"'
http.sp http.s http.o: EXTRA_CPPFLAGS = \
-DGIT_HTTP_USER_AGENT='"git/$(GIT_VERSION)"'
ifdef NO_EXPAT
http-walker.sp http-walker.s http-walker.o: EXTRA_CPPFLAGS = -DNO_EXPAT
endif

View File

@ -9,7 +9,6 @@
#define DEFAULT_MERGE_LOG_LEN 20
extern const char git_version_string[];
extern const char git_usage_string[];
extern const char git_more_info_string[];

View File

@ -21,6 +21,7 @@
#include "parse-options.h"
#include "branch.h"
#include "streaming.h"
#include "version.h"
/* Set a default date-time format for git log ("log.date" config variable) */
static const char *default_date_mode = NULL;

2
git.c
View File

@ -256,8 +256,6 @@ static int handle_alias(int *argcp, const char ***argv)
return ret;
}
const char git_version_string[] = GIT_VERSION;
#define RUN_SETUP (1<<0)
#define RUN_SETUP_GENTLY (1<<1)
#define USE_PAGER (1<<2)

1
help.c
View File

@ -6,6 +6,7 @@
#include "common-cmds.h"
#include "string-list.h"
#include "column.h"
#include "version.h"
void add_cmdname(struct cmdnames *cmds, const char *name, int len)
{

3
http.c
View File

@ -4,6 +4,7 @@
#include "run-command.h"
#include "url.h"
#include "credential.h"
#include "version.h"
int active_requests;
int http_is_verbose;
@ -299,7 +300,7 @@ static CURL *get_curl_handle(void)
curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
curl_easy_setopt(result, CURLOPT_USERAGENT,
user_agent ? user_agent : GIT_HTTP_USER_AGENT);
user_agent ? user_agent : git_user_agent());
if (curl_ftp_no_epsv)
curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);

17
version.c Normal file
View File

@ -0,0 +1,17 @@
#include "git-compat-util.h"
#include "version.h"
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;
}

8
version.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef VERSION_H
#define VERSION_H
extern const char git_version_string[];
const char *git_user_agent(void);
#endif /* VERSION_H */