[PATCH] send-email: recognize absolute path on Windows

Subsystems: the rest

DORMANTno replies

4 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] send-email: recognize absolute path on Windows

From: Erik Faye-Lund <hidden>
Date: 2016-06-15 23:00:42

From: Erik Faye-Lund <redacted>

On Windows, absolute paths might start with a DOS drive prefix,
which this check fails to recognize.

Unfortunately, we cannot simply use the file_name_is_absolute
helper in File::Spec::Functions, because Git for Windows has an
MSYS-based Perl, where this helper doesn't grok DOS
drive-prefixes.

So let's manually check for these in that case, and fall back to
the File::Spec-helper on other platforms (e.g Win32 with native
Perl)

Signed-off-by: Erik Faye-Lund <redacted>
---

Here's a patch that we've been running with a variation of in
Git for Windows for a while. That version wasn't quite palatable,
as it recognized DOS drive-prefixes on all platforms.

 git-send-email.perl | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index fdb0029..c4d85a7 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1113,6 +1113,18 @@ sub ssl_verify_params {
 	}
 }
 
+sub file_name_is_absolute {
+	my ($path) = @_;
+
+	# msys does not grok DOS drive-prefixes
+	if ($^O eq 'msys') {
+		return ($path =~ m#^/# || $path =~ m#[a-zA-Z]\:#)
+	}
+
+	require File::Spec::Functions;
+	return File::Spec::Functions::file_name_is_absolute($path);
+}
+
 # Returns 1 if the message was sent, and 0 otherwise.
 # In actuality, the whole program dies when there
 # is an error sending a message.
@@ -1197,7 +1209,7 @@ X-Mailer: git-send-email $gitversion
 
 	if ($dry_run) {
 		# We don't want to send the email.
-	} elsif ($smtp_server =~ m#^/#) {
+	} elsif (file_name_is_absolute($smtp_server)) {
 		my $pid = open my $sm, '|-';
 		defined $pid or die $!;
 		if (!$pid) {
-- 
1.9.0.msysgit.0

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: [PATCH] send-email: recognize absolute path on Windows

From: Johannes Sixt <hidden>
Date: 2016-06-15 23:00:42

Am 4/15/2014 10:44, schrieb Erik Faye-Lund:
From: Erik Faye-Lund <redacted>

On Windows, absolute paths might start with a DOS drive prefix,
which this check fails to recognize.

Unfortunately, we cannot simply use the file_name_is_absolute
helper in File::Spec::Functions, because Git for Windows has an
MSYS-based Perl, where this helper doesn't grok DOS
drive-prefixes.

So let's manually check for these in that case, and fall back to
the File::Spec-helper on other platforms (e.g Win32 with native
Perl)

Signed-off-by: Erik Faye-Lund <redacted>
---

Here's a patch that we've been running with a variation of in
Git for Windows for a while. That version wasn't quite palatable,
as it recognized DOS drive-prefixes on all platforms.
Did you consider patching msysgit's lib/perl5/5.8.8/File/Spec.pm by
inserting a line "msys => 'Win32'," near the top of the file; it is the
hash table that decides which path "style" is selected depending on $^O.
Then File::Spec->file_name_is_absolute($path) could be used without a wrapper.
quoted hunk
 git-send-email.perl | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index fdb0029..c4d85a7 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1113,6 +1113,18 @@ sub ssl_verify_params {
 	}
 }
 
+sub file_name_is_absolute {
+	my ($path) = @_;
+
+	# msys does not grok DOS drive-prefixes
+	if ($^O eq 'msys') {
+		return ($path =~ m#^/# || $path =~ m#[a-zA-Z]\:#)
+	}
+
+	require File::Spec::Functions;
+	return File::Spec::Functions::file_name_is_absolute($path);
+}
+
 # Returns 1 if the message was sent, and 0 otherwise.
 # In actuality, the whole program dies when there
 # is an error sending a message.
@@ -1197,7 +1209,7 @@ X-Mailer: git-send-email $gitversion
 
 	if ($dry_run) {
 		# We don't want to send the email.
-	} elsif ($smtp_server =~ m#^/#) {
+	} elsif (file_name_is_absolute($smtp_server)) {
 		my $pid = open my $sm, '|-';
 		defined $pid or die $!;
 		if (!$pid) {
There's another instance in the non-$quiet code path around line 1275 that
needs the same treatment.

-- Hannes

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: [PATCH] send-email: recognize absolute path on Windows

From: Erik Faye-Lund <hidden>
Date: 2016-06-15 23:00:42

On Tue, Apr 15, 2014 at 12:32 PM, Johannes Sixt [off-list ref] wrote:
Am 4/15/2014 10:44, schrieb Erik Faye-Lund:
quoted
From: Erik Faye-Lund <redacted>

On Windows, absolute paths might start with a DOS drive prefix,
which this check fails to recognize.

Unfortunately, we cannot simply use the file_name_is_absolute
helper in File::Spec::Functions, because Git for Windows has an
MSYS-based Perl, where this helper doesn't grok DOS
drive-prefixes.

So let's manually check for these in that case, and fall back to
the File::Spec-helper on other platforms (e.g Win32 with native
Perl)

Signed-off-by: Erik Faye-Lund <redacted>
---

Here's a patch that we've been running with a variation of in
Git for Windows for a while. That version wasn't quite palatable,
as it recognized DOS drive-prefixes on all platforms.
Did you consider patching msysgit's lib/perl5/5.8.8/File/Spec.pm by
inserting a line "msys => 'Win32'," near the top of the file; it is the
hash table that decides which path "style" is selected depending on $^O.
Then File::Spec->file_name_is_absolute($path) could be used without a wrapper.
I did not, but that works, and is IMO much nicer. Thanks for the idea!
quoted
 git-send-email.perl | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index fdb0029..c4d85a7 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1113,6 +1113,18 @@ sub ssl_verify_params {
      }
 }

+sub file_name_is_absolute {
+     my ($path) = @_;
+
+     # msys does not grok DOS drive-prefixes
+     if ($^O eq 'msys') {
+             return ($path =~ m#^/# || $path =~ m#[a-zA-Z]\:#)
+     }
+
+     require File::Spec::Functions;
+     return File::Spec::Functions::file_name_is_absolute($path);
+}
+
 # Returns 1 if the message was sent, and 0 otherwise.
 # In actuality, the whole program dies when there
 # is an error sending a message.
@@ -1197,7 +1209,7 @@ X-Mailer: git-send-email $gitversion

      if ($dry_run) {
              # We don't want to send the email.
-     } elsif ($smtp_server =~ m#^/#) {
+     } elsif (file_name_is_absolute($smtp_server)) {
              my $pid = open my $sm, '|-';
              defined $pid or die $!;
              if (!$pid) {
There's another instance in the non-$quiet code path around line 1275 that
needs the same treatment.
Good catch, thanks!

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: [PATCH] send-email: recognize absolute path on Windows

From: Erik Faye-Lund <hidden>
Date: 2016-06-15 23:00:42

On Tue, Apr 15, 2014 at 12:42 PM, Erik Faye-Lund [off-list ref] wrote:
On Tue, Apr 15, 2014 at 12:32 PM, Johannes Sixt [off-list ref] wrote:
quoted
Am 4/15/2014 10:44, schrieb Erik Faye-Lund:
quoted
From: Erik Faye-Lund <redacted>

On Windows, absolute paths might start with a DOS drive prefix,
which this check fails to recognize.

Unfortunately, we cannot simply use the file_name_is_absolute
helper in File::Spec::Functions, because Git for Windows has an
MSYS-based Perl, where this helper doesn't grok DOS
drive-prefixes.

So let's manually check for these in that case, and fall back to
the File::Spec-helper on other platforms (e.g Win32 with native
Perl)

Signed-off-by: Erik Faye-Lund <redacted>
---

Here's a patch that we've been running with a variation of in
Git for Windows for a while. That version wasn't quite palatable,
as it recognized DOS drive-prefixes on all platforms.
Did you consider patching msysgit's lib/perl5/5.8.8/File/Spec.pm by
inserting a line "msys => 'Win32'," near the top of the file; it is the
hash table that decides which path "style" is selected depending on $^O.
Then File::Spec->file_name_is_absolute($path) could be used without a wrapper.
I did not, but that works, and is IMO much nicer. Thanks for the idea!
Actually, after having tried that, other stuff starts to break... So
back to the drawing-board.

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help