[PATCH v2] cli: abstract dump file open from the dump command
authorJani Nikula <jani@nikula.org>
Tue, 25 Mar 2014 17:48:57 +0000 (19:48 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:00:59 +0000 (10:00 -0800)
f0/e438629f483dc7662f7143d51c4407eb3c0a9a [new file with mode: 0644]

diff --git a/f0/e438629f483dc7662f7143d51c4407eb3c0a9a b/f0/e438629f483dc7662f7143d51c4407eb3c0a9a
new file mode 100644 (file)
index 0000000..b37c880
--- /dev/null
@@ -0,0 +1,217 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 3873F431FBF\r
+       for <notmuch@notmuchmail.org>; Tue, 25 Mar 2014 10:49:08 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 4XnOq63NSIqT for <notmuch@notmuchmail.org>;\r
+       Tue, 25 Mar 2014 10:49:02 -0700 (PDT)\r
+Received: from mail-ee0-f42.google.com (mail-ee0-f42.google.com\r
+ [74.125.83.42])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ 7DD73431FBD   for <notmuch@notmuchmail.org>; Tue, 25 Mar 2014 10:49:02 -0700\r
+ (PDT)\r
+Received: by mail-ee0-f42.google.com with SMTP id d17so743323eek.29\r
+       for <notmuch@notmuchmail.org>; Tue, 25 Mar 2014 10:49:00 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=1e100.net; s=20130820;\r
+       h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+       :references;\r
+       bh=Xgc2UWmTFhQZVkKmF56y2nz94HBdnmVQXwlfnWA7/Ik=;\r
+       b=CsKdcx1WL1EXL2izviNw42Zxiyk7FUYU4k6VHsVtGKhuDd4aCEaOHAgUb6gN8VVFsh\r
+       tgt3W/1Nkf0XQQWi1H/ir9trinXIQam9Me+vs/q9ghqKYelvP+iBBiyoGQVkYiW4wazg\r
+       YSxlbQJaXsxeKiAIVXVaD9+Sd0RnQla8JwN8XsmwgWMnxMyWFHs75XE8MuNMoLbAwkzW\r
+       MZdqMQrWgJZI4eLoQ0P7y6Tlep06lxfhWIqllwb/huO02/0bI/cFNK+mn6grGgTiJzXG\r
+       klb0xOR06iGeT79WUDU+sIzFm1njTqMXc+gBLqtM0SwuGghI7JzNFxya8mvw+3/TBtcP\r
+       HgRA==\r
+X-Gm-Message-State:\r
+ ALoCoQkzk9e+GuLEqym9xaIMH6Oz1a0uqTZ9NZ2f6R/Z6MDxYE2oWsPVjNv81z85VG8+XYfBVbk0\r
+X-Received: by 10.14.198.197 with SMTP id v45mr71281009een.9.1395769739874;\r
+       Tue, 25 Mar 2014 10:48:59 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.\r
+       [88.195.111.91])\r
+       by mx.google.com with ESMTPSA id m1sm41573676een.7.2014.03.25.10.48.58\r
+       for <multiple recipients>\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Tue, 25 Mar 2014 10:48:58 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2] cli: abstract dump file open from the dump command\r
+Date: Tue, 25 Mar 2014 19:48:57 +0200\r
+Message-Id: <1395769737-14598-1-git-send-email-jani@nikula.org>\r
+X-Mailer: git-send-email 1.9.0\r
+In-Reply-To:\r
+ <92929cc512b9e9cd5ccb7d4e537671ce84de514f.1395767165.git.jani@nikula.org>\r
+References:\r
+ <92929cc512b9e9cd5ccb7d4e537671ce84de514f.1395767165.git.jani@nikula.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 25 Mar 2014 17:49:08 -0000\r
+\r
+Also expose the dump function to the rest of notmuch. No functional\r
+changes, except for slight improvement in error handling.\r
+---\r
+ dump-restore-private.h | 13 -------------\r
+ notmuch-client.h       | 11 +++++++++++\r
+ notmuch-dump.c         | 47 +++++++++++++++++++++++++++++++----------------\r
+ notmuch-restore.c      |  2 +-\r
+ 4 files changed, 43 insertions(+), 30 deletions(-)\r
+ delete mode 100644 dump-restore-private.h\r
+\r
+diff --git a/dump-restore-private.h b/dump-restore-private.h\r
+deleted file mode 100644\r
+index 896a00430986..000000000000\r
+--- a/dump-restore-private.h\r
++++ /dev/null\r
+@@ -1,13 +0,0 @@\r
+-#ifndef DUMP_RESTORE_PRIVATE_H\r
+-#define DUMP_RESTORE_PRIVATE_H\r
+-\r
+-#include "hex-escape.h"\r
+-#include "command-line-arguments.h"\r
+-\r
+-typedef enum dump_formats {\r
+-    DUMP_FORMAT_AUTO,\r
+-    DUMP_FORMAT_BATCH_TAG,\r
+-    DUMP_FORMAT_SUP\r
+-} dump_format_t;\r
+-\r
+-#endif\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index 278b498a246a..d11064824ddf 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -441,5 +441,16 @@ mime_node_child (mime_node_t *parent, int child);\r
+ mime_node_t *\r
+ mime_node_seek_dfs (mime_node_t *node, int n);\r
\r
++typedef enum dump_formats {\r
++    DUMP_FORMAT_AUTO,\r
++    DUMP_FORMAT_BATCH_TAG,\r
++    DUMP_FORMAT_SUP\r
++} dump_format_t;\r
++\r
++int\r
++notmuch_database_dump (notmuch_database_t *notmuch,\r
++                     const char *output_file_name,\r
++                     const char *query_str, dump_format_t output_format);\r
++\r
+ #include "command-line-arguments.h"\r
+ #endif\r
+diff --git a/notmuch-dump.c b/notmuch-dump.c\r
+index 179e2e97bf61..21702d793bcf 100644\r
+--- a/notmuch-dump.c\r
++++ b/notmuch-dump.c\r
+@@ -19,7 +19,7 @@\r
+  */\r
\r
+ #include "notmuch-client.h"\r
+-#include "dump-restore-private.h"\r
++#include "hex-escape.h"\r
+ #include "string-util.h"\r
\r
+ static int\r
+@@ -115,11 +115,38 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output,\r
+     return EXIT_SUCCESS;\r
+ }\r
\r
++/* Dump database into output_file_name if it's non-NULL, stdout\r
++ * otherwise.\r
++ */\r
++int\r
++notmuch_database_dump (notmuch_database_t *notmuch,\r
++                     const char *output_file_name,\r
++                     const char *query_str, dump_format_t output_format)\r
++{\r
++    FILE *output = stdout;\r
++    int ret;\r
++\r
++    if (output_file_name) {\r
++      output = fopen (output_file_name, "w");\r
++      if (output == NULL) {\r
++          fprintf (stderr, "Error opening %s for writing: %s\n",\r
++                   output_file_name, strerror (errno));\r
++          return EXIT_FAILURE;\r
++      }\r
++    }\r
++\r
++    ret = database_dump_file (notmuch, output, query_str, output_format);\r
++\r
++    if (output != stdout)\r
++      fclose (output);\r
++\r
++    return ret;\r
++}\r
++\r
+ int\r
+ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
+ {\r
+     notmuch_database_t *notmuch;\r
+-    FILE *output = stdout;\r
+     const char *query_str = NULL;\r
+     int ret;\r
\r
+@@ -145,16 +172,6 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
+     if (opt_index < 0)\r
+       return EXIT_FAILURE;\r
\r
+-    if (output_file_name) {\r
+-      output = fopen (output_file_name, "w");\r
+-      if (output == NULL) {\r
+-          fprintf (stderr, "Error opening %s for writing: %s\n",\r
+-                   output_file_name, strerror (errno));\r
+-          return EXIT_FAILURE;\r
+-      }\r
+-    }\r
+-\r
+-\r
+     if (opt_index < argc) {\r
+       query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);\r
+       if (query_str == NULL) {\r
+@@ -163,10 +180,8 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
+       }\r
+     }\r
\r
+-    ret = database_dump_file (notmuch, output, query_str, output_format);\r
+-\r
+-    if (output != stdout)\r
+-      fclose (output);\r
++    ret = notmuch_database_dump (notmuch, output_file_name, query_str,\r
++                               output_format);\r
\r
+     notmuch_database_destroy (notmuch);\r
\r
+diff --git a/notmuch-restore.c b/notmuch-restore.c\r
+index f23ab983a93d..c54d51328b51 100644\r
+--- a/notmuch-restore.c\r
++++ b/notmuch-restore.c\r
+@@ -19,7 +19,7 @@\r
+  */\r
\r
+ #include "notmuch-client.h"\r
+-#include "dump-restore-private.h"\r
++#include "hex-escape.h"\r
+ #include "tag-util.h"\r
+ #include "string-util.h"\r
\r
+-- \r
+1.9.0\r
+\r