Re: [PATCH] dir: allow a BOM at the beginning of exclude files
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 16, 2015, 15:39 UTC
- Message-ID
- <xmqqsic0hyk4.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <1429193112-41184-1-git-send-email-cmn@elego.de>
Carlos Martín Nieto <cmn@elego.de> writes:
Show 19 quoted lines
> diff --git a/dir.c b/dir.c > index 0943a81..6368247 100644 > --- a/dir.c > +++ b/dir.c > @@ -581,6 +581,7 @@ int add_excludes_from_file_to_list(const char *fname, > struct stat st; > int fd, i, lineno = 1; > size_t size = 0; > + static const unsigned char *utf8_bom = (unsigned char *) "\xef\xbb\xbf"; > char *buf, *entry; > > fd = open(fname, O_RDONLY); > @@ -617,7 +618,12 @@ int add_excludes_from_file_to_list(const char *fname, > } > > el->filebuf = buf; > - entry = buf; > + > + if (size >= 3 && !memcmp(buf, utf8_bom, 3))
OK.
Show 17 quoted lines
> + entry = buf + 3;
> + else
> + entry = buf;
> +
> for (i = 0; i < size; i++) {
> if (buf[i] == '\n') {
> if (entry != buf + i && entry[0] != '#') {
> diff --git a/t/t7061-wtstatus-ignore.sh b/t/t7061-wtstatus-ignore.sh
> index 460789b..0a06fbf 100755
> --- a/t/t7061-wtstatus-ignore.sh
> +++ b/t/t7061-wtstatus-ignore.sh
> @@ -13,6 +13,8 @@ EOF
>
> test_expect_success 'status untracked directory with --ignored' '
> echo "ignored" >.gitignore &&
> + sed -e "s/^/\xef\xbb\xbf/" .gitignore >.gitignore.new &&
> + mv .gitignore.new .gitignore &&Is this "write literal in \xHEX on the replacement side of sed substitution" potable? In any case, replacing the above three with something like:
printf "<bom>ignored\n" >.gitignore
may be more sensible, no?
Also do we need a similar change to the attribute side, or are we already covered and we forgot to do the same for the ignore files?
> mkdir untracked && > : >untracked/ignored && > : >untracked/uncommitted &&