1360
return sparse_dir_matches_path(ce, info, name);
1361
}
1362
1363
+static int unpack_sparse_callback(int n, unsigned long mask, unsigned long dirmask, struct name_entry *names, struct traverse_info *info)
1364
+{
1365
+ struct cache_entry *src[MAX_UNPACK_TREES + 1] = { NULL, };
1366
+ struct unpack_trees_options *o = info->data;
1367
+ int ret;
1368
+
1369
+ assert(o->merge);
1370
+
1371
+ /*
1372
+ * Unlike in 'unpack_callback', where src[0] is derived from the index when
1373
+ * merging, src[0] is a transient cache entry derived from the first tree
1374
+ * provided. Create the temporary entry as if it came from a non-sparse index.
1375
+ */
1376
+ if (!is_null_oid(&names[0].oid)) {
1377
+ src[0] = create_ce_entry(info, &names[0], 0,
1378
+ &o->result, 1,
1379
+ dirmask & (1ul << 0));
1380
+ src[0]->ce_flags |= (CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE);
1381
+ }
1382
+
1383
+ /*
1384
+ * 'unpack_single_entry' assumes that src[0] is derived directly from
1385
+ * the index, rather than from an entry in 'names'. This is *not* true when
1386
+ * merging a sparse directory, in which case names[0] is the "index" source
1387
+ * entry. To match the expectations of 'unpack_single_entry', shift past the
1388
+ * "index" tree (i.e., names[0]) and adjust 'names', 'n', 'mask', and
1389
+ * 'dirmask' accordingly.
1390
+ */
1391
+ ret = unpack_single_entry(n - 1, mask >> 1, dirmask >> 1, src, names + 1, info);
1392
+
1393
+ if (src[0])
1394
+ discard_cache_entry(src[0]);
1395
+
1396
+ return ret >= 0 ? mask : -1;
1397
+}
1398
+
1399
/*
1400
* Note that traverse_by_cache_tree() duplicates some logic in this function
1401
* without actually calling it. If you change the logic here you may need to
2508
return 1;
2509
}
2510
2511
+static int merged_sparse_dir(const struct cache_entry * const *src, int n,
2512
+ struct unpack_trees_options *o)
2513
+{
2514
+ struct tree_desc t[MAX_UNPACK_TREES + 1];
2515
+ void * tree_bufs[MAX_UNPACK_TREES + 1];
2516
+ struct traverse_info info;
2517
+ int i, ret;
2518
+
2519
+ /*
2520
+ * Create the tree traversal information for traversing into *only* the
2521
+ * sparse directory.
2522
+ */
2523
+ setup_traverse_info(&info, src[0]->name);
2524
+ info.fn = unpack_sparse_callback;
2525
+ info.data = o;
2526
+ info.show_all_errors = o->show_all_errors;
2527
+ info.pathspec = o->pathspec;
2528
+
2529
+ /* Get the tree descriptors of the sparse directory in each of the merging trees */
2530
+ for (i = 0; i < n; i++)
2531
+ tree_bufs[i] = fill_tree_descriptor(o->src_index->repo, &t[i],
2532
+ src[i] && !is_null_oid(&src[i]->oid) ? &src[i]->oid : NULL);
2533
+
2534
+ ret = traverse_trees(o->src_index, n, t, &info);
2535
+
2536
+ for (i = 0; i < n; i++)
2537
+ free(tree_bufs[i]);
2538
+
2539
+ return ret;
2540
+}
2541
+
2542
static int deleted_entry(const struct cache_entry *ce,
2543
const struct cache_entry *old,
2544
struct unpack_trees_options *o)
2809
* reject the merge instead.
2810
*/
2811
return merged_entry(newtree, current, o);
2812
+ } else if (S_ISSPARSEDIR(current->ce_mode)) {
2813
+ /*
2814
+ * The sparse directories differ, but we don't know whether that's
2815
+ * because of two different files in the directory being modified
2816
+ * (can be trivially merged) or if there is a real file conflict.
2817
+ * Merge the sparse directory by OID to compare file-by-file.
2818
+ */
2819
+ return merged_sparse_dir(src, 3, o);
2820
} else
2821
return reject_merge(current, o);
2822
}