cli/compact: convert to new configuration framework

Switch to the newly created API function notmuch_database_compact_db,
which takes the database opened in main().
This commit is contained in:
David Bremner 2020-12-23 23:45:23 -04:00
parent 5232462dcf
commit f118ef3c3d
3 changed files with 18 additions and 5 deletions

View file

@ -27,9 +27,8 @@ status_update_cb (const char *msg, unused (void *closure))
} }
int int
notmuch_compact_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) notmuch_compact_command (unused(notmuch_config_t *config), notmuch_database_t *notmuch, int argc, char *argv[])
{ {
const char *path = notmuch_config_get_database_path (config);
const char *backup_path = NULL; const char *backup_path = NULL;
notmuch_status_t ret; notmuch_status_t ret;
bool quiet = false; bool quiet = false;
@ -55,7 +54,7 @@ notmuch_compact_command (notmuch_config_t *config, unused(notmuch_database_t *no
if (! quiet) if (! quiet)
printf ("Compacting database...\n"); printf ("Compacting database...\n");
ret = notmuch_database_compact (path, backup_path, ret = notmuch_database_compact_db (notmuch, backup_path,
quiet ? NULL : status_update_cb, NULL); quiet ? NULL : status_update_cb, NULL);
if (ret) { if (ret) {
fprintf (stderr, "Compaction failed: %s\n", notmuch_status_to_string (ret)); fprintf (stderr, "Compaction failed: %s\n", notmuch_status_to_string (ret));

View file

@ -163,7 +163,7 @@ static command_t commands[] = {
"Create a plain-text dump of the tags for each message." }, "Create a plain-text dump of the tags for each message." },
{ "restore", notmuch_restore_command, NOTMUCH_COMMAND_DATABASE_EARLY | NOTMUCH_COMMAND_DATABASE_WRITE, { "restore", notmuch_restore_command, NOTMUCH_COMMAND_DATABASE_EARLY | NOTMUCH_COMMAND_DATABASE_WRITE,
"Restore the tags from the given dump file (see 'dump')." }, "Restore the tags from the given dump file (see 'dump')." },
{ "compact", notmuch_compact_command, NOTMUCH_COMMAND_CONFIG_OPEN, { "compact", notmuch_compact_command, NOTMUCH_COMMAND_DATABASE_EARLY | NOTMUCH_COMMAND_DATABASE_WRITE,
"Compact the notmuch database." }, "Compact the notmuch database." },
{ "reindex", notmuch_reindex_command, NOTMUCH_COMMAND_DATABASE_EARLY | NOTMUCH_COMMAND_DATABASE_WRITE, { "reindex", notmuch_reindex_command, NOTMUCH_COMMAND_DATABASE_EARLY | NOTMUCH_COMMAND_DATABASE_WRITE,
"Re-index all messages matching the search terms." }, "Re-index all messages matching the search terms." },

View file

@ -447,4 +447,18 @@ EOF
restore_config restore_config
test_expect_equal_file EXPECTED OUTPUT test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "running compact (xdg)"
xdg_config
notmuch compact
output=$(notmuch count '*')
restore_config
test_expect_equal "52" "$output"
test_begin_subtest "running compact (xdg + profile)"
xdg_config ${RANDOM}
notmuch compact
output=$(notmuch count '*')
restore_config
test_expect_equal "52" "$output"
test_done test_done