New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show more information in get_git_commit #2468
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ create_postgres_build_image() { | |
docker run -d --name ${BUILD_CONTAINER_NAME} --env POSTGRES_HOST_AUTH_METHOD=trust -v ${BASE_DIR}:/src postgres:${PG_IMAGE_TAG} | ||
|
||
# Install build dependencies | ||
docker exec -u root ${BUILD_CONTAINER_NAME} /bin/bash -c "apk add --no-cache --virtual .build-deps gdb git coreutils dpkg-dev gcc libc-dev make cmake util-linux-dev diffutils openssl-dev && mkdir -p /build/debug" | ||
docker exec -u root ${BUILD_CONTAINER_NAME} /bin/bash -c "apk add --no-cache --virtual .build-deps gdb coreutils dpkg-dev gcc git libc-dev make cmake util-linux-dev diffutils openssl-dev && mkdir -p /build/debug" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. I'll remove it if I make more changes to the PR. |
||
docker commit -a $USER -m "TimescaleDB build base image version $PG_IMAGE_TAG" ${BUILD_CONTAINER_NAME} ${image} | ||
remove_build_container ${BUILD_CONTAINER_NAME} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
DROP VIEW IF EXISTS timescaledb_information.continuous_aggregates; | ||
DROP VIEW IF EXISTS timescaledb_information.job_stats; | ||
DROP FUNCTION IF EXISTS _timescaledb_internal.get_git_commit; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* This file and its contents are licensed under the Apache License 2.0. | ||
* Please see the included NOTICE for copyright information and | ||
* LICENSE-APACHE for a copy of the license. | ||
*/ | ||
|
||
#ifndef GITCOMMIT_H_ | ||
#define GITCOMMIT_H_ | ||
|
||
#cmakedefine EXT_GIT_COMMIT_TAG "@EXT_GIT_COMMIT_TAG@" | ||
#cmakedefine EXT_GIT_COMMIT_HASH "@EXT_GIT_COMMIT_HASH@" | ||
#cmakedefine EXT_GIT_COMMIT_TIME "@EXT_GIT_COMMIT_TIME@" | ||
|
||
#endif /* GITCOMMIT_H_ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,32 +10,88 @@ | |
#include <funcapi.h> | ||
#include <fmgr.h> | ||
#include <storage/fd.h> | ||
#include <utils/timestamp.h> | ||
|
||
#include "fmgr.h" | ||
#include "compat.h" | ||
#include "annotations.h" | ||
#include "gitcommit.h" | ||
#include "version.h" | ||
#include "config.h" | ||
|
||
#define STR_EXPAND(x) #x | ||
#define STR(x) STR_EXPAND(x) | ||
/* Export the strings to that we can read them using strings(1). We add a | ||
* prefix so that we can easily find it using grep(1). We only bother about | ||
* generating them if the relevant symbol is defined. */ | ||
#ifdef EXT_GIT_COMMIT_HASH | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this work as expected? Even if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not according to the documentation: https://cmake.org/cmake/help/latest/command/configure_file.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still unclear what happens if
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it is not defined like that in the generated file, it is either
or
If a builder decides on editing the file and putting anything else there, they can break the build whatever we do, so there is no reason to handle that case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what I wanted to know. |
||
static const char commit_hash[] TS_USED = "commit-hash:" EXT_GIT_COMMIT_HASH; | ||
#endif | ||
|
||
static const char *git_commit = STR(EXT_GIT_COMMIT); | ||
#ifdef EXT_GIT_COMMIT_TAG | ||
static const char commit_tag[] TS_USED = "commit-tag:" EXT_GIT_COMMIT_TAG; | ||
#endif | ||
|
||
#ifdef EXT_GIT_COMMIT_TIME | ||
static const char commit_time[] TS_USED = "commit-time:" EXT_GIT_COMMIT_TIME; | ||
#endif | ||
|
||
TS_FUNCTION_INFO_V1(ts_get_git_commit); | ||
|
||
/* Return git commit information defined in header file gitcommit.h. We | ||
* support that some of the fields are defined and will only show the fields | ||
* that are defined. If no fields are defined, we throw an error notifying the | ||
* user that there is no git information available at all. */ | ||
#if defined(EXT_GIT_COMMIT_HASH) || defined(EXT_GIT_COMMIT_TAG) || defined(EXT_GIT_COMMIT_TIME) | ||
Datum | ||
ts_get_git_commit(PG_FUNCTION_ARGS) | ||
{ | ||
size_t var_size = VARHDRSZ + strlen(git_commit); | ||
text *version_text = (text *) palloc(var_size); | ||
TupleDesc tupdesc; | ||
HeapTuple tuple; | ||
Datum values[3] = { 0 }; | ||
bool nulls[3] = { false }; | ||
|
||
SET_VARSIZE(version_text, var_size); | ||
/* Build a tuple descriptor for our result type */ | ||
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) | ||
ereport(ERROR, | ||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), | ||
errmsg("function returning record called in context " | ||
"that cannot accept type record"))); | ||
|
||
memcpy((void *) VARDATA(version_text), (void *) git_commit, var_size - VARHDRSZ); | ||
tupdesc = BlessTupleDesc(tupdesc); | ||
|
||
PG_RETURN_TEXT_P(version_text); | ||
#ifdef EXT_GIT_COMMIT_TAG | ||
values[0] = CStringGetTextDatum(EXT_GIT_COMMIT_TAG); | ||
#else | ||
nulls[0] = true; | ||
#endif | ||
|
||
#ifdef EXT_GIT_COMMIT_HASH | ||
values[1] = CStringGetTextDatum(EXT_GIT_COMMIT_HASH); | ||
#else | ||
nulls[1] = true; | ||
#endif | ||
|
||
#ifdef EXT_GIT_COMMIT_TIME | ||
values[2] = DirectFunctionCall3(timestamptz_in, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we know that the the Git timestamp is always a parsable TimestampTz string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AIUI, yes. The default is RFC2822, which is parseable by the timestamptz function: https://www.postgresql.org/message-id/32c009ea0510121301y6da7d43eq@mail.gmail.com Documentation is vague, but says:
|
||
CStringGetDatum(EXT_GIT_COMMIT_TIME), | ||
Int32GetDatum(-1), | ||
Int32GetDatum(-1)); | ||
#else | ||
nulls[2] = true; | ||
#endif | ||
|
||
tuple = heap_form_tuple(tupdesc, values, nulls); | ||
|
||
return HeapTupleGetDatum(tuple); | ||
} | ||
#else | ||
Datum | ||
ts_get_git_commit(PG_FUNCTION_ARGS) | ||
{ | ||
ereport(ERROR, | ||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), | ||
errmsg("extension not built with any Git commit information"))); | ||
} | ||
#endif | ||
|
||
#ifdef WIN32 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this dependency now that Git is still optional? Isn't it good to also run some tests where we don't have Git installed and build the dummy version of the get_git_commit function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should require git also for this case. Before, the tests was designed to not fail when Git was not available, but that is not the case right now and it will fail if git is not available (because the function generate an error rather than some output).
Since this is an internal function intended for debugging, I do not think a full test is necessary, but if you feel strongly about testing this, we can create a separate test that is only added if Git is absent.