Skip to content

Commit

Permalink
trailer: avoid ambiguity with the word "DEFAULT"
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Arver committed Aug 5, 2023
1 parent 8e61749 commit 26acd10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
17 changes: 10 additions & 7 deletions trailer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_CONFIG;
else if (!strcasecmp("after", value))
*item = WHERE_AFTER;
else if (!strcasecmp("before", value))
Expand All @@ -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_CONFIG;
else if (!strcasecmp("addIfDifferent", value))
*item = EXISTS_ADD_IF_DIFFERENT;
else if (!strcasecmp("addIfDifferentNeighbor", value))
Expand All @@ -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_CONFIG;
else if (!strcasecmp("doNothing", value))
*item = MISSING_DO_NOTHING;
else if (!strcasecmp("add", value))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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_CONFIG)
new_item->conf.where = new_trailer_item->where;
if (new_trailer_item->if_exists != EXISTS_DEFAULT)
if (new_trailer_item->if_exists != EXISTS_CONFIG)
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_CONFIG)
new_item->conf.if_missing = new_trailer_item->if_missing;
}
list_add_tail(&new_item->list, arg_head);
Expand Down
6 changes: 3 additions & 3 deletions trailer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
#include "strbuf.h"

enum trailer_where {
WHERE_DEFAULT,
WHERE_CONFIG,
WHERE_END,
WHERE_AFTER,
WHERE_BEFORE,
WHERE_START
};
enum trailer_if_exists {
EXISTS_DEFAULT,
EXISTS_CONFIG,
EXISTS_ADD_IF_DIFFERENT_NEIGHBOR,
EXISTS_ADD_IF_DIFFERENT,
EXISTS_ADD,
EXISTS_REPLACE,
EXISTS_DO_NOTHING
};
enum trailer_if_missing {
MISSING_DEFAULT,
MISSING_CONFIG,
MISSING_ADD,
MISSING_DO_NOTHING
};
Expand Down

0 comments on commit 26acd10

Please sign in to comment.