1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-16 21:35:24 +00:00

Add helper function to create version string

And remove all the duplicate code.

Depending on the situation prof_get_version() will return:
* 0.13.1
* 0.13.1dev
* 0.13.1dev.master.69d8c1f9
This commit is contained in:
Michael Vetter 2023-07-25 20:58:15 +02:00
parent 13af6c96dc
commit 22b1d14b67
9 changed files with 35 additions and 89 deletions

View File

@ -62,6 +62,10 @@
#include "log.h"
#include "common.h"
#ifdef HAVE_GIT_VERSION
#include "gitversion.h"
#endif
struct curl_data_t
{
char* buffer;
@ -688,3 +692,20 @@ glib_hash_table_free(GHashTable* hash_table)
g_hash_table_remove_all(hash_table);
g_hash_table_unref(hash_table);
}
/* build profanity version string.
* example: 0.13.1dev.master.69d8c1f9
*/
gchar*
prof_get_version(void)
{
if (strcmp(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION
return g_strdup_printf("%sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
#else
return g_strdup_printf("%sdev", PACKAGE_VERSION);
#endif
} else {
return g_strdup_printf("%s", PACKAGE_VERSION);
}
}

View File

@ -180,4 +180,6 @@ gchar* get_expanded_path(const char* path);
void glib_hash_table_free(GHashTable* hash_table);
char* basename_from_url(const char* url);
gchar* prof_get_version(void);
#endif

View File

@ -39,10 +39,6 @@
#include <string.h>
#include <glib.h>
#ifdef HAVE_GIT_VERSION
#include "gitversion.h"
#endif
#ifdef HAVE_LIBOTR
#include "otr/otr.h"
#endif
@ -104,15 +100,8 @@ main(int argc, char** argv)
g_option_context_free(context);
if (version == TRUE) {
if (strcmp(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION
g_print("Profanity, version %sdev.%s.%s\n", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
#else
g_print("Profanity, version %sdev\n", PACKAGE_VERSION);
#endif
} else {
g_print("Profanity, version %s\n", PACKAGE_VERSION);
}
auto_gchar gchar* prof_version = prof_get_version();
g_print("Profanity, version %s\n", prof_version);
// lets use fixed email instead of PACKAGE_BUGREPORT
g_print("Copyright (C) 2012 - 2019 James Booth <boothj5web@gmail.com>.\n");

View File

@ -35,10 +35,6 @@
*/
#include "config.h"
#ifdef HAVE_GIT_VERSION
#include "gitversion.h"
#endif
#ifdef HAVE_GTK
#include "ui/tray.h"
#endif
@ -180,15 +176,8 @@ _init(char* log_level, char* config_file, char* log_file, char* theme_name)
log_init(prof_log_level, log_file);
log_stderr_init(PROF_LEVEL_ERROR);
if (strcmp(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION
log_info("Starting Profanity (%sdev.%s.%s)…", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
#else
log_info("Starting Profanity (%sdev)…", PACKAGE_VERSION);
#endif
} else {
log_info("Starting Profanity (%s)…", PACKAGE_VERSION);
}
auto_gchar gchar* prof_version = prof_get_version();
log_info("Starting Profanity (%s)…", prof_version);
chat_log_init();
groupchat_log_init();

View File

@ -66,10 +66,6 @@
#include "xmpp/muc.h"
#include "xmpp/roster_list.h"
#ifdef HAVE_GIT_VERSION
#include "gitversion.h"
#endif
static void _cons_splash_logo(void);
static void _show_roster_contacts(GSList* list, gboolean show_groups);
static GList* alert_list;
@ -413,16 +409,8 @@ cons_about(void)
if (prefs_get_boolean(PREF_SPLASH)) {
_cons_splash_logo();
} else {
if (strcmp(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION
win_println(console, THEME_DEFAULT, "-", "Welcome to Profanity, version %sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
#else
win_println(console, THEME_DEFAULT, "Welcome to Profanity, version %sdev", PACKAGE_VERSION);
#endif
} else {
win_println(console, THEME_DEFAULT, "-", "Welcome to Profanity, version %s", PACKAGE_VERSION);
}
auto_gchar gchar* prof_version = prof_get_version();
win_println(console, THEME_DEFAULT, "-", "Welcome to Profanity, version %s", prof_version);
}
win_println(console, THEME_DEFAULT, "-", "Copyright (C) 2012 - 2019 James Booth <boothj5web@gmail.com>.");
@ -2778,15 +2766,8 @@ _cons_splash_logo(void)
win_println(console, THEME_SPLASH, "-", "|_| (____/ ");
win_println(console, THEME_SPLASH, "-", "");
if (strcmp(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION
win_println(console, THEME_DEFAULT, "-", "Version %sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
#else
win_println(console, THEME_DEFAULT, "Version %sdev", PACKAGE_VERSION);
#endif
} else {
win_println(console, THEME_DEFAULT, "-", "Version %s", PACKAGE_VERSION);
}
auto_gchar gchar* prof_version = prof_get_version();
win_println(console, THEME_DEFAULT, "-", "Version %s", prof_version);
}
static void

View File

@ -35,10 +35,6 @@
#include "config.h"
#ifdef HAVE_GIT_VERSION
#include "gitversion.h"
#endif
#include <stdlib.h>
#include <string.h>
#include <assert.h>

View File

@ -35,10 +35,6 @@
#include "config.h"
#ifdef HAVE_GIT_VERSION
#include "gitversion.h"
#endif
#include <stdlib.h>
#include <string.h>

View File

@ -35,10 +35,6 @@
#include "config.h"
#ifdef HAVE_GIT_VERSION
#include "gitversion.h"
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@ -1627,20 +1623,10 @@ _version_get_handler(xmpp_stanza_t* const stanza)
xmpp_stanza_t* version = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(version, "version");
xmpp_stanza_t* version_txt = xmpp_stanza_new(ctx);
GString* version_str = g_string_new(PACKAGE_VERSION);
auto_gchar gchar* prof_version = prof_get_version();
if (!is_custom_client) {
if (strcmp(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION
g_string_append(version_str, "dev.");
g_string_append(version_str, PROF_GIT_BRANCH);
g_string_append(version_str, ".");
g_string_append(version_str, PROF_GIT_REVISION);
#else
g_string_append(version_str, "dev");
#endif
}
xmpp_stanza_set_text(version_txt, version_str->str);
xmpp_stanza_set_text(version_txt, prof_version);
xmpp_stanza_add_child(version, version_txt);
xmpp_stanza_add_child(query, version);
@ -1678,7 +1664,6 @@ _version_get_handler(xmpp_stanza_t* const stanza)
iq_send_stanza(response);
// Cleanup
g_string_free(version_str, TRUE);
xmpp_stanza_release(version_txt);
xmpp_stanza_release(name_txt);
if (!is_custom_client && include_os) {

View File

@ -35,10 +35,6 @@
#include "config.h"
#ifdef HAVE_GIT_VERSION
#include "gitversion.h"
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@ -963,17 +959,8 @@ stanza_create_caps_query_element(xmpp_ctx_t* ctx)
GString* name_str = g_string_new(is_custom_client ? client : "Profanity ");
if (!is_custom_client) {
xmpp_stanza_set_type(identity, "console");
g_string_append(name_str, PACKAGE_VERSION);
if (g_strcmp0(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION
g_string_append(name_str, "dev.");
g_string_append(name_str, PROF_GIT_BRANCH);
g_string_append(name_str, ".");
g_string_append(name_str, PROF_GIT_REVISION);
#else
g_string_append(name_str, "dev");
#endif
}
auto_gchar gchar* prof_version = prof_get_version();
g_string_append(name_str, prof_version);
}
account_free(account);