[PATCH 6/8] CLI: refactor dumping of tags.
[notmuch-archives.git] / 12 / e2b1ecc8c71d3c1bac08ebe69663f71d6a558c
1 Return-Path: <tomi.ollila@iki.fi>\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 A11FC431FBF\r
6         for <notmuch@notmuchmail.org>; Sun,  6 Jan 2013 07:28:12 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 ho2UNqO0ds9I for <notmuch@notmuchmail.org>;\r
16         Sun,  6 Jan 2013 07:28:11 -0800 (PST)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id 99EB0431FAE\r
19         for <notmuch@notmuchmail.org>; Sun,  6 Jan 2013 07:28:11 -0800 (PST)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id 224B51000D0;\r
22         Sun,  6 Jan 2013 17:28:02 +0200 (EET)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: david@tethera.net, notmuch@notmuchmail.org\r
25 Subject: Re: [Patch v2] notmuch-restore: handle empty input file,\r
26         leading blank lines and comments.\r
27 In-Reply-To: <1357481096-31254-1-git-send-email-david@tethera.net>\r
28 References: <m2wqvri8k3.fsf@guru.guru-group.fi>\r
29         <1357481096-31254-1-git-send-email-david@tethera.net>\r
30 User-Agent: Notmuch/0.14+236~ge6d0259 (http://notmuchmail.org) Emacs/24.2.1\r
31         (x86_64-unknown-linux-gnu)\r
32 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
33         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
34         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
35 Date: Sun, 06 Jan 2013 17:28:01 +0200\r
36 Message-ID: <m2wqvqfi0u.fsf@guru.guru-group.fi>\r
37 MIME-Version: 1.0\r
38 Content-Type: text/plain\r
39 Cc: David Bremner <bremner@debian.org>\r
40 X-BeenThere: notmuch@notmuchmail.org\r
41 X-Mailman-Version: 2.1.13\r
42 Precedence: list\r
43 List-Id: "Use and development of the notmuch mail system."\r
44         <notmuch.notmuchmail.org>\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
48 List-Post: <mailto:notmuch@notmuchmail.org>\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
52 X-List-Received-Date: Sun, 06 Jan 2013 15:28:12 -0000\r
53 \r
54 On Sun, Jan 06 2013, david@tethera.net wrote:\r
55 \r
56 > From: David Bremner <bremner@debian.org>\r
57 >\r
58 > This patch corrects several undesirable behaviours:\r
59 >\r
60 > 1) Empty files were not detected, leading to buffer read overrun.\r
61 >\r
62 > 2) An initial blank line cause restore to silently abort\r
63 >\r
64 > 3) Initial comment line caused format detection to fail\r
65 > ---\r
66 \r
67 LGTM.\r
68 \r
69 Tomi\r
70 \r
71 >  notmuch-restore.c |   18 +++++++++++++-----\r
72 >  test/dump-restore |    3 ---\r
73 >  2 files changed, 13 insertions(+), 8 deletions(-)\r
74 >\r
75 > diff --git a/notmuch-restore.c b/notmuch-restore.c\r
76 > index d43546d..f436989 100644\r
77 > --- a/notmuch-restore.c\r
78 > +++ b/notmuch-restore.c\r
79 > @@ -181,11 +181,6 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
80 >                argv[opt_index]);\r
81 >       return 1;\r
82 >      }\r
83 > -    char *p;\r
84 > -\r
85 > -    line_len = getline (&line, &line_size, input);\r
86 > -    if (line_len == 0)\r
87 > -     return 0;\r
88 >  \r
89 >      tag_ops = tag_op_list_create (ctx);\r
90 >      if (tag_ops == NULL) {\r
91 > @@ -193,6 +188,19 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
92 >       return 1;\r
93 >      }\r
94 >  \r
95 > +    do {\r
96 > +     line_len = getline (&line, &line_size, input);\r
97 > +\r
98 > +     /* empty input file not considered an error */\r
99 > +     if (line_len < 0)\r
100 > +         return 0;\r
101 > +\r
102 > +    } while ((line_len == 0) ||\r
103 > +          (line[0] == '#') ||\r
104 > +          /* the cast is safe because we checked about for line_len < 0 */\r
105 > +          (strspn (line, " \t\n") == (unsigned)line_len));\r
106 > +\r
107 > +    char *p;\r
108 >      for (p = line; (input_format == DUMP_FORMAT_AUTO) && *p; p++) {\r
109 >       if (*p == '(')\r
110 >           input_format = DUMP_FORMAT_SUP;\r
111 > diff --git a/test/dump-restore b/test/dump-restore\r
112 > index c2ddb92..ae30cd1 100755\r
113 > --- a/test/dump-restore\r
114 > +++ b/test/dump-restore\r
115 > @@ -146,13 +146,11 @@ cat <<EOF > comments-and-blanks\r
116 >  EOF\r
117 >  \r
118 >  test_begin_subtest 'restoring empty file is not an error'\r
119 > -test_subtest_known_broken\r
120 >  notmuch restore < /dev/null 2>OUTPUT.$test_count\r
121 >  cp /dev/null EXPECTED\r
122 >  test_expect_equal_file EXPECTED OUTPUT.$test_count\r
123 >  \r
124 >  test_begin_subtest 'file of comments and blank lines is not an error'\r
125 > -test_subtest_known_broken\r
126 >  notmuch restore --input=comments-and-blanks\r
127 >  ret_val=$?\r
128 >  test_expect_equal "$ret_val" "0"\r
129 > @@ -172,7 +170,6 @@ echo "yun1vjwegii.fsf@aiko.keithp.com (another_tag)" \\r
130 >      >> leading-comments-blanks-sup\r
131 >  \r
132 >  test_begin_subtest 'detect format=sup with leading comments and blanks'\r
133 > -test_subtest_known_broken\r
134 >  notmuch restore --input=leading-comments-blanks-sup\r
135 >  notmuch search --output=tags id:yun1vjwegii.fsf@aiko.keithp.com > OUTPUT.$test_count\r
136 >  echo "another_tag" > EXPECTED\r
137 > -- \r
138 > 1.7.10.4\r
139 >\r
140 > _______________________________________________\r
141 > notmuch mailing list\r
142 > notmuch@notmuchmail.org\r
143 > http://notmuchmail.org/mailman/listinfo/notmuch\r