svn_load_dirs.pl for Win32 (was RE: svn_dump_dirs problem)
From: Ian Brockbank <Ian.Brockbank_at_wolfsonmicro.com>
Date: 2004-04-28 13:21:04 CEST
Hi Jack (and everyone else),
I've now got svn_load_dirs.pl working on Windows.
I had to make the following changes:
Here's the patch. I've tested it on both Windows XP and Linux (with a
Index:
--- 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"; @@ -1411,6 +1415,7 @@ } # Start a child process safely without using /bin/sh. +my $openfork_available = "MSWin32" ne $^O; sub safe_read_from_pipe { unless (@_) @@ -1418,18 +1423,58 @@ 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"; + 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; + + 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 + { + 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>) { =================================================================== 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
---------------------------------------------------------------------
|
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.