From: Junio C Hamano <junkio@cox.net>
To: Shawn Pearce <spearce@spearce.org>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 3/3] Don't crash during repack of a reflog with pruned commits.
Date: Fri, 22 Dec 2006 00:16:23 -0800 [thread overview]
Message-ID: <7vodpw5ors.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <20061222005606.GA14773@spearce.org> (Shawn Pearce's message of "Thu, 21 Dec 2006 19:56:06 -0500")
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,
next prev parent reply other threads:[~2006-12-22 8:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <be6b1443171482e1930bd7744a0218db0c03d611.1166748450.git.spearce@spearce.org>
2006-12-22 0:48 ` [PATCH 2/3] Introduce a global level warn() function Shawn O. Pearce
2006-12-22 0:49 ` [PATCH 3/3] Don't crash during repack of a reflog with pruned commits Shawn O. Pearce
2006-12-22 0:52 ` Junio C Hamano
2006-12-22 1:00 ` Shawn Pearce
2006-12-22 1:18 ` Jakub Narebski
2006-12-22 1:23 ` Shawn Pearce
2006-12-22 0:56 ` Shawn Pearce
2006-12-22 8:16 ` Junio C Hamano [this message]
2006-12-22 8:22 ` Shawn Pearce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vodpw5ors.fsf@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).