10
10
* Copyright (c) 2013, 2014 Christian Couder <[email protected] >
11
11
*/
12
12
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
-
18
13
struct conf_info {
19
14
char * name ;
20
15
char * key ;
21
16
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 ;
25
20
};
26
21
27
22
static struct conf_info default_conf_info ;
@@ -63,7 +58,7 @@ static const char *git_generated_prefixes[] = {
63
58
pos != (head); \
64
59
pos = is_reverse ? pos->prev : pos->next)
65
60
66
- static int after_or_end (enum action_where where )
61
+ static int after_or_end (enum trailer_where where )
67
62
{
68
63
return (where == WHERE_AFTER ) || (where == WHERE_END );
69
64
}
@@ -201,7 +196,7 @@ static int check_if_different(struct trailer_item *in_tok,
201
196
int check_all ,
202
197
struct list_head * head )
203
198
{
204
- enum action_where where = arg_tok -> conf .where ;
199
+ enum trailer_where where = arg_tok -> conf .where ;
205
200
struct list_head * next_head ;
206
201
do {
207
202
if (same_trailer (in_tok , arg_tok ))
@@ -306,7 +301,7 @@ static void apply_arg_if_exists(struct trailer_item *in_tok,
306
301
static void apply_arg_if_missing (struct list_head * head ,
307
302
struct arg_item * arg_tok )
308
303
{
309
- enum action_where where ;
304
+ enum trailer_where where ;
310
305
struct trailer_item * to_add ;
311
306
312
307
switch (arg_tok -> conf .if_missing ) {
@@ -331,7 +326,7 @@ static int find_same_and_apply_arg(struct list_head *head,
331
326
struct trailer_item * in_tok ;
332
327
struct trailer_item * on_tok ;
333
328
334
- enum action_where where = arg_tok -> conf .where ;
329
+ enum trailer_where where = arg_tok -> conf .where ;
335
330
int middle = (where == WHERE_AFTER ) || (where == WHERE_BEFORE );
336
331
int backwards = after_or_end (where );
337
332
struct trailer_item * start_tok ;
@@ -373,44 +368,44 @@ static void process_trailers_lists(struct list_head *head,
373
368
}
374
369
}
375
370
376
- static int set_where ( struct conf_info * item , const char * value )
371
+ int trailer_set_where ( enum trailer_where * item , const char * value )
377
372
{
378
373
if (!strcasecmp ("after" , value ))
379
- item -> where = WHERE_AFTER ;
374
+ * item = WHERE_AFTER ;
380
375
else if (!strcasecmp ("before" , value ))
381
- item -> where = WHERE_BEFORE ;
376
+ * item = WHERE_BEFORE ;
382
377
else if (!strcasecmp ("end" , value ))
383
- item -> where = WHERE_END ;
378
+ * item = WHERE_END ;
384
379
else if (!strcasecmp ("start" , value ))
385
- item -> where = WHERE_START ;
380
+ * item = WHERE_START ;
386
381
else
387
382
return -1 ;
388
383
return 0 ;
389
384
}
390
385
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 )
392
387
{
393
388
if (!strcasecmp ("addIfDifferent" , value ))
394
- item -> if_exists = EXISTS_ADD_IF_DIFFERENT ;
389
+ * item = EXISTS_ADD_IF_DIFFERENT ;
395
390
else if (!strcasecmp ("addIfDifferentNeighbor" , value ))
396
- item -> if_exists = EXISTS_ADD_IF_DIFFERENT_NEIGHBOR ;
391
+ * item = EXISTS_ADD_IF_DIFFERENT_NEIGHBOR ;
397
392
else if (!strcasecmp ("add" , value ))
398
- item -> if_exists = EXISTS_ADD ;
393
+ * item = EXISTS_ADD ;
399
394
else if (!strcasecmp ("replace" , value ))
400
- item -> if_exists = EXISTS_REPLACE ;
395
+ * item = EXISTS_REPLACE ;
401
396
else if (!strcasecmp ("doNothing" , value ))
402
- item -> if_exists = EXISTS_DO_NOTHING ;
397
+ * item = EXISTS_DO_NOTHING ;
403
398
else
404
399
return -1 ;
405
400
return 0 ;
406
401
}
407
402
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 )
409
404
{
410
405
if (!strcasecmp ("doNothing" , value ))
411
- item -> if_missing = MISSING_DO_NOTHING ;
406
+ * item = MISSING_DO_NOTHING ;
412
407
else if (!strcasecmp ("add" , value ))
413
- item -> if_missing = MISSING_ADD ;
408
+ * item = MISSING_ADD ;
414
409
else
415
410
return -1 ;
416
411
return 0 ;
@@ -470,15 +465,18 @@ static int git_trailer_default_config(const char *conf_key, const char *value, v
470
465
variable_name = strrchr (trailer_item , '.' );
471
466
if (!variable_name ) {
472
467
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 )
474
470
warning (_ ("unknown value '%s' for key '%s'" ),
475
471
value , conf_key );
476
472
} 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 )
478
475
warning (_ ("unknown value '%s' for key '%s'" ),
479
476
value , conf_key );
480
477
} 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 )
482
480
warning (_ ("unknown value '%s' for key '%s'" ),
483
481
value , conf_key );
484
482
} else if (!strcmp (trailer_item , "separators" )) {
@@ -532,15 +530,15 @@ static int git_trailer_config(const char *conf_key, const char *value, void *cb)
532
530
conf -> command = xstrdup (value );
533
531
break ;
534
532
case TRAILER_WHERE :
535
- if (set_where ( conf , value ))
533
+ if (trailer_set_where ( & conf -> where , value ))
536
534
warning (_ ("unknown value '%s' for key '%s'" ), value , conf_key );
537
535
break ;
538
536
case TRAILER_IF_EXISTS :
539
- if (set_if_exists ( conf , value ))
537
+ if (trailer_set_if_exists ( & conf -> if_exists , value ))
540
538
warning (_ ("unknown value '%s' for key '%s'" ), value , conf_key );
541
539
break ;
542
540
case TRAILER_IF_MISSING :
543
- if (set_if_missing ( conf , value ))
541
+ if (trailer_set_if_missing ( & conf -> if_missing , value ))
544
542
warning (_ ("unknown value '%s' for key '%s'" ), value , conf_key );
545
543
break ;
546
544
default :
@@ -555,6 +553,9 @@ static void ensure_configured(void)
555
553
return ;
556
554
557
555
/* 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 ;
558
559
git_config (git_trailer_default_config , NULL );
559
560
git_config (git_trailer_config , NULL );
560
561
configured = 1 ;
0 commit comments