[PATCH v3 08/20] tag-util: move out 'tag' command-line checks

Jani Nikula jani at nikula.org
Mon Jan 21 10:05:00 PST 2013


On Sun, 20 Jan 2013, Peter Wang <novalazy at gmail.com> wrote:
> parse_tag_command_line checked for two error conditions which are
> specific to the 'tag' command.  It can be reused for the notmuch
> 'insert' command if we move the checks out, into notmuch-tag.c.

*three* error conditions, two of which are specific to notmuch tag. See
 below.

> ---
>  notmuch-tag.c | 10 ++++++++++
>  tag-util.c    | 10 ----------
>  2 files changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/notmuch-tag.c b/notmuch-tag.c
> index d9daf8f..a901dad 100644
> --- a/notmuch-tag.c
> +++ b/notmuch-tag.c
> @@ -234,6 +234,16 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
>  	if (parse_tag_command_line (ctx, argc - opt_index, argv + opt_index,
>  				    &query_string, tag_ops))
>  	    return 1;
> +
> +	if (tag_op_list_size (tag_ops) == 0) {
> +	    fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n");
> +	    return 1;
> +	}
> +
> +	if (*query_string == '\0') {
> +	    fprintf (stderr, "Error: notmuch tag requires at least one search term.\n");
> +	    return 1;
> +	}
>      }
>  
>      config = notmuch_config_open (ctx, NULL, NULL);
> diff --git a/tag-util.c b/tag-util.c
> index 3f9da05..41f2c09 100644
> --- a/tag-util.c
> +++ b/tag-util.c
> @@ -186,18 +186,8 @@ parse_tag_command_line (void *ctx, int argc, char **argv,
>  	tag_op_list_append (tag_ops, argv[i] + 1, is_remove);
>      }
>  
> -    if (tag_op_list_size (tag_ops) == 0) {
> -	fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n");
> -	return TAG_PARSE_INVALID;
> -    }
> -
>      *query_str = query_string_from_args (ctx, argc - i, &argv[i]);
>  
> -    if (*query_str == NULL || **query_str == '\0') {

You must leave *query_str == NULL check intact here. Fix the error
message to be about allocation failure and drop the reference to notmuch
tag while at it.

Otherwise LGTM.

> -	fprintf (stderr, "Error: notmuch tag requires at least one search term.\n");
> -	return TAG_PARSE_INVALID;
> -    }
> -
>      return TAG_PARSE_SUCCESS;
>  }
>  
> -- 
> 1.7.12.1
>
> _______________________________________________
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


More information about the notmuch mailing list