From: Junio C Hamano Date: Fri, 16 Dec 2016 23:27:48 +0000 (-0800) Subject: Merge branch 'nd/qsort-in-merge-recursive' X-Git-Tag: v2.12.0-rc0~154 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/7e73488b46b317eea289373eed15086feb0cd959?ds=inline;hp=-c Merge branch 'nd/qsort-in-merge-recursive' Code simplification. * nd/qsort-in-merge-recursive: merge-recursive.c: use string_list_sort instead of qsort --- 7e73488b46b317eea289373eed15086feb0cd959 diff --combined merge-recursive.c index e64b48b25d,6802d86c14..c07ba0df9d --- a/merge-recursive.c +++ b/merge-recursive.c @@@ -382,18 -382,16 +382,16 @@@ static struct string_list *get_unmerged } e = item->util; e->stages[ce_stage(ce)].mode = ce->ce_mode; - hashcpy(e->stages[ce_stage(ce)].oid.hash, ce->sha1); + oidcpy(&e->stages[ce_stage(ce)].oid, &ce->oid); } return unmerged; } - static int string_list_df_name_compare(const void *a, const void *b) + static int string_list_df_name_compare(const char *one, const char *two) { - const struct string_list_item *one = a; - const struct string_list_item *two = b; - int onelen = strlen(one->string); - int twolen = strlen(two->string); + int onelen = strlen(one); + int twolen = strlen(two); /* * Here we only care that entries for D/F conflicts are * adjacent, in particular with the file of the D/F conflict @@@ -406,8 -404,8 +404,8 @@@ * since in other cases any changes in their order due to * sorting cause no problems for us. */ - int cmp = df_name_compare(one->string, onelen, S_IFDIR, - two->string, twolen, S_IFDIR); + int cmp = df_name_compare(one, onelen, S_IFDIR, + two, twolen, S_IFDIR); /* * Now that 'foo' and 'foo/bar' compare equal, we have to make sure * that 'foo' comes before 'foo/bar'. @@@ -451,8 -449,8 +449,8 @@@ static void record_df_conflict_files(st string_list_append(&df_sorted_entries, next->string)->util = next->util; } - qsort(df_sorted_entries.items, entries->nr, sizeof(*entries->items), - string_list_df_name_compare); + df_sorted_entries.cmp = string_list_df_name_compare; + string_list_sort(&df_sorted_entries); string_list_clear(&o->df_conflict_file_set, 1); for (i = 0; i < df_sorted_entries.nr; i++) { @@@ -664,13 -662,7 +662,13 @@@ static char *unique_path(struct merge_o return strbuf_detach(&newpath, NULL); } -static int dir_in_way(const char *path, int check_working_copy) +/** + * Check whether a directory in the index is in the way of an incoming + * file. Return 1 if so. If check_working_copy is non-zero, also + * check the working directory. If empty_ok is non-zero, also return + * 0 in the case where the working-tree dir exists but is empty. + */ +static int dir_in_way(const char *path, int check_working_copy, int empty_ok) { int pos; struct strbuf dirpath = STRBUF_INIT; @@@ -690,8 -682,7 +688,8 @@@ } strbuf_release(&dirpath); - return check_working_copy && !lstat(path, &st) && S_ISDIR(st.st_mode); + return check_working_copy && !lstat(path, &st) && S_ISDIR(st.st_mode) && + !(empty_ok && is_empty_dir(path)); } static int was_tracked(const char *path) @@@ -917,9 -908,9 +915,9 @@@ static int merge_3way(struct merge_opti name2 = mkpathdup("%s", branch2); } - read_mmblob(&orig, one->oid.hash); - read_mmblob(&src1, a->oid.hash); - read_mmblob(&src2, b->oid.hash); + read_mmblob(&orig, &one->oid); + read_mmblob(&src1, &a->oid); + read_mmblob(&src2, &b->oid); merge_status = ll_merge(result_buf, a->path, &orig, base_name, &src1, name1, &src2, name2, &ll_opts); @@@ -1069,7 -1060,7 +1067,7 @@@ static int handle_change_delete(struct { char *renamed = NULL; int ret = 0; - if (dir_in_way(path, !o->call_depth)) { + if (dir_in_way(path, !o->call_depth, 0)) { renamed = unique_path(o, path, a_oid ? o->branch1 : o->branch2); } @@@ -1202,7 -1193,7 +1200,7 @@@ static int handle_file(struct merge_opt remove_file(o, 0, rename->path, 0); dst_name = unique_path(o, rename->path, cur_branch); } else { - if (dir_in_way(rename->path, !o->call_depth)) { + if (dir_in_way(rename->path, !o->call_depth, 0)) { dst_name = unique_path(o, rename->path, cur_branch); output(o, 1, _("%s is a directory in %s adding as %s instead"), rename->path, other_branch, dst_name); @@@ -1711,8 -1702,7 +1709,8 @@@ static int merge_content(struct merge_o o->branch2 == rename_conflict_info->branch1) ? pair1->two->path : pair1->one->path; - if (dir_in_way(path, !o->call_depth)) + if (dir_in_way(path, !o->call_depth, + S_ISGITLINK(pair1->two->mode))) df_conflict_remains = 1; } if (merge_file_special_markers(o, &one, &a, &b, @@@ -1870,8 -1860,7 +1868,8 @@@ static int process_entry(struct merge_o oid = b_oid; conf = _("directory/file"); } - if (dir_in_way(path, !o->call_depth)) { + if (dir_in_way(path, !o->call_depth, + S_ISGITLINK(a_mode))) { char *new_path = unique_path(o, path, add_branch); clean_merge = 0; output(o, 1, _("CONFLICT (%s): There is a directory with name %s in %s. "