[PATCH 1/7] cli: Framework for structured output versioning
authorAustin Clements <amdragon@MIT.EDU>
Sun, 16 Dec 2012 03:17:23 +0000 (22:17 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:22 +0000 (09:52 -0800)
68/fe7771ab0f071f803b381681c4214b0c61ac04 [new file with mode: 0644]

diff --git a/68/fe7771ab0f071f803b381681c4214b0c61ac04 b/68/fe7771ab0f071f803b381681c4214b0c61ac04
new file mode 100644 (file)
index 0000000..01d5eba
--- /dev/null
@@ -0,0 +1,226 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 2F372431FB6\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 19:17:42 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id i+wsidXDbfsk for <notmuch@notmuchmail.org>;\r
+       Sat, 15 Dec 2012 19:17:41 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU\r
+       [18.9.25.12])\r
+       by olra.theworths.org (Postfix) with ESMTP id C16E8431FBC\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 19:17:40 -0800 (PST)\r
+X-AuditID: 1209190c-b7f886d000000936-1a-50cd3d54a98f\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id A8.59.02358.45D3DC05; Sat, 15 Dec 2012 22:17:40 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id qBG3HcUq011429; \r
+       Sat, 15 Dec 2012 22:17:38 -0500\r
+Received: from drake.dyndns.org\r
+       (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [209.6.116.242]) (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qBG3HaA7012055\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sat, 15 Dec 2012 22:17:37 -0500 (EST)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1Tk4jP-0007c1-HX; Sat, 15 Dec 2012 22:17:35 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/7] cli: Framework for structured output versioning\r
+Date: Sat, 15 Dec 2012 22:17:23 -0500\r
+Message-Id: <1355627849-29099-2-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1355627849-29099-1-git-send-email-amdragon@mit.edu>\r
+References: <1355627849-29099-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrGIsWRmVeSWpSXmKPExsUixG6nrhtiezbA4M9FfovVc3ksrt+cyezA\r
+       5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZVxcdo6poEGvovtoXgPjLtUuRg4OCQETiaaP\r
+       wV2MnECmmMSFe+vZuhi5OIQE9jFKfN98iREkISSwgVHi2mVWiMQjJokrl9cwQThzGSVW7J3L\r
+       DlLFJqAhsW3/crAOEQFpiZ13Z7OC2MwCjhKf9y9iA7GFBVwkZvfPYwaxWQRUJSZfuQ5Wwyvg\r
+       ILH0eTcjxBmKEt3PJoDVcwL1bt7ykw3iCgeJ2UeOsk1g5F/AyLCKUTYlt0o3NzEzpzg1Wbc4\r
+       OTEvL7VI11AvN7NELzWldBMjKIg4JXl2ML45qHSIUYCDUYmH1+LrmQAh1sSy4srcQ4ySHExK\r
+       orw5lmcDhPiS8lMqMxKLM+KLSnNSiw8xSnAwK4nwJs0HKudNSaysSi3Kh0lJc7AoifNeTrnp\r
+       LySQnliSmp2aWpBaBJOV4eBQkuBltgEaKliUmp5akZaZU4KQZuLgBBnOAzRcGaSGt7ggMbc4\r
+       Mx0if4pRl6Ph5Y2njEIsefl5qVLivE+tgYoEQIoySvPg5sCi/xWjONBbwrwaIKN4gIkDbtIr\r
+       oCVMQEuW24B8UFySiJCSamA0NPsaFzs/b/Kyb/42Xy/Oifo2mbXY8rmHzgqXDUW8Yft69P/6\r
+       3j8zK8j57PKkNlfzpd16hWeelWXz7gtrrl8hGJR2IKqorZthbvydi7zlof/nLZ2ZvG1P39z2\r
+       uCs283ZNO/I3csUUz+87Vd88jg6+r3F597/dc5fJtc5aoN2ZLsuxRPHNmvxAJZbijERDLeai\r
+       4kQA+EQ7+dkCAAA=\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 16 Dec 2012 03:17:42 -0000\r
+\r
+Currently there is a period of pain whenever we make\r
+backward-incompatible changes to the structured output format, which\r
+discourages not only backward-incompatible improvements to the format,\r
+but also backwards-compatible additions that may not be "perfect".  In\r
+the end, these problems limit experimentation and innovation.\r
+\r
+This series of patches introduces a way for CLI callers to request a\r
+specific format version on the command line and to determine if the\r
+CLI does not supported the requested version (and perhaps present a\r
+useful diagnostic to the user).  Since the caller requests a format\r
+version, it's also possible for the CLI to support multiple\r
+incompatible versions simultaneously, unlike the alternate approach of\r
+including version information in the output.\r
+\r
+This patch lays the groundwork by introducing a versioning convention,\r
+standard exit codes, and a utility function to check the requested\r
+version and produce standardized diagnostic messages and exit\r
+statuses.\r
+---\r
+ devel/schemata   |    2 ++\r
+ notmuch-client.h |   45 +++++++++++++++++++++++++++++++++++++++++++++\r
+ notmuch.c        |   32 ++++++++++++++++++++++++++++++++\r
+ 3 files changed, 79 insertions(+)\r
+\r
+diff --git a/devel/schemata b/devel/schemata\r
+index d1ab983..292f287 100644\r
+--- a/devel/schemata\r
++++ b/devel/schemata\r
+@@ -14,6 +14,8 @@ are interleaved. Keys are printed as keywords (symbols preceded by a\r
+ colon), e.g. (:id "123" :time 54321 :from "foobar"). Null is printed as\r
+ nil, true as t and false as nil.\r
\r
++This is version 1 of the structured output format.\r
++\r
+ Common non-terminals\r
+ --------------------\r
\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index 1c336dc..d7b352e 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -117,6 +117,51 @@ chomp_newline (char *str)\r
+       str[strlen(str)-1] = '\0';\r
+ }\r
\r
++/* Exit status code indicating the requested format version is too old\r
++ * (support for that version has been dropped).  CLI code should use\r
++ * notmuch_exit_if_unsupported_format rather than directly exiting\r
++ * with this code.\r
++ */\r
++#define NOTMUCH_EXIT_FORMAT_TOO_OLD 20\r
++/* Exit status code indicating the requested format version is newer\r
++ * than the version supported by the CLI.  CLI code should use\r
++ * notmuch_exit_if_unsupported_format rather than directly exiting\r
++ * with this code.\r
++ */\r
++#define NOTMUCH_EXIT_FORMAT_TOO_NEW 21\r
++\r
++/* The current structured output format version.  Requests for format\r
++ * versions above this will return an error.  Backwards-incompatible\r
++ * changes such as removing map fields, changing the meaning of map\r
++ * fields, or changing the meanings of list elements should increase\r
++ * this.  New (required) map fields can be added without increasing\r
++ * this.\r
++ */\r
++#define NOTMUCH_FORMAT_CUR 1\r
++/* The minimum supported structured output format version.  Requests\r
++ * for format versions below this will return an error. */\r
++#define NOTMUCH_FORMAT_MIN 1\r
++\r
++/* The output format version requested by the caller on the command\r
++ * line.  If no format version is requested, this will be set to\r
++ * NOTMUCH_FORMAT_CUR.  Even though the command-line option is\r
++ * per-command, this is global because commands can share structured\r
++ * output code.\r
++ */\r
++extern int notmuch_format_version;\r
++\r
++/* Commands that support structured output should support the\r
++ * following argument\r
++ *  { NOTMUCH_OPT_INT, &notmuch_format_version, "format-version", 0, 0 }\r
++ * and should invoke notmuch_exit_if_unsupported_format to check the\r
++ * requested version.  If notmuch_format_version is outside the\r
++ * supported range, this will print a detailed diagnostic message for\r
++ * the user and exit with NOTMUCH_EXIT_FORMAT_TOO_{OLD,NEW} to inform\r
++ * the invoking program of the problem.\r
++ */\r
++void\r
++notmuch_exit_if_unsupported_format (void);\r
++\r
+ notmuch_crypto_context_t *\r
+ notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol);\r
\r
+diff --git a/notmuch.c b/notmuch.c\r
+index 4ff66e3..9516dfb 100644\r
+--- a/notmuch.c\r
++++ b/notmuch.c\r
+@@ -82,6 +82,8 @@ static command_t commands[] = {\r
+       "This message, or more detailed help for the named command." }\r
+ };\r
\r
++int notmuch_format_version;\r
++\r
+ static void\r
+ usage (FILE *out)\r
+ {\r
+@@ -109,6 +111,33 @@ usage (FILE *out)\r
+     "and \"notmuch help search-terms\" for the common search-terms syntax.\n\n");\r
+ }\r
\r
++void\r
++notmuch_exit_if_unsupported_format (void)\r
++{\r
++    if (notmuch_format_version > NOTMUCH_FORMAT_CUR) {\r
++      fprintf (stderr, "\\r
++A caller requested output format version %d, but the installed notmuch\n\\r
++CLI only supports up to format version %d.  You may need to upgrade your\n\\r
++notmuch CLI.\n",\r
++               notmuch_format_version, NOTMUCH_FORMAT_CUR);\r
++      exit (NOTMUCH_EXIT_FORMAT_TOO_NEW);\r
++    } else if (notmuch_format_version < NOTMUCH_FORMAT_MIN) {\r
++      fprintf (stderr, "\\r
++A caller requested output format version %d, which is no longer supported\n\\r
++by the notmuch CLI (it requires at least version %d).  You may need to\n\\r
++upgrade your notmuch front-end.\n",\r
++               notmuch_format_version, NOTMUCH_FORMAT_MIN);\r
++      exit (NOTMUCH_EXIT_FORMAT_TOO_OLD);\r
++    } else if (notmuch_format_version != NOTMUCH_FORMAT_CUR) {\r
++      /* Warn about old version requests so compatibility issues are\r
++       * less likely when we drop support for a deprecated format\r
++       * versions. */\r
++      fprintf (stderr, "\\r
++A caller requested deprecated output format version %d, which may not\n\\r
++be supported in the future.\n", notmuch_format_version);\r
++    }\r
++}\r
++\r
+ static void\r
+ exec_man (const char *page)\r
+ {\r
+@@ -242,6 +271,9 @@ main (int argc, char *argv[])\r
+     g_mime_init (0);\r
+     g_type_init ();\r
\r
++    /* Globally default to the current output format version. */\r
++    notmuch_format_version = NOTMUCH_FORMAT_CUR;\r
++\r
+     if (argc == 1)\r
+       return notmuch (local);\r
\r
+-- \r
+1.7.10.4\r
+\r