[PATCH] notmuch-show: use correct format specifier for ssize_t

2021-01-24 Thread Đoàn Trần Công Danh
Signed-off-by: Đoàn Trần Công Danh 
---

 I found this after inspecting one of my build today.
 I'm not sure what is acceptable action.
 I think using %zd is the right move.
 But I'm not sure if you prefer to case ssize to long int.

 notmuch-show.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index dd836add..c0498c66 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -909,7 +909,7 @@ format_part_raw (unused (const void *ctx), unused 
(sprinter_t *sp),
}
 
if (ssize > 0 && fwrite (buf, ssize, 1, stdout) != 1) {
-   fprintf (stderr, "Error: Write %ld chars to stdout failed\n", 
ssize);
+   fprintf (stderr, "Error: Write %zd chars to stdout failed\n", 
ssize);
goto DONE;
}
}
-- 
2.30.0
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH 37/38] CLI: use configured hook directory

2021-01-24 Thread Tomi Ollila
On Sat, Jan 16 2021, David Bremner wrote:

> This enables support for hooks outside the database directory.
> It relies strongly on configuration information being usable between
> closing the database and destroying it.
> ---
>  hooks.c|   7 +-
>  notmuch-client.h   |   2 +-
>  notmuch-insert.c   |   7 +-
>  notmuch-new.c  |   4 +-
>  test/T400-hooks.sh | 197 +
>  5 files changed, 120 insertions(+), 97 deletions(-)
>
> diff --git a/hooks.c b/hooks.c
> index 59c58070..ec89b22e 100644
> --- a/hooks.c
> +++ b/hooks.c
> @@ -24,14 +24,15 @@
>  #include 
>  
>  int
> -notmuch_run_hook (const char *db_path, const char *hook)
> +notmuch_run_hook (notmuch_database_t *notmuch, const char *hook)
>  {
>  char *hook_path;
>  int status = 0;
>  pid_t pid;
>  
> -hook_path = talloc_asprintf (NULL, "%s/%s/%s/%s", db_path, ".notmuch",
> -  "hooks", hook);
> +hook_path = talloc_asprintf (notmuch, "%s/%s",
> +  notmuch_config_get (notmuch, 
> NOTMUCH_CONFIG_HOOK_DIR),
> +  hook);
>  if (hook_path == NULL) {
>   fprintf (stderr, "Out of memory\n");
>   return 1;
> diff --git a/notmuch-client.h b/notmuch-client.h
> index 9e09c36a..f60f5406 100644
> --- a/notmuch-client.h
> +++ b/notmuch-client.h
> @@ -339,7 +339,7 @@ const char *
>  _notmuch_config_get_path (notmuch_config_t *config);
>  
>  int
> -notmuch_run_hook (const char *db_path, const char *hook);
> +notmuch_run_hook (notmuch_database_t *notmuch, const char *hook);
>  
>  bool
>  debugger_is_active (void);
> diff --git a/notmuch-insert.c b/notmuch-insert.c
> index e483b949..0f272e2e 100644
> --- a/notmuch-insert.c
> +++ b/notmuch-insert.c
> @@ -481,7 +481,6 @@ notmuch_insert_command (unused(notmuch_config_t 
> *config),notmuch_database_t *not
>  notmuch_process_shared_options (argv[0]);
>  
>  
> -/* XXX TODO replace this use of DATABASE_PATH with something specific to 
> hooks */
>  db_path = notmuch_config_get (notmuch, NOTMUCH_CONFIG_DATABASE_PATH);
>  
>  if (! db_path)
> @@ -570,7 +569,7 @@ notmuch_insert_command (unused(notmuch_config_t 
> *config),notmuch_database_t *not
>  status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep, 
> indexing_cli_choices.opts);
>  
>  /* Commit changes. */
> -close_status = notmuch_database_destroy (notmuch);
> +close_status = notmuch_database_close (notmuch);
>  if (close_status) {
>   /* Hold on to the first error, if any. */
>   if (! status)
> @@ -595,9 +594,11 @@ notmuch_insert_command (unused(notmuch_config_t 
> *config),notmuch_database_t *not
>  
>  if (hooks && status == NOTMUCH_STATUS_SUCCESS) {
>   /* Ignore hook failures. */
> - notmuch_run_hook (db_path, "post-insert");
> + notmuch_run_hook (notmuch, "post-insert");
>  }
>  
> +notmuch_database_destroy (notmuch);
> +
>  talloc_free (local);
>  
>  return status_to_exit (status);
> diff --git a/notmuch-new.c b/notmuch-new.c
> index 0f416939..2fc34e2c 100644
> --- a/notmuch-new.c
> +++ b/notmuch-new.c
> @@ -1167,7 +1167,7 @@ notmuch_new_command (unused(notmuch_config_t *config), 
> notmuch_database_t *notmu
>  }
>  
>  if (hooks) {
> - ret = notmuch_run_hook (db_path, "pre-new");
> + ret = notmuch_run_hook (notmuch, "pre-new");
>   if (ret)
>   return EXIT_FAILURE;
>  }
> @@ -1284,7 +1284,7 @@ notmuch_new_command (unused(notmuch_config_t *config), 
> notmuch_database_t *notmu
>  notmuch_database_close (notmuch);
>  
>  if (hooks && ! ret && ! interrupted)
> - ret = notmuch_run_hook (db_path, "post-new");
> + ret = notmuch_run_hook (notmuch, "post-new");
>  
>  notmuch_database_destroy (notmuch);
>  
> diff --git a/test/T400-hooks.sh b/test/T400-hooks.sh
> index 49c690eb..b9894853 100755
> --- a/test/T400-hooks.sh
> +++ b/test/T400-hooks.sh
> @@ -2,8 +2,6 @@
>  test_description='hooks'
>  . $(dirname "$0")/test-lib.sh || exit 1
>  
> -HOOK_DIR=${MAIL_DIR}/.notmuch/hooks
> -
>  create_echo_hook () {
>  local TOKEN="${RANDOM}"
>  mkdir -p ${HOOK_DIR}
> @@ -16,6 +14,7 @@ EOF
>  }
>  
>  create_failing_hook () {
> +local HOOK_DIR=${2}
>  mkdir -p ${HOOK_DIR}
>  cat <"${HOOK_DIR}/${1}"
>  #!/bin/sh
> @@ -24,98 +23,120 @@ EOF
>  chmod +x "${HOOK_DIR}/${1}"
>  }
>  
> -rm_hooks () {
> -rm -rf ${HOOK_DIR}
> -}
> -
>  # add a message to generate mail dir and database
>  add_message
>  # create maildir structure for notmuch-insert
>  mkdir -p "$MAIL_DIR"/{cur,new,tmp}
>  
> -test_begin_subtest "pre-new is run"
> -rm_hooks
> -generate_message
> -create_echo_hook "pre-new" expected output
> -notmuch new > /dev/null
> -test_expect_equal_file expected output
> -
> -test_begin_subtest "post-new is run"
> -rm_hooks
> -generate_message
> -create_echo_hook "post-new" expected output
> -notmuch new > /dev/null
> -test_expect_equal_file expected out

Re: [PATCH 01/38] lib: add _notmuch_string_map_set

2021-01-24 Thread David Bremner
Tomi Ollila  writes:

> On Sat, Jan 16 2021, David Bremner wrote:
>
>
> First, is this patch series safe to be applied and put into use ? :D

At least the backwards compatibility part is pretty well tested. I have
been running variations of it for a month or so.

>
> The style in string-map.c (and matches the .h above) would indicate the abobe 
> should be:
>
> _notmuch_string_map_set (notmuch_string_map_t *map, 
>  const char *key, 
>  const char *val)
>

Sure. Although I think string-map.c is not completely consistent, that
is no reason not to match the header for new stuff.

d
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH 04/38] lib/open: add support for config profiles and default locations

2021-01-24 Thread Tomi Ollila
On Sat, Jan 16 2021, David Bremner wrote:

In id:20210116170406.842014-4-da...@tethera.net there is missing space
after , 

gchar **groups,**keys, *val;

Here, perhaps s/This commits fills in/Fill in/  (?)


> This commit fills in the remainder of the documented functionality for
> n_d_open_with_config with respect to config file location. Similar
> searching default locations of the database file still needs to be
> added.
> ---
>  lib/open.cc|  95 +
>  test/T590-libconfig.sh | 153 ++---
>  2 files changed, 227 insertions(+), 21 deletions(-)
>
> diff --git a/lib/open.cc b/lib/open.cc
> index 7acaea7b..76255283 100644
> --- a/lib/open.cc
> +++ b/lib/open.cc
> @@ -37,6 +37,82 @@ notmuch_database_open_verbose (const char *path,
> database, status_string);
>  }
>  
> +static const char *
> +_xdg_dir (void *ctx,
> +   const char *xdg_root_variable,
> +   const char *xdg_prefix,
> +   const char *profile_name)
> +{
> +const char *xdg_root = getenv (xdg_root_variable);
> +const char *home = getenv ("HOME");

Resolving HOME from env is not needed always, move it inside
next if() -- that will also make its scope smaller.

> +
> +if (! xdg_root) {
> + if (! home) return NULL;
> +
> + xdg_root = talloc_asprintf (ctx,
> + "%s/%s",
> + home,
> + xdg_prefix);
> +}
> +
> +if (! profile_name)
> + profile_name = getenv ("NOTMUCH_PROFILE");
> +
> +if (! profile_name)
> + profile_name = "default";
> +
> +return talloc_asprintf (ctx,
> + "%s/notmuch/%s",
> + xdg_root,
> + profile_name);
> +}
> +
> +static notmuch_status_t
> +_load_key_file (const char *path,
> + const char *profile,
> + GKeyFile **key_file)
> +{
> +notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
> +void *local = talloc_new (NULL);
> +
> +if (path && EMPTY_STRING (path))
> + goto DONE;
> +
> +if (! path)
> + path = getenv ("NOTMUCH_CONFIG");
> +
> +if (! path) {
> + const char *dir = _xdg_dir (local, "XDG_CONFIG_HOME", ".config", 
> profile);
> +
> + if (dir) {
> + path = talloc_asprintf (local, "%s/config", dir);
> + if (access (path, R_OK) !=0)
> + path = NULL;
> + }
> +}
> +
> +if (! path) {
> + const char *home = getenv ("HOME");
> +
> + path = talloc_asprintf (local, "%s/.notmuch-config", home);
> +
> + if (! profile)
> + profile = getenv ("NOTMUCH_PROFILE");
> +
> + if (profile)
> + path = talloc_asprintf (local, "%s.%s", path, profile);
> +}
> +
> +*key_file = g_key_file_new ();
> +if (! g_key_file_load_from_file (*key_file, path, G_KEY_FILE_NONE, 
> NULL)) {
> + status = NOTMUCH_STATUS_FILE_ERROR;
> +}
> +
> +DONE:
> +talloc_free (local);
> +return status;
> +}
> +
>  notmuch_status_t
>  notmuch_database_open_with_config (const char *database_path,
>  notmuch_database_mode_t mode,
> @@ -49,7 +125,6 @@ notmuch_database_open_with_config (const char 
> *database_path,
>  void *local = talloc_new (NULL);
>  notmuch_database_t *notmuch = NULL;
>  char *notmuch_path, *xapian_path, *incompat_features;
> -char *configured_database_path = NULL;
>  char *message = NULL;
>  struct stat st;
>  int err;
> @@ -57,18 +132,14 @@ notmuch_database_open_with_config (const char 
> *database_path,
>  GKeyFile *key_file = NULL;
>  static int initialized = 0;
>  
> -/* XXX TODO: default locations for NULL case, handle profiles */
> -if (config_path != NULL && ! EMPTY_STRING (config_path)) {
> - key_file = g_key_file_new ();
> - if (! g_key_file_load_from_file (key_file, config_path, 
> G_KEY_FILE_NONE, NULL)) {
> - status = NOTMUCH_STATUS_FILE_ERROR;
> - goto DONE;
> - }
> - configured_database_path = g_key_file_get_value (key_file, "database", 
> "path", NULL);
> +status = _load_key_file (config_path, profile, &key_file);
> +if (status) {
> + message = strdup ("Error: cannot load config file");
> + goto DONE;
>  }
> -
> -if (database_path == NULL)
> - database_path = configured_database_path;
> + 
> +if (! database_path && key_file)
> + database_path = g_key_file_get_value (key_file, "database", "path", 
> NULL);
>  
>  if (database_path == NULL) {
>   message = strdup ("Error: Cannot open a database for a NULL path.\n");
> diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
> index 5fb1bb87..2986284a 100755
> --- a/test/T590-libconfig.sh
> +++ b/test/T590-libconfig.sh
> @@ -15,14 +15,21 @@ int main (int argc, char** argv)
> notmuch_database_t *db;
> char *val;
> notmuch_status_t stat;
> +   char *msg =

Re: [PATCH 01/38] lib: add _notmuch_string_map_set

2021-01-24 Thread Tomi Ollila


On Sat, Jan 16 2021, David Bremner wrote:


First, is this patch series safe to be applied and put into use ? :D

I've looked this through once. So much stuff hard to figure out
if there is something broken. 

Most of the comments here and other patches are about style (line
break), but some (IIRC at least 2) which changes functionality a bit...

> This will be used (and tested) by the configuration caching code to be
> added in the next commit.
> ---
>  lib/notmuch-private.h |  5 +
>  lib/string-map.c  | 15 +++
>  2 files changed, 20 insertions(+)
>
> diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
> index 57ec7f72..51016b0b 100644
> --- a/lib/notmuch-private.h
> +++ b/lib/notmuch-private.h
> @@ -638,6 +638,11 @@ _notmuch_string_map_append (notmuch_string_map_t *map,
>   const char *key,
>   const char *value);
>  
> +void
> +_notmuch_string_map_set (notmuch_string_map_t *map,
> +  const char *key,
> +  const char *value);
> +
>  const char *
>  _notmuch_string_map_get (notmuch_string_map_t *map, const char *key);
>  
> diff --git a/lib/string-map.c b/lib/string-map.c
> index a88404c7..1f3215fb 100644
> --- a/lib/string-map.c
> +++ b/lib/string-map.c
> @@ -142,6 +142,21 @@ bsearch_first (notmuch_string_pair_t *array, size_t len, 
> const char *key, bool e
>   return NULL;
>  
>  }
> +void
> +_notmuch_string_map_set (notmuch_string_map_t *map, const char *key, const 
> char *val)

The style in string-map.c (and matches the .h above) would indicate the abobe 
should be:

_notmuch_string_map_set (notmuch_string_map_t *map, 
 const char *key, 
 const char *val)

> +{
> +notmuch_string_pair_t *pair;
> +
> +/* this means that calling string_map_set invalidates iterators */
> +_notmuch_string_map_sort (map);
> +pair = bsearch_first (map->pairs, map->length, key, true);
> +if (! pair)
> +   _notmuch_string_map_append (map, key, val);
> +else {
> +   talloc_free (pair->value);
> +   pair->value = talloc_strdup (map->pairs, val);
> +}
> +}
>  
>  const char *
>  _notmuch_string_map_get (notmuch_string_map_t *map, const char *key)
> -- 
> 2.29.2
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org