mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-27 21:27:58 +01:00
CLI: stash pointer to database in sprinter structs
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.
This commit is contained in:
parent
78e6cf12c0
commit
417d202e64
5 changed files with 21 additions and 13 deletions
|
@ -65,7 +65,7 @@ struct sprinter;
|
||||||
struct notmuch_show_params;
|
struct notmuch_show_params;
|
||||||
|
|
||||||
typedef struct notmuch_show_format {
|
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,
|
notmuch_status_t (*part)(const void *ctx, struct sprinter *sprinter,
|
||||||
struct mime_node *node, int indent,
|
struct mime_node *node, int indent,
|
||||||
const struct notmuch_show_params *params);
|
const struct notmuch_show_params *params);
|
||||||
|
|
|
@ -172,7 +172,7 @@ json_separator (struct sprinter *sp)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sprinter *
|
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 = {
|
static const struct sprinter_json template = {
|
||||||
.vtable = {
|
.vtable = {
|
||||||
|
@ -192,11 +192,12 @@ sprinter_json_create (const void *ctx, FILE *stream)
|
||||||
};
|
};
|
||||||
struct sprinter_json *res;
|
struct sprinter_json *res;
|
||||||
|
|
||||||
res = talloc (ctx, struct sprinter_json);
|
res = talloc (db, struct sprinter_json);
|
||||||
if (! res)
|
if (! res)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
*res = template;
|
*res = template;
|
||||||
|
res->vtable.notmuch = db;
|
||||||
res->stream = stream;
|
res->stream = stream;
|
||||||
return &res->vtable;
|
return &res->vtable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,7 +207,7 @@ sexp_separator (struct sprinter *sp)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sprinter *
|
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 = {
|
static const struct sprinter_sexp template = {
|
||||||
.vtable = {
|
.vtable = {
|
||||||
|
@ -227,11 +227,12 @@ sprinter_sexp_create (const void *ctx, FILE *stream)
|
||||||
};
|
};
|
||||||
struct sprinter_sexp *res;
|
struct sprinter_sexp *res;
|
||||||
|
|
||||||
res = talloc (ctx, struct sprinter_sexp);
|
res = talloc (db, struct sprinter_sexp);
|
||||||
if (! res)
|
if (! res)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
*res = template;
|
*res = template;
|
||||||
|
res->vtable.notmuch = db;
|
||||||
res->stream = stream;
|
res->stream = stream;
|
||||||
return &res->vtable;
|
return &res->vtable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ text_map_key (unused (struct sprinter *sp), unused (const char *key))
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sprinter *
|
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 = {
|
static const struct sprinter_text template = {
|
||||||
.vtable = {
|
.vtable = {
|
||||||
|
@ -134,21 +134,22 @@ sprinter_text_create (const void *ctx, FILE *stream)
|
||||||
};
|
};
|
||||||
struct sprinter_text *res;
|
struct sprinter_text *res;
|
||||||
|
|
||||||
res = talloc (ctx, struct sprinter_text);
|
res = talloc (db, struct sprinter_text);
|
||||||
if (! res)
|
if (! res)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
*res = template;
|
*res = template;
|
||||||
|
res->vtable.notmuch = db;
|
||||||
res->stream = stream;
|
res->stream = stream;
|
||||||
return &res->vtable;
|
return &res->vtable;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sprinter *
|
struct sprinter *
|
||||||
sprinter_text0_create (const void *ctx, FILE *stream)
|
sprinter_text0_create (notmuch_database_t *db, FILE *stream)
|
||||||
{
|
{
|
||||||
struct sprinter *sp;
|
struct sprinter *sp;
|
||||||
|
|
||||||
sp = sprinter_text_create (ctx, stream);
|
sp = sprinter_text_create (db, stream);
|
||||||
if (! sp)
|
if (! sp)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
13
sprinter.h
13
sprinter.h
|
@ -9,6 +9,11 @@
|
||||||
* (strings, integers and booleans).
|
* (strings, integers and booleans).
|
||||||
*/
|
*/
|
||||||
typedef struct sprinter {
|
typedef struct sprinter {
|
||||||
|
/*
|
||||||
|
* Open notmuch database
|
||||||
|
*/
|
||||||
|
notmuch_database_t *notmuch;
|
||||||
|
|
||||||
/* Start a new map/dictionary structure. This should be followed by
|
/* Start a new map/dictionary structure. This should be followed by
|
||||||
* a sequence of alternating calls to map_key and one of the
|
* a sequence of alternating calls to map_key and one of the
|
||||||
* value-printing functions until the map is ended by end.
|
* 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
|
/* Create a new unstructured printer that emits the default text format
|
||||||
* for "notmuch search". */
|
* for "notmuch search". */
|
||||||
struct sprinter *
|
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
|
/* Create a new unstructured printer that emits the text format for
|
||||||
* "notmuch search", with each field separated by a null character
|
* "notmuch search", with each field separated by a null character
|
||||||
* instead of the newline character. */
|
* instead of the newline character. */
|
||||||
struct sprinter *
|
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. */
|
/* Create a new structure printer that emits JSON. */
|
||||||
struct sprinter *
|
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. */
|
/* Create a new structure printer that emits S-Expressions. */
|
||||||
struct sprinter *
|
struct sprinter *
|
||||||
sprinter_sexp_create (const void *ctx, FILE *stream);
|
sprinter_sexp_create (notmuch_database_t *db, FILE *stream);
|
||||||
|
|
||||||
#endif // NOTMUCH_SPRINTER_H
|
#endif // NOTMUCH_SPRINTER_H
|
||||||
|
|
Loading…
Reference in a new issue