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>
This commit is contained in:
parent
c28c571c14
commit
eed46644ca
@ -2059,13 +2059,16 @@ static void create_file(struct patch *patch)
|
|||||||
cache_tree_invalidate_path(active_cache_tree, path);
|
cache_tree_invalidate_path(active_cache_tree, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_out_one_result(struct patch *patch)
|
/* phase zero is to remove, phase one is to create */
|
||||||
|
static void write_out_one_result(struct patch *patch, int phase)
|
||||||
{
|
{
|
||||||
if (patch->is_delete > 0) {
|
if (patch->is_delete > 0) {
|
||||||
|
if (phase == 0)
|
||||||
remove_file(patch);
|
remove_file(patch);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (patch->is_new > 0 || patch->is_copy) {
|
if (patch->is_new > 0 || patch->is_copy) {
|
||||||
|
if (phase == 1)
|
||||||
create_file(patch);
|
create_file(patch);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2073,18 +2076,25 @@ static void write_out_one_result(struct patch *patch)
|
|||||||
* Rename or modification boils down to the same
|
* Rename or modification boils down to the same
|
||||||
* thing: remove the old, write the new
|
* thing: remove the old, write the new
|
||||||
*/
|
*/
|
||||||
|
if (phase == 0)
|
||||||
remove_file(patch);
|
remove_file(patch);
|
||||||
|
if (phase == 1)
|
||||||
create_file(patch);
|
create_file(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_out_results(struct patch *list, int skipped_patch)
|
static void write_out_results(struct patch *list, int skipped_patch)
|
||||||
{
|
{
|
||||||
|
int phase;
|
||||||
|
|
||||||
if (!list && !skipped_patch)
|
if (!list && !skipped_patch)
|
||||||
die("No changes");
|
die("No changes");
|
||||||
|
|
||||||
while (list) {
|
for (phase = 0; phase < 2; phase++) {
|
||||||
write_out_one_result(list);
|
struct patch *l = list;
|
||||||
list = list->next;
|
while (l) {
|
||||||
|
write_out_one_result(l, phase);
|
||||||
|
l = l->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user