@@ -33,7 +33,6 @@ struct checkout_opts {
33
33
int force ;
34
34
int force_detach ;
35
35
int writeout_stage ;
36
- int writeout_error ;
37
36
int overwrite_ignore ;
38
37
39
38
/* not set by parse_options */
@@ -216,7 +215,7 @@ static int checkout_merged(int pos, struct checkout *state)
216
215
}
217
216
218
217
static 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 )
220
219
{
221
220
int pos ;
222
221
struct checkout state ;
@@ -309,7 +308,8 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec,
309
308
return errs ;
310
309
}
311
310
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 )
313
313
{
314
314
struct rev_info rev ;
315
315
/* 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)
331
331
strbuf_release (& sb );
332
332
}
333
333
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 )
335
336
{
336
337
struct unpack_trees_options opts ;
337
338
struct tree_desc tree_desc ;
@@ -350,7 +351,7 @@ static int reset_tree(struct tree *tree, struct checkout_opts *o, int worktree)
350
351
init_tree_desc (& tree_desc , tree -> buffer , tree -> size );
351
352
switch (unpack_trees (1 , & tree_desc , & opts )) {
352
353
case -2 :
353
- o -> writeout_error = 1 ;
354
+ * writeout_error = 1 ;
354
355
/*
355
356
* We return 0 nevertheless, as the index is all right
356
357
* and more importantly we have made best efforts to
@@ -381,8 +382,10 @@ static void setup_branch_path(struct branch_info *branch)
381
382
branch -> path = strbuf_detach (& buf , NULL );
382
383
}
383
384
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 )
386
389
{
387
390
int ret ;
388
391
struct lock_file * lock_file = xcalloc (1 , sizeof (struct lock_file ));
@@ -393,7 +396,7 @@ static int merge_working_tree(struct checkout_opts *opts,
393
396
394
397
resolve_undo_clear ();
395
398
if (opts -> force ) {
396
- ret = reset_tree (new -> commit -> tree , opts , 1 );
399
+ ret = reset_tree (new -> commit -> tree , opts , 1 , writeout_error );
397
400
if (ret )
398
401
return ret ;
399
402
} else {
@@ -479,15 +482,17 @@ static int merge_working_tree(struct checkout_opts *opts,
479
482
o .verbosity = 0 ;
480
483
work = write_tree_from_memory (& o );
481
484
482
- ret = reset_tree (new -> commit -> tree , opts , 1 );
485
+ ret = reset_tree (new -> commit -> tree , opts , 1 ,
486
+ writeout_error );
483
487
if (ret )
484
488
return ret ;
485
489
o .ancestor = old -> name ;
486
490
o .branch1 = new -> name ;
487
491
o .branch2 = "local" ;
488
492
merge_trees (& o , new -> commit -> tree , work ,
489
493
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 );
491
496
if (ret )
492
497
return ret ;
493
498
}
@@ -514,7 +519,7 @@ static void report_tracking(struct branch_info *new)
514
519
strbuf_release (& sb );
515
520
}
516
521
517
- static void update_refs_for_switch (struct checkout_opts * opts ,
522
+ static void update_refs_for_switch (const struct checkout_opts * opts ,
518
523
struct branch_info * old ,
519
524
struct branch_info * new )
520
525
{
@@ -701,13 +706,13 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new)
701
706
free (refs .objects );
702
707
}
703
708
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 )
705
710
{
706
711
int ret = 0 ;
707
712
struct branch_info old ;
708
713
void * path_to_free ;
709
714
unsigned char rev [20 ];
710
- int flag ;
715
+ int flag , writeout_error = 0 ;
711
716
memset (& old , 0 , sizeof (old ));
712
717
old .path = path_to_free = resolve_refdup ("HEAD" , rev , 0 , & flag );
713
718
old .commit = lookup_commit_reference_gently (rev , 1 );
@@ -725,7 +730,7 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
725
730
parse_commit (new -> commit );
726
731
}
727
732
728
- ret = merge_working_tree (opts , & old , new );
733
+ ret = merge_working_tree (opts , & old , new , & writeout_error );
729
734
if (ret ) {
730
735
free (path_to_free );
731
736
return ret ;
@@ -738,7 +743,7 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
738
743
739
744
ret = post_checkout_hook (old .commit , new -> commit , 1 );
740
745
free (path_to_free );
741
- return ret || opts -> writeout_error ;
746
+ return ret || writeout_error ;
742
747
}
743
748
744
749
static 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,
910
915
return argcount ;
911
916
}
912
917
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 )
914
919
{
915
920
int status ;
916
921
struct strbuf branch_ref = STRBUF_INIT ;
0 commit comments