gitweb: pick up updates
[girocco.git] / toolbox / trash-project.pl
blob5b5500328e12724cc75405e726f07834575d4082
1 #!/usr/bin/perl
3 # Send a project to the trash
5 use strict;
6 use warnings;
7 use lib @basedir@;
9 use Girocco::Config;
10 use Girocco::Project;
11 use Girocco::Util qw(noFatalsToBrowser);
12 BEGIN {noFatalsToBrowser}
14 my $bin = $Girocco::Config::reporoot.'/_recyclebin';
15 mkdir $bin;
17 my $project = shift @ARGV || die "Please give project name on command line.";
19 # WARNING!
20 # Physical removal isn't actually supported. You have to do it manually.
21 # This only deletes the project from the list.
22 my $delete = 0;
23 if ($project eq '--really-delete') {
24 $delete = 1;
25 $project = shift @ARGV || die "Please give project name on command line.";
28 # WARNING!
29 # Don't use this option while jobd is running. You run the risk of destroying data.
30 my $keep_forks = 0;
31 if ($project eq '--keep-forks') {
32 $keep_forks = 1;
33 $project = shift @ARGV || die "Please give project name on command line.";
36 my $p = Girocco::Project->load($project) || die "Project '$project' not found!";
38 if ($keep_forks) {
39 # Run GC on that repository so that objects don't get lost within forks
40 my $reporoot = $Girocco::Config::reporoot;
41 my $basedir = $Girocco::Config::basedir;
42 print "We have to run GC on the repo so that the forks don't lose data. Hang on...\n";
43 system($Girocco::Config::git_bin, "--git-dir=$reporoot/$project.git", 'config',
44 '--unset', 'gitweb.lastgc');
45 $ENV{'show_progress'} = 1;
46 system("$basedir/jobd/gc.sh", $project);
47 } else {
48 die "Complicated situation: project still has forks. Please deal with it manually."
49 if (-d "$Girocco::Config::reporoot/$project/");
52 if (!$delete) {
53 use POSIX qw(strftime);
54 die "Already have a deleted version of the project. You need to make a decision now."
55 if (-d "$bin/$project.git");
57 if ($project =~ m!/!) {
58 my $parent = $project; $parent =~ s{^(.+)/.*$}{$1};
59 system('mkdir', '-p', "$bin/$parent") == 0 or
60 die "Problem creating directory hierarchy in recycle bin: $!";
63 rename $p->{'path'}, "$bin/$project.git" || die "Problem moving project data: $!";
64 my ($S,$M,$H,$d,$m,$y) = gmtime(time());
65 my $recycletime = strftime("%Y-%m-%dT%H:%M:%SZ", $S, $M, $H, $d, $m, $y, -1, -1, -1);
66 system($Girocco::Config::git_bin, "--git-dir=$bin/$project.git", 'config',
67 'girocco.recycletime', $recycletime);
69 $p->delete();
70 print "Project '$project' removed from $Girocco::Config::name".
71 ($delete ? '' : ", backup in $bin/$project.git") .".\n";