You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2018/07/17 06:44:37 UTC

[couchdb] branch master updated (3acf15f -> 1d69790)

This is an automated email from the ASF dual-hosted git repository.

jan pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


    from 3acf15f  Make MD5 hash implementation configurable (#1171)
     new 79eb1af  Report git sha on welcome request
     new 1d69790  Improve detection of git tags/dirty status

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Makefile                                | 45 +++++++++++++++++++++++++++------
 Makefile.win                            | 45 ++++++++++++++++++++++++++++++---
 build-aux/couchdb-build-release.sh      |  6 ++++-
 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 ++-
 7 files changed, 96 insertions(+), 14 deletions(-)


[couchdb] 02/02: Improve detection of git tags/dirty status

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 1d697901a283d4abc38916a1c883bd5b8c47155f
Author: Joan Touzet <jo...@atypical.net>
AuthorDate: Mon Jul 16 16:56:52 2018 -0400

    Improve detection of git tags/dirty status
    
    Unfortuantely, #1437 brought in a build bug that caused dist tarballs
    to be created always using the last tag that could be found on the
    tree. This lead to `master` building tarballs labelled `2.1.0`.
    
    The new approach includes extensive comments to explain the approach,
    fixes the bug, and for an encore adds -dirty if you're building a
    CouchDB with local changes that aren't committed to git.
---
 Makefile     | 41 ++++++++++++++++++++++++++++++++++-------
 Makefile.win | 41 ++++++++++++++++++++++++++++++++++++++---
 2 files changed, 72 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index 306961a..304b48e 100644
--- a/Makefile
+++ b/Makefile
@@ -13,22 +13,49 @@
 include version.mk
 
 REBAR?=$(shell echo `pwd`/bin/rebar)
+
+# Handle the following scenarios:
+#   1. When building from a tarball, use version.mk.
+#   2. When building from a clean release tag (#.#.#), use that tag.
+#   3. When building from a clean RC tag (#.#.#-RC#), use JUST the version
+#      number inside the tarball, but use the full name for the name of the
+#      tarball itself.
+#   4. When not on a clean tag, use version.mk + git sha + dirty status.
+
 COUCHDB_GIT_SHA=$(git_sha)
+
 IN_RELEASE = $(shell if [ ! -d .git ]; then echo true; fi)
 ifeq ($(IN_RELEASE), true)
+
+# 1. Building from tarball, use version.mk.
 COUCHDB_VERSION = $(vsn_major).$(vsn_minor).$(vsn_patch)
+
 else
-# IN_RC generates a tarball that has the -RCx suffix in the name if needed
+
+# Gather some additional information.
+# We do it this way so we don't bake shell-isms into Makefile
+# to make it easier to port to Windows. I know, I know. -jst
+# IN_RC contains the -RCx suffix in the name if present
 IN_RC = $(shell git describe --tags --always --first-parent \
-							| grep -Eo -- '-RC[0-9]+' 2>/dev/null)
-RELTAG = $(shell git describe --dirty --abbrev=0 --tags --always --first-parent \
-				| grep -Eo '^[0-9]+\.[0-9]\.[0-9]+')
+        | grep -Eo -- '-RC[0-9]+' 2>/dev/null)
+# ON_TAG matches *ONLY* if we are on a release or RC tag
+ON_TAG = $(shell git describe --tags --always --first-parent \
+        | grep -Eo -- '^[0-9]+\.[0-9]\.[0-9]+(-RC[0-9]+)?$$' 2>/dev/null)
+# RELTAG contains the #.#.# from git describe, which might be used
+RELTAG = $(shell git describe --tags --always --first-parent \
+        | grep -Eo -- '^[0-9]+\.[0-9]\.[0-9]+' 2>/dev/null)
+# DIRTY identifies if we're not on a commit
+DIRTY = $(shell git describe --dirty | grep -Eo -- '-dirty' 2>/dev/null)
+# COUCHDB_GIT_SHA is our current git hash.
 COUCHDB_GIT_SHA=$(shell git rev-parse --short --verify HEAD)
-ifeq ($(RELTAG),)
-COUCHDB_VERSION_SUFFIX = $(COUCHDB_GIT_SHA)
+
+ifeq ($(ON_TAG),)
+# 4. Not on a tag.
+COUCHDB_VERSION_SUFFIX = $(COUCHDB_GIT_SHA)$(DIRTY)
 COUCHDB_VERSION = $(vsn_major).$(vsn_minor).$(vsn_patch)-$(COUCHDB_VERSION_SUFFIX)
 else
-COUCHDB_VERSION = $(RELTAG)
+# 2 and 3. On a tag.
+COUCHDB_VERSION = $(RELTAG)$(DIRTY)
 endif
 endif
 
diff --git a/Makefile.win b/Makefile.win
index 7cf3cfa..67c15fc 100644
--- a/Makefile.win
+++ b/Makefile.win
@@ -14,15 +14,50 @@ include version.mk
 
 SHELL=cmd.exe
 REBAR?=$(shell where rebar.cmd)
+
+# Handle the following scenarios:
+#   1. When building from a tarball, use version.mk.
+#   2. When building from a clean release tag (#.#.#), use that tag.
+#   3. When building from a clean RC tag (#.#.#-RC#), use JUST the version
+#      number inside the tarball, but use the full name for the name of the
+#      tarball itself.
+#   4. When not on a clean tag, use version.mk + git sha + dirty status.
+
 COUCHDB_GIT_SHA=$(git_sha)
 IN_RELEASE = $(shell if not exist .git echo true)
+
 ifeq ($(IN_RELEASE), true)
-COUCHDB_VERSION_SUFFIX=
+
+# 1. Building from tarball, use version.mk.
 COUCHDB_VERSION = $(vsn_major).$(vsn_minor).$(vsn_patch)
+
 else
+
+# Gather some additional information.
+# We do it this way so we don't bake shell-isms into Makefile
+# to make it easier to port to Windows. I know, I know. -jst
+# COUCHDB_GIT_SHA is our current git hash.
 COUCHDB_GIT_SHA=$(shell git rev-parse --short --verify HEAD)
-COUCHDB_VERSION_SUFFIX = -$(COUCHDB_GIT_SHA)
-COUCHDB_VERSION = $(vsn_major).$(vsn_minor).$(vsn_patch)$(COUCHDB_VERSION_SUFFIX)
+# IN_RC contains the -RCx suffix in the name if present
+IN_RC = $(shell git describe --tags --always --first-parent \
+        | grep -Eo -- '-RC[0-9]+' 2>/dev/null)
+# ON_TAG matches *ONLY* if we are on a release or RC tag
+ON_TAG = $(shell git describe --tags --always --first-parent \
+        | grep -Eo -- '^[0-9]+\.[0-9]\.[0-9]+(-RC[0-9]+)?$$' 2>/dev/null)
+# RELTAG contains the #.#.# from git describe, which might be used
+RELTAG = $(shell git describe --tags --always --first-parent \
+        | grep -Eo -- '^[0-9]+\.[0-9]\.[0-9]+' 2>/dev/null)
+# DIRTY identifies if we're not on a commit
+DIRTY = $(shell git describe --dirty | grep -Eo -- '-dirty' 2>/dev/null)
+
+ifeq ($(ON_TAG),)
+# 4. Not on a tag.
+COUCHDB_VERSION_SUFFIX = $(COUCHDB_GIT_SHA)$(DIRTY)
+COUCHDB_VERSION = $(vsn_major).$(vsn_minor).$(vsn_patch)-$(COUCHDB_VERSION_SUFFIX)
+else
+# 2 and 3. On a tag.
+COUCHDB_VERSION = $(RELTAG)$(DIRTY)
+endif
 endif
 
 DESTDIR=


[couchdb] 01/02: Report git sha on welcome request

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 79eb1afc8e2c11d3ae1a71057656af05a541fffe
Author: Jan Lehnardt <ja...@apache.org>
AuthorDate: Fri Jul 13 14:26:43 2018 +0200

    Report git sha on welcome request
    
    Closes #1309
---
 Makefile                                | 6 ++++--
 Makefile.win                            | 6 ++++--
 build-aux/couchdb-build-release.sh      | 6 +++++-
 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 ++-
 7 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index 27d9531..306961a 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,7 @@
 include version.mk
 
 REBAR?=$(shell echo `pwd`/bin/rebar)
+COUCHDB_GIT_SHA=$(git_sha)
 IN_RELEASE = $(shell if [ ! -d .git ]; then echo true; fi)
 ifeq ($(IN_RELEASE), true)
 COUCHDB_VERSION = $(vsn_major).$(vsn_minor).$(vsn_patch)
@@ -22,8 +23,9 @@ IN_RC = $(shell git describe --tags --always --first-parent \
 							| grep -Eo -- '-RC[0-9]+' 2>/dev/null)
 RELTAG = $(shell git describe --dirty --abbrev=0 --tags --always --first-parent \
 				| grep -Eo '^[0-9]+\.[0-9]\.[0-9]+')
+COUCHDB_GIT_SHA=$(shell git rev-parse --short --verify HEAD)
 ifeq ($(RELTAG),)
-COUCHDB_VERSION_SUFFIX = $(shell git rev-parse --short --verify HEAD)
+COUCHDB_VERSION_SUFFIX = $(COUCHDB_GIT_SHA)
 COUCHDB_VERSION = $(vsn_major).$(vsn_minor).$(vsn_patch)-$(COUCHDB_VERSION_SUFFIX)
 else
 COUCHDB_VERSION = $(RELTAG)
@@ -82,7 +84,7 @@ help:
 .PHONY: couch
 # target: couch - Build CouchDB core, use ERL_OPTS to provide custom compiler's options
 couch: config.erl
-	@COUCHDB_VERSION=$(COUCHDB_VERSION) $(REBAR) compile $(COMPILE_OPTS)
+	@COUCHDB_VERSION=$(COUCHDB_VERSION) COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) $(REBAR) compile $(COMPILE_OPTS)
 	@cp src/couch/priv/couchjs bin/
 
 
diff --git a/Makefile.win b/Makefile.win
index 5a2a73a..7cf3cfa 100644
--- a/Makefile.win
+++ b/Makefile.win
@@ -14,12 +14,14 @@ include version.mk
 
 SHELL=cmd.exe
 REBAR?=$(shell where rebar.cmd)
+COUCHDB_GIT_SHA=$(git_sha)
 IN_RELEASE = $(shell if not exist .git echo true)
 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_GIT_SHA=$(shell git rev-parse --short --verify HEAD)
+COUCHDB_VERSION_SUFFIX = -$(COUCHDB_GIT_SHA)
 COUCHDB_VERSION = $(vsn_major).$(vsn_minor).$(vsn_patch)$(COUCHDB_VERSION_SUFFIX)
 endif
 
@@ -53,7 +55,7 @@ all: couch fauxton docs
 .PHONY: couch
 # target: couch - Build CouchDB core
 couch: config.erl
-	@set COUCHDB_VERSION=$(COUCHDB_VERSION) && $(REBAR) compile
+	@set COUCHDB_VERSION=$(COUCHDB_VERSION) && set COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) && $(REBAR) compile
 	@copy src\couch\priv\couchjs.exe bin
 
 
diff --git a/build-aux/couchdb-build-release.sh b/build-aux/couchdb-build-release.sh
index 4482b71..2d219e5 100755
--- a/build-aux/couchdb-build-release.sh
+++ b/build-aux/couchdb-build-release.sh
@@ -35,8 +35,12 @@ done
 
 cd ..
 
-# create CONTRIBUTORS file
+
 if test -e .git; then
+    # save git sha in version.mk
+    git_sha=`git rev-parse --short HEAD`
+    echo "git_sha=$git_sha" >> $RELDIR/version.mk
+    # create CONTRIBUTORS file
     OS=`uname -s`
     case "$OS" in
     Linux|CYGWIN*) # GNU sed
diff --git a/src/chttpd/src/chttpd_misc.erl b/src/chttpd/src/chttpd_misc.erl
index 95345d4..596e014 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_git_sha())},
         {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 fe249d0..fe7383c 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,
 
+GitSha = case os:getenv("COUCHDB_GIT_SHA") of
+    false ->
+        ""; % release builds won’t get a fallback
+    GitSha0 ->
+        string:strip(GitSha0, right)
+end,
+
 CouchConfig = case filelib:is_file(os:getenv("COUCHDB_CONFIG")) of
     true ->
         {ok, Result} = file:consult(os:getenv("COUCHDB_CONFIG")),
@@ -149,6 +156,7 @@ AddConfig = [
     {port_specs, PortSpecs},
     {erl_opts, PlatformDefines ++ [
         {d, 'COUCHDB_VERSION', Version},
+        {d, 'COUCHDB_GIT_SHA', GitSha},
         {i, "../"}
     ] ++ MD5Config},
     {eunit_compile_opts, PlatformDefines}
diff --git a/src/couch/src/couch_server.erl b/src/couch/src/couch_server.erl
index 002f08e..ede8227 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_git_sha/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_git_sha() -> ?COUCHDB_GIT_SHA.
 
 get_uuid() ->
     case config:get("couchdb", "uuid", undefined) of