Merge branch 'nd/qsort-in-merge-recursive' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 17 Jan 2017 23:19:03 +0000 (15:19 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Jan 2017 23:19:03 +0000 (15:19 -0800)
Code simplification.

* nd/qsort-in-merge-recursive:
merge-recursive.c: use string_list_sort instead of qsort

1  2 
merge-recursive.c
diff --combined merge-recursive.c
index 214f5a693bbbfdc5a6da5727dbad7830f83748dd,6802d86c14730f03f7a220eb21ed969a7ea87fbf..23d6992f4037b37a9c3e133001af16595e8da394
@@@ -235,8 -235,6 +235,8 @@@ static int add_cacheinfo(struct merge_o
                struct cache_entry *nce;
  
                nce = refresh_cache_entry(ce, CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING);
 +              if (!nce)
 +                      return err(o, _("addinfo_cache failed for path '%s'"), path);
                if (nce != ce)
                        ret = add_cache_entry(nce, options);
        }
@@@ -384,18 -382,16 +384,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
         * 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'.
@@@ -453,8 -449,8 +451,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++) {
@@@ -666,13 -662,7 +664,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;
        }
  
        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)
@@@ -919,9 -908,9 +917,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);
@@@ -1071,7 -1060,7 +1069,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);
        }
  
@@@ -1204,7 -1193,7 +1202,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);
@@@ -1713,8 -1702,7 +1711,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,
@@@ -1872,8 -1860,7 +1870,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. "