@@ -381,7 +381,7 @@ static void add_same_unmerged(struct cache_entry *ce,
381
381
static int unpack_index_entry (struct cache_entry * ce ,
382
382
struct unpack_trees_options * o )
383
383
{
384
- struct cache_entry * src [5 ] = { NULL };
384
+ struct cache_entry * src [MAX_UNPACK_TREES + 1 ] = { NULL , };
385
385
int ret ;
386
386
387
387
src [0 ] = ce ;
@@ -427,14 +427,26 @@ static int switch_cache_bottom(struct traverse_info *info)
427
427
return ret ;
428
428
}
429
429
430
- static int traverse_trees_recursive (int n , unsigned long dirmask , unsigned long df_conflicts , struct name_entry * names , struct traverse_info * info )
430
+ static int fast_forward_merge (int n , unsigned long dirmask ,
431
+ struct name_entry * names ,
432
+ struct traverse_info * info );
433
+
434
+ static int traverse_trees_recursive (int n , unsigned long dirmask ,
435
+ unsigned long df_conflicts ,
436
+ struct name_entry * names ,
437
+ struct traverse_info * info )
431
438
{
432
439
int i , ret , bottom ;
433
440
struct tree_desc t [MAX_UNPACK_TREES ];
434
441
void * buf [MAX_UNPACK_TREES ];
435
442
struct traverse_info newinfo ;
436
443
struct name_entry * p ;
437
444
445
+ if (!df_conflicts ) {
446
+ int status = fast_forward_merge (n , dirmask , names , info );
447
+ if (status )
448
+ return status ;
449
+ }
438
450
p = names ;
439
451
while (!p -> mode )
440
452
p ++ ;
@@ -682,6 +694,53 @@ static struct cache_entry *find_cache_entry(struct traverse_info *info,
682
694
return NULL ;
683
695
}
684
696
697
+ static int fast_forward_merge (int n , unsigned long dirmask ,
698
+ struct name_entry * names ,
699
+ struct traverse_info * info )
700
+ {
701
+ int i ;
702
+ struct cache_entry * src [MAX_UNPACK_TREES + 1 ] = { NULL , };
703
+ struct unpack_trees_options * o = info -> data ;
704
+
705
+ /* merging two or more trees with an identical subdirectory? */
706
+ if ((n < 2 ) || ((1UL << n ) - 1 ) != dirmask ||
707
+ !o -> merge || o -> reset || o -> initial_checkout )
708
+ return 0 ;
709
+ for (i = 1 ; i < n ; i ++ )
710
+ if (hashcmp (names [i - 1 ].sha1 , names [i ].sha1 ))
711
+ return 0 ;
712
+
713
+ /*
714
+ * Instead of descending into the directory, keep the contents
715
+ * of the current index.
716
+ */
717
+ while (1 ) {
718
+ struct cache_entry * ce ;
719
+ ce = next_cache_entry (o );
720
+ if (!ce )
721
+ break ;
722
+ /* Is the entry still in that directory? */
723
+ if (do_compare_entry (ce , info , names ))
724
+ break ;
725
+ /*
726
+ * Note: we do not just run unpack_index_entry() here,
727
+ * as the callback may want to compare what is in the
728
+ * index with what are from the HEAD and the other tree
729
+ * and reject the merge. We pretend that ancestors, the
730
+ * HEAD and the other tree all have the same contents as
731
+ * the current index, which is a lie, but it works.
732
+ */
733
+ for (i = 0 ; i < n + 1 ; i ++ )
734
+ src [i ] = ce ;
735
+ mark_ce_used (ce , o );
736
+ if (call_unpack_fn (src , o ) < 0 )
737
+ return unpack_failed (o , NULL );
738
+ if (ce_stage (ce ))
739
+ mark_ce_used_same_name (ce , o );
740
+ }
741
+ return dirmask ;
742
+ }
743
+
685
744
static void debug_path (struct traverse_info * info )
686
745
{
687
746
if (info -> prev ) {
@@ -1105,6 +1164,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1105
1164
1106
1165
}
1107
1166
if (o -> result .cache_nr && empty_worktree ) {
1167
+ /* dubious---why should this fail??? */
1108
1168
ret = unpack_failed (o , "Sparse checkout leaves no entry on working directory" );
1109
1169
goto done ;
1110
1170
}
0 commit comments