toolbox/update-all-config.pl: quiet means quiet
[girocco.git] / toolbox / create_projects_bom.pl
blob2560e4bd20294254f39553d40014d0f4f98148e6
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/refs
60 refs
63 sub list_files($$) {
64 my ($rdir, $pdir) = @_;
65 my $odir = "$rdir/$pdir";
66 opendir LISTDIR, "$odir" or return;
67 my @tags = grep { !/^\./ && !/[,\s\/\\]/ && ! -l "$odir/$_" && -f "$odir/$_" } readdir(LISTDIR);
68 closedir LISTDIR;
69 print "$pdir/$_\n" foreach sort({lc($a) cmp lc($b) || $a cmp $b} @tags);
72 sub bom_for_project($) {
73 my $rroot = $Girocco::Config::reporoot;
74 my $proj = shift;
75 print "$proj.git\n";
76 -l "$rroot/$proj.git" and return;
78 # For each entry from @projparts that exists, output
79 # a line. BUT, if it exists AND it's a symlink, SKIP
80 # outputting a line for anything beneath it that's also
81 # in @projparts.
83 my %links = ();
84 my $test = "$rroot/$proj.git";
85 foreach (@projparts) {
86 my $idx = index($_, "/");
87 next if $idx > 0 && $links{substr($_, 0, $idx)};
88 if (-l "$test/$_") {
89 $links{$_} = 1;
90 print "$proj.git/$_\n";
91 next;
92 } elsif ($_ eq "packed-refs") {
93 next;
94 } elsif (-e "$test/$_") {
95 print "$proj.git/$_\n";
96 list_files($rroot, "$proj.git/$_") if $_ eq "ctags";
101 sub main {
102 local *ARGV = \@_;
103 my %projects = map({$_ => 1} Girocco::Project::get_full_list());
104 my @names;
105 my $rroot = $Girocco::Config::reporoot;
106 if (@ARGV) {
107 my @list = ();
108 foreach (@ARGV) {
109 s/\.git$//i;
110 $_ ne "" or next;
111 $projects{$_} || (-l "$rroot/$_.git" && -d "$rroot/$_.git") or
112 die "no such project: $_\n";
113 push(@list, $_);
115 my %list = map({$_ => 1} @list);
116 @names = sort({lc($a) cmp lc($b) || $a cmp $b} keys(%list));
117 } else {
118 if (opendir REPOROOT, $rroot) {
119 my @links = grep {
120 /^[^._]/ && s/\.git$//i &&
121 -l "$rroot/$_.git" && -d "$rroot/$_.git"
122 } readdir(REPOROOT);
123 closedir REPOROOT;
124 $projects{$_} = 1 foreach @links;
126 @names = sort({lc($a) cmp lc($b) || $a cmp $b} keys(%projects));
128 @names or die "no projects specified\n";
129 #print map("$_\n", @names);
130 bom_for_project($_) foreach @names;
131 exit 0;