~ubuntu-branches/ubuntu/wily/gitolite3/wily

« back to all changes in this revision

Viewing changes to src/commands/mirror

  • Committer: Package Import Robot
  • Author(s): David Bremner
  • Date: 2014-10-06 12:30:00 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20141006123000-pzkzr0u220sjmpg7
Tags: 3.6.1-1
New upstream release (Closes: #755784)

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
can use the special name "all" to get the status of all slaves for the given
35
35
repo.  (Admins wishing to find the status of all slaves for ALL repos will
36
36
have to script it using the output of "gitolite list-phy-repos".)
 
37
 
 
38
SERVER LIST: 'gitolite mirror list master <reponame>' and 'gitolite mirror
 
39
list slaves <reponame>' will show you the name of the master server, and list
 
40
the slave servers, for the repo.  They only work on the server command line
 
41
(any server), but not remotely (from a normal user).
37
42
=cut
38
43
 
39
44
usage() if not @ARGV or $ARGV[0] eq '-h';
92
97
 
93
98
    $host = '*' if $host eq 'all';
94
99
    map { print_status($_) } sort glob("gl-slave-$host.status");
 
100
} else {
 
101
    # strictly speaking, we could allow some of the possible commands remotely
 
102
    # also, at least for admins.  However, these commands are mainly intended
 
103
    # for server-side scripting so I don't care.
 
104
    usage() if $ENV{GL_USER};
 
105
 
 
106
    server_side_commands(@ARGV);
95
107
}
96
108
 
 
109
# ----------------------------------------------------------------------
 
110
 
97
111
sub valid_slave {
98
112
    my ( $host, $repo ) = @_;
99
113
    _die "invalid repo '$repo'" unless $repo =~ $REPONAME_PATT;
100
114
 
 
115
    my %list = repo_slaves($repo);
 
116
    _die "'$host' not a valid slave for '$repo'" unless $list{$host};
 
117
}
 
118
 
 
119
sub repo_slaves {
 
120
    my $repo = shift;
 
121
 
101
122
    my $ref = git_config( $repo, "^gitolite-options\\.mirror\\.slaves.*" );
102
123
    my %list = map { $_ => 1 } map { split } values %$ref;
103
124
 
104
 
    _die "'$host' not a valid slave for '$repo'" unless $list{$host};
 
125
    return %list;
 
126
}
 
127
 
 
128
sub repo_master {
 
129
    my $repo = shift;
 
130
 
 
131
    my $ref = git_config( $repo, "^gitolite-options\\.mirror\\.master\$" );
 
132
    my @list = map { split } values %$ref;
 
133
    _die "'$repo' seems to have more than one master" if @list > 1;
 
134
 
 
135
    return $list[0] || '';
105
136
}
106
137
 
107
138
sub print_status {
113
144
    print slurp($file);
114
145
    print "----------\n";
115
146
}
 
147
 
 
148
# ----------------------------------------------------------------------
 
149
# server side commands.  Very little error checking.
 
150
#   gitolite mirror list master <repo>
 
151
#   gitolite mirror list slaves <repo>
 
152
 
 
153
sub server_side_commands {
 
154
    if ( $cmd eq 'list' ) {
 
155
        if ( $host eq 'master' ) {
 
156
            say repo_master($repo);
 
157
        } elsif ( $host eq 'slaves' ) {
 
158
            my %list = repo_slaves($repo);
 
159
            say join( " ", sort keys %list );
 
160
        } else {
 
161
            _die "gitolite mirror list master|slaves <reponame>";
 
162
        }
 
163
    } else {
 
164
        _die "invalid command";
 
165
    }
 
166
}