@@ -548,13 +548,53 @@ static void write_tree_trivial(unsigned char *sha1)
548
548
die ("git write-tree failed to write a tree" );
549
549
}
550
550
551
- static int try_merge_strategy (const char * strategy , struct commit_list * common ,
552
- const char * head_arg )
551
+ static int try_merge_command (const char * strategy , struct commit_list * common ,
552
+ const char * head_arg , struct commit_list * remotes )
553
553
{
554
554
const char * * args ;
555
555
int i = 0 , x = 0 , ret ;
556
556
struct commit_list * j ;
557
557
struct strbuf buf = STRBUF_INIT ;
558
+
559
+ args = xmalloc ((4 + xopts_nr + commit_list_count (common ) +
560
+ commit_list_count (remotes )) * sizeof (char * ));
561
+ strbuf_addf (& buf , "merge-%s" , strategy );
562
+ args [i ++ ] = buf .buf ;
563
+ for (x = 0 ; x < xopts_nr ; x ++ ) {
564
+ char * s = xmalloc (strlen (xopts [x ])+ 2 + 1 );
565
+ strcpy (s , "--" );
566
+ strcpy (s + 2 , xopts [x ]);
567
+ args [i ++ ] = s ;
568
+ }
569
+ for (j = common ; j ; j = j -> next )
570
+ args [i ++ ] = xstrdup (sha1_to_hex (j -> item -> object .sha1 ));
571
+ args [i ++ ] = "--" ;
572
+ args [i ++ ] = head_arg ;
573
+ for (j = remotes ; j ; j = j -> next )
574
+ args [i ++ ] = xstrdup (sha1_to_hex (j -> item -> object .sha1 ));
575
+ args [i ] = NULL ;
576
+ ret = run_command_v_opt (args , RUN_GIT_CMD );
577
+ strbuf_release (& buf );
578
+ i = 1 ;
579
+ for (x = 0 ; x < xopts_nr ; x ++ )
580
+ free ((void * )args [i ++ ]);
581
+ for (j = common ; j ; j = j -> next )
582
+ free ((void * )args [i ++ ]);
583
+ i += 2 ;
584
+ for (j = remotes ; j ; j = j -> next )
585
+ free ((void * )args [i ++ ]);
586
+ free (args );
587
+ discard_cache ();
588
+ if (read_cache () < 0 )
589
+ die ("failed to read the cache" );
590
+ resolve_undo_clear ();
591
+
592
+ return ret ;
593
+ }
594
+
595
+ static int try_merge_strategy (const char * strategy , struct commit_list * common ,
596
+ const char * head_arg )
597
+ {
558
598
int index_fd ;
559
599
struct lock_file * lock = xcalloc (1 , sizeof (struct lock_file ));
560
600
@@ -567,12 +607,13 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
567
607
rollback_lock_file (lock );
568
608
569
609
if (!strcmp (strategy , "recursive" ) || !strcmp (strategy , "subtree" )) {
570
- int clean ;
610
+ int clean , x ;
571
611
struct commit * result ;
572
612
struct lock_file * lock = xcalloc (1 , sizeof (struct lock_file ));
573
613
int index_fd ;
574
614
struct commit_list * reversed = NULL ;
575
615
struct merge_options o ;
616
+ struct commit_list * j ;
576
617
577
618
if (remoteheads -> next ) {
578
619
error ("Not handling anything other than two heads merge." );
@@ -612,39 +653,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
612
653
rollback_lock_file (lock );
613
654
return clean ? 0 : 1 ;
614
655
} else {
615
- args = xmalloc ((4 + xopts_nr + commit_list_count (common ) +
616
- commit_list_count (remoteheads )) * sizeof (char * ));
617
- strbuf_addf (& buf , "merge-%s" , strategy );
618
- args [i ++ ] = buf .buf ;
619
- for (x = 0 ; x < xopts_nr ; x ++ ) {
620
- char * s = xmalloc (strlen (xopts [x ])+ 2 + 1 );
621
- strcpy (s , "--" );
622
- strcpy (s + 2 , xopts [x ]);
623
- args [i ++ ] = s ;
624
- }
625
- for (j = common ; j ; j = j -> next )
626
- args [i ++ ] = xstrdup (sha1_to_hex (j -> item -> object .sha1 ));
627
- args [i ++ ] = "--" ;
628
- args [i ++ ] = head_arg ;
629
- for (j = remoteheads ; j ; j = j -> next )
630
- args [i ++ ] = xstrdup (sha1_to_hex (j -> item -> object .sha1 ));
631
- args [i ] = NULL ;
632
- ret = run_command_v_opt (args , RUN_GIT_CMD );
633
- strbuf_release (& buf );
634
- i = 1 ;
635
- for (x = 0 ; x < xopts_nr ; x ++ )
636
- free ((void * )args [i ++ ]);
637
- for (j = common ; j ; j = j -> next )
638
- free ((void * )args [i ++ ]);
639
- i += 2 ;
640
- for (j = remoteheads ; j ; j = j -> next )
641
- free ((void * )args [i ++ ]);
642
- free (args );
643
- discard_cache ();
644
- if (read_cache () < 0 )
645
- die ("failed to read the cache" );
646
- resolve_undo_clear ();
647
- return ret ;
656
+ return try_merge_command (strategy , common , head_arg , remoteheads );
648
657
}
649
658
}
650
659
0 commit comments