git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/3] utf8-bom: introduce skip_utf8_bom() helper

From
Jeff King <peff@peff.net>
Date
Apr 16, 2015, 18:14 UTC
Message-ID
<20150416181407.GA12517@peff.net>
In-Reply-To
<1429206774-10087-2-git-send-email-gitster@pobox.com>
On Thu, Apr 16, 2015 at 10:52:52AM -0700, Junio C Hamano wrote:
Show 13 quoted lines
> @@ -576,10 +576,8 @@ int add_excludes_from_file_to_list(const char *fname,
>  
>  	el->filebuf = buf;
>  
> -	if (size >= 3 && !memcmp(buf, utf8_bom, 3))
> -		entry = buf + 3;
> -	else
> -		entry = buf;
> +	entry = buf;
> +	skip_utf8_bom(&entry, size);
>  
>  	for (i = 0; i < size; i++) {
>  		if (buf[i] == '\n') {

I'm surprised that in both yours and the original that we do not need to subtract 3 from "size".

It looks like we advance "entry" here, not "buf", and then iterate over "buf". But I think that makes the later logic weird:

   if (entry != buf + i && entry[0] != '#')

because if there is a BOM, we end up with "entry > buf + i", which I think this code isn't expecting. I'm not sure it does anything bad, but I think it might be simpler as just:

  /* save away the "real" copy for later, as we do now */
  el->filebuf = buf;
  /*
   * now pretend as if the BOM was not there at all by advancing
   * the pointer and shrinking the size
   */
  skip_utf8_bom(&buf, &size);
  /*
   * and now we do our usual magic with "entry"
   */
  entry = buf;
  for (i = 0; i < size; i++)
     ...
-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 10 of 24 in “dir: allow a BOM at the beginning of exclude files”
  1. dir: allow a BOM at the beginning of exclude filesCarlos Martín Nieto, Apr 16, 2015
  2. Johannes SchindelinApr 16, 2015
  3. Carlos Martín NietoApr 16, 2015
  4. Carlos Martín NietoApr 16, 2015
  5. Junio C HamanoApr 16, 2015
  6. Jeff KingApr 16, 2015
  7. Junio C HamanoApr 16, 2015
  8. 0/3 UTF8 BOM follow-upJunio C Hamano, Apr 16, 2015
  9. 1/3 utf8-bom: introduce skip_utf8_bom() helperJunio C Hamano, Apr 16, 2015
  10. Jeff KingApr 16, 2015
  11. Junio C HamanoApr 16, 2015
  12. 2/3 config: use utf8_bom[] from utf.[ch] in git_parse_source()Junio C Hamano, Apr 16, 2015
  13. 3/3 attr: skip UTF8 BOM at the beginning of the input fileJunio C Hamano, Apr 16, 2015
  14. Carlos Martín NietoApr 16, 2015
  15. 0/4 UTF8 BOM follow-upJunio C Hamano, Apr 16, 2015
  16. 1/4 add_excludes_from_file: clarify the bom skipping logicJunio C Hamano, Apr 16, 2015
  17. 2/4 utf8-bom: introduce skip_utf8_bom() helperJunio C Hamano, Apr 16, 2015
  18. 3/4 config: use utf8_bom[] from utf.[ch] in git_parse_source()Junio C Hamano, Apr 16, 2015
  19. 4/4 attr: skip UTF8 BOM at the beginning of the input fileJunio C Hamano, Apr 16, 2015
  20. Jeff KingApr 16, 2015
  21. Karsten BleesApr 17, 2015
  22. Junio C HamanoApr 20, 2015
  23. Johannes SchindelinApr 16, 2015
  24. Torsten BögershausenApr 16, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.