unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 0/9] cli/show: refactoring and cleanup
@ 2017-01-06 20:14 Jani Nikula
  2017-01-06 20:14 ` [PATCH 1/9] cli/show: detangle overloading of params.part for single message display Jani Nikula
                   ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: Jani Nikula @ 2017-01-06 20:14 UTC (permalink / raw)
  To: notmuch

I was planning on adding mime structure printing to notmuch show, not
unlike devel/printmimestructure, but notmuch-show was in need of some
cleanup first. Here goes.

BR,
Jani.


Jani Nikula (9):
  cli/show: detangle overloading of params.part for single message
    display
  cli/show: remove unused raw member from show parameters struct
  cli/show: consistently use format_sel for checking the format
  cli/show: use a table for choosing the formatter
  cli/show: rename format_sel to simply format
  cli/show: group --entire-thread option handling into one place
  cli/show: move formatter structs closer to where they're needed
  cli: simplify mime node walk
  cli: do not initialize zero values with designated initializers

 mime-node.c      |  13 ++---
 notmuch-client.h |   1 -
 notmuch-reply.c  |   5 --
 notmuch-show.c   | 157 ++++++++++++++++++++++---------------------------------
 4 files changed, 70 insertions(+), 106 deletions(-)

-- 
2.11.0

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/9] cli/show: detangle overloading of params.part for single message display
  2017-01-06 20:14 [PATCH 0/9] cli/show: refactoring and cleanup Jani Nikula
@ 2017-01-06 20:14 ` Jani Nikula
  2017-03-11 14:06   ` David Bremner
  2017-01-06 20:14 ` [PATCH 2/9] cli/show: remove unused raw member from show parameters struct Jani Nikula
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 11+ messages in thread
From: Jani Nikula @ 2017-01-06 20:14 UTC (permalink / raw)
  To: notmuch

The use of params.part has become rather convoluted in notmuch
show. Add another variable for selecting single message display to
make the code easier to read. No functional changes.
---
 notmuch-show.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index 22fa655ad20d..2f0d142a26e2 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1013,6 +1013,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
     int exclude = EXCLUDE_TRUE;
     int entire_thread = ENTIRE_THREAD_DEFAULT;
+    notmuch_bool_t single_message;
 
     notmuch_opt_desc_t options[] = {
 	{ NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',
@@ -1051,6 +1052,9 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     if (params.crypto.decrypt)
 	params.crypto.verify = TRUE;
 
+    /* specifying a part implies single message display */
+    single_message = params.part >= 0;
+
     if (format_sel == NOTMUCH_FORMAT_NOT_SPECIFIED) {
 	/* if part was requested and format was not specified, use format=raw */
 	if (params.part >= 0)
@@ -1079,10 +1083,8 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 	break;
     case NOTMUCH_FORMAT_RAW:
 	format = &format_raw;
-	/* If --format=raw specified without specifying part, we can only
-	 * output single message, so set part=0 */
-	if (params.part < 0)
-	    params.part = 0;
+	/* raw format only supports single message display */
+	single_message = TRUE;
 	params.raw = TRUE;
 	break;
     }
@@ -1148,9 +1150,9 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     sprinter = format->new_sprinter(config, stdout);
 
     /* If a single message is requested we do not use search_excludes. */
-    if (params.part >= 0)
+    if (single_message) {
 	ret = do_show_single (config, query, format, sprinter, &params);
-    else {
+    } else {
 	/* We always apply set the exclude flag. The
 	 * exclude=true|false option controls whether or not we return
 	 * threads that only match in an excluded message */
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/9] cli/show: remove unused raw member from show parameters struct
  2017-01-06 20:14 [PATCH 0/9] cli/show: refactoring and cleanup Jani Nikula
  2017-01-06 20:14 ` [PATCH 1/9] cli/show: detangle overloading of params.part for single message display Jani Nikula
@ 2017-01-06 20:14 ` Jani Nikula
  2017-01-06 20:14 ` [PATCH 3/9] cli/show: consistently use format_sel for checking the format Jani Nikula
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Jani Nikula @ 2017-01-06 20:14 UTC (permalink / raw)
  To: notmuch

The raw member has been unused since b1130bc71c02 ("show: Convert raw
format to the new self-recursive style, properly support interior
parts"). Good riddance. No functional changes.
---
 notmuch-client.h | 1 -
 notmuch-show.c   | 1 -
 2 files changed, 2 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index d026e6004239..4179d8eac1fc 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -83,7 +83,6 @@ typedef struct notmuch_show_params {
     notmuch_bool_t entire_thread;
     notmuch_bool_t omit_excluded;
     notmuch_bool_t output_body;
-    notmuch_bool_t raw;
     int part;
     notmuch_crypto_t crypto;
     notmuch_bool_t include_html;
diff --git a/notmuch-show.c b/notmuch-show.c
index 2f0d142a26e2..273b5d3ba3ac 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1085,7 +1085,6 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 	format = &format_raw;
 	/* raw format only supports single message display */
 	single_message = TRUE;
-	params.raw = TRUE;
 	break;
     }
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/9] cli/show: consistently use format_sel for checking the format
  2017-01-06 20:14 [PATCH 0/9] cli/show: refactoring and cleanup Jani Nikula
  2017-01-06 20:14 ` [PATCH 1/9] cli/show: detangle overloading of params.part for single message display Jani Nikula
  2017-01-06 20:14 ` [PATCH 2/9] cli/show: remove unused raw member from show parameters struct Jani Nikula
@ 2017-01-06 20:14 ` Jani Nikula
  2017-01-06 20:14 ` [PATCH 4/9] cli/show: use a table for choosing the formatter Jani Nikula
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Jani Nikula @ 2017-01-06 20:14 UTC (permalink / raw)
  To: notmuch

The mixed use of the format pointer and the format selection variables
is confusing. Add more clarity by using format_sel alone. No
functional changes.
---
 notmuch-show.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index 273b5d3ba3ac..b8e45f187360 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1093,7 +1093,8 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     /* Default is entire-thread = FALSE except for format=json and
      * format=sexp. */
     if (entire_thread == ENTIRE_THREAD_DEFAULT) {
-	if (format == &format_json || format == &format_sexp)
+	if (format_sel == NOTMUCH_FORMAT_JSON ||
+	    format_sel == NOTMUCH_FORMAT_SEXP)
 	    entire_thread = ENTIRE_THREAD_TRUE;
 	else
 	    entire_thread = ENTIRE_THREAD_FALSE;
@@ -1104,7 +1105,8 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 	    fprintf (stderr, "Warning: --body=false is incompatible with --part > 0. Disabling.\n");
 	    params.output_body = TRUE;
 	} else {
-	    if (format != &format_json && format != &format_sexp)
+	    if (format_sel != NOTMUCH_FORMAT_JSON &&
+		format_sel != NOTMUCH_FORMAT_SEXP)
 		fprintf (stderr,
 			 "Warning: --body=false only implemented for format=json and format=sexp\n");
 	}
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/9] cli/show: use a table for choosing the formatter
  2017-01-06 20:14 [PATCH 0/9] cli/show: refactoring and cleanup Jani Nikula
                   ` (2 preceding siblings ...)
  2017-01-06 20:14 ` [PATCH 3/9] cli/show: consistently use format_sel for checking the format Jani Nikula
@ 2017-01-06 20:14 ` Jani Nikula
  2017-01-06 20:14 ` [PATCH 5/9] cli/show: rename format_sel to simply format Jani Nikula
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Jani Nikula @ 2017-01-06 20:14 UTC (permalink / raw)
  To: notmuch

Continue detangling format pointer and format selection variables. No
functional changes.
---
 notmuch-show.c | 36 +++++++++++++++---------------------
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index b8e45f187360..93b51008381c 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -978,6 +978,14 @@ enum {
     NOTMUCH_FORMAT_RAW
 };
 
+static const notmuch_show_format_t *formatters[] = {
+    [NOTMUCH_FORMAT_JSON] = &format_json,
+    [NOTMUCH_FORMAT_SEXP] = &format_sexp,
+    [NOTMUCH_FORMAT_TEXT] = &format_text,
+    [NOTMUCH_FORMAT_MBOX] = &format_mbox,
+    [NOTMUCH_FORMAT_RAW] = &format_raw,
+};
+
 enum {
     ENTIRE_THREAD_DEFAULT,
     ENTIRE_THREAD_TRUE,
@@ -997,7 +1005,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     notmuch_query_t *query;
     char *query_string;
     int opt_index, ret;
-    const notmuch_show_format_t *format = &format_text;
+    const notmuch_show_format_t *formatter;
     sprinter_t *sprinter;
     notmuch_show_params_t params = {
 	.part = -1,
@@ -1063,29 +1071,14 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 	    format_sel = NOTMUCH_FORMAT_TEXT;
     }
 
-    switch (format_sel) {
-    case NOTMUCH_FORMAT_JSON:
-	format = &format_json;
-	break;
-    case NOTMUCH_FORMAT_TEXT:
-	format = &format_text;
-	break;
-    case NOTMUCH_FORMAT_SEXP:
-	format = &format_sexp;
-	break;
-    case NOTMUCH_FORMAT_MBOX:
+    if (format_sel == NOTMUCH_FORMAT_MBOX) {
 	if (params.part > 0) {
 	    fprintf (stderr, "Error: specifying parts is incompatible with mbox output format.\n");
 	    return EXIT_FAILURE;
 	}
-
-	format = &format_mbox;
-	break;
-    case NOTMUCH_FORMAT_RAW:
-	format = &format_raw;
+    } else if (format_sel == NOTMUCH_FORMAT_RAW) {
 	/* raw format only supports single message display */
 	single_message = TRUE;
-	break;
     }
 
     notmuch_exit_if_unsupported_format ();
@@ -1148,11 +1141,12 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     }
 
     /* Create structure printer. */
-    sprinter = format->new_sprinter(config, stdout);
+    formatter = formatters[format_sel];
+    sprinter = formatter->new_sprinter(config, stdout);
 
     /* If a single message is requested we do not use search_excludes. */
     if (single_message) {
-	ret = do_show_single (config, query, format, sprinter, &params);
+	ret = do_show_single (config, query, formatter, sprinter, &params);
     } else {
 	/* We always apply set the exclude flag. The
 	 * exclude=true|false option controls whether or not we return
@@ -1171,7 +1165,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 	    params.omit_excluded = FALSE;
 	}
 
-	ret = do_show (config, query, format, sprinter, &params);
+	ret = do_show (config, query, formatter, sprinter, &params);
     }
 
     notmuch_crypto_cleanup (&params.crypto);
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/9] cli/show: rename format_sel to simply format
  2017-01-06 20:14 [PATCH 0/9] cli/show: refactoring and cleanup Jani Nikula
                   ` (3 preceding siblings ...)
  2017-01-06 20:14 ` [PATCH 4/9] cli/show: use a table for choosing the formatter Jani Nikula
@ 2017-01-06 20:14 ` Jani Nikula
  2017-01-06 20:14 ` [PATCH 6/9] cli/show: group --entire-thread option handling into one place Jani Nikula
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Jani Nikula @ 2017-01-06 20:14 UTC (permalink / raw)
  To: notmuch

Now that the format pointer is a temporary variable, and named
formatter, shorten format_sel to format. No functional changes.
---
 notmuch-show.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index 93b51008381c..1032694edcd9 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -1018,13 +1018,13 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 	},
 	.include_html = FALSE
     };
-    int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
+    int format = NOTMUCH_FORMAT_NOT_SPECIFIED;
     int exclude = EXCLUDE_TRUE;
     int entire_thread = ENTIRE_THREAD_DEFAULT;
     notmuch_bool_t single_message;
 
     notmuch_opt_desc_t options[] = {
-	{ NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',
+	{ NOTMUCH_OPT_KEYWORD, &format, "format", 'f',
 	  (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
 				  { "text", NOTMUCH_FORMAT_TEXT },
 				  { "sexp", NOTMUCH_FORMAT_SEXP },
@@ -1063,20 +1063,20 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     /* specifying a part implies single message display */
     single_message = params.part >= 0;
 
-    if (format_sel == NOTMUCH_FORMAT_NOT_SPECIFIED) {
+    if (format == NOTMUCH_FORMAT_NOT_SPECIFIED) {
 	/* if part was requested and format was not specified, use format=raw */
 	if (params.part >= 0)
-	    format_sel = NOTMUCH_FORMAT_RAW;
+	    format = NOTMUCH_FORMAT_RAW;
 	else
-	    format_sel = NOTMUCH_FORMAT_TEXT;
+	    format = NOTMUCH_FORMAT_TEXT;
     }
 
-    if (format_sel == NOTMUCH_FORMAT_MBOX) {
+    if (format == NOTMUCH_FORMAT_MBOX) {
 	if (params.part > 0) {
 	    fprintf (stderr, "Error: specifying parts is incompatible with mbox output format.\n");
 	    return EXIT_FAILURE;
 	}
-    } else if (format_sel == NOTMUCH_FORMAT_RAW) {
+    } else if (format == NOTMUCH_FORMAT_RAW) {
 	/* raw format only supports single message display */
 	single_message = TRUE;
     }
@@ -1086,8 +1086,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     /* Default is entire-thread = FALSE except for format=json and
      * format=sexp. */
     if (entire_thread == ENTIRE_THREAD_DEFAULT) {
-	if (format_sel == NOTMUCH_FORMAT_JSON ||
-	    format_sel == NOTMUCH_FORMAT_SEXP)
+	if (format == NOTMUCH_FORMAT_JSON || format == NOTMUCH_FORMAT_SEXP)
 	    entire_thread = ENTIRE_THREAD_TRUE;
 	else
 	    entire_thread = ENTIRE_THREAD_FALSE;
@@ -1098,15 +1097,14 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 	    fprintf (stderr, "Warning: --body=false is incompatible with --part > 0. Disabling.\n");
 	    params.output_body = TRUE;
 	} else {
-	    if (format_sel != NOTMUCH_FORMAT_JSON &&
-		format_sel != NOTMUCH_FORMAT_SEXP)
+	    if (format != NOTMUCH_FORMAT_JSON && format != NOTMUCH_FORMAT_SEXP)
 		fprintf (stderr,
 			 "Warning: --body=false only implemented for format=json and format=sexp\n");
 	}
     }
 
     if (params.include_html &&
-        (format_sel != NOTMUCH_FORMAT_JSON && format_sel != NOTMUCH_FORMAT_SEXP)) {
+        (format != NOTMUCH_FORMAT_JSON && format != NOTMUCH_FORMAT_SEXP)) {
 	fprintf (stderr, "Warning: --include-html only implemented for format=json and format=sexp\n");
     }
 
@@ -1141,7 +1139,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     }
 
     /* Create structure printer. */
-    formatter = formatters[format_sel];
+    formatter = formatters[format];
     sprinter = formatter->new_sprinter(config, stdout);
 
     /* If a single message is requested we do not use search_excludes. */
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 6/9] cli/show: group --entire-thread option handling into one place
  2017-01-06 20:14 [PATCH 0/9] cli/show: refactoring and cleanup Jani Nikula
                   ` (4 preceding siblings ...)
  2017-01-06 20:14 ` [PATCH 5/9] cli/show: rename format_sel to simply format Jani Nikula
@ 2017-01-06 20:14 ` Jani Nikula
  2017-01-06 20:14 ` [PATCH 7/9] cli/show: move formatter structs closer to where they're needed Jani Nikula
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Jani Nikula @ 2017-01-06 20:14 UTC (permalink / raw)
  To: notmuch

The --entire-thread option handling is split around, making the logic
harder to follow than necessary. Put it in one place. While at it,
make the true/false values match notmuch_bool_t values for
simplicity. No functional changes.
---
 notmuch-show.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index 1032694edcd9..bddcb190e4cf 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -987,9 +987,9 @@ static const notmuch_show_format_t *formatters[] = {
 };
 
 enum {
-    ENTIRE_THREAD_DEFAULT,
-    ENTIRE_THREAD_TRUE,
-    ENTIRE_THREAD_FALSE,
+    ENTIRE_THREAD_DEFAULT = -1,
+    ENTIRE_THREAD_FALSE = FALSE,
+    ENTIRE_THREAD_TRUE = TRUE,
 };
 
 /* The following is to allow future options to be added more easily */
@@ -1087,9 +1087,11 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
      * format=sexp. */
     if (entire_thread == ENTIRE_THREAD_DEFAULT) {
 	if (format == NOTMUCH_FORMAT_JSON || format == NOTMUCH_FORMAT_SEXP)
-	    entire_thread = ENTIRE_THREAD_TRUE;
+	    params.entire_thread = TRUE;
 	else
-	    entire_thread = ENTIRE_THREAD_FALSE;
+	    params.entire_thread = FALSE;
+    } else {
+	params.entire_thread = entire_thread;
     }
 
     if (!params.output_body) {
@@ -1108,11 +1110,6 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 	fprintf (stderr, "Warning: --include-html only implemented for format=json and format=sexp\n");
     }
 
-    if (entire_thread == ENTIRE_THREAD_TRUE)
-	params.entire_thread = TRUE;
-    else
-	params.entire_thread = FALSE;
-
     query_string = query_string_from_args (config, argc-opt_index, argv+opt_index);
     if (query_string == NULL) {
 	fprintf (stderr, "Out of memory\n");
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 7/9] cli/show: move formatter structs closer to where they're needed
  2017-01-06 20:14 [PATCH 0/9] cli/show: refactoring and cleanup Jani Nikula
                   ` (5 preceding siblings ...)
  2017-01-06 20:14 ` [PATCH 6/9] cli/show: group --entire-thread option handling into one place Jani Nikula
@ 2017-01-06 20:14 ` Jani Nikula
  2017-01-06 20:14 ` [PATCH 8/9] cli: simplify mime node walk Jani Nikula
  2017-01-06 20:14 ` [PATCH 9/9] cli: do not initialize zero values with designated initializers Jani Nikula
  8 siblings, 0 replies; 11+ messages in thread
From: Jani Nikula @ 2017-01-06 20:14 UTC (permalink / raw)
  To: notmuch

The formatter structs are only needed for the formatter array
initialization. Move them closer to use. This also lets us drop some
forward declarations. No functional changes.
---
 notmuch-show.c | 67 ++++++++++++++++++++++------------------------------------
 1 file changed, 25 insertions(+), 42 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index bddcb190e4cf..cd16cbf68fe0 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -22,48 +22,6 @@
 #include "gmime-filter-reply.h"
 #include "sprinter.h"
 
-static notmuch_status_t
-format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
-		  int indent, const notmuch_show_params_t *params);
-
-static const notmuch_show_format_t format_text = {
-    .new_sprinter = sprinter_text_create,
-    .part = format_part_text,
-};
-
-static notmuch_status_t
-format_part_sprinter_entry (const void *ctx, sprinter_t *sp, mime_node_t *node,
-			    int indent, const notmuch_show_params_t *params);
-
-static const notmuch_show_format_t format_json = {
-    .new_sprinter = sprinter_json_create,
-    .part = format_part_sprinter_entry,
-};
-
-static const notmuch_show_format_t format_sexp = {
-    .new_sprinter = sprinter_sexp_create,
-    .part = format_part_sprinter_entry,
-};
-
-static notmuch_status_t
-format_part_mbox (const void *ctx, sprinter_t *sp, mime_node_t *node,
-		  int indent, const notmuch_show_params_t *params);
-
-static const notmuch_show_format_t format_mbox = {
-    .new_sprinter = sprinter_text_create,
-    .part = format_part_mbox,
-};
-
-static notmuch_status_t
-format_part_raw (unused (const void *ctx), sprinter_t *sp, mime_node_t *node,
-		 unused (int indent),
-		 unused (const notmuch_show_params_t *params));
-
-static const notmuch_show_format_t format_raw = {
-    .new_sprinter = sprinter_text_create,
-    .part = format_part_raw,
-};
-
 static const char *
 _get_tags_as_string (const void *ctx, notmuch_message_t *message)
 {
@@ -978,6 +936,31 @@ enum {
     NOTMUCH_FORMAT_RAW
 };
 
+static const notmuch_show_format_t format_json = {
+    .new_sprinter = sprinter_json_create,
+    .part = format_part_sprinter_entry,
+};
+
+static const notmuch_show_format_t format_sexp = {
+    .new_sprinter = sprinter_sexp_create,
+    .part = format_part_sprinter_entry,
+};
+
+static const notmuch_show_format_t format_text = {
+    .new_sprinter = sprinter_text_create,
+    .part = format_part_text,
+};
+
+static const notmuch_show_format_t format_mbox = {
+    .new_sprinter = sprinter_text_create,
+    .part = format_part_mbox,
+};
+
+static const notmuch_show_format_t format_raw = {
+    .new_sprinter = sprinter_text_create,
+    .part = format_part_raw,
+};
+
 static const notmuch_show_format_t *formatters[] = {
     [NOTMUCH_FORMAT_JSON] = &format_json,
     [NOTMUCH_FORMAT_SEXP] = &format_sexp,
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 8/9] cli: simplify mime node walk
  2017-01-06 20:14 [PATCH 0/9] cli/show: refactoring and cleanup Jani Nikula
                   ` (6 preceding siblings ...)
  2017-01-06 20:14 ` [PATCH 7/9] cli/show: move formatter structs closer to where they're needed Jani Nikula
@ 2017-01-06 20:14 ` Jani Nikula
  2017-01-06 20:14 ` [PATCH 9/9] cli: do not initialize zero values with designated initializers Jani Nikula
  8 siblings, 0 replies; 11+ messages in thread
From: Jani Nikula @ 2017-01-06 20:14 UTC (permalink / raw)
  To: notmuch

The function is more straighforward to read when it's clear that the
only non-NULL return is at one place. No functional changes.
---
 mime-node.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/mime-node.c b/mime-node.c
index c9b82330f6e0..f719422ec678 100644
--- a/mime-node.c
+++ b/mime-node.c
@@ -322,20 +322,21 @@ mime_node_child (mime_node_t *parent, int child)
 static mime_node_t *
 _mime_node_seek_dfs_walk (mime_node_t *node, int *n)
 {
-    mime_node_t *ret = NULL;
     int i;
 
     if (*n == 0)
 	return node;
 
     *n -= 1;
-    for (i = 0; i < node->nchildren && !ret; i++) {
+    for (i = 0; i < node->nchildren; i++) {
 	mime_node_t *child = mime_node_child (node, i);
-	ret = _mime_node_seek_dfs_walk (child, n);
-	if (!ret)
-	    talloc_free (child);
+	mime_node_t *ret = _mime_node_seek_dfs_walk (child, n);
+	if (ret)
+	    return ret;
+
+	talloc_free (child);
     }
-    return ret;
+    return NULL;
 }
 
 mime_node_t *
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 9/9] cli: do not initialize zero values with designated initializers
  2017-01-06 20:14 [PATCH 0/9] cli/show: refactoring and cleanup Jani Nikula
                   ` (7 preceding siblings ...)
  2017-01-06 20:14 ` [PATCH 8/9] cli: simplify mime node walk Jani Nikula
@ 2017-01-06 20:14 ` Jani Nikula
  8 siblings, 0 replies; 11+ messages in thread
From: Jani Nikula @ 2017-01-06 20:14 UTC (permalink / raw)
  To: notmuch

Let the language initialize defaults to zero when some values are
initialized to non-zero values. No functional changes.
---
 notmuch-reply.c | 5 -----
 notmuch-show.c  | 6 ------
 2 files changed, 11 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 8c894974485d..166a59467eec 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -701,11 +701,6 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
     int opt_index;
     notmuch_show_params_t params = {
 	.part = -1,
-	.crypto = {
-	    .verify = FALSE,
-	    .decrypt = FALSE,
-	    .gpgpath = NULL
-	}
     };
     int format = FORMAT_DEFAULT;
     int reply_all = TRUE;
diff --git a/notmuch-show.c b/notmuch-show.c
index cd16cbf68fe0..7fd5e9bc46c6 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -994,12 +994,6 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
 	.part = -1,
 	.omit_excluded = TRUE,
 	.output_body = TRUE,
-	.crypto = {
-	    .verify = FALSE,
-	    .decrypt = FALSE,
-	    .gpgpath = NULL
-	},
-	.include_html = FALSE
     };
     int format = NOTMUCH_FORMAT_NOT_SPECIFIED;
     int exclude = EXCLUDE_TRUE;
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/9] cli/show: detangle overloading of params.part for single message display
  2017-01-06 20:14 ` [PATCH 1/9] cli/show: detangle overloading of params.part for single message display Jani Nikula
@ 2017-03-11 14:06   ` David Bremner
  0 siblings, 0 replies; 11+ messages in thread
From: David Bremner @ 2017-03-11 14:06 UTC (permalink / raw)
  To: Jani Nikula, notmuch

Jani Nikula <jani@nikula.org> writes:

> The use of params.part has become rather convoluted in notmuch
> show. Add another variable for selecting single message display to
> make the code easier to read. No functional changes.

Series pushed to master.

d

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-03-11 14:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-06 20:14 [PATCH 0/9] cli/show: refactoring and cleanup Jani Nikula
2017-01-06 20:14 ` [PATCH 1/9] cli/show: detangle overloading of params.part for single message display Jani Nikula
2017-03-11 14:06   ` David Bremner
2017-01-06 20:14 ` [PATCH 2/9] cli/show: remove unused raw member from show parameters struct Jani Nikula
2017-01-06 20:14 ` [PATCH 3/9] cli/show: consistently use format_sel for checking the format Jani Nikula
2017-01-06 20:14 ` [PATCH 4/9] cli/show: use a table for choosing the formatter Jani Nikula
2017-01-06 20:14 ` [PATCH 5/9] cli/show: rename format_sel to simply format Jani Nikula
2017-01-06 20:14 ` [PATCH 6/9] cli/show: group --entire-thread option handling into one place Jani Nikula
2017-01-06 20:14 ` [PATCH 7/9] cli/show: move formatter structs closer to where they're needed Jani Nikula
2017-01-06 20:14 ` [PATCH 8/9] cli: simplify mime node walk Jani Nikula
2017-01-06 20:14 ` [PATCH 9/9] cli: do not initialize zero values with designated initializers Jani Nikula

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).