Merge branch 'release'

This commit is contained in:
David Bremner 2021-05-10 11:36:56 -03:00
commit b4a4ed0df9
7 changed files with 96 additions and 9 deletions

7
NEWS
View file

@ -6,6 +6,13 @@ Vim
Respect excluded tags when showing a thread.
Notmuch 0.32.1 (UNRELEASED)
===========================
Restore handling of relative values for `database.path` that was
broken by 0.32. Extend this handling to `database.mail_root`,
`database.backup_dir`, and `database.hook_dir`.
Notmuch 0.32 (2021-05-02)
=========================

View file

@ -44,7 +44,9 @@ configuration file and corresponding database.
characters. In a multiple-value item (a list), the values are
separated by semicolon characters.
The available configuration items are described below.
The available configuration items are described below. Non-absolute
paths are presumed relative to `$HOME` for items in section
**database**.
**database.path**
Notmuch will store its database here, (in
@ -63,6 +65,14 @@ The available configuration items are described below.
Default: For compatibility with older configurations, the value of
database.path is used if **database.mail\_root** is unset.
**database.backup_dir**
Directory to store tag dumps when upgrading database.
History: this configuration value was introduced in notmuch 0.32.
Default: A sibling directory of the Xapian database called
`backups`.
**database.hook_dir**
Directory containing hooks run by notmuch commands. See

View file

@ -46,6 +46,7 @@ struct _notmuch_config_pairs {
};
static const char *_notmuch_config_key_to_string (notmuch_config_key_t key);
static char *_expand_path (void *ctx, const char *key, const char *val);
static int
_notmuch_config_list_destroy (notmuch_config_list_t *list)
@ -257,9 +258,10 @@ _notmuch_config_load_from_database (notmuch_database_t *notmuch)
return status;
for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
_notmuch_string_map_append (notmuch->config,
notmuch_config_list_key (list),
notmuch_config_list_value (list));
const char *key = notmuch_config_list_key (list);
char *normalized_val = _expand_path (list, key, notmuch_config_list_value (list));
_notmuch_string_map_append (notmuch->config, key, normalized_val);
talloc_free (normalized_val);
}
return status;
@ -387,6 +389,23 @@ notmuch_config_pairs_destroy (notmuch_config_pairs_t *pairs)
talloc_free (pairs);
}
static char *
_expand_path (void *ctx, const char *key, const char *val)
{
char *expanded_val;
if ((strcmp (key, "database.path") == 0 ||
strcmp (key, "database.mail_root") == 0 ||
strcmp (key, "database.hook_dir") == 0 ||
strcmp (key, "database.backup_path") == 0 ) &&
val[0] != '/')
expanded_val = talloc_asprintf (ctx, "%s/%s", getenv ("HOME"), val);
else
expanded_val = talloc_strdup (ctx, val);
return expanded_val;
}
notmuch_status_t
_notmuch_config_load_from_file (notmuch_database_t *notmuch,
GKeyFile *file)
@ -407,14 +426,17 @@ _notmuch_config_load_from_file (notmuch_database_t *notmuch,
keys = g_key_file_get_keys (file, *grp, NULL, NULL);
for (gchar **keys_p = keys; *keys_p; keys_p++) {
char *absolute_key = talloc_asprintf (notmuch, "%s.%s", *grp, *keys_p);
char *normalized_val;
val = g_key_file_get_value (file, *grp, *keys_p, NULL);
if (! val) {
status = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
_notmuch_string_map_set (notmuch->config, absolute_key, val);
normalized_val = _expand_path (notmuch, absolute_key, val);
_notmuch_string_map_set (notmuch->config, absolute_key, normalized_val);
g_free (val);
talloc_free (absolute_key);
talloc_free (normalized_val);
if (status)
goto DONE;
}

View file

@ -117,12 +117,12 @@ test_expect_equal "$(notmuch config get database.path)" \
ln -s `pwd`/mail home/Maildir
add_email_corpus
test_begin_subtest "Relative database path expanded in open"
test_begin_subtest "Relative database path expanded"
notmuch config set database.path Maildir
path=$(notmuch config get database.path)
path=$(notmuch config get database.path | notmuch_dir_sanitize)
count=$(notmuch count '*')
test_expect_equal "${path} ${count}" \
"Maildir 52"
"CWD/home/Maildir 52"
test_begin_subtest "Add config to database"
notmuch new

View file

@ -394,6 +394,30 @@ exit status: 75
EOF
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "Relative database path expanded in new"
ln -s "$PWD/mail" home/Maildir
notmuch config set database.path Maildir
generate_message
NOTMUCH_NEW > OUTPUT
cat <<EOF >EXPECTED
Added 1 new message to the database.
EOF
notmuch config set database.path ${MAIL_DIR}
rm home/Maildir
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "Relative mail root (in db) expanded in new"
ln -s "$PWD/mail" home/Maildir
notmuch config set --database database.mail_root Maildir
generate_message
NOTMUCH_NEW > OUTPUT
cat <<EOF >EXPECTED
Added 1 new message to the database.
EOF
notmuch config set database.mail_root
rm home/Maildir
test_expect_equal_file EXPECTED OUTPUT
add_email_corpus broken
test_begin_subtest "reference loop does not crash"
test_expect_code 0 "notmuch show --format=json id:mid-loop-12@example.org id:mid-loop-21@example.org > OUTPUT"

View file

@ -43,7 +43,7 @@ add_message
# create maildir structure for notmuch-insert
mkdir -p "$MAIL_DIR"/{cur,new,tmp}
for config in traditional profile explicit XDG split; do
for config in traditional profile explicit relative XDG split; do
unset NOTMUCH_PROFILE
notmuch config set database.hook_dir
notmuch config set database.path ${MAIL_DIR}
@ -63,6 +63,11 @@ for config in traditional profile explicit XDG split; do
mkdir -p $HOOK_DIR
notmuch config set database.hook_dir $HOOK_DIR
;;
relative)
HOOK_DIR=${HOME}/.notmuch-hooks
mkdir -p $HOOK_DIR
notmuch config set database.hook_dir .notmuch-hooks
;;
XDG)
HOOK_DIR=${HOME}/.config/notmuch/default/hooks
;;

View file

@ -54,4 +54,23 @@ for key in 'from/subject/message-ID in database' \
restore_database
done
test_begin_subtest "upgrade with configured backup dir"
notmuch config set database.backup_dir ${HOME}/backups
delete_feature 'modification tracking'
notmuch new | grep Backing | notmuch_dir_sanitize | sed 's/dump-[0-9T]*/dump-XXX/' > OUTPUT
cat <<EOF > EXPECTED
Backing up tags to CWD/home/backups/dump-XXX.gz...
EOF
test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "upgrade with relative configured backup dir"
notmuch config set database.backup_dir ${HOME}/backups
delete_feature 'modification tracking'
notmuch new | grep Backing | notmuch_dir_sanitize | sed 's/dump-[0-9T]*/dump-XXX/' > OUTPUT
cat <<EOF > EXPECTED
Backing up tags to CWD/home/backups/dump-XXX.gz...
EOF
test_expect_equal_file EXPECTED OUTPUT
test_done