commit 2aa0475caa333b7d3f25991b11b09ab048e8e6de from: Stefan Sperling date: Sun Feb 03 16:00:40 2019 UTC add got_error_not_ref() commit - e34f9ed6ad6d7e550cdfa067e0e45300e232bfb7 commit + 2aa0475caa333b7d3f25991b11b09ab048e8e6de blob - ebbdea23c0612b374f10b8fd8811bf08d2c70011 blob + ba1061d2d3ac93f19f71d48ea83f35e9524c3976 --- include/got_error.h +++ include/got_error.h @@ -174,3 +174,11 @@ const struct got_error *got_ferror(FILE *, int); */ struct got_object_id; /* forward declaration */ const struct got_error *got_error_no_obj(struct got_object_id *); + +/* + * Obtain an error with code GOT_ERR_NOT_REF and an error message which + * contains the specified reference name. The message buffer is statically + * allocated; future invocations of this function will overwrite the + * message set during earlier invocations. + */ +const struct got_error *got_error_not_ref(const char *); blob - 1df8f21c31406cf60b15c413d2e14e77d0005d0d blob + 72cf6ae7f1505bf4f6059b6384a1f700ea922bbd --- lib/error.c +++ lib/error.c @@ -107,3 +107,16 @@ got_error_no_obj(struct got_object_id *id) return got_error_msg(GOT_ERR_NO_OBJ, msg); } + +const struct got_error * +got_error_not_ref(const char *refname) +{ + static char msg[sizeof("reference not found") + 1004]; + int ret; + + ret = snprintf(msg, sizeof(msg), "reference %s not found", refname); + if (ret == -1 || ret >= sizeof(msg)) + return got_error(GOT_ERR_NOT_REF); + + return got_error_msg(GOT_ERR_NOT_REF, msg); +}