Skip to content

Commit 92f742f

Browse files
author
Linus Arver
committed
trailer: avoid ambiguity with the word "DEFAULT"
Do not use *_DEFAULT as a suffix to the enums, because "default" is overloaded. The following are two examples: (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(), and reflected in the manpage for interpret-trailers. These values are used if no trailer.* configurations are defined in .gitconfig. (2) "Default" can also mean the default trailer values that can be configured in .gitconfig, under "trailer.where", "trailer.ifexists", or "trailer.ifmissing" (or their trailer.<token>.* counterparts). These configured values are used by default if no command line arguments are provided. In addition, the *_DEFAULT values are chosen when the user supplies the "--no-where", "--no-if-exists", or "--no-if-missing" flags on the command line. These flags are used to go back to the behavior specified by the relevant _configuration_ values, if any. So instead of using "*_DEFAULT", use "*_CONFIG" because this avoids the ambiguity. Signed-off-by: Linus Arver <linusa@google.com>
1 parent 4dd1dc2 commit 92f742f

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_CONFIG;
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_CONFIG;
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_CONFIG;
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_CONFIG)
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_CONFIG)
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_CONFIG)
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_CONFIG,
99
WHERE_END,
1010
WHERE_AFTER,
1111
WHERE_BEFORE,
1212
WHERE_START
1313
};
1414
enum trailer_if_exists {
15-
EXISTS_DEFAULT,
15+
EXISTS_CONFIG,
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_CONFIG,
2424
MISSING_ADD,
2525
MISSING_DO_NOTHING
2626
};

0 commit comments

Comments
 (0)