@matheusbsbs / matheus-bagliano / commits / 650d30d8a1
Fork 0

mailinfo: Remove only one set of square brackets

git-format-patch prepends patches with a [PATCH x/n] prefix, but mailinfo used to remove any number of square-bracket pairs and the content between them. This prevents one from using a commit subject like this: [ and ] must be allowed as input Removing the square bracket pair from this rather clumsily constructed subject line loses important information, so we must take care not to. This patch causes the subject stripping to stop after it has encountered one pair of square brackets. One possible downside of this patch is that the patch-handling programs will now fail at removing author-added square-brackets to be removed, such as [RFC][PATCH x/n] However, since format-patch only adds one set of square brackets, this behaviour is quite easily undesrstood and defended while the previous behaviour is not. Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Andreas Ericsson committed Jun 29, 2009 at 11:55 UTC 650d30d8a120c8982309ccb9ef40432b4ea2eb74
3 files changed +9 -2
builtin-mailinfo.c
+7
@@ -222,6 +222,8 @@ static void cleanup_subject(struct strbuf *subject)
222 {
223 char *pos;
224 size_t remove;
225 + int brackets_removed = 0;
226 +
227 while (subject->len) {
228 switch (*subject->buf) {
229 case 'r': case 'R':
@@ -236,10 +238,15 @@ static void cleanup_subject(struct strbuf *subject)
238 strbuf_remove(subject, 0, 1);
239 continue;
240 case '[':
241 + /* remove only one set of square brackets */
242 + if (brackets_removed)
243 + break;
244 +
245 if ((pos = strchr(subject->buf, ']'))) {
246 remove = pos - subject->buf;
247 if (remove <= (subject->len - remove) * 2) {
248 strbuf_remove(subject, 0, remove + 1);
249 + brackets_removed = 1;
250 continue;
251 }
252 } else
t/t5100/info0012
+1 -1
@@ -1,5 +1,5 @@
1 Author: Dmitriy Blinov
2 Email: bda@mnsspb.ru
3 -Subject: Изменён список пакетов необходимых для сборки
3 +Subject: [Navy-patches] Изменён список пакетов необходимых для сборки
4 Date: Wed, 12 Nov 2008 17:54:41 +0300
5
t/t5100/sample.mbox
+1 -1
@@ -514,7 +514,7 @@ MIME-Version: 1.0
514 Content-Type: text/plain;
515 charset=utf-8
516 Content-Transfer-Encoding: 8bit
517 -Subject: [Navy-patches] [PATCH]
517 +Subject: [PATCH] [Navy-patches]
518 =?utf-8?b?0JjQt9C80LXQvdGR0L0g0YHQv9C40YHQvtC6INC/0LA=?=
519 =?utf-8?b?0LrQtdGC0L7QsiDQvdC10L7QsdGF0L7QtNC40LzRi9GFINC00LvRjyA=?=
520 =?utf-8?b?0YHQsdC+0YDQutC4?=