Re: Hi all
[notmuch-archives.git] / 67 / 481743f732c4a90bf6550da752518e4bcf1e8e
1 Return-Path: <bremner@tethera.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 4FA5C429E30\r
6         for <notmuch@notmuchmail.org>; Fri, 28 Oct 2011 20:05:10 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id y2dUlg6Vm9zN for <notmuch@notmuchmail.org>;\r
16         Fri, 28 Oct 2011 20:05:08 -0700 (PDT)\r
17 Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])\r
18         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id DF3ED429E2F\r
21         for <notmuch@notmuchmail.org>; Fri, 28 Oct 2011 20:05:03 -0700 (PDT)\r
22 Received: from zancas.localnet\r
23         (fctnnbsc36w-156034064058.pppoe-dynamic.High-Speed.nb.bellaliant.net\r
24         [156.34.64.58]) (authenticated bits=0)\r
25         by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id p9T34xxR016365\r
26         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);\r
27         Sat, 29 Oct 2011 00:05:00 -0300\r
28 Received: from bremner by zancas.localnet with local (Exim 4.76)\r
29         (envelope-from <bremner@tethera.net>)\r
30         id 1RJzEB-0003DJ-5A; Sat, 29 Oct 2011 00:04:59 -0300\r
31 From: David Bremner <david@tethera.net>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH 4/4] notmuch-restore: implement --match functionality\r
34 Date: Sat, 29 Oct 2011 00:04:51 -0300\r
35 Message-Id: <1319857491-12298-5-git-send-email-david@tethera.net>\r
36 X-Mailer: git-send-email 1.7.6.3\r
37 In-Reply-To: <1319857491-12298-1-git-send-email-david@tethera.net>\r
38 References: <1319406673-7208-1-git-send-email-david@tethera.net>\r
39         <1319857491-12298-1-git-send-email-david@tethera.net>\r
40 Cc: David Bremner <bremner@debian.org>\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.13\r
43 Precedence: list\r
44 List-Id: "Use and development of the notmuch mail system."\r
45         <notmuch.notmuchmail.org>\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
49 List-Post: <mailto:notmuch@notmuchmail.org>\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
53 X-List-Received-Date: Sat, 29 Oct 2011 03:05:10 -0000\r
54 \r
55 From: David Bremner <bremner@debian.org>\r
56 \r
57 notmuch restore --match=<regex> will for each message in the dump\r
58 file, delete any tags from the database matching <regex> and add any\r
59 from the dump file matching <regex>.\r
60 \r
61 I tried to keep this simple, so in particular turning on regex\r
62 matching disables one of the optimizations.\r
63 ---\r
64  notmuch-restore.c |   16 +++++++++++++---\r
65  test/dump-restore |    4 ----\r
66  2 files changed, 13 insertions(+), 7 deletions(-)\r
67 \r
68 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
69 index e5ac162..a1b6b81 100644\r
70 --- a/notmuch-restore.c\r
71 +++ b/notmuch-restore.c\r
72 @@ -64,7 +64,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
73             break;\r
74         case 'm':\r
75             match_enabled = TRUE;\r
76 -           if ( xregcomp (&match_regex, optarg, REG_EXTENDED) )\r
77 +           if ( xregcomp (&match_regex, optarg, REG_EXTENDED|REG_NOSUB) )\r
78                 return 1;\r
79             break;\r
80         case '?':\r
81 @@ -147,6 +147,10 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
82         {\r
83             const char *tag = notmuch_tags_get (db_tags);\r
84  \r
85 +           if (match_enabled && !accumulate &&\r
86 +               !regexec (&match_regex, tag, 0, NULL, 0) )\r
87 +               notmuch_message_remove_tag (message, tag);\r
88 +\r
89             if (db_tags_str)\r
90                 db_tags_str = talloc_asprintf_append (db_tags_str, " %s", tag);\r
91             else\r
92 @@ -155,14 +159,15 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
93  \r
94         if (((file_tags == NULL || *file_tags == '\0') &&\r
95              (db_tags_str == NULL || *db_tags_str == '\0')) ||\r
96 -           (file_tags && db_tags_str && strcmp (file_tags, db_tags_str) == 0))\r
97 +           (!match_enabled && file_tags && db_tags_str && \r
98 +            strcmp (file_tags, db_tags_str) == 0))\r
99         {\r
100             goto NEXT_LINE;\r
101         }\r
102  \r
103         notmuch_message_freeze (message);\r
104  \r
105 -       if (!accumulate)\r
106 +       if (!accumulate && !match_enabled)\r
107             notmuch_message_remove_all_tags (message);\r
108  \r
109         next = file_tags;\r
110 @@ -170,6 +175,11 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
111             tag = strsep (&next, " ");\r
112             if (*tag == '\0')\r
113                 continue;\r
114 +\r
115 +           if (match_enabled &&\r
116 +               regexec (&match_regex, tag, 0, NULL, 0))\r
117 +               continue;\r
118 +\r
119             status = notmuch_message_add_tag (message, tag);\r
120             if (status) {\r
121                 fprintf (stderr,\r
122 diff --git a/test/dump-restore b/test/dump-restore\r
123 index 18925a4..a4517f6 100755\r
124 --- a/test/dump-restore\r
125 +++ b/test/dump-restore\r
126 @@ -72,7 +72,6 @@ test_expect_success 'Restoring with trivial match' \\r
127  \r
128  sed 's/inbox\|unread\|signed//g' < dump-ABC_DEF.expected > dump-ABC_DEF-only\r
129  \r
130 -test_subtest_known_broken\r
131  test_expect_success 'Simulate accumulate with match' \\r
132    'notmuch restore < dump.expected &&\r
133     notmuch restore --match="(ABC|DEF)" < dump-ABC_DEF-only &&\r
134 @@ -80,7 +79,6 @@ test_expect_success 'Simulate accumulate with match' \\r
135     notmuch restore < dump.expected &&\r
136     test_cmp dump-ABC_DEF.expected dump-simulate.actual'\r
137  \r
138 -test_subtest_known_broken\r
139  test_expect_success 'clear only matched tags' \\r
140    'notmuch restore < dump-ABC_DEF.expected &&\r
141     notmuch restore --match="(ABC|DEF)" < clear.expected &&\r
142 @@ -88,7 +86,6 @@ test_expect_success 'clear only matched tags' \\r
143     notmuch restore < dump.expected &&\r
144     test_cmp dump.expected dump-clear-match.actual'\r
145  \r
146 -test_subtest_known_broken\r
147  test_expect_success 'import only matched tags' \\r
148    'notmuch restore < dump.expected &&\r
149     notmuch restore --match="(inbox|unread)" < dump-ABC_DEF.expected &&\r
150 @@ -99,7 +96,6 @@ test_expect_success 'import only matched tags' \\r
151  sed 's/inbox\|unread\|signed\|ABC//g' < dump-ABC_DEF.expected > dump-DEF-only\r
152  sed 's/inbox\|unread\|signed\|DEF//g' < dump-ABC_DEF.expected > dump-ABC-only\r
153  \r
154 -test_subtest_known_broken\r
155  test_expect_success 'combine --match and --accumulate' \\r
156    'notmuch restore < dump.expected &&\r
157     notmuch restore --match="(ABC|DEF)" < dump-ABC-only &&\r
158 -- \r
159 1.7.6.3\r
160 \r