Re: [PATCH] checkpatch: Add a --strict check for utf-8 in commitlogs

From: Andrew Morton
Date: Mon Oct 10 2011 - 18:42:10 EST


On Mon, 10 Oct 2011 15:32:30 -0700
Joe Perches <joe@xxxxxxxxxxx> wrote:

> Some find using utf-8 in commit logs inappropriate.
>
> Some patch commit logs contain unintended utf-8 characters
> when doing things like copy/pasting compilation output.
>
> Look for the start of any commit log by skipping initial
> lines that look like email headers and "From: " lines.
>
> Stop looking for utf-8 at the first signature line.
>
> Suggested-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Signed-off-by: Joe Perches <joe@xxxxxxxxxxx>
>
> ---
>
> I don't feel strongly that this patch should be applied,
> that's why it's a --strict check and not on by default,
> but Andrew Morton seems to want something like it...

Mainly because of the non-ascii single-quote chars which gcc emits in
its warning/error messages. I use LANG=C to stop gcc from doing that,
and also have a proglet to undo this nonsense when I'm merging patches
(below) (I totally forget how it works). But I see such things turning
up in the tree via other merge paths.



#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>

static void dump(int *buf)
{
if (buf[0] == 0xE2 && buf[1] == 0x80 && buf[2] == 0x98) {
putchar('`');
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
} else if (buf[0] == 0xE2 && buf[1] == 0x80 && buf[2] == 0x99) {
putchar('\'');
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
} else if (buf[0] == 0xa1) {
putchar('`');
goto move;
} else if (buf[0] == 0xa2) {
putchar('\'');
goto move;
} else {
if (buf[0])
putchar(buf[0]);
move:
buf[0] = buf[1];
buf[1] = buf[2];
buf[2] = 0;
}
}

static void doit(FILE *f)
{
int buf[3] = {};
int c;

while ((c = fgetc(f)) != EOF) {
dump(buf);
buf[2] = c;
}
dump(buf);
dump(buf);
dump(buf);
}

int main(int argc, char *argv[])
{
if (argc == 1) {
doit(stdin);
} else {
int i;

for (i = 1; i < argc; i++) {
FILE *f = fopen(argv[i], "r");

if (f == NULL) {
fprintf(stderr, "%s: cannot open `%s': %s\n",
argv[0], argv[1], strerror(errno));
exit(1);
}
doit(f);
fclose(f);
}
}
exit(0);
}

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/