This is an automated email from the ASF dual-hosted git repository. jan pushed a commit to branch feat/show-git-hash-in-info in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 0a6447fc77c70b4699c78b845f098cbabc5c665e Author: Jan Lehnardt <[email protected]> AuthorDate: Fri Jul 13 14:26:43 2018 +0200 report git sha on welcome request Closes #1309 --- Makefile | 3 ++- Makefile.win | 2 +- src/chttpd/src/chttpd_misc.erl | 1 + src/chttpd/test/chttpd_welcome_test.erl | 2 ++ src/couch/rebar.config.script | 8 ++++++++ src/couch/src/couch_server.erl | 3 ++- 6 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1e0ea82..b6323a1 100644 --- a/Makefile +++ b/Makefile @@ -14,18 +14,19 @@ include version.mk REBAR?=$(shell echo `pwd`/bin/rebar) IN_RELEASE = $(shell if [ ! -d .git ]; then echo true; fi) +COUCHDB_VERSION_SUFFIX = $(shell git rev-parse --short --verify HEAD) ifeq ($(IN_RELEASE), true) COUCHDB_VERSION = $(vsn_major).$(vsn_minor).$(vsn_patch) else RELTAG = $(shell git describe | grep -E '^[0-9]+\.[0-9]\.[0-9]+(-RC[0-9]+)?$$') ifeq ($(RELTAG),) -COUCHDB_VERSION_SUFFIX = $(shell git rev-parse --short --verify HEAD) COUCHDB_VERSION = $(vsn_major).$(vsn_minor).$(vsn_patch)-$(COUCHDB_VERSION_SUFFIX) else COUCHDB_VERSION = $(RELTAG) endif endif + DESTDIR= # Rebar options diff --git a/Makefile.win b/Makefile.win index 5a2a73a..26aef18 100644 --- a/Makefile.win +++ b/Makefile.win @@ -15,11 +15,11 @@ include version.mk SHELL=cmd.exe REBAR?=$(shell where rebar.cmd) IN_RELEASE = $(shell if not exist .git echo true) +COUCHDB_VERSION_SUFFIX = -$(shell git rev-parse --short --verify HEAD) ifeq ($(IN_RELEASE), true) COUCHDB_VERSION_SUFFIX= COUCHDB_VERSION = $(vsn_major).$(vsn_minor).$(vsn_patch) else -COUCHDB_VERSION_SUFFIX = -$(shell git rev-parse --short --verify HEAD) COUCHDB_VERSION = $(vsn_major).$(vsn_minor).$(vsn_patch)$(COUCHDB_VERSION_SUFFIX) endif diff --git a/src/chttpd/src/chttpd_misc.erl b/src/chttpd/src/chttpd_misc.erl index 253da23..7b34182 100644 --- a/src/chttpd/src/chttpd_misc.erl +++ b/src/chttpd/src/chttpd_misc.erl @@ -49,6 +49,7 @@ handle_welcome_req(#httpd{method='GET'}=Req, WelcomeMessage) -> send_json(Req, {[ {couchdb, WelcomeMessage}, {version, list_to_binary(couch_server:get_version())}, + {git_sha, list_to_binary(couch_server:get_version_suffix())}, {features, config:features()} ] ++ case config:get("vendor") of [] -> diff --git a/src/chttpd/test/chttpd_welcome_test.erl b/src/chttpd/test/chttpd_welcome_test.erl index af9732f..b737abd 100644 --- a/src/chttpd/test/chttpd_welcome_test.erl +++ b/src/chttpd/test/chttpd_welcome_test.erl @@ -60,6 +60,8 @@ should_have_version(Url) -> Version = couch_util:get_value(<<"version">>, Json, undefined), CouchDB = couch_util:get_value(<<"couchdb">>, Json, undefined), Features = couch_util:get_value(<<"features">>, Json, undefined), + Sha = couch_util:get_value(<<"git_sha">>, Json, undefined), + ?assertNotEqual(Sha, undefined), ?assertEqual(<<"Welcome">>, CouchDB), RealVersion = list_to_binary(couch_server:get_version()), ?assertEqual(RealVersion, Version), diff --git a/src/couch/rebar.config.script b/src/couch/rebar.config.script index 498ce3a..186ea9f 100644 --- a/src/couch/rebar.config.script +++ b/src/couch/rebar.config.script @@ -39,6 +39,13 @@ Version = case os:getenv("COUCHDB_VERSION") of string:strip(Version0, right) end, +VersionSuffix = case os:getenv("COUCHDB_VERSION_SUFFIX") of + false -> + string:strip(os:cmd("git rev-parse --short --verify HEAD"), right, $\n); + VersionSuffix0 -> + string:strip(VersionSuffix0, right) +end, + CouchConfig = case filelib:is_file(os:getenv("COUCHDB_CONFIG")) of true -> {ok, Result} = file:consult(os:getenv("COUCHDB_CONFIG")), @@ -142,6 +149,7 @@ AddConfig = [ {port_specs, PortSpecs}, {erl_opts, PlatformDefines ++ [ {d, 'COUCHDB_VERSION', Version}, + {d, 'COUCHDB_VERSION_SUFFIX', VersionSuffix}, {i, "../"} ]}, {eunit_compile_opts, PlatformDefines} diff --git a/src/couch/src/couch_server.erl b/src/couch/src/couch_server.erl index 002f08e..ea42b4c 100644 --- a/src/couch/src/couch_server.erl +++ b/src/couch/src/couch_server.erl @@ -15,7 +15,7 @@ -behaviour(config_listener). -vsn(3). --export([open/2,create/2,delete/2,get_version/0,get_version/1,get_uuid/0]). +-export([open/2,create/2,delete/2,get_version/0,get_version/1,get_version_suffix/0,get_uuid/0]). -export([all_databases/0, all_databases/2]). -export([init/1, handle_call/3,sup_start_link/0]). -export([handle_cast/2,code_change/3,handle_info/2,terminate/2]). @@ -57,6 +57,7 @@ get_version(short) -> [Version|_Rest] = string:tokens(get_version(), "+"), Version. +get_version_suffix() -> ?COUCHDB_VERSION_SUFFIX. get_uuid() -> case config:get("couchdb", "uuid", undefined) of
