[PATCH] add patchlevel to --version output

dana <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <[email protected]>
wesley brought w/49374 (and w/52045 etc -- for some reason the mla
doesn't thread any of the replies) to our attention on irc today. i
think it's a good idea, but we talked about it more and revised

with this patch, the patchlevel (custom or not) is displayed in the
--version output whenever it doesn't look like the default patchlevel
for a tagged release

we also changed the format from the previous revision to ensure that any
scripts that might expect the target string at the end continue to work

the result looks like this:

  # built from release tag or tarball (no change)
  % Src/zsh --version
  zsh 5.9.0.4-test (arm-apple-darwin24.6.0)

  # built from master
  % Src/zsh --version
  zsh 5.9.999.3-test [zsh-5.9.0.3-test-279-g8714db6] (arm-apple-darwin24.6.0)

  # built from tarball with custom patchlevel like debian's
  % Src/zsh --version
  zsh 5.9 [debian/5.9-8+b22] (x86_64-debian-linux-gnu)

wesley pointed out that the middle one is a bit noisy, and i agree, but
i'm not sure what a reliable alternative is. he had some other ideas,
i'll let him advocate for them if he likes

dana


diff --git a/Src/init.c b/Src/init.c
index 28bff0763..89a7ff714 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -35,6 +35,14 @@
 #include "init.pro"
 
 #include "version.h"
+#ifdef CUSTOM_PATCHLEVEL
+#define ZSH_PATCHLEVEL CUSTOM_PATCHLEVEL
+#else
+#include "patchlevel.h"
+#ifndef ZSH_PATCHLEVEL
+#define ZSH_PATCHLEVEL "unknown"
+#endif
+#endif
 
 #if defined(HAVE_SYS_SYSCTL_H) && !defined(__linux)
 #include <sys/sysctl.h>
@@ -435,8 +443,15 @@ parseopts(char *nam, char ***argvp, char *new_opts, char **cmdp,
 		/* GNU-style long options */
 		++*argv;
 		if (!strcmp(*argv, "version")) {
-		    printf("zsh %s (%s-%s-%s)\n",
-			    ZSH_VERSION, MACHTYPE, VENDOR, OSTYPE);
+		    // omit patchlevel for a tagged release, which looks like:
+		    // zsh-x.y.z-0-gabcdef
+		    static const char *pfx = "zsh-" ZSH_VERSION "-0-";
+		    if (strncmp(ZSH_PATCHLEVEL, pfx, strlen(pfx)))
+			printf("zsh %s [%s] (%s-%s-%s)\n",
+				ZSH_VERSION, ZSH_PATCHLEVEL, MACHTYPE, VENDOR, OSTYPE);
+		    else
+			printf("zsh %s (%s-%s-%s)\n",
+				ZSH_VERSION, MACHTYPE, VENDOR, OSTYPE);
 		    LAST_OPTION(0);
 		}
 		if (!strcmp(*argv, "help")) {
diff --git a/Src/zsh.mdd b/Src/zsh.mdd
index da8d58322..9a5e9daab 100644
--- a/Src/zsh.mdd
+++ b/Src/zsh.mdd
@@ -41,7 +41,7 @@ signames.c: signames1.awk signames2.awk ../config.h @SIGNAL_H@
 sigcount.h: signames.c
 	grep 'define.*SIGCOUNT' signames.c > $@
 
-init.o: bltinmods.list zshpaths.h zshxmods.h
+init.o: bltinmods.list zshpaths.h zshxmods.h patchlevel.h
 
 init.o params.o parse.o: version.h
 
diff --git a/Test/E01options.ztst b/Test/E01options.ztst
index dcb14e013..6e4690ef7 100644
--- a/Test/E01options.ztst
+++ b/Test/E01options.ztst
@@ -96,6 +96,15 @@
 
 %test
 
+# --version is technically an option
+  v=$( $ZTST_testdir/../Src/zsh --version )
+  print -r - $v
+  # patchlevel should appear in output if different from version
+  [[ $ZSH_PATCHLEVEL == zsh-$ZSH_VERSION-0-* ]] ||
+  [[ $v == *\[$ZSH_PATCHLEVEL\]* ]]
+0:zsh --version output
+*>zsh * \(*\)
+
   # setopt should move on to the next operation in the face of an error, but
   # preserve the >0 return code
   unsetopt aliases
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.