@@ -295,6 +295,9 @@ static void apply_arg_if_exists(struct trailer_item *in_tok,
295295 else
296296 free_arg_item (arg_tok );
297297 break ;
298+ default :
299+ die ("BUG: trailer.c: unhandled value %d" ,
300+ arg_tok -> conf .if_exists );
298301 }
299302}
300303
@@ -316,6 +319,10 @@ static void apply_arg_if_missing(struct list_head *head,
316319 list_add_tail (& to_add -> list , head );
317320 else
318321 list_add (& to_add -> list , head );
322+ break ;
323+ default :
324+ die ("BUG: trailer.c: unhandled value %d" ,
325+ arg_tok -> conf .if_missing );
319326 }
320327}
321328
@@ -370,7 +377,9 @@ static void process_trailers_lists(struct list_head *head,
370377
371378int trailer_set_where (enum trailer_where * item , const char * value )
372379{
373- if (!strcasecmp ("after" , value ))
380+ if (!value )
381+ * item = WHERE_DEFAULT ;
382+ else if (!strcasecmp ("after" , value ))
374383 * item = WHERE_AFTER ;
375384 else if (!strcasecmp ("before" , value ))
376385 * item = WHERE_BEFORE ;
@@ -385,7 +394,9 @@ int trailer_set_where(enum trailer_where *item, const char *value)
385394
386395int trailer_set_if_exists (enum trailer_if_exists * item , const char * value )
387396{
388- if (!strcasecmp ("addIfDifferent" , value ))
397+ if (!value )
398+ * item = EXISTS_DEFAULT ;
399+ else if (!strcasecmp ("addIfDifferent" , value ))
389400 * item = EXISTS_ADD_IF_DIFFERENT ;
390401 else if (!strcasecmp ("addIfDifferentNeighbor" , value ))
391402 * item = EXISTS_ADD_IF_DIFFERENT_NEIGHBOR ;
@@ -402,7 +413,9 @@ int trailer_set_if_exists(enum trailer_if_exists *item, const char *value)
402413
403414int trailer_set_if_missing (enum trailer_if_missing * item , const char * value )
404415{
405- if (!strcasecmp ("doNothing" , value ))
416+ if (!value )
417+ * item = MISSING_DEFAULT ;
418+ else if (!strcasecmp ("doNothing" , value ))
406419 * item = MISSING_DO_NOTHING ;
407420 else if (!strcasecmp ("add" , value ))
408421 * item = MISSING_ADD ;
@@ -659,12 +672,21 @@ static struct trailer_item *add_trailer_item(struct list_head *head, char *tok,
659672}
660673
661674static void add_arg_item (struct list_head * arg_head , char * tok , char * val ,
662- const struct conf_info * conf )
675+ const struct conf_info * conf ,
676+ const struct new_trailer_item * new_trailer_item )
663677{
664678 struct arg_item * new = xcalloc (sizeof (* new ), 1 );
665679 new -> token = tok ;
666680 new -> value = val ;
667681 duplicate_conf (& new -> conf , conf );
682+ if (new_trailer_item ) {
683+ if (new_trailer_item -> where != WHERE_DEFAULT )
684+ new -> conf .where = new_trailer_item -> where ;
685+ if (new_trailer_item -> if_exists != EXISTS_DEFAULT )
686+ new -> conf .if_exists = new_trailer_item -> if_exists ;
687+ if (new_trailer_item -> if_missing != MISSING_DEFAULT )
688+ new -> conf .if_missing = new_trailer_item -> if_missing ;
689+ }
668690 list_add_tail (& new -> list , arg_head );
669691}
670692
@@ -690,7 +712,7 @@ static void process_command_line_args(struct list_head *arg_head,
690712 add_arg_item (arg_head ,
691713 xstrdup (token_from_item (item , NULL )),
692714 xstrdup ("" ),
693- & item -> conf );
715+ & item -> conf , NULL );
694716 }
695717
696718 /* Add an arg item for each trailer on the command line */
@@ -712,7 +734,7 @@ static void process_command_line_args(struct list_head *arg_head,
712734 add_arg_item (arg_head ,
713735 strbuf_detach (& tok , NULL ),
714736 strbuf_detach (& val , NULL ),
715- conf );
737+ conf , tr );
716738 }
717739 }
718740
0 commit comments