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

Re: [PATCH 3/3] Don't crash during repack of a reflog with pruned commits.

From
Junio C Hamano <junkio@cox.net>
Date
Dec 22, 2006, 08:16 UTC
Message-ID
<7vodpw5ors.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20061222005606.GA14773@spearce.org>
Shawn Pearce <spearce@spearce.org> writes:
> Just because the commit has not been pruned does not mean that a blob
> or tree referenced by that commit has not been pruned.
True.  How about this?
---
 builtin-reflog.c |   43 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/builtin-reflog.c b/builtin-reflog.c
index d4f7353..4097c32 100644
--- a/builtin-reflog.c
+++ b/builtin-reflog.c
@@ -3,7 +3,7 @@
 #include "commit.h"
 #include "refs.h"
 #include "dir.h"
-#include <time.h>
+#include "tree-walk.h"
 
 struct expire_reflog_cb {
 	FILE *newlog;
@@ -13,13 +13,50 @@ struct expire_reflog_cb {
 	unsigned long expire_unreachable;
 };
 
+static int tree_is_complete(const unsigned char *sha1)
+{
+	struct tree_desc desc;
+	void *buf;
+	char type[20];
+
+	buf = read_sha1_file(sha1, type, &desc.size);
+	if (!buf)
+		return 0;
+	desc.buf = buf;
+	while (desc.size) {
+		const unsigned char *elem;
+		const char *name;
+		unsigned mode;
+
+		elem = tree_entry_extract(&desc, &name, &mode);
+		if (!has_sha1_file(elem) ||
+		    (S_ISDIR(mode) && !tree_is_complete(elem))) {
+			free(buf);
+			return 0;
+		}
+		update_tree_entry(&desc);
+	}
+	free(buf);
+	return 1;
+}
+
 static int keep_entry(struct commit **it, unsigned char *sha1)
 {
+	struct commit *commit;
+
 	*it = NULL;
 	if (is_null_sha1(sha1))
 		return 1;
-	*it = lookup_commit_reference_gently(sha1, 1);
-	return (*it != NULL);
+	commit = lookup_commit_reference_gently(sha1, 1);
+	if (!commit)
+		return 0;
+
+	/* Make sure everything in this commit exists. */
+	parse_object(commit->object.sha1);
+	if (!tree_is_complete(commit->tree->object.sha1))
+		return 0;
+	*it = commit;
+	return 1;
 }
 
 static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
Previous: Shawn PearceNext: Shawn Pearce
Message 8 of 9 in “Introduce a global level warn() function.”
  1. 2/3 Introduce a global level warn() function.Shawn O. Pearce, Dec 22, 2006
  2. 3/3 Don't crash during repack of a reflog with pruned commits.Shawn O. Pearce, Dec 22, 2006
  3. Junio C HamanoDec 22, 2006
  4. Shawn PearceDec 22, 2006
  5. Jakub NarebskiDec 22, 2006
  6. Shawn PearceDec 22, 2006
  7. Shawn PearceDec 22, 2006
  8. Junio C HamanoDec 22, 2006
  9. Shawn PearceDec 22, 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.