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

[PATCH] commit-email.pl : rewrite 'safe_read_from_pipe' for Windows

From: Michael Wallendahl <mwallend_at_spikus.com>
Date: 2005-01-27 09:27:47 CET

Attached is an updated 'safe_read_from_pipe' subroutine that also runs
on Windows machines.

Would appreciate any feedback,

Thanks,

-Mike

Work on making commit-email.pl friendlier to Windows systems.

* tools/hook-scripts/commit-email.pl.in
  (safe_read_from_pipe): Reworked the 'safe_read_from_pipe' subroutine
  so that it does not attempt to fork on Windows systems. Under Windows
  the subroutine also munges the command to work better with the command
  interpreter. Adds $openfork_available, @commandline, and $command.
  Based upon code from contrib/client-side/svn_load_dirs.pl submitted by
  Ian Brockbank.

Index: commit-email.pl.in
===================================================================
--- commit-email.pl.in (revision 12864)
+++ commit-email.pl.in (working copy)
@@ -542,17 +542,43 @@
       croak "$0: safe_read_from_pipe passed no arguments.\n";
     }
 
- my $pid = open(SAFE_READ, '-|');
- unless (defined $pid)
+ my $openfork_available = "MSWin32" ne $^O;
+ if ($openfork_available) # We can fork on this system.
     {
- die "$0: cannot fork: $!\n";
+ my $pid = open(SAFE_READ, "-|");
+ unless (defined $pid)
+ {
+ die "$0: cannot fork: $!\n";
+ }
+ unless ($pid)
+ {
+ open(STDERR, ">&STDOUT")
+ or die "$0: cannot dup STDOUT: $!\n";
+ exec(@_)
+ or die "$0: cannot exec '@_': $!\n";
+ }
     }
- unless ($pid)
+ else # Running on Windows. No fork.
     {
- open(STDERR, ">&STDOUT")
- or die "$0: cannot dup STDOUT: $!\n";
- exec(@_)
- or die "$0: cannot exec `@_': $!\n";
+ my @commandline = ();
+ my $command;
+
+ while ($command = shift)
+ {
+ # Munge the command to protect it from the command line
+ $command =~ s/\"/\\\"/g; # Replace all " with \"
+ 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);
+ }
+
+ # Now do the pipe.
+ open(SAFE_READ, "@commandline |")
+ or die "$0: cannot pipe to command: $!\n";
     }
   my @output;
   while (<SAFE_READ>)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Jan 27 09:33:27 2005

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.