gitweb/indextext_readonly.html: include sample readonly file
[girocco.git] / toolbox / create_projects_bom.pl
blobf50aad1bd1ffad5d440e4139a8121b6e711d0ff0
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 .no_blob_plain
27 .noconfig
28 .nofetch
29 .nogc
30 .nohooks
31 HEAD
32 README.dat
33 README.html
34 config
35 ctags
36 description
37 info
38 info/lastactivity
39 mob
40 mob/HEAD
41 mob/config
42 mob/description
43 mob/hooks
44 mob/info
45 mob/objects
46 mob/packed-refs
47 mob/refs
48 mob/refs/heads
49 mob/refs/mob
50 objects
51 objects/info
52 objects/info/alternates
53 packed-refs
54 private
55 private/HEAD
56 private/config
57 private/gc.pid
58 private/objects
59 private/packed-refs
60 private/refs
61 refs
64 sub list_files($$) {
65 my ($rdir, $pdir) = @_;
66 my $odir = "$rdir/$pdir";
67 opendir LISTDIR, "$odir" or return;
68 my @tags = grep { !/^\./ && !/[,\s\/\\]/ && ! -l "$odir/$_" && -f "$odir/$_" } readdir(LISTDIR);
69 closedir LISTDIR;
70 print "$pdir/$_\n" foreach sort({lc($a) cmp lc($b) || $a cmp $b} @tags);
73 sub bom_for_project($) {
74 my $rroot = $Girocco::Config::reporoot;
75 my $proj = shift;
76 print "$proj.git\n";
77 -l "$rroot/$proj.git" and return;
79 # For each entry from @projparts that exists, output
80 # a line. BUT, if it exists AND it's a symlink, SKIP
81 # outputting a line for anything beneath it that's also
82 # in @projparts.
84 my %links = ();
85 my $test = "$rroot/$proj.git";
86 foreach (@projparts) {
87 my $idx = index($_, "/");
88 next if $idx > 0 && $links{substr($_, 0, $idx)};
89 if (-l "$test/$_") {
90 $links{$_} = 1;
91 print "$proj.git/$_\n";
92 next;
93 } elsif ($_ eq "packed-refs") {
94 next;
95 } elsif (-e "$test/$_") {
96 print "$proj.git/$_\n";
97 list_files($rroot, "$proj.git/$_") if $_ eq "ctags";
102 sub main {
103 local *ARGV = \@_;
104 my %projects = map({$_ => 1} Girocco::Project::get_full_list());
105 my @names;
106 my $rroot = $Girocco::Config::reporoot;
107 if (@ARGV) {
108 my @list = ();
109 foreach (@ARGV) {
110 s/\.git$//i;
111 $_ ne "" or next;
112 $projects{$_} || (-l "$rroot/$_.git" && -d "$rroot/$_.git") or
113 die "no such project: $_\n";
114 push(@list, $_);
116 my %list = map({$_ => 1} @list);
117 @names = sort({lc($a) cmp lc($b) || $a cmp $b} keys(%list));
118 } else {
119 if (opendir REPOROOT, $rroot) {
120 my @links = grep {
121 /^[^._]/ && s/\.git$//i &&
122 -l "$rroot/$_.git" && -d "$rroot/$_.git"
123 } readdir(REPOROOT);
124 closedir REPOROOT;
125 $projects{$_} = 1 foreach @links;
127 @names = sort({lc($a) cmp lc($b) || $a cmp $b} keys(%projects));
129 @names or die "no projects specified\n";
130 #print map("$_\n", @names);
131 bom_for_project($_) foreach @names;
132 exit 0;