Commit 2aa0475caa333b7d3f25991b11b09ab048e8e6de

Stefan Sperling 2019-02-03T17:00:40

add got_error_not_ref()

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);
+}