From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Subject: [PATCH 1/2] cli: abstract database dumping from the dump command
Date: Tue, 25 Mar 2014 19:07:49 +0200 [thread overview]
Message-ID: <8fce111b04768fda5594a0c1883d780183d19cda.1395767165.git.jani@nikula.org> (raw)
In-Reply-To: <cover.1395767165.git.jani@nikula.org>
In-Reply-To: <cover.1395767165.git.jani@nikula.org>
No functional changes, except for slight improvement in error
handling.
---
notmuch-dump.c | 107 ++++++++++++++++++++++++++++++++-------------------------
1 file changed, 61 insertions(+), 46 deletions(-)
diff --git a/notmuch-dump.c b/notmuch-dump.c
index 158142f55b49..179e2e97bf61 100644
--- a/notmuch-dump.c
+++ b/notmuch-dump.c
@@ -22,56 +22,17 @@
#include "dump-restore-private.h"
#include "string-util.h"
-int
-notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
+static int
+database_dump_file (notmuch_database_t *notmuch, FILE *output,
+ const char *query_str, int output_format)
{
- notmuch_database_t *notmuch;
notmuch_query_t *query;
- FILE *output = stdout;
notmuch_messages_t *messages;
notmuch_message_t *message;
notmuch_tags_t *tags;
- const char *query_str = "";
-
- if (notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
- return EXIT_FAILURE;
-
- char *output_file_name = NULL;
- int opt_index;
-
- int output_format = DUMP_FORMAT_BATCH_TAG;
- notmuch_opt_desc_t options[] = {
- { NOTMUCH_OPT_KEYWORD, &output_format, "format", 'f',
- (notmuch_keyword_t []){ { "sup", DUMP_FORMAT_SUP },
- { "batch-tag", DUMP_FORMAT_BATCH_TAG },
- { 0, 0 } } },
- { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0 },
- { 0, 0, 0, 0, 0 }
- };
-
- opt_index = parse_arguments (argc, argv, options, 1);
- if (opt_index < 0)
- return EXIT_FAILURE;
-
- if (output_file_name) {
- output = fopen (output_file_name, "w");
- if (output == NULL) {
- fprintf (stderr, "Error opening %s for writing: %s\n",
- output_file_name, strerror (errno));
- return EXIT_FAILURE;
- }
- }
-
-
- if (opt_index < argc) {
- query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);
- if (query_str == NULL) {
- fprintf (stderr, "Out of memory.\n");
- return EXIT_FAILURE;
- }
- }
+ if (! query_str)
+ query_str = "";
query = notmuch_query_create (notmuch, query_str);
if (query == NULL) {
@@ -149,11 +110,65 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
notmuch_message_destroy (message);
}
+ notmuch_query_destroy (query);
+
+ return EXIT_SUCCESS;
+}
+
+int
+notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
+{
+ notmuch_database_t *notmuch;
+ FILE *output = stdout;
+ const char *query_str = NULL;
+ int ret;
+
+ if (notmuch_database_open (notmuch_config_get_database_path (config),
+ NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
+ return EXIT_FAILURE;
+
+ char *output_file_name = NULL;
+ int opt_index;
+
+ int output_format = DUMP_FORMAT_BATCH_TAG;
+
+ notmuch_opt_desc_t options[] = {
+ { NOTMUCH_OPT_KEYWORD, &output_format, "format", 'f',
+ (notmuch_keyword_t []){ { "sup", DUMP_FORMAT_SUP },
+ { "batch-tag", DUMP_FORMAT_BATCH_TAG },
+ { 0, 0 } } },
+ { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0 },
+ { 0, 0, 0, 0, 0 }
+ };
+
+ opt_index = parse_arguments (argc, argv, options, 1);
+ if (opt_index < 0)
+ return EXIT_FAILURE;
+
+ if (output_file_name) {
+ output = fopen (output_file_name, "w");
+ if (output == NULL) {
+ fprintf (stderr, "Error opening %s for writing: %s\n",
+ output_file_name, strerror (errno));
+ return EXIT_FAILURE;
+ }
+ }
+
+
+ if (opt_index < argc) {
+ query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);
+ if (query_str == NULL) {
+ fprintf (stderr, "Out of memory.\n");
+ return EXIT_FAILURE;
+ }
+ }
+
+ ret = database_dump_file (notmuch, output, query_str, output_format);
+
if (output != stdout)
fclose (output);
- notmuch_query_destroy (query);
notmuch_database_destroy (notmuch);
- return EXIT_SUCCESS;
+ return ret;
}
--
1.9.0
next prev parent reply other threads:[~2014-03-25 17:08 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-25 17:07 [PATCH 0/2] cli: notmuch dump abstractions Jani Nikula
2014-03-25 17:07 ` Jani Nikula [this message]
2014-03-25 17:07 ` [PATCH 2/2] cli: abstract dump file open from the dump command Jani Nikula
2014-03-25 17:48 ` [PATCH v2] " Jani Nikula
2014-03-26 22:01 ` [PATCH 0/2] cli: notmuch dump abstractions Mark Walters
2014-03-29 1:20 ` [PATCH] RFC: impliment gzipped output for notmuch dump David Bremner
2014-03-29 7:16 ` Tomi Ollila
2014-03-29 9:25 ` Jani Nikula
2014-03-29 12:29 ` David Bremner
2014-03-29 13:02 ` Jani Nikula
2014-03-29 16:25 ` David Bremner
2014-03-29 13:46 ` [PATCH] dump: support gzipped output David Bremner
2014-03-29 18:16 ` David Bremner
2014-03-29 18:16 ` [Patch v2 1/3] dump: support gzipped output David Bremner
2014-03-29 18:16 ` [Patch v2 2/3] util: add gzreadline David Bremner
2014-03-30 8:30 ` Tomi Ollila
2014-03-30 11:23 ` [Patch v3] " David Bremner
2014-03-30 12:45 ` Tomi Ollila
2014-03-30 14:37 ` David Bremner
2014-03-30 16:13 ` Tomi Ollila
2014-03-30 11:03 ` [Patch v2 2/3] " David Bremner
2014-03-29 18:16 ` [Patch v2 3/3] restore: transparently support gzipped input David Bremner
2014-03-30 22:33 ` [PATCH 0/2] cli: notmuch dump abstractions David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8fce111b04768fda5594a0c1883d780183d19cda.1395767165.git.jani@nikula.org \
--to=jani@nikula.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).