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

Re: [PATCH v5 3/3] notes.c: introduce "--separator" option

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 16, 2023, 23:22 UTC
Message-ID
<xmqq7cwhnql3.fsf@gitster.g>
In-Reply-To
<a74c96d6dd23f2f1df6d3492093f3fd27451e24c.1676551077.git.dyroneteng@gmail.com>
Teng Long <dyroneteng@gmail.com> writes:
> When appending to a given notes object and the appended note is not
> empty too, we will insert a blank line at first which separates the
> existing note and the appended one, which as the separator.

", which as the separator" does not sound grammatically correct. Without that part, the above is a perfectly readable description of the current behaviour.

Show 6 quoted lines
> Sometimes, we want to use a specified <separator> as the separator. For
> example, if we specify as:
>
>     * --separator='------': we will insert "------\n" as the separator,
>     because user do not provide the line break char at last, we will add
>     the trailing '\n' compatibly.

In a way compatible to what? I think s/compatibly// would be even easier to read. I think you are doing that for convenience.

>     * --separator='------\n': we will insert as-is because it contains
>     the line break at last.

If this behaviour gets spelled out like this, it needs to be justified.

After seeing that "------" gives the user these dashes on its own single line, wouldn't a natural expectation by the user be to see a line with dashes, followed by a blank line, if you give "------\n"? How do you justify removal of that newline in a way that is easy to understand to readers?

I am not saying that you should allow --separator="---\n\n\n" to give three blank lines between paragraphs. I think it makes sense to keep the stripspace in the code after a paragraph gets added. I just prefer to see it done as our design choice, not "because there is stripspace that removes them", i.e. what the code happens to do.

>     * not specified --separator option: will use '\n' as the separator
>     when do appending and this is the default behavour.

s/not specified --separator option/no --separator option/; the way you phrased can be misread for

	git notes --separator -m foo -m bar

i.e. any additional specifics is not given but --separator is still on the command line. But I do not think you meant that---rather this entry is what happens by default, i.e. a blank line separates each paragraph.

>     * --separator='': we specify an empty separator which has the same
>     behavour with --separator='\n' and or not specified the option.

I do not quite see why it is necessary to spell this out. Isn't this a natural consequence of the first one (i.e. "six dashes without any terminating LF gets a line with dashes plus LF" naturally extends to "0 dashes without any terminating LF gets a blank line")?

Show 5 quoted lines
> In addition, if a user specifies multple "-m" with "--separator", the
> separator should be inserted between the messages too, so we use
> OPT_STRING_LIST instead of OPT_CALLBACK_F to parse "-m" option, make
> sure the option value of "--separator" been parsed already when we need
> it.

This is hard to grok. Is it an instruction to whoever is implementing this new feature, or is it an instruct to end-users telling that they need to give --separator before they start giving -m <msg>, -F <file>, -c <object>, etc.?

Show 7 quoted lines
> diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
> index efbc10f0..5abe6092 100644
> --- a/Documentation/git-notes.txt
> +++ b/Documentation/git-notes.txt
> @@ -11,7 +11,7 @@ SYNOPSIS
>  'git notes' [list [<object>]]
>  'git notes' add [-f] [--allow-empty] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
Doesn't add allow you to say
	$ git notes add -m foo -m bar

Shouldn't it also honor --separator to specify an alternate paragraph break?

> -'git notes' append [--allow-empty] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
> +'git notes' append [--allow-empty] [--separator] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
"--separator" -> "--separator=<paragraph-break>" or something?
Show 8 quoted lines
> @@ -86,7 +86,9 @@ the command can read the input given to the `post-rewrite` hook.)
>  
>  append::
>  	Append to the notes of an existing object (defaults to HEAD).
> -	Creates a new notes object if needed.
> +	Creates a new notes object if needed. If the note and the
> +	message are not empty, "\n" will be inserted between them.
> +	Use the `--separator` option to insert other delimiters.

"\n" is so, ... programmer lingo? "A blank line" is inserted between these paragraphs.

> +--separator <separator>::
> +	The '<separator>' inserted between the note and message
> +	by 'append', "\n" by default. A custom separator can be

I see no reason to single out 'append'; "add -m <msg> -m <msg>" follows exactly the same paragraph concatenation logic in the current code, no? If we allow customized paragraph separators, we should use the same logic there as well.

It probably is simpler to explain if you treat the "current note in 'append'" as if the text were just "earlier paragraphs", to which more paragraphs taken from each -m <msg> and -F <file> are concatenated, with paragraph break before each of them. In the case of 'add', there happens to be zero "earlier paragraphs", but everything else gets concatenated the same way, no?

> +	provided, if it doesn't end in a "\n", one will be added
> +	implicitly .
Funny punctuation.
Previous: Teng LongNext: Teng Long
Message 87 of 91 in “notes.c: introduce "--no-blankline" option”
  1. 0/2 notes.c: introduce "--no-blankline" optionTeng Long, Oct 13, 2022
  2. 1/2 notes.c: introduce "--no-blankline" optionTeng Long, Oct 13, 2022
  3. Junio C HamanoOct 13, 2022
  4. Teng LongOct 17, 2022
  5. Ævar Arnfjörð BjarmasonOct 13, 2022
  6. Teng LongOct 17, 2022
  7. 2/2 notes.c: fixed tip when target and append note are both emptyTeng Long, Oct 13, 2022
  8. Ævar Arnfjörð BjarmasonOct 13, 2022
  9. Phillip WoodOct 13, 2022
  10. Ævar Arnfjörð BjarmasonOct 13, 2022
  11. Phillip WoodOct 15, 2022
  12. Teng LongOct 18, 2022
  13. Teng LongOct 18, 2022
  14. Teng LongOct 18, 2022
  15. Ævar Arnfjörð BjarmasonOct 18, 2022
  16. 0/3 notes.c: introduce "--blank-line" optionTeng Long, Nov 7, 2022
  17. 1/3 notes.c: introduce "--blank-line" optionTeng Long, Nov 7, 2022
  18. Ævar Arnfjörð BjarmasonNov 7, 2022
  19. Eric SunshineNov 7, 2022
  20. Ævar Arnfjörð BjarmasonNov 7, 2022
  21. Taylor BlauNov 7, 2022
  22. Ævar Arnfjörð BjarmasonNov 7, 2022
  23. Taylor BlauNov 8, 2022
  24. Teng LongNov 8, 2022
  25. Teng LongNov 8, 2022
  26. Ævar Arnfjörð BjarmasonNov 8, 2022
  27. Teng LongNov 9, 2022
  28. Ævar Arnfjörð BjarmasonNov 7, 2022
  29. Teng LongNov 8, 2022
  30. Taylor BlauNov 7, 2022
  31. Teng LongNov 8, 2022
  32. 2/3 notes.c: fixed tip when target and append note are both emptyTeng Long, Nov 7, 2022
  33. Ævar Arnfjörð BjarmasonNov 7, 2022
  34. Taylor BlauNov 7, 2022
  35. Ævar Arnfjörð BjarmasonNov 7, 2022
  36. Taylor BlauNov 7, 2022
  37. Teng LongNov 8, 2022
  38. 3/3 notes.c: drop unreachable code in "append_edit()"Teng Long, Nov 7, 2022
  39. Ævar Arnfjörð BjarmasonNov 7, 2022
  40. Ævar Arnfjörð BjarmasonNov 7, 2022
  41. Teng LongNov 9, 2022
  42. Teng LongNov 9, 2022
  43. 0/5 notes.c: introduce "--no-blank-line" optionTeng Long, Nov 9, 2022
  44. 1/5 notes.c: cleanup 'strbuf_grow' call in 'append_edit'Teng Long, Nov 9, 2022
  45. 2/5 notes.c: cleanup for "designated init" and "char ptr init"Teng Long, Nov 9, 2022
  46. 4/5 notes.c: provide tips when target and append note are both emptyTeng Long, Nov 9, 2022
  47. 3/5 notes.c: drop unreachable code in 'append_edit()'Teng Long, Nov 9, 2022
  48. 5/5 notes.c: introduce "--no-blank-line" optionTeng Long, Nov 9, 2022
  49. 0/5 notes.c: introduce "--no-blank-line" optionTeng Long, Nov 28, 2022
  50. Junio C HamanoNov 29, 2022
  51. Taylor BlauNov 29, 2022
  52. Teng LongNov 29, 2022
  53. Junio C HamanoNov 29, 2022
  54. Teng LongDec 15, 2022
  55. Eric SunshineDec 19, 2022
  56. Teng LongDec 21, 2022
  57. Junio C HamanoDec 21, 2022
  58. Teng LongDec 22, 2022
  59. Eric SunshineDec 23, 2022
  60. 0/5 notes.c: introduce "--separator" optioTeng Long, Jan 12, 2023
  61. 1/5 notes.c: cleanup 'strbuf_grow' call in 'append_edit'Teng Long, Jan 12, 2023
  62. Eric SunshineJan 15, 2023
  63. Teng LongJan 28, 2023
  64. 2/5 notes.c: cleanup for "designated init" and "char ptr init"Teng Long, Jan 12, 2023
  65. Ævar Arnfjörð BjarmasonJan 12, 2023
  66. Teng LongJan 28, 2023
  67. 4/5 notes.c: provide tips when target and append note are both emptyTeng Long, Jan 12, 2023
  68. Ævar Arnfjörð BjarmasonJan 12, 2023
  69. Eric SunshineJan 15, 2023
  70. 3/5 notes.c: drop unreachable code in 'append_edit()'Teng Long, Jan 12, 2023
  71. Eric SunshineJan 15, 2023
  72. Eric SunshineJan 15, 2023
  73. Teng LongJan 28, 2023
  74. Eric SunshineJan 30, 2023
  75. Teng LongFeb 1, 2023
  76. 5/5 notes.c: introduce "--separator" optionTeng Long, Jan 12, 2023
  77. Ævar Arnfjörð BjarmasonJan 12, 2023
  78. Eric SunshineJan 15, 2023
  79. Eric SunshineJan 15, 2023
  80. 0/3 notes.c: introduce "--separator" optionTeng Long, Feb 16, 2023
  81. 1/3 notes.c: cleanup 'strbuf_grow' call in 'append_edit'Teng Long, Feb 16, 2023
  82. Junio C HamanoFeb 16, 2023
  83. Teng LongFeb 20, 2023
  84. 2/3 notes.c: cleanup for "designated init"Teng Long, Feb 16, 2023
  85. Junio C HamanoFeb 16, 2023
  86. 3/3 notes.c: introduce "--separator" optionTeng Long, Feb 16, 2023
  87. Junio C HamanoFeb 16, 2023
  88. Teng LongFeb 20, 2023
  89. Junio C HamanoFeb 21, 2023
  90. Teng LongFeb 22, 2023
  91. Junio C HamanoFeb 22, 2023

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.