apply: split out removal and creation into different phases.
This reworks write_out_result() loop so we first remove the paths that are to go away and then create them after finishing all the removal. This is necessary when a patch creates a file "foo" and removes a file "foo/bar". Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jul 16, 2006 at 23:52 UTC
eed46644ca48ad08e1fd71e14afbe801399e8a67
1 file changed
+17
-7
builtin-apply.c
+17
-7
@@ -2059,32 +2059,42 @@ static void create_file(struct patch *patch)
2059
cache_tree_invalidate_path(active_cache_tree, path);
2060
}
2061
2062
-static void write_out_one_result(struct patch *patch)
2062
+/* phase zero is to remove, phase one is to create */
2063
+static void write_out_one_result(struct patch *patch, int phase)
2064
{
2065
if (patch->is_delete > 0) {
2065
- remove_file(patch);
2066
+ if (phase == 0)
2067
+ remove_file(patch);
2068
return;
2069
}
2070
if (patch->is_new > 0 || patch->is_copy) {
2069
- create_file(patch);
2071
+ if (phase == 1)
2072
+ create_file(patch);
2073
return;
2074
}
2075
/*
2076
* Rename or modification boils down to the same
2077
* thing: remove the old, write the new
2078
*/
2076
- remove_file(patch);
2079
+ if (phase == 0)
2080
+ remove_file(patch);
2081
+ if (phase == 1)
2082
create_file(patch);
2083
}
2084
2085
static void write_out_results(struct patch *list, int skipped_patch)
2086
{
2087
+ int phase;
2088
+
2089
if (!list && !skipped_patch)
2090
die("No changes");
2091
2085
- while (list) {
2086
- write_out_one_result(list);
2087
- list = list->next;
2092
+ for (phase = 0; phase < 2; phase++) {
2093
+ struct patch *l = list;
2094
+ while (l) {
2095
+ write_out_one_result(l, phase);
2096
+ l = l->next;
2097
+ }
2098
}
2099
}
2100