Merge branch 'ps/receive-pack-shallow-optim'

The code to accept shallow "git push" has been optimized.

* ps/receive-pack-shallow-optim:
  commit: use commit graph in `lookup_commit_reference_gently()`
  commit: make `repo_parse_commit_no_graph()` more robust
  commit: avoid parsing non-commits in `lookup_commit_reference_gently()`
This commit is contained in:
Junio C Hamano
2026-03-02 17:06:53 -08:00
5 changed files with 63 additions and 13 deletions

View File

@@ -42,13 +42,35 @@ const char *commit_type = "commit";
struct commit *lookup_commit_reference_gently(struct repository *r,
const struct object_id *oid, int quiet)
{
struct object *obj = deref_tag(r,
parse_object(r, oid),
NULL, 0);
const struct object_id *maybe_peeled;
struct object_id peeled_oid;
struct commit *commit;
enum object_type type;
if (!obj)
switch (peel_object_ext(r, oid, &peeled_oid, 0, &type)) {
case PEEL_NON_TAG:
maybe_peeled = oid;
break;
case PEEL_PEELED:
maybe_peeled = &peeled_oid;
break;
default:
return NULL;
return object_as_type(obj, OBJ_COMMIT, quiet);
}
if (type != OBJ_COMMIT) {
if (!quiet)
error(_("object %s is a %s, not a %s"),
oid_to_hex(oid), type_name(type),
type_name(OBJ_COMMIT));
return NULL;
}
commit = lookup_commit(r, maybe_peeled);
if (!commit || repo_parse_commit_gently(r, commit, quiet) < 0)
return NULL;
return commit;
}
struct commit *lookup_commit_reference(struct repository *r, const struct object_id *oid)