#!/usr/bin/env perl # # Copyright (c) 2008-2014 Cisco Systems, Inc. All rights reserved. # Copyright (c) 2014 Intel, Inc. All rights reserved. # $COPYRIGHT$ # # Dumb script to run through all the svn:ignore's in the tree and build # build a .hgignore file for Mercurial. Do a few trivial things to # to try to have a few "global" files that don't need to be listed in # every directory (i.e., reduce the total length of the .hgignore file). use strict; use Getopt::Long; my $verbose_arg = 0; # Default to writing .hgignore my $output_arg = ".hgignore"; my $help_arg = 0; &Getopt::Long::Configure("bundling"); my $ok = Getopt::Long::GetOptions("verbose|v!" => \$verbose_arg, "output|o=s" => \$output_arg, "help|h!" => \$help_arg); if (!$ok || $help_arg) { print " Usage: $0 [-v] [-o output] [-h]\n"; exit($ok); } print "Writing to: $output_arg\n" if ($verbose_arg); ############################################################################# print "Thinking...\n" if (!$verbose_arg); my @hgignore; my @globals; # if we are not in an svn repo, then just concatenate # the .hgignore_global and any .hgignore_local files # to make the new .hgignore if (! -d "./.svn") { print "Not in an svn repo - creating .hgignore from existing files\n" if ($verbose_arg); my @files = qw(.hgignore_global .hgignore_local); while (@files) { local $_ = shift @files; if (-f $_) { open(IN, $_) || die "Can't open $_"; print "Reading $_...\n" if ($verbose_arg); while () { chomp; push(@hgignore, $_); } close(IN); } } } else { # Put in some specials that we ignore everywhere push(@hgignore, "# Automatically generated by build-hgignore.pl; edits may be lost! syntax: glob"); @globals = qw/.libs .deps .svn *.la *.lo *.o *.so *.a .dirstamp *.dSYM *.S *.loT *.orig *.rej *.class *.xcscheme *.plist .git* .mailmap .DS_Store stamp-h[1-9] configure config.guess config.sub config.log config.status libtool ltmain.sh missing depcomp install-sh aclocal.m4 autom4te.cache Makefile static-components.h project_list.m4 orte_wrapper_script ompi_wrapper_script make.out config.out auto.out diff.out *~ *\\\#/; # Start at the top level process("."); # See if there's an .hgignore_local file. If so, add its contents to the end. if (-f ".hgignore_local") { print "Reading .hgignore_local...\n" if ($verbose_arg); open(IN, ".hgignore_local") || die "Can't open .hgignore_local"; while () { chomp; push(@globals, $_); } close(IN); } } # If there's an old $output_arg file, delete it unlink($output_arg) if (-f $output_arg); # Write the new one open(FILE, ">$output_arg"); print FILE join("\n", @hgignore) . "\n"; print FILE join("\n", @globals) . "\n"; close(FILE); print "Wrote to $output_arg\n" if ($verbose_arg); # Done! exit(0); ####################################################################### # DFS-oriented recursive directory search sub process { my $dir = shift; # 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 ($verbose_arg); foreach my $line (split(/\n/, $svn_ignore)) { chomp($line); $line =~ s/^\.\///; next if ($line eq ""); # Ensure not to ignore special hg files next if ($line eq ".hgignore" || $line eq ".hgrc" || $line eq ".hg"); # 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(@hgignore, "$dir/$line"); } } # Now find subdirectories in this directory my @entries; opendir(DIR, $dir) || die "Cannot open directory \"$dir\" for reading: $!"; @entries = sort(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 ".hg" || -l "$dir/$e"); # If it's a directory, analyze it process("$dir/$e") if (-d "$dir/$e"); } }