Commit 63e5aa5c34d2e70074f9c3a1f42b7b7188a785fa

Stefan Sperling 2021-08-23T10:51:48

Expose got_ref_name_is_valid() for general purpose use. This will be needed for a future 'got send' command.

diff --git a/include/got_reference.h b/include/got_reference.h
index 57e9e86..927c10b 100644
--- a/include/got_reference.h
+++ b/include/got_reference.h
@@ -26,6 +26,9 @@ struct got_reference;
 struct got_repository;
 struct got_object_id;
 
+/* Determine whether a given reference name is valid. */
+int got_ref_name_is_valid(const char *);
+
 /*
  * Attempt to open the reference with the provided name in a repository.
  * The caller must dispose of the reference with got_ref_close().
diff --git a/lib/reference.c b/lib/reference.c
index 951594f..6f10967 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -265,8 +265,8 @@ get_refs_dir_path(struct got_repository *repo, const char *refname)
 	return got_repo_get_path_refs(repo);
 }
 
-static int
-is_valid_ref_name(const char *name)
+int
+got_ref_name_is_valid(const char *name)
 {
 	const char *s, *seg;
 	const char forbidden[] = { ' ', '~', '^', ':', '?', '*', '[' , '\\' };
@@ -320,7 +320,7 @@ const struct got_error *
 got_ref_alloc(struct got_reference **ref, const char *name,
     struct got_object_id *id)
 {
-	if (!is_valid_ref_name(name))
+	if (!got_ref_name_is_valid(name))
 		return got_error_path(name, GOT_ERR_BAD_REF_NAME);
 
 	return alloc_ref(ref, name, id, 0, 0);
@@ -330,7 +330,7 @@ const struct got_error *
 got_ref_alloc_symref(struct got_reference **ref, const char *name,
 	struct got_reference *target_ref)
 {
-	if (!is_valid_ref_name(name))
+	if (!got_ref_name_is_valid(name))
 		return got_error_path(name, GOT_ERR_BAD_REF_NAME);
 
 	return alloc_symref(ref, name, got_ref_get_name(target_ref), 0);
@@ -418,7 +418,7 @@ open_ref(struct got_reference **ref, const char *path_refs, const char *subdir,
 
 	*ref = NULL;
 
-	if (!is_valid_ref_name(name))
+	if (!got_ref_name_is_valid(name))
 		return got_error_path(name, GOT_ERR_BAD_REF_NAME);
 
 	if (ref_is_absolute || ref_is_well_known) {