--- /dev/null
+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 2CDF6431FBF\r
+ for <notmuch@notmuchmail.org>; Tue, 25 Mar 2014 10:08:03 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\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 RU+4LbszokoC for <notmuch@notmuchmail.org>;\r
+ Tue, 25 Mar 2014 10:07:59 -0700 (PDT)\r
+Received: from mail-ee0-f52.google.com (mail-ee0-f52.google.com\r
+ [74.125.83.52]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client\r
+ certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
+ 5BED8431FC0 for <notmuch@notmuchmail.org>; Tue, 25 Mar 2014 10:07:59 -0700\r
+ (PDT)\r
+Received: by mail-ee0-f52.google.com with SMTP id e49so699698eek.11\r
+ for <notmuch@notmuchmail.org>; Tue, 25 Mar 2014 10:07:58 -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:in-reply-to:references;\r
+ bh=eUoxc5Cau1BOQncxLPyJmpBSprrtgIScYhtrM9R6Sm0=;\r
+ b=RHi3ji1bpszx3hTa2LG9I2oTTM5XjFqfs2EDVQ0iKuY3Jy1OWYtr2er1RCidNYor/j\r
+ TqnXnJhRpZfyuRwBoVTeD/vg34fe8CL+hnhxouwDXxw6woOmpl0vvu0kSMTBR7Zn10sK\r
+ /kHi2Jd/S+MBWTm666OTJ9ueeaBv9WByYxUHvq8GseU82Ar3fB2HE+RgJ7bbWIwLi7bj\r
+ cMGbL26CWVruTzTrg5GFCiCizmbAIxA471w38+Xt+AUbX8nItXq8GNB7N16bQRgNkOOZ\r
+ UW1mvBQxkPTn9KrxaQVoSZ2FPNAEFLQB13N2Hh0zIJ2WysTmVBznA4ucUcKqJQD2cLsC\r
+ RvtA==\r
+X-Gm-Message-State:\r
+ ALoCoQmbBYXmakBWT57yoJqWXXGI0viTAb2tKrly7rz49KxF7evSigtjkaOhtQkde4uPd9+bvzVI\r
+X-Received: by 10.14.39.65 with SMTP id c41mr1262236eeb.97.1395767277975;\r
+ Tue, 25 Mar 2014 10:07:57 -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 y7sm22946700eev.5.2014.03.25.10.07.56\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Tue, 25 Mar 2014 10:07:57 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/2] cli: abstract dump file open from the dump command\r
+Date: Tue, 25 Mar 2014 19:07:50 +0200\r
+Message-Id:\r
+ <92929cc512b9e9cd5ccb7d4e537671ce84de514f.1395767165.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.9.0\r
+In-Reply-To: <cover.1395767165.git.jani@nikula.org>\r
+References: <cover.1395767165.git.jani@nikula.org>\r
+In-Reply-To: <cover.1395767165.git.jani@nikula.org>\r
+References: <cover.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:08:03 -0000\r
+\r
+No functional changes, except for slight improvement in error\r
+handling.\r
+---\r
+ notmuch-dump.c | 43 ++++++++++++++++++++++++++++---------------\r
+ 1 file changed, 28 insertions(+), 15 deletions(-)\r
+\r
+diff --git a/notmuch-dump.c b/notmuch-dump.c\r
+index 179e2e97bf61..88bef3f77e82 100644\r
+--- a/notmuch-dump.c\r
++++ b/notmuch-dump.c\r
+@@ -115,11 +115,37 @@ 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
++static int\r
++database_dump (notmuch_database_t *notmuch, const char *output_file_name,\r
++ const char *query_str, int 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 +171,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 +179,7 @@ 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 = database_dump (notmuch, output_file_name, query_str, output_format);\r
+ \r
+ notmuch_database_destroy (notmuch);\r
+ \r
+-- \r
+1.9.0\r
+\r