ソースを参照

GIS_H_VERSION: use git hash (#325)

previously, GIS_H_VERSION was the svn revision number of gis.h and GIS_H_DATE was the svn revision date of gis.h

now they are the git hash and date of the last change to GRASS headers (and anything else in include)
in g.version, these have been and are still referred to as GIS library revision number and date which is wrong, these are
GIS headers revision number and date, which is not the same

Co-authored-by: Huidae Cho <grass4u@gmail.com>
Co-authored-by: Martin Landa <landa.martin@gmail.com>
Markus Metz 5 年 前
コミット
f062bffc82
6 ファイル変更783 行追加693 行削除
  1. 741 674
      configure
  2. 14 0
      configure.in
  3. 16 17
      general/g.version/main.c
  4. 8 2
      include/gis.h
  5. 2 0
      include/version.h.in
  6. 2 0
      lib/gis/gisinit.c

ファイルの差分が大きいため隠しています
+ 741 - 674
configure


+ 14 - 0
configure.in

@@ -140,12 +140,24 @@ LIB_VER=`echo ${GRASS_VERSION_NUMBER} | sed 's/^\([0-9.]*\).*$/\1/'`
 changequote([,])
 
 GRASS_VERSION_GIT="exported"
+# get git short hash + date of last change in GRASS headers
+# (and anything else in include)
+GRASS_HEADERS_GIT_HASH=`date`
+GRASS_HEADERS_GIT_DATE=`date`
 AC_PATH_PROG(GIT, git, no)
 if test "$GIT" != "no" ; then
    GRASS_VERSION_GIT=`$GIT rev-parse --short HEAD 2>/dev/null`
    if test -z "$GRASS_VERSION_GIT"; then
       GRASS_VERSION_GIT="exported"
    fi
+   GRASS_HEADERS_GIT_HASH=`$GIT log -1 --pretty=format:"%h" -- "${SRCDIR}/include" 2>/dev/null`
+   if test -z "$GRASS_HEADERS_GIT_HASH"; then
+      GRASS_HEADERS_GIT_HASH=`date`
+   fi
+   GRASS_HEADERS_GIT_DATE=`$GIT log -1 --pretty=format:"%cd" -- "${SRCDIR}/include" 2>/dev/null`
+   if test -z "$GRASS_HEADERS_GIT_DATE"; then
+      GRASS_HEADERS_GIT_DATE=`date`
+   fi
 fi
 
 AC_SUBST(GRASS_VERSION_FILE)
@@ -155,6 +167,8 @@ AC_SUBST(GRASS_VERSION_RELEASE)
 AC_SUBST(GRASS_VERSION_NUMBER)
 AC_SUBST(GRASS_VERSION_DATE)
 AC_SUBST(GRASS_VERSION_GIT)
+AC_SUBST(GRASS_HEADERS_GIT_HASH)
+AC_SUBST(GRASS_HEADERS_GIT_DATE)
 AC_SUBST(NAME_VER)
 AC_SUBST(LIB_VER)
 

+ 16 - 17
general/g.version/main.c

@@ -92,6 +92,10 @@ int main(int argc, char *argv[])
 
     gish_rev = G_define_flag();
     gish_rev->key = 'r';
+    /* this was never the library revision number and date
+     * it was the revision number and date of gis.h
+     * now it is the git hash and date of all GRASS headers
+     * (and anything else in include) */
     gish_rev->description =
 	_("Print also the GIS library revision number and date");
     gish_rev->guisection = _("Additional info");
@@ -140,26 +144,23 @@ int main(int argc, char *argv[])
     }
 
     if (gish_rev->answer) {
-	char **rev_ver = G_tokenize(GIS_H_VERSION, "$");
-	char **rev_time = G_tokenize(GIS_H_DATE, "$");
-	const int tokens_expected = 3;
+	char *rev_ver = GIS_H_VERSION;
+	char *rev_time = GIS_H_DATE;
 	int no_libgis = FALSE;
 
-	/* if number of tokes is right, print it */
-	if (G_number_of_tokens(rev_ver) == tokens_expected &&
-	    G_number_of_tokens(rev_time) == tokens_expected) {
+	if (*rev_ver && *rev_time) {
 	    if (shell->answer) {
-                const char *p;
-                p = strstr(rev_ver[1], " ");
-		fprintf(stdout, "libgis_revision=%s\n",
-			p ? p + 1 : "00000");
-                p = strstr(rev_time[1], " ");
-		fprintf(stdout, "libgis_date=\"%s\"\n",
-			p ? p + 1 : "?");
+                fprintf(stdout, "libgis_revision=");
+                if (strstr(rev_ver, " ") != NULL)
+                    fprintf(stdout, "\"%s\"", rev_ver);
+                else
+                    fprintf(stdout, "%s", rev_ver);
+                fprintf(stdout, "\n");
+		fprintf(stdout, "libgis_date=\"%s\"\n", rev_time);
 	    }
 	    else {
-		fprintf(stdout, "libgis %s\nlibgis %s\n", rev_ver[1],
-			rev_time[1]);
+		fprintf(stdout, "libgis revision: %s\n", rev_ver);
+		fprintf(stdout, "libgis date: %s\n", rev_time);
 	    }
 	}
 	else {
@@ -185,8 +186,6 @@ int main(int argc, char *argv[])
 	    G_debug(1, _("GIS_H_VERSION=\"%s\""), GIS_H_VERSION);
 	    G_debug(1, _("GIS_H_DATE=\"%s\""), GIS_H_DATE);
 	}
-	G_free_tokens(rev_ver);
-	G_free_tokens(rev_time);
     }
 
     if (extended->answer) {

+ 8 - 2
include/gis.h

@@ -39,8 +39,14 @@
 static const char *GRASS_copyright __attribute__ ((unused))
     = "GRASS GNU GPL licensed Software";
 
-#define GIS_H_VERSION GRASS_VERSION_STRING
-#define GIS_H_DATE    "$Date$"
+/* GRASS version, GRASS date, git short hash of last change in GRASS headers
+ * (and anything else in include)
+ */
+#define GIS_H_VERSION GRASS_HEADERS_VERSION
+/* git date of last change in GRASS headers
+ * (and anything else in include)
+ */
+#define GIS_H_DATE    GRASS_HEADERS_DATE
 
 #define G_gisinit(pgm) G__gisinit(GIS_H_VERSION, (pgm))
 #define G_no_gisinit() G__no_gisinit(GIS_H_VERSION)

+ 2 - 0
include/version.h.in

@@ -2,3 +2,5 @@
 #define GRASS_VERSION_MAJOR    @GRASS_VERSION_MAJOR@
 #define GRASS_VERSION_MINOR    @GRASS_VERSION_MINOR@
 #define GRASS_VERSION_RELEASE  @GRASS_VERSION_RELEASE@
+#define GRASS_HEADERS_VERSION "@GRASS_HEADERS_GIT_HASH@"
+#define GRASS_HEADERS_DATE "@GRASS_HEADERS_GIT_DATE@"

+ 2 - 0
lib/gis/gisinit.c

@@ -49,6 +49,7 @@ void G__gisinit(const char *version, const char *pgm)
 
     G_set_program_name(pgm);
 
+    /* verify version of GRASS headers (and anything else in include) */
     if (strcmp(version, GIS_H_VERSION) != 0)
 	G_fatal_error(_("Module built against version %s but "
 			"trying to use version %s. "
@@ -83,6 +84,7 @@ void G__no_gisinit(const char *version)
     if (initialized)
 	return;
 
+    /* verify version of GRASS headers (and anything else in include) */
     if (strcmp(version, GIS_H_VERSION) != 0)
 	G_fatal_error(_("Module built against version %s but "
 			"trying to use version %s. "