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

RE: Re: [PATCH] svn_load_dirs.pl patch for Win32

From: Ian Brockbank <Ian.Brockbank_at_wolfsonmicro.com>
Date: 2004-05-19 13:39:58 CEST

Most odd. I'm sure it ran, but indeed it fails now. I must have picked
up a different copy somehow without noticing.

Here's another patch which uses English and definitely runs and does my
(pretty simple) test import (I have triple-checked I was running the
right thing).

Log message:

Get svn_load_dirs.pl working on Windows.

   * svn_load_dirs.pl.in
     (main code, setting up $temp_dir): Use TMPDIR => 1 in call
     to tempdir to pick up the system temporary directory portably.

     (main code, processing properties): Windows chokes on
     multi-line commands, caused (potentially) by properties.
     Write to a temporary file and use --file instead of passing
     the value. This also requires use of File::Temp::tempfile().

     (safe_read_from_pipe): open(HANDLE, "-|"); doesn't work on
     Windows. Replaced it with open(HANDLE, "@commandline |"); on
     Windows. This also necessitates pre-processing the command
     line to protect it from the Windows shell, and passing
     comments via a temporary file using --file instead of -m.

Patch:
Index:
http://svn.collab.net/repos/svn/trunk/contrib/client-side/svn_load_dirs.
pl.in
===================================================================
---http://svn.collab.net/repos/svn/trunk/contrib/client-side/svn_load_di
rs.pl.in (revision 9503)
+++http://svn.collab.net/repos/svn/trunk/contrib/client-side/svn_load_di
rs.pl.in (working copy)
@@ -14,10 +14,11 @@
 use File::Copy 2.03;
 use File::Find;
 use File::Path 1.0404;
-use File::Temp 0.12 qw(tempdir);
+use File::Temp 0.12 qw(tempdir tempfile);
 use Getopt::Long 2.25;
 use Text::Wrap;
 use URI 1.17;
+use English;
 
 $Text::Wrap::columns = 72;
 
@@ -339,12 +340,7 @@
   }
 
 # Create a temporary directory for svn to work in.
-my $temp_dir = $ENV{TMPDIR};
-unless (defined $temp_dir and length $temp_dir) {
- $temp_dir = '/tmp';
-}
-my $temp_template = "$temp_dir/svn_load_dirs_XXXXXXXXXX";
-$temp_dir = tempdir($temp_template);
+my $temp_dir = tempdir( "svn_load_dirs_XXXXXXXXXX", TMPDIR => 1 );
 
 # Put in a signal handler to clean up any temporary directories.
 sub catch_signal {
@@ -1133,11 +1129,17 @@
                   {
                     @diff_ignore_space_changes = ('-b');
                   }
+
+ # Write the value to a temporary file in case it's
multi-line
+ my ($handle, $tmpfile) = tempfile(DIR => $temp_dir);
+ print $handle $property_value;
+ close($handle);
 
                 read_from_process($svn,
                                   'propset',
                                   $property_name,
- $property_value,
+ '--file',
+ $tmpfile,
                                   $add_file);
               }
           }
@@ -1411,25 +1413,74 @@
 }
 
 # Start a child process safely without using /bin/sh.
+my $openfork_available = "MSWin32" ne $OSNAME;
 sub safe_read_from_pipe
 {
   unless (@_)
     {
       croak "$0: safe_read_from_pipe $INCORRECT_NUMBER_OF_ARGS";
     }
- print "Running @_\n";
- my $pid = open(SAFE_READ, '-|');
- unless (defined $pid)
+
+ if ($openfork_available)
     {
- die "$0: cannot fork: $!\n";
+ print "Running @_\n";
+ my $pid = open(SAFE_READ, "-|");
+ unless (defined $pid)
+ {
+ die "$0: cannot fork: $!\n";
+ }
+ unless ($pid)
+ {
+ # child
+ open(STDERR, ">&STDOUT")
+ or die "$0: cannot dup STDOUT: $!\n";
+ exec(@_)
+ or die "$0: cannot exec '@_': $!\n";
+ }
     }
- unless ($pid)
+ else
     {
- open(STDERR, ">&STDOUT")
- or die "$0: cannot dup STDOUT: $!\n";
- exec(@_)
- 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;
+ my $comment;
+
+ while ($command = shift)
+ {
+ if ("-m" eq $command)
+ {
+ my $comment = shift;
+ my ($handle, $tmpfile) = tempfile(DIR => $temp_dir);
+ print $handle $comment;
+ close($handle);
+
+ push(@commandline, "--file");
+ push(@commandline, $tmpfile);
+ }
+ else
+ {
+ # Munge the command to protect it from the command line
+ $command =~ s/\"/\\\"/g;
+ if ($command =~ m"\s") { $command = "\"$command\""; }
+ if ($command eq "") { $command = "\"\""; }
+ if ($command =~ m"\n")
+ {
+ warn "$0: carriage return detected in command - may
not work\n";
+ }
+ push(@commandline, $command);
+ }
+ }
+
+ print "Running @commandline\n";
+ if ( $comment ) { print $comment; }
+
+ # Now do the pipe.
+ open(SAFE_READ, "@commandline |")
+ or die "$0: cannot pipe to command: $!\n";
+ }
+
+ # parent
   my @output;
   while (<SAFE_READ>)
     {

Ian Brockbank
Senior Applications Software Engineer
e: ian.brockbank@wolfsonmicro.com / apps@wolfsonmicro.com
scd: ian@scottishdance.net
t: +44 131 272 7145
f: +44 131 272 7001
  

 

> -----Original Message-----
> From: Michael W Thelen [mailto:thelenm@cs.utah.edu]
> Sent: 18 May 2004 17:11
> To: dev@subversion.tigris.org
> Subject: Re: [PATCH] svn_load_dirs.pl patch for Win32
>
> * Ian Brockbank <Ian.Brockbank@wolfsonmicro.com> [2004-05-18 09:57]:
> > > The short of it: Ian Brockbank created a patch for
> svn_load_dirs.pl
> > > which allows it to run on the Win32 platform. I have
> just applied the
> > > patch, and I would like to report that it works perfectly.
> > > Only had to
> > > replace $OSNAME with $^O. Perl was complaining that
> $OSNAME had to be
> > > prefixed with a package name, and I didn't know which one to use.
> >
> > Thanks! Interesting about $OSNAME - it works fine for me.
> However, I
> > originally wrote it with $^O and then changed it to $OSNAME
> for better
> > readability. I'm happy to change it back.
>
> $OSNAME should work fine if the program uses the English
> module (but it
> doesn't look like it does). Without using English, it shouldn't even
> make it past compilation, since svn_load_dirs.pl also uses strict.
>
> -- Mike
>
> --
> Michael W. Thelen
> Nostalgia isn't what it used to be.
> -- Peter DeVries
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed May 19 13:40:18 2004

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

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