Skip to content

Commit

Permalink
Item11171: Adding git support, checking that all files in MANIFEST ex…
Browse files Browse the repository at this point in the history
…ist in the versionning system, and it should even work on Windows (untested)

git-svn-id: http://svn.foswiki.org/trunk@12720 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
OlivierRaginel authored and OlivierRaginel committed Oct 6, 2011
1 parent e3f1200 commit 7ef5a4f
Showing 1 changed file with 106 additions and 44 deletions.
150 changes: 106 additions & 44 deletions core/tools/check_manifest.pl
@@ -1,62 +1,124 @@
#!/usr/bin/perl

use strict;
use warnings;

# cruise back up the tree until we find lib and data subdirs
require Cwd;
use Cwd;
use File::Spec;
use File::Find;

my $manifest = shift || 'MANIFEST';
my @skip = qw(tools test working logs);
my $cvs = 'subversion';
my $skipPattern = join( '|', @skip );
my @lost; # Files on disk not in MANIFEST
my %man; # Hash of MANIFEST content: file => perm

my $manifest = 'MANIFEST';
#unless (-f $manifest) {
# File::Find::find( sub { /^MANIFEST\z/ && ( $manifest = $File::Find::name )
# }, "$root/lib/TWiki" );
#}
die "No such MANIFEST $manifest" unless -e $manifest;

my %man;

open MAN, '<', $manifest or die "Can't open $manifest for reading: $!";
while( <MAN> ) {
next if /^!include/;
$man{$1} = 1 if /^(\S+)\s+\d+.*$/;
}
close MAN;
# Search the current working directory and its parents
# for a directory called like the first parameter
sub findPathToDir {
my $lookForDir = shift;

my @dirlist = File::Spec->splitdir( Cwd::getcwd() );
do {
my $dir = File::Spec->catdir( @dirlist, $lookForDir );
return File::Spec->catdir(@dirlist) if -d $dir;
} while ( pop @dirlist );
return;
}

my @cwd = split(/[\/\\]/, Cwd::getcwd());
my $root;
# Checks if a file is in the MANIFEST, and removes it
# otherwise, adds it to @lost
sub checkFileInManifest {
my ( $root, $file ) = @_;

while (scalar(@cwd) > 1) {
$root = join('/', @cwd);
if (-d "$root/lib" && -d "$root/data") {
last;
my $diskfile = "$root/$file";
return if -d $diskfile; # For Subversion
if ( my $mode = delete $man{$file} ) {
my $cmode = ( stat($diskfile) )[2] & 07777;
print "Permissions for $file differ"
. " in MANIFEST ($mode) and on disk ($cmode)\n"
if $cmode != $mode;
}
else {
return if $file =~ m#^(?:$skipPattern)/#o; # For git
return if $file =~ m#/TestCases/#;
push @lost, $file;
}
pop(@cwd);
}

die "Can't find root" unless (-d "$root/lib" && -d "$root/data");

my @skip = qw(tools test working logs);
print <<END;
Run this script from anywhere a directory with a MANIFEST file
# Prints some "helpful" messages
sub help {
print <<"END";
Run this script from a directory with a MANIFEST file.
The script will find and scan MANIFEST and compare the contents with
what is checked in under subversion. Any differences are reported.
what is checked in under $cvs. Any differences are reported.
END
print "The ",join(',', @skip)," directories are *not* scanned.\n";

my @lost;
my $sk = join('|', @skip);
foreach my $dir( grep { -d "$root/$_" }
split(/\n/, `svn ls $root`) ) {
next if $dir =~ /^($sk)\/$/;
print "Examining $root/$dir\n";
push( @lost,
grep { !$man{$_} && !/\/TestCases\// && ! -d "$root/$_" }
map{ "$dir$_" }
split(/\n/, `svn ls -R $root/$dir`));
}
print "The following files were found in subversion, but are not in MANIFEST\n";
print join("\n", @lost ),"\n";
print "The " . join( ', ', @skip ) . " directories are *not* scanned.\n";
}

my $root = findPathToDir('lib');
die "Can't find root" unless ( -d "$root/lib" && -d "$root/data" );

unless ( -f $manifest ) {
File::Find::find(
sub {
/^MANIFEST\z/ && ( $manifest = $File::Find::name );
},
File::Spec->catdir( $root, 'lib' )
);
}
die "No such MANIFEST $manifest" unless -e $manifest;

open my $man, '<', $manifest or die "Can't open $manifest for reading: $!";
while (<$man>) {
next if /^!include/;
$man{$1} = $2 if /^(\S+)\s+(\d+)/;
}
close $man;

if ( my $gitdir = findPathToDir('.git') ) {
$cvs = 'git';
help($cvs);
for my $file ( split /\n/, qx{git ls-files $root} ) {
$file =~ s#^$root/##; # Should never happen, but safer
checkFileInManifest( $root => $file );
}
}
else {
help($cvs);
foreach my $dir (
grep { -d "$root/$_" }
split( /\n/, `svn ls $root` )
)
{
next if $dir =~ m#/(?:$skipPattern)/#o;
print "Examining $root/$dir\n";
for my $file (
map { "$dir$_" }
split( /\n/, `svn ls -R $root/$dir` )
)
{
checkFileInManifest( $root => $file );
}
}
}
if (@lost) {
print "The following "
. ( scalar @lost )
. " files were found in $cvs, but are not in MANIFEST:\n";
print join( "\n", @lost, '' );
}
else {
print "All files in MANIFEST are checked in.\n";
}
my @found = sort keys %man;
if (@found) {
print "The following "
. ( scalar @found )
. " files were found in MANIFEST, but not in $cvs:\n";
print join( "\n", @found, '' );
}

0 comments on commit 7ef5a4f

Please sign in to comment.