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

[PATCH 2/2] When packing and pruning refs, remove "deleted-refs".

From
Christian Couder <chriscool@tuxfamily.org>
Date
Oct 14, 2006, 13:41 UTC
Message-ID
<20061014154109.9a093319.chriscool@tuxfamily.org>

When running "git pack-refs --prune" we have to also prune deleted ref files. To do this, remove recusively everything under "$GIT_DIR/deleted-refs".

The new "remove_all_recursive" function has been copied from "remove_empty_dir_recursive" in "refs.c".

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin-pack-refs.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/builtin-pack-refs.c b/builtin-pack-refs.c
index 1087657..84ca170 100644
--- a/builtin-pack-refs.c
+++ b/builtin-pack-refs.c
@@ -54,12 +54,54 @@ static void prune_ref(struct ref_to_prun
 	}
 }
 
+static int remove_all_recursive(char *path)
+{
+	DIR *dir = opendir(path);
+	struct dirent *e;
+	int ret = 0;
+	int len = strlen(path);
+
+	if (!dir)
+		return unlink(path);
+	if (path[len-1] != '/')
+		path[len++] = '/';
+	while ((e = readdir(dir)) != NULL) {
+		struct stat st;
+		int namlen;
+		if ((e->d_name[0] == '.') &&
+		    ((e->d_name[1] == 0) ||
+		     ((e->d_name[1] == '.') && e->d_name[2] == 0)))
+			continue; /* "." and ".." */
+
+		namlen = strlen(e->d_name);
+		if ((len + namlen < PATH_MAX) &&
+		    strcpy(path + len, e->d_name) &&
+		    !lstat(path, &st) &&
+		    (S_ISDIR(st.st_mode) ?
+		     !remove_all_recursive(path) :
+		     !unlink(path)))
+			continue; /* happy */
+
+		/* path too long, stat, rmdir or unlink fails */
+		ret = -1;
+		break;
+	}
+	closedir(dir);
+	if (!ret) {
+		path[len] = 0;
+		ret = rmdir(path);
+	}
+	return ret;
+}
+
 static void prune_refs(struct ref_to_prune *r)
 {
 	while (r) {
 		prune_ref(r);
 		r = r->next;
 	}
+
+	remove_all_recursive(git_path("deleted-refs"));
 }
 
 static struct lock_file packed;
-- 
1.4.3.rc2.gbcf275-dirty
Message 1 of 1 in “When packing and pruning refs, remove "deleted-refs".”
  1. 2/2 When packing and pruning refs, remove "deleted-refs".Christian Couder, Oct 14, 2006

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.