You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Ian Brockbank <Ia...@wolfsonmicro.com> on 2004/05/03 10:38:05 UTC
[PATCH] svn_load_dirs.pl patch for Win32
Hi,
As I posted on the users list, I had to make a few modifications to get
svn_load_dirs.pl working on Windows XP (with ActivePerl 5.8). Here's
the patch:
Log message:
Get svn_load_dirs.pl working on Windows. This required the following
changes:
* open(HANDLE, "-|"); doesn't work on Windows. I replaced it with
open(HANDLE, "@commandline |"); on Windows ($^O eq "MSWin32").
* Windows chokes on the multi-line commands. This is caused by
comments and (potentially) properties.
I write these to a temporary file and use --file instead of -m.
* Windows does some processing of the command line so the script
needs to deal with this.
* Windows doesn't define TMPDIR by default. It does define TEMP,
so I use that if TMPDIR isn't found.
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_dirs.
pl.in (revision 9503)
+++
http://svn.collab.net/repos/svn/trunk/contrib/client-side/svn_load_dirs.
pl.in (working copy)
@@ -14,7 +14,7 @@
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;
@@ -341,6 +341,10 @@
# Create a temporary directory for svn to work in.
my $temp_dir = $ENV{TMPDIR};
unless (defined $temp_dir and length $temp_dir) {
+ # Try the Windows standard environment variable
+ $temp_dir = $ENV{TEMP};
+}
+unless (defined $temp_dir and length $temp_dir) {
$temp_dir = '/tmp';
}
my $temp_template = "$temp_dir/svn_load_dirs_XXXXXXXXXX";
@@ -1133,11 +1137,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 +1421,74 @@
}
# Start a child process safely without using /bin/sh.
+my $openfork_available = "MSWin32" ne $^O;
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>)
{
===================================================================
Cheers,
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
Wolfson Microelectronics plc
www.wolfsonmicro.com
T +44 131 272 7000
F +44 131 272 7001
Registered in Scotland 89839
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH] svn_load_dirs.pl patch for Win32
Posted by Branko Čibej <br...@xbc.nu>.
Ian Brockbank wrote:
>Hi,
>
>As I posted on the users list, I had to make a few modifications to get
>svn_load_dirs.pl working on Windows XP (with ActivePerl 5.8). Here's
>the patch:
>
>
>Log message:
>
>Get svn_load_dirs.pl working on Windows. This required the following
>changes:
>
> * open(HANDLE, "-|"); doesn't work on Windows. I replaced it with
> open(HANDLE, "@commandline |"); on Windows ($^O eq "MSWin32").
> * Windows chokes on the multi-line commands. This is caused by
> comments and (potentially) properties.
> I write these to a temporary file and use --file instead of -m.
> * Windows does some processing of the command line so the script
> needs to deal with this.
> * Windows doesn't define TMPDIR by default. It does define TEMP,
> so I use that if TMPDIR isn't found.
>
>
Would it be very hard to reformat this log message so that it conforms
to the rules set out in the HACKING file?
-- Brane
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH] svn_load_dirs.pl patch for Win32
Posted by Michael W Thelen <th...@cs.utah.edu>.
* Ian Brockbank <Ia...@wolfsonmicro.com> [2004-05-03 08:43]:
> As I posted on the users list, I had to make a few modifications to get
> svn_load_dirs.pl working on Windows XP (with ActivePerl 5.8). Here's
> the patch:
I've filed this patch as issue 1892:
http://subversion.tigris.org/issues/show_bug.cgi?id=1892
-- Mike
--
Michael W. Thelen
I am returning this otherwise good typing paper to you because someone has
printed gibberish all over it and put your name at the top.
-- an English professor, Ohio University
Re: [PATCH] svn_load_dirs.pl patch for Win32
Posted by Ben Reser <be...@reser.org>.
On Mon, May 03, 2004 at 11:38:05AM +0100, Ian Brockbank wrote:
> # Create a temporary directory for svn to work in.
> my $temp_dir = $ENV{TMPDIR};
> unless (defined $temp_dir and length $temp_dir) {
> + # Try the Windows standard environment variable
> + $temp_dir = $ENV{TEMP};
> +}
> +unless (defined $temp_dir and length $temp_dir) {
> $temp_dir = '/tmp';
> }
I'd prefer that we ditch this code entirely and ...
> + # 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);
use TMPDIR => 1 instead of DIR => $temp_dir. Doing this causes
File::Temp to figure out the temp directory for us using File::Spec.
Considering that File::Spec contains implementations for a variety of
platforms not just Windows and Unix, this would end up being a lot more
portable...
--
Ben Reser <be...@reser.org>
http://ben.reser.org
"Conscience is the inner voice which warns us somebody may be looking."
- H.L. Mencken
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org