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

Re: [PATCH 1/3] last-modified: handle and document NUL termination

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 26, 2025, 16:57 UTC
Message-ID
<xmqq3460pw8y.fsf@gitster.g>
In-Reply-To
<20251126-toon-last-modified-zzzz-v1-1-608350df0caa@iotcl.com>
Toon Claes <toon@iotcl.com> writes:
> When option `-z` is provided to git-last-modified(1), each line is
> separated with a NUL instead of a newline. Document this properly and
> handle parsing of the option in the builtin itself.

I think documenting does make sense, but it is not clear from the description why it is better to handle the option in the builtin itself, instead of letting the setup_revisions() take care of it.

Is it because after the command lets setup_revisions() to parse out the revision range, the command does not really let the revision machinery drive diffs and let it output anything (hence, even though rev.diffopt.line_termination is set from the command line, the calling builtin is the only one that pays attention, and the revision machinery and the diff machinery called from there does not pay attention to it?

And assuming that this new division of labor between the revision machinery and the subcommand makes sense (it needs to be explained better), the updated code does make sense to me.

But it looks suboptimal.  See below.
> +#define LAST_MODIFIED_INIT { \
> +	.line_termination = '\n', \
> +}

You have to introduce such a non-zero initialization, only because you pretend to accept _any_ byte here, and use it as the line termination character. If you were porting Git to ancient Macintosh, you could set this to '\r' and it would follow their text file convention there ;-)

But ...
Show 20 quoted lines
>  struct last_modified_entry {
>  	struct hashmap_entry hashent;
>  	struct object_id oid;
> @@ -55,6 +59,7 @@ struct last_modified {
>  	struct rev_info rev;
>  	bool recursive;
>  	bool show_trees;
> +	int line_termination;
>  
>  	const char **all_paths;
>  	size_t all_paths_nr;
> @@ -165,7 +170,7 @@ static void last_modified_emit(struct last_modified *lm,
>  		putchar('^');
>  	printf("%s\t", oid_to_hex(&commit->object.oid));
>  
> -	if (lm->rev.diffopt.line_termination)
> +	if (lm->line_termination)
>  		write_name_quoted(path, stdout, '\n');
>  	else
>  		printf("%s%c", path, '\0');

... you use hardcoded '\n' here, without allowing the value of line_termination to affect the termination character.

This is way suboptimal.  Instead, would it work if you add
	bool null_termination;
to the last_modified structure, and do
	if (!lm->null_termination)
		write_name_quoted(path, stdout, '\n');
	else
		printf("%s%c", path, '\0');
here?   Then
Show 6 quoted lines
> @@ -507,10 +512,10 @@ int cmd_last_modified(int argc, const char **argv, const char *prefix,
>  		      struct repository *repo)
>  {
>  	int ret;
> -	struct last_modified lm = { 0 };
> +	struct last_modified lm = LAST_MODIFIED_INIT;
You do not need this change, and
Show 12 quoted lines
>  	const char * const last_modified_usage[] = {
> -		N_("git last-modified [--recursive] [--show-trees] "
> +		N_("git last-modified [--recursive] [--show-trees] [-z] "
>  		   "[<revision-range>] [[--] <path>...]"),
>  		NULL
>  	};
> @@ -520,6 +525,8 @@ int cmd_last_modified(int argc, const char **argv, const char *prefix,
>  			 N_("recurse into subtrees")),
>  		OPT_BOOL('t', "show-trees", &lm.show_trees,
>  			 N_("show tree entries when recursing into subtrees")),
> +		OPT_SET_INT('z', NULL, &lm.line_termination,
> +			N_("lines are separated with NUL character"), '\0'),
This will become OPT_BOOL() to set the &lm.null_termination.
>  		OPT_END()
>  	};
Previous: Karthik NayakNext: Toon Claes
Message 4 of 36 in “Expand and enhance git-last-modified(1) documentation”
  1. 0/3 Expand and enhance git-last-modified(1) documentationToon Claes, Nov 26, 2025
  2. 1/3 last-modified: handle and document NUL terminationToon Claes, Nov 26, 2025
  3. Karthik NayakNov 26, 2025
  4. Junio C HamanoNov 26, 2025
  5. Toon ClaesNov 28, 2025
  6. Patrick SteinhardtDec 1, 2025
  7. 2/3 last-modified: document option --max-depthToon Claes, Nov 26, 2025
  8. Karthik NayakNov 26, 2025
  9. Toon ClaesJan 16, 2026
  10. Junio C HamanoNov 26, 2025
  11. Toon ClaesNov 28, 2025
  12. 3/3 last-modified: better document how depth in handledToon Claes, Nov 26, 2025
  13. Eric SunshineNov 26, 2025
  14. Patrick SteinhardtDec 1, 2025
  15. Toon ClaesDec 2, 2025
  16. Patrick SteinhardtDec 2, 2025
  17. 0/5 Change git-last-modified(1) default behavior and add documentationToon Claes, Jan 16, 2026
  18. 1/5 last-modified: document NUL terminationToon Claes, Jan 16, 2026
  19. 2/5 last-modified: add option '-z' to help outputToon Claes, Jan 16, 2026
  20. Junio C HamanoJan 16, 2026
  21. 3/5 last-modified: document option --max-depthToon Claes, Jan 16, 2026
  22. 4/5 last-modified: add option '--max-depth' to help outputToon Claes, Jan 16, 2026
  23. Junio C HamanoJan 16, 2026
  24. 5/5 last-modified: change default max-depth to 0Toon Claes, Jan 16, 2026
  25. Junio C HamanoJan 16, 2026
  26. Kristoffer HaugsbakkJan 16, 2026
  27. Toon ClaesJan 20, 2026
  28. 0/4 Change git-last-modified(1) default behavior and add documentationToon Claes, Jan 20, 2026
  29. 1/4 last-modified: clarify in the docs the command takes a pathspecToon Claes, Jan 20, 2026
  30. 2/4 last-modified: document option '-z'Toon Claes, Jan 20, 2026
  31. 3/4 last-modified: document option '--max-depth'Toon Claes, Jan 20, 2026
  32. 4/4 last-modified: change default max-depth to 0Toon Claes, Jan 20, 2026
  33. Kristoffer HaugsbakkJan 25, 2026
  34. Junio C HamanoJan 21, 2026
  35. Karthik NayakFeb 3, 2026
  36. Junio C HamanoFeb 3, 2026

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.