merge-ort: add data structures for an alternate tree traversal
In order to determine whether directory rename detection is needed, we as a pre-requisite need a way to traverse through all the files in a given tree before visiting any directories within that tree. traverse_trees() only iterates through the entries in the order they appear, so add some data structures that will store all the entries as we iterate through them in traverse_trees(), which will allow us to re-traverse them in our desired order. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Mar 11, 2021 at 00:38 UTC
beb06145f83813505397d420bddef0231c127426
1 file changed
+26
merge-ort.c
+26
@@ -51,6 +51,12 @@ enum merge_side {
51
MERGE_SIDE2 = 2
52
};
53
54
+struct traversal_callback_data {
55
+ unsigned long mask;
56
+ unsigned long dirmask;
57
+ struct name_entry names[3];
58
+};
59
+
60
struct rename_info {
61
/*
62
* All variables that are arrays of size 3 correspond to data tracked
@@ -102,6 +108,22 @@ struct rename_info {
108
*/
109
struct strset relevant_sources[3];
110
111
+ /*
112
+ * callback_data_*: supporting data structures for alternate traversal
113
+ *
114
+ * We sometimes need to be able to traverse through all the files
115
+ * in a given tree before all immediate subdirectories within that
116
+ * tree. Since traverse_trees() doesn't do that naturally, we have
117
+ * a traverse_trees_wrapper() that stores any immediate
118
+ * subdirectories while traversing files, then traverses the
119
+ * immediate subdirectories later. These callback_data* variables
120
+ * store the information for the subdirectories so that we can do
121
+ * that traversal order.
122
+ */
123
+ struct traversal_callback_data *callback_data;
124
+ int callback_data_nr, callback_data_alloc;
125
+ char *callback_data_traverse_path;
126
+
127
/*
128
* needed_limit: value needed for inexact rename detection to run
129
*
@@ -396,6 +418,10 @@ static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
418
}
419
strmap_clear(&opti->output, 0);
420
}
421
+
422
+ /* Clean out callback_data as well. */
423
+ FREE_AND_NULL(renames->callback_data);
424
+ renames->callback_data_nr = renames->callback_data_alloc = 0;
425
}
426
427
static int err(struct merge_options *opt, const char *err, ...)