From a663783343cb992d132ecc18e4e4d4e37bbf12e9 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sat, 8 May 2021 09:11:11 -0300 Subject: [PATCH 1/8] test: add known broken tests for notuch-{before,after}-tag-hook These tests illustrate the bug reported in id:87v97ytd2s.fsf@fastmail.fm --- test/T310-emacs.sh | 24 ++++++++++++++++++++++++ test/test-lib.el | 3 +++ 2 files changed, 27 insertions(+) diff --git a/test/T310-emacs.sh b/test/T310-emacs.sh index 78ac19a8..5ebc8e66 100755 --- a/test/T310-emacs.sh +++ b/test/T310-emacs.sh @@ -161,6 +161,30 @@ test_emacs "(notmuch-show \"$os_x_darwin_thread\") output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize) test_expect_equal "$output" "thread:XXX 2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)" +test_begin_subtest "notmuch-show: before-tag-hook is run, variables are defined" +test_subtest_known_broken +output=$(test_emacs '(let ((notmuch-test-tag-hook-output nil) + (notmuch-before-tag-hook (function notmuch-test-tag-hook))) + (notmuch-show "id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com") + (execute-kbd-macro "+activate-hook\n") + (execute-kbd-macro "-activate-hook\n") + notmuch-test-tag-hook-output)') +test_expect_equal "$output" \ +'(("id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com" "-activate-hook") + ("id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com" "+activate-hook"))' + +test_begin_subtest "notmuch-show: after-tag-hook is run, variables are defined" +test_subtest_known_broken +output=$(test_emacs '(let ((notmuch-test-tag-hook-output nil) + (notmuch-after-tag-hook (function notmuch-test-tag-hook))) + (notmuch-show "id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com") + (execute-kbd-macro "+activate-hook\n") + (execute-kbd-macro "-activate-hook\n") + notmuch-test-tag-hook-output)') +test_expect_equal "$output" \ +'(("id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com" "-activate-hook") + ("id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com" "+activate-hook"))' + test_begin_subtest "Message with .. in Message-Id:" add_message [id]=123..456@example '[subject]="Message with .. in Message-Id"' test_emacs '(notmuch-search "id:\"123..456@example\"") diff --git a/test/test-lib.el b/test/test-lib.el index 4de5b292..32d53736 100644 --- a/test/test-lib.el +++ b/test/test-lib.el @@ -99,6 +99,9 @@ running, quit if it terminated." (add-hook 'notmuch-hello-refresh-hook (lambda () (cl-incf notmuch-hello-refresh-hook-counter))) +(defvar notmuch-test-tag-hook-output nil) +(defun notmuch-test-tag-hook () (push (cons query tag-changes) notmuch-test-tag-hook-output)) + (defun notmuch-test-mark-links () "Enclose links in the current buffer with << and >>." ;; Links are often created by jit-lock functions From 319dcfb50e5bc929719167afa353e19632ea55f3 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sat, 8 May 2021 09:11:12 -0300 Subject: [PATCH 2/8] emacs: restore tag-changes and query bindings for tag hooks notmuch-before-tag-hook and notmuch-after-tag-hook are supposed to have access to two dynamic variables, tag-changes and query, but these were lost with the switch to lexical binding in fc4cda07 (emacs: use lexical-bindings in all libraries, 2021-01-13). Add a variant of Emacs's dlet (not available until Emacs 28) and use it in notmuch-tag to expose tag-changes and query to the hooks. --- emacs/notmuch-compat.el | 12 ++++++++++++ emacs/notmuch-tag.el | 8 ++++++-- test/T310-emacs.sh | 2 -- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/emacs/notmuch-compat.el b/emacs/notmuch-compat.el index ad134dfe..179bf59c 100644 --- a/emacs/notmuch-compat.el +++ b/emacs/notmuch-compat.el @@ -41,6 +41,18 @@ (unless (fboundp 'message--fold-long-headers) (add-hook 'message-header-hook 'notmuch-message--fold-long-headers)) +;; `dlet' isn't available until Emacs 28.1. Below is a copy, with the +;; addition of `with-no-warnings'. +(defmacro notmuch-dlet (binders &rest body) + "Like `let*' but using dynamic scoping." + (declare (indent 1) (debug let)) + `(let (_) + (with-no-warnings ; Quiet "lacks a prefix" warning. + ,@(mapcar (lambda (binder) + `(defvar ,(if (consp binder) (car binder) binder))) + binders)) + (let* ,binders ,@body))) + (provide 'notmuch-compat) ;;; notmuch-compat.el ends here diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el index f348d4ae..ebccb5a0 100644 --- a/emacs/notmuch-tag.el +++ b/emacs/notmuch-tag.el @@ -486,7 +486,9 @@ notmuch-after-tag-hook will be run." (unless query (error "Nothing to tag!")) (when tag-changes - (run-hooks 'notmuch-before-tag-hook) + (notmuch-dlet ((tag-changes tag-changes) + (query query)) + (run-hooks 'notmuch-before-tag-hook)) (if (<= (length query) notmuch-tag-argument-limit) (apply 'notmuch-call-notmuch-process "tag" (append tag-changes (list "--" query))) @@ -494,7 +496,9 @@ notmuch-after-tag-hook will be run." (let ((batch-op (concat (mapconcat #'notmuch-hex-encode tag-changes " ") " -- " query))) (notmuch-call-notmuch-process :stdin-string batch-op "tag" "--batch"))) - (run-hooks 'notmuch-after-tag-hook))) + (notmuch-dlet ((tag-changes tag-changes) + (query query)) + (run-hooks 'notmuch-after-tag-hook)))) (defun notmuch-tag-change-list (tags &optional reverse) "Convert TAGS into a list of tag changes. diff --git a/test/T310-emacs.sh b/test/T310-emacs.sh index 5ebc8e66..e6489246 100755 --- a/test/T310-emacs.sh +++ b/test/T310-emacs.sh @@ -162,7 +162,6 @@ output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize) test_expect_equal "$output" "thread:XXX 2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)" test_begin_subtest "notmuch-show: before-tag-hook is run, variables are defined" -test_subtest_known_broken output=$(test_emacs '(let ((notmuch-test-tag-hook-output nil) (notmuch-before-tag-hook (function notmuch-test-tag-hook))) (notmuch-show "id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com") @@ -174,7 +173,6 @@ test_expect_equal "$output" \ ("id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com" "+activate-hook"))' test_begin_subtest "notmuch-show: after-tag-hook is run, variables are defined" -test_subtest_known_broken output=$(test_emacs '(let ((notmuch-test-tag-hook-output nil) (notmuch-after-tag-hook (function notmuch-test-tag-hook))) (notmuch-show "id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com") From 0e8795b28c809861e81dd50653a5355333cbcd59 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sat, 8 May 2021 09:11:13 -0300 Subject: [PATCH 3/8] NEWS: add NEWS for notmuch-{before,after}-tag-hook fixes --- NEWS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/NEWS b/NEWS index 91ebaa0d..d482f1cd 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,9 @@ Notmuch 0.32.1 (UNRELEASED) =========================== +General +------- + 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`. @@ -9,6 +12,12 @@ Reload certain metadata from Xapian database in notmuch_database_reopen. This fixes a bug when adding messages to the database in a pre-new hook. +Emacs +----- + +Restore the dynamically bound variables `tag-changes` and `query` in +in `notmuch-before-tag-hook` and `notmuch-after-tag-hook`. + Notmuch 0.32 (2021-05-02) ========================= From b3258244c84a7673db39c46cad96ddb63b131dae Mon Sep 17 00:00:00 2001 From: David Bremner Date: Mon, 10 May 2021 07:39:18 -0300 Subject: [PATCH 4/8] lib/open: restore default database path of $HOME/mail Although this default worked for "notmuch config get", it didn't work most other places. Restore the previous functionality, with the wrinkle that XDG locations will shadow $HOME/mail if they exist. This fixes a bug reported by Jack Kamm in id:87eeefdc8b.fsf@gmail.com --- lib/open.cc | 19 ++++++++++++++++++- test/T055-path-config.sh | 22 ++++++++++++++++++++-- test/T560-lib-error.sh | 4 ++-- test/T590-libconfig.sh | 4 ++-- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index 1e9c86fe..3325e725 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -209,8 +209,25 @@ _choose_database_path (void *ctx, } } if (! *database_path) { + notmuch_status_t status; + *database_path = _xdg_dir (ctx, "XDG_DATA_HOME", ".local/share", profile); - *split = true; + status = _db_dir_exists (*database_path, message); + if (status) { + *database_path = NULL; + } else { + *split = true; + } + } + + if (! *database_path) { + notmuch_status_t status; + + *database_path = talloc_asprintf (ctx, "%s/mail", getenv ("HOME")); + status = _db_dir_exists (*database_path, message); + if (status) { + *database_path = NULL; + } } if (*database_path == NULL) { diff --git a/test/T055-path-config.sh b/test/T055-path-config.sh index 2045a555..8ef76aed 100755 --- a/test/T055-path-config.sh +++ b/test/T055-path-config.sh @@ -16,6 +16,7 @@ restore_config () { unset DATABASE_PATH unset NOTMUCH_PROFILE unset XAPIAN_PATH + rm -f "$HOME/mail" cp notmuch-config-backup.${test_name} ${NOTMUCH_CONFIG} } @@ -42,6 +43,18 @@ symlink_config () { unset DATABASE_PATH } + +home_mail_config () { + local dir + backup_config + dir="${HOME}/mail" + ln -s $MAIL_DIR $dir + notmuch config set database.path + notmuch config set database.mail_root + XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian" + unset DATABASE_PATH +} + xdg_config () { local dir local profile=${1:-default} @@ -66,7 +79,7 @@ xdg_config () { notmuch --config=${CONFIG_PATH} config set database.path } -for config in traditional split XDG XDG+profile symlink; do +for config in traditional split XDG XDG+profile symlink home_mail; do #start each set of tests with an known set of messages add_email_corpus @@ -90,6 +103,9 @@ for config in traditional split XDG XDG+profile symlink; do symlink) symlink_config ;; + home_mail) + home_mail_config + ;; esac test_begin_subtest "count ($config)" @@ -236,7 +252,9 @@ EOF test_begin_subtest "Config list ($config)" notmuch config list | notmuch_dir_sanitize | sed -e "s/^database.backup_dir=.*$/database.backup_dir/" \ -e "s/^database.hook_dir=.*$/database.hook_dir/" \ - -e "s/^database.path=.*$/database.path/" > OUTPUT + -e "s/^database.path=.*$/database.path/" \ + -e "s,^database.mail_root=CWD/home/mail,database.mail_root=MAIL_DIR," \ + > OUTPUT cat < EXPECTED built_with.compact=true built_with.field_processor=true diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh index 89447e9a..1f4482cb 100755 --- a/test/T560-lib-error.sh +++ b/test/T560-lib-error.sh @@ -22,7 +22,7 @@ EOF cat <<'EOF' >EXPECTED == stdout == == stderr == -Error: Cannot open database at CWD/home/.local/share/notmuch/default: No such file or directory. +Error: could not locate database. EOF test_expect_equal_file EXPECTED OUTPUT @@ -93,7 +93,7 @@ EOF cat <<'EOF' >EXPECTED == stdout == == stderr == -Error: Cannot open database at CWD/home/.local/share/notmuch/default: No such file or directory. +Error: could not locate database. EOF test_expect_equal_file EXPECTED OUTPUT diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh index 51dd29c8..745e1bb4 100755 --- a/test/T590-libconfig.sh +++ b/test/T590-libconfig.sh @@ -546,8 +546,8 @@ cat <<'EOF' >EXPECTED == stdout == == stderr == error opening database -Something went wrong trying to read or write a file -Error: Cannot open database at CWD/home/.local/share/notmuch/default: No such file or directory. +No database found +Error: could not locate database. EOF test_expect_equal_file EXPECTED OUTPUT From 44881fa53ea99e24756e497f2de0f29cfa9cd857 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sat, 15 May 2021 08:52:47 -0300 Subject: [PATCH 5/8] NEWS: add news for $HOME/mail fix --- NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS b/NEWS index d482f1cd..124d0b53 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,9 @@ Reload certain metadata from Xapian database in notmuch_database_reopen. This fixes a bug when adding messages to the database in a pre-new hook. +Fix default of `$HOME/mail` for `database.path`. In release 0.32, this +default worked only in "notmuch config". + Emacs ----- From 6d5531da0c4e9abf86be776567f8e32d4ccbd12d Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sat, 15 May 2021 08:59:01 -0300 Subject: [PATCH 6/8] version: bump to 0.32.1 --- bindings/python-cffi/version.txt | 2 +- bindings/python/notmuch/version.py | 2 +- version.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/python-cffi/version.txt b/bindings/python-cffi/version.txt index 00d0c14d..fd9620c0 100644 --- a/bindings/python-cffi/version.txt +++ b/bindings/python-cffi/version.txt @@ -1 +1 @@ -0.32 +0.32.1 diff --git a/bindings/python/notmuch/version.py b/bindings/python/notmuch/version.py index c9f31763..fc867ea7 100644 --- a/bindings/python/notmuch/version.py +++ b/bindings/python/notmuch/version.py @@ -1,3 +1,3 @@ # this file should be kept in sync with ../../../version -__VERSION__ = '0.32' +__VERSION__ = '0.32.1' SOVERSION = '5' diff --git a/version.txt b/version.txt index 00d0c14d..fd9620c0 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.32 +0.32.1 From 57c62c3aeb7cbc61b42e4919230e8f0d77101055 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sat, 15 May 2021 09:03:19 -0300 Subject: [PATCH 7/8] debian: changelog for 0.32.1-1 --- debian/changelog | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/debian/changelog b/debian/changelog index 7f14b438..a813c59d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +notmuch (0.32.1-1) experimental; urgency=medium + + * New upstream bugfix release + * Configuration bug fixes (see /usr/share/doc/notmuch/NEWS.gz) + * Bug fix for {pre,after}-tag hooks in emacs, related to lexical scope + transition. + + -- David Bremner Sat, 15 May 2021 09:01:27 -0300 + notmuch (0.32-1) experimental; urgency=medium * New upstream release From b580009e2bc69efb019983bf2f7dc5052c19545a Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sat, 15 May 2021 09:04:20 -0300 Subject: [PATCH 8/8] NEWS: finalize release date --- NEWS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 124d0b53..e1fa2d73 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -Notmuch 0.32.1 (UNRELEASED) +Notmuch 0.32.1 (2021-05-15) =========================== General