Skip to content

Commit 7c9b63c

Browse files
author
Linus Arver
committed
trailer: rename *_DEFAULT enums to *_UNSPECIFIED
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. 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>
1 parent 1fc0600 commit 7c9b63c

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

trailer.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ static void process_trailers_lists(struct list_head *head,
388388
int trailer_set_where(enum trailer_where *item, const char *value)
389389
{
390390
if (!value)
391-
*item = WHERE_DEFAULT;
391+
*item = WHERE_UNSPECIFIED;
392392
else if (!strcasecmp("after", value))
393393
*item = WHERE_AFTER;
394394
else if (!strcasecmp("before", value))
@@ -405,7 +405,7 @@ int trailer_set_where(enum trailer_where *item, const char *value)
405405
int trailer_set_if_exists(enum trailer_if_exists *item, const char *value)
406406
{
407407
if (!value)
408-
*item = EXISTS_DEFAULT;
408+
*item = EXISTS_UNSPECIFIED;
409409
else if (!strcasecmp("addIfDifferent", value))
410410
*item = EXISTS_ADD_IF_DIFFERENT;
411411
else if (!strcasecmp("addIfDifferentNeighbor", value))
@@ -424,7 +424,7 @@ int trailer_set_if_exists(enum trailer_if_exists *item, const char *value)
424424
int trailer_set_if_missing(enum trailer_if_missing *item, const char *value)
425425
{
426426
if (!value)
427-
*item = MISSING_DEFAULT;
427+
*item = MISSING_UNSPECIFIED;
428428
else if (!strcasecmp("doNothing", value))
429429
*item = MISSING_DO_NOTHING;
430430
else if (!strcasecmp("add", value))
@@ -586,7 +586,10 @@ static void ensure_configured(void)
586586
if (configured)
587587
return;
588588

589-
/* Default config must be setup first */
589+
/*
590+
* Default config must be setup first. These defaults are used if there
591+
* are no "trailer.*" or "trailer.<token>.*" options configured.
592+
*/
590593
default_conf_info.where = WHERE_END;
591594
default_conf_info.if_exists = EXISTS_ADD_IF_DIFFERENT_NEIGHBOR;
592595
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,
701704
new_item->value = val;
702705
duplicate_conf(&new_item->conf, conf);
703706
if (new_trailer_item) {
704-
if (new_trailer_item->where != WHERE_DEFAULT)
707+
if (new_trailer_item->where != WHERE_UNSPECIFIED)
705708
new_item->conf.where = new_trailer_item->where;
706-
if (new_trailer_item->if_exists != EXISTS_DEFAULT)
709+
if (new_trailer_item->if_exists != EXISTS_UNSPECIFIED)
707710
new_item->conf.if_exists = new_trailer_item->if_exists;
708-
if (new_trailer_item->if_missing != MISSING_DEFAULT)
711+
if (new_trailer_item->if_missing != MISSING_UNSPECIFIED)
709712
new_item->conf.if_missing = new_trailer_item->if_missing;
710713
}
711714
list_add_tail(&new_item->list, arg_head);

trailer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
#include "strbuf.h"
66

77
enum trailer_where {
8-
WHERE_DEFAULT,
8+
WHERE_UNSPECIFIED,
99
WHERE_END,
1010
WHERE_AFTER,
1111
WHERE_BEFORE,
1212
WHERE_START
1313
};
1414
enum trailer_if_exists {
15-
EXISTS_DEFAULT,
15+
EXISTS_UNSPECIFIED,
1616
EXISTS_ADD_IF_DIFFERENT_NEIGHBOR,
1717
EXISTS_ADD_IF_DIFFERENT,
1818
EXISTS_ADD,
1919
EXISTS_REPLACE,
2020
EXISTS_DO_NOTHING
2121
};
2222
enum trailer_if_missing {
23-
MISSING_DEFAULT,
23+
MISSING_UNSPECIFIED,
2424
MISSING_ADD,
2525
MISSING_DO_NOTHING
2626
};

0 commit comments

Comments
 (0)