[PATCH] git-apply: Remove directories that have become empty after deleting a file.

From: Alexandre Julliard <julliard@winehq.org>
Date: 2007-01-10 07:25:46
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
---
 builtin-apply.c |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/builtin-apply.c b/builtin-apply.c
index 1c35837..fac8349 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -2239,7 +2239,21 @@ static void remove_file(struct patch *patch)
 		cache_tree_invalidate_path(active_cache_tree, patch->old_name);
 	}
 	if (!cached)
-		unlink(patch->old_name);
+	{
+		if (!unlink(patch->old_name))
+		{
+			char *name = xstrdup(patch->old_name);
+			char *end = strrchr(name, '/');
+			while (end)
+			{
+				*end = 0;
+				if (rmdir(name))
+					break;
+				end = strrchr(name, '/');
+			}
+			free(name);
+		}
+	}
 }
 
 static void add_index_file(const char *path, unsigned mode, void *buf, unsigned long size)
-- 
1.4.4.4.g37ed

-- 
Alexandre Julliard
julliard@winehq.org
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Wed Jan 10 07:26:26 2007

This archive was generated by hypermail 2.1.8 : 2007-01-10 07:32:46 EST