@@ -33,7 +33,6 @@ struct checkout_opts {
3333 int force ;
3434 int force_detach ;
3535 int writeout_stage ;
36- int writeout_error ;
3736 int overwrite_ignore ;
3837
3938 /* not set by parse_options */
@@ -216,7 +215,7 @@ static int checkout_merged(int pos, struct checkout *state)
216215}
217216
218217static int checkout_paths (struct tree * source_tree , const char * * pathspec ,
219- const char * prefix , struct checkout_opts * opts )
218+ const char * prefix , const struct checkout_opts * opts )
220219{
221220 int pos ;
222221 struct checkout state ;
@@ -309,7 +308,8 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec,
309308 return errs ;
310309}
311310
312- static void show_local_changes (struct object * head , struct diff_options * opts )
311+ static void show_local_changes (struct object * head ,
312+ const struct diff_options * opts )
313313{
314314 struct rev_info rev ;
315315 /* I think we want full paths, even if we're in a subdirectory. */
@@ -331,7 +331,8 @@ static void describe_detached_head(const char *msg, struct commit *commit)
331331 strbuf_release (& sb );
332332}
333333
334- static int reset_tree (struct tree * tree , struct checkout_opts * o , int worktree )
334+ static int reset_tree (struct tree * tree , const struct checkout_opts * o ,
335+ int worktree , int * writeout_error )
335336{
336337 struct unpack_trees_options opts ;
337338 struct tree_desc tree_desc ;
@@ -350,7 +351,7 @@ static int reset_tree(struct tree *tree, struct checkout_opts *o, int worktree)
350351 init_tree_desc (& tree_desc , tree -> buffer , tree -> size );
351352 switch (unpack_trees (1 , & tree_desc , & opts )) {
352353 case -2 :
353- o -> writeout_error = 1 ;
354+ * writeout_error = 1 ;
354355 /*
355356 * We return 0 nevertheless, as the index is all right
356357 * and more importantly we have made best efforts to
@@ -381,8 +382,10 @@ static void setup_branch_path(struct branch_info *branch)
381382 branch -> path = strbuf_detach (& buf , NULL );
382383}
383384
384- static int merge_working_tree (struct checkout_opts * opts ,
385- struct branch_info * old , struct branch_info * new )
385+ static int merge_working_tree (const struct checkout_opts * opts ,
386+ struct branch_info * old ,
387+ struct branch_info * new ,
388+ int * writeout_error )
386389{
387390 int ret ;
388391 struct lock_file * lock_file = xcalloc (1 , sizeof (struct lock_file ));
@@ -393,7 +396,7 @@ static int merge_working_tree(struct checkout_opts *opts,
393396
394397 resolve_undo_clear ();
395398 if (opts -> force ) {
396- ret = reset_tree (new -> commit -> tree , opts , 1 );
399+ ret = reset_tree (new -> commit -> tree , opts , 1 , writeout_error );
397400 if (ret )
398401 return ret ;
399402 } else {
@@ -479,15 +482,17 @@ static int merge_working_tree(struct checkout_opts *opts,
479482 o .verbosity = 0 ;
480483 work = write_tree_from_memory (& o );
481484
482- ret = reset_tree (new -> commit -> tree , opts , 1 );
485+ ret = reset_tree (new -> commit -> tree , opts , 1 ,
486+ writeout_error );
483487 if (ret )
484488 return ret ;
485489 o .ancestor = old -> name ;
486490 o .branch1 = new -> name ;
487491 o .branch2 = "local" ;
488492 merge_trees (& o , new -> commit -> tree , work ,
489493 old -> commit -> tree , & result );
490- ret = reset_tree (new -> commit -> tree , opts , 0 );
494+ ret = reset_tree (new -> commit -> tree , opts , 0 ,
495+ writeout_error );
491496 if (ret )
492497 return ret ;
493498 }
@@ -514,7 +519,7 @@ static void report_tracking(struct branch_info *new)
514519 strbuf_release (& sb );
515520}
516521
517- static void update_refs_for_switch (struct checkout_opts * opts ,
522+ static void update_refs_for_switch (const struct checkout_opts * opts ,
518523 struct branch_info * old ,
519524 struct branch_info * new )
520525{
@@ -701,13 +706,13 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new)
701706 free (refs .objects );
702707}
703708
704- static int switch_branches (struct checkout_opts * opts , struct branch_info * new )
709+ static int switch_branches (const struct checkout_opts * opts , struct branch_info * new )
705710{
706711 int ret = 0 ;
707712 struct branch_info old ;
708713 void * path_to_free ;
709714 unsigned char rev [20 ];
710- int flag ;
715+ int flag , writeout_error = 0 ;
711716 memset (& old , 0 , sizeof (old ));
712717 old .path = path_to_free = resolve_refdup ("HEAD" , rev , 0 , & flag );
713718 old .commit = lookup_commit_reference_gently (rev , 1 );
@@ -725,7 +730,7 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
725730 parse_commit (new -> commit );
726731 }
727732
728- ret = merge_working_tree (opts , & old , new );
733+ ret = merge_working_tree (opts , & old , new , & writeout_error );
729734 if (ret ) {
730735 free (path_to_free );
731736 return ret ;
@@ -738,7 +743,7 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
738743
739744 ret = post_checkout_hook (old .commit , new -> commit , 1 );
740745 free (path_to_free );
741- return ret || opts -> writeout_error ;
746+ return ret || writeout_error ;
742747}
743748
744749static int git_checkout_config (const char * var , const char * value , void * cb )
@@ -910,7 +915,7 @@ static int parse_branchname_arg(int argc, const char **argv,
910915 return argcount ;
911916}
912917
913- static int switch_unborn_to_new_branch (struct checkout_opts * opts )
918+ static int switch_unborn_to_new_branch (const struct checkout_opts * opts )
914919{
915920 int status ;
916921 struct strbuf branch_ref = STRBUF_INIT ;
0 commit comments