From 28286cef0b30327da4b1a7ef60292c0c823a9538 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Wed, 13 Jan 2016 23:10:10 +2000 Subject: [PATCH] [WIP2 4/4] CLI: add optional metadata to dump output. --- 96/e595cab1736a12f6a02550ce1417e4be9d1592 | 216 ++++++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 96/e595cab1736a12f6a02550ce1417e4be9d1592 diff --git a/96/e595cab1736a12f6a02550ce1417e4be9d1592 b/96/e595cab1736a12f6a02550ce1417e4be9d1592 new file mode 100644 index 000000000..23cd5f197 --- /dev/null +++ b/96/e595cab1736a12f6a02550ce1417e4be9d1592 @@ -0,0 +1,216 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id F22946DE01FF + for ; Tue, 12 Jan 2016 19:10:28 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -0.311 +X-Spam-Level: +X-Spam-Status: No, score=-0.311 tagged_above=-999 required=5 tests=[AWL=0.240, + RP_MATCHES_RCVD=-0.55, SPF_PASS=-0.001] autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id cFR9P_HEN4-j for ; + Tue, 12 Jan 2016 19:10:27 -0800 (PST) +Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) + by arlo.cworth.org (Postfix) with ESMTPS id A316D6DE0B4F + for ; Tue, 12 Jan 2016 19:10:24 -0800 (PST) +Received: from remotemail by fethera.tethera.net with local (Exim 4.84) + (envelope-from ) + id 1aJBp8-0000ye-8s; Tue, 12 Jan 2016 22:10:14 -0500 +Received: (nullmailer pid 23106 invoked by uid 1000); + Wed, 13 Jan 2016 03:10:18 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [WIP2 4/4] CLI: add optional metadata to dump output. +Date: Tue, 12 Jan 2016 23:10:10 -0400 +Message-Id: <1452654610-22864-5-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.6.4 +In-Reply-To: <1452654610-22864-1-git-send-email-david@tethera.net> +References: <1452654610-22864-1-git-send-email-david@tethera.net> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.20 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Wed, 13 Jan 2016 03:10:29 -0000 + +This lacks at least documentation. Note that it changes the default dump +output format, but doesn't break existing notmuch-restore. It might +break user scripts though. +--- + notmuch-client.h | 6 ++++++ + notmuch-dump.c | 41 ++++++++++++++++++++++++++++++++++++++--- + notmuch-new.c | 2 +- + test/T590-libconfig.sh | 10 ++++++++++ + 4 files changed, 55 insertions(+), 4 deletions(-) + +diff --git a/notmuch-client.h b/notmuch-client.h +index 7c9a1ea..2dca83c 100644 +--- a/notmuch-client.h ++++ b/notmuch-client.h +@@ -443,11 +443,17 @@ typedef enum dump_formats { + DUMP_FORMAT_SUP + } dump_format_t; + ++typedef enum dump_includes { ++ DUMP_INCLUDE_TAGS=1, ++ DUMP_INCLUDE_CONFIG=2, ++} dump_include_t; ++ + int + notmuch_database_dump (notmuch_database_t *notmuch, + const char *output_file_name, + const char *query_str, + dump_format_t output_format, ++ dump_include_t include, + notmuch_bool_t gzip_output); + + /* If status is non-zero (i.e. error) print appropriate +diff --git a/notmuch-dump.c b/notmuch-dump.c +index 829781f..4909493 100644 +--- a/notmuch-dump.c ++++ b/notmuch-dump.c +@@ -23,16 +23,43 @@ + #include "string-util.h" + #include + ++static notmuch_status_t ++database_dump_config(notmuch_database_t *notmuch, gzFile output) ++{ ++ notmuch_config_list_t *list; ++ notmuch_status_t status; ++ status = notmuch_database_get_config_list (notmuch, NULL, &list); ++ if (status) ++ return status; ++ ++ for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) { ++ /* FIXME hexencode key and values */ ++ gzprintf(output, "#@ %s %s\n", ++ notmuch_config_list_key (list), notmuch_config_list_value (list)); ++ } ++ notmuch_config_list_destroy (list); ++ ++ return NOTMUCH_STATUS_SUCCESS; ++} + + static int + database_dump_file (notmuch_database_t *notmuch, gzFile output, +- const char *query_str, int output_format) ++ const char *query_str, int output_format, int include) + { + notmuch_query_t *query; + notmuch_messages_t *messages; + notmuch_message_t *message; + notmuch_tags_t *tags; + ++ if (include | DUMP_INCLUDE_CONFIG) { ++ if (print_status_database ("notmuch dump", notmuch, ++ database_dump_config(notmuch,output))) ++ return EXIT_FAILURE; ++ } ++ ++ if (! (include & DUMP_INCLUDE_TAGS)) ++ return EXIT_SUCCESS; ++ + if (! query_str) + query_str = ""; + +@@ -130,6 +157,7 @@ notmuch_database_dump (notmuch_database_t *notmuch, + const char *output_file_name, + const char *query_str, + dump_format_t output_format, ++ dump_include_t include, + notmuch_bool_t gzip_output) + { + gzFile output = NULL; +@@ -164,7 +192,7 @@ notmuch_database_dump (notmuch_database_t *notmuch, + goto DONE; + } + +- ret = database_dump_file (notmuch, output, query_str, output_format); ++ ret = database_dump_file (notmuch, output, query_str, output_format, include); + if (ret) goto DONE; + + ret = gzflush (output, Z_FINISH); +@@ -226,6 +254,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]) + int opt_index; + + int output_format = DUMP_FORMAT_BATCH_TAG; ++ int include = 0; + notmuch_bool_t gzip_output = 0; + + notmuch_opt_desc_t options[] = { +@@ -233,6 +262,9 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]) + (notmuch_keyword_t []){ { "sup", DUMP_FORMAT_SUP }, + { "batch-tag", DUMP_FORMAT_BATCH_TAG }, + { 0, 0 } } }, ++ { NOTMUCH_OPT_KEYWORD_FLAGS, &include, "include", 'i', ++ (notmuch_keyword_t []){ { "metadata", DUMP_INCLUDE_CONFIG }, ++ { "tags", DUMP_INCLUDE_TAGS} } }, + { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0 }, + { NOTMUCH_OPT_BOOLEAN, &gzip_output, "gzip", 'z', 0 }, + { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 }, +@@ -245,6 +277,9 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]) + + notmuch_process_shared_options (argv[0]); + ++ if (include == 0) ++ include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS; ++ + if (opt_index < argc) { + query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index); + if (query_str == NULL) { +@@ -254,7 +289,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]) + } + + ret = notmuch_database_dump (notmuch, output_file_name, query_str, +- output_format, gzip_output); ++ output_format, include, gzip_output); + + notmuch_database_destroy (notmuch); + +diff --git a/notmuch-new.c b/notmuch-new.c +index e503776..fd2ff82 100644 +--- a/notmuch-new.c ++++ b/notmuch-new.c +@@ -1041,7 +1041,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) + } + + if (notmuch_database_dump (notmuch, backup_name, "", +- DUMP_FORMAT_BATCH_TAG, TRUE)) { ++ DUMP_FORMAT_BATCH_TAG, DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS, TRUE)) { + fprintf (stderr, "Backup failed. Aborting upgrade."); + return EXIT_FAILURE; + } +diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh +index 8ca6883..4fe6bd1 100755 +--- a/test/T590-libconfig.sh ++++ b/test/T590-libconfig.sh +@@ -115,4 +115,14 @@ testkey2 testvalue2 + EOF + test_expect_equal_file EXPECTED OUTPUT + ++test_begin_subtest "dump config" ++notmuch dump --include=metadata >OUTPUT ++cat <<'EOF' >EXPECTED ++#@ aaabefore beforeval ++#@ testkey1 testvalue1 ++#@ testkey2 testvalue2 ++#@ zzzafter afterval ++EOF ++test_expect_equal_file EXPECTED OUTPUT ++ + test_done +-- +2.6.4 + -- 2.26.2