Girocco/ValidUtil.pm: refactor valid branch name check
commit5abec837ec5ed5ec195a54c241d5389e07d6f26d
authorKyle J. McKay <mackyle@gmail.com>
Sun, 27 Jun 2021 19:51:33 +0000 (27 12:51 -0700)
committerKyle J. McKay <mackyle@gmail.com>
Sun, 27 Jun 2021 19:51:33 +0000 (27 12:51 -0700)
tree1b196450add0302db2d9f1095985b627872da463
parente09888e2caa69ebbfce08d5511eaf1aca86c78eb
Girocco/ValidUtil.pm: refactor valid branch name check

The branch name checking regular expression has become more-or-less
unreadable:

    /^\/|^\.|[\x00-\x1f \x7f\[\[~^"'"<>*?\\:]|\@\{|\.\.|\.lock$|\.$|\/$/

And is duplicated in three different places while not managing to catch
all the restrictions enforced by Git (see `git help check-ref-format`).

The fact that if you look closely at it you can even see it checking
for the same disallowed character twice (the '[') character.

This suggests it has become somewhat unmaintainable in its current form.

One challenge is that it's used by the install-time-only
Girocco::Validator module and at runtime by the Girocco::Project module.

Its use by the Girocco::Validator module makes it particularly
tricky to refactor since the Girocco::Validator module validates
the Girocco::Config module which pretty much all the other
currently existing Girocco modules "use".  Therefore moving the
validation expression into Girocco::Util will simply not work
(because then Girocco::Validator would need to "use" that module
which in turn "use"s Girocco::Config which Girocco::Validator is
trying to validate -- a bad idea).

Create a new Girocco::ValidUtil module that does not "use" any other
modules but exports a suitable `valid_branch_name` function for use
by other modules.

Take this opportunity to explicitly list all the rules it enforces,
fix the items it was failing to catch and make the regex much more
readable and understandable by using the "/x" modifier.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
Girocco/ValidUtil.pm [new file with mode: 0644]