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 4FA5C429E30 for ; Fri, 28 Oct 2011 20:05:10 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.3 X-Spam-Level: X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_MED=-2.3] 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 y2dUlg6Vm9zN for ; Fri, 28 Oct 2011 20:05:08 -0700 (PDT) Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id DF3ED429E2F for ; Fri, 28 Oct 2011 20:05:03 -0700 (PDT) Received: from zancas.localnet (fctnnbsc36w-156034064058.pppoe-dynamic.High-Speed.nb.bellaliant.net [156.34.64.58]) (authenticated bits=0) by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id p9T34xxR016365 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Sat, 29 Oct 2011 00:05:00 -0300 Received: from bremner by zancas.localnet with local (Exim 4.76) (envelope-from ) id 1RJzEB-0003DJ-5A; Sat, 29 Oct 2011 00:04:59 -0300 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 4/4] notmuch-restore: implement --match functionality Date: Sat, 29 Oct 2011 00:04:51 -0300 Message-Id: <1319857491-12298-5-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.7.6.3 In-Reply-To: <1319857491-12298-1-git-send-email-david@tethera.net> References: <1319406673-7208-1-git-send-email-david@tethera.net> <1319857491-12298-1-git-send-email-david@tethera.net> Cc: David Bremner 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: Sat, 29 Oct 2011 03:05:10 -0000 From: David Bremner notmuch restore --match= will for each message in the dump file, delete any tags from the database matching and add any from the dump file matching . I tried to keep this simple, so in particular turning on regex matching disables one of the optimizations. --- notmuch-restore.c | 16 +++++++++++++--- test/dump-restore | 4 ---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/notmuch-restore.c b/notmuch-restore.c index e5ac162..a1b6b81 100644 --- a/notmuch-restore.c +++ b/notmuch-restore.c @@ -64,7 +64,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) break; case 'm': match_enabled = TRUE; - if ( xregcomp (&match_regex, optarg, REG_EXTENDED) ) + if ( xregcomp (&match_regex, optarg, REG_EXTENDED|REG_NOSUB) ) return 1; break; case '?': @@ -147,6 +147,10 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) { const char *tag = notmuch_tags_get (db_tags); + if (match_enabled && !accumulate && + !regexec (&match_regex, tag, 0, NULL, 0) ) + notmuch_message_remove_tag (message, tag); + if (db_tags_str) db_tags_str = talloc_asprintf_append (db_tags_str, " %s", tag); else @@ -155,14 +159,15 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) if (((file_tags == NULL || *file_tags == '\0') && (db_tags_str == NULL || *db_tags_str == '\0')) || - (file_tags && db_tags_str && strcmp (file_tags, db_tags_str) == 0)) + (!match_enabled && file_tags && db_tags_str && + strcmp (file_tags, db_tags_str) == 0)) { goto NEXT_LINE; } notmuch_message_freeze (message); - if (!accumulate) + if (!accumulate && !match_enabled) notmuch_message_remove_all_tags (message); next = file_tags; @@ -170,6 +175,11 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) tag = strsep (&next, " "); if (*tag == '\0') continue; + + if (match_enabled && + regexec (&match_regex, tag, 0, NULL, 0)) + continue; + status = notmuch_message_add_tag (message, tag); if (status) { fprintf (stderr, diff --git a/test/dump-restore b/test/dump-restore index 18925a4..a4517f6 100755 --- a/test/dump-restore +++ b/test/dump-restore @@ -72,7 +72,6 @@ test_expect_success 'Restoring with trivial match' \ sed 's/inbox\|unread\|signed//g' < dump-ABC_DEF.expected > dump-ABC_DEF-only -test_subtest_known_broken test_expect_success 'Simulate accumulate with match' \ 'notmuch restore < dump.expected && notmuch restore --match="(ABC|DEF)" < dump-ABC_DEF-only && @@ -80,7 +79,6 @@ test_expect_success 'Simulate accumulate with match' \ notmuch restore < dump.expected && test_cmp dump-ABC_DEF.expected dump-simulate.actual' -test_subtest_known_broken test_expect_success 'clear only matched tags' \ 'notmuch restore < dump-ABC_DEF.expected && notmuch restore --match="(ABC|DEF)" < clear.expected && @@ -88,7 +86,6 @@ test_expect_success 'clear only matched tags' \ notmuch restore < dump.expected && test_cmp dump.expected dump-clear-match.actual' -test_subtest_known_broken test_expect_success 'import only matched tags' \ 'notmuch restore < dump.expected && notmuch restore --match="(inbox|unread)" < dump-ABC_DEF.expected && @@ -99,7 +96,6 @@ test_expect_success 'import only matched tags' \ sed 's/inbox\|unread\|signed\|ABC//g' < dump-ABC_DEF.expected > dump-DEF-only sed 's/inbox\|unread\|signed\|DEF//g' < dump-ABC_DEF.expected > dump-ABC-only -test_subtest_known_broken test_expect_success 'combine --match and --accumulate' \ 'notmuch restore < dump.expected && notmuch restore --match="(ABC|DEF)" < dump-ABC-only && -- 1.7.6.3