From 02e2a93f4903ff3a482db9c1cff827143ba59f45 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Fri, 20 Jul 2018 10:36:20 -0700
Subject: [PROPOSED] Put a bit more info into tzdata.zi version string

Inspired by a remark by Brian Inglis, who suggested REDO in:
https://mm.icann.org/pipermail/tz/2018-July/026664.html
This doesn't do the other things he mentioned, as they are
not supported by our Makefile; if a downstream distributor
implements those other things, the distributor should append
a downstream-specific suffix to the 'version' string.
* Makefile (tzdata.zi): Depend on zishrink.awk.
Pass REDO and dependencies to zishrink.awk, instead of
just BACKWARD and PACKRATDATA.
* NEWS: Mention this.
* zishrink.awk: Report any changes to list of input files, not
merely changes to BACKWARD or PACKRATDATA.  Output nondefault REDO
as well; although REDO doesn't affect tzdata.zi it does affect
whether leap seconds are intended to be in the generated TZif
files, and this might be useful.

2018-07-18  Paul Eggert  <eggert@cs.ucla.edu>

* Makefile (AWK): Mention mawk problems.
---
 Makefile     |  7 ++++---
 NEWS         | 11 +++++++----
 zishrink.awk | 51 ++++++++++++++++++++++++++++++++++++++++-----------
 3 files changed, 51 insertions(+), 18 deletions(-)

diff --git a/Makefile b/Makefile
index 272e4cc..44b9b36 100644
--- a/Makefile
+++ b/Makefile
@@ -577,12 +577,13 @@ vanguard.zi main.zi rearguard.zi: $(DSTDATA_ZI_DEPS)
 		  $(TDATA) $(PACKRATDATA) >$@.out
 		mv $@.out $@
 # This file has a version comment that attempts to capture any tailoring
-# via BACKWARD, DATAFORM, and PACKRATDATA.
-tzdata.zi:	$(DATAFORM).zi version
+# via BACKWARD, DATAFORM, PACKRATDATA, and REDO.
+tzdata.zi:	$(DATAFORM).zi version zishrink.awk
 		version=`sed 1q version` && \
 		  LC_ALL=C $(AWK) \
-		    -v backlinks='$(BACKWARD) $(PACKRATDATA)' \
 		    -v dataform='$(DATAFORM)' \
+		    -v deps='$(DSTDATA_ZI_DEPS) zishrink.awk' \
+		    -v redo='$(REDO)' \
 		    -v version="$$version" \
 		    -f zishrink.awk \
 		    $(DATAFORM).zi >$@.out
diff --git a/NEWS b/NEWS
index bdf3cfe..413d649 100644
--- a/NEWS
+++ b/NEWS
@@ -93,10 +93,13 @@ Unreleased, experimental changes
     noted by Tom Lane.)  It is also a bit shorter.
 
     tzdata.zi's version comment now contains information about which
-    data format was selected, and whether backward, backzone and
-    pacificnew were used.  (Problem noted by Lester Caine.)  If the
-    Makefile defaults were used, no information is appended to the
-    version comment, for backward compatibility.
+    data format was selected, which input files were used, and how
+    leap seconds are treated.  (Problems noted by Lester Caine and
+    Brian Inglis.)  If the Makefile defaults are used, no text is
+    appended to the version comment, for backward compatibility.
+    A redistributor intending to alter its copy of the files should
+    also append "-SOMETHING" to the 'version' file's first line, where
+    "SOMETHING" identifies what was changed.
 
 
 Release 2018e - 2018-05-01 23:42:51 -0700
diff --git a/zishrink.awk b/zishrink.awk
index 1cc4c9d..162e515 100644
--- a/zishrink.awk
+++ b/zishrink.awk
@@ -267,23 +267,52 @@ function output_saved_lines(i)
 }
 
 BEGIN {
+  # Files that the output normally depends on.
+  default_dep["africa"] = 1
+  default_dep["antarctica"] = 1
+  default_dep["asia"] = 1
+  default_dep["australasia"] = 1
+  default_dep["backward"] = 1
+  default_dep["etcetera"] = 1
+  default_dep["europe"] = 1
+  default_dep["factory"] = 1
+  default_dep["northamerica"] = 1
+  default_dep["southamerica"] = 1
+  default_dep["systemv"] = 1
+  default_dep["ziguard.awk"] = 1
+  default_dep["zishrink.awk"] = 1
+
+  # Output a version string from 'version' and related configuration variables
+  # supported by tzdb's Makefile.  If you change the makefile or any other files
+  # that affect the output of this script, you should append '-SOMETHING'
+  # to the contents of 'version', where SOMETHING identifies what was changed.
+
   if (dataform != "main") {
-    version = version "," dataform
+    version = version ",dataform=" dataform
   }
-  not_backward = ",!backward"
-  nback = split(backlinks, back)
-  for (i = 1; i <= nback; i++) {
-    if (back[i] != "-") {
-      if (back[i] == "backward") {
-	not_backward = ""
-      } else {
-	version = version "," back[i]
-      }
+  if (redo != "posix_right") {
+    version = version ",redo=" redo
+  }
+  ndeps = split(deps, dep)
+  ddeps = ""
+  for (i = 1; i <= ndeps; i++) {
+    if (default_dep[dep[i]]) {
+      default_dep[dep[i]]++
+    } else {
+      ddeps = ddeps "," dep[i]
     }
   }
-  version = version not_backward
+  for (d in default_dep) {
+    if (default_dep[d] == 1) {
+      ddeps = ddeps ",!" d
+    }
+  }
+  if (ddeps) {
+    version = version ",ddeps=(" substr(ddeps, 2) ")"
+  }
   print "# version", version
   print "# This zic input file is in the public domain."
+
   prehash_rule_names()
 }
 
-- 
2.7.4

