git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
AJAlexandre Julliard <julliard@winehq.org>
Date
Jan 9, 2007, 20:25 UTC
Message-ID
<87fyak0wxh.fsf@wine.dyndns.org>
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
Message 1 of 1 in “git-apply: Remove directories that have become empty after deleting a file.”
  1. git-apply: Remove directories that have become empty after deleting a file.Alexandre Julliard, Jan 9, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.