@@ -219,6 +219,8 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
219
219
}
220
220
#endif
221
221
ret = o -> fn (src , o , remove );
222
+ if (ret < 0 )
223
+ return ret ;
222
224
223
225
#if DBRT_DEBUG > 1
224
226
printf ("Added %d entries\n" , ret );
@@ -359,18 +361,18 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
359
361
}
360
362
361
363
if (o -> trivial_merges_only && o -> nontrivial_merge )
362
- die ("Merge requires file-level merging" );
364
+ return error ("Merge requires file-level merging" );
363
365
364
366
check_updates (active_cache , active_nr , o );
365
367
return 0 ;
366
368
}
367
369
368
370
/* Here come the merge functions */
369
371
370
- static void reject_merge (struct cache_entry * ce )
372
+ static int reject_merge (struct cache_entry * ce )
371
373
{
372
- die ("Entry '%s' would be overwritten by merge. Cannot merge." ,
373
- ce -> name );
374
+ return error ("Entry '%s' would be overwritten by merge. Cannot merge." ,
375
+ ce -> name );
374
376
}
375
377
376
378
static int same (struct cache_entry * a , struct cache_entry * b )
@@ -388,18 +390,18 @@ static int same(struct cache_entry *a, struct cache_entry *b)
388
390
* When a CE gets turned into an unmerged entry, we
389
391
* want it to be up-to-date
390
392
*/
391
- static void verify_uptodate (struct cache_entry * ce ,
393
+ static int verify_uptodate (struct cache_entry * ce ,
392
394
struct unpack_trees_options * o )
393
395
{
394
396
struct stat st ;
395
397
396
398
if (o -> index_only || o -> reset )
397
- return ;
399
+ return 0 ;
398
400
399
401
if (!lstat (ce -> name , & st )) {
400
402
unsigned changed = ce_match_stat (ce , & st , CE_MATCH_IGNORE_VALID );
401
403
if (!changed )
402
- return ;
404
+ return 0 ;
403
405
/*
404
406
* NEEDSWORK: the current default policy is to allow
405
407
* submodule to be out of sync wrt the supermodule
@@ -408,12 +410,12 @@ static void verify_uptodate(struct cache_entry *ce,
408
410
* checked out.
409
411
*/
410
412
if (S_ISGITLINK (ce -> ce_mode ))
411
- return ;
413
+ return 0 ;
412
414
errno = 0 ;
413
415
}
414
416
if (errno == ENOENT )
415
- return ;
416
- die ("Entry '%s' not uptodate. Cannot merge." , ce -> name );
417
+ return 0 ;
418
+ return error ("Entry '%s' not uptodate. Cannot merge." , ce -> name );
417
419
}
418
420
419
421
static void invalidate_ce_path (struct cache_entry * ce )
@@ -479,7 +481,8 @@ static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
479
481
* ce->name is an entry in the subdirectory.
480
482
*/
481
483
if (!ce_stage (ce )) {
482
- verify_uptodate (ce , o );
484
+ if (verify_uptodate (ce , o ))
485
+ return -1 ;
483
486
ce -> ce_flags |= CE_REMOVE ;
484
487
}
485
488
cnt ++ ;
@@ -498,8 +501,8 @@ static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
498
501
d .exclude_per_dir = o -> dir -> exclude_per_dir ;
499
502
i = read_directory (& d , ce -> name , pathbuf , namelen + 1 , NULL );
500
503
if (i )
501
- die ("Updating '%s' would lose untracked files in it" ,
502
- ce -> name );
504
+ return error ("Updating '%s' would lose untracked files in it" ,
505
+ ce -> name );
503
506
free (pathbuf );
504
507
return cnt ;
505
508
}
@@ -508,16 +511,16 @@ static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
508
511
* We do not want to remove or overwrite a working tree file that
509
512
* is not tracked, unless it is ignored.
510
513
*/
511
- static void verify_absent (struct cache_entry * ce , const char * action ,
512
- struct unpack_trees_options * o )
514
+ static int verify_absent (struct cache_entry * ce , const char * action ,
515
+ struct unpack_trees_options * o )
513
516
{
514
517
struct stat st ;
515
518
516
519
if (o -> index_only || o -> reset || !o -> update )
517
- return ;
520
+ return 0 ;
518
521
519
522
if (has_symlink_leading_path (ce -> name , NULL ))
520
- return ;
523
+ return 0 ;
521
524
522
525
if (!lstat (ce -> name , & st )) {
523
526
int cnt ;
@@ -527,7 +530,7 @@ static void verify_absent(struct cache_entry *ce, const char *action,
527
530
* ce->name is explicitly excluded, so it is Ok to
528
531
* overwrite it.
529
532
*/
530
- return ;
533
+ return 0 ;
531
534
if (S_ISDIR (st .st_mode )) {
532
535
/*
533
536
* We are checking out path "foo" and
@@ -556,7 +559,7 @@ static void verify_absent(struct cache_entry *ce, const char *action,
556
559
* deleted entries here.
557
560
*/
558
561
o -> pos += cnt ;
559
- return ;
562
+ return 0 ;
560
563
}
561
564
562
565
/*
@@ -568,12 +571,13 @@ static void verify_absent(struct cache_entry *ce, const char *action,
568
571
if (0 <= cnt ) {
569
572
struct cache_entry * ce = active_cache [cnt ];
570
573
if (ce -> ce_flags & CE_REMOVE )
571
- return ;
574
+ return 0 ;
572
575
}
573
576
574
- die ("Untracked working tree file '%s' "
575
- "would be %s by merge." , ce -> name , action );
577
+ return error ("Untracked working tree file '%s' "
578
+ "would be %s by merge." , ce -> name , action );
576
579
}
580
+ return 0 ;
577
581
}
578
582
579
583
static int merged_entry (struct cache_entry * merge , struct cache_entry * old ,
@@ -591,12 +595,14 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
591
595
if (same (old , merge )) {
592
596
memcpy (merge , old , offsetof(struct cache_entry , name ));
593
597
} else {
594
- verify_uptodate (old , o );
598
+ if (verify_uptodate (old , o ))
599
+ return -1 ;
595
600
invalidate_ce_path (old );
596
601
}
597
602
}
598
603
else {
599
- verify_absent (merge , "overwritten" , o );
604
+ if (verify_absent (merge , "overwritten" , o ))
605
+ return -1 ;
600
606
invalidate_ce_path (merge );
601
607
}
602
608
@@ -608,10 +614,12 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
608
614
static int deleted_entry (struct cache_entry * ce , struct cache_entry * old ,
609
615
struct unpack_trees_options * o )
610
616
{
611
- if (old )
612
- verify_uptodate (old , o );
613
- else
614
- verify_absent (ce , "removed" , o );
617
+ if (old ) {
618
+ if (verify_uptodate (old , o ))
619
+ return -1 ;
620
+ } else
621
+ if (verify_absent (ce , "removed" , o ))
622
+ return -1 ;
615
623
ce -> ce_flags |= CE_REMOVE ;
616
624
add_cache_entry (ce , ADD_CACHE_OK_TO_ADD |ADD_CACHE_OK_TO_REPLACE );
617
625
invalidate_ce_path (ce );
@@ -699,15 +707,15 @@ int threeway_merge(struct cache_entry **stages,
699
707
/* #14, #14ALT, #2ALT */
700
708
if (remote && !df_conflict_head && head_match && !remote_match ) {
701
709
if (index && !same (index , remote ) && !same (index , head ))
702
- reject_merge (index );
710
+ return reject_merge (index );
703
711
return merged_entry (remote , index , o );
704
712
}
705
713
/*
706
714
* If we have an entry in the index cache, then we want to
707
715
* make sure that it matches head.
708
716
*/
709
717
if (index && !same (index , head )) {
710
- reject_merge (index );
718
+ return reject_merge (index );
711
719
}
712
720
713
721
if (head ) {
@@ -758,8 +766,10 @@ int threeway_merge(struct cache_entry **stages,
758
766
remove_entry (remove );
759
767
if (index )
760
768
return deleted_entry (index , index , o );
761
- else if (ce && !head_deleted )
762
- verify_absent (ce , "removed" , o );
769
+ else if (ce && !head_deleted ) {
770
+ if (verify_absent (ce , "removed" , o ))
771
+ return -1 ;
772
+ }
763
773
return 0 ;
764
774
}
765
775
/*
@@ -775,7 +785,8 @@ int threeway_merge(struct cache_entry **stages,
775
785
* conflict resolution files.
776
786
*/
777
787
if (index ) {
778
- verify_uptodate (index , o );
788
+ if (verify_uptodate (index , o ))
789
+ return -1 ;
779
790
}
780
791
781
792
remove_entry (remove );
@@ -855,11 +866,11 @@ int twoway_merge(struct cache_entry **src,
855
866
/* all other failures */
856
867
remove_entry (remove );
857
868
if (oldtree )
858
- reject_merge (oldtree );
869
+ return reject_merge (oldtree );
859
870
if (current )
860
- reject_merge (current );
871
+ return reject_merge (current );
861
872
if (newtree )
862
- reject_merge (newtree );
873
+ return reject_merge (newtree );
863
874
return -1 ;
864
875
}
865
876
}
@@ -886,7 +897,7 @@ int bind_merge(struct cache_entry **src,
886
897
return error ("Cannot do a bind merge of %d trees\n" ,
887
898
o -> merge_size );
888
899
if (a && old )
889
- die ("Entry '%s' overlaps. Cannot bind." , a -> name );
900
+ return error ("Entry '%s' overlaps. Cannot bind." , a -> name );
890
901
if (!a )
891
902
return keep_entry (old , o );
892
903
else
0 commit comments