]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit: add gentle reference lookup method
authorDerrick Stolee <derrickstolee@github.com>
Wed, 14 Aug 2024 10:31:28 +0000 (10:31 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Aug 2024 17:10:05 +0000 (10:10 -0700)
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>
commit.c
commit.h

index 087cb19f4f84f353db26289f97d72f91578fd8c3..e0691c9e52cb658776e0cd83c8bff6d79f89f2f3 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -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)
+{
+       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;
index d62b1d93f9566250fa9b8cabe36a050bf3cc7b78..0e5fce543c2897d710176e074d58cda0bf6fc4ff 100644 (file)
--- 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,