From: David Bremner Date: Sun, 10 Jan 2016 02:51:41 +0000 (+2000) Subject: [WIP patch 9/9] CLI: add optional metadata to dump output. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=df5c31951288e7b9d0551e0c729d1774dd97aad8;p=notmuch-archives.git [WIP patch 9/9] CLI: add optional metadata to dump output. --- diff --git a/58/d728a7e6f5b841b6b4e61def3ade5a98216c2d b/58/d728a7e6f5b841b6b4e61def3ade5a98216c2d new file mode 100644 index 000000000..b1adcf548 --- /dev/null +++ b/58/d728a7e6f5b841b6b4e61def3ade5a98216c2d @@ -0,0 +1,218 @@ +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 123BC6DE1502 + for ; Sat, 9 Jan 2016 18:52:34 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -0.312 +X-Spam-Level: +X-Spam-Status: No, score=-0.312 tagged_above=-999 required=5 tests=[AWL=0.239, + 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 1dX5cdfp5IBH for ; + Sat, 9 Jan 2016 18:52:32 -0800 (PST) +Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) + by arlo.cworth.org (Postfix) with ESMTPS id DD7476DE028A + for ; Sat, 9 Jan 2016 18:52:00 -0800 (PST) +Received: from remotemail by fethera.tethera.net with local (Exim 4.84) + (envelope-from ) + id 1aI66h-0007EQ-De; Sat, 09 Jan 2016 21:51:51 -0500 +Received: (nullmailer pid 29661 invoked by uid 1000); + Sun, 10 Jan 2016 02:51:47 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [WIP patch 9/9] CLI: add optional metadata to dump output. +Date: Sat, 9 Jan 2016 22:51:41 -0400 +Message-Id: <1452394301-29499-10-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.6.4 +In-Reply-To: <1452394301-29499-1-git-send-email-david@tethera.net> +References: <1452394301-29499-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: Sun, 10 Jan 2016 02:52:34 -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 | 45 ++++++++++++++++++++++++++++++++++++++++++--- + notmuch-new.c | 2 +- + test/T590-metadata.sh | 8 ++++++++ + 4 files changed, 57 insertions(+), 4 deletions(-) + +diff --git a/notmuch-client.h b/notmuch-client.h +index 7c9a1ea..8ee6e0e 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_METADATA=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..a88b5d5 100644 +--- a/notmuch-dump.c ++++ b/notmuch-dump.c +@@ -23,16 +23,47 @@ + #include "string-util.h" + #include + ++static notmuch_status_t ++database_dump_metadata(notmuch_database_t *notmuch, gzFile output) ++{ ++ notmuch_metadata_class_t mclass; ++ notmuch_metadata_t *meta; ++ notmuch_status_t status; ++ ++ for (mclass = NOTMUCH_METADATA_FIRST_CLASS; mclass < NOTMUCH_METADATA_LAST_CLASS; mclass++) { ++ status = notmuch_database_get_all_metadata (notmuch, NOTMUCH_METADATA_CONFIG, &meta); ++ if (status) ++ return status; ++ ++ for (; notmuch_metadata_valid (meta); notmuch_metadata_move_to_next (meta)) { ++ /* FIXME hexencode key and values */ ++ gzprintf(output, "#@ %s %s %s\n", ++ notmuch_metadata_prefix_string(mclass), ++ notmuch_metadata_key (meta), notmuch_metadata_value (meta)); ++ } ++ notmuch_metadata_destroy (meta); ++ } ++ 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_METADATA) { ++ if (print_status_database ("notmuch dump", notmuch, ++ database_dump_metadata(notmuch,output))) ++ return EXIT_FAILURE; ++ } ++ ++ if (! (include & DUMP_INCLUDE_TAGS)) ++ return EXIT_SUCCESS; ++ + if (! query_str) + query_str = ""; + +@@ -130,6 +161,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 +196,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 +258,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 +266,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_METADATA }, ++ { "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 +281,9 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]) + + notmuch_process_shared_options (argv[0]); + ++ if (include == 0) ++ include = DUMP_INCLUDE_METADATA | 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 +293,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..1f8050d 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_METADATA | DUMP_INCLUDE_TAGS, TRUE)) { + fprintf (stderr, "Backup failed. Aborting upgrade."); + return EXIT_FAILURE; + } +diff --git a/test/T590-metadata.sh b/test/T590-metadata.sh +index 4d55298..45a49be 100755 +--- a/test/T590-metadata.sh ++++ b/test/T590-metadata.sh +@@ -77,4 +77,12 @@ val = testvalue2 + EOF + test_expect_equal_file EXPECTED OUTPUT + ++test_begin_subtest "dump metadata" ++notmuch dump --include=metadata >OUTPUT ++cat <<'EOF' >EXPECTED ++#@ C testkey1 testvalue1 ++#@ C testkey2 testvalue2 ++EOF ++test_expect_equal_file EXPECTED OUTPUT ++ + test_done +-- +2.6.4 +