grep: read submodule entry with explicit repo

Replace an existing parse_object_or_die() call (which implicitly works on the_repository) with a function call that allows a repository to be passed in. There is no such direct equivalent to parse_object_or_die(), but we only need the type of the object, so replace with oid_object_info(). Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Reviewed-by: Emily Shaffer <emilyshaffer@google.com> Reviewed-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Aug 16, 2021 at 14:09 UTC 78ca584f1c4a720988f6066693b4d2ccde920813
1 file changed +5 -5
builtin/grep.c
+5 -5
@@ -457,27 +457,27 @@ static int grep_submodule(struct grep_opt *opt,
457 subopt.repo = &subrepo;
458
459 if (oid) {
460 - struct object *object;
460 + enum object_type object_type;
461 struct tree_desc tree;
462 void *data;
463 unsigned long size;
464 struct strbuf base = STRBUF_INIT;
465
466 obj_read_lock();
467 - object = parse_object_or_die(oid, NULL);
467 + object_type = oid_object_info(&subrepo, oid, NULL);
468 obj_read_unlock();
469 data = read_object_with_reference(&subrepo,
470 - &object->oid, tree_type,
470 + oid, tree_type,
471 &size, NULL);
472 if (!data)
473 - die(_("unable to read tree (%s)"), oid_to_hex(&object->oid));
473 + die(_("unable to read tree (%s)"), oid_to_hex(oid));
474
475 strbuf_addstr(&base, filename);
476 strbuf_addch(&base, '/');
477
478 init_tree_desc(&tree, data, size);
479 hit = grep_tree(&subopt, pathspec, &tree, &base, base.len,
480 - object->type == OBJ_COMMIT);
480 + object_type == OBJ_COMMIT);
481 strbuf_release(&base);
482 free(data);
483 } else {