Skip to content

Commit 52fc319

Browse files
bonzinigitster
authored andcommitted
trailers: export action enums and corresponding lookup functions
Separate the mechanical changes out of the next patch. The functions are changed to take a pointer to enum, because struct conf_info is not going to be public. Set the default values explicitly in default_conf_info, since they are not anymore close to default_conf_info and it's not obvious which constant has value 0. With the next patches, in fact, the values will not be zero anymore! Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5800c63 commit 52fc319

File tree

2 files changed

+55
-32
lines changed

2 files changed

+55
-32
lines changed

trailer.c

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@
1010
* Copyright (c) 2013, 2014 Christian Couder <[email protected]>
1111
*/
1212

13-
enum action_where { WHERE_END, WHERE_AFTER, WHERE_BEFORE, WHERE_START };
14-
enum action_if_exists { EXISTS_ADD_IF_DIFFERENT_NEIGHBOR, EXISTS_ADD_IF_DIFFERENT,
15-
EXISTS_ADD, EXISTS_REPLACE, EXISTS_DO_NOTHING };
16-
enum action_if_missing { MISSING_ADD, MISSING_DO_NOTHING };
17-
1813
struct conf_info {
1914
char *name;
2015
char *key;
2116
char *command;
22-
enum action_where where;
23-
enum action_if_exists if_exists;
24-
enum action_if_missing if_missing;
17+
enum trailer_where where;
18+
enum trailer_if_exists if_exists;
19+
enum trailer_if_missing if_missing;
2520
};
2621

2722
static struct conf_info default_conf_info;
@@ -63,7 +58,7 @@ static const char *git_generated_prefixes[] = {
6358
pos != (head); \
6459
pos = is_reverse ? pos->prev : pos->next)
6560

66-
static int after_or_end(enum action_where where)
61+
static int after_or_end(enum trailer_where where)
6762
{
6863
return (where == WHERE_AFTER) || (where == WHERE_END);
6964
}
@@ -201,7 +196,7 @@ static int check_if_different(struct trailer_item *in_tok,
201196
int check_all,
202197
struct list_head *head)
203198
{
204-
enum action_where where = arg_tok->conf.where;
199+
enum trailer_where where = arg_tok->conf.where;
205200
struct list_head *next_head;
206201
do {
207202
if (same_trailer(in_tok, arg_tok))
@@ -306,7 +301,7 @@ static void apply_arg_if_exists(struct trailer_item *in_tok,
306301
static void apply_arg_if_missing(struct list_head *head,
307302
struct arg_item *arg_tok)
308303
{
309-
enum action_where where;
304+
enum trailer_where where;
310305
struct trailer_item *to_add;
311306

312307
switch (arg_tok->conf.if_missing) {
@@ -331,7 +326,7 @@ static int find_same_and_apply_arg(struct list_head *head,
331326
struct trailer_item *in_tok;
332327
struct trailer_item *on_tok;
333328

334-
enum action_where where = arg_tok->conf.where;
329+
enum trailer_where where = arg_tok->conf.where;
335330
int middle = (where == WHERE_AFTER) || (where == WHERE_BEFORE);
336331
int backwards = after_or_end(where);
337332
struct trailer_item *start_tok;
@@ -373,44 +368,44 @@ static void process_trailers_lists(struct list_head *head,
373368
}
374369
}
375370

376-
static int set_where(struct conf_info *item, const char *value)
371+
int trailer_set_where(enum trailer_where *item, const char *value)
377372
{
378373
if (!strcasecmp("after", value))
379-
item->where = WHERE_AFTER;
374+
*item = WHERE_AFTER;
380375
else if (!strcasecmp("before", value))
381-
item->where = WHERE_BEFORE;
376+
*item = WHERE_BEFORE;
382377
else if (!strcasecmp("end", value))
383-
item->where = WHERE_END;
378+
*item = WHERE_END;
384379
else if (!strcasecmp("start", value))
385-
item->where = WHERE_START;
380+
*item = WHERE_START;
386381
else
387382
return -1;
388383
return 0;
389384
}
390385

391-
static int set_if_exists(struct conf_info *item, const char *value)
386+
int trailer_set_if_exists(enum trailer_if_exists *item, const char *value)
392387
{
393388
if (!strcasecmp("addIfDifferent", value))
394-
item->if_exists = EXISTS_ADD_IF_DIFFERENT;
389+
*item = EXISTS_ADD_IF_DIFFERENT;
395390
else if (!strcasecmp("addIfDifferentNeighbor", value))
396-
item->if_exists = EXISTS_ADD_IF_DIFFERENT_NEIGHBOR;
391+
*item = EXISTS_ADD_IF_DIFFERENT_NEIGHBOR;
397392
else if (!strcasecmp("add", value))
398-
item->if_exists = EXISTS_ADD;
393+
*item = EXISTS_ADD;
399394
else if (!strcasecmp("replace", value))
400-
item->if_exists = EXISTS_REPLACE;
395+
*item = EXISTS_REPLACE;
401396
else if (!strcasecmp("doNothing", value))
402-
item->if_exists = EXISTS_DO_NOTHING;
397+
*item = EXISTS_DO_NOTHING;
403398
else
404399
return -1;
405400
return 0;
406401
}
407402

408-
static int set_if_missing(struct conf_info *item, const char *value)
403+
int trailer_set_if_missing(enum trailer_if_missing *item, const char *value)
409404
{
410405
if (!strcasecmp("doNothing", value))
411-
item->if_missing = MISSING_DO_NOTHING;
406+
*item = MISSING_DO_NOTHING;
412407
else if (!strcasecmp("add", value))
413-
item->if_missing = MISSING_ADD;
408+
*item = MISSING_ADD;
414409
else
415410
return -1;
416411
return 0;
@@ -470,15 +465,18 @@ static int git_trailer_default_config(const char *conf_key, const char *value, v
470465
variable_name = strrchr(trailer_item, '.');
471466
if (!variable_name) {
472467
if (!strcmp(trailer_item, "where")) {
473-
if (set_where(&default_conf_info, value) < 0)
468+
if (trailer_set_where(&default_conf_info.where,
469+
value) < 0)
474470
warning(_("unknown value '%s' for key '%s'"),
475471
value, conf_key);
476472
} else if (!strcmp(trailer_item, "ifexists")) {
477-
if (set_if_exists(&default_conf_info, value) < 0)
473+
if (trailer_set_if_exists(&default_conf_info.if_exists,
474+
value) < 0)
478475
warning(_("unknown value '%s' for key '%s'"),
479476
value, conf_key);
480477
} else if (!strcmp(trailer_item, "ifmissing")) {
481-
if (set_if_missing(&default_conf_info, value) < 0)
478+
if (trailer_set_if_missing(&default_conf_info.if_missing,
479+
value) < 0)
482480
warning(_("unknown value '%s' for key '%s'"),
483481
value, conf_key);
484482
} else if (!strcmp(trailer_item, "separators")) {
@@ -532,15 +530,15 @@ static int git_trailer_config(const char *conf_key, const char *value, void *cb)
532530
conf->command = xstrdup(value);
533531
break;
534532
case TRAILER_WHERE:
535-
if (set_where(conf, value))
533+
if (trailer_set_where(&conf->where, value))
536534
warning(_("unknown value '%s' for key '%s'"), value, conf_key);
537535
break;
538536
case TRAILER_IF_EXISTS:
539-
if (set_if_exists(conf, value))
537+
if (trailer_set_if_exists(&conf->if_exists, value))
540538
warning(_("unknown value '%s' for key '%s'"), value, conf_key);
541539
break;
542540
case TRAILER_IF_MISSING:
543-
if (set_if_missing(conf, value))
541+
if (trailer_set_if_missing(&conf->if_missing, value))
544542
warning(_("unknown value '%s' for key '%s'"), value, conf_key);
545543
break;
546544
default:
@@ -555,6 +553,9 @@ static void ensure_configured(void)
555553
return;
556554

557555
/* Default config must be setup first */
556+
default_conf_info.where = WHERE_END;
557+
default_conf_info.if_exists = EXISTS_ADD_IF_DIFFERENT_NEIGHBOR;
558+
default_conf_info.if_missing = MISSING_ADD;
558559
git_config(git_trailer_default_config, NULL);
559560
git_config(git_trailer_config, NULL);
560561
configured = 1;

trailer.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
#ifndef TRAILER_H
22
#define TRAILER_H
33

4+
enum trailer_where {
5+
WHERE_END,
6+
WHERE_AFTER,
7+
WHERE_BEFORE,
8+
WHERE_START
9+
};
10+
enum trailer_if_exists {
11+
EXISTS_ADD_IF_DIFFERENT_NEIGHBOR,
12+
EXISTS_ADD_IF_DIFFERENT,
13+
EXISTS_ADD,
14+
EXISTS_REPLACE,
15+
EXISTS_DO_NOTHING
16+
};
17+
enum trailer_if_missing {
18+
MISSING_ADD,
19+
MISSING_DO_NOTHING
20+
};
21+
22+
int trailer_set_where(enum trailer_where *item, const char *value);
23+
int trailer_set_if_exists(enum trailer_if_exists *item, const char *value);
24+
int trailer_set_if_missing(enum trailer_if_missing *item, const char *value);
25+
426
struct trailer_info {
527
/*
628
* True if there is a blank line before the location pointed to by

0 commit comments

Comments
 (0)