commit: add gentle reference lookup method

The lookup_commit_reference_by_name() method uses lookup_commit_reference()
without an option to use lookup_commit_reference_gently(). Create a gentle
version of the method so it can be used in locations where non-commits may
be found but error messages should be silenced.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Derrick Stolee
2024-08-14 10:31:28 +00:00
committed by Junio C Hamano
parent e32eaf73b0
commit 69020d034b
2 changed files with 9 additions and 1 deletions

View File

@ -84,13 +84,19 @@ struct commit *lookup_commit(struct repository *r, const struct object_id *oid)
} }
struct commit *lookup_commit_reference_by_name(const char *name) struct commit *lookup_commit_reference_by_name(const char *name)
{
return lookup_commit_reference_by_name_gently(name, 0);
}
struct commit *lookup_commit_reference_by_name_gently(const char *name,
int quiet)
{ {
struct object_id oid; struct object_id oid;
struct commit *commit; struct commit *commit;
if (repo_get_oid_committish(the_repository, name, &oid)) if (repo_get_oid_committish(the_repository, name, &oid))
return NULL; return NULL;
commit = lookup_commit_reference(the_repository, &oid); commit = lookup_commit_reference_gently(the_repository, &oid, quiet);
if (repo_parse_commit(the_repository, commit)) if (repo_parse_commit(the_repository, commit))
return NULL; return NULL;
return commit; return commit;

View File

@ -81,6 +81,8 @@ struct commit *lookup_commit_reference_gently(struct repository *r,
const struct object_id *oid, const struct object_id *oid,
int quiet); int quiet);
struct commit *lookup_commit_reference_by_name(const char *name); struct commit *lookup_commit_reference_by_name(const char *name);
struct commit *lookup_commit_reference_by_name_gently(const char *name,
int quiet);
/* /*
* Look up object named by "oid", dereference tag as necessary, * Look up object named by "oid", dereference tag as necessary,