diff options
author | 2015-05-30 15:58:54 +0530 | |
---|---|---|
committer | 2015-05-31 07:05:35 +0530 | |
commit | 2b918fc3700cfc78613f91d9ea230c1f2eec4055 (patch) | |
tree | b48a84ee29da82835d6bb2e89197a73a36f65c3d | |
parent | create command: remove race condition... (diff) | |
download | gitolite-gentoo-2b918fc3700cfc78613f91d9ea230c1f2eec4055.tar.gz gitolite-gentoo-2b918fc3700cfc78613f91d9ea230c1f2eec4055.tar.bz2 gitolite-gentoo-2b918fc3700cfc78613f91d9ea230c1f2eec4055.zip |
Alias.pm learns a few more tricks...
(thanks to Nicholas Clark for the first requirement)
- allow replacement by "prefix"
- allow customised warning message (to better warn users of the new repo
name)
- allow "inform and abort" -- forces users to switch to the new name
-rw-r--r-- | src/lib/Gitolite/Triggers/Alias.pm | 59 |
1 files changed, 53 insertions, 6 deletions
diff --git a/src/lib/Gitolite/Triggers/Alias.pm b/src/lib/Gitolite/Triggers/Alias.pm index acff44b..1fa24bb 100644 --- a/src/lib/Gitolite/Triggers/Alias.pm +++ b/src/lib/Gitolite/Triggers/Alias.pm @@ -26,16 +26,42 @@ Why: How: + * uncomment the line "Alias" in the "user-visible behaviour" section in the + rc file + * add a new variable REPO_ALIASES to the rc file, with entries like: REPO_ALIASES => { + # if you need a more aggressive warning message than the default + WARNING => "Please change your URLs to use '%new'; '%old' will not work after XXXX-XX-XX", + + # prefix mapping section + PREFIX_MAPS => { + # note: NO leading slash in keys or values below + 'var/lib/git/' => '', + 'var/opt/git/' => 'opt/', + }, + + # individual repo mapping section 'foo' => 'foo/code', - } - * add the following line to the INPUT section in the rc file: + # force users to change their URLs + 'bar' => '301/bar/code', + # a target repo starting with "301/" won't actually work; + # it will just produce an error message pointing the user + # to the new name. This allows admins to force users to + # fix their URLs. + }, + + If a prefix map is supplied, each key is checked (in *undefined* order), + and the *first* key which matches the prefix of the repo will be applied. + If more than one key matches (for example if you specify '/abc/def' as one + key, and '/abc' as another), it is undefined which will get picked up. - 'Alias::input', + The result of this, (or the original repo name if no map was found), will + then be subject to the individual repo mappings. Since these are full + repo names, there is no possibility of multiple matches. Notes: @@ -65,13 +91,34 @@ sub input { my $repo = $1; ( my $norm = $repo ) =~ s/\.git$//; # normalised repo name - my $target; + my $target = $norm; - return unless $target = $rc{REPO_ALIASES}{$norm}; + # prefix maps first + my $pm = $rc{REPO_ALIASES}{PREFIX_MAPS} || {}; + while (my($k, $v) = each %$pm) { + last if $target =~ s/^$k/$v/; + # no /i, /g, etc. by design + } + + # individual repo map next + $target = $rc{REPO_ALIASES}{$target} || $target; + + # undocumented; don't use without discussing on mailing list $target = $target->{$user} if ref($target) eq 'HASH'; + + # if the repo name finally maps to empty, we bail, with no changes return unless $target; - _warn "'$norm' is an alias for '$target'"; + # we're done. Did we actually change anything? + return if $norm eq $target; + + # if the new name starts with "301/", inform and abort + _die "please use '$target' instead of '$norm'" if $target =~ s(^301/)(); + # otherwise print a warning and continue with the new name + my $wm = $rc{REPO_ALIASES}{WARNING} || "'%old' is an alias for '%new'"; + $wm =~ s/%new/$target/g; + $wm =~ s/%old/$norm/g; + _warn $wm; $ENV{SSH_ORIGINAL_COMMAND} =~ s/'\/?$repo'/'$target'/; } |