source: tags/ms_r16q2/SOURCE_TOOLS/svn_apply_ignores.pl

Last change on this file was 7803, checked in by westram, 13 years ago

merge from dev [7716] [7732] [7733] [7734] [7735]

  • script to add+remove svn ignores recursively
    • ignore *.gcno
    • do not ignore *.gcda
    • no longer ignore 'Makefile.bak' - instead ignore '*.bak'
    • no longer ignore 'ChangeLog' in subdirs
  • Property svn:executable set to *
File size: 4.8 KB
Line 
1#!/usr/bin/perl
2# ============================================================ #
3#                                                              #
4#   File      : svn_apply_ignores.pl                           #
5#   Purpose   : apply SVN default ignores for ARB              #
6#                                                              #
7#   Coded by Ralf Westram (coder@reallysoft.de) in July 2011   #
8#   Institute of Microbiology (Technical University Munich)    #
9#   http://www.arb-home.de/                                    #
10#                                                              #
11# ============================================================ #
12
13# configure here
14my $dump = 0;
15# configure here
16
17
18my $ARBHOME = $ENV{ARBHOME};
19if (not -d $ARBHOME) { die "no ARBHOME"; }
20
21my $SELF = $ARBHOME.'/SOURCE_TOOLS/svn_apply_ignores.pl';
22
23sub apply_dir($$) {
24  my ($full,$rel) = @_;
25
26  my $cmd = "svn pe svn:ignore $rel --editor-cmd \"$SELF --dopropedit $full \"";
27  system($cmd)==0 || die "can't execute '$cmd' (Reason: $?)";
28}
29
30sub apply_recursive($$);
31sub apply_recursive($$) {
32  my ($full,$rel) = @_;
33
34  my $have_svn = 0;
35  my @subdirs  = ();
36
37  opendir(DIR,$full) || die "can't read directory '$full' (Reason: $!)";
38  foreach (readdir(DIR)) {
39    if ($_ ne '.' and $_ ne '..') {
40      my $sub = $full.'/'.$_;
41      if (-d $sub and not -l $sub) { push @subdirs, $_; }
42      if ($_ eq '.svn') { $have_svn = 1; }
43    }
44  }
45  closedir(DIR);
46
47  if ($have_svn==1) { apply_dir($full,$rel); }
48  foreach (@subdirs) { apply_recursive($full.'/'.$_,$rel.'/'.$_); }
49}
50
51sub dumpContent($\@) {
52  my ($tag,$content_r) = @_;
53  print "------------------------------ [$tag start]\n";
54  foreach (@$content_r) { print "$_\n"; }
55  print "------------------------------ [$tag end]\n";
56}
57
58sub scanFilesExtensions($\%\%) {
59  my ($dir,$files_r,$ext_r) = @_;
60  opendir(DIR,$dir) || die "can't read directory '$dir' (Reason: $!)";
61  foreach (readdir(DIR)) {
62    my $full = $dir.'/'.$_;
63    if (-f $full) {
64      $$files_r{$_} = 1;
65      if (/\.([^.]+)$/) { $$ext_r{$1} = 1; }
66    }
67  }
68  closedir(DIR);
69}
70
71sub propedit_dir($$$) {
72  # called as editor from svn-command
73
74  my ($rel,$full,$propfile) = @_;
75
76  open(IN,'<'.$propfile) || die "can't load '$propfile' (Reason: $!)";
77  my @content = ();
78  my $line;
79  while (defined($line=<IN>)) { chomp($line); push @content, $line; }
80  close(IN);
81
82  my %have = ();
83  sub add_missing($) {
84    my ($want) = @_;
85    if (not defined $have{$want}) {
86      print "Added '$want'\n";
87      push @content, $want;
88    }
89  }
90
91  $dump==0 || dumpContent('old', @content);
92
93  my %file = ();
94  my %ext = ();
95  scanFilesExtensions($full,%file,%ext);
96
97  # ---------------------------------------- conditions
98
99  my $creates_gcov = (defined $ext{c} or defined $ext{cpp} or defined $ext{cxx});
100  my $creates_bak = (defined $file{Makefile});
101  my $is_root = ($rel eq '.');
102
103  %have = map { $_ => 1; } @content;
104
105  # ---------------------------------------- remove ignores
106
107  my @unwanted = (
108                  'Makefile.bak',
109                  '*.gcda',
110                 );
111
112  if (not $creates_gcov) { push @unwanted, '*.gcno'; }
113  if (not $creates_bak) { push @unwanted, '*.bak'; }
114  if (not $is_root) { push @unwanted, 'ChangeLog'; }
115
116  # ---------------------------------------- remove ignores
117
118  my %unwanted = map { $_ => 1; } @unwanted;
119
120  foreach (@content) {
121    if (defined $unwanted{$_}) { print "Removed '$_'\n"; }
122  }
123  @content = map {
124    if (defined $unwanted{$_}) { ; }
125    else { $_; }
126  } @content;
127
128  %have = map { $_ => 1; } @content;
129
130  # ---------------------------------------- add ignores
131
132  if ($creates_bak) { add_missing('*.bak'); }
133  if ($creates_gcov) { add_missing('*.gcno'); }
134
135  # ---------------------------------------- add ignores
136
137  $dump==0 || dumpContent('new', @content);
138
139
140  open(OUT,'>'.$propfile) || die "can't save '$propfile' (Reason: $!)";
141  foreach (@content) { print OUT $_."\n"; }
142  close(OUT);
143}
144
145sub show_usage() {
146  print "Usage: svn_apply_ignores.pl --apply\n";
147  print "       Apply all\n";
148  print "Usage: svn_apply_ignores.pl --dopropedit DIR PROPFILE\n";
149  print "       Edit property for directory 'DIR'\n";
150}
151
152sub main() {
153  my $args = scalar(@ARGV);
154
155  if ($args==0) {
156    show_usage();
157  }
158  else {
159    if ($ARGV[0] eq '--apply') {
160      chdir($ARBHOME);
161      apply_recursive($ARBHOME,'.');
162    }
163    elsif ($ARGV[0] eq '--dopropedit') {
164      my $DIR = $ARGV[1];
165      my $PROPFILE = $ARGV[2];
166      my ($REL,$FULL);
167      if ($DIR =~ /^$ARBHOME(\/)?/) {
168        ($REL,$FULL) = ($',$DIR);
169        if ($REL eq '') { $REL = '.'; }
170      }
171      else {
172        ($REL,$FULL) = ($DIR,$ARBHOME.'/'.$DIR);
173      }
174      if (not -d $FULL) { die "No such directory '$FULL'"; }
175      if (not -f $PROPFILE) { die "No such directory '$PROPFILE'"; }
176
177      propedit_dir($REL,$FULL,$PROPFILE);
178    }
179  }
180}
181main();
182
Note: See TracBrowser for help on using the repository browser.