From a31e39cc971a1e16c403a11463cd2fc98fe691c4 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 6 Mar 2012 18:48:39 +0000 Subject: [PATCH] [PATCH v2 3/8] show: Allow formatters to return errors --- 4e/9b7a4b5a4e8414edb9dc182c900d7808345aa0 | 291 ++++++++++++++++++++++ 1 file changed, 291 insertions(+) create mode 100644 4e/9b7a4b5a4e8414edb9dc182c900d7808345aa0 diff --git a/4e/9b7a4b5a4e8414edb9dc182c900d7808345aa0 b/4e/9b7a4b5a4e8414edb9dc182c900d7808345aa0 new file mode 100644 index 000000000..e26f3bb13 --- /dev/null +++ b/4e/9b7a4b5a4e8414edb9dc182c900d7808345aa0 @@ -0,0 +1,291 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id A96FC429E29 + for ; Tue, 6 Mar 2012 10:48:55 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 1e7IRtpcixha for ; + Tue, 6 Mar 2012 10:48:53 -0800 (PST) +Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU + [18.9.25.12]) + by olra.theworths.org (Postfix) with ESMTP id 2CD28431FC9 + for ; Tue, 6 Mar 2012 10:48:52 -0800 (PST) +X-AuditID: 1209190c-b7fad6d000000920-57-4f565c13c9aa +Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) + by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP + id D1.1D.02336.31C565F4; Tue, 6 Mar 2012 13:48:51 -0500 (EST) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q26ImoRK016036; + Tue, 6 Mar 2012 13:48:50 -0500 +Received: from drake.mit.edu (firewall.royalsociety.org [193.63.75.2]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q26Imm4N016463 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Tue, 6 Mar 2012 13:48:50 -0500 (EST) +Received: from amthrax by drake.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1S4zRI-0003pM-2D; Tue, 06 Mar 2012 18:48:48 +0000 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v2 3/8] show: Allow formatters to return errors +Date: Tue, 6 Mar 2012 18:48:39 +0000 +Message-Id: <1331059724-14653-4-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.7.3 +In-Reply-To: <1331059724-14653-1-git-send-email-amdragon@mit.edu> +References: <1330752025-2542-1-git-send-email-amdragon@mit.edu> + <1331059724-14653-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrJIsWRmVeSWpSXmKPExsUixCmqrCscE+ZvcHirusWefV4W12/OZHZg + 8rh7msvj2apbzAFMUVw2Kak5mWWpRfp2CVwZ65rWMhZs0K/omraaqYFxo0oXIyeHhICJxKZF + P5ghbDGJC/fWs4HYQgL7GCX+fzDrYuQCstczStz5uZoZwjnIJDH9xFk2CGc+o8TMr/OYQFrY + BDQktu1fzghiiwhIS+y8O5u1i5GDg1nASaKtzQvEFBawl5j7mQekgkVAVWLi6hVg1bwCDhJ9 + L/4xQRyhIHFu9Tl2EJtTwFFiz9NNjBAHlUlcunmBZQIj/wJGhlWMsim5Vbq5iZk5xanJusXJ + iXl5qUW6hnq5mSV6qSmlmxjBISTJs4PxzUGlQ4wCHIxKPLwX9cP8hVgTy4orcw8xSnIwKYny + 5kQBhfiS8lMqMxKLM+KLSnNSiw8xSnAwK4nwfnsf6i/Em5JYWZValA+TkuZgURLnVdF65yck + kJ5YkpqdmlqQWgSTleHgUJLgzYgGGipYlJqeWpGWmVOCkGbi4AQZzgM03Aikhre4IDG3ODMd + In+KUVFKnNcPJCEAksgozYPrhcX4K0ZxoFeEeR1BqniA6QGu+xXQYCagwW3KwSCDSxIRUlIN + jHHvHmTor1hvWHKpLjb3R+cG474u1t8vtjR7z8+79mdV5UnP6dxtanmC8/4eXjPbpmBRlvHv + h2dvs29JmO8nLX/S9qStS7L/5G9SV5kqHKdyvb5x+vC5Xrlbi7zF2Z3nJAbz9Sj5mcx6oXl/ + 0tLf0T/Xr37MwrD5/NQopqKK3DwVN8OGC/xiP5VYijMSDbWYi4oTAWcLH8nMAgAA +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Tue, 06 Mar 2012 18:48:56 -0000 + +Formatter errors are propagated to the exit status of notmuch show. + +This isn't used by the JSON or text formatters, but it will be useful +for the raw format, which is pickier. +--- + notmuch-client.h | 6 ++-- + notmuch-show.c | 71 +++++++++++++++++++++++++++++++++++------------------- + 2 files changed, 49 insertions(+), 28 deletions(-) + +diff --git a/notmuch-client.h b/notmuch-client.h +index f4a62cc..a220fe4 100644 +--- a/notmuch-client.h ++++ b/notmuch-client.h +@@ -67,9 +67,9 @@ struct notmuch_show_params; + + typedef struct notmuch_show_format { + const char *message_set_start; +- void (*part) (const void *ctx, +- struct mime_node *node, int indent, +- const struct notmuch_show_params *params); ++ notmuch_status_t (*part) (const void *ctx, ++ struct mime_node *node, int indent, ++ const struct notmuch_show_params *params); + const char *message_start; + void (*message) (const void *ctx, + notmuch_message_t *message, +diff --git a/notmuch-show.c b/notmuch-show.c +index 6a171a4..648f468 100644 +--- a/notmuch-show.c ++++ b/notmuch-show.c +@@ -23,7 +23,7 @@ + static void + format_headers_message_part_text (GMimeMessage *message); + +-static void ++static notmuch_status_t + format_part_text (const void *ctx, mime_node_t *node, + int indent, const notmuch_show_params_t *params); + +@@ -34,7 +34,7 @@ static const notmuch_show_format_t format_text = { + .message_set_end = "" + }; + +-static void ++static notmuch_status_t + format_part_json_entry (const void *ctx, mime_node_t *node, + int indent, const notmuch_show_params_t *params); + +@@ -562,7 +562,7 @@ format_part_content_raw (GMimeObject *part) + g_object_unref(stream_stdout); + } + +-static void ++static notmuch_status_t + format_part_text (const void *ctx, mime_node_t *node, + int indent, const notmuch_show_params_t *params) + { +@@ -650,6 +650,8 @@ format_part_text (const void *ctx, mime_node_t *node, + printf ("\fbody}\n"); + + printf ("\f%s}\n", part_type); ++ ++ return NOTMUCH_STATUS_SUCCESS; + } + + static void +@@ -751,14 +753,16 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first) + printf ("%s}", terminator); + } + +-static void ++static notmuch_status_t + format_part_json_entry (const void *ctx, mime_node_t *node, unused (int indent), + unused (const notmuch_show_params_t *params)) + { + format_part_json (ctx, node, TRUE); ++ ++ return NOTMUCH_STATUS_SUCCESS; + } + +-static void ++static notmuch_status_t + show_message (void *ctx, + const notmuch_show_format_t *format, + notmuch_message_t *message, +@@ -768,14 +772,18 @@ show_message (void *ctx, + if (format->part) { + void *local = talloc_new (ctx); + mime_node_t *root, *part; +- +- if (mime_node_open (local, message, params->cryptoctx, params->decrypt, +- &root) == NOTMUCH_STATUS_SUCCESS && +- (part = mime_node_seek_dfs (root, (params->part < 0 ? +- 0 : params->part)))) +- format->part (local, part, indent, params); ++ notmuch_status_t status; ++ ++ status = mime_node_open (local, message, params->cryptoctx, ++ params->decrypt, &root); ++ if (status) ++ goto DONE; ++ part = mime_node_seek_dfs (root, (params->part < 0 ? 0 : params->part)); ++ if (part) ++ status = format->part (local, part, indent, params); ++ DONE: + talloc_free (local); +- return; ++ return status; + } + + if (params->part <= 0) { +@@ -799,9 +807,11 @@ show_message (void *ctx, + + fputs (format->message_end, stdout); + } ++ ++ return NOTMUCH_STATUS_SUCCESS; + } + +-static void ++static notmuch_status_t + show_messages (void *ctx, + const notmuch_show_format_t *format, + notmuch_messages_t *messages, +@@ -812,6 +822,7 @@ show_messages (void *ctx, + notmuch_bool_t match; + int first_set = 1; + int next_indent; ++ notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS; + + fputs (format->message_set_start, stdout); + +@@ -832,17 +843,22 @@ show_messages (void *ctx, + next_indent = indent; + + if (match || params->entire_thread) { +- show_message (ctx, format, message, indent, params); ++ status = show_message (ctx, format, message, indent, params); ++ if (status && !res) ++ res = status; + next_indent = indent + 1; + +- fputs (format->message_set_sep, stdout); ++ if (!status) ++ fputs (format->message_set_sep, stdout); + } + +- show_messages (ctx, +- format, +- notmuch_message_get_replies (message), +- next_indent, +- params); ++ status = show_messages (ctx, ++ format, ++ notmuch_message_get_replies (message), ++ next_indent, ++ params); ++ if (status && !res) ++ res = status; + + notmuch_message_destroy (message); + +@@ -850,6 +866,8 @@ show_messages (void *ctx, + } + + fputs (format->message_set_end, stdout); ++ ++ return res; + } + + /* Formatted output of single message */ +@@ -914,13 +932,13 @@ do_show_single (void *ctx, + + fclose (file); + ++ return 0; ++ + } else { + +- show_message (ctx, format, message, 0, params); ++ return show_message (ctx, format, message, 0, params) != NOTMUCH_STATUS_SUCCESS; + + } +- +- return 0; + } + + /* Formatted output of threads */ +@@ -934,6 +952,7 @@ do_show (void *ctx, + notmuch_thread_t *thread; + notmuch_messages_t *messages; + int first_toplevel = 1; ++ notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS; + + fputs (format->message_set_start, stdout); + +@@ -953,7 +972,9 @@ do_show (void *ctx, + fputs (format->message_set_sep, stdout); + first_toplevel = 0; + +- show_messages (ctx, format, messages, 0, params); ++ status = show_messages (ctx, format, messages, 0, params); ++ if (status && !res) ++ res = status; + + notmuch_thread_destroy (thread); + +@@ -961,7 +982,7 @@ do_show (void *ctx, + + fputs (format->message_set_end, stdout); + +- return 0; ++ return res != NOTMUCH_STATUS_SUCCESS; + } + + enum { +-- +1.7.7.3 + -- 2.26.2