diff options
author | Sitaram Chamarty <sitaramc@gmail.com> | 2020-08-04 18:45:27 +0530 |
---|---|---|
committer | Sitaram Chamarty <sitaramc@gmail.com> | 2020-08-04 18:45:27 +0530 |
commit | 91f73356bd2a30fcf6ab923ad8e616351adb6cbd (patch) | |
tree | 8cc3c53a490e8ea88060f1d6602e637a25fcf795 /src/commands | |
parent | Install script can now modify shebangs when using a custom perl executable. (diff) | |
download | gitolite-gentoo-91f73356bd2a30fcf6ab923ad8e616351adb6cbd.tar.gz gitolite-gentoo-91f73356bd2a30fcf6ab923ad8e616351adb6cbd.tar.bz2 gitolite-gentoo-91f73356bd2a30fcf6ab923ad8e616351adb6cbd.zip |
gitolite mirroring terminology changes
This affects the mirroring code and documentation:
"slave"/"slaves" are now "copy"/"copies".
Backward compatibility should be maintained; you do not need to
change either your gitolite.conf, or any scripts you have
written on top, until you are ready to do so. (This in turn
means the word "slave" will still be present in the code, though
only just as much as needed.)
Should you wish to make this change, you need to migrate to the
latest version (which is also tagged as 3.6.12, so if you want
to wait till the distros pick it up wait for that), and then:
- In the gitolite.conf file, change `option mirror.slaves` to
`option mirror.copies`.
- If you have any scripts that use the `gitolite mirror list
slaves` command, change to `gitolite mirror list copies`.
sitaram
Diffstat (limited to 'src/commands')
-rwxr-xr-x | src/commands/1plus1 | 2 | ||||
-rwxr-xr-x | src/commands/mirror | 63 | ||||
-rwxr-xr-x | src/commands/newbranch | 41 |
3 files changed, 74 insertions, 32 deletions
diff --git a/src/commands/1plus1 b/src/commands/1plus1 index 897d235..1d94006 100755 --- a/src/commands/1plus1 +++ b/src/commands/1plus1 @@ -5,7 +5,7 @@ use warnings; # import LOCK_* use Fcntl qw(:flock); -my $lockbase = shift; # suggested: $GL_REPO_BASE/$GL_REPO.git/.gl-mirror-push-lock.$SLAVE_NAME +my $lockbase = shift; # suggested: $GL_REPO_BASE/$GL_REPO.git/.gl-mirror-push-lock.$COPY_NAME my @cmd_plus_args = @ARGV; # the actual 'gitolite mirror ...' command @ARGV = (); diff --git a/src/commands/mirror b/src/commands/mirror index 3a74a42..b22ec2a 100755 --- a/src/commands/mirror +++ b/src/commands/mirror @@ -15,32 +15,32 @@ use Gitolite::Common; use Gitolite::Conf::Load; =for usage -Usage 1: gitolite mirror push <slave> <repo> - gitolite mirror status <slave> <repo> +Usage 1: gitolite mirror push <copy> <repo> + gitolite mirror status <copy> <repo> gitolite mirror status all <repo> gitolite mirror status all all -Usage 2: ssh git@master-server mirror push <slave> <repo> - ssh git@master-server mirror status <slave> <repo> +Usage 2: ssh git@master-server mirror push <copy> <repo> + ssh git@master-server mirror status <copy> <repo> -Forces a push of one repo to one slave. +Forces a push of one repo to one copy. -Usage 1 is directly on the master server. Nothing is checked; if the slave -accepts it, the push happens, even if the slave is not in any slaves +Usage 1 is directly on the master server. Nothing is checked; if the copy +accepts it, the push happens, even if the copy is not in any copies option. This is how you do delayed or lagged pushes to servers that do not need real-time updates or have bandwidth/connectivity issues. Usage 2 can be initiated by *any* user who has *any* gitolite access to the -master server, but it checks that the slave is in one of the slaves options +master server, but it checks that the copy is in one of the copies options before doing the push. MIRROR STATUS: The usage examples above show what can be done. The 'status -all <repo>' usage checks the status of all the slaves defined for the given +all <repo>' usage checks the status of all the copies defined for the given repo. The 'status all all' usage is special, in that it only prints a list of repos that have *some* error, instead of dumping all the error info itself. SERVER LIST: 'gitolite mirror list master <reponame>' and 'gitolite mirror -list slaves <reponame>' will show you the name of the master server, and list -the slave servers, for the repo. They only work on the server command line +list copies <reponame>' will show you the name of the master server, and list +the copy servers, for the repo. They only work on the server command line (any server), but not remotely (from a normal user). =cut @@ -49,12 +49,13 @@ usage() if not @ARGV or $ARGV[0] eq '-h'; _die "HOSTNAME not set" if not $rc{HOSTNAME}; my ( $cmd, $host, $repo ) = @ARGV; +$host = 'copies' if $host eq 'slaves'; $repo =~ s/\.git$//; usage() if not $repo; if ( $cmd eq 'push' ) { - valid_slave( $host, $repo ) if exists $ENV{GL_USER}; - # will die if host not in slaves for repo + valid_copy( $host, $repo ) if exists $ENV{GL_USER}; + # will die if host not in copies for repo trace( 1, "TID=$tid host=$host repo=$repo", "gitolite mirror push started" ); _chdir( $rc{GL_REPO_BASE} ); @@ -80,15 +81,15 @@ if ( $cmd eq 'push' ) { trace( 1, "mirror: $_" ); } } - # save the mirror push status for this slave if the word 'fatal' is found, + # save the mirror push status for this copy if the word 'fatal' is found, # else remove the status file. We don't store "success" output messages; # you can always get those from the log files if you really need them. if ( $glss =~ /fatal/i ) { my $glss_prefix = Gitolite::Common::gen_ts() . "\t$ENV{GL_TID}\t"; $glss =~ s/^/$glss_prefix/gm; - _print("gl-slave-$host.status", $glss); + _print("gl-copy-$host.status", $glss); } else { - unlink "gl-slave-$host.status"; + unlink "gl-copy-$host.status"; } exit $errors; @@ -101,20 +102,20 @@ if ( $cmd eq 'push' ) { _chdir( $rc{GL_REPO_BASE} ); my $phy_repos = list_phy_repos(1); for my $repo ( @{$phy_repos} ) { - my @x = glob("$rc{GL_REPO_BASE}/$repo.git/gl-slave-*.status"); + my @x = glob("$rc{GL_REPO_BASE}/$repo.git/gl-copy-*.status"); print "$repo\n" if @x; } exit 0; } - valid_slave( $host, $repo ) if exists $ENV{GL_USER}; - # will die if host not in slaves for repo + valid_copy( $host, $repo ) if exists $ENV{GL_USER}; + # will die if host not in copies for repo _chdir( $rc{GL_REPO_BASE} ); _chdir("$repo.git"); $host = '*' if $host eq 'all'; - map { print_status($repo, $_) } sort glob("gl-slave-$host.status"); + map { print_status($repo, $_) } sort glob("gl-copy-$host.status"); } else { # strictly speaking, we could allow some of the possible commands remotely # also, at least for admins. However, these commands are mainly intended @@ -126,18 +127,18 @@ if ( $cmd eq 'push' ) { # ---------------------------------------------------------------------- -sub valid_slave { +sub valid_copy { my ( $host, $repo ) = @_; _die "invalid repo '$repo'" unless $repo =~ $REPONAME_PATT; - my %list = repo_slaves($repo); - _die "'$host' not a valid slave for '$repo'" unless $list{$host}; + my %list = repo_copies($repo); + _die "'$host' not a valid copy for '$repo'" unless $list{$host}; } -sub repo_slaves { +sub repo_copies { my $repo = shift; - my $ref = git_config( $repo, "^gitolite-options\\.mirror\\.slaves.*" ); + my $ref = git_config( $repo, "^gitolite-options\\.mirror\\.copies.*" ); my %list = map { $_ => 1 } map { split } values %$ref; return %list; @@ -157,9 +158,9 @@ sub print_status { my $repo = shift; my $file = shift; return unless -f $file; - my $slave = $1 if $file =~ /^gl-slave-(.+)\.status$/; + my $copy = $1 if $file =~ /^gl-copy-(.+)\.status$/; print "----------\n"; - print "WARNING: previous mirror push of repo '$repo' to host '$slave' failed, status is:\n"; + print "WARNING: previous mirror push of repo '$repo' to host '$copy' failed, status is:\n"; print slurp($file); print "----------\n"; } @@ -167,17 +168,17 @@ sub print_status { # ---------------------------------------------------------------------- # server side commands. Very little error checking. # gitolite mirror list master <repo> -# gitolite mirror list slaves <repo> +# gitolite mirror list copies <repo> sub server_side_commands { if ( $cmd eq 'list' ) { if ( $host eq 'master' ) { say repo_master($repo); - } elsif ( $host eq 'slaves' ) { - my %list = repo_slaves($repo); + } elsif ( $host eq 'copies' ) { + my %list = repo_copies($repo); say join( " ", sort keys %list ); } else { - _die "gitolite mirror list master|slaves <reponame>"; + _die "gitolite mirror list master|copies <reponame>"; } } else { _die "invalid command"; diff --git a/src/commands/newbranch b/src/commands/newbranch new file mode 100755 index 0000000..6dff545 --- /dev/null +++ b/src/commands/newbranch @@ -0,0 +1,41 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use lib $ENV{GL_LIBDIR}; +use Gitolite::Easy; + +=for usage +Usage: ssh git@host newbranch <repo name> <new branch name> <based-on ref name> + +Create a new branch and set it to existing branch or tag. You should have +write access to that branch. + +NOTE: runs "git branch arg-2 arg-3" in repo given by arg-1, which means you +should NOT prefix arguments with "refs/heads/" or "refs/tags/". + +---- + +This is for people who have restrictions on what files they can "touch". When +you fork a branch and change a file, even if you changed only the files you're +allowed to, gitolite thinks you changed *all* the files in the repo because +the "old SHA" is basically empty. + +This helps get around that by first creating the new branch, so that you can +then push to it. + +To enable this command, add it to the rc file as a 'command'. + +TODO: handle deletes also (less commonly encountered and left as an "exercise +for the reader" for now!) +=cut + +usage() if not @ARGV or @ARGV < 3 or $ARGV[0] eq '-h'; + +my $repo = shift; +my $newbr = shift; +my $oldref = shift; + +_die "you are not authorized" unless can_write($repo, "W", "refs/heads/$newbr"); + +Gitolite::Common::_system("git", "branch", $newbr, $oldref); |