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

Re: [PATCH] check-mime-type.pl on Windows

From: Maddes <maddes_svnlists_at_arcor.de>
Date: 2007-08-15 23:49:44 CEST

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.

Regards
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
> 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 8)
+++ check-mime-type.pl (working copy)
@@ -102,7 +102,7 @@
 
 # Figure out what files have added using svnlook.
 my @files_added;
-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 @@
   }
 
 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/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");
 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 23:47:28 2007

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