summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 700ea47)
raw | patch | inline | side by side (parent: 700ea47)
author | Junio C Hamano <junkio@cox.net> | |
Tue, 20 Feb 2007 01:58:58 +0000 (17:58 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 20 Feb 2007 02:44:21 +0000 (18:44 -0800) |
When a patch modifies (not deletes) the last file in a
directory, because we treat a modification just as deletion
followed by creation, and deleting the last file in a directory
automatically rmdir(2)'s that directory, we ended up removing
the directory, which can potentially be the cwd, and then
recreating the same directory to create the patch result.
Avoid the rmdir step when remove_file() is called only because
we are replacing it with the result by later calling
create_file().
Signed-off-by: Junio C Hamano <junkio@cox.net>
directory, because we treat a modification just as deletion
followed by creation, and deleting the last file in a directory
automatically rmdir(2)'s that directory, we ended up removing
the directory, which can potentially be the cwd, and then
recreating the same directory to create the patch result.
Avoid the rmdir step when remove_file() is called only because
we are replacing it with the result by later calling
create_file().
Signed-off-by: Junio C Hamano <junkio@cox.net>
builtin-apply.c | patch | blob | history |
diff --git a/builtin-apply.c b/builtin-apply.c
index 2784db2efb5030c819f41b6c880f53e8876ec023..3f829fb661d28778a3527b01ada4334ea53093db 100644 (file)
--- a/builtin-apply.c
+++ b/builtin-apply.c
}
}
-static void remove_file(struct patch *patch)
+static void remove_file(struct patch *patch, int rmdir_empty)
{
if (write_index) {
if (remove_file_from_cache(patch->old_name) < 0)
cache_tree_invalidate_path(active_cache_tree, patch->old_name);
}
if (!cached) {
- if (!unlink(patch->old_name)) {
+ if (!unlink(patch->old_name) && rmdir_empty) {
char *name = xstrdup(patch->old_name);
char *end = strrchr(name, '/');
while (end) {
{
if (patch->is_delete > 0) {
if (phase == 0)
- remove_file(patch);
+ remove_file(patch, 1);
return;
}
if (patch->is_new > 0 || patch->is_copy) {
* thing: remove the old, write the new
*/
if (phase == 0)
- remove_file(patch);
+ remove_file(patch, 0);
if (phase == 1)
create_file(patch);
}