Here's a new version of my patch:
1. The repository folder is now put in quotes too.
2. I was able to test the modified script successfully on Debian 4.0, so
it should be working for everybody with these changes.
Can someone please verify my result? - Thanks.
Also a correction to the batch file excerpt:
Please remove the quotes from the % arguments as Subversion already
provides quotes when there are white spaces in the names.
I recognized that an old draft of my first posting was send to this
list. Please ignore it and sorry for the inconvenience.
Matthias "Maddes" Bücher
On 15.08.2007 01:26, Maddes wrote:
> 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
> which then led me to the following two pages
> 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
> 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
> 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
> echo. 1>&2
> REM *** All checks done
> echo All checks done. RC=%RC_ALL% 1>&2
> exit %RC_ALL%
--- check-mime-type.pl (revision 8)
+++ check-mime-type.pl (working copy)
@@ -102,7 +102,7 @@
# Figure out what files have added using svnlook.
-foreach my $line (&read_from_process($svnlook, 'changed', $repos, '-t', $txn))
+foreach my $line (&read_from_process($svnlook, 'changed', '"' . $repos . '"', '-t', $txn)) # Windows: files/pathes with spaces have to be put in quotes
# Add only files that were added to @files_added
if ($line =~ /^A. (.*[^\/])$/)
@@ -112,15 +112,15 @@
-foreach my $path ( @files_added )
+foreach my $path ( @files_added )
# 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/pathes 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");
@@ -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 @@
+ # child
or die "$0: cannot dup STDOUT: $!\n";
or die "$0: cannot exec `@_': $!\n";
+ # 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;
+ push(@commandline, "--file");
+ push(@commandline, $tmpfile);
+ 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
To unsubscribe, e-mail: firstname.lastname@example.org
For additional commands, e-mail: email@example.com
Received on Wed Aug 15 23:47:28 2007