fast-export: do not parse non-commit objects while reading marks file

We read from the marks file and keep only marked commits, but in order to find the type of object, we are parsing the whole thing, which is slow, specially in big repositories with lots of big files. There's no need for that, we can query the object information with sha1_object_info(). Before this, loading the objects of a fresh emacs import, with 260598 blobs took 14 minutes, after this patch, it takes 3 seconds. This is the way fast-import does it. Also die if the object is not found (like fast-import). Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed May 5, 2013 at 17:38 UTC e6812cfa9aba69a8c9d83b0710291b27bff0f7a3
1 file changed +9 -6
builtin/fast-export.c
+9 -6
@@ -613,6 +613,7 @@ static void import_marks(char *input_file)
613 char *line_end, *mark_end;
614 unsigned char sha1[20];
615 struct object *object;
616 + enum object_type type;
617
618 line_end = strchr(line, '\n');
619 if (line[0] != ':' || !line_end)
@@ -627,17 +628,19 @@ static void import_marks(char *input_file)
628 if (last_idnum < mark)
629 last_idnum = mark;
630
630 - object = parse_object(sha1);
631 - if (!object)
631 + type = sha1_object_info(sha1, NULL);
632 + if (type < 0)
633 + die("object not found: %s", sha1_to_hex(sha1));
634 +
635 + if (type != OBJ_COMMIT)
636 + /* only commits */
637 continue;
638
639 + object = parse_object(sha1);
640 +
641 if (object->flags & SHOWN)
642 error("Object %s already has a mark", sha1_to_hex(sha1));
643
637 - if (object->type != OBJ_COMMIT)
638 - /* only commits */
639 - continue;
640 -
644 mark_object(object, mark);
645
646 object->flags |= SHOWN;