apache.conf.in: redirect www.repo.or.cz to repo.or.cz
[girocco.git] / toolbox / create_projects_bom.pl
blobd8a554c5b3da906b885dcaf8e65bfe93cfeaa82e
1 #!/usr/bin/perl
3 # create_projects_bom.pl - generate list of files to backup
4 # Copyright (C) 2020 Kyle J. McKay. All rights reserved.
5 # License GPLv2+: GNU GPL version 2 or later.
6 # www.gnu.org/licenses/gpl-2.0.html
7 # This is free software: you are free to change and redistribute it.
8 # There is NO WARRANTY, to the extent permitted by law.
10 use strict;
11 use warnings;
12 use vars qw($VERSION);
13 BEGIN {*VERSION = \'1.0.0'}
14 use lib "__BASEDIR__";
15 use Girocco::Config;
16 use Girocco::CLIUtil;
17 use Girocco::Project;
19 exit(&main(@ARGV)||0);
21 my @projparts;
22 BEGIN {@projparts = qw(
23 .bypass
24 .bypass_fetch
25 .last_refresh
26 .noconfig
27 .nofetch
28 .nogc
29 .nohooks
30 HEAD
31 README.html
32 config
33 ctags
34 description
35 info
36 info/lastactivity
37 mob
38 mob/HEAD
39 mob/config
40 mob/description
41 mob/hooks
42 mob/info
43 mob/objects
44 mob/packed-refs
45 mob/refs
46 mob/refs/heads
47 mob/refs/mob
48 objects
49 objects/info
50 objects/info/alternates
51 packed-refs
52 private
53 private/HEAD
54 private/config
55 private/gc.pid
56 private/objects
57 private/refs
58 refs
61 sub list_files($$) {
62 my ($rdir, $pdir) = @_;
63 my $odir = "$rdir/$pdir";
64 opendir LISTDIR, "$odir" or return;
65 my @tags = grep { !/^\./ && !/[,\s\/\\]/ && ! -l "$odir/$_" && -f "$odir/$_" } readdir(LISTDIR);
66 closedir LISTDIR;
67 print "$pdir/$_\n" foreach sort({lc($a) cmp lc($b) || $a cmp $b} @tags);
70 sub bom_for_project($) {
71 my $rroot = $Girocco::Config::reporoot;
72 my $proj = shift;
73 print "$proj.git\n";
74 -l "$rroot/$proj.git" and return;
76 # For each entry from @projparts that exists, output
77 # a line. BUT, if it exists AND it's a symlink, SKIP
78 # outputting a line for anything beneath it that's also
79 # in @projparts.
81 my %links = ();
82 my $test = "$rroot/$proj.git";
83 foreach (@projparts) {
84 my $idx = index($_, "/");
85 next if $idx > 0 && $links{substr($_, 0, $idx)};
86 if (-l "$test/$_") {
87 $links{$_} = 1;
88 print "$proj.git/$_\n";
89 next;
90 } elsif ($_ eq "packed-refs") {
91 next;
92 } elsif (-e "$test/$_") {
93 print "$proj.git/$_\n";
94 list_files($rroot, "$proj.git/$_") if $_ eq "ctags";
99 sub main {
100 local *ARGV = \@_;
101 my %projects = map({$_ => 1} Girocco::Project::get_full_list());
102 my @names;
103 my $rroot = $Girocco::Config::reporoot;
104 if (@ARGV) {
105 my @list = ();
106 foreach (@ARGV) {
107 s/\.git$//i;
108 $_ ne "" or next;
109 $projects{$_} || (-l "$rroot/$_.git" && -d "$rroot/$_.git") or
110 die "no such project: $_\n";
111 push(@list, $_);
113 my %list = map({$_ => 1} @list);
114 @names = sort({lc($a) cmp lc($b) || $a cmp $b} keys(%list));
115 } else {
116 if (opendir REPOROOT, $rroot) {
117 my @links = grep {
118 /^[^._]/ && s/\.git$//i &&
119 -l "$rroot/$_.git" && -d "$rroot/$_.git"
120 } readdir(REPOROOT);
121 closedir REPOROOT;
122 $projects{$_} = 1 foreach @links;
124 @names = sort({lc($a) cmp lc($b) || $a cmp $b} keys(%projects));
126 @names or die "no projects specified\n";
127 #print map("$_\n", @names);
128 bom_for_project($_) foreach @names;
129 exit 0;