add got_error_not_ref()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
diff --git a/include/got_error.h b/include/got_error.h
index ebbdea2..ba1061d 100644
--- a/include/got_error.h
+++ b/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 *);
diff --git a/lib/error.c b/lib/error.c
index 1df8f21..72cf6ae 100644
--- a/lib/error.c
+++ b/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);
+}