Skip to contentSkip to conversation

send-email: use catfile() to concatenate files

PATCH In review Ævar Arnfjörð Bjarmason 3 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 send-email: use catfile() to concatenate files

Change send-email to use Perl's catfile() function instead of "$dir/$file". If send-email is given a $dir that ends with a / we'll end up printing a double slashed path like "dir//mtfnpy.patch".

This doesn't cause any problems since Perl's IO layer will handle it, but it looks ugly.

---
 git-send-email.perl |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
git-send-email.perl +2 -1
index 6dab3bf..7f702e3 100755
@@ -24,6 +24,7 @@ use Text::ParseWords;
 use Data::Dumper;
 use Term::ANSIColor;
 use File::Temp qw/ tempdir tempfile /;
+use File::Spec::Functions qw(catfile);
 use Error qw(:try);
 use Git;
 
@@ -511,7 +512,7 @@ while (defined(my $f = shift @ARGV)) {
 		opendir(DH,$f)
 			or die "Failed to opendir $f: $!";
 
-		push @files, grep { -f $_ } map { +$f . "/" . $_ }
+		push @files, grep { -f $_ } map { catfile($f, $_) }
 				sort readdir(DH);
 		closedir(DH);
 	} elsif ((-f $f or -p $f) and !check_file_rev_conflict($f)) {
Signature · 1 line
1.7.3.rc1.234.g8dc15
#1 lore raw
Quoted 8 lines · Ævar Arnfjörð Bjarmason

Change send-email to use Perl's catfile() function instead of "$dir/$file". If send-email is given a $dir that ends with a / we'll end up printing a double slashed path like "dir//mtfnpy.patch".

This doesn't cause any problems since Perl's IO layer will handle it, but it looks ugly.

If you mentioned in the proposed log message that File::Spec::Functions have been with us since Perl 5.6.1, it would have saved me (and others) some time worrying about the portability issues.

Quoted 26 lines
 git-send-email.perl |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
git-send-email.perl +2 -1
index 6dab3bf..7f702e3 100755
@@ -24,6 +24,7 @@ use Text::ParseWords;
 use Data::Dumper;
 use Term::ANSIColor;
 use File::Temp qw/ tempdir tempfile /;
+use File::Spec::Functions qw(catfile);
 use Error qw(:try);
 use Git;
 
@@ -511,7 +512,7 @@ while (defined(my $f = shift @ARGV)) {
 		opendir(DH,$f)
 			or die "Failed to opendir $f: $!";
 
-		push @files, grep { -f $_ } map { +$f . "/" . $_ }
+		push @files, grep { -f $_ } map { catfile($f, $_) }
 				sort readdir(DH);
 		closedir(DH);
 	} elsif ((-f $f or -p $f) and !check_file_rev_conflict($f)) {
Signature · 1 line
1.7.3.rc1.234.g8dc15
#2 lore raw
Quoted 6 lines · Junio C Hamano
Quoted 4 lines · Ævar Arnfjörð Bjarmason

Change send-email to use Perl's catfile() function instead of "$dir/$file". If send-email is given a $dir that ends with a / we'll end up printing a double slashed path like "dir//mtfnpy.patch".

Quoted 8 lines
Quoted 4 lines

This doesn't cause any problems since Perl's IO layer will handle it, but it looks ugly.

If you mentioned in the proposed log message that File::Spec::Functions have been with us since Perl 5.6.1, it would have saved me (and others) some time worrying about the portability issues.

I thought you might trust me to write portable code by default :)

Anyway, I forgot to mention it. But one can use the corelist(1) program to see when what modules appeared in perl core:

    $ corelist File::Spec::Functions
    File::Spec::Functions was first released with perl 5.00504
#3 lore raw
Quoted 16 lines · Ævar Arnfjörð Bjarmason
Quoted 6 lines · Junio C Hamano
Quoted 4 lines · Ævar Arnfjörð Bjarmason

Change send-email to use Perl's catfile() function instead of "$dir/$file". If send-email is given a $dir that ends with a / we'll end up printing a double slashed path like "dir//mtfnpy.patch".

Quoted 8 lines
Quoted 4 lines

This doesn't cause any problems since Perl's IO layer will handle it, but it looks ugly.

If you mentioned in the proposed log message that File::Spec::Functions have been with us since Perl 5.6.1, it would have saved me (and others) some time worrying about the portability issues.

Quoted 7 lines

I thought you might trust me to write portable code by default :)

Anyway, I forgot to mention it. But one can use the corelist(1) program to see when what modules appeared in perl core:

    $ corelist File::Spec::Functions
    File::Spec::Functions was first released with perl 5.00504

Also using File::Spec / File::Spec::Functions makes code more portable (with respect to things such as different directory separators, and volume portion of pathname) than using "$dir/$file".

Signature · 3 lines
Jakub Narebski
Poland
ShadeHawk on #git
#4 lore raw
Quoted 22 lines · Jakub Narebski
Quoted 21 lines · Ævar Arnfjörð Bjarmason
Quoted 6 lines · Junio C Hamano
Quoted 4 lines · Ævar Arnfjörð Bjarmason

Change send-email to use Perl's catfile() function instead of "$dir/$file". If send-email is given a $dir that ends with a / we'll end up printing a double slashed path like "dir//mtfnpy.patch".

Quoted 8 lines
Quoted 4 lines

This doesn't cause any problems since Perl's IO layer will handle it, but it looks ugly.

If you mentioned in the proposed log message that File::Spec::Functions have been with us since Perl 5.6.1, it would have saved me (and others) some time worrying about the portability issues.

I thought you might trust me to write portable code by default :)

Anyway, I forgot to mention it. But one can use the corelist(1) program to see when what modules appeared in perl core:

Quoted 6 lines
Quoted 2 lines
    $ corelist File::Spec::Functions
    File::Spec::Functions was first released with perl 5.00504

Also using File::Spec / File::Spec::Functions makes code more portable (with respect to things such as different directory separators, and volume portion of pathname) than using "$dir/$file".

Right, but perl mitigates that to some extent by converting Unix paths on-the-fly
to whatever the native platform uses. But of course that falls down in cases like Win32
volume labels.