unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] cli: use designated initializer to initialize add_files_state
@ 2015-09-25 18:47 Jani Nikula
  2015-09-25 19:19 ` Tomi Ollila
  2015-09-29 11:27 ` David Bremner
  0 siblings, 2 replies; 3+ messages in thread
From: Jani Nikula @ 2015-09-25 18:47 UTC (permalink / raw)
  To: notmuch

The side effect is that all of add_files_state will be initialized to
zero, removing any lingering doubt that some of it might not be
initialized. It's not a small struct, and the initialization is
scattered around a bit, so this makes the code more readable.
---
 notmuch-new.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index 33645349cd5f..442a2f0ae288 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -933,7 +933,11 @@ int
 notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
 {
     notmuch_database_t *notmuch;
-    add_files_state_t add_files_state;
+    add_files_state_t add_files_state = {
+	.verbosity = VERBOSITY_NORMAL,
+	.debug = FALSE,
+	.output_is_a_tty = isatty (fileno (stdout)),
+    };
     struct timeval tv_start;
     int ret = 0;
     struct stat st;
@@ -948,10 +952,6 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
     notmuch_bool_t quiet = FALSE, verbose = FALSE;
     notmuch_status_t status;
 
-    add_files_state.verbosity = VERBOSITY_NORMAL;
-    add_files_state.debug = FALSE;
-    add_files_state.output_is_a_tty = isatty (fileno (stdout));
-
     notmuch_opt_desc_t options[] = {
 	{ NOTMUCH_OPT_BOOLEAN,  &quiet, "quiet", 'q', 0 },
 	{ NOTMUCH_OPT_BOOLEAN,  &verbose, "verbose", 'v', 0 },
@@ -1086,9 +1086,6 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
     talloc_free (dot_notmuch_path);
     dot_notmuch_path = NULL;
 
-    add_files_state.processed_files = 0;
-    add_files_state.added_messages = 0;
-    add_files_state.removed_messages = add_files_state.renamed_messages = 0;
     gettimeofday (&add_files_state.tv_start, NULL);
 
     add_files_state.removed_files = _filename_list_create (config);
-- 
2.1.4

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

* Re: [PATCH] cli: use designated initializer to initialize add_files_state
  2015-09-25 18:47 [PATCH] cli: use designated initializer to initialize add_files_state Jani Nikula
@ 2015-09-25 19:19 ` Tomi Ollila
  2015-09-29 11:27 ` David Bremner
  1 sibling, 0 replies; 3+ messages in thread
From: Tomi Ollila @ 2015-09-25 19:19 UTC (permalink / raw)
  To: Jani Nikula, notmuch

On Fri, Sep 25 2015, Jani Nikula <jani@nikula.org> wrote:

> The side effect is that all of add_files_state will be initialized to
> zero, removing any lingering doubt that some of it might not be
> initialized. It's not a small struct, and the initialization is
> scattered around a bit, so this makes the code more readable.

LGTM. Should I test ? ;/

Tomi


> ---
>  notmuch-new.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/notmuch-new.c b/notmuch-new.c
> index 33645349cd5f..442a2f0ae288 100644
> --- a/notmuch-new.c
> +++ b/notmuch-new.c
> @@ -933,7 +933,11 @@ int
>  notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
>  {
>      notmuch_database_t *notmuch;
> -    add_files_state_t add_files_state;
> +    add_files_state_t add_files_state = {
> +	.verbosity = VERBOSITY_NORMAL,
> +	.debug = FALSE,
> +	.output_is_a_tty = isatty (fileno (stdout)),
> +    };
>      struct timeval tv_start;
>      int ret = 0;
>      struct stat st;
> @@ -948,10 +952,6 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
>      notmuch_bool_t quiet = FALSE, verbose = FALSE;
>      notmuch_status_t status;
>  
> -    add_files_state.verbosity = VERBOSITY_NORMAL;
> -    add_files_state.debug = FALSE;
> -    add_files_state.output_is_a_tty = isatty (fileno (stdout));
> -
>      notmuch_opt_desc_t options[] = {
>  	{ NOTMUCH_OPT_BOOLEAN,  &quiet, "quiet", 'q', 0 },
>  	{ NOTMUCH_OPT_BOOLEAN,  &verbose, "verbose", 'v', 0 },
> @@ -1086,9 +1086,6 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
>      talloc_free (dot_notmuch_path);
>      dot_notmuch_path = NULL;
>  
> -    add_files_state.processed_files = 0;
> -    add_files_state.added_messages = 0;
> -    add_files_state.removed_messages = add_files_state.renamed_messages = 0;
>      gettimeofday (&add_files_state.tv_start, NULL);
>  
>      add_files_state.removed_files = _filename_list_create (config);
> -- 
> 2.1.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

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

* Re: [PATCH] cli: use designated initializer to initialize add_files_state
  2015-09-25 18:47 [PATCH] cli: use designated initializer to initialize add_files_state Jani Nikula
  2015-09-25 19:19 ` Tomi Ollila
@ 2015-09-29 11:27 ` David Bremner
  1 sibling, 0 replies; 3+ messages in thread
From: David Bremner @ 2015-09-29 11:27 UTC (permalink / raw)
  To: Jani Nikula, notmuch

Jani Nikula <jani@nikula.org> writes:

> The side effect is that all of add_files_state will be initialized to
> zero, removing any lingering doubt that some of it might not be
> initialized. It's not a small struct, and the initialization is
> scattered around a bit, so this makes the code more readable.

pushed

d

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

end of thread, other threads:[~2015-09-29 11:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-25 18:47 [PATCH] cli: use designated initializer to initialize add_files_state Jani Nikula
2015-09-25 19:19 ` Tomi Ollila
2015-09-29 11:27 ` David Bremner

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).