From f2eec24c0e4311cc4b4638cab8f1731b698cd33a Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 8 Apr 2016 10:22:09 +0200 Subject: [PATCH] build-sys: detect a build from git; then show its short commit hash --- configure.ac | 12 +++++++++++- src/nano.c | 4 ++++ src/nano.h | 6 ++++++ src/winio.c | 8 +++----- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 78f6c30..0c42e1e 100644 --- a/configure.ac +++ b/configure.ac @@ -18,7 +18,7 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, # USA. -AC_INIT([GNU nano], [2.5.3-git], address@hidden, [nano]) +AC_INIT([GNU nano], [2.5.3], address@hidden, [nano]) AC_CONFIG_SRCDIR([src/nano.c]) AC_CANONICAL_HOST AM_INIT_AUTOMAKE @@ -692,6 +692,16 @@ AM_CONDITIONAL(GROFF_HTML, test x$groff_html_support = xyes) AC_CHECK_PROG(haveit, makeinfo, yes, no) AM_CONDITIONAL(HAVE_MAKEINFO, test x$haveit = xyes) +AC_MSG_CHECKING([whether building from git]) +if test -d .git ; then + AC_MSG_RESULT([yes]) + AC_PATH_PROG([GIT], [git]) + REVISION=`($GIT rev-parse --is-inside-work-tree >/dev/null 2>&1) && ($GIT rev-parse --short HEAD)` + AC_SUBST(REVISION) + AC_DEFINE_UNQUOTED([REVISION],"${REVISION}","Setting REVISION in config.h.") +else + AC_MSG_RESULT([no]) +fi AC_CONFIG_FILES([ Makefile diff --git a/src/nano.c b/src/nano.c index 1658b3c..efc21f6 100644 --- a/src/nano.c +++ b/src/nano.c @@ -933,7 +933,11 @@ void usage(void) * it was compiled with. */ void version(void) { +#ifdef REVISION + printf(" GNU nano from git, commit %s (after %s)\n", REVISION, VERSION); +#else printf(_(" GNU nano, version %s\n"), VERSION); +#endif printf(" (C) 1999..2016 Free Software Foundation, Inc.\n"); printf( _(" Email: address@hidden Web: http://www.nano-editor.org/")); diff --git a/src/nano.h b/src/nano.h index b79f3d2..f811f33 100644 --- a/src/nano.h +++ b/src/nano.h @@ -581,4 +581,10 @@ enum /* The maximum number of bytes buffered at one time. */ #define MAX_BUF_SIZE 128 +#ifdef REVISION +#define BRANDING PACKAGE_VERSION"-git "REVISION +#else +#define BRANDING PACKAGE_STRING +#endif + #endif /* !NANO_H */ diff --git a/src/winio.c b/src/winio.c index 3f4f9a6..3127e26 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1952,9 +1952,8 @@ void titlebar(const char *path) { int space = COLS; /* The space we have available for display. */ - size_t verlen = strlenpt(PACKAGE_STRING) + 1; - /* The length of the version message in columns, plus one for - * padding. */ + size_t verlen = strlenpt(BRANDING); + /* The length of the version message in columns. */ const char *prefix; /* "DIR:", "File:", or "New Buffer". Goes before filename. */ size_t prefixlen; @@ -1996,8 +1995,7 @@ void titlebar(const char *path) if (space >= 4) { /* Add a space after the version message, and account for both * it and the two spaces before it. */ - mvwaddnstr(topwin, 0, 2, PACKAGE_STRING, - actual_x(PACKAGE_STRING, verlen)); + mvwaddnstr(topwin, 0, 2, BRANDING, actual_x(BRANDING, verlen)); verlen += 3; /* Account for the full length of the version message. */ -- 2.8.1