commit 63e5aa5c34d2e70074f9c3a1f42b7b7188a785fa from: Stefan Sperling date: Mon Aug 23 10:51:48 2021 UTC Expose got_ref_name_is_valid() for general purpose use. This will be needed for a future 'got send' command. commit - dc7edd429e3aae9d685c43504872d528567f3007 commit + 63e5aa5c34d2e70074f9c3a1f42b7b7188a785fa blob - 57e9e869807e74b9550bb2dc26f6520eb30f2478 blob + 927c10b5f2d5bd38831138167a2c77e989ca9afe --- include/got_reference.h +++ 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(). blob - 951594f62e06613aa74ada22eaa951e58b48716d blob + 6f10967566ee57bb91278a816d22af648bed70e3 --- lib/reference.c +++ lib/reference.c @@ -265,8 +265,8 @@ get_refs_dir_path(struct got_repository *repo, const c 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_ *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) {