| 4486 | } |
| 4487 | |
| 4488 | static int process_entries(struct merge_options *opt, |
| 4489 | struct object_id *result_oid) |
| 4490 | { |
| 4491 | struct hashmap_iter iter; |
| 4492 | struct strmap_entry *e; |
| 4493 | struct string_list plist = STRING_LIST_INIT_NODUP; |
| 4494 | struct string_list_item *entry; |
| 4495 | struct directory_versions dir_metadata = { STRING_LIST_INIT_NODUP, |
| 4496 | STRING_LIST_INIT_NODUP, |
| 4497 | NULL, 0 }; |
| 4498 | int ret = 0; |
| 4499 | const int record_tree = (!opt->mergeability_only || |
| 4500 | opt->priv->call_depth); |
| 4501 | |
| 4502 | trace2_region_enter("merge", "process_entries setup", opt->repo); |
| 4503 | if (strmap_empty(&opt->priv->paths)) { |
| 4504 | oidcpy(result_oid, opt->repo->hash_algo->empty_tree); |
| 4505 | return 0; |
| 4506 | } |
| 4507 | |
| 4508 | /* Hack to pre-allocate plist to the desired size */ |
| 4509 | trace2_region_enter("merge", "plist grow", opt->repo); |
| 4510 | ALLOC_GROW(plist.items, strmap_get_size(&opt->priv->paths), plist.alloc); |
| 4511 | trace2_region_leave("merge", "plist grow", opt->repo); |
| 4512 | |
| 4513 | /* Put every entry from paths into plist, then sort */ |
| 4514 | trace2_region_enter("merge", "plist copy", opt->repo); |
| 4515 | strmap_for_each_entry(&opt->priv->paths, &iter, e) { |
| 4516 | string_list_append(&plist, e->key)->util = e->value; |
| 4517 | } |
| 4518 | trace2_region_leave("merge", "plist copy", opt->repo); |
| 4519 | |
| 4520 | trace2_region_enter("merge", "plist special sort", opt->repo); |
| 4521 | plist.cmp = sort_dirs_next_to_their_children; |
| 4522 | string_list_sort(&plist); |
| 4523 | trace2_region_leave("merge", "plist special sort", opt->repo); |
| 4524 | |
| 4525 | trace2_region_leave("merge", "process_entries setup", opt->repo); |
| 4526 | |
| 4527 | /* |
| 4528 | * Iterate over the items in reverse order, so we can handle paths |
| 4529 | * below a directory before needing to handle the directory itself. |
| 4530 | * |
| 4531 | * This allows us to write subtrees before we need to write trees, |
| 4532 | * and it also enables sane handling of directory/file conflicts |
| 4533 | * (because it allows us to know whether the directory is still in |
| 4534 | * the way when it is time to process the file at the same path). |
| 4535 | */ |
| 4536 | trace2_region_enter("merge", "processing", opt->repo); |
| 4537 | prefetch_for_content_merges(opt, &plist); |
| 4538 | for (entry = &plist.items[plist.nr-1]; entry >= plist.items; --entry) { |
| 4539 | char *path = entry->string; |
| 4540 | /* |
| 4541 | * NOTE: mi may actually be a pointer to a conflict_info, but |
| 4542 | * we have to check mi->clean first to see if it's safe to |
| 4543 | * reassign to such a pointer type. |
| 4544 | */ |
| 4545 | struct merged_info *mi = entry->util; |
no test coverage detected