-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathsvn_set_ignore
executable file
·143 lines (123 loc) · 3.88 KB
/
svn_set_ignore
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/perl -w
# $Id: svn_set_ignore 1189 2019-07-13 16:41:07Z mueller $
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright 2007-2019 by Walter F.J. Mueller <[email protected]>
#
# Revision History:
# Date Rev Vers Comment
# 2019-07-13 1189 1.2.3 drop superfluous exists for $opts
# 2018-12-18 1089 1.2.2 add and use bailout
# 2017-05-27 899 1.2.1 check svn:ignore existance before reading it
# 2016-12-17 821 1.2 use .gitignore rather .cvsignore
# 2014-11-04 601 1.1 use 'svn info' rather /.svn check for svn >= 1.7
# 2010-04-26 284 1.0.1 add error check for GetOptions
# 2007-06-16 56 1.0 Initial version
#
use 5.14.0; # require Perl 5.14 or higher
use strict; # require strict checking
use Getopt::Long;
my @dirlist;
my %ignores;
my %opts = ();
GetOptions(\%opts, "trace", "dry-run")
or bailout("bad command options");
if (@ARGV) {
push @dirlist, @ARGV;
} else {
@dirlist = `find -type d | sort`;
bailout("bad find|grep") if $?;
chomp @dirlist;
# drop some directories at this level
@dirlist = grep {! /\/(\.svn|\.Xil)/} @dirlist;
}
foreach (@dirlist) { do_dir($_); }
#-------------------------------------------------------------------------------
sub do_dir {
my ($dirname) = @_;
my @cur_ipat;
my @new_ipat;
my %ipat;
# skip ise directories (they have sometimes strange chars in dir names
return if $dirname =~ m|/ise/|;
# check for svn working directory
my $svn_info = `svn info $dirname 2>&1`;
return if $?;
print "$dirname\n";
my @dpelist = split '/', $dirname;
my @dpecurr = ();
foreach my $e (@dpelist) {
push @dpecurr, $e;
my $d = join '/',@dpecurr;
if (not exists $ignores{$d}) {
$ignores{$d} = ();
if (-r "$d/.gitignore") {
print "read $d/.gitignore\n" if $opts{trace};
open (CVSIG, "$d/.gitignore")
or bailout("failed to read '$d/.gitignore': $!");
while (<CVSIG>) {
chomp;
next if /^\s*$/; # ignore empty or space only lines
next if /^#/; # ignore comments
push @{$ignores{$d}}, $_;
print " $_\n" if $opts{trace};
}
close (CVSIG);
}
}
foreach my $i (@{$ignores{$d}}) {
next if exists $ipat{$i};
$ipat{$i} = 1;
push @new_ipat, $i;
}
}
# check whether svn:ignore already defined
my $has_ignore = 0;
open (SVN, "svn pl $dirname|")
or bailout("failed to open svn pl pipe for '$dirname': $!");
while (<SVN>) {
chomp;
if (m/^\s*svn:ignore\s*$/) {
$has_ignore = 1;
last;
}
}
close (SVN);
# read svn:ignore, if it exists
if ($has_ignore) {
open (SVN, "svn pg svn:ignore $dirname|")
or bailout("failed to open svn pg pipe for '$dirname': $!");
while (<SVN>) {
chomp;
next if /^\s*$/; # ignore empty or space only lines
push @cur_ipat, $_;
}
close (SVN);
}
if (join("\n",@cur_ipat) ne join("\n",@new_ipat)) {
if ($has_ignore) {
print "update svn:ignore for $dirname\n";
print "old svn:ignore:\n";
print " ", join("\n ",@cur_ipat),"\n";
} else {
print "setup svn:ignore for $dirname\n";
}
print "new svn:ignore:\n";
print " ", join("\n ",@new_ipat),"\n";
if (not $opts{"dry-run"}) {
open (TMP, ">/tmp/svn_set_ignore_$$")
or bailout("failed to open tmp file: $1");
print TMP join("\n",@new_ipat),"\n";
close (TMP);
print `svn ps svn:ignore -F /tmp/svn_set_ignore_$$ $dirname`;
bailout("bad svn ps") if $?;
unlink "/tmp/svn_set_ignore_$$"
or bailout("failed to delete tmp file: $!");
}
}
}
#-------------------------------------------------------------------------------
sub bailout {
my ($msg) = @_;
print STDERR "svn_set_ignore-F: $msg\n";
exit 1;
}