From: David Bremner Date: Sun, 10 Jan 2016 02:51:35 +0000 (+2000) Subject: [WIP patch 3/9] lib: add and test function to retrive current key X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=230c4f9def2e6fb86eccdee3062e068029a27943;p=notmuch-archives.git [WIP patch 3/9] lib: add and test function to retrive current key --- diff --git a/6e/2050044a794d091cb4101705254baf987e0016 b/6e/2050044a794d091cb4101705254baf987e0016 new file mode 100644 index 000000000..0f9c72834 --- /dev/null +++ b/6e/2050044a794d091cb4101705254baf987e0016 @@ -0,0 +1,136 @@ +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 B758E6DE0350 + for ; Sat, 9 Jan 2016 18:51:55 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -0.31 +X-Spam-Level: +X-Spam-Status: No, score=-0.31 tagged_above=-999 required=5 tests=[AWL=0.241, + 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 ucYN7Dj1nb0i for ; + Sat, 9 Jan 2016 18:51:53 -0800 (PST) +Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) + by arlo.cworth.org (Postfix) with ESMTPS id 806716DE02C9 + for ; Sat, 9 Jan 2016 18:51:53 -0800 (PST) +Received: from remotemail by fethera.tethera.net with local (Exim 4.84) + (envelope-from ) + id 1aI66Z-0007DA-SG; Sat, 09 Jan 2016 21:51:43 -0500 +Received: (nullmailer pid 29644 invoked by uid 1000); + Sun, 10 Jan 2016 02:51:47 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [WIP patch 3/9] lib: add and test function to retrive current key +Date: Sat, 9 Jan 2016 22:51:35 -0400 +Message-Id: <1452394301-29499-4-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:51:55 -0000 + +--- + lib/metadata.cc | 17 +++++++++++++++++ + lib/notmuch.h | 6 ++++++ + test/T590-metadata.sh | 4 +++- + 3 files changed, 26 insertions(+), 1 deletion(-) + +diff --git a/lib/metadata.cc b/lib/metadata.cc +index 5d319c5..20805e5 100644 +--- a/lib/metadata.cc ++++ b/lib/metadata.cc +@@ -26,6 +26,7 @@ struct _notmuch_metadata { + notmuch_database_t *notmuch; + Xapian::TermIterator *iterator; + notmuch_metadata_class_t mclass; ++ char *current_key; + }; + + static int +@@ -180,6 +181,7 @@ notmuch_database_get_all_metadata (notmuch_database_t *notmuch, + list->iterator = new Xapian::TermIterator; + list->notmuch = notmuch; + list->mclass = mclass; ++ list->current_key = NULL; + + try { + +@@ -211,3 +213,18 @@ notmuch_metadata_valid (notmuch_metadata_t *metadata) + + return (strncmp((**(metadata->iterator)).c_str (), prefix, strlen (prefix)) == 0); + } ++ ++const char * ++notmuch_metadata_key (notmuch_metadata_t *metadata) ++{ ++ const char *prefix = _find_metadata_prefix (metadata->mclass); ++ ++ if (metadata->current_key) ++ talloc_free (metadata->current_key); ++ metadata->current_key = talloc_strdup (metadata, (**(metadata->iterator)).c_str () + strlen (prefix)); ++ ++ return metadata->current_key; ++} ++ ++const char * ++} +diff --git a/lib/notmuch.h b/lib/notmuch.h +index a2b7040..16d0973 100644 +--- a/lib/notmuch.h ++++ b/lib/notmuch.h +@@ -1866,6 +1866,12 @@ notmuch_database_get_all_metadata (notmuch_database_t *db, notmuch_metadata_clas + */ + notmuch_bool_t + notmuch_metadata_valid (notmuch_metadata_t *metadata); ++ ++/** ++ * return key for current metadata pair ++ */ ++const char * ++notmuch_metadata_key (notmuch_metadata_t *metadata); + /* @} */ + + NOTMUCH_END_DECLS +diff --git a/test/T590-metadata.sh b/test/T590-metadata.sh +index c36a7d7..2c44746 100755 +--- a/test/T590-metadata.sh ++++ b/test/T590-metadata.sh +@@ -55,17 +55,19 @@ testkey2 = testvalue2 + EOF + test_expect_equal_file EXPECTED OUTPUT + +-test_begin_subtest "notmuch_database_get_all_metadata initially valid" ++test_begin_subtest "notmuch_database_get_all_metadata first item" + cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} + { + notmuch_metadata_t *meta; + RUN(notmuch_database_get_all_metadata (db, NOTMUCH_METADATA_CONFIG, &meta)); + printf("valid = %d\n", notmuch_metadata_valid (meta)); ++ printf("key = %s\n", notmuch_metadata_key (meta)); + } + EOF + cat <<'EOF' >EXPECTED + == stdout == + valid = 1 ++key = testkey1 + == stderr == + EOF + test_expect_equal_file EXPECTED OUTPUT +-- +2.6.4 +