Skip to content

Commit

Permalink
Add function to get git version of code base.
Browse files Browse the repository at this point in the history
  • Loading branch information
olofr committed Jul 10, 2017
1 parent 766c65b commit 84b0338
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ EXTENSION = timescaledb
SQL_FILES = $(shell cat sql/load_order.txt)

EXT_VERSION = $(shell cat timescaledb.control | grep 'default' | sed "s/^.*'\(.*\)'$\/\1/g")
EXT_GIT_COMMIT := $(shell git describe --abbrev=4 --dirty --always --tags || echo $(EXT_GIT_COMMIT))
EXT_SQL_FILE = sql/$(EXTENSION)--$(EXT_VERSION).sql

DATA = $(EXT_SQL_FILE)
Expand Down Expand Up @@ -41,7 +42,8 @@ SRCS = \
src/insert_statement_state.c \
src/agg_bookend.c \
src/subspace_store.c \
src/guc.c
src/guc.c \
src/version.c

OBJS = $(SRCS:.c=.o)
DEPS = $(SRCS:.c=.d)
Expand Down Expand Up @@ -83,7 +85,7 @@ PGXS := $(shell $(PG_CONFIG) --pgxs)
EXTRA_CLEAN = $(EXT_SQL_FILE) $(DEPS)

include $(PGXS)
override CFLAGS += -DINCLUDE_PACKAGE_SUPPORT=0 -MMD
override CFLAGS += -DINCLUDE_PACKAGE_SUPPORT=0 -MMD -DEXT_GIT_COMMIT=\"$(EXT_GIT_COMMIT)\"
override pg_regress_clean_files = test/results/ test/regression.diffs test/regression.out tmp_check/ log/ $(TEST_CLUSTER)
-include $(DEPS)

Expand Down
1 change: 1 addition & 0 deletions sql/load_order.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ sql/bookend.sql
sql/time_bucket.sql
sql/permissions.sql
sql/init.sql
sql/version.sql
2 changes: 2 additions & 0 deletions sql/version.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE OR REPLACE FUNCTION _timescaledb_internal.get_git_commit() RETURNS TEXT
AS '$libdir/timescaledb', 'get_git_commit' LANGUAGE C IMMUTABLE STRICT;
21 changes: 21 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "postgres.h"
#include <string.h>
#include "fmgr.h"

const char* git_commit = EXT_GIT_COMMIT;

PG_FUNCTION_INFO_V1(get_git_commit);

Datum
get_git_commit(PG_FUNCTION_ARGS) {
int32 var_size = VARHDRSZ + strlen(git_commit);
text *version_text = (text *) palloc(var_size);

SET_VARSIZE(version_text, var_size);

memcpy((void *) VARDATA(version_text),
(void *) git_commit,
var_size - VARHDRSZ);

PG_RETURN_TEXT_P(version_text);
}
4 changes: 2 additions & 2 deletions test/expected/pg_dump.out
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ SELECT count(*)
AND refobjid = (SELECT oid FROM pg_extension WHERE extname = 'timescaledb');
count
-------
110
111
(1 row)

\c postgres
Expand All @@ -66,7 +66,7 @@ SELECT count(*)
AND refobjid = (SELECT oid FROM pg_extension WHERE extname = 'timescaledb');
count
-------
110
111
(1 row)

\c single
Expand Down
8 changes: 8 additions & 0 deletions test/expected/version.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Just test that the function does not error out as the output
-- will change.
select count(*) from _timescaledb_internal.get_git_commit();
count
-------
1
(1 row)

4 changes: 4 additions & 0 deletions test/sql/version.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Just test that the function does not error out as the output
-- will change.
select count(*) from _timescaledb_internal.get_git_commit();

0 comments on commit 84b0338

Please sign in to comment.