Git development
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Nicolas Pitre <nico@cam.org>
Cc: "R. Tyler Ballance" <tyler@slide.com>,
	Johannes Sixt <j.sixt@viscovery.net>,
	Junio C Hamano <gitster@pobox.com>,
	Git Mailing List <git@vger.kernel.org>
Subject: Re: epic fsck SIGSEGV! (was Recovering from epic fail (deleted .git/objects/pack))
Date: Wed, 10 Dec 2008 19:44:37 -0800 (PST)	[thread overview]
Message-ID: <alpine.LFD.2.00.0812101930590.3340@localhost.localdomain> (raw)
In-Reply-To: <alpine.LFD.2.00.0812101854230.3340@localhost.localdomain>



On Wed, 10 Dec 2008, Linus Torvalds wrote:
> 
> On Wed, 10 Dec 2008, Nicolas Pitre wrote:
> 
> > On Wed, 10 Dec 2008, Linus Torvalds wrote:
> > 
> > > But we should definitely fix this braindamage in fsck. Rather than 
> > > recursively walk the commits, we should add them to a commit list and just 
> > > walk the list iteratively.
> > 
> > What about:
> > 
> > 	http://marc.info/?l=git&m=122889563424786&w=2
> 
> Not very pretty. The basic notion is ok, but wouldn't it be nicer to at 
> least use a "struct object_array" instead?
> 
> Let me try to cook something up.

I dunno. I like this patch better. It's a bit larger. I think it's a bit 
more clearly separated (ie a "mark_object_reachable()" _literally_ just 
puts the object on a list, and the whole traversal is a whole separate 
phase), but I guess it's a matter of taste.

It has gotten no real testing. Caveat emptor. And I didn't even bother to 
check that it can run with less stack or that it makes any other 
difference.

			Linus

---
 builtin-fsck.c |   38 +++++++++++++++++++++++++++++++-------
 1 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/builtin-fsck.c b/builtin-fsck.c
index afded5e..297b2c4 100644
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
@@ -64,11 +64,11 @@ static int fsck_error_func(struct object *obj, int type, const char *err, ...)
 	return (type == FSCK_WARN) ? 0 : 1;
 }
 
+static struct object_array pending;
+
 static int mark_object(struct object *obj, int type, void *data)
 {
-	struct tree *tree = NULL;
 	struct object *parent = data;
-	int result;
 
 	if (!obj) {
 		printf("broken link from %7s %s\n",
@@ -96,6 +96,20 @@ static int mark_object(struct object *obj, int type, void *data)
 		return 1;
 	}
 
+	add_object_array(obj, (void *) parent, &pending);
+	return 0;
+}
+
+static void mark_object_reachable(struct object *obj)
+{
+	mark_object(obj, OBJ_ANY, 0);
+}
+
+static int traverse_one_object(struct object *obj, struct object *parent)
+{
+	int result;
+	struct tree *tree = NULL;
+
 	if (obj->type == OBJ_TREE) {
 		obj->parsed = 0;
 		tree = (struct tree *)obj;
@@ -107,15 +121,22 @@ static int mark_object(struct object *obj, int type, void *data)
 		free(tree->buffer);
 		tree->buffer = NULL;
 	}
-	if (result < 0)
-		result = 1;
-
 	return result;
 }
 
-static void mark_object_reachable(struct object *obj)
+static int traverse_reachable(void)
 {
-	mark_object(obj, OBJ_ANY, 0);
+	int result = 0;
+	while (pending.nr) {
+		struct object_array_entry *entry;
+		struct object *obj, *parent;
+
+		entry = pending.objects + --pending.nr;
+		obj = entry->item;
+		parent = (struct object *) entry->name;
+		result |= traverse_one_object(obj, parent);
+	}
+	return !!result;
 }
 
 static int mark_used(struct object *obj, int type, void *data)
@@ -237,6 +258,9 @@ static void check_connectivity(void)
 {
 	int i, max;
 
+	/* Traverse the pending reachable objects */
+	traverse_reachable();
+
 	/* Look up all the requirements, warn about missing objects.. */
 	max = get_max_object_index();
 	if (verbose)

  reply	other threads:[~2008-12-11  3:46 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-10  0:11 Recovering from epic fail (deleted .git/objects/pack) R. Tyler Ballance
2008-12-10  0:19 ` Junio C Hamano
2008-12-10 10:06   ` R. Tyler Ballance
2008-12-10 11:39     ` Johannes Sixt
2008-12-10 22:52       ` epic fsck SIGSEGV! (was Recovering from epic fail (deleted .git/objects/pack)) R. Tyler Ballance
2008-12-10 23:40         ` Linus Torvalds
2008-12-11  0:24           ` R. Tyler Ballance
2008-12-11  0:45             ` Linus Torvalds
2008-12-11  1:21               ` R. Tyler Ballance
2008-12-11  0:51           ` epic fsck SIGSEGV! Junio C Hamano
2008-12-11  1:03           ` epic fsck SIGSEGV! (was Recovering from epic fail (deleted .git/objects/pack)) Boyd Stephen Smith Jr.
2008-12-11  1:16             ` Shawn O. Pearce
2008-12-11  1:33           ` Nicolas Pitre
2008-12-11  1:52             ` epic fsck SIGSEGV! Junio C Hamano
2008-12-11  2:16               ` Nicolas Pitre
2008-12-11  3:28             ` epic fsck SIGSEGV! (was Recovering from epic fail (deleted .git/objects/pack)) Linus Torvalds
2008-12-11  3:44               ` Linus Torvalds [this message]
2008-12-11  7:33                 ` epic fsck SIGSEGV! Junio C Hamano
2008-12-11 17:33                   ` Linus Torvalds
2008-12-11 20:18                     ` Linus Torvalds
2008-12-11  7:53                 ` Junio C Hamano
2008-12-11  4:00               ` epic fsck SIGSEGV! (was Recovering from epic fail (deleted .git/objects/pack)) Boyd Stephen Smith Jr.

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.2.00.0812101930590.3340@localhost.localdomain \
    --to=torvalds@linux-foundation.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    --cc=nico@cam.org \
    --cc=tyler@slide.com \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox