aboutsummaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-03-02 17:06:53 -0800
committerJunio C Hamano <gitster@pobox.com>2026-03-02 17:06:53 -0800
commit13763ecf7d92be72beff75c59163c5448d9e085e (patch)
tree936c5d97e77cefb1f0da9b2aae1054b1433bc690 /commit.c
parent34113149cfde760b6b791939c6d8d87d27ca2767 (diff)
parentbb5da75d6116c35924a04a418ef4c3182663d0a2 (diff)
downloadgit-13763ecf7d92be72beff75c59163c5448d9e085e.tar.xz
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()`
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/commit.c b/commit.c
index d16ae73345..0ffdd6679e 100644
--- a/commit.c
+++ b/commit.c
@@ -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)