From: Derrick Stolee via GitGitGadget Date: Wed, 14 Aug 2024 10:31:28 GMT Subject: [PATCH v3 2/4] commit: add gentle reference lookup method Message-ID: <5240c2a7b328e3d356574a1ab00e2faa8a71d92a.1723631490.git.gitgitgadget@gmail.com> In-Reply-To: From: Derrick Stolee 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 --- commit.c | 8 +++++++- commit.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/commit.c b/commit.c index 1a479a997c4..ed49be8dce5 100644 --- a/commit.c +++ b/commit.c @@ -82,13 +82,19 @@ struct commit *lookup_commit(struct repository *r, const struct object_id *oid) } 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 commit *commit; if (repo_get_oid_committish(the_repository, name, &oid)) 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)) return NULL; return commit; diff --git a/commit.h b/commit.h index 62fe0d77a70..ef17668cc69 100644 --- a/commit.h +++ b/commit.h @@ -81,6 +81,8 @@ struct commit *lookup_commit_reference_gently(struct repository *r, const struct object_id *oid, int quiet); 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, -- gitgitgadget