From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 40DA6431FD0 for ; Thu, 29 Sep 2011 10:37:53 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5RP3VPZiHZ-d for ; Thu, 29 Sep 2011 10:37:52 -0700 (PDT) Received: from smtprelay04.ispgateway.de (smtprelay04.ispgateway.de [80.67.31.38]) by olra.theworths.org (Postfix) with ESMTP id 0E24F431FB6 for ; Thu, 29 Sep 2011 10:37:52 -0700 (PDT) Received: from [87.180.87.168] (helo=stokes.schwinge.homeip.net) by smtprelay04.ispgateway.de with esmtpa (Exim 4.68) (envelope-from ) id 1R9KYP-0004n3-Dc for notmuch@notmuchmail.org; Thu, 29 Sep 2011 19:37:49 +0200 Received: (qmail 24622 invoked from network); 29 Sep 2011 17:37:44 -0000 Received: from kepler.schwinge.homeip.net (192.168.111.7) by stokes.schwinge.homeip.net with QMQP; 29 Sep 2011 17:37:44 -0000 Received: (nullmailer pid 29670 invoked by uid 1000); Thu, 29 Sep 2011 17:37:44 -0000 From: Thomas Schwinge To: notmuch@notmuchmail.org Subject: [PATCH, v2] notmuch restore --accumulate Date: Thu, 29 Sep 2011 19:37:37 +0200 Message-Id: <1317317857-29636-1-git-send-email-thomas@schwinge.name> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1317317811-29540-1-git-send-email-thomas@schwinge.name> References: <1317317811-29540-1-git-send-email-thomas@schwinge.name> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Df-Sender: dGhvbWFzQHNjaHdpbmdlLm5hbWU= X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Sep 2011 17:37:53 -0000 From: Thomas Schwinge The --accumulate switch causes the union of the existing and new tags to be applied, instead of replacing each message's tags as they are read in from the dump file. --- Hi! Beware that I have not yet used this new functionality in the wild. ;-) (But I do plan to do so, soon.) And, I think that the testsuite enhancements cover quite a number of real-world scenarios. This is v2; it addresses Jameson's and Austin's comments. Grüße, Thomas --- NEWS | 9 +++++++++ notmuch-restore.c | 42 +++++++++++++++++++++++++++++++++--------- notmuch.1 | 14 ++++++++++---- notmuch.c | 10 +++++++--- test/dump-restore | 10 ---------- 5 files changed, 59 insertions(+), 26 deletions(-) diff --git a/NEWS b/NEWS index ee84e9a..2a184ef 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,15 @@ Correct handling of interruptions during "notmuch new" detect messages on resume, or leave the database in a state temporarily or permanently inconsistent with the mail store. +New command-line features +------------------------- + +Add "notmuch restore --accumulate" option + + The --accumulate switch causes the union of the existing and new tags to be + applied, instead of replacing each message's tags as they are read in from + the dump file. + Library changes --------------- diff --git a/notmuch-restore.c b/notmuch-restore.c index f095f64..5aad60c 100644 --- a/notmuch-restore.c +++ b/notmuch-restore.c @@ -31,7 +31,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) size_t line_size; ssize_t line_len; regex_t regex; - int rerr; + notmuch_bool_t accumulate; + int i, rerr; config = notmuch_config_open (ctx, NULL, NULL); if (config == NULL) @@ -44,14 +45,28 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config); - if (argc) { - input = fopen (argv[0], "r"); - if (input == NULL) { - fprintf (stderr, "Error opening %s for reading: %s\n", - argv[0], strerror (errno)); - return 1; + accumulate = FALSE; + input = NULL; + for (i = 0; i < argc; i++) { + if (STRNCMP_LITERAL (argv[i], "--accumulate") == 0) { + accumulate = TRUE; + } else { + if (input == NULL) { + input = fopen (argv[i], "r"); + if (input == NULL) { + fprintf (stderr, "Error opening %s for reading: %s\n", + argv[i], strerror (errno)); + return 1; + } + } else { + fprintf (stderr, + "Cannot read dump from more than one file: %s\n", + argv[i]); + return 1; + } } - } else { + } + if (input == NULL) { printf ("No filename given. Reading dump from stdin.\n"); input = stdin; } @@ -94,6 +109,13 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) goto NEXT_LINE; } + /* In order to detect missing messages, this check/optimization is + * intentionally done *after* first finding the message. */ + if (accumulate && (file_tags == NULL || *file_tags == '\0')) + { + goto NEXT_LINE; + } + db_tags_str = NULL; for (db_tags = notmuch_message_get_tags (message); notmuch_tags_valid (db_tags); @@ -115,7 +137,9 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) } notmuch_message_freeze (message); - notmuch_message_remove_all_tags (message); + + if (!accumulate) + notmuch_message_remove_all_tags (message); next = file_tags; while (next) { diff --git a/notmuch.1 b/notmuch.1 index 5a8c83d..883371d 100644 --- a/notmuch.1 +++ b/notmuch.1 @@ -454,7 +454,7 @@ section below for details of the supported syntax for . The .BR dump " and " restore commands can be used to create a textual dump of email tags for backup -purposes, and to restore from that dump +purposes, and to restore from that dump. .RS 4 .TP 4 @@ -462,17 +462,19 @@ purposes, and to restore from that dump Creates a plain-text dump of the tags of each message. -The output is to the given filename, if any, or to stdout. +The output is written to the given filename, if any, or to stdout. These tags are the only data in the notmuch database that can't be recreated from the messages themselves. The output of notmuch dump is therefore the only critical thing to backup (and much more friendly to incremental backup than the native database files.) .TP -.BR restore " " +.BR restore " [--accumulate] []" Restores the tags from the given file (see -.BR "notmuch dump" "." +.BR "notmuch dump" ")." + +The input is read from the given filename, if any, or from stdin. Note: The dump file format is specifically chosen to be compatible with the format of files produced by sup-dump. @@ -480,6 +482,10 @@ So if you've previously been using sup for mail, then the .B "notmuch restore" command provides you a way to import all of your tags (or labels as sup calls them). + +The --accumulate switch causes the union of the existing and new tags to be +applied, instead of replacing each message's tags as they are read in from the +dump file. .RE The diff --git a/notmuch.c b/notmuch.c index f9d6629..9a9b0a2 100644 --- a/notmuch.c +++ b/notmuch.c @@ -377,20 +377,24 @@ static command_t commands[] = { { "dump", notmuch_dump_command, "[]", "Create a plain-text dump of the tags for each message.", - "\tOutput is to the given filename, if any, or to stdout.\n" + "\tOutput is written to the given filename, if any, or to stdout.\n" "\tThese tags are the only data in the notmuch database\n" "\tthat can't be recreated from the messages themselves.\n" "\tThe output of notmuch dump is therefore the only\n" "\tcritical thing to backup (and much more friendly to\n" "\tincremental backup than the native database files.)" }, { "restore", notmuch_restore_command, - "", + "[--accumulate] []", "Restore the tags from the given dump file (see 'dump').", + "\tInput is read from the given filename, if any, or from stdin.\n" "\tNote: The dump file format is specifically chosen to be\n" "\tcompatible with the format of files produced by sup-dump.\n" "\tSo if you've previously been using sup for mail, then the\n" "\t\"notmuch restore\" command provides you a way to import\n" - "\tall of your tags (or labels as sup calls them)." }, + "\tall of your tags (or labels as sup calls them).\n" + "\tThe --accumulate switch causes the union of the existing and new\n" + "\ttags to be applied, instead of replacing each message's tags as\n" + "\tthey are read in from the dump file."}, { "config", notmuch_config_command, "[get|set]
. [value ...]", "Get or set settings in the notmuch configuration file.", diff --git a/test/dump-restore b/test/dump-restore index d253756..be0eb2a 100755 --- a/test/dump-restore +++ b/test/dump-restore @@ -24,8 +24,6 @@ test_expect_success 'Clearing all tags' \ notmuch dump clear.actual && test_cmp clear.expected clear.actual' -# Missing notmuch restore --accumulate. -test_subtest_known_broken test_expect_success 'Accumulate original tags' \ 'notmuch tag +ABC +DEF -- $search_term && notmuch restore --accumulate < dump.expected && @@ -42,27 +40,19 @@ test_expect_success 'Restore with nothing to do' \ notmuch dump > dump.actual && test_cmp dump.expected dump.actual' -# Missing notmuch restore --accumulate. -test_subtest_known_broken test_expect_success 'Restore with nothing to do, II' \ 'notmuch restore --accumulate dump.expected && notmuch dump dump.actual && test_cmp dump.expected dump.actual' -# Missing notmuch restore --accumulate. -test_subtest_known_broken test_expect_success 'Restore with nothing to do, III' \ 'notmuch restore --accumulate < clear.expected && notmuch dump dump.actual && test_cmp dump.expected dump.actual' -# notmuch restore currently only considers the first argument. -test_subtest_known_broken test_expect_success 'Invalid restore invocation' \ 'test_must_fail notmuch restore dump.expected another_one' -# The follwing test already succeeds due to notmuch restore currently only -# considering the first argument. test_expect_success 'Invalid restore invocation, II' \ 'test_must_fail notmuch restore --accumulate dump.expected another_one' -- tg: (b968722..) t/restore-accumulate (depends on: master t/restore-accumulate-test)