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

Re: [PATCH 4/4] format-rev: learn --abbrev, --color, and --date

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 15, 2026, 02:17 UTC
Message-ID
<xmqqbjb4ktz5.fsf@gitster.g>
In-Reply-To
<format-rev_three_more_opts.b84@msgid.xyz>
kristofferhaugsbakk@fastmail.com writes:
Show 10 quoted lines
> +static int date_cb(const struct option *option,
> +		   const char *arg,
> +		   int unset)
> +{
> +	struct rev_info *data = option->value;
> +	parse_date_format(arg, &data->date_mode);
> +	data->date_mode_explicit = 1;
> +	BUG_ON_OPT_NEG(unset);
> +	return 0;
> +}

This BUG_ON_OPT_NEG(unset) is a bit curious and confusing to me. If the caller could pass unset==1 (e.g., "--no-date"), option->value would be NULL, and we would already have dereferenced data->date_mode when preparing to call parse_date_format().

On the other hand, ...
> +		OPT_CALLBACK_F(0, "date", &data.rev, N_("date"),
> +			       N_("date format"),
> +			       PARSE_OPT_NONEG, date_cb),

... because we mark the option entry with PARSE_OPT_NONEG, "--no-date" would not cause date_cb() to be called with unset==1.

I guess, from existing uses of BUG_ON_OPT_NEG() elsewhere (like apply.c), that the intention is to notice when this callback function is broken by future changes, i.e., somebody careless makes the calling parse_options(), or an additional side caller that calls this callback directly, pass unset==1 and option->value==NULL combinations. But then the assertion should come before the first potentially problematic use, i.e., in this order:

	struct rev_info *data = option->value;
	BUG_ON_OPT_NEG(unset);
	parse_date_format(arg, &data->date_mode);
	data->date_mode_explicit = 1;
	return 0;
or the assertion will not trigger before the code segfaults, no?
Thanks.
Previous: kristofferhaugsbakk@fastmail.comNext: Kristoffer Haugsbakk
Message 8 of 25 in “format-rev: add --abbrev, --color, and --date”
  1. 0/4 format-rev: add --abbrev, --color, and --datekristofferhaugsbakk@fastmail.com, Aug 13, 2026
  2. 1/4 format-rev: use lower case for opts descriptionkristofferhaugsbakk@fastmail.com, Aug 13, 2026
  3. 2/4 format-rev: factor option variables into a structkristofferhaugsbakk@fastmail.com, Aug 13, 2026
  4. Junio C HamanoAug 13, 2026
  5. Kristoffer HaugsbakkAug 14, 2026
  6. 3/4 doc: rev-list-options.adoc: factor out --date altskristofferhaugsbakk@fastmail.com, Aug 13, 2026
  7. 4/4 format-rev: learn --abbrev, --color, and --datekristofferhaugsbakk@fastmail.com, Aug 13, 2026
  8. Junio C HamanoAug 15, 2026
  9. Kristoffer HaugsbakkAug 17, 2026
  10. Junio C HamanoAug 17, 2026
  11. Kristoffer HaugsbakkAug 18, 2026
  12. 0/5 format-rev: add --abbrev, --color, and --datekristofferhaugsbakk@fastmail.com, Aug 18, 2026
  13. 1/5 format-rev: use lower case for opts descriptionkristofferhaugsbakk@fastmail.com, Aug 18, 2026
  14. 2/5 format-rev: place BUG calls first in callbackkristofferhaugsbakk@fastmail.com, Aug 18, 2026
  15. 3/5 format-rev: factor option variables into a structkristofferhaugsbakk@fastmail.com, Aug 18, 2026
  16. 4/5 doc: rev-list-options.adoc: factor out --date altskristofferhaugsbakk@fastmail.com, Aug 18, 2026
  17. 5/5 format-rev: learn --abbrev, --color, and --datekristofferhaugsbakk@fastmail.com, Aug 18, 2026
  18. Junio C HamanoAug 26, 2026
  19. Ben KnobleSep 3, 2026
  20. Kristoffer HaugsbakkSep 3, 2026
  21. Junio C HamanoNov 2, 2026
  22. Kristoffer HaugsbakkNov 2, 2026
  23. Ben KnobleNov 2, 2026
  24. Kristoffer HaugsbakkNov 3, 2026
  25. D. Ben KnobleNov 7, 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.