Skip to content

Commit 650d30d

Browse files
agericgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1bed73c commit 650d30d

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

builtin-mailinfo.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ static void cleanup_subject(struct strbuf *subject)
222222
{
223223
char *pos;
224224
size_t remove;
225+
int brackets_removed = 0;
226+
225227
while (subject->len) {
226228
switch (*subject->buf) {
227229
case 'r': case 'R':
@@ -236,10 +238,15 @@ static void cleanup_subject(struct strbuf *subject)
236238
strbuf_remove(subject, 0, 1);
237239
continue;
238240
case '[':
241+
/* remove only one set of square brackets */
242+
if (brackets_removed)
243+
break;
244+
239245
if ((pos = strchr(subject->buf, ']'))) {
240246
remove = pos - subject->buf;
241247
if (remove <= (subject->len - remove) * 2) {
242248
strbuf_remove(subject, 0, remove + 1);
249+
brackets_removed = 1;
243250
continue;
244251
}
245252
} else

t/t5100/info0012

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Author: Dmitriy Blinov
22
3-
Subject: Изменён список пакетов необходимых для сборки
3+
Subject: [Navy-patches] Изменён список пакетов необходимых для сборки
44
Date: Wed, 12 Nov 2008 17:54:41 +0300
55

t/t5100/sample.mbox

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ MIME-Version: 1.0
514514
Content-Type: text/plain;
515515
charset=utf-8
516516
Content-Transfer-Encoding: 8bit
517-
Subject: [Navy-patches] [PATCH]
517+
Subject: [PATCH] [Navy-patches]
518518
=?utf-8?b?0JjQt9C80LXQvdGR0L0g0YHQv9C40YHQvtC6INC/0LA=?=
519519
=?utf-8?b?0LrQtdGC0L7QsiDQvdC10L7QsdGF0L7QtNC40LzRi9GFINC00LvRjyA=?=
520520
=?utf-8?b?0YHQsdC+0YDQutC4?=

0 commit comments

Comments
 (0)