merge-recursive: split out code for determining diff_filepairs

Create a new function, get_diffpairs() to compute the diff_filepairs
between two trees.  While these are currently only used in
get_renames(), I want them to be available to some new functions.  No
actual logic changes yet.

Reviewed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Elijah Newren 2018-02-14 10:51:53 -08:00 коммит произвёл Junio C Hamano
Родитель e7f04a3aaf
Коммит 3f646871a3
1 изменённых файлов: 62 добавлений и 22 удалений

Просмотреть файл

@ -1312,24 +1312,15 @@ static int conflict_rename_rename_2to1(struct merge_options *o,
} }
/* /*
* Get information of all renames which occurred between 'o_tree' and * Get the diff_filepairs changed between o_tree and tree.
* 'tree'. We need the three trees in the merge ('o_tree', 'a_tree' and
* 'b_tree') to be able to associate the correct cache entries with
* the rename information. 'tree' is always equal to either a_tree or b_tree.
*/ */
static struct string_list *get_renames(struct merge_options *o, static struct diff_queue_struct *get_diffpairs(struct merge_options *o,
struct tree *tree, struct tree *o_tree,
struct tree *o_tree, struct tree *tree)
struct tree *a_tree,
struct tree *b_tree,
struct string_list *entries)
{ {
int i; struct diff_queue_struct *ret;
struct string_list *renames;
struct diff_options opts; struct diff_options opts;
renames = xcalloc(1, sizeof(struct string_list));
diff_setup(&opts); diff_setup(&opts);
opts.flags.recursive = 1; opts.flags.recursive = 1;
opts.flags.rename_empty = 0; opts.flags.rename_empty = 0;
@ -1345,10 +1336,41 @@ static struct string_list *get_renames(struct merge_options *o,
diffcore_std(&opts); diffcore_std(&opts);
if (opts.needed_rename_limit > o->needed_rename_limit) if (opts.needed_rename_limit > o->needed_rename_limit)
o->needed_rename_limit = opts.needed_rename_limit; o->needed_rename_limit = opts.needed_rename_limit;
for (i = 0; i < diff_queued_diff.nr; ++i) {
ret = xmalloc(sizeof(*ret));
*ret = diff_queued_diff;
opts.output_format = DIFF_FORMAT_NO_OUTPUT;
diff_queued_diff.nr = 0;
diff_queued_diff.queue = NULL;
diff_flush(&opts);
return ret;
}
/*
* Get information of all renames which occurred in 'pairs', making use of
* any implicit directory renames inferred from the other side of history.
* We need the three trees in the merge ('o_tree', 'a_tree' and 'b_tree')
* to be able to associate the correct cache entries with the rename
* information; tree is always equal to either a_tree or b_tree.
*/
static struct string_list *get_renames(struct merge_options *o,
struct diff_queue_struct *pairs,
struct tree *tree,
struct tree *o_tree,
struct tree *a_tree,
struct tree *b_tree,
struct string_list *entries)
{
int i;
struct string_list *renames;
renames = xcalloc(1, sizeof(struct string_list));
for (i = 0; i < pairs->nr; ++i) {
struct string_list_item *item; struct string_list_item *item;
struct rename *re; struct rename *re;
struct diff_filepair *pair = diff_queued_diff.queue[i]; struct diff_filepair *pair = pairs->queue[i];
if (pair->status != 'R') { if (pair->status != 'R') {
diff_free_filepair(pair); diff_free_filepair(pair);
@ -1373,9 +1395,6 @@ static struct string_list *get_renames(struct merge_options *o,
item = string_list_insert(renames, pair->one->path); item = string_list_insert(renames, pair->one->path);
item->util = re; item->util = re;
} }
opts.output_format = DIFF_FORMAT_NO_OUTPUT;
diff_queued_diff.nr = 0;
diff_flush(&opts);
return renames; return renames;
} }
@ -1646,15 +1665,36 @@ static int handle_renames(struct merge_options *o,
struct string_list *entries, struct string_list *entries,
struct rename_info *ri) struct rename_info *ri)
{ {
struct diff_queue_struct *head_pairs, *merge_pairs;
int clean;
ri->head_renames = NULL; ri->head_renames = NULL;
ri->merge_renames = NULL; ri->merge_renames = NULL;
if (!o->detect_rename) if (!o->detect_rename)
return 1; return 1;
ri->head_renames = get_renames(o, head, common, head, merge, entries); head_pairs = get_diffpairs(o, common, head);
ri->merge_renames = get_renames(o, merge, common, head, merge, entries); merge_pairs = get_diffpairs(o, common, merge);
return process_renames(o, ri->head_renames, ri->merge_renames);
ri->head_renames = get_renames(o, head_pairs, head,
common, head, merge, entries);
ri->merge_renames = get_renames(o, merge_pairs, merge,
common, head, merge, entries);
clean = process_renames(o, ri->head_renames, ri->merge_renames);
/*
* Some cleanup is deferred until cleanup_renames() because the
* data structures are still needed and referenced in
* process_entry(). But there are a few things we can free now.
*/
free(head_pairs->queue);
free(head_pairs);
free(merge_pairs->queue);
free(merge_pairs);
return clean;
} }
static void cleanup_rename(struct string_list *rename) static void cleanup_rename(struct string_list *rename)