2012-12-01 22:21:13 +04:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
#
|
|
|
|
# Copyright (c) 2008-2010 Cisco Systems, Inc. All rights reserved.
|
|
|
|
#
|
|
|
|
# Dumb script to run through all the svn:ignore's in the tree and
|
|
|
|
# build build .gitignore files for Git.
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
# Put in some specials that we ignore everywhere
|
|
|
|
my @globals = qw/.libs
|
|
|
|
.deps
|
2013-03-06 18:53:51 +04:00
|
|
|
.libs
|
|
|
|
.svn
|
2012-12-01 22:21:13 +04:00
|
|
|
*.la
|
|
|
|
*.lo
|
|
|
|
*.o
|
|
|
|
*.so
|
|
|
|
*.a
|
|
|
|
.dirstamp
|
|
|
|
*.dSYM
|
|
|
|
*.S
|
|
|
|
*.loT
|
|
|
|
*.orig
|
|
|
|
*.rej
|
|
|
|
*.class
|
|
|
|
*.xcscheme
|
|
|
|
*.plist
|
|
|
|
*~
|
2013-03-06 18:53:51 +04:00
|
|
|
Makefile
|
|
|
|
Makefile.in
|
|
|
|
static-components.h
|
2012-12-01 22:21:13 +04:00
|
|
|
*\\\#/;
|
|
|
|
unshift(@globals, "# Automatically generated by build-gitignore.pl; edits may be lost!");
|
|
|
|
|
|
|
|
my $debug;
|
|
|
|
$debug = 1
|
|
|
|
if ($ARGV[0]);
|
|
|
|
|
2013-03-06 18:53:51 +04:00
|
|
|
open(OUT, ">.gitignore");
|
|
|
|
|
|
|
|
# add the globals */
|
|
|
|
foreach my $val (@globals) {
|
|
|
|
print OUT "$val\n";
|
|
|
|
}
|
|
|
|
|
2012-12-01 22:21:13 +04:00
|
|
|
print "Thinking...\n"
|
|
|
|
if (!$debug);
|
|
|
|
|
|
|
|
# Start at the top level
|
|
|
|
process(".");
|
|
|
|
|
2013-03-06 18:53:51 +04:00
|
|
|
close(OUT);
|
|
|
|
|
2012-12-01 22:21:13 +04:00
|
|
|
# Done!
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
#######################################################################
|
|
|
|
|
|
|
|
# DFS-oriented recursive directory search
|
|
|
|
sub process {
|
|
|
|
my $dir = shift;
|
2013-03-06 18:53:51 +04:00
|
|
|
my $outdir = $dir;
|
|
|
|
$outdir =~ s/^\.\///;
|
2012-12-01 22:21:13 +04:00
|
|
|
|
|
|
|
# Look at the svn:ignore property for this directory
|
|
|
|
my $svn_ignore = `svn pg svn:ignore $dir 2> /dev/null`;
|
|
|
|
# If svn failed, bail on this directory.
|
|
|
|
return
|
|
|
|
if ($? != 0);
|
|
|
|
|
|
|
|
chomp($svn_ignore);
|
|
|
|
if ($svn_ignore ne "") {
|
|
|
|
print "Found svn:ignore in $dir\n"
|
|
|
|
if ($debug);
|
|
|
|
|
2013-03-06 18:53:51 +04:00
|
|
|
my @git;
|
2012-12-01 22:21:13 +04:00
|
|
|
|
|
|
|
# See if there's an .gitignore_local file. If so, add its
|
|
|
|
# contents to the end.
|
|
|
|
if (-f "$dir/.gitignore_local") {
|
|
|
|
open(IN, "$dir/.gitignore_local") || die "Can't open .gitignore_local";
|
|
|
|
while (<IN>) {
|
|
|
|
chomp;
|
|
|
|
push(@git, $_);
|
|
|
|
}
|
|
|
|
|
|
|
|
close(IN);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Now read the svn:ignore value
|
|
|
|
foreach my $line (split(/\n/, $svn_ignore)) {
|
|
|
|
chomp($line);
|
|
|
|
$line =~ s/^\.\///;
|
|
|
|
next
|
|
|
|
if ($line eq "");
|
|
|
|
|
|
|
|
# Ensure not to ignore special git files
|
|
|
|
next
|
|
|
|
if ($line eq ".gitignore" || $line eq ".gitignore_local" ||
|
|
|
|
$line eq ".git" || $line eq ".svn");
|
|
|
|
# We're globally ignoring some specials already; we can
|
|
|
|
# skip those
|
|
|
|
my $skip = 0;
|
|
|
|
foreach my $g (@globals) {
|
|
|
|
if ($g eq $line) {
|
|
|
|
$skip = 1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
next
|
|
|
|
if ($skip);
|
|
|
|
|
|
|
|
push(@git, "$line");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Write out a new .gitignore file
|
|
|
|
foreach my $val (@git) {
|
2013-03-06 18:53:51 +04:00
|
|
|
if ($outdir eq ".") {
|
|
|
|
print OUT "$val\n";
|
|
|
|
} else {
|
|
|
|
print OUT "$outdir/$val\n";
|
|
|
|
}
|
2012-12-01 22:21:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# Now find subdirectories in this directory
|
|
|
|
my @entries;
|
|
|
|
opendir(DIR, $dir) || die "Cannot open directory \"$dir\" for reading: $!";
|
|
|
|
@entries = readdir(DIR);
|
|
|
|
closedir DIR;
|
|
|
|
|
|
|
|
foreach my $e (@entries) {
|
|
|
|
# Skip special directories and sym links
|
|
|
|
next
|
|
|
|
if ($e eq "." || $e eq ".." || $e eq ".svn" || $e eq ".git" ||
|
|
|
|
-l "$dir/$e");
|
|
|
|
|
|
|
|
# If it's a directory, analyze it
|
|
|
|
process("$dir/$e")
|
|
|
|
if (-d "$dir/$e");
|
|
|
|
}
|
|
|
|
}
|