Pick up git-browser multiple scheme fix
[girocco.git] / cgi / mirrorproj.cgi
blob2a164ca3d9232c39cbce18e9af7dc97be82e7e2f
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib ".";
9 use Girocco::CGI;
10 use Girocco::Config;
11 use Girocco::Project;
12 use Girocco::Util;
14 my $gcgi = Girocco::CGI->new('Project Mirroring');
15 my $cgi = $gcgi->cgi;
17 my $name = $cgi->param('name');
18 $name =~ s#\.git$## if $name; #
20 unless (defined $name) {
21 print "<p>I need the project name as an argument now.</p>\n";
22 exit;
25 if (!Girocco::Project::valid_name($name)) {
26 print "<p>Invalid project name. Go away, sorcerer.</p>\n";
27 exit;
30 if (!Girocco::Project::does_exist($name)) {
31 print "<p>Sorry but the project $name does not exist. Now, how did you <em>get</em> here?!</p>\n";
32 exit;
35 my $proj = Girocco::Project->load($name);
36 $proj or die "not found project $name, that's really weird!";
38 if (!$proj->{mirror}) {
39 print "<p>This project is not a mirror to be cloned.</p>\n";
40 exit;
44 $| = 1;
46 if (!$proj->{clone_logged} or $proj->{clone_failed}) {
47 # Kick off the clone since it is not running yet
48 print "<p>Initiated mirroring of ".$proj->{url}." to $Girocco::Config::name project ".
49 "<a href=\"@{[url_path($Girocco::Config::gitweburl)]}/$name.git\">$name</a>.git:</p>\n";
50 $proj->clone;
52 } elsif ($proj->{clone_in_progress}) {
53 print "<p>Mirroring of ".$proj->{url}." to $Girocco::Config::name project ".
54 "<a href=\"@{[url_path($Girocco::Config::gitweburl)]}/$name.git\">$name</a>.git in progress:</p>\n";
55 } else {
56 print "<p>Mirroring of ".$proj->{url}." to $Girocco::Config::name project ".
57 "<a href=\"@{[url_path($Girocco::Config::gitweburl)]}/$name.git\">$name</a>.git completed:</p>\n";
60 print "<pre>\n";
62 open LOG, $proj->_clonelog_path() or die "clonelog: $!";
63 tailf: for (;;) {
64 my $curpos;
65 for ($curpos = tell(LOG); <LOG>; $curpos = tell(LOG)) {
66 chomp;
67 $_ eq '@OVER@' and last tailf;
68 print "$_\n";
70 sleep 1;
71 seek(LOG, $curpos, 0); # seek to where we had been
73 close LOG;
75 print "</pre>\n";
77 $proj = Girocco::Project->load($name);
78 $proj or die "not found project $name on second load, that's _REALLY_ weird!";
80 if ($proj->{clone_failed}) {
81 print <<EOT;
82 <p><strong>Mirroring failed!</strong> Please <a
83 href="@{[url_path($Girocco::Config::webadmurl)]}/editproj.cgi?name=$name"
84 >revisit the project settings</a>.</p>
85 EOT