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

Re: [PATCH v4 2/2] convert: ce_compare_data() checks for a sha1 of a path

From
Junio C Hamano <gitster@pobox.com>
Date
May 17, 2016, 18:58 UTC
Message-ID
<xmqq60ucwlz8.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1463503301-3634-1-git-send-email-tboegi@web.de>
tboegi@web.de writes:
>  #define HASH_WRITE_OBJECT 1
>  #define HASH_FORMAT_CHECK 2
> +#define HASH_CE_HAS_SHA1  4

How does one pronounce the words in this constant? Does it make a listener understand what this constant means?

/*
 * We need a comment around here to say what these two
 * parameters mean.  I am guessing that (1) if sha1 is not NULL,
 * path is ignored and the function inspects if it has CR; (2)
 * otherwise it checks the index entry at path and inspects if
 * it has CR.
 */
>  
> -static int has_cr_in_index(const char *path)
> +static int has_cr_in_index(const char *path, const unsigned char *sha1)
>  {

This makes me seriously wonder if it is a good idea to modify this function like this. (1) means this function is not about IN INDEX at all!

Perhaps add a "static int blob_has_cr(const unsigned char *sha1)" and call it from the real caller you added that wants to call this butchered two-param version that has sha1 is a better solution?

Show 12 quoted lines
> -static int crlf_to_git(const char *path, const char *src, size_t len,
> +static int crlf_to_git(const char *path, const unsigned char *sha1,
> +		       const char *src, size_t len,
>  		       struct strbuf *buf,
>  		       enum crlf_action crlf_action, enum safe_crlf checksafe)
>  {
> @@ -260,7 +267,7 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
>  			 * If the file in the index has any CR in it, do not convert.
>  			 * This is the new safer autocrlf handling.
>  			 */
> -			if (has_cr_in_index(path))
> +			if (has_cr_in_index(path, sha1))

I think this change is too ugly. The new "sha1" parameter is telling us that "in order to see if the indexed version has CR, do not look at the index, but look at the contents of this blob".

But wouldn't the result become more understandable if instead we passed a new parameter "cr-state-for-conversion" that takes UNKNOWN, HAS_CR, or NO_CR to this function?

In other words, what if, when the caller knows it does not care what's in the index but wants to instead see if a different blob has CR, we make it the caller's responsibility to figure it out by calling blob_has_cr() before calling into this codepath and pass the result of that check down? When cr-state-for-conversion is UNKNOWN, this code knows that it needs to call has_cr_in_index(path) to figure it out itself. Otherwise, it can and should use the caller-supplied value without asking has_cr_in_index(path).

Previous: tboegi@web.deNext: Torsten Bögershausen
Message 27 of 53 in “Bug report: Duplicate CRLF rewrite warnings on commit”
  1. Adam DinwoodieMay 13, 2016
  2. Junio C HamanoMay 13, 2016
  3. Torsten BögershausenMay 14, 2016
  4. Adam DinwoodieMay 14, 2016
  5. Jeff KingMay 13, 2016
  6. Junio C HamanoMay 13, 2016
  7. Jeff KingMay 13, 2016
  8. 0/1 Quickfix ?No duplicate CRLF rewrite warnings on committboegi@web.de, May 15, 2016
  9. 1/1 No duplicate CRLF rewrite warnings on committboegi@web.de, May 15, 2016
  10. Eric SunshineMay 15, 2016
  11. 0/3 CRLF-Handling: bug fix around ce_compare_data()tboegi@web.de, May 15, 2016
  12. 1/3 t6038; use crlf on all platformstboegi@web.de, May 15, 2016
  13. Eric SunshineMay 15, 2016
  14. 2/3 read-cache: factor out get_sha1_from_index() helpertboegi@web.de, May 15, 2016
  15. Eric SunshineMay 15, 2016
  16. 3/3 convert: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 15, 2016
  17. Eric SunshineMay 15, 2016
  18. Junio C HamanoMay 15, 2016
  19. 0/1 CRLF-Handling: bug fix around ce_compare_data()tboegi@web.de, May 16, 2016
  20. Junio C HamanoMay 16, 2016
  21. Torsten BögershausenMay 17, 2016
  22. 1/1 t6038; use crlf on all platformstboegi@web.de, May 17, 2016
  23. Junio C HamanoMay 17, 2016
  24. 0/2 CRLF: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 17, 2016
  25. 1/2 read-cache: factor out get_sha1_from_index() helpertboegi@web.de, May 17, 2016
  26. 2/2 convert: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 17, 2016
  27. Junio C HamanoMay 17, 2016
  28. Torsten BögershausenMay 18, 2016
  29. Torsten BögershausenMay 18, 2016
  30. 0/2 CRLF: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 19, 2016
  31. Junio C HamanoMay 19, 2016
  32. 1/2 read-cache: factor out get_sha1_from_index() helpertboegi@web.de, May 19, 2016
  33. 2/2 convert: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 19, 2016
  34. Junio C HamanoMay 19, 2016
  35. 1/2 read-cache: factor out get_sha1_from_index() helpertboegi@web.de, May 20, 2016
  36. 2/2 convert: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 20, 2016
  37. Junio C HamanoMay 20, 2016
  38. 1/2 read-cache: factor out get_sha1_from_index() helpertboegi@web.de, May 21, 2016
  39. 2/2 convert: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 21, 2016
  40. Junio C HamanoMay 24, 2016
  41. 1/1 convert: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 16, 2016
  42. 0/1 t6038-merge-text-auto.shtboegi@web.de, May 30, 2016
  43. Junio C HamanoMay 30, 2016
  44. Junio C HamanoMay 30, 2016
  45. 1/1 t6038: different eol for "Merge addition of text=auto"tboegi@web.de, May 30, 2016
  46. 0/3 unified auto CRLF handling, V2tboegi@web.de, Jun 7, 2016
  47. 1/3 convert: unify the "auto" handling of CRLFtboegi@web.de, Jun 7, 2016
  48. 2/3 read-cache: factor out get_sha1_from_index() helpertboegi@web.de, Jun 7, 2016
  49. 3/3 Correct ce_compare_data() in a middle of a mergetboegi@web.de, Jun 7, 2016
  50. 0/3 CRLF-Handling: bug fix around ce_compare_data()tboegi@web.de, May 15, 2016
  51. 1/3 read-cache: factor out get_sha1_from_index() helpertboegi@web.de, May 15, 2016
  52. 2/3 convert: ce_compare_data() checks for a sha1 of a pathtboegi@web.de, May 15, 2016
  53. 3/3 t6038; use crlf on all platformstboegi@web.de, May 15, 2016

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.