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

[PATCH v3 4/9] trailer: rename *_DEFAULT enums to *_UNSPECIFIED

From
LGLinus Arver via GitGitGadget <gitgitgadget@gmail.com>
Date
Sep 22, 2023, 19:50 UTC
Message-ID
<47186a09b24522bacf459006330fd469766072f2.1695412245.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1563.v3.git.1695412245.gitgitgadget@gmail.com>
From: Linus Arver <linusa@google.com>

Do not use *_DEFAULT as a suffix to the enums, because the word "default" is overloaded. The following are two examples of the ambiguity of the word "default":

(1) "Default" can mean using the "default" values that are hardcoded
    in trailer.c as
        default_conf_info.where = WHERE_END;
        default_conf_info.if_exists = EXISTS_ADD_IF_DIFFERENT_NEIGHBOR;
        default_conf_info.if_missing = MISSING_ADD;
    in ensure_configured(). These values are referred to as "the
    default" in the docs for interpret-trailers. These defaults are used
    if no "trailer.*" configurations are defined.
(2) "Default" can also mean the "trailer.*" configurations themselves,
    because these configurations are used by "default" (ahead of the
    hardcoded defaults in (1)) if no command line arguments are
    provided. This concept of defaulting back to the configurations was
    introduced in 0ea5292e6b (interpret-trailers: add options for
    actions, 2017-08-01).

In addition, the corresponding *_DEFAULT values are chosen when the user provides the "--no-where", "--no-if-exists", or "--no-if-missing" flags on the command line. These "--no-*" flags are used to clear previously provided flags of the form "--where", "--if-exists", and "--if-missing". Using these "--no-*" flags undoes the specifying of these flags (if any), so using the word "UNSPECIFIED" is more natural here.

So instead of using "*_DEFAULT", use "*_UNSPECIFIED" because this signals to the reader that the *_UNSPECIFIED value by itself carries no meaning (it's a zero value and by itself does not "default" to anything, necessitating the need to have some other way of getting to a useful value).

Signed-off-by: Linus Arver <linusa@google.com>
---
 trailer.c | 17 ++++++++++-------
 trailer.h |  6 +++---
 2 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/trailer.c b/trailer.c
index b6de5d9cb2d..0b66effceb5 100644
--- a/trailer.c
+++ b/trailer.c
@@ -388,7 +388,7 @@ static void process_trailers_lists(struct list_head *head,
 int trailer_set_where(enum trailer_where *item, const char *value)
 {
 	if (!value)
-		*item = WHERE_DEFAULT;
+		*item = WHERE_UNSPECIFIED;
 	else if (!strcasecmp("after", value))
 		*item = WHERE_AFTER;
 	else if (!strcasecmp("before", value))
@@ -405,7 +405,7 @@ int trailer_set_where(enum trailer_where *item, const char *value)
 int trailer_set_if_exists(enum trailer_if_exists *item, const char *value)
 {
 	if (!value)
-		*item = EXISTS_DEFAULT;
+		*item = EXISTS_UNSPECIFIED;
 	else if (!strcasecmp("addIfDifferent", value))
 		*item = EXISTS_ADD_IF_DIFFERENT;
 	else if (!strcasecmp("addIfDifferentNeighbor", value))
@@ -424,7 +424,7 @@ int trailer_set_if_exists(enum trailer_if_exists *item, const char *value)
 int trailer_set_if_missing(enum trailer_if_missing *item, const char *value)
 {
 	if (!value)
-		*item = MISSING_DEFAULT;
+		*item = MISSING_UNSPECIFIED;
 	else if (!strcasecmp("doNothing", value))
 		*item = MISSING_DO_NOTHING;
 	else if (!strcasecmp("add", value))
@@ -586,7 +586,10 @@ static void ensure_configured(void)
 	if (configured)
 		return;
 
-	/* Default config must be setup first */
+	/*
+	 * Default config must be setup first. These defaults are used if there
+	 * are no "trailer.*" or "trailer.<token>.*" options configured.
+	 */
 	default_conf_info.where = WHERE_END;
 	default_conf_info.if_exists = EXISTS_ADD_IF_DIFFERENT_NEIGHBOR;
 	default_conf_info.if_missing = MISSING_ADD;
@@ -701,11 +704,11 @@ static void add_arg_item(struct list_head *arg_head, char *tok, char *val,
 	new_item->value = val;
 	duplicate_conf(&new_item->conf, conf);
 	if (new_trailer_item) {
-		if (new_trailer_item->where != WHERE_DEFAULT)
+		if (new_trailer_item->where != WHERE_UNSPECIFIED)
 			new_item->conf.where = new_trailer_item->where;
-		if (new_trailer_item->if_exists != EXISTS_DEFAULT)
+		if (new_trailer_item->if_exists != EXISTS_UNSPECIFIED)
 			new_item->conf.if_exists = new_trailer_item->if_exists;
-		if (new_trailer_item->if_missing != MISSING_DEFAULT)
+		if (new_trailer_item->if_missing != MISSING_UNSPECIFIED)
 			new_item->conf.if_missing = new_trailer_item->if_missing;
 	}
 	list_add_tail(&new_item->list, arg_head);
diff --git a/trailer.h b/trailer.h
index ab2cd017567..a689d768c79 100644
--- a/trailer.h
+++ b/trailer.h
@@ -5,14 +5,14 @@
 #include "strbuf.h"
 
 enum trailer_where {
-	WHERE_DEFAULT,
+	WHERE_UNSPECIFIED,
 	WHERE_END,
 	WHERE_AFTER,
 	WHERE_BEFORE,
 	WHERE_START
 };
 enum trailer_if_exists {
-	EXISTS_DEFAULT,
+	EXISTS_UNSPECIFIED,
 	EXISTS_ADD_IF_DIFFERENT_NEIGHBOR,
 	EXISTS_ADD_IF_DIFFERENT,
 	EXISTS_ADD,
@@ -20,7 +20,7 @@ enum trailer_if_exists {
 	EXISTS_DO_NOTHING
 };
 enum trailer_if_missing {
-	MISSING_DEFAULT,
+	MISSING_UNSPECIFIED,
 	MISSING_ADD,
 	MISSING_DO_NOTHING
 };
-- 
gitgitgadget
Previous: Linus Arver via GitGitGadgetNext: Linus Arver via GitGitGadget
Message 48 of 72 in “Trailer readability cleanups”
  1. 0/5 Trailer readability cleanupsLinus Arver via GitGitGadget, Aug 5, 2023
  2. 1/5 trailer: separate public from internal portion of trailer_iteratorLinus Arver via GitGitGadget, Aug 5, 2023
  3. Glen ChooAug 7, 2023
  4. Phillip WoodAug 8, 2023
  5. Linus ArverAug 10, 2023
  6. Linus ArverAug 10, 2023
  7. 2/5 trailer: split process_input_file into separate piecesLinus Arver via GitGitGadget, Aug 5, 2023
  8. Glen ChooAug 7, 2023
  9. Linus ArverAug 11, 2023
  10. 4/5 trailer: teach find_patch_start about --no-dividerLinus Arver via GitGitGadget, Aug 5, 2023
  11. Glen ChooAug 7, 2023
  12. Linus ArverAug 11, 2023
  13. Glen ChooAug 11, 2023
  14. 3/5 trailer: split process_command_line_args into separate functionsLinus Arver via GitGitGadget, Aug 5, 2023
  15. Glen ChooAug 7, 2023
  16. Linus ArverAug 11, 2023
  17. Linus ArverAug 11, 2023
  18. Glen ChooAug 11, 2023
  19. 5/5 trailer: rename *_DEFAULT enums to *_UNSPECIFIEDLinus Arver via GitGitGadget, Aug 5, 2023
  20. Glen ChooAug 7, 2023
  21. Linus ArverAug 11, 2023
  22. 0/6 Trailer readability cleanupsLinus Arver via GitGitGadget, Sep 9, 2023
  23. 1/6 trailer: separate public from internal portion of trailer_iteratorLinus Arver via GitGitGadget, Sep 9, 2023
  24. Junio C HamanoSep 11, 2023
  25. 2/6 trailer: split process_input_file into separate piecesLinus Arver via GitGitGadget, Sep 9, 2023
  26. Junio C HamanoSep 11, 2023
  27. 3/6 trailer: split process_command_line_args into separate functionsLinus Arver via GitGitGadget, Sep 9, 2023
  28. 4/6 trailer: teach find_patch_start about --no-dividerLinus Arver via GitGitGadget, Sep 9, 2023
  29. Junio C HamanoSep 11, 2023
  30. Linus ArverSep 14, 2023
  31. Junio C HamanoSep 14, 2023
  32. Linus ArverSep 14, 2023
  33. 6/6 trailer: use offsets for trailer_start/trailer_endLinus Arver via GitGitGadget, Sep 9, 2023
  34. Junio C HamanoSep 11, 2023
  35. Linus ArverSep 14, 2023
  36. Linus ArverSep 14, 2023
  37. 5/6 trailer: rename *_DEFAULT enums to *_UNSPECIFIEDLinus Arver via GitGitGadget, Sep 9, 2023
  38. Junio C HamanoSep 11, 2023
  39. Linus ArverSep 14, 2023
  40. Junio C HamanoSep 14, 2023
  41. Linus ArverSep 22, 2023
  42. Junio C HamanoSep 22, 2023
  43. Linus ArverSep 26, 2023
  44. 0/9 Trailer readability cleanupsLinus Arver via GitGitGadget, Sep 22, 2023
  45. 1/9 trailer: separate public from internal portion of trailer_iteratorLinus Arver via GitGitGadget, Sep 22, 2023
  46. 2/9 trailer: split process_input_file into separate piecesLinus Arver via GitGitGadget, Sep 22, 2023
  47. 3/9 trailer: split process_command_line_args into separate functionsLinus Arver via GitGitGadget, Sep 22, 2023
  48. 4/9 trailer: rename *_DEFAULT enums to *_UNSPECIFIEDLinus Arver via GitGitGadget, Sep 22, 2023
  49. 5/9 commit: ignore_non_trailer computes number of bytes to ignoreLinus Arver via GitGitGadget, Sep 22, 2023
  50. 6/9 trailer: find the end of the log messageLinus Arver via GitGitGadget, Sep 22, 2023
  51. 9/9 trailer: make stack variable names match field namesLinus Arver via GitGitGadget, Sep 22, 2023
  52. 7/9 trailer: use offsets for trailer_start/trailer_endLinus Arver via GitGitGadget, Sep 22, 2023
  53. 8/9 trailer: only use trailer_block_* variables if trailers were foundLinus Arver via GitGitGadget, Sep 22, 2023
  54. Junio C HamanoSep 22, 2023
  55. Linus ArverSep 22, 2023
  56. Junio C HamanoSep 23, 2023
  57. Linus ArverSep 26, 2023
  58. 0/4 Trailer readability cleanupsLinus Arver via GitGitGadget, Sep 26, 2023
  59. 1/4 commit: ignore_non_trailer computes number of bytes to ignoreLinus Arver via GitGitGadget, Sep 26, 2023
  60. 2/4 trailer: find the end of the log messageLinus Arver via GitGitGadget, Sep 26, 2023
  61. Jonathan TanSep 28, 2023
  62. Linus ArverOct 20, 2023
  63. Junio C HamanoOct 20, 2023
  64. 3/4 trailer: use offsets for trailer_start/trailer_endLinus Arver via GitGitGadget, Sep 26, 2023
  65. 4/4 trailer: only use trailer_block_* variables if trailers were foundLinus Arver via GitGitGadget, Sep 26, 2023
  66. 0/3 Trailer readability cleanupsLinus Arver via GitGitGadget, Oct 20, 2023
  67. 1/3 commit: ignore_non_trailer computes number of bytes to ignoreLinus Arver via GitGitGadget, Oct 20, 2023
  68. 2/3 trailer: find the end of the log messageLinus Arver via GitGitGadget, Oct 20, 2023
  69. Junio C HamanoOct 20, 2023
  70. Linus ArverDec 29, 2023
  71. Linus ArverDec 29, 2023
  72. 3/3 trailer: use offsets for trailer_start/trailer_endLinus Arver via GitGitGadget, Oct 20, 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.