Re: Applying patches directly from emails?
[notmuch-archives.git] / 2d / 35594ffb327021f87e4c3855d67ea2bda2ea89
1 Return-Path: <amdragon@mit.edu>\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 5F470431FAF\r
6         for <notmuch@notmuchmail.org>; Thu, 19 Jan 2012 20:19:23 -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.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 JL3u0az9MHWG for <notmuch@notmuchmail.org>;\r
16         Thu, 19 Jan 2012 20:19:22 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU\r
18         [18.7.68.37])\r
19         by olra.theworths.org (Postfix) with ESMTP id 9B8FF431FAE\r
20         for <notmuch@notmuchmail.org>; Thu, 19 Jan 2012 20:19:22 -0800 (PST)\r
21 X-AuditID: 12074425-b7f4a6d0000008e0-55-4f18eb4a6a50\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 6D.6B.02272.A4BE81F4; Thu, 19 Jan 2012 23:19:22 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0K4JLRJ018735; \r
27         Thu, 19 Jan 2012 23:19:21 -0500\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0K4JK4K011605\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Thu, 19 Jan 2012 23:19:21 -0500 (EST)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1Ro5wM-0004cf-6U; Thu, 19 Jan 2012 23:19:02 -0500\r
37 Date: Thu, 19 Jan 2012 23:19:02 -0500\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Pieter Praet <pieter@praet.org>\r
40 Subject: Re: [PATCH 4/4] setup: prompt user for search.exclude_tags value\r
41 Message-ID: <20120120041902.GV16740@mit.edu>\r
42 References: <1326586654-16840-3-git-send-email-amdragon@mit.edu>\r
43         <1327000744-25463-1-git-send-email-pieter@praet.org>\r
44         <1327000744-25463-5-git-send-email-pieter@praet.org>\r
45         <20120119194437.GP16740@mit.edu> <8762g7o0k4.fsf@praet.org>\r
46 MIME-Version: 1.0\r
47 Content-Type: text/plain; charset=us-ascii\r
48 Content-Disposition: inline\r
49 In-Reply-To: <8762g7o0k4.fsf@praet.org>\r
50 User-Agent: Mutt/1.5.21 (2010-09-15)\r
51 X-Brightmail-Tracker:\r
52  H4sIAAAAAAAAA+NgFmphleLIzCtJLcpLzFFi42IRYrdT1/V6LeFv8HY6h8X1mzOZLX6/vsHs\r
53         wOTxbNUtZo+OfZdZA5iiuGxSUnMyy1KL9O0SuDJOnz/FVLBcpWLhqilMDYyPpboYOTkkBEwk\r
54         2p7cZ4OwxSQu3FsPZgsJ7GOUOPsqpouRC8jewCgx9dtNFgjnJJNEy7lDjBDOEkaJH7vPg7Ww\r
55         CKhKXJp5hQnEZhPQkNi2fzkjiC0ioCxx+slPdhCbWUBLYuvGD2BxYQFPiZfz28DivAI6Ems6\r
56         LrJBDH3HKLHh8SQmiISgxMmZT1hgmm/8ewkU5wCypSWW/+MACXMKqEvsPnWCGcQWFVCRmHJy\r
57         G9sERqFZSLpnIemehdC9gJF5FaNsSm6Vbm5iZk5xarJucXJiXl5qka6FXm5miV5qSukmRnBg\r
58         u6juYJxwSOkQowAHoxIPL7erhL8Qa2JZcWXuIUZJDiYlUV6Vx0AhvqT8lMqMxOKM+KLSnNTi\r
59         Q4wSHMxKIrwOT4ByvCmJlVWpRfkwKWkOFiVxXk2td35CAumJJanZqakFqUUwWRkODiUJ3rWv\r
60         gBoFi1LTUyvSMnNKENJMHJwgw3mAhi8BqeEtLkjMLc5Mh8ifYlSUEudtBUkIgCQySvPgemGJ\r
61         5xWjONArwryrQKp4gEkLrvsV0GAmoMEeTWIgg0sSEVJSDYwdt5fm3TTwmtSVfvmlV9oWrszm\r
62         fccjdjyq7upYIllxg3+ro92s/CXttyOUC2zvTOWtMJ9mu0ZTuZT70WTz28y3gpZ8nbto89ar\r
63         29QLDO8GXnTk+qDzenmUanPwsaMnFjx6ueGT5IPmd89v/7cuuvp+2ta4SKMJCa0/p3jXbhHc\r
64         vfX9zEmVJzSXKbEUZyQaajEXFScCAOWOm2cXAwAA\r
65 Cc: Notmuch Mail <notmuch@notmuchmail.org>\r
66 X-BeenThere: notmuch@notmuchmail.org\r
67 X-Mailman-Version: 2.1.13\r
68 Precedence: list\r
69 List-Id: "Use and development of the notmuch mail system."\r
70         <notmuch.notmuchmail.org>\r
71 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
73 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
74 List-Post: <mailto:notmuch@notmuchmail.org>\r
75 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
76 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
77         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
78 X-List-Received-Date: Fri, 20 Jan 2012 04:19:23 -0000\r
79 \r
80 Quoth Pieter Praet on Jan 19 at 10:16 pm:\r
81 > On Thu, 19 Jan 2012 14:44:37 -0500, Austin Clements <amdragon@MIT.EDU> wrote:\r
82 > > Quoth Pieter Praet on Jan 19 at  8:19 pm:\r
83 > > > Allow users to customize the search.exclude_tags option during setup.\r
84 > > > \r
85 > > > ---\r
86 > > >  notmuch-setup.c |   36 ++++++++++++++++++++++++++++++++++++\r
87 > > >  1 files changed, 36 insertions(+), 0 deletions(-)\r
88 > > > \r
89 > > > diff --git a/notmuch-setup.c b/notmuch-setup.c\r
90 > > > index c3ea937..44d4aaa 100644\r
91 > > > --- a/notmuch-setup.c\r
92 > > > +++ b/notmuch-setup.c\r
93 > > > @@ -101,6 +101,8 @@ notmuch_setup_command (unused (void *ctx),\r
94 > > >      int is_new;\r
95 > > >      const char **new_tags;\r
96 > > >      size_t new_tags_len;\r
97 > > > +    const char **search_exclude_tags;\r
98 > > > +    size_t search_exclude_tags_len;\r
99 > > >  \r
100 > > >  #define prompt(format, ...)                                      \\r
101 > > >      do {                                                 \\r
102 > > > @@ -195,6 +197,40 @@ notmuch_setup_command (unused (void *ctx),\r
103 > > >   g_ptr_array_free (tags, TRUE);\r
104 > > >      }\r
105 > > >  \r
106 > > > +    search_exclude_tags = notmuch_config_get_search_exclude_tags (config, &search_exclude_tags_len);\r
107 > > > +\r
108 > > > +    printf ("Tags to exclude when searching messages (separated by spaces) [");\r
109 > > > +\r
110 > > > +    for (i = 0; i < search_exclude_tags_len; i++) {\r
111 > > > + if (i != 0)\r
112 > > > +     printf (" ");\r
113 > > > + printf ("%s", search_exclude_tags[i]);\r
114 > > > +    }\r
115 > > > +\r
116 > > > +    prompt ("]: ");\r
117 > > > +\r
118 > > > +    if (strlen (response)) {\r
119 > > > + GPtrArray *tags = g_ptr_array_new ();\r
120 > > > + char *tag = response;\r
121 > > > + char *space;\r
122 > > > +\r
123 > > > + while (tag && *tag) {\r
124 > > > +     space = strchr (tag, ' ');\r
125 > > > +     if (space)\r
126 > > > +         g_ptr_array_add (tags, talloc_strndup (ctx, tag, space - tag));\r
127 > > > +     else\r
128 > > > +         g_ptr_array_add (tags, talloc_strdup (ctx, tag));\r
129 > > > +     tag = space;\r
130 > > > +     while (tag && *tag == ' ')\r
131 > > > +         tag++;\r
132 > > > + }\r
133 > > > +\r
134 > > > + notmuch_config_set_search_exclude_tags (config, (const char **) tags->pdata,\r
135 > > > +                              tags->len);\r
136 > > > +\r
137 > > > + g_ptr_array_free (tags, TRUE);\r
138 > > > +    }\r
139 > > > +\r
140 > > \r
141 > > Holy code duplication.  Can we move most of this (at least the\r
142 > > response parsing part and maybe the prompt printing) into a function\r
143 > > and use it for both new tags and exclude tags?\r
144 > > \r
145\r
146 > Depends on who "we" is... :)  I would gladly do it if I could, but I\r
147 > think this uber1337 copy-paste coding job serves as *very* convincing\r
148 > proof that I'm pretty much in the dark (with a single wet match) when it\r
149 > comes to C :)\r
150 \r
151 Hah, okay.  How about this as an initial minor refactoring of the code\r
152 for new.tags?\r
153 \r
154 diff --git a/notmuch-setup.c b/notmuch-setup.c\r
155 index c3ea937..dcfa607 100644\r
156 --- a/notmuch-setup.c\r
157 +++ b/notmuch-setup.c\r
158 @@ -87,6 +87,38 @@ welcome_message_post_setup (void)\r
159  "have sufficient storage space available now.\n\n");\r
160  }\r
161  \r
162 +static void\r
163 +print_tag_list (const char **tags, size_t tags_len)\r
164 +{\r
165 +    unsigned int i;\r
166 +    for (i = 0; i < tags_len; i++) {\r
167 +       if (i != 0)\r
168 +           printf (" ");\r
169 +       printf ("%s", tags[i]);\r
170 +    }\r
171 +}\r
172 +\r
173 +static GPtrArray *\r
174 +parse_tag_list (void *ctx, char *response)\r
175 +{\r
176 +    GPtrArray *tags = g_ptr_array_new ();\r
177 +    char *tag = response;\r
178 +    char *space;\r
179 +\r
180 +    while (tag && *tag) {\r
181 +       space = strchr (tag, ' ');\r
182 +       if (space)\r
183 +           g_ptr_array_add (tags, talloc_strndup (ctx, tag, space - tag));\r
184 +       else\r
185 +           g_ptr_array_add (tags, talloc_strdup (ctx, tag));\r
186 +       tag = space;\r
187 +       while (tag && *tag == ' ')\r
188 +           tag++;\r
189 +    }\r
190 +\r
191 +    return tags;\r
192 +}\r
193 +\r
194  int\r
195  notmuch_setup_command (unused (void *ctx),\r
196                        unused (int argc), unused (char *argv[]))\r
197 @@ -164,30 +196,11 @@ notmuch_setup_command (unused (void *ctx),\r
198      new_tags = notmuch_config_get_new_tags (config, &new_tags_len);\r
199  \r
200      printf ("Tags to apply to all new messages (separated by spaces) [");\r
201 -\r
202 -    for (i = 0; i < new_tags_len; i++) {\r
203 -       if (i != 0)\r
204 -           printf (" ");\r
205 -       printf ("%s", new_tags[i]);\r
206 -    }\r
207 -\r
208 +    print_tag_list(new_tags, new_tags_len);\r
209      prompt ("]: ");\r
210  \r
211      if (strlen (response)) {\r
212 -       GPtrArray *tags = g_ptr_array_new ();\r
213 -       char *tag = response;\r
214 -       char *space;\r
215 -\r
216 -       while (tag && *tag) {\r
217 -           space = strchr (tag, ' ');\r
218 -           if (space)\r
219 -               g_ptr_array_add (tags, talloc_strndup (ctx, tag, space - tag));\r
220 -           else\r
221 -               g_ptr_array_add (tags, talloc_strdup (ctx, tag));\r
222 -           tag = space;\r
223 -           while (tag && *tag == ' ')\r
224 -               tag++;\r
225 -       }\r
226 +       GPtrArray *tags = parse_tag_list (ctx, response);\r
227  \r
228         notmuch_config_set_new_tags (config, (const char **) tags->pdata,\r
229                                      tags->len);\r
230 \r