-#!/usr/bin/env perl\r
-\r
-# ====================================================================\r
-# commit-mime-type-check.pl: check that every added file has the\r
-# svn:mime-type property set and every added file with a mime-type\r
-# matching text/* also has svn:eol-style set. If any file fails this\r
-# test the user is sent a verbose error message suggesting solutions and\r
-# the commit is aborted.\r
-#\r
-# Usage: commit-mime-type-check.pl REPOS TXN-NAME\r
-# ====================================================================\r
-# Most of commit-mime-type-check.pl was taken from\r
-# commit-access-control.pl, Revision 9986, 2004-06-14 16:29:22 -0400.\r
-# ====================================================================\r
-# Copyright (c) 2000-2004 CollabNet. All rights reserved.\r
-#\r
-# This software is licensed as described in the file COPYING, which\r
-# you should have received as part of this distribution. The terms\r
-# are also available at http://subversion.tigris.org/license.html.\r
-# If newer versions of this license are posted there, you may use a\r
-# newer version instead, at your option.\r
-#\r
-# This software consists of voluntary contributions made by many\r
-# individuals. For exact contribution history, see the revision\r
-# history and logs, available at http://subversion.tigris.org/.\r
-# ====================================================================\r
-\r
-# Turn on warnings the best way depending on the Perl version.\r
-BEGIN {\r
- if ( $] >= 5.006_000)\r
- { require warnings; import warnings; }\r
- else\r
- { $^W = 1; }\r
-}\r
-\r
-use strict;\r
-use Carp;\r
-\r
-\r
-######################################################################\r
-# Configuration section.\r
-\r
-# Svnlook path.\r
-my $svnlook = "/usr/bin/svnlook";\r
-\r
-# Since the path to svnlook depends upon the local installation\r
-# preferences, check that the required program exists to insure that\r
-# the administrator has set up the script properly.\r
-{\r
- my $ok = 1;\r
- foreach my $program ($svnlook)\r
- {\r
- if (-e $program)\r
- {\r
- unless (-x $program)\r
- {\r
- warn "$0: required program `$program' is not executable, ",\r
- "edit $0.\n";\r
- $ok = 0;\r
- }\r
- }\r
- else\r
- {\r
- warn "$0: required program `$program' does not exist, edit $0.\n";\r
- $ok = 0;\r
- }\r
- }\r
- exit 1 unless $ok;\r
-}\r
-\r
-######################################################################\r
-# Initial setup/command-line handling.\r
-\r
-&usage unless @ARGV == 2;\r
-\r
-my $repos = shift;\r
-my $txn = shift;\r
-\r
-unless (-e $repos)\r
- {\r
- &usage("$0: repository directory `$repos' does not exist.");\r
- }\r
-unless (-d $repos)\r
- {\r
- &usage("$0: repository directory `$repos' is not a directory.");\r
- }\r
-\r
-# Define two constant subroutines to stand for read-only or read-write\r
-# access to the repository.\r
-sub ACCESS_READ_ONLY () { 'read-only' }\r
-sub ACCESS_READ_WRITE () { 'read-write' }\r
-\r
-\r
-######################################################################\r
-# Harvest data using svnlook.\r
-\r
-# Change into /tmp so that svnlook diff can create its .svnlook\r
-# directory.\r
-my $tmp_dir = '/tmp';\r
-chdir($tmp_dir)\r
- or die "$0: cannot chdir `$tmp_dir': $!\n";\r
-\r
-# Figure out what files have added using svnlook.\r
-my @files_added;\r
-foreach my $line (&read_from_process($svnlook, 'changed', $repos, '-t', $txn))\r
- {\r
- # Add only files that were added to @files_added\r
- if ($line =~ /^A. (.*[^\/])$/)\r
- {\r
- push(@files_added, $1);\r
- }\r
- }\r
-\r
-my @errors;\r
-foreach my $path ( @files_added )\r
- {\r
- my $mime_type;\r
- my $eol_style;\r
-\r
- # Parse the complete list of property values of the file $path to extract\r
- # the mime-type and eol-style\r
- foreach my $prop (&read_from_process($svnlook, 'proplist', $repos, '-t',\r
- $txn, '--verbose', $path))\r
- {\r
- if ($prop =~ /^\s*svn:mime-type : (\S+)/)\r
- {\r
- $mime_type = $1;\r
- }\r
- elsif ($prop =~ /^\s*svn:eol-style : (\S+)/)\r
- {\r
- $eol_style = $1;\r
- }\r
- }\r
-\r
- # Detect error conditions and add them to @errors\r
- if (not $mime_type)\r
- {\r
- push @errors, "$path : svn:mime-type n'est pas defini";\r
- }\r
- elsif ($mime_type =~ /^text\// and not $eol_style)\r
- {\r
- push @errors, "$path : svn:eol-style n'est pas defini (svn:mime-type=$mime_type)";\r
- }\r
- }\r
-\r
-# If there are any errors list the problem files and give information\r
-# on how to avoid the problem. Hopefully people will set up auto-props\r
-# and will not see this verbose message more than once.\r
-if (@errors)\r
- {\r
- #warn "$0:\n\n",\r
- warn "-------------------------SIRHEN PRE COMMIT HOOK-------------------------\n\nListe des fichiers en erreurs:\n\t",\r
- join("\n\t", @errors), "\n\n",\r
- <<EOS;\r
-Explications:\r
-\tChaque fichier ajoute sur SVN doit posseder la propriete:\r
-\t\tsvn:mime-type\r
-\tDe plus, les fichiers textes doivent egalement posseder la propriete:\r
-\t\tsvn:eol-style\r
-\r
-Configuration de l'environnement:\r
-\tSi votre environnement de developpement SIRHEN est correctement configure,\r
-\tce message ne devrait jamais s'afficher. Dans le cas contraire, verifiez la\r
-\tconfiguration automatique des proprietes SVN dans le menu MyEclipse:\r
-\t\tWindow > Preferences > Team > SVN > Properties Configuration\r
-\r
-Commandes en ligne:\r
-\tPour les fichiers binaires:\r
-\t\tsvn propset svn:mime-type application/octet-stream path/of/file\r
-\r
-\tPour les fichiers textes:\r
-\t\tsvn propset svn:mime-type text/plain path/of/file\r
-\t\tsvn propset svn:eol-style native path/of/file\r
-\r
--------------------------SIRHEN PRE COMMIT HOOK-------------------------\r
-EOS\r
- exit 1;\r
- }\r
-else\r
- {\r
- exit 0;\r
- }\r
-\r
-sub usage\r
-{\r
- warn "@_\n" if @_;\r
- die "usage: $0 REPOS TXN-NAME\n";\r
-}\r
-\r
-sub safe_read_from_pipe\r
-{\r
- unless (@_)\r
- {\r
- croak "$0: safe_read_from_pipe passed no arguments.\n";\r
- }\r
- print "Running @_\n";\r
- my $pid = open(SAFE_READ, '-|');\r
- unless (defined $pid)\r
- {\r
- die "$0: cannot fork: $!\n";\r
- }\r
- unless ($pid)\r
- {\r
- open(STDERR, ">&STDOUT")\r
- or die "$0: cannot dup STDOUT: $!\n";\r
- exec(@_)\r
- or die "$0: cannot exec `@_': $!\n";\r
- }\r
- my @output;\r
- while (<SAFE_READ>)\r
- {\r
- chomp;\r
- push(@output, $_);\r
- }\r
- close(SAFE_READ);\r
- my $result = $?;\r
- my $exit = $result >> 8;\r
- my $signal = $result & 127;\r
- my $cd = $result & 128 ? "with core dump" : "";\r
- if ($signal or $cd)\r
- {\r
- warn "$0: pipe from `@_' failed $cd: exit=$exit signal=$signal\n";\r
- }\r
- if (wantarray)\r
- {\r
- return ($result, @output);\r
- }\r
- else\r
- {\r
- return $result;\r
- }\r
-}\r
-\r
-sub read_from_process\r
- {\r
- unless (@_)\r
- {\r
- croak "$0: read_from_process passed no arguments.\n";\r
- }\r
- my ($status, @output) = &safe_read_from_pipe(@_);\r
- if ($status)\r
- {\r
- if (@output)\r
- {\r
- die "$0: `@_' failed with this output:\n", join("\n", @output), "\n";\r
- }\r
- else\r
- {\r
- die "$0: `@_' failed with no output.\n";\r
- }\r
- }\r
- else\r
- {\r
- return @output;\r
- }\r
-}\r
+#!/usr/bin/env perl
+
+# ====================================================================
+# commit-mime-type-check.pl: check that every added file has the
+# svn:mime-type property set and every added file with a mime-type
+# matching text/* also has svn:eol-style set. If any file fails this
+# test the user is sent a verbose error message suggesting solutions and
+# the commit is aborted.
+#
+# Usage: commit-mime-type-check.pl REPOS TXN-NAME
+# ====================================================================
+# Most of commit-mime-type-check.pl was taken from
+# commit-access-control.pl, Revision 9986, 2004-06-14 16:29:22 -0400.
+# ====================================================================
+# Copyright (c) 2000-2004 CollabNet. All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://subversion.tigris.org/license.html.
+# If newer versions of this license are posted there, you may use a
+# newer version instead, at your option.
+#
+# This software consists of voluntary contributions made by many
+# individuals. For exact contribution history, see the revision
+# history and logs, available at http://subversion.tigris.org/.
+# ====================================================================
+
+# Turn on warnings the best way depending on the Perl version.
+BEGIN {
+ if ( $] >= 5.006_000)
+ { require warnings; import warnings; }
+ else
+ { $^W = 1; }
+}
+
+use strict;
+use Carp;
+
+
+######################################################################
+# Configuration section.
+
+# Svnlook path.
+my $svnlook = "/usr/bin/svnlook";
+
+# Since the path to svnlook depends upon the local installation
+# preferences, check that the required program exists to insure that
+# the administrator has set up the script properly.
+{
+ my $ok = 1;
+ foreach my $program ($svnlook)
+ {
+ if (-e $program)
+ {
+ unless (-x $program)
+ {
+ warn "$0: required program `$program' is not executable, ",
+ "edit $0.\n";
+ $ok = 0;
+ }
+ }
+ else
+ {
+ warn "$0: required program `$program' does not exist, edit $0.\n";
+ $ok = 0;
+ }
+ }
+ exit 1 unless $ok;
+}
+
+######################################################################
+# Initial setup/command-line handling.
+
+&usage unless @ARGV == 2;
+
+my $repos = shift;
+my $txn = shift;
+
+unless (-e $repos)
+ {
+ &usage("$0: repository directory `$repos' does not exist.");
+ }
+unless (-d $repos)
+ {
+ &usage("$0: repository directory `$repos' is not a directory.");
+ }
+
+# Define two constant subroutines to stand for read-only or read-write
+# access to the repository.
+sub ACCESS_READ_ONLY () { 'read-only' }
+sub ACCESS_READ_WRITE () { 'read-write' }
+
+
+######################################################################
+# Harvest data using svnlook.
+
+# Change into /tmp so that svnlook diff can create its .svnlook
+# directory.
+my $tmp_dir = '/tmp';
+chdir($tmp_dir)
+ or die "$0: cannot chdir `$tmp_dir': $!\n";
+
+# Figure out what files have added using svnlook.
+my @files_added;
+foreach my $line (&read_from_process($svnlook, 'changed', $repos, '-t', $txn))
+ {
+ # Add only files that were added to @files_added
+ if ($line =~ /^A. (.*[^\/])$/)
+ {
+ push(@files_added, $1);
+ }
+ }
+
+my @errors;
+foreach my $path ( @files_added )
+ {
+ my $mime_type;
+ my $eol_style;
+
+ # Parse the complete list of property values of the file $path to extract
+ # the mime-type and eol-style
+ foreach my $prop (&read_from_process($svnlook, 'proplist', $repos, '-t',
+ $txn, '--verbose', $path))
+ {
+ if ($prop =~ /^\s*svn:mime-type : (\S+)/)
+ {
+ $mime_type = $1;
+ }
+ elsif ($prop =~ /^\s*svn:eol-style : (\S+)/)
+ {
+ $eol_style = $1;
+ }
+ }
+
+ # Detect error conditions and add them to @errors
+ if (not $mime_type)
+ {
+ push @errors, "$path : svn:mime-type n'est pas defini";
+ }
+ elsif ($mime_type =~ /^text\// and not $eol_style)
+ {
+ push @errors, "$path : svn:eol-style n'est pas defini (svn:mime-type=$mime_type)";
+ }
+ }
+
+# If there are any errors list the problem files and give information
+# on how to avoid the problem. Hopefully people will set up auto-props
+# and will not see this verbose message more than once.
+if (@errors)
+ {
+ #warn "$0:\n\n",
+ warn "-------------------------SIRHEN PRE COMMIT HOOK-------------------------\n\nListe des fichiers en erreurs:\n\t",
+ join("\n\t", @errors), "\n\n",
+ <<EOS;
+Explications:
+\tChaque fichier ajoute sur SVN doit posseder la propriete:
+\t\tsvn:mime-type
+\tDe plus, les fichiers textes doivent egalement posseder la propriete:
+\t\tsvn:eol-style
+
+Configuration de l'environnement:
+\tSi votre environnement de developpement SIRHEN est correctement configure,
+\tce message ne devrait jamais s'afficher. Dans le cas contraire, verifiez la
+\tconfiguration automatique des proprietes SVN dans le menu MyEclipse:
+\t\tWindow > Preferences > Team > SVN > Properties Configuration
+
+Commandes en ligne:
+\tPour les fichiers binaires:
+\t\tsvn propset svn:mime-type application/octet-stream path/of/file
+
+\tPour les fichiers textes:
+\t\tsvn propset svn:mime-type text/plain path/of/file
+\t\tsvn propset svn:eol-style native path/of/file
+
+-------------------------SIRHEN PRE COMMIT HOOK-------------------------
+EOS
+ exit 1;
+ }
+else
+ {
+ exit 0;
+ }
+
+sub usage
+{
+ warn "@_\n" if @_;
+ die "usage: $0 REPOS TXN-NAME\n";
+}
+
+sub safe_read_from_pipe
+{
+ unless (@_)
+ {
+ croak "$0: safe_read_from_pipe passed no arguments.\n";
+ }
+ print "Running @_\n";
+ my $pid = open(SAFE_READ, '-|');
+ unless (defined $pid)
+ {
+ die "$0: cannot fork: $!\n";
+ }
+ unless ($pid)
+ {
+ open(STDERR, ">&STDOUT")
+ or die "$0: cannot dup STDOUT: $!\n";
+ exec(@_)
+ or die "$0: cannot exec `@_': $!\n";
+ }
+ my @output;
+ while (<SAFE_READ>)
+ {
+ chomp;
+ push(@output, $_);
+ }
+ close(SAFE_READ);
+ my $result = $?;
+ my $exit = $result >> 8;
+ my $signal = $result & 127;
+ my $cd = $result & 128 ? "with core dump" : "";
+ if ($signal or $cd)
+ {
+ warn "$0: pipe from `@_' failed $cd: exit=$exit signal=$signal\n";
+ }
+ if (wantarray)
+ {
+ return ($result, @output);
+ }
+ else
+ {
+ return $result;
+ }
+}
+
+sub read_from_process
+ {
+ unless (@_)
+ {
+ croak "$0: read_from_process passed no arguments.\n";
+ }
+ my ($status, @output) = &safe_read_from_pipe(@_);
+ if ($status)
+ {
+ if (@output)
+ {
+ die "$0: `@_' failed with this output:\n", join("\n", @output), "\n";
+ }
+ else
+ {
+ die "$0: `@_' failed with no output.\n";
+ }
+ }
+ else
+ {
+ return @output;
+ }
+}