From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 1/3] CLI: stash pointer to database in sprinter structs
Date: Sat, 1 Jan 2022 08:01:34 -0400 [thread overview]
Message-ID: <20220101120136.37988-2-david@tethera.net> (raw)
In-Reply-To: <20220101120136.37988-1-david@tethera.net>
We already use an allocated (and presumably open) database as a talloc
context. Keeping the pointer in the allocated struct will allow us to
e.g. interrogate the configuration in a sprinter function without
threading the database all the way through the various levels of function.
---
notmuch-client.h | 2 +-
sprinter-json.c | 5 +++--
sprinter-sexp.c | 5 +++--
sprinter-text.c | 9 +++++----
sprinter.h | 13 +++++++++----
5 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/notmuch-client.h b/notmuch-client.h
index de318e1f..9f57ac5e 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -65,7 +65,7 @@ struct sprinter;
struct notmuch_show_params;
typedef struct notmuch_show_format {
- struct sprinter *(*new_sprinter)(const void *ctx, FILE *stream);
+ struct sprinter *(*new_sprinter)(notmuch_database_t * db, FILE *stream);
notmuch_status_t (*part)(const void *ctx, struct sprinter *sprinter,
struct mime_node *node, int indent,
const struct notmuch_show_params *params);
diff --git a/sprinter-json.c b/sprinter-json.c
index c7f4851c..502f89fb 100644
--- a/sprinter-json.c
+++ b/sprinter-json.c
@@ -172,7 +172,7 @@ json_separator (struct sprinter *sp)
}
struct sprinter *
-sprinter_json_create (const void *ctx, FILE *stream)
+sprinter_json_create (notmuch_database_t *db, FILE *stream)
{
static const struct sprinter_json template = {
.vtable = {
@@ -192,11 +192,12 @@ sprinter_json_create (const void *ctx, FILE *stream)
};
struct sprinter_json *res;
- res = talloc (ctx, struct sprinter_json);
+ res = talloc (db, struct sprinter_json);
if (! res)
return NULL;
*res = template;
+ res->vtable.notmuch = db;
res->stream = stream;
return &res->vtable;
}
diff --git a/sprinter-sexp.c b/sprinter-sexp.c
index 63b25428..e37cb1f9 100644
--- a/sprinter-sexp.c
+++ b/sprinter-sexp.c
@@ -207,7 +207,7 @@ sexp_separator (struct sprinter *sp)
}
struct sprinter *
-sprinter_sexp_create (const void *ctx, FILE *stream)
+sprinter_sexp_create (notmuch_database_t *db, FILE *stream)
{
static const struct sprinter_sexp template = {
.vtable = {
@@ -227,11 +227,12 @@ sprinter_sexp_create (const void *ctx, FILE *stream)
};
struct sprinter_sexp *res;
- res = talloc (ctx, struct sprinter_sexp);
+ res = talloc (db, struct sprinter_sexp);
if (! res)
return NULL;
*res = template;
+ res->vtable.notmuch = db;
res->stream = stream;
return &res->vtable;
}
diff --git a/sprinter-text.c b/sprinter-text.c
index c75ec5be..99330a94 100644
--- a/sprinter-text.c
+++ b/sprinter-text.c
@@ -114,7 +114,7 @@ text_map_key (unused (struct sprinter *sp), unused (const char *key))
}
struct sprinter *
-sprinter_text_create (const void *ctx, FILE *stream)
+sprinter_text_create (notmuch_database_t *db, FILE *stream)
{
static const struct sprinter_text template = {
.vtable = {
@@ -134,21 +134,22 @@ sprinter_text_create (const void *ctx, FILE *stream)
};
struct sprinter_text *res;
- res = talloc (ctx, struct sprinter_text);
+ res = talloc (db, struct sprinter_text);
if (! res)
return NULL;
*res = template;
+ res->vtable.notmuch = db;
res->stream = stream;
return &res->vtable;
}
struct sprinter *
-sprinter_text0_create (const void *ctx, FILE *stream)
+sprinter_text0_create (notmuch_database_t *db, FILE *stream)
{
struct sprinter *sp;
- sp = sprinter_text_create (ctx, stream);
+ sp = sprinter_text_create (db, stream);
if (! sp)
return NULL;
diff --git a/sprinter.h b/sprinter.h
index 528d8a2d..fd08641c 100644
--- a/sprinter.h
+++ b/sprinter.h
@@ -9,6 +9,11 @@
* (strings, integers and booleans).
*/
typedef struct sprinter {
+ /*
+ * Open notmuch database
+ */
+ notmuch_database_t *notmuch;
+
/* Start a new map/dictionary structure. This should be followed by
* a sequence of alternating calls to map_key and one of the
* value-printing functions until the map is ended by end.
@@ -65,20 +70,20 @@ typedef struct sprinter {
/* Create a new unstructured printer that emits the default text format
* for "notmuch search". */
struct sprinter *
-sprinter_text_create (const void *ctx, FILE *stream);
+sprinter_text_create (notmuch_database_t *db, FILE *stream);
/* Create a new unstructured printer that emits the text format for
* "notmuch search", with each field separated by a null character
* instead of the newline character. */
struct sprinter *
-sprinter_text0_create (const void *ctx, FILE *stream);
+sprinter_text0_create (notmuch_database_t *db, FILE *stream);
/* Create a new structure printer that emits JSON. */
struct sprinter *
-sprinter_json_create (const void *ctx, FILE *stream);
+sprinter_json_create (notmuch_database_t *db, FILE *stream);
/* Create a new structure printer that emits S-Expressions. */
struct sprinter *
-sprinter_sexp_create (const void *ctx, FILE *stream);
+sprinter_sexp_create (notmuch_database_t *db, FILE *stream);
#endif // NOTMUCH_SPRINTER_H
--
2.34.1
next prev parent reply other threads:[~2022-01-01 12:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-01 12:01 support extra headers in notmuch show v2 David Bremner
2022-01-01 12:01 ` David Bremner [this message]
2022-01-18 12:14 ` [PATCH 1/3] CLI: stash pointer to database in sprinter structs David Bremner
2022-01-18 13:26 ` [PATCH] doc: document new option `show.extra_headers` David Bremner
2022-01-25 11:57 ` David Bremner
2022-01-01 12:01 ` [PATCH 2/3] lib/config: add known config key "show.extra_headers" David Bremner
2022-01-01 12:01 ` [PATCH 3/3] CLI: print extra headers in structured output David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220101120136.37988-2-david@tethera.net \
--to=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).