[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

check-mime-type.pl on Windows

From: Maddes <maddes_svnlists_at_arcor.de>
Date: 2007-08-15 01:26:27 CEST

Hello everybody,

when you try to use check-mime-type.pl on Windows, you unfortunately get
errors like "svnlook ... failed with no output".

By searching for similar errors I came across
http://svn.haxx.se/users/archive-2004-04/1280.shtml
which then led me to the following two pages
http://perldoc.perl.org/perlport.html#Interprocess-Communication-(IPC)
http://perldoc.perl.org/perlport.html#PLATFORMS

According to the PerlPort doc I see these script problems as a
bug/shortcoming of those scripts.
I would like to see that the most common hook scripts are written in an
OS-independent way, or at least take care of OS-specialities like pipes.
Subversion is a cross-platform Version Control System and not every new
user is used to Perl/Python to adopt the scripts to their OS.

Maybe a standardized "safe_read_from_pipe" Perl sub can be developed,
that works for all Subversion target systems.
Does anyone agree on this? Or I'm the only one using hook scripts on
Windows/Non-Unix/Non-Linux?

As I do not want to only "complain" but also to contribute, I tried and
was able to make the script work on my Windows XP SP2 with the
information from the above URLs.
The resulting patch is attached to this mail.

I hope that this patch can be tested on/reviewed for other OSes and get
into the official script posted in the "Tools & Contrib" section.

For the people interested in how to implement a this hook script on
Windows [XP], here are the important lines of my pre-commit.bat for
check-mime-type.pl:

set RC_ALL=0

...

REM *** Check MIME types
D:\Repositories\SVN\_Scripts\check-mime-type.pl "%1" "%2"
if not errorlevel 1 goto check_mime_ok
set /A RC_ALL+=1
:check_mime_ok
echo. 1>&2

...

REM *** All checks done
echo All checks done. RC=%RC_ALL% 1>&2

exit %RC_ALL%

Regards
Maddes

Index: check-mime-type.pl
===================================================================
--- check-mime-type.pl (revision 6)
+++ check-mime-type.pl (working copy)
@@ -112,15 +112,15 @@
   }
 
 my @errors;
-foreach my $path ( @files_added )
+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))
+ foreach my $prop (&read_from_process($svnlook, 'proplist', $repos, '-t',
+ $txn, '--verbose', '"' . $path . '"')) # Windows: files with spaces have to be put in quotes
                         {
                                 if ($prop =~ /^\s*svn:mime-type : (\S+)/)
                                         {
@@ -180,6 +180,10 @@
   die "usage: $0 REPOS TXN-NAME\n";
 }
 
+# Windows/DOS: can not use openforks ('-|')
+# see http://perldoc.perl.org/perlport.html#Interprocess-Communication-(IPC)
+# see http://perldoc.perl.org/perlport.html#PLATFORMS
+my $openfork_available = ($^O ne "MSWin32") && ($^O ne "dos");
 sub safe_read_from_pipe
 {
   unless (@_)
@@ -187,6 +191,8 @@
       croak "$0: safe_read_from_pipe passed no arguments.\n";
     }
   print "Running @_\n";
+ if ($openfork_available)
+ {
   my $pid = open(SAFE_READ, '-|');
   unless (defined $pid)
     {
@@ -194,11 +200,48 @@
     }
   unless ($pid)
     {
+ # child
       open(STDERR, ">&STDOUT")
         or die "$0: cannot dup STDOUT: $!\n";
       exec(@_)
         or die "$0: cannot exec `@_': $!\n";
     }
+ }
+ else
+ {
+ # Redirect the comment into a temp file and use that to work around
+ # Windoze's (non-)handling of multi-line commands.
+ my @commandline = ();
+ my $command;
+
+ while ($command = shift)
+ {
+ if ("-m" eq $command)
+ {
+ my $comment = shift;
+ my ($handle, $tmpfile) = tempfile( DIR => $tmp_dir);
+ print $handle $comment;
+ close($handle);
+
+ push(@commandline, "--file");
+ push(@commandline, $tmpfile);
+ }
+ else
+ {
+ if ($command =~ m"\n")
+ {
+ warn "$0: carriage return detected in command - may not work\n";
+ }
+ push(@commandline, $command);
+ }
+ }
+
+ # Now do the pipe.
+ open(SAFE_READ, "@commandline |")
+ or die "$0: cannot pipe to command: $!\n";
+ }
+
+ # parent
   my @output;
   while (<SAFE_READ>)
     {

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Wed Aug 15 01:24:25 2007

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.