git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/8] various perl fixes
@ 2018-02-14 22:21 Ævar Arnfjörð Bjarmason
  2018-02-14 22:21 ` [PATCH 1/8] perl: *.pm files should not have the executable bit Ævar Arnfjörð Bjarmason
                   ` (21 more replies)
  0 siblings, 22 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-14 22:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep, Ævar Arnfjörð Bjarmason

I'd been meaning to submit 3/* once my Makefile.PL removal landed in
master, but noticed a few more things along the way, including the
issue fixed in 1/* which I just noted in
<CACBZZX7xC37W5+MLtYSrBaPawh+QfOSqci_rFOp_ukVi4fp6Gg@mail.gmail.com>,
and while I was at it resolved some of my long-standing TODOs noted in
<87d13jd4fd.fsf@evledraar.gmail.com>, and more.

If you're CC'd on this series it's because one of the commit messages
mentions a commit you authored.

[45]/* do not cleanly pass the default --check, so they have
.gitattributes files to make them pass, as noted in 4/* it's much
easier if we can just use this upstream code as-is, and not accumulate
our own typo/whitespace etc. fixes along the way, which just makes
subsequent updates harder.

Ævar Arnfjörð Bjarmason (8):
  perl: *.pm files should not have the executable bit
  perl: move CPAN loader wrappers to another namespace
  perl: generalize the Git::LoadCPAN facility
  perl: update our ancient copy of Error.pm
  perl: update our copy of Mail::Address
  git-send-email: unconditionally use Net::{SMTP,Domain}
  gitweb: hard-depend on the Digest::MD5 5.8 module
  perl: hard-depend on the File::{Temp,Spec} modules

 contrib/examples/git-difftool.perl    |   2 +-
 git-send-email.perl                   |  28 +--
 gitweb/INSTALL                        |   3 +-
 gitweb/gitweb.perl                    |  17 +-
 perl/Git.pm                           |   7 +-
 perl/Git/Error.pm                     |  46 ----
 perl/Git/FromCPAN/.gitattributes      |   1 +
 perl/Git/FromCPAN/Error.pm            | 296 +++++++++++++++++++----
 perl/Git/FromCPAN/Mail/.gitattributes |   1 +
 perl/Git/FromCPAN/Mail/Address.pm     | 436 +++++++++++++---------------------
 perl/Git/LoadCPAN.pm                  |  74 ++++++
 perl/Git/LoadCPAN/Error.pm            |  10 +
 perl/Git/LoadCPAN/Mail/Address.pm     |  10 +
 perl/Git/Mail/Address.pm              |  24 --
 14 files changed, 537 insertions(+), 418 deletions(-)
 delete mode 100644 perl/Git/Error.pm
 create mode 100644 perl/Git/FromCPAN/.gitattributes
 create mode 100644 perl/Git/FromCPAN/Mail/.gitattributes
 create mode 100644 perl/Git/LoadCPAN.pm
 create mode 100644 perl/Git/LoadCPAN/Error.pm
 create mode 100644 perl/Git/LoadCPAN/Mail/Address.pm
 delete mode 100755 perl/Git/Mail/Address.pm

-- 
2.15.1.424.g9478a66081


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 1/8] perl: *.pm files should not have the executable bit
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
@ 2018-02-14 22:21 ` Ævar Arnfjörð Bjarmason
  2018-02-14 22:41   ` Jonathan Nieder
  2018-02-14 22:21 ` [PATCH 2/8] perl: move CPAN loader wrappers to another namespace Ævar Arnfjörð Bjarmason
                   ` (20 subsequent siblings)
  21 siblings, 1 reply; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-14 22:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep, Ævar Arnfjörð Bjarmason

The Git::Mail::Address file added in bd869f67b9 ("send-email: add and
use a local copy of Mail::Address", 2018-01-05) had the executable bit
set, this should not be the case with *.pm files, it breaks nothing,
but is redundant and confusing as none of the other files have it, and
it's never executed as a stand-alone program.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git/Mail/Address.pm | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 mode change 100755 => 100644 perl/Git/Mail/Address.pm

diff --git a/perl/Git/Mail/Address.pm b/perl/Git/Mail/Address.pm
old mode 100755
new mode 100644
-- 
2.15.1.424.g9478a66081


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 2/8] perl: move CPAN loader wrappers to another namespace
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
  2018-02-14 22:21 ` [PATCH 1/8] perl: *.pm files should not have the executable bit Ævar Arnfjörð Bjarmason
@ 2018-02-14 22:21 ` Ævar Arnfjörð Bjarmason
  2018-02-14 22:43   ` Jonathan Nieder
  2018-02-14 22:21 ` [PATCH 3/8] perl: generalize the Git::LoadCPAN facility Ævar Arnfjörð Bjarmason
                   ` (19 subsequent siblings)
  21 siblings, 1 reply; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-14 22:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep, Ævar Arnfjörð Bjarmason

Move the Git::Error and Git::Mail::Address wrappers to the
Git::LoadCPAN::Loader::* namespace, e.g. Git::LoadCPAN::Error, that
module will then either load Error from CPAN (if installed on the OS),
or use Git::FromCPAN::Error.

When I added the Error wrapper in 20d2a30f8f ("Makefile: replace
perl/Makefile.PL with simple make rules", 2017-12-10) I didn't think
about how confusing it would be to have these modules sitting in the
same tree as our normal modules. Let's put these all into
Git::{Load,From}CPAN::* to clearly distinguish them from the rest.

This also makes things a bit less confusing since there was already a
Git::Error namespace ever since 8b9150e3e3 ("Git.pm: Handle failed
commands' output", 2006-06-24).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 contrib/examples/git-difftool.perl      | 2 +-
 git-send-email.perl                     | 4 ++--
 perl/Git.pm                             | 2 +-
 perl/Git/{ => LoadCPAN}/Error.pm        | 8 ++++----
 perl/Git/{ => LoadCPAN}/Mail/Address.pm | 4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)
 rename perl/Git/{ => LoadCPAN}/Error.pm (78%)
 rename perl/Git/{ => LoadCPAN}/Mail/Address.pm (69%)

diff --git a/contrib/examples/git-difftool.perl b/contrib/examples/git-difftool.perl
index fb0fd0b84b..b2ea80f9ed 100755
--- a/contrib/examples/git-difftool.perl
+++ b/contrib/examples/git-difftool.perl
@@ -13,7 +13,7 @@
 use 5.008;
 use strict;
 use warnings;
-use Git::Error qw(:try);
+use Git::LoadCPAN::Error qw(:try);
 use File::Basename qw(dirname);
 use File::Copy;
 use File::Find;
diff --git a/git-send-email.perl b/git-send-email.perl
index bbf4deaa0d..85bb6482f2 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -26,11 +26,11 @@ use Text::ParseWords;
 use Term::ANSIColor;
 use File::Temp qw/ tempdir tempfile /;
 use File::Spec::Functions qw(catdir catfile);
-use Git::Error qw(:try);
+use Git::LoadCPAN::Error qw(:try);
 use Cwd qw(abs_path cwd);
 use Git;
 use Git::I18N;
-use Git::Mail::Address;
+use Git::LoadCPAN::Mail::Address;
 
 Getopt::Long::Configure qw/ pass_through /;
 
diff --git a/perl/Git.pm b/perl/Git.pm
index 9d60d7948b..8e02ee2cca 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -101,7 +101,7 @@ increase notwithstanding).
 
 
 use Carp qw(carp croak); # but croak is bad - throw instead
-use Git::Error qw(:try);
+use Git::LoadCPAN::Error qw(:try);
 use Cwd qw(abs_path cwd);
 use IPC::Open2 qw(open2);
 use Fcntl qw(SEEK_SET SEEK_CUR);
diff --git a/perl/Git/Error.pm b/perl/Git/LoadCPAN/Error.pm
similarity index 78%
rename from perl/Git/Error.pm
rename to perl/Git/LoadCPAN/Error.pm
index 09bbc97390..3513fe745b 100644
--- a/perl/Git/Error.pm
+++ b/perl/Git/LoadCPAN/Error.pm
@@ -1,11 +1,11 @@
-package Git::Error;
+package Git::LoadCPAN::Error;
 use 5.008;
 use strict;
 use warnings;
 
 =head1 NAME
 
-Git::Error - Wrapper for the L<Error> module, in case it's not installed
+Git::LoadCPAN::Error - Wrapper for the L<Error> module, in case it's not installed
 
 =head1 DESCRIPTION
 
@@ -26,13 +26,13 @@ sub import {
     } or do {
 	my $error = $@ || "Zombie Error";
 
-	my $Git_Error_pm_path = $INC{"Git/Error.pm"} || die "BUG: Should have our own path from %INC!";
+	my $Git_Error_pm_path = $INC{"Git/LoadCPAN/Error.pm"} || die "BUG: Should have our own path from %INC!";
 
 	require File::Basename;
 	my $Git_Error_pm_root = File::Basename::dirname($Git_Error_pm_path) || die "BUG: Can't figure out lib/Git dirname from '$Git_Error_pm_path'!";
 
 	require File::Spec;
-	my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_Error_pm_root, 'FromCPAN');
+	my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_Error_pm_root, '..', 'FromCPAN');
 	die "BUG: '$Git_pm_FromCPAN_root' should be a directory!" unless -d $Git_pm_FromCPAN_root;
 
 	local @INC = ($Git_pm_FromCPAN_root, @INC);
diff --git a/perl/Git/Mail/Address.pm b/perl/Git/LoadCPAN/Mail/Address.pm
similarity index 69%
rename from perl/Git/Mail/Address.pm
rename to perl/Git/LoadCPAN/Mail/Address.pm
index 2ce3e84670..879c2f5cd1 100644
--- a/perl/Git/Mail/Address.pm
+++ b/perl/Git/LoadCPAN/Mail/Address.pm
@@ -1,11 +1,11 @@
-package Git::Mail::Address;
+package Git::LoadCPAN::Mail::Address;
 use 5.008;
 use strict;
 use warnings;
 
 =head1 NAME
 
-Git::Mail::Address - Wrapper for the L<Mail::Address> module, in case it's not installed
+Git::LoadCPAN::Mail::Address - Wrapper for the L<Mail::Address> module, in case it's not installed
 
 =head1 DESCRIPTION
 
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 3/8] perl: generalize the Git::LoadCPAN facility
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
  2018-02-14 22:21 ` [PATCH 1/8] perl: *.pm files should not have the executable bit Ævar Arnfjörð Bjarmason
  2018-02-14 22:21 ` [PATCH 2/8] perl: move CPAN loader wrappers to another namespace Ævar Arnfjörð Bjarmason
@ 2018-02-14 22:21 ` Ævar Arnfjörð Bjarmason
  2018-02-14 22:57   ` Jonathan Nieder
  2018-02-15  4:53   ` Todd Zullinger
  2018-02-14 22:21 ` [PATCH 4/8] perl: update our ancient copy of Error.pm Ævar Arnfjörð Bjarmason
                   ` (18 subsequent siblings)
  21 siblings, 2 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-14 22:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep, Ævar Arnfjörð Bjarmason

Change the two wrappers to load from CPAN (local OS) or our own copy
to do so via the same codepath.

I added the Error.pm wrapper in 20d2a30f8f ("Makefile: replace
perl/Makefile.PL with simple make rules", 2017-12-10), and shortly
afterwards Matthieu Moy added a wrapper for Mail::Address in
bd869f67b9 ("send-email: add and use a local copy of Mail::Address",
2018-01-05).

His was simpler since Mail::Address doesn't have an "import" method,
but didn't do the same sanity checking, e.g. a missing FromCPAN
directory (which OS packages are likely not to have) wouldn't be
explicitly warned about.

Now both use a modification of the previously Error.pm-specific
codepath, which has been amended to take the module to load as
parameter, as well as whether or not that module has an import method.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git/LoadCPAN.pm              | 74 +++++++++++++++++++++++++++++++++++++++
 perl/Git/LoadCPAN/Error.pm        | 44 +++--------------------
 perl/Git/LoadCPAN/Mail/Address.pm | 22 +++---------
 3 files changed, 82 insertions(+), 58 deletions(-)
 create mode 100644 perl/Git/LoadCPAN.pm

diff --git a/perl/Git/LoadCPAN.pm b/perl/Git/LoadCPAN.pm
new file mode 100644
index 0000000000..2262812654
--- /dev/null
+++ b/perl/Git/LoadCPAN.pm
@@ -0,0 +1,74 @@
+package Git::LoadCPAN;
+use 5.008;
+use strict;
+use warnings;
+
+=head1 NAME
+
+Git::LoadCPAN - Wrapper for loading modules from the CPAN (OS) or Git's own copy
+
+=head1 DESCRIPTION
+
+The Perl code in Git depends on some modules from the CPAN, but we
+don't want to make those a hard requirement for anyone building from
+source.
+
+Therefore the L<Git::LoadCPAN> namespace shipped with Git contains
+wrapper modules like C<Git::LoadCPAN::Module::Name> that will first
+attempt to load C<Module::Name> from the OS, and if that doesn't work
+will fall back on C<Git::FromCPAN::Module::Name> shipped with Git
+itself.
+
+Usually OS's will not ship with Git's Git::FromCPAN tree at all,
+preferring to use their own packaging of CPAN modules instead.
+
+This module is only intended to be used for code shipping in the
+C<git.git> repository. Use it for anything else at your peril!
+
+=cut
+
+sub import {
+    shift;
+    my $caller = caller;
+    my %args = @_;
+    my $module = exists $args{module} ? delete $args{module} : die "BUG: Expected 'module' parameter!";
+    my $import = exists $args{import} ? delete $args{import} : die "BUG: Expected 'import' parameter!";
+    die "BUG: Too many arguments!" if keys %args;
+
+    # Foo::Bar to Foo/Bar.pm
+    my $package_pm = $module;
+    $package_pm =~ s[::][/]g;
+    $package_pm .= '.pm';
+
+    eval {
+	require $package_pm;
+	1;
+    } or do {
+	my $error = $@ || "Zombie Error";
+
+	my $Git_LoadCPAN_pm_path = $INC{"Git/LoadCPAN.pm"} || die "BUG: Should have our own path from %INC!";
+
+	require File::Basename;
+	my $Git_LoadCPAN_pm_root = File::Basename::dirname($Git_LoadCPAN_pm_path) || die "BUG: Can't figure out lib/Git dirname from '$Git_LoadCPAN_pm_path'!";
+
+	require File::Spec;
+	my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_LoadCPAN_pm_root, 'FromCPAN');
+	die "BUG: '$Git_pm_FromCPAN_root' should be a directory!" unless -d $Git_pm_FromCPAN_root;
+
+	local @INC = ($Git_pm_FromCPAN_root, @INC);
+	require $package_pm;
+    };
+
+    if ($import) {
+	no strict 'refs';
+	*{"${caller}::import"}= sub {
+	    shift;
+	    use strict 'refs';
+	    unshift @_, $module;
+	    goto &{"${module}::import"};
+	};
+	use strict 'refs';
+    }
+}
+
+1;
diff --git a/perl/Git/LoadCPAN/Error.pm b/perl/Git/LoadCPAN/Error.pm
index 3513fe745b..9ba53cccf2 100644
--- a/perl/Git/LoadCPAN/Error.pm
+++ b/perl/Git/LoadCPAN/Error.pm
@@ -2,45 +2,9 @@ package Git::LoadCPAN::Error;
 use 5.008;
 use strict;
 use warnings;
-
-=head1 NAME
-
-Git::LoadCPAN::Error - Wrapper for the L<Error> module, in case it's not installed
-
-=head1 DESCRIPTION
-
-Wraps the import function for the L<Error> module.
-
-This module is only intended to be used for code shipping in the
-C<git.git> repository. Use it for anything else at your peril!
-
-=cut
-
-sub import {
-    shift;
-    my $caller = caller;
-
-    eval {
-	require Error;
-	1;
-    } or do {
-	my $error = $@ || "Zombie Error";
-
-	my $Git_Error_pm_path = $INC{"Git/LoadCPAN/Error.pm"} || die "BUG: Should have our own path from %INC!";
-
-	require File::Basename;
-	my $Git_Error_pm_root = File::Basename::dirname($Git_Error_pm_path) || die "BUG: Can't figure out lib/Git dirname from '$Git_Error_pm_path'!";
-
-	require File::Spec;
-	my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_Error_pm_root, '..', 'FromCPAN');
-	die "BUG: '$Git_pm_FromCPAN_root' should be a directory!" unless -d $Git_pm_FromCPAN_root;
-
-	local @INC = ($Git_pm_FromCPAN_root, @INC);
-	require Error;
-    };
-
-    unshift @_, $caller;
-    goto &Error::import;
-}
+use Git::LoadCPAN (
+    module => 'Error',
+    import => 1,
+);
 
 1;
diff --git a/perl/Git/LoadCPAN/Mail/Address.pm b/perl/Git/LoadCPAN/Mail/Address.pm
index 879c2f5cd1..a13f0e58cf 100644
--- a/perl/Git/LoadCPAN/Mail/Address.pm
+++ b/perl/Git/LoadCPAN/Mail/Address.pm
@@ -2,23 +2,9 @@ package Git::LoadCPAN::Mail::Address;
 use 5.008;
 use strict;
 use warnings;
-
-=head1 NAME
-
-Git::LoadCPAN::Mail::Address - Wrapper for the L<Mail::Address> module, in case it's not installed
-
-=head1 DESCRIPTION
-
-This module is only intended to be used for code shipping in the
-C<git.git> repository. Use it for anything else at your peril!
-
-=cut
-
-eval {
-    require Mail::Address;
-    1;
-} or do {
-    require Git::FromCPAN::Mail::Address;
-};
+use Git::LoadCPAN (
+    module => 'Mail::Address',
+    import => 0,
+);
 
 1;
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 4/8] perl: update our ancient copy of Error.pm
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (2 preceding siblings ...)
  2018-02-14 22:21 ` [PATCH 3/8] perl: generalize the Git::LoadCPAN facility Ævar Arnfjörð Bjarmason
@ 2018-02-14 22:21 ` Ævar Arnfjörð Bjarmason
  2018-02-14 23:03   ` Jonathan Nieder
  2018-02-14 22:21 ` [PATCH 5/8] perl: update our copy of Mail::Address Ævar Arnfjörð Bjarmason
                   ` (17 subsequent siblings)
  21 siblings, 1 reply; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-14 22:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep, Ævar Arnfjörð Bjarmason

The Error.pm shipped with Git as a fallback if there was no Error.pm
on the system was released in April 2006, there's been dozens of
releases since then, the latest at August 7, 2017, let's update to
that.

This undoes a local hack we'd accumulated in 96bc4de85c ("Eliminate
Scalar::Util usage from private-Error.pm", 2006-07-26), it's been
redundant since my d48b284183 ("perl: bump the required Perl version
to 5.8 from 5.6.[21]", 2010-09-24).

This also undoes 3a51467b94 ("Typo fix: replacing it's -> its",
2013-04-13). This is the Nth time I find that some upstream code of
ours (in contrib/, in sha1dc/ and now in perl/ ...) has diverged from
upstream because of some tree-wide typo fixing. Let's not do those
fixes against upstream projects, it's more valuable that we have a 1=1
mapping to upstream than to fix typos in docs we never even generate
from this code. If someone wants to fix typos in them fine, but they
should do it with a patch to upstream which git.git can then
incorporate.

The upstream code doesn't cleanly pass a --check, so I'm adding a
.gitattributes file for similar reasons as done for sha1dc in
5d184f468e ("sha1dc: ignore indent-with-non-tab whitespace
violations", 2017-06-06).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git/FromCPAN/.gitattributes |   1 +
 perl/Git/FromCPAN/Error.pm       | 296 +++++++++++++++++++++++++++++++++------
 2 files changed, 256 insertions(+), 41 deletions(-)
 create mode 100644 perl/Git/FromCPAN/.gitattributes

diff --git a/perl/Git/FromCPAN/.gitattributes b/perl/Git/FromCPAN/.gitattributes
new file mode 100644
index 0000000000..8b64fc5e22
--- /dev/null
+++ b/perl/Git/FromCPAN/.gitattributes
@@ -0,0 +1 @@
+/Error.pm whitespace=-blank-at-eof
diff --git a/perl/Git/FromCPAN/Error.pm b/perl/Git/FromCPAN/Error.pm
index 6098135ae2..f9c36e9e98 100644
--- a/perl/Git/FromCPAN/Error.pm
+++ b/perl/Git/FromCPAN/Error.pm
@@ -12,10 +12,12 @@
 package Error;
 
 use strict;
+use warnings;
+
 use vars qw($VERSION);
 use 5.004;
 
-$VERSION = "0.15009";
+$VERSION = "0.17025";
 
 use overload (
 	'""'	   =>	'stringify',
@@ -32,21 +34,35 @@ $Error::THROWN = undef;	# last error thrown, a workaround until die $ref works
 my $LAST;		# Last error created
 my %ERROR;		# Last error associated with package
 
-sub throw_Error_Simple
+sub _throw_Error_Simple
 {
     my $args = shift;
     return Error::Simple->new($args->{'text'});
 }
 
-$Error::ObjectifyCallback = \&throw_Error_Simple;
+$Error::ObjectifyCallback = \&_throw_Error_Simple;
 
 
 # Exported subs are defined in Error::subs
 
+use Scalar::Util ();
+
 sub import {
     shift;
+    my @tags = @_;
     local $Exporter::ExportLevel = $Exporter::ExportLevel + 1;
-    Error::subs->import(@_);
+
+    @tags = grep {
+       if( $_ eq ':warndie' ) {
+          Error::WarnDie->import();
+          0;
+       }
+       else {
+          1;
+       }
+    } @tags;
+
+    Error::subs->import(@tags);
 }
 
 # I really want to use last for the name of this method, but it is a keyword
@@ -107,10 +123,6 @@ sub stacktrace {
     $text;
 }
 
-# Allow error propagation, ie
-#
-# $ber->encode(...) or
-#    return Error->prior($ber)->associate($ldap);
 
 sub associate {
     my $err = shift;
@@ -130,6 +142,7 @@ sub associate {
     return;
 }
 
+
 sub new {
     my $self = shift;
     my($pkg,$file,$line) = caller($Error::Depth);
@@ -246,6 +259,10 @@ sub value {
 
 package Error::Simple;
 
+use vars qw($VERSION);
+
+$VERSION = "0.17025";
+
 @Error::Simple::ISA = qw(Error);
 
 sub new {
@@ -288,14 +305,6 @@ use vars qw(@EXPORT_OK @ISA %EXPORT_TAGS);
 
 @ISA = qw(Exporter);
 
-
-sub blessed {
-	my $item = shift;
-	local $@; # don't kill an outer $@
-	ref $item and eval { $item->can('can') };
-}
-
-
 sub run_clauses ($$$\@) {
     my($clauses,$err,$wantarray,$result) = @_;
     my $code = undef;
@@ -314,16 +323,17 @@ sub run_clauses ($$$\@) {
 		my $pkg = $catch->[$i];
 		unless(defined $pkg) {
 		    #except
-		    splice(@$catch,$i,2,$catch->[$i+1]->());
+		    splice(@$catch,$i,2,$catch->[$i+1]->($err));
 		    $i -= 2;
 		    next CATCHLOOP;
 		}
-		elsif(blessed($err) && $err->isa($pkg)) {
+		elsif(Scalar::Util::blessed($err) && $err->isa($pkg)) {
 		    $code = $catch->[$i+1];
 		    while(1) {
 			my $more = 0;
-			local($Error::THROWN);
+			local($Error::THROWN, $@);
 			my $ok = eval {
+			    $@ = $err;
 			    if($wantarray) {
 				@{$result} = $code->($err,\$more);
 			    }
@@ -341,10 +351,9 @@ sub run_clauses ($$$\@) {
 			    undef $err;
 			}
 			else {
-			    $err = defined($Error::THROWN)
-				    ? $Error::THROWN : $@;
-                $err = $Error::ObjectifyCallback->({'text' =>$err})
-                    unless ref($err);
+			    $err = $@ || $Error::THROWN;
+				$err = $Error::ObjectifyCallback->({'text' =>$err})
+					unless ref($err);
 			}
 			last CATCH;
 		    };
@@ -357,7 +366,9 @@ sub run_clauses ($$$\@) {
 	if(defined($owise = $clauses->{'otherwise'})) {
 	    my $code = $clauses->{'otherwise'};
 	    my $more = 0;
+        local($Error::THROWN, $@);
 	    my $ok = eval {
+		$@ = $err;
 		if($wantarray) {
 		    @{$result} = $code->($err,\$more);
 		}
@@ -374,11 +385,10 @@ sub run_clauses ($$$\@) {
 		undef $err;
 	    }
 	    else {
-		$err = defined($Error::THROWN)
-			? $Error::THROWN : $@;
+		$err = $@ || $Error::THROWN;
 
-        $err = $Error::ObjectifyCallback->({'text' =>$err})
-            unless ref($err);
+		$err = $Error::ObjectifyCallback->({'text' =>$err})
+			unless ref($err);
 	    }
 	}
     }
@@ -398,7 +408,7 @@ sub try (&;$) {
 
     do {
 	local $Error::THROWN = undef;
-    local $@ = undef;
+	local $@ = undef;
 
 	$ok = eval {
 	    if($wantarray) {
@@ -413,21 +423,21 @@ sub try (&;$) {
 	    1;
 	};
 
-	$err = defined($Error::THROWN) ? $Error::THROWN : $@
+	$err = $@ || $Error::THROWN
 	    unless $ok;
     };
 
     shift @Error::STACK;
 
     $err = run_clauses($clauses,$err,wantarray,@result)
-	unless($ok);
+    unless($ok);
 
     $clauses->{'finally'}->()
 	if(defined($clauses->{'finally'}));
 
     if (defined($err))
     {
-        if (blessed($err) && $err->can('throw'))
+        if (Scalar::Util::blessed($err) && $err->can('throw'))
         {
             throw $err;
         }
@@ -506,12 +516,116 @@ sub otherwise (&;$) {
 }
 
 1;
+
+package Error::WarnDie;
+
+sub gen_callstack($)
+{
+    my ( $start ) = @_;
+
+    require Carp;
+    local $Carp::CarpLevel = $start;
+    my $trace = Carp::longmess("");
+    # Remove try calls from the trace
+    $trace =~ s/(\n\s+\S+__ANON__[^\n]+)?\n\s+eval[^\n]+\n\s+Error::subs::try[^\n]+(?=\n)//sog;
+    $trace =~ s/(\n\s+\S+__ANON__[^\n]+)?\n\s+eval[^\n]+\n\s+Error::subs::run_clauses[^\n]+\n\s+Error::subs::try[^\n]+(?=\n)//sog;
+    my @callstack = split( m/\n/, $trace );
+    return @callstack;
+}
+
+my $old_DIE;
+my $old_WARN;
+
+sub DEATH
+{
+    my ( $e ) = @_;
+
+    local $SIG{__DIE__} = $old_DIE if( defined $old_DIE );
+
+    die @_ if $^S;
+
+    my ( $etype, $message, $location, @callstack );
+    if ( ref($e) && $e->isa( "Error" ) ) {
+        $etype = "exception of type " . ref( $e );
+        $message = $e->text;
+        $location = $e->file . ":" . $e->line;
+        @callstack = split( m/\n/, $e->stacktrace );
+    }
+    else {
+        # Don't apply subsequent layer of message formatting
+        die $e if( $e =~ m/^\nUnhandled perl error caught at toplevel:\n\n/ );
+        $etype = "perl error";
+        my $stackdepth = 0;
+        while( caller( $stackdepth ) =~ m/^Error(?:$|::)/ ) {
+            $stackdepth++
+        }
+
+        @callstack = gen_callstack( $stackdepth + 1 );
+
+        $message = "$e";
+        chomp $message;
+
+        if ( $message =~ s/ at (.*?) line (\d+)\.$// ) {
+            $location = $1 . ":" . $2;
+        }
+        else {
+            my @caller = caller( $stackdepth );
+            $location = $caller[1] . ":" . $caller[2];
+        }
+    }
+
+    shift @callstack;
+    # Do it this way in case there are no elements; we don't print a spurious \n
+    my $callstack = join( "", map { "$_\n"} @callstack );
+
+    die "\nUnhandled $etype caught at toplevel:\n\n  $message\n\nThrown from: $location\n\nFull stack trace:\n\n$callstack\n";
+}
+
+sub TAXES
+{
+    my ( $message ) = @_;
+
+    local $SIG{__WARN__} = $old_WARN if( defined $old_WARN );
+
+    $message =~ s/ at .*? line \d+\.$//;
+    chomp $message;
+
+    my @callstack = gen_callstack( 1 );
+    my $location = shift @callstack;
+
+    # $location already starts in a leading space
+    $message .= $location;
+
+    # Do it this way in case there are no elements; we don't print a spurious \n
+    my $callstack = join( "", map { "$_\n"} @callstack );
+
+    warn "$message:\n$callstack";
+}
+
+sub import
+{
+    $old_DIE  = $SIG{__DIE__};
+    $old_WARN = $SIG{__WARN__};
+
+    $SIG{__DIE__}  = \&DEATH;
+    $SIG{__WARN__} = \&TAXES;
+}
+
+1;
+
 __END__
 
 =head1 NAME
 
 Error - Error/exception handling in an OO-ish way
 
+=head1 WARNING
+
+Using the "Error" module is B<no longer recommended> due to the black-magical
+nature of its syntactic sugar, which often tends to break. Its maintainers
+have stopped actively writing code that uses it, and discourage people
+from doing so. See the "SEE ALSO" section below for better recommendations.
+
 =head1 SYNOPSIS
 
     use Error qw(:try);
@@ -529,7 +643,7 @@ Error - Error/exception handling in an OO-ish way
     try {
 	do_some_stuff();
 	die "error!" if $condition;
-	throw Error::Simple -text => "Oops!" if $other_condition;
+	throw Error::Simple "Oops!" if $other_condition;
     }
     catch Error::IO with {
 	my $E = shift;
@@ -587,7 +701,7 @@ C<BLOCK> will be passed two arguments. The first will be the error
 being thrown. The second is a reference to a scalar variable. If this
 variable is set by the catch block then, on return from the catch
 block, try will continue processing as if the catch block was never
-found.
+found. The error will also be available in C<$@>.
 
 To propagate the error the catch block may call C<$err-E<gt>throw>
 
@@ -608,7 +722,7 @@ type.
 Catch any error by executing the code in C<BLOCK>
 
 When evaluated C<BLOCK> will be passed one argument, which will be the
-error being processed.
+error being processed. The error will also be available in C<$@>.
 
 Only one otherwise block may be specified per try block
 
@@ -625,12 +739,25 @@ Only one finally block may be specified per try block
 
 =back
 
+=head1 COMPATIBILITY
+
+L<Moose> exports a keyword called C<with> which clashes with Error's. This
+example returns a prototype mismatch error:
+
+    package MyTest;
+
+    use warnings;
+    use Moose;
+    use Error qw(:try);
+
+(Thanks to C<maik.hentsche@amd.com> for the report.).
+
 =head1 CLASS INTERFACE
 
 =head2 CONSTRUCTORS
 
 The C<Error> object is implemented as a HASH. This HASH is initialized
-with the arguments that are passed to its constructor. The elements
+with the arguments that are passed to it's constructor. The elements
 that are used by, or are retrievable by the C<Error> class are listed
 below, other classes may add to these.
 
@@ -655,6 +782,10 @@ an object blessed into that package as the C<-object> argument.
 
 =over 4
 
+=item Error->new()
+
+See the Error::Simple documentation.
+
 =item throw ( [ ARGS ] )
 
 Create a new C<Error> object and throw an error, which will be caught
@@ -730,6 +861,13 @@ The line where the constructor of this error was called from
 
 The text of the error
 
+=item $err->associate($obj)
+
+Associates an error with an object to allow error propagation. I.e:
+
+    $ber->encode(...) or
+        return Error->prior($ber)->associate($ldap);
+
 =back
 
 =head2 OVERLOAD METHODS
@@ -759,11 +897,9 @@ to the constructor.
 
 =head1 PRE-DEFINED ERROR CLASSES
 
-=over 4
-
-=item Error::Simple
+=head2 Error::Simple
 
-This class can be used to hold simple error strings and values. Its
+This class can be used to hold simple error strings and values. It's
 constructor takes two arguments. The first is a text value, the second
 is a numeric value. These values are what will be returned by the
 overload methods.
@@ -775,7 +911,6 @@ of the error object.
 This class is used internally if an eval'd block die's with an error
 that is a plain string. (Unless C<$Error::ObjectifyCallback> is modified)
 
-=back
 
 =head1 $Error::ObjectifyCallback
 
@@ -804,6 +939,76 @@ class MyError::Bar by default:
         # Error handling here.
     }
 
+=cut
+
+=head1 MESSAGE HANDLERS
+
+C<Error> also provides handlers to extend the output of the C<warn()> perl
+function, and to handle the printing of a thrown C<Error> that is not caught
+or otherwise handled. These are not installed by default, but are requested
+using the C<:warndie> tag in the C<use> line.
+
+ use Error qw( :warndie );
+
+These new error handlers are installed in C<$SIG{__WARN__}> and
+C<$SIG{__DIE__}>. If these handlers are already defined when the tag is
+imported, the old values are stored, and used during the new code. Thus, to
+arrange for custom handling of warnings and errors, you will need to perform
+something like the following:
+
+ BEGIN {
+   $SIG{__WARN__} = sub {
+     print STDERR "My special warning handler: $_[0]"
+   };
+ }
+
+ use Error qw( :warndie );
+
+Note that setting C<$SIG{__WARN__}> after the C<:warndie> tag has been
+imported will overwrite the handler that C<Error> provides. If this cannot be
+avoided, then the tag can be explicitly C<import>ed later
+
+ use Error;
+
+ $SIG{__WARN__} = ...;
+
+ import Error qw( :warndie );
+
+=head2 EXAMPLE
+
+The C<__DIE__> handler turns messages such as
+
+ Can't call method "foo" on an undefined value at examples/warndie.pl line 16.
+
+into
+
+ Unhandled perl error caught at toplevel:
+
+   Can't call method "foo" on an undefined value
+
+ Thrown from: examples/warndie.pl:16
+
+ Full stack trace:
+
+         main::inner('undef') called at examples/warndie.pl line 20
+         main::outer('undef') called at examples/warndie.pl line 23
+
+=cut
+
+=head1 SEE ALSO
+
+See L<Exception::Class> for a different module providing Object-Oriented
+exception handling, along with a convenient syntax for declaring hierarchies
+for them. It doesn't provide Error's syntactic sugar of C<try { ... }>,
+C<catch { ... }>, etc. which may be a good thing or a bad thing based
+on what you want. (Because Error's syntactic sugar tends to break.)
+
+L<Error::Exception> aims to combine L<Error> and L<Exception::Class>
+"with correct stringification".
+
+L<TryCatch> and L<Try::Tiny> are similar in concept to Error.pm only providing
+a syntax that hopefully breaks less.
+
 =head1 KNOWN BUGS
 
 None, but that does not mean there are not any.
@@ -816,12 +1021,21 @@ The code that inspired me to write this was originally written by
 Peter Seibel <peter@weblogic.com> and adapted by Jesse Glick
 <jglick@sig.bsh.com>.
 
+C<:warndie> handlers added by Paul Evans <leonerd@leonerd.org.uk>
+
 =head1 MAINTAINER
 
-Shlomi Fish <shlomif@iglu.org.il>
+Shlomi Fish, L<http://www.shlomifish.org/> .
 
 =head1 PAST MAINTAINERS
 
 Arun Kumar U <u_arunkumar@yahoo.com>
 
+=head1 COPYRIGHT
+
+Copyright (c) 1997-8  Graham Barr. All rights reserved.
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
 =cut
+
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 5/8] perl: update our copy of Mail::Address
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (3 preceding siblings ...)
  2018-02-14 22:21 ` [PATCH 4/8] perl: update our ancient copy of Error.pm Ævar Arnfjörð Bjarmason
@ 2018-02-14 22:21 ` Ævar Arnfjörð Bjarmason
  2018-02-14 23:46   ` Jonathan Nieder
  2018-02-14 22:21 ` [PATCH 6/8] git-send-email: unconditionally use Net::{SMTP,Domain} Ævar Arnfjörð Bjarmason
                   ` (16 subsequent siblings)
  21 siblings, 1 reply; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-14 22:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep, Ævar Arnfjörð Bjarmason

Update our copy of Mail::Address from 2.19 (Aug 22, 2017) to 2.20 (Jan
23, 2018). This should be a trivial update[1] but it seems the version
Matthieu Moy imported in bd869f67b9 ("send-email: add and use a local
copy of Mail::Address", 2018-01-05) doesn't correspond to any 2.19
version found on the CPAN. From the comment at the top of the file it
looks like some OS version with the POD stripped, and with different
indentation.

Let's instead use the upstream version as-is, and without copyright
notices stripped. Like Error.pm this doesn't cleanly pass --check, so
add a .gitattributes file to ignore the errors.

1. https://metacpan.org/diff/file?target=MARKOV/MailTools-2.20/lib%2FMail%2FAddress.pod&source=MARKOV%2FMailTools-2.19%2Flib%2FMail%2FAddress.pod

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git/FromCPAN/Mail/.gitattributes |   1 +
 perl/Git/FromCPAN/Mail/Address.pm     | 436 +++++++++++++---------------------
 2 files changed, 163 insertions(+), 274 deletions(-)
 create mode 100644 perl/Git/FromCPAN/Mail/.gitattributes

diff --git a/perl/Git/FromCPAN/Mail/.gitattributes b/perl/Git/FromCPAN/Mail/.gitattributes
new file mode 100644
index 0000000000..94f3e5bb86
--- /dev/null
+++ b/perl/Git/FromCPAN/Mail/.gitattributes
@@ -0,0 +1 @@
+/Address.pm whitespace=-trailing-space
diff --git a/perl/Git/FromCPAN/Mail/Address.pm b/perl/Git/FromCPAN/Mail/Address.pm
index 13b2ff7d05..ee333e0f5a 100644
--- a/perl/Git/FromCPAN/Mail/Address.pm
+++ b/perl/Git/FromCPAN/Mail/Address.pm
@@ -1,276 +1,164 @@
-# Copyrights 1995-2017 by [Mark Overmeer <perl@overmeer.net>].
-#  For other contributors see ChangeLog.
-# See the manual pages for details on the licensing terms.
-# Pod stripped from pm file by OODoc 2.02.
-package Mail::Address;
-use vars '$VERSION';
-$VERSION = '2.19';
-
-use strict;
-
-use Carp;
-
-# use locale;   removed in version 1.78, because it causes taint problems
-
-sub Version { our $VERSION }
-
-
-
-# given a comment, attempt to extract a person's name
-sub _extract_name
-{   # This function can be called as method as well
-    my $self = @_ && ref $_[0] ? shift : undef;
-
-    local $_ = shift
-        or return '';
-
-    # Using encodings, too hard. See Mail::Message::Field::Full.
-    return '' if m/\=\?.*?\?\=/;
-
-    # trim whitespace
-    s/^\s+//;
-    s/\s+$//;
-    s/\s+/ /;
-
-    # Disregard numeric names (e.g. 123456.1234@compuserve.com)
-    return "" if /^[\d ]+$/;
-
-    s/^\((.*)\)$/$1/; # remove outermost parenthesis
-    s/^"(.*)"$/$1/;   # remove outer quotation marks
-    s/\(.*?\)//g;     # remove minimal embedded comments
-    s/\\//g;          # remove all escapes
-    s/^"(.*)"$/$1/;   # remove internal quotation marks
-    s/^([^\s]+) ?, ?(.*)$/$2 $1/; # reverse "Last, First M." if applicable
-    s/,.*//;
-
-    # Change casing only when the name contains only upper or only
-    # lower cased characters.
-    unless( m/[A-Z]/ && m/[a-z]/ )
-    {   # Set the case of the name to first char upper rest lower
-        s/\b(\w+)/\L\u$1/igo;  # Upcase first letter on name
-        s/\bMc(\w)/Mc\u$1/igo; # Scottish names such as 'McLeod'
-        s/\bo'(\w)/O'\u$1/igo; # Irish names such as 'O'Malley, O'Reilly'
-        s/\b(x*(ix)?v*(iv)?i*)\b/\U$1/igo; # Roman numerals, eg 'Level III Support'
-    }
+=encoding utf8
 
-    # some cleanup
-    s/\[[^\]]*\]//g;
-    s/(^[\s'"]+|[\s'"]+$)//g;
-    s/\s{2,}/ /g;
-
-    $_;
-}
-
-sub _tokenise
-{   local $_ = join ',', @_;
-    my (@words,$snippet,$field);
-
-    s/\A\s+//;
-    s/[\r\n]+/ /g;
-
-    while ($_ ne '')
-    {   $field = '';
-        if(s/^\s*\(/(/ )    # (...)
-        {   my $depth = 0;
-
-     PAREN: while(s/^(\(([^\(\)\\]|\\.)*)//)
-            {   $field .= $1;
-                $depth++;
-                while(s/^(([^\(\)\\]|\\.)*\)\s*)//)
-                {   $field .= $1;
-                    last PAREN unless --$depth;
-	            $field .= $1 if s/^(([^\(\)\\]|\\.)+)//;
-                }
-            }
-
-            carp "Unmatched () '$field' '$_'"
-                if $depth;
-
-            $field =~ s/\s+\Z//;
-            push @words, $field;
-
-            next;
-        }
-
-        if( s/^("(?:[^"\\]+|\\.)*")\s*//       # "..."
-         || s/^(\[(?:[^\]\\]+|\\.)*\])\s*//    # [...]
-         || s/^([^\s()<>\@,;:\\".[\]]+)\s*//
-         || s/^([()<>\@,;:\\".[\]])\s*//
-          )
-        {   push @words, $1;
-            next;
-        }
-
-        croak "Unrecognised line: $_";
-    }
-
-    push @words, ",";
-    \@words;
-}
-
-sub _find_next
-{   my ($idx, $tokens, $len) = @_;
-
-    while($idx < $len)
-    {   my $c = $tokens->[$idx];
-        return $c if $c eq ',' || $c eq ';' || $c eq '<';
-        $idx++;
-    }
-
-    "";
-}
-
-sub _complete
-{   my ($class, $phrase, $address, $comment) = @_;
-
-    @$phrase || @$comment || @$address
-       or return undef;
-
-    my $o = $class->new(join(" ",@$phrase), join("",@$address), join(" ",@$comment));
-    @$phrase = @$address = @$comment = ();
-    $o;
-}
-
-#------------
-
-sub new(@)
-{   my $class = shift;
-    bless [@_], $class;
-}
-
-
-sub parse(@)
-{   my $class = shift;
-    my @line  = grep {defined} @_;
-    my $line  = join '', @line;
-
-    my (@phrase, @comment, @address, @objs);
-    my ($depth, $idx) = (0, 0);
-
-    my $tokens  = _tokenise @line;
-    my $len     = @$tokens;
-    my $next    = _find_next $idx, $tokens, $len;
-
-    local $_;
-    for(my $idx = 0; $idx < $len; $idx++)
-    {   $_ = $tokens->[$idx];
-
-        if(substr($_,0,1) eq '(') { push @comment, $_ }
-        elsif($_ eq '<')    { $depth++ }
-        elsif($_ eq '>')    { $depth-- if $depth }
-        elsif($_ eq ',' || $_ eq ';')
-        {   warn "Unmatched '<>' in $line" if $depth;
-            my $o = $class->_complete(\@phrase, \@address, \@comment);
-            push @objs, $o if defined $o;
-            $depth = 0;
-            $next = _find_next $idx+1, $tokens, $len;
-        }
-        elsif($depth)       { push @address, $_ }
-        elsif($next eq '<') { push @phrase,  $_ }
-        elsif( /^[.\@:;]$/ || !@address || $address[-1] =~ /^[.\@:;]$/ )
-        {   push @address, $_ }
-        else
-        {   warn "Unmatched '<>' in $line" if $depth;
-            my $o = $class->_complete(\@phrase, \@address, \@comment);
-            push @objs, $o if defined $o;
-            $depth = 0;
-            push @address, $_;
-        }
-    }
-    @objs;
-}
-
-#------------
-
-sub phrase  { shift->set_or_get(0, @_) }
-sub address { shift->set_or_get(1, @_) }
-sub comment { shift->set_or_get(2, @_) }
-
-sub set_or_get($)
-{   my ($self, $i) = (shift, shift);
-    @_ or return $self->[$i];
-
-    my $val = $self->[$i];
-    $self->[$i] = shift if @_;
-    $val;
-}
-
-
-my $atext = '[\-\w !#$%&\'*+/=?^`{|}~]';
-sub format
-{   my @addrs;
-
-    foreach (@_)
-    {   my ($phrase, $email, $comment) = @$_;
-        my @addr;
-
-        if(defined $phrase && length $phrase)
-        {   push @addr
-              , $phrase =~ /^(?:\s*$atext\s*)+$/o ? $phrase
-              : $phrase =~ /(?<!\\)"/             ? $phrase
-              :                                    qq("$phrase");
-
-            push @addr, "<$email>"
-                if defined $email && length $email;
-        }
-        elsif(defined $email && length $email)
-        {   push @addr, $email;
-        }
-
-        if(defined $comment && $comment =~ /\S/)
-        {   $comment =~ s/^\s*\(?/(/;
-            $comment =~ s/\)?\s*$/)/;
-        }
-
-        push @addr, $comment
-            if defined $comment && length $comment;
-
-        push @addrs, join(" ", @addr)
-            if @addr;
-    }
-
-    join ", ", @addrs;
-}
-
-#------------
-
-sub name
-{   my $self   = shift;
-    my $phrase = $self->phrase;
-    my $addr   = $self->address;
-
-    $phrase    = $self->comment
-        unless defined $phrase && length $phrase;
-
-    my $name   = $self->_extract_name($phrase);
-
-    # first.last@domain address
-    if($name eq '' && $addr =~ /([^\%\.\@_]+([\._][^\%\.\@_]+)+)[\@\%]/)
-    {   ($name  = $1) =~ s/[\._]+/ /g;
-	$name   = _extract_name $name;
-    }
-
-    if($name eq '' && $addr =~ m#/g=#i)    # X400 style address
-    {   my ($f) = $addr =~ m#g=([^/]*)#i;
-	my ($l) = $addr =~ m#s=([^/]*)#i;
-	$name   = _extract_name "$f $l";
-    }
-
-    length $name ? $name : undef;
-}
-
-
-sub host
-{   my $addr = shift->address || '';
-    my $i    = rindex $addr, '@';
-    $i >= 0 ? substr($addr, $i+1) : undef;
-}
-
-
-sub user
-{   my $addr = shift->address || '';
-    my $i    = rindex $addr, '@';
-    $i >= 0 ? substr($addr,0,$i) : $addr;
-}
+=head1 NAME
+
+Mail::Address - parse mail addresses
+
+=head1 SYNOPSIS
+
+ use Mail::Address;
+ my @addrs = Mail::Address->parse($line);
+
+ foreach $addr (@addrs) {
+     print $addr->format,"\n";
+ }
+
+=head1 DESCRIPTION
+
+C<Mail::Address> extracts and manipulates email addresses from a message
+header.  It cannot be used to extract addresses from some random text.
+You can use this module to create RFC822 compliant fields.
+
+Although C<Mail::Address> is a very popular subject for books, and is
+used in many applications, it does a very poor job on the more complex
+message fields.  It does only handle simple address formats (which
+covers about 95% of what can be found). Problems are with
+
+=over 4
+
+=item *
+
+no support for address groups, even not with the semi-colon as
+separator between addresses;
+
+=item *
+
+limited support for escapes in phrases and comments.  There are
+cases where it can get wrong; and
+
+=item *
+
+you have to take care of most escaping when you create an address yourself:
+C<Mail::Address> does not do that for you.
+
+=back
+
+Often requests are made to the maintainers of this code improve this
+situation, but this is not a good idea, where it will break zillions
+of existing applications.  If you wish for a fully RFC2822 compliant
+implementation you may take a look at L<Mail::Message::Field::Full>,
+part of MailBox.
+
+B<. Example>
+
+  my $s = Mail::Message::Field::Full->new($from_header);
+  # ref $s isa Mail::Message::Field::Addresses;
+
+  my @g = $s->groups;          # all groups, at least one
+  # ref $g[0] isa Mail::Message::Field::AddrGroup;
+  my $ga = $g[0]->addresses;   # group addresses
+
+  my @a = $s->addresses;       # all addresses
+  # ref $a[0] isa Mail::Message::Field::Address;
+
+=head1 METHODS
+
+=head2 Constructors
+
+=over 4
+
+=item Mail::Address-E<gt>B<new>( $phrase, $address, [ $comment ] )
+
+Create a new C<Mail::Address> object which represents an address with the
+elements given. In a message these 3 elements would be seen like:
+
+ PHRASE <ADDRESS> (COMMENT)
+ ADDRESS (COMMENT)
+
+example: 
+
+ Mail::Address->new("Perl5 Porters", "perl5-porters@africa.nicoh.com");
+
+=item $obj-E<gt>B<parse>($line)
+
+Parse the given line a return a list of extracted C<Mail::Address> objects.
+The line would normally be one taken from a To,Cc or Bcc line in a message
+
+example: 
+
+ my @addr = Mail::Address->parse($line);
+
+=back
+
+=head2 Accessors
+
+=over 4
+
+=item $obj-E<gt>B<address>()
+
+Return the address part of the object.
+
+=item $obj-E<gt>B<comment>()
+
+Return the comment part of the object
+
+=item $obj-E<gt>B<format>(@addresses)
+
+Return a string representing the address in a suitable form to be placed
+on a C<To>, C<Cc>, or C<Bcc> line of a message.  This method is called on
+the first address to be used; other specified addresses will be appended,
+separated by commas.
+
+=item $obj-E<gt>B<phrase>()
+
+Return the phrase part of the object.
+
+=back
+
+=head2 Smart accessors
+
+=over 4
+
+=item $obj-E<gt>B<host>()
+
+Return the address excluding the user id and '@'
+
+=item $obj-E<gt>B<name>()
+
+Using the information contained within the object attempt to identify what
+the person or groups name is.
+
+B<Note:> This function tries to be smart with the "phrase" of the
+email address, which is probably a very bad idea.  Consider to use
+L<phrase()|Mail::Address/"Accessors"> itself.
+
+=item $obj-E<gt>B<user>()
+
+Return the address excluding the '@' and the mail domain
+
+=back
+
+=head1 SEE ALSO
+
+This module is part of the MailTools distribution,
+F<http://perl.overmeer.net/mailtools/>.
+
+=head1 AUTHORS
+
+The MailTools bundle was developed by Graham Barr.  Later, Mark
+Overmeer took over maintenance without commitment to further development.
+
+Mail::Cap by Gisle Aas E<lt>aas@oslonett.noE<gt>.
+Mail::Field::AddrList by Peter Orbaek E<lt>poe@cit.dkE<gt>.
+Mail::Mailer and Mail::Send by Tim Bunce E<lt>Tim.Bunce@ig.co.ukE<gt>.
+For other contributors see ChangeLog.
+
+=head1 LICENSE
+
+Copyrights 1995-2000 Graham Barr E<lt>gbarr@pobox.comE<gt> and
+2001-2017 Mark Overmeer E<lt>perl@overmeer.netE<gt>.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+See F<http://www.perl.com/perl/misc/Artistic.html>
 
-1;
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 6/8] git-send-email: unconditionally use Net::{SMTP,Domain}
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (4 preceding siblings ...)
  2018-02-14 22:21 ` [PATCH 5/8] perl: update our copy of Mail::Address Ævar Arnfjörð Bjarmason
@ 2018-02-14 22:21 ` Ævar Arnfjörð Bjarmason
  2018-02-14 23:49   ` Jonathan Nieder
  2018-02-14 22:21 ` [PATCH 7/8] gitweb: hard-depend on the Digest::MD5 5.8 module Ævar Arnfjörð Bjarmason
                   ` (15 subsequent siblings)
  21 siblings, 1 reply; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-14 22:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep, Ævar Arnfjörð Bjarmason

The Net::SMTP and Net::Domain were both first released with perl
v5.7.3, since my d48b284183 ("perl: bump the required Perl version to
5.8 from 5.6.[21]", 2010-09-24) we've depended on 5.8, so there's no
reason to conditionally require this anymore.

This conditional loading was initially added in
87840620fd ("send-email: only 'require' instead of 'use' Net::SMTP",
2006-06-01) for Net::SMTP and 134550fe21 ("git-send-email.perl - try
to give real name of the calling host to HELO/EHLO", 2010-03-14) for
Net::Domain, both of which predate the hard dependency on 5.8.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 git-send-email.perl | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index 85bb6482f2..69bd443245 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1143,10 +1143,9 @@ sub valid_fqdn {
 sub maildomain_net {
 	my $maildomain;
 
-	if (eval { require Net::Domain; 1 }) {
-		my $domain = Net::Domain::domainname();
-		$maildomain = $domain if valid_fqdn($domain);
-	}
+	require Net::Domain;
+	my $domain = Net::Domain::domainname();
+	$maildomain = $domain if valid_fqdn($domain);
 
 	return $maildomain;
 }
@@ -1154,17 +1153,16 @@ sub maildomain_net {
 sub maildomain_mta {
 	my $maildomain;
 
-	if (eval { require Net::SMTP; 1 }) {
-		for my $host (qw(mailhost localhost)) {
-			my $smtp = Net::SMTP->new($host);
-			if (defined $smtp) {
-				my $domain = $smtp->domain;
-				$smtp->quit;
+	require Net::SMTP;
+	for my $host (qw(mailhost localhost)) {
+		my $smtp = Net::SMTP->new($host);
+		if (defined $smtp) {
+			my $domain = $smtp->domain;
+			$smtp->quit;
 
-				$maildomain = $domain if valid_fqdn($domain);
+			$maildomain = $domain if valid_fqdn($domain);
 
-				last if $maildomain;
-			}
+			last if $maildomain;
 		}
 	}
 
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 7/8] gitweb: hard-depend on the Digest::MD5 5.8 module
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (5 preceding siblings ...)
  2018-02-14 22:21 ` [PATCH 6/8] git-send-email: unconditionally use Net::{SMTP,Domain} Ævar Arnfjörð Bjarmason
@ 2018-02-14 22:21 ` Ævar Arnfjörð Bjarmason
  2018-02-14 23:52   ` Jonathan Nieder
  2018-02-14 22:21 ` [PATCH 8/8] perl: hard-depend on the File::{Temp,Spec} modules Ævar Arnfjörð Bjarmason
                   ` (14 subsequent siblings)
  21 siblings, 1 reply; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-14 22:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep, Ævar Arnfjörð Bjarmason

Since my d48b284183 ("perl: bump the required Perl version to 5.8 from
5.6.[21]", 2010-09-24), we've depended on 5.8, so there's no reason to
conditionally require Digest::MD5 anymore. It was released with perl
v5.7.3.

The initial introduction of the dependency in
e9fdd74e53 ("gitweb: (gr)avatar support", 2009-06-30) says as much,
this also undoes part of the later 2e9c8789b7 ("gitweb: Mention
optional Perl modules in INSTALL", 2011-02-04) since gitweb will
always be run on at least 5.8, so there's no need to mention
Digest::MD5 as a required module in the documentation, let's instead
say that we require perl 5.8.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 gitweb/INSTALL     |  3 +--
 gitweb/gitweb.perl | 17 +++++------------
 2 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/gitweb/INSTALL b/gitweb/INSTALL
index 408f2859d3..a58e6b3c44 100644
--- a/gitweb/INSTALL
+++ b/gitweb/INSTALL
@@ -29,12 +29,11 @@ Requirements
 ------------
 
  - Core git tools
- - Perl
+ - Perl 5.8
  - Perl modules: CGI, Encode, Fcntl, File::Find, File::Basename.
  - web server
 
 The following optional Perl modules are required for extra features
- - Digest::MD5 - for gravatar support
  - CGI::Fast and FCGI - for running gitweb as FastCGI script
  - HTML::TagCloud - for fancy tag cloud in project list view
  - HTTP::Date or Time::ParseDate - to support If-Modified-Since for feeds
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 2417057f2b..8f48e3c02e 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -490,7 +490,6 @@ our %feature = (
 	# Currently available providers are gravatar and picon.
 	# If an unknown provider is specified, the feature is disabled.
 
-	# Gravatar depends on Digest::MD5.
 	# Picon currently relies on the indiana.edu database.
 
 	# To enable system wide have in $GITWEB_CONFIG
@@ -1166,18 +1165,11 @@ sub configure_gitweb_features {
 	our @snapshot_fmts = gitweb_get_feature('snapshot');
 	@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
 
-	# check that the avatar feature is set to a known provider name,
-	# and for each provider check if the dependencies are satisfied.
-	# if the provider name is invalid or the dependencies are not met,
-	# reset $git_avatar to the empty string.
+	# check that the avatar feature is set to a known provider
+	# name, if the provider name is invalid, reset $git_avatar to
+	# the empty string.
 	our ($git_avatar) = gitweb_get_feature('avatar');
-	if ($git_avatar eq 'gravatar') {
-		$git_avatar = '' unless (eval { require Digest::MD5; 1; });
-	} elsif ($git_avatar eq 'picon') {
-		# no dependencies
-	} else {
-		$git_avatar = '';
-	}
+	$git_avatar = '' unless $git_avatar =~ /^(?:gravatar|picon)$/s;
 
 	our @extra_branch_refs = gitweb_get_feature('extra-branch-refs');
 	@extra_branch_refs = filter_and_validate_refs (@extra_branch_refs);
@@ -2165,6 +2157,7 @@ sub picon_url {
 sub gravatar_url {
 	my $email = lc shift;
 	my $size = shift;
+	require Digest::MD5;
 	$avatar_cache{$email} ||=
 		"//www.gravatar.com/avatar/" .
 			Digest::MD5::md5_hex($email) . "?s=";
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 8/8] perl: hard-depend on the File::{Temp,Spec} modules
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (6 preceding siblings ...)
  2018-02-14 22:21 ` [PATCH 7/8] gitweb: hard-depend on the Digest::MD5 5.8 module Ævar Arnfjörð Bjarmason
@ 2018-02-14 22:21 ` Ævar Arnfjörð Bjarmason
  2018-02-14 23:54   ` Jonathan Nieder
  2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (13 subsequent siblings)
  21 siblings, 1 reply; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-14 22:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep, Ævar Arnfjörð Bjarmason

Since my d48b284183 ("perl: bump the required Perl version to 5.8 from
5.6.[21]", 2010-09-24), we've depended on 5.8, so there's no reason to
conditionally require File::Temp and File::Spec anymore. They were
first released with perl versions v5.6.1 and 5.00405, respectively.

This code was originally added in c14c8ceb13 ("Git.pm: Make File::Spec
and File::Temp requirement lazy", 2008-08-15), presumably to make
Git.pm work on 5.6.0.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git.pm | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/perl/Git.pm b/perl/Git.pm
index 8e02ee2cca..221e827e83 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -1324,8 +1324,9 @@ sub _temp_cache {
 }
 
 sub _verify_require {
-	eval { require File::Temp; require File::Spec; };
-	$@ and throw Error::Simple($@);
+	require File::Temp;
+	require File::Spec;
+	return;
 }
 
 =item temp_reset ( FILEHANDLE )
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* Re: [PATCH 1/8] perl: *.pm files should not have the executable bit
  2018-02-14 22:21 ` [PATCH 1/8] perl: *.pm files should not have the executable bit Ævar Arnfjörð Bjarmason
@ 2018-02-14 22:41   ` Jonathan Nieder
  2018-02-25 19:01     ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 66+ messages in thread
From: Jonathan Nieder @ 2018-02-14 22:41 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep

Hi,

Ævar Arnfjörð Bjarmason wrote:

> The Git::Mail::Address file added in bd869f67b9 ("send-email: add and
> use a local copy of Mail::Address", 2018-01-05) had the executable bit
> set, this should not be the case with *.pm files, it breaks nothing,
> but is redundant and confusing as none of the other files have it, and
> it's never executed as a stand-alone program.

Needs a period somewhere to break up the long sentence with comma
splices.  How about:

	The Git::Mail::Address file added in bd869f67b9 ("send-email: add and
	use a local copy of Mail::Address", 2018-01-05) had the executable bit
	set. That bit should not be set for *.pm files. It breaks nothing but
	but it is redundant and confusing as none of the other files have it
	and these files are never executed as stand-alone programs.

> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>

With or without such a tweak,
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

Thanks.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 2/8] perl: move CPAN loader wrappers to another namespace
  2018-02-14 22:21 ` [PATCH 2/8] perl: move CPAN loader wrappers to another namespace Ævar Arnfjörð Bjarmason
@ 2018-02-14 22:43   ` Jonathan Nieder
  0 siblings, 0 replies; 66+ messages in thread
From: Jonathan Nieder @ 2018-02-14 22:43 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep

Ævar Arnfjörð Bjarmason wrote:

> Move the Git::Error and Git::Mail::Address wrappers to the
> Git::LoadCPAN::Loader::* namespace, e.g. Git::LoadCPAN::Error, that
> module will then either load Error from CPAN (if installed on the OS),
> or use Git::FromCPAN::Error.
[...]
> This also makes things a bit less confusing since there was already a
> Git::Error namespace ever since 8b9150e3e3 ("Git.pm: Handle failed
> commands' output", 2006-06-24).
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>

Makes sense.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 3/8] perl: generalize the Git::LoadCPAN facility
  2018-02-14 22:21 ` [PATCH 3/8] perl: generalize the Git::LoadCPAN facility Ævar Arnfjörð Bjarmason
@ 2018-02-14 22:57   ` Jonathan Nieder
  2018-02-15  5:09     ` Todd Zullinger
  2018-02-25 18:56     ` Ævar Arnfjörð Bjarmason
  2018-02-15  4:53   ` Todd Zullinger
  1 sibling, 2 replies; 66+ messages in thread
From: Jonathan Nieder @ 2018-02-14 22:57 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep

Ævar Arnfjörð Bjarmason wrote:

> Change the two wrappers to load from CPAN (local OS) or our own copy
> to do so via the same codepath.

nit: I think with s/to load/that load/ this will be easier to read.

> I added the Error.pm wrapper in 20d2a30f8f ("Makefile: replace
> perl/Makefile.PL with simple make rules", 2017-12-10), and shortly
> afterwards Matthieu Moy added a wrapper for Mail::Address in
> bd869f67b9 ("send-email: add and use a local copy of Mail::Address",
> 2018-01-05).
>
> His was simpler since Mail::Address doesn't have an "import" method,
> but didn't do the same sanity checking, e.g. a missing FromCPAN
> directory (which OS packages are likely not to have) wouldn't be
> explicitly warned about.

I'm having trouble parsing this.  Mail::Address didn't do the same
sanity checking or his didn't?

The comma before e.g. should be a period or semicolon, since it's
starting a new independent clause.

> Now both use a modification of the previously Error.pm-specific
> codepath, which has been amended to take the module to load as
> parameter, as well as whether or not that module has an import method.

Does "now" mean before this patch or after this patch?  Usually
commit messages describe the status quo without the patch in the
present tense and the change the patch will make in the imperative.
So this could say:

	Update both to use a common implementation based on the previous
	Error.pm loader.

[...]
> +++ b/perl/Git/LoadCPAN.pm
> @@ -0,0 +1,74 @@
[...]
> +The Perl code in Git depends on some modules from the CPAN, but we
> +don't want to make those a hard requirement for anyone building from
> +source.

not about this patch: have we considered making it a hard requirement?
Both Mail::Address and Error.pm are pretty widely available, and I
wonder if we could make the instructions in the INSTALL file say that
they are required dependencies to simplify things.

I admit part of my bias here is coming from the distro world, where we
have to do extra work to get rid of the FromCPAN embedded copies and
would be happier not to have to.

[...]
> +Usually OS's will not ship with Git's Git::FromCPAN tree at all,
> +preferring to use their own packaging of CPAN modules instead.

nit: I think the plural of OS is OSes, or something like
"distributors" or "operating systems".

[...]
> +    eval {
> +	require $package_pm;
> +	1;
> +    } or do {

also not about this patch: this mixed tabs/spacing formatting feels a
bit unusual.  I don't know if it's idiomatic for perl, and if it is
then no complaints; it just stood out a little.  Can
Documentation/CodingGuidelines say something about the preferred
indentation in Perl to avoid having to think about such questions?

> --- a/perl/Git/LoadCPAN/Error.pm
> +++ b/perl/Git/LoadCPAN/Error.pm
> @@ -2,45 +2,9 @@ package Git::LoadCPAN::Error;
>  use 5.008;
>  use strict;
>  use warnings;
> +use Git::LoadCPAN (
> +    module => 'Error',
> +    import => 1,
> +);

Nice!

Thanks and hope that helps,
Jonathan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 4/8] perl: update our ancient copy of Error.pm
  2018-02-14 22:21 ` [PATCH 4/8] perl: update our ancient copy of Error.pm Ævar Arnfjörð Bjarmason
@ 2018-02-14 23:03   ` Jonathan Nieder
  2018-02-15 20:46     ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 66+ messages in thread
From: Jonathan Nieder @ 2018-02-14 23:03 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep

Ævar Arnfjörð Bjarmason wrote:

> The Error.pm shipped with Git as a fallback if there was no Error.pm
> on the system was released in April 2006, there's been dozens of
> releases since then, the latest at August 7, 2017, let's update to
> that.

Comma splices:
 s/, there's/. There's/
 s/, let's/. Let's/

The one piece of information I was curious about that this (quite clear,
thank you) commit message is missing is what changed in the intervening
time.  Is this just about keeping up with upstream to make it easy to
keep up later, or has upstream made any useful changes?  E.g. did any
API or behaviors get better?

Related: do we have to worry about in-tree users taking advantage of
improved API and packagers forgetting to add a dependency on the new
version?  Do we declare the minimal required Error.pm version somewhere
(e.g. in the INSTALL file)?

[...]
>  perl/Git/FromCPAN/.gitattributes |   1 +
>  perl/Git/FromCPAN/Error.pm       | 296 +++++++++++++++++++++++++++++++++------
>  2 files changed, 256 insertions(+), 41 deletions(-)
>  create mode 100644 perl/Git/FromCPAN/.gitattributes

Most of the added lines are documentation, so this diffstat doesn't look
half-bad.

Thanks for writing it.

Jonathan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 5/8] perl: update our copy of Mail::Address
  2018-02-14 22:21 ` [PATCH 5/8] perl: update our copy of Mail::Address Ævar Arnfjörð Bjarmason
@ 2018-02-14 23:46   ` Jonathan Nieder
  2018-02-15  9:32     ` Matthieu Moy
  0 siblings, 1 reply; 66+ messages in thread
From: Jonathan Nieder @ 2018-02-14 23:46 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep

Ævar Arnfjörð Bjarmason wrote:

> Update our copy of Mail::Address from 2.19 (Aug 22, 2017) to 2.20 (Jan
> 23, 2018). This should be a trivial update[1] but it seems the version
> Matthieu Moy imported in bd869f67b9 ("send-email: add and use a local
> copy of Mail::Address", 2018-01-05) doesn't correspond to any 2.19
> version found on the CPAN. From the comment at the top of the file it
> looks like some OS version with the POD stripped, and with different
> indentation.

Were there changes other than the POD stripping?

> Let's instead use the upstream version as-is, and without copyright
> notices stripped. Like Error.pm this doesn't cleanly pass --check, so
> add a .gitattributes file to ignore the errors.
>
> 1. https://metacpan.org/diff/file?target=MARKOV/MailTools-2.20/lib%2FMail%2FAddress.pod&source=MARKOV%2FMailTools-2.19%2Flib%2FMail%2FAddress.pod
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  perl/Git/FromCPAN/Mail/.gitattributes |   1 +
>  perl/Git/FromCPAN/Mail/Address.pm     | 436 +++++++++++++---------------------
>  2 files changed, 163 insertions(+), 274 deletions(-)
>  create mode 100644 perl/Git/FromCPAN/Mail/.gitattributes

Yikes re the stripped POD with license notice. Thanks for fixing it.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 6/8] git-send-email: unconditionally use Net::{SMTP,Domain}
  2018-02-14 22:21 ` [PATCH 6/8] git-send-email: unconditionally use Net::{SMTP,Domain} Ævar Arnfjörð Bjarmason
@ 2018-02-14 23:49   ` Jonathan Nieder
  2018-02-15 20:43     ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 66+ messages in thread
From: Jonathan Nieder @ 2018-02-14 23:49 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep

Ævar Arnfjörð Bjarmason wrote:

> The Net::SMTP and Net::Domain were both first released with perl
> v5.7.3, since my d48b284183 ("perl: bump the required Perl version to
> 5.8 from 5.6.[21]", 2010-09-24) we've depended on 5.8, so there's no
> reason to conditionally require this anymore.
>
> This conditional loading was initially added in
> 87840620fd ("send-email: only 'require' instead of 'use' Net::SMTP",
> 2006-06-01) for Net::SMTP and 134550fe21 ("git-send-email.perl - try
> to give real name of the calling host to HELO/EHLO", 2010-03-14) for
> Net::Domain, both of which predate the hard dependency on 5.8.
> 
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  git-send-email.perl | 24 +++++++++++-------------
>  1 file changed, 11 insertions(+), 13 deletions(-)
> 
> diff --git a/git-send-email.perl b/git-send-email.perl
> index 85bb6482f2..69bd443245 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -1143,10 +1143,9 @@ sub valid_fqdn {
>  sub maildomain_net {
>  	my $maildomain;
>  
> -	if (eval { require Net::Domain; 1 }) {
> -		my $domain = Net::Domain::domainname();
> -		$maildomain = $domain if valid_fqdn($domain);
> -	}
> +	require Net::Domain;
> +	my $domain = Net::Domain::domainname();
> +	$maildomain = $domain if valid_fqdn($domain);

Now that we indeed require the module, any reason not to 'use' it?
E.g. is it particularly expensive to load?

I haven't checked the assertions above about minimal perl versions
including these modules, but I assume they're true. :)  So this looks
like a good change.

Thanks,
Jonathan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 7/8] gitweb: hard-depend on the Digest::MD5 5.8 module
  2018-02-14 22:21 ` [PATCH 7/8] gitweb: hard-depend on the Digest::MD5 5.8 module Ævar Arnfjörð Bjarmason
@ 2018-02-14 23:52   ` Jonathan Nieder
  0 siblings, 0 replies; 66+ messages in thread
From: Jonathan Nieder @ 2018-02-14 23:52 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep

Ævar Arnfjörð Bjarmason wrote:

> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  gitweb/INSTALL     |  3 +--
>  gitweb/gitweb.perl | 17 +++++------------
>  2 files changed, 6 insertions(+), 14 deletions(-)

Makes sense, and I like the diffstat.

[...]
> +++ b/gitweb/gitweb.perl
[...]
> @@ -1166,18 +1165,11 @@ sub configure_gitweb_features {
>  	our @snapshot_fmts = gitweb_get_feature('snapshot');
>  	@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
>  
> -	# check that the avatar feature is set to a known provider name,
> -	# and for each provider check if the dependencies are satisfied.
> -	# if the provider name is invalid or the dependencies are not met,
> -	# reset $git_avatar to the empty string.
> +	# check that the avatar feature is set to a known provider
> +	# name, if the provider name is invalid, reset $git_avatar to
> +	# the empty string.

Comma splice.  Formatting as sentences would make this easier to read,
anyway:

	# Check that the avatar feature is set to a known provider name.
	# If the provider name is invalid, reset $git_avatar to the empty
	# string.

Even better would be to remove the comment altogether.  The code is
clear enough on its own and the comment should not be needed now that
it is a one-liner.

[...]
> @@ -2165,6 +2157,7 @@ sub picon_url {
>  sub gravatar_url {
>  	my $email = lc shift;
>  	my $size = shift;
> +	require Digest::MD5;

Same question as the previous patch: how do we decide whether to 'use'
or to 'require' in cases like this?

Thanks,
Jonathan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 8/8] perl: hard-depend on the File::{Temp,Spec} modules
  2018-02-14 22:21 ` [PATCH 8/8] perl: hard-depend on the File::{Temp,Spec} modules Ævar Arnfjörð Bjarmason
@ 2018-02-14 23:54   ` Jonathan Nieder
  2018-02-15 20:42     ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 66+ messages in thread
From: Jonathan Nieder @ 2018-02-14 23:54 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep

Ævar Arnfjörð Bjarmason wrote:

> --- a/perl/Git.pm
> +++ b/perl/Git.pm
> @@ -1324,8 +1324,9 @@ sub _temp_cache {
>  }
>  
>  sub _verify_require {
> -	eval { require File::Temp; require File::Spec; };
> -	$@ and throw Error::Simple($@);
> +	require File::Temp;
> +	require File::Spec;
> +	return;

Same question as in the other patches: any reason not to simplify by
using 'use' at the top of the file instead?

Thanks,
Jonathan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 3/8] perl: generalize the Git::LoadCPAN facility
  2018-02-14 22:21 ` [PATCH 3/8] perl: generalize the Git::LoadCPAN facility Ævar Arnfjörð Bjarmason
  2018-02-14 22:57   ` Jonathan Nieder
@ 2018-02-15  4:53   ` Todd Zullinger
  2018-02-15 20:41     ` Ævar Arnfjörð Bjarmason
  1 sibling, 1 reply; 66+ messages in thread
From: Todd Zullinger @ 2018-02-15  4:53 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep

Hi Ævar,

Ævar Arnfjörð Bjarmason wrote:
> +Git::LoadCPAN - Wrapper for loading modules from the CPAN (OS) or Git's own copy
> +
> +=head1 DESCRIPTION
> +
> +The Perl code in Git depends on some modules from the CPAN, but we
> +don't want to make those a hard requirement for anyone building from
> +source.
> +
> +Therefore the L<Git::LoadCPAN> namespace shipped with Git contains
> +wrapper modules like C<Git::LoadCPAN::Module::Name> that will first
> +attempt to load C<Module::Name> from the OS, and if that doesn't work
> +will fall back on C<Git::FromCPAN::Module::Name> shipped with Git
> +itself.
> +
> +Usually OS's will not ship with Git's Git::FromCPAN tree at all,
> +preferring to use their own packaging of CPAN modules instead.

This is something I wondered about.  What's the recommended
method to ensure git packaged for an OS/distribution doesn't
ever use the fallbacks?  Remove $perllibdir/Git/FromCPAN
after make install?

If so, would it be useful to add a Makefile knob to not
install the FromCPAN bits, which may be generally useful to
packagers?

Something like the following, perhaps?

(I'd feel bad suggesting this without a patch, after all the
work you've already done to simplify and improve the perl
bits.)

---- 8< ----
From: Todd Zullinger <tmz@pobox.com>
Date: Wed, 14 Feb 2018 23:00:30 -0500
Subject: [PATCH] Makefile: add NO_PERL_CPAN to disable fallback module install

As noted in perl/Git/LoadCPAN.pm, operating system packages often don't
want to ship Git::FromCPAN tree at all, preferring to use their own
packaging of CPAN modules instead.  Allow such packagers to set
NO_PERL_CPAN to easily avoid installing these fallback perl CPAN
modules.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
---
 Makefile | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Makefile b/Makefile
index 5bcd83ddf3..c4e035e5bf 100644
--- a/Makefile
+++ b/Makefile
@@ -296,6 +296,9 @@ all::
 #
 # Define NO_PERL if you do not want Perl scripts or libraries at all.
 #
+# Define NO_PERL_CPAN if you do not want to install fallbacks for perl CPAN
+# modules.
+#
 # Define PYTHON_PATH to the path of your Python binary (often /usr/bin/python
 # but /usr/bin/python2.7 on some platforms).
 #
@@ -2572,6 +2575,7 @@ ifndef NO_GETTEXT
 endif
 ifndef NO_PERL
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perllibdir_SQ)'
+	test -z "$(NO_PERL_CPAN)" || rm -rf perl/build/lib/Git/FromCPAN
 	(cd perl/build/lib && $(TAR) cf - .) | \
 	(cd '$(DESTDIR_SQ)$(perllibdir_SQ)' && umask 022 && $(TAR) xof -)
 	$(MAKE) -C gitweb install
-- 
2.16.1

I don't particularly like NO_PERL_CPAN, but I'm confident
someone else will suggest an obviously better name.

I thought about moving the 'rm -rf Git/FromCPAN' after the
tar/untar, to keep the files in place for the tests.  No
tests seem to rely on those local files, so I stuck with
removing them before.  That diff was:

--- a/Makefile
+++ b/Makefile
@@ -2574,6 +2574,7 @@
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perllibdir_SQ)'
 	(cd perl/build/lib && $(TAR) cf - .) | \
 	(cd '$(DESTDIR_SQ)$(perllibdir_SQ)' && umask 022 && $(TAR) xof -)
+	test -n "$(NO_PERL_CPAN)" && rm -rf '$(DESTDIR_SQ)$(perllibdir_SQ)'/Git/FromCPAN
 	$(MAKE) -C gitweb install
 endif
 ifndef NO_TCLTK

-- 
Todd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Man has made use of his intelligence, he invented stupidity.
    -- Remy De Gourmant


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* Re: [PATCH 3/8] perl: generalize the Git::LoadCPAN facility
  2018-02-14 22:57   ` Jonathan Nieder
@ 2018-02-15  5:09     ` Todd Zullinger
  2018-02-25 18:56     ` Ævar Arnfjörð Bjarmason
  1 sibling, 0 replies; 66+ messages in thread
From: Todd Zullinger @ 2018-02-15  5:09 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Ævar Arnfjörð Bjarmason, git, Junio C Hamano,
	Matthieu Moy, Petr Baudis, Jeff King, Johannes Schindelin,
	Jari Aalto, Giuseppe Bilotta, Marcus Griep

Hi Jonathan,

Jonathan Nieder wrote:
> Ævar Arnfjörð Bjarmason wrote:
> [...]
>> +++ b/perl/Git/LoadCPAN.pm
>> @@ -0,0 +1,74 @@
> [...]
>> +The Perl code in Git depends on some modules from the CPAN, but we
>> +don't want to make those a hard requirement for anyone building from
>> +source.
> 
> not about this patch: have we considered making it a hard requirement?
> Both Mail::Address and Error.pm are pretty widely available, and I
> wonder if we could make the instructions in the INSTALL file say that
> they are required dependencies to simplify things.
> 
> I admit part of my bias here is coming from the distro world, where we
> have to do extra work to get rid of the FromCPAN embedded copies and
> would be happier not to have to.

Heh, a similar bias is what led me to suggest a Makefile
knob to prevent installing the fallbacks.  I neglected to
add you to the Cc list on that reply.  But I was thinking of
Debian and other distributions whom I know would similarly
want to exclude Git/FromCPAN from their git packages.  I
know it's a simple rm, but it might as well be a simple rm
in one place than spread across each package.  :)

It may still be worth considering whether it's reasonable to
make Mail::Address and Error.pm hard requirements, but I'm
not sure if there are any platforms where such a requirement
would be a pain.  If there are folks here who are happy to
maintain this fallback method, then a simple Makefile knob
gives us the best of both worlds.

-- 
Todd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Historian, n. A broad-gauge gossip.
    -- Ambrose Bierce, "The Devil's Dictionary"


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 5/8] perl: update our copy of Mail::Address
  2018-02-14 23:46   ` Jonathan Nieder
@ 2018-02-15  9:32     ` Matthieu Moy
  2018-02-15 20:31       ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 66+ messages in thread
From: Matthieu Moy @ 2018-02-15  9:32 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Ævar Arnfjörð Bjarmason, Git Mailing List,
	Junio C Hamano, Petr Baudis, Benoit Bourbie, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Marcus Griep

"Jonathan Nieder" <jrnieder@gmail.com> wrote:

> Ævar Arnfjörð Bjarmason wrote:
>
> > Update our copy of Mail::Address from 2.19 (Aug 22, 2017) to 2.20 (Jan
> > 23, 2018). This should be a trivial update[1] but it seems the version
> > Matthieu Moy imported in bd869f67b9 ("send-email: add and use a local
> > copy of Mail::Address", 2018-01-05) doesn't correspond to any 2.19
> > version found on the CPAN. From the comment at the top of the file it
> > looks like some OS version with the POD stripped, and with different
> > indentation.
>
> Were there changes other than the POD stripping?

No.

I should have mentionned it in the commit message, but the one I took was
from:

  http://cpansearch.perl.org/src/MARKOV/MailTools-2.19/lib/Mail/Address.pm

i.e. following the "source" link from:

  http://search.cpan.org/~markov/MailTools-2.19/lib/Mail/Address.pod

The link name suggested it was the actual source code but indeed it's a
pre-processed file with the POD stripped.

It would make sense to indicate explicitly where this file is from in
this commit's message to avoid having the same discussion next time someone
upgrades the package.

-- 
Matthieu Moy
https://matthieu-moy.fr/

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 5/8] perl: update our copy of Mail::Address
  2018-02-15  9:32     ` Matthieu Moy
@ 2018-02-15 20:31       ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-15 20:31 UTC (permalink / raw)
  To: Matthieu Moy
  Cc: Jonathan Nieder, Git Mailing List, Junio C Hamano, Petr Baudis,
	Benoit Bourbie, Jeff King, Johannes Schindelin, Jari Aalto,
	Giuseppe Bilotta, Marcus Griep


On Thu, Feb 15 2018, Matthieu Moy jotted:

> "Jonathan Nieder" <jrnieder@gmail.com> wrote:
>
>> Ævar Arnfjörð Bjarmason wrote:
>>
>> > Update our copy of Mail::Address from 2.19 (Aug 22, 2017) to 2.20 (Jan
>> > 23, 2018). This should be a trivial update[1] but it seems the version
>> > Matthieu Moy imported in bd869f67b9 ("send-email: add and use a local
>> > copy of Mail::Address", 2018-01-05) doesn't correspond to any 2.19
>> > version found on the CPAN. From the comment at the top of the file it
>> > looks like some OS version with the POD stripped, and with different
>> > indentation.
>>
>> Were there changes other than the POD stripping?
>
> No.
>
> I should have mentionned it in the commit message, but the one I took was
> from:
>
>   http://cpansearch.perl.org/src/MARKOV/MailTools-2.19/lib/Mail/Address.pm
>
> i.e. following the "source" link from:
>
>   http://search.cpan.org/~markov/MailTools-2.19/lib/Mail/Address.pod
>
> The link name suggested it was the actual source code but indeed it's a
> pre-processed file with the POD stripped.
>
> It would make sense to indicate explicitly where this file is from in
> this commit's message to avoid having the same discussion next time someone
> upgrades the package.

I see that I'm being a complete idiot and added the *.pod file in the
distro instead of the *.pm file, I got it from metacpan and didn't check
it carefully enough (and only tested with system Error.pm removed, not
Mail::Address), sorry. So yours was the right version. Will fix in a
re-roll.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 3/8] perl: generalize the Git::LoadCPAN facility
  2018-02-15  4:53   ` Todd Zullinger
@ 2018-02-15 20:41     ` Ævar Arnfjörð Bjarmason
  2018-02-15 21:23       ` Todd Zullinger
  0 siblings, 1 reply; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-15 20:41 UTC (permalink / raw)
  To: Todd Zullinger
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep


On Thu, Feb 15 2018, Todd Zullinger jotted:

> Hi Ævar,
>
> Ævar Arnfjörð Bjarmason wrote:
>> +Git::LoadCPAN - Wrapper for loading modules from the CPAN (OS) or Git's own copy
>> +
>> +=head1 DESCRIPTION
>> +
>> +The Perl code in Git depends on some modules from the CPAN, but we
>> +don't want to make those a hard requirement for anyone building from
>> +source.
>> +
>> +Therefore the L<Git::LoadCPAN> namespace shipped with Git contains
>> +wrapper modules like C<Git::LoadCPAN::Module::Name> that will first
>> +attempt to load C<Module::Name> from the OS, and if that doesn't work
>> +will fall back on C<Git::FromCPAN::Module::Name> shipped with Git
>> +itself.
>> +
>> +Usually OS's will not ship with Git's Git::FromCPAN tree at all,
>> +preferring to use their own packaging of CPAN modules instead.
>
> This is something I wondered about.  What's the recommended
> method to ensure git packaged for an OS/distribution doesn't
> ever use the fallbacks?  Remove $perllibdir/Git/FromCPAN
> after make install?
>
> If so, would it be useful to add a Makefile knob to not
> install the FromCPAN bits, which may be generally useful to
> packagers?
>
> Something like the following, perhaps?
>
> (I'd feel bad suggesting this without a patch, after all the
> work you've already done to simplify and improve the perl
> bits.)
>
> ---- 8< ----
> From: Todd Zullinger <tmz@pobox.com>
> Date: Wed, 14 Feb 2018 23:00:30 -0500
> Subject: [PATCH] Makefile: add NO_PERL_CPAN to disable fallback module install
>
> As noted in perl/Git/LoadCPAN.pm, operating system packages often don't
> want to ship Git::FromCPAN tree at all, preferring to use their own
> packaging of CPAN modules instead.  Allow such packagers to set
> NO_PERL_CPAN to easily avoid installing these fallback perl CPAN
> modules.
>
> Signed-off-by: Todd Zullinger <tmz@pobox.com>
> ---
>  Makefile | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/Makefile b/Makefile
> index 5bcd83ddf3..c4e035e5bf 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -296,6 +296,9 @@ all::
>  #
>  # Define NO_PERL if you do not want Perl scripts or libraries at all.
>  #
> +# Define NO_PERL_CPAN if you do not want to install fallbacks for perl CPAN
> +# modules.
> +#
>  # Define PYTHON_PATH to the path of your Python binary (often /usr/bin/python
>  # but /usr/bin/python2.7 on some platforms).
>  #
> @@ -2572,6 +2575,7 @@ ifndef NO_GETTEXT
>  endif
>  ifndef NO_PERL
>  	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perllibdir_SQ)'
> +	test -z "$(NO_PERL_CPAN)" || rm -rf perl/build/lib/Git/FromCPAN
>  	(cd perl/build/lib && $(TAR) cf - .) | \
>  	(cd '$(DESTDIR_SQ)$(perllibdir_SQ)' && umask 022 && $(TAR) xof -)
>  	$(MAKE) -C gitweb install
> --
> 2.16.1
>
> I don't particularly like NO_PERL_CPAN, but I'm confident
> someone else will suggest an obviously better name.
>
> I thought about moving the 'rm -rf Git/FromCPAN' after the
> tar/untar, to keep the files in place for the tests.  No
> tests seem to rely on those local files, so I stuck with
> removing them before.  That diff was:
>
> --- a/Makefile
> +++ b/Makefile
> @@ -2574,6 +2574,7 @@
>  	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perllibdir_SQ)'
>  	(cd perl/build/lib && $(TAR) cf - .) | \
>  	(cd '$(DESTDIR_SQ)$(perllibdir_SQ)' && umask 022 && $(TAR) xof -)
> +	test -n "$(NO_PERL_CPAN)" && rm -rf '$(DESTDIR_SQ)$(perllibdir_SQ)'/Git/FromCPAN
>  	$(MAKE) -C gitweb install
>  endif
>  ifndef NO_TCLTK

That makes sense, I'll incorporate that in a re-roll. I like
NO_PERL_CPAN_FALLBACKS or just NO_CPAN_FALLBACKS better.

I'd really like to find some solution that works differently though,
because with this approach we'll run the full test suite against a
system where our fallbacks will be in place (although if the OS
distributor has done as promised we won't use them), and then just
remove this at 'make install' time, also meaning we'll re-gen it before
running 'make install' again, only to rm it again.

The former issue we could deal with by munging the Git::LoadCPAN file so
it knows about NO_PERL_CPAN_FALLBACKS, and will always refuse to use the
fallbacks if that's set. That's a good idea anyway, because right now if
you e.g. uninstall Error.pm on Debian (which strips the CPAN fallbacks)
you get a cryptic "BUG: ..." message, it should instead say "we couldn't
get this module the OS promised we'd have" or something to that effect.

The latter is trickier, I don't see an easy way to coerce the Makefile
into not copying the FromCPAN directory without going back to a
hardcoded list again, the easiest thing is probably to turn that:

    $(TAR) cf - .)

Into:

    $(TAR) cf - $(find ... -not ....)

Or something like that to get all the stuff that isn't the Git/FromCPAN
directory.

Other suggestions most welcome.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 8/8] perl: hard-depend on the File::{Temp,Spec} modules
  2018-02-14 23:54   ` Jonathan Nieder
@ 2018-02-15 20:42     ` Ævar Arnfjörð Bjarmason
  2018-02-15 21:33       ` Junio C Hamano
  0 siblings, 1 reply; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-15 20:42 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep


On Wed, Feb 14 2018, Jonathan Nieder jotted:

> Ævar Arnfjörð Bjarmason wrote:
>
>> --- a/perl/Git.pm
>> +++ b/perl/Git.pm
>> @@ -1324,8 +1324,9 @@ sub _temp_cache {
>>  }
>>
>>  sub _verify_require {
>> -	eval { require File::Temp; require File::Spec; };
>> -	$@ and throw Error::Simple($@);
>> +	require File::Temp;
>> +	require File::Spec;
>> +	return;
>
> Same question as in the other patches: any reason not to simplify by
> using 'use' at the top of the file instead?

I was just going for the minimal change, but yeah, that makes
sense. Will do that in v2.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 6/8] git-send-email: unconditionally use Net::{SMTP,Domain}
  2018-02-14 23:49   ` Jonathan Nieder
@ 2018-02-15 20:43     ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-15 20:43 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep


On Wed, Feb 14 2018, Jonathan Nieder jotted:

> Ævar Arnfjörð Bjarmason wrote:
>
>> The Net::SMTP and Net::Domain were both first released with perl
>> v5.7.3, since my d48b284183 ("perl: bump the required Perl version to
>> 5.8 from 5.6.[21]", 2010-09-24) we've depended on 5.8, so there's no
>> reason to conditionally require this anymore.
>>
>> This conditional loading was initially added in
>> 87840620fd ("send-email: only 'require' instead of 'use' Net::SMTP",
>> 2006-06-01) for Net::SMTP and 134550fe21 ("git-send-email.perl - try
>> to give real name of the calling host to HELO/EHLO", 2010-03-14) for
>> Net::Domain, both of which predate the hard dependency on 5.8.
>>
>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> ---
>>  git-send-email.perl | 24 +++++++++++-------------
>>  1 file changed, 11 insertions(+), 13 deletions(-)
>>
>> diff --git a/git-send-email.perl b/git-send-email.perl
>> index 85bb6482f2..69bd443245 100755
>> --- a/git-send-email.perl
>> +++ b/git-send-email.perl
>> @@ -1143,10 +1143,9 @@ sub valid_fqdn {
>>  sub maildomain_net {
>>  	my $maildomain;
>>
>> -	if (eval { require Net::Domain; 1 }) {
>> -		my $domain = Net::Domain::domainname();
>> -		$maildomain = $domain if valid_fqdn($domain);
>> -	}
>> +	require Net::Domain;
>> +	my $domain = Net::Domain::domainname();
>> +	$maildomain = $domain if valid_fqdn($domain);
>
> Now that we indeed require the module, any reason not to 'use' it?
> E.g. is it particularly expensive to load?
>
> I haven't checked the assertions above about minimal perl versions
> including these modules, but I assume they're true. :)  So this looks
> like a good change.

FWIW this is easily found out for any given module by running `corelist
<module name>` on a system with perl installed:

    $ corelist File::Spec
    Data for 2017-01-14
    File::Spec was first released with perl 5.00405

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 4/8] perl: update our ancient copy of Error.pm
  2018-02-14 23:03   ` Jonathan Nieder
@ 2018-02-15 20:46     ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-15 20:46 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep


On Wed, Feb 14 2018, Jonathan Nieder jotted:

> Ævar Arnfjörð Bjarmason wrote:
>
>> The Error.pm shipped with Git as a fallback if there was no Error.pm
>> on the system was released in April 2006, there's been dozens of
>> releases since then, the latest at August 7, 2017, let's update to
>> that.
>
> Comma splices:
>  s/, there's/. There's/
>  s/, let's/. Let's/
>
> The one piece of information I was curious about that this (quite clear,
> thank you) commit message is missing is what changed in the intervening
> time.  Is this just about keeping up with upstream to make it easy to
> keep up later, or has upstream made any useful changes?  E.g. did any
> API or behaviors get better?

Will note that in v2, nothing we need changed, this is just a matter of
keeping up, and e.g. if I run Git on Debian I get a few month old
Error.pm, but if I build Git from source I get one that's more than a
decade old.

> Related: do we have to worry about in-tree users taking advantage of
> improved API and packagers forgetting to add a dependency on the new
> version?  Do we declare the minimal required Error.pm version somewhere
> (e.g. in the INSTALL file)?

We don't, but if that situation arises we could just start doing 'use
<module> <version>' to declare it, see "perldoc -f use", but right now
we work on seemingly every version of these modules ever released.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 3/8] perl: generalize the Git::LoadCPAN facility
  2018-02-15 20:41     ` Ævar Arnfjörð Bjarmason
@ 2018-02-15 21:23       ` Todd Zullinger
  2018-02-16 14:39         ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 66+ messages in thread
From: Todd Zullinger @ 2018-02-15 21:23 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Marcus Griep

[I dropped bbourbie@slb.com from the Cc: list, as it bounced
on my previous reply.]

Ævar Arnfjörð Bjarmason wrote:
> That makes sense, I'll incorporate that in a re-roll. I like
> NO_PERL_CPAN_FALLBACKS or just NO_CPAN_FALLBACKS better.

Either is an improvement.  Starting with NO_PERL_ seems
like a slightly better bikeshed color. :)

> I'd really like to find some solution that works differently though,
> because with this approach we'll run the full test suite against a
> system where our fallbacks will be in place (although if the OS
> distributor has done as promised we won't use them), and then just
> remove this at 'make install' time, also meaning we'll re-gen it before
> running 'make install' again, only to rm it again.
> 
> The former issue we could deal with by munging the Git::LoadCPAN file so
> it knows about NO_PERL_CPAN_FALLBACKS, and will always refuse to use the
> fallbacks if that's set. That's a good idea anyway, because right now if
> you e.g. uninstall Error.pm on Debian (which strips the CPAN fallbacks)
> you get a cryptic "BUG: ..." message, it should instead say "we couldn't
> get this module the OS promised we'd have" or something to that effect.

Teaching Git::LoadCPAN to never fallback sounds like a good
idea.  At least then if the packager intended to avoid the
fallbacks and didn't get it right the error message could be
more useful.

Hopefully that's not a common problem for packagers though.
(And adding the Makefile knob was intended to help make it
easier for packagers to achieve this common goal.)

> The latter is trickier, I don't see an easy way to coerce the Makefile
> into not copying the FromCPAN directory without going back to a
> hardcoded list again, the easiest thing is probably to turn that:
> 
>     $(TAR) cf - .)
> 
> Into:
> 
>     $(TAR) cf - $(find ... -not ....)
> 
> Or something like that to get all the stuff that isn't the Git/FromCPAN
> directory.
> 
> Other suggestions most welcome.

What about moving perl/Git/FromCPAN to perl/FromCPAN and
then including perl/FromCPAN in LIB_PERL{,_GEN} only if
NO_PERL_CPAN_FALLBACKS is unset?

 LIB_PERL := $(wildcard perl/Git.pm perl/Git/*.pm perl/Git/*/*.pm perl/Git/*/*/*.pm)
+ifndef NO_PERL_CPAN_FALLBACKS
+LIB_PERL += $(wildcard perl/FromCPAN/*.pm perl/FromCPAN/*/*.pm)
+endif
 LIB_PERL_GEN := $(patsubst perl/%.pm,perl/build/lib/%.pm,$(LIB_PERL))

I haven't tested that at all, so it could be broken in many
ways.

Thanks,

-- 
Todd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The nice thing about egotists is that they don't talk about other
people.
    -- Lucille S. Harper


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 8/8] perl: hard-depend on the File::{Temp,Spec} modules
  2018-02-15 20:42     ` Ævar Arnfjörð Bjarmason
@ 2018-02-15 21:33       ` Junio C Hamano
  0 siblings, 0 replies; 66+ messages in thread
From: Junio C Hamano @ 2018-02-15 21:33 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Jonathan Nieder, git, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> On Wed, Feb 14 2018, Jonathan Nieder jotted:
>
>> Ævar Arnfjörð Bjarmason wrote:
>>
>>> --- a/perl/Git.pm
>>> +++ b/perl/Git.pm
>>> @@ -1324,8 +1324,9 @@ sub _temp_cache {
>>>  }
>>>
>>>  sub _verify_require {
>>> -	eval { require File::Temp; require File::Spec; };
>>> -	$@ and throw Error::Simple($@);
>>> +	require File::Temp;
>>> +	require File::Spec;
>>> +	return;
>>
>> Same question as in the other patches: any reason not to simplify by
>> using 'use' at the top of the file instead?
>
> I was just going for the minimal change, but yeah, that makes
> sense. Will do that in v2.

Yes, if we are making them hard dependency, unless a major part of
the perl/Git.pm can be used without hitting _verify_require in the
current code, there is no point using "require only if we use it"
pattern.  As _verify_require is used even in the Git::repository
constructor, I think it makes more sense to have "use" upfront for
these two modules.


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 3/8] perl: generalize the Git::LoadCPAN facility
  2018-02-15 21:23       ` Todd Zullinger
@ 2018-02-16 14:39         ` Ævar Arnfjörð Bjarmason
  2018-02-16 17:55           ` Todd Zullinger
  0 siblings, 1 reply; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-16 14:39 UTC (permalink / raw)
  To: Todd Zullinger
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Marcus Griep


On Thu, Feb 15 2018, Todd Zullinger jotted:

> [I dropped bbourbie@slb.com from the Cc: list, as it bounced
> on my previous reply.]
>
> Ævar Arnfjörð Bjarmason wrote:
>> That makes sense, I'll incorporate that in a re-roll. I like
>> NO_PERL_CPAN_FALLBACKS or just NO_CPAN_FALLBACKS better.
>
> Either is an improvement.  Starting with NO_PERL_ seems
> like a slightly better bikeshed color. :)
>
>> I'd really like to find some solution that works differently though,
>> because with this approach we'll run the full test suite against a
>> system where our fallbacks will be in place (although if the OS
>> distributor has done as promised we won't use them), and then just
>> remove this at 'make install' time, also meaning we'll re-gen it before
>> running 'make install' again, only to rm it again.
>>
>> The former issue we could deal with by munging the Git::LoadCPAN file so
>> it knows about NO_PERL_CPAN_FALLBACKS, and will always refuse to use the
>> fallbacks if that's set. That's a good idea anyway, because right now if
>> you e.g. uninstall Error.pm on Debian (which strips the CPAN fallbacks)
>> you get a cryptic "BUG: ..." message, it should instead say "we couldn't
>> get this module the OS promised we'd have" or something to that effect.
>
> Teaching Git::LoadCPAN to never fallback sounds like a good
> idea.  At least then if the packager intended to avoid the
> fallbacks and didn't get it right the error message could be
> more useful.
>
> Hopefully that's not a common problem for packagers though.
> (And adding the Makefile knob was intended to help make it
> easier for packagers to achieve this common goal.)
>
>> The latter is trickier, I don't see an easy way to coerce the Makefile
>> into not copying the FromCPAN directory without going back to a
>> hardcoded list again, the easiest thing is probably to turn that:
>>
>>     $(TAR) cf - .)
>>
>> Into:
>>
>>     $(TAR) cf - $(find ... -not ....)
>>
>> Or something like that to get all the stuff that isn't the Git/FromCPAN
>> directory.
>>
>> Other suggestions most welcome.
>
> What about moving perl/Git/FromCPAN to perl/FromCPAN and
> then including perl/FromCPAN in LIB_PERL{,_GEN} only if
> NO_PERL_CPAN_FALLBACKS is unset?
>
>  LIB_PERL := $(wildcard perl/Git.pm perl/Git/*.pm perl/Git/*/*.pm perl/Git/*/*/*.pm)
> +ifndef NO_PERL_CPAN_FALLBACKS
> +LIB_PERL += $(wildcard perl/FromCPAN/*.pm perl/FromCPAN/*/*.pm)
> +endif
>  LIB_PERL_GEN := $(patsubst perl/%.pm,perl/build/lib/%.pm,$(LIB_PERL))
>
> I haven't tested that at all, so it could be broken in many
> ways.

Yes that's a much better idea, it evades the whole problem of conflating
the perl/Git* glob.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 3/8] perl: generalize the Git::LoadCPAN facility
  2018-02-16 14:39         ` Ævar Arnfjörð Bjarmason
@ 2018-02-16 17:55           ` Todd Zullinger
  2018-02-16 22:03             ` Jonathan Nieder
  0 siblings, 1 reply; 66+ messages in thread
From: Todd Zullinger @ 2018-02-16 17:55 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Marcus Griep

Ævar Arnfjörð Bjarmason wrote:
> On Thu, Feb 15 2018, Todd Zullinger jotted:
>> What about moving perl/Git/FromCPAN to perl/FromCPAN and
>> then including perl/FromCPAN in LIB_PERL{,_GEN} only if
>> NO_PERL_CPAN_FALLBACKS is unset?
>>
>>  LIB_PERL := $(wildcard perl/Git.pm perl/Git/*.pm perl/Git/*/*.pm perl/Git/*/*/*.pm)
>> +ifndef NO_PERL_CPAN_FALLBACKS
>> +LIB_PERL += $(wildcard perl/FromCPAN/*.pm perl/FromCPAN/*/*.pm)
>> +endif
>>  LIB_PERL_GEN := $(patsubst perl/%.pm,perl/build/lib/%.pm,$(LIB_PERL))
>>
>> I haven't tested that at all, so it could be broken in many
>> ways.
> 
> Yes that's a much better idea, it evades the whole problem of conflating
> the perl/Git* glob.

I did test this yesterday and it seems to work well.  Here
it is in patch form, in case it's helpful to you for the
next version.  It might well be better as part of a commit
teaching Git::LoadCPAN to respect NO_PERL_CPAN_FALLBACKS.

---- 8< ----
From: Todd Zullinger <tmz@pobox.com>
Subject: [PATCH] Makefile: add NO_PERL_CPAN_FALLBACKS to disable fallback
 module install

As noted in perl/Git/LoadCPAN.pm, operating system packages often don't
want to ship Git::FromCPAN tree at all, preferring to use their own
packaging of CPAN modules instead.  Allow such packagers to set
NO_PERL_CPAN_FALLBACKS to easily avoid installing these fallback perl
CPAN modules.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
---
 Makefile                                    | 6 ++++++
 perl/{Git => }/FromCPAN/.gitattributes      | 0
 perl/{Git => }/FromCPAN/Error.pm            | 0
 perl/{Git => }/FromCPAN/Mail/.gitattributes | 0
 perl/{Git => }/FromCPAN/Mail/Address.pm     | 0
 5 files changed, 6 insertions(+)
 rename perl/{Git => }/FromCPAN/.gitattributes (100%)
 rename perl/{Git => }/FromCPAN/Error.pm (100%)
 rename perl/{Git => }/FromCPAN/Mail/.gitattributes (100%)
 rename perl/{Git => }/FromCPAN/Mail/Address.pm (100%)

diff --git a/Makefile b/Makefile
index 5bcd83ddf3..838b3c6393 100644
--- a/Makefile
+++ b/Makefile
@@ -296,6 +296,9 @@ all::
 #
 # Define NO_PERL if you do not want Perl scripts or libraries at all.
 #
+# Define NO_PERL_CPAN_FALLBACKS if you do not want to install fallbacks for
+# perl CPAN modules.
+#
 # Define PYTHON_PATH to the path of your Python binary (often /usr/bin/python
 # but /usr/bin/python2.7 on some platforms).
 #
@@ -2297,6 +2300,9 @@ po/build/locale/%/LC_MESSAGES/git.mo: po/%.po
 	$(QUIET_MSGFMT)mkdir -p $(dir $@) && $(MSGFMT) -o $@ $<
 
 LIB_PERL := $(wildcard perl/Git.pm perl/Git/*.pm perl/Git/*/*.pm perl/Git/*/*/*.pm)
+ifndef NO_PERL_CPAN_FALLBACKS
+LIB_PERL += $(wildcard perl/FromCPAN/*.pm perl/FromCPAN/*/*.pm)
+endif
 LIB_PERL_GEN := $(patsubst perl/%.pm,perl/build/lib/%.pm,$(LIB_PERL))
 
 ifndef NO_PERL
diff --git a/perl/Git/FromCPAN/.gitattributes b/perl/FromCPAN/.gitattributes
similarity index 100%
rename from perl/Git/FromCPAN/.gitattributes
rename to perl/FromCPAN/.gitattributes
diff --git a/perl/Git/FromCPAN/Error.pm b/perl/FromCPAN/Error.pm
similarity index 100%
rename from perl/Git/FromCPAN/Error.pm
rename to perl/FromCPAN/Error.pm
diff --git a/perl/Git/FromCPAN/Mail/.gitattributes b/perl/FromCPAN/Mail/.gitattributes
similarity index 100%
rename from perl/Git/FromCPAN/Mail/.gitattributes
rename to perl/FromCPAN/Mail/.gitattributes
diff --git a/perl/Git/FromCPAN/Mail/Address.pm b/perl/FromCPAN/Mail/Address.pm
similarity index 100%
rename from perl/Git/FromCPAN/Mail/Address.pm
rename to perl/FromCPAN/Mail/Address.pm
-- 
2.16.1

-- 
Todd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Damn you and your estrogenical treachery!
    -- Stewie Griffin


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* Re: [PATCH 3/8] perl: generalize the Git::LoadCPAN facility
  2018-02-16 17:55           ` Todd Zullinger
@ 2018-02-16 22:03             ` Jonathan Nieder
  2018-02-17  0:47               ` Todd Zullinger
  0 siblings, 1 reply; 66+ messages in thread
From: Jonathan Nieder @ 2018-02-16 22:03 UTC (permalink / raw)
  To: Todd Zullinger
  Cc: Ævar Arnfjörð Bjarmason, git, Junio C Hamano,
	Matthieu Moy, Petr Baudis, Jeff King, Johannes Schindelin,
	Jari Aalto, Giuseppe Bilotta, Marcus Griep

Hi,

Todd Zullinger wrote:

> Subject: [PATCH] Makefile: add NO_PERL_CPAN_FALLBACKS to disable fallback module install
>
> As noted in perl/Git/LoadCPAN.pm, operating system packages often don't
> want to ship Git::FromCPAN tree at all, preferring to use their own
> packaging of CPAN modules instead.  Allow such packagers to set
> NO_PERL_CPAN_FALLBACKS to easily avoid installing these fallback perl
> CPAN modules.
>
> Signed-off-by: Todd Zullinger <tmz@pobox.com>
> ---
>  Makefile                                    | 6 ++++++
>  perl/{Git => }/FromCPAN/.gitattributes      | 0
>  perl/{Git => }/FromCPAN/Error.pm            | 0
>  perl/{Git => }/FromCPAN/Mail/.gitattributes | 0
>  perl/{Git => }/FromCPAN/Mail/Address.pm     | 0
>  5 files changed, 6 insertions(+)
>  rename perl/{Git => }/FromCPAN/.gitattributes (100%)
>  rename perl/{Git => }/FromCPAN/Error.pm (100%)
>  rename perl/{Git => }/FromCPAN/Mail/.gitattributes (100%)
>  rename perl/{Git => }/FromCPAN/Mail/Address.pm (100%)

Nice!  I like it.

[...]
> +++ b/Makefile
> @@ -296,6 +296,9 @@ all::
>  #
>  # Define NO_PERL if you do not want Perl scripts or libraries at all.
>  #
> +# Define NO_PERL_CPAN_FALLBACKS if you do not want to install fallbacks for
> +# perl CPAN modules.

nit: Looking at this as a naive user, it's not obvious what kind of
fallbacks are meant. How about:

	Define NO_PERL_CPAN_FALLBACKS if you do not want to install bundled
	copies of CPAN modules that serve as a fallback in case the modules are
	not available on the system.

Or perhaps:

	Define HAVE_CPAN_MODULES if you have Error.pm and Mail::Address installed
	and do not want to install the fallback copies from perl/FromCPAN.

Would this patch need to update the loader to expect the modules in
the new location?

Thanks,
Jonathan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 3/8] perl: generalize the Git::LoadCPAN facility
  2018-02-16 22:03             ` Jonathan Nieder
@ 2018-02-17  0:47               ` Todd Zullinger
  2018-02-17  5:40                 ` Todd Zullinger
  0 siblings, 1 reply; 66+ messages in thread
From: Todd Zullinger @ 2018-02-17  0:47 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Ævar Arnfjörð Bjarmason, git, Junio C Hamano,
	Matthieu Moy, Petr Baudis, Jeff King, Johannes Schindelin,
	Jari Aalto, Giuseppe Bilotta, Marcus Griep

Hi Jonathan,

Jonathan Nieder wrote:
> Todd Zullinger wrote:
[...]
>> +++ b/Makefile
>> @@ -296,6 +296,9 @@ all::
>>  #
>>  # Define NO_PERL if you do not want Perl scripts or libraries at all.
>>  #
>> +# Define NO_PERL_CPAN_FALLBACKS if you do not want to install fallbacks for
>> +# perl CPAN modules.
> 
> nit: Looking at this as a naive user, it's not obvious what kind of
> fallbacks are meant. How about:
> 
> 	Define NO_PERL_CPAN_FALLBACKS if you do not want to install bundled
> 	copies of CPAN modules that serve as a fallback in case the modules are
> 	not available on the system.
> 
> Or perhaps:
> 
> 	Define HAVE_CPAN_MODULES if you have Error.pm and Mail::Address installed
> 	and do not want to install the fallback copies from perl/FromCPAN.

Hmm, a positive variable like HAVE_CPAN_MODULES is
appealing.

I don't know about listing the modules, as those seem likely
to change and then the comment becomes stale.  It's nice to
have a shorter name.  I could easily go back and forth.
Hopefully some other folks will chime in with preferences.

> Would this patch need to update the loader to expect the modules in
> the new location?

That's a good catch.  In checking how this ends up when not
setting NO_PERL_CPAN_FALLBACKS, we end up installing
FromCPAN at the root of $perllibdir rather than under the
Git dir.

While we could probably fix Git::LoadCPAN, I doubt we want
to pollute the namespace. ;) So we'll want to ensure the
files get put in the right place from the start.  I'll try
to fix that up.

Thanks for the careful eyes, as usual.

-- 
Todd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Happiness is like peeing on yourself. Everyone can see it, but only
you can feel its warmth


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 3/8] perl: generalize the Git::LoadCPAN facility
  2018-02-17  0:47               ` Todd Zullinger
@ 2018-02-17  5:40                 ` Todd Zullinger
  0 siblings, 0 replies; 66+ messages in thread
From: Todd Zullinger @ 2018-02-17  5:40 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Ævar Arnfjörð Bjarmason, git, Junio C Hamano,
	Matthieu Moy, Petr Baudis, Jeff King, Johannes Schindelin,
	Jari Aalto, Giuseppe Bilotta, Marcus Griep

I wrote:
> Hi Jonathan,
> 
> Jonathan Nieder wrote:
>> Todd Zullinger wrote:
> [...]
>>> +++ b/Makefile
>>> @@ -296,6 +296,9 @@ all::
>>>  #
>>>  # Define NO_PERL if you do not want Perl scripts or libraries at all.
>>>  #
>>> +# Define NO_PERL_CPAN_FALLBACKS if you do not want to install fallbacks for
>>> +# perl CPAN modules.
>> 
>> nit: Looking at this as a naive user, it's not obvious what kind of
>> fallbacks are meant. How about:
>> 
>> 	Define NO_PERL_CPAN_FALLBACKS if you do not want to install bundled
>> 	copies of CPAN modules that serve as a fallback in case the modules are
>> 	not available on the system.
>> 
>> Or perhaps:
>> 
>> 	Define HAVE_CPAN_MODULES if you have Error.pm and Mail::Address installed
>> 	and do not want to install the fallback copies from perl/FromCPAN.
> 
> Hmm, a positive variable like HAVE_CPAN_MODULES is
> appealing.
> 
> I don't know about listing the modules, as those seem likely
> to change and then the comment becomes stale.  It's nice to
> have a shorter name.  I could easily go back and forth.
> Hopefully some other folks will chime in with preferences.
> 
>> Would this patch need to update the loader to expect the modules in
>> the new location?
> 
> That's a good catch.  In checking how this ends up when not
> setting NO_PERL_CPAN_FALLBACKS, we end up installing
> FromCPAN at the root of $perllibdir rather than under the
> Git dir.
> 
> While we could probably fix Git::LoadCPAN, I doubt we want
> to pollute the namespace. ;) So we'll want to ensure the
> files get put in the right place from the start.  I'll try
> to fix that up.

I ended up adding a second variable to hold the FromCPAN
wildcard match, as I couldn't come up with any clean way to
do it in the same LIB_PERL{,_GEN} vars.

I tested it with and without NO_PERL_CPAN_FALLBACKS set and
with and without the system Error and Mail::Address modules
installed.  There's nothing which automatically removes the
perl/build/lib/Git/FromCPAN tree if make was run without
NO_PERL_CPAN_FALLBACKS set and then re-run with it.  I don't
know if that's something we'd care to support or not.  I
suspect it's simpler to require 'make clean' between such
runs.

(I had to restore the FromCPAN copy of Address.pm, as noted
in <87tvuif10e.fsf@evledraar.gmail.com>, of course.)

Here's what it looks like now (still subject to changing the
NO_PERL_CPAN_FALLBACKS variable).

---- 8> ----
From: Todd Zullinger <tmz@pobox.com>
Subject: [PATCH] Makefile: add NO_PERL_CPAN_FALLBACKS knob

We include some perl modules which are not part of the core perl
install, as a convenience.  This allows us to rely on those modules in
our perl-based tools and scripts without requiring users to install the
modules from CPAN or their operating system packages.

Users whose operating system provides these modules and packagers of Git
often don't want to ship or use these bundled modules.  Allow these
users to set NO_PERL_CPAN_FALLBACKS to avoid installing the bundled
modules.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
---
 Makefile                                    | 14 ++++++++++++++
 perl/{Git => }/FromCPAN/.gitattributes      |  0
 perl/{Git => }/FromCPAN/Error.pm            |  0
 perl/{Git => }/FromCPAN/Mail/.gitattributes |  0
 perl/{Git => }/FromCPAN/Mail/Address.pm     |  0
 5 files changed, 14 insertions(+)
 rename perl/{Git => }/FromCPAN/.gitattributes (100%)
 rename perl/{Git => }/FromCPAN/Error.pm (100%)
 rename perl/{Git => }/FromCPAN/Mail/.gitattributes (100%)
 rename perl/{Git => }/FromCPAN/Mail/Address.pm (100%)

diff --git a/Makefile b/Makefile
index bdd50069af..49244fb116 100644
--- a/Makefile
+++ b/Makefile
@@ -296,6 +296,10 @@ all::
 #
 # Define NO_PERL if you do not want Perl scripts or libraries at all.
 #
+# Define NO_PERL_CPAN_FALLBACKS if you do not want to install bundled
+# copies of CPAN modules that serve as a fallback in case the modules are
+# not available on the system.
+#
 # Define PYTHON_PATH to the path of your Python binary (often /usr/bin/python
 # but /usr/bin/python2.7 on some platforms).
 #
@@ -2300,15 +2304,25 @@ po/build/locale/%/LC_MESSAGES/git.mo: po/%.po
 
 LIB_PERL := $(wildcard perl/Git.pm perl/Git/*.pm perl/Git/*/*.pm perl/Git/*/*/*.pm)
 LIB_PERL_GEN := $(patsubst perl/%.pm,perl/build/lib/%.pm,$(LIB_PERL))
+ifndef NO_PERL_CPAN_FALLBACKS
+LIB_CPAN := $(wildcard perl/FromCPAN/*.pm perl/FromCPAN/*/*.pm)
+LIB_CPAN_GEN := $(patsubst perl/%.pm,perl/build/lib/Git/%.pm,$(LIB_CPAN))
+endif
 
 ifndef NO_PERL
 all:: $(LIB_PERL_GEN)
+ifndef NO_PERL_CPAN_FALLBACKS
+all:: $(LIB_CPAN_GEN)
+endif
 endif
 
 perl/build/lib/%.pm: perl/%.pm
 	$(QUIET_GEN)mkdir -p $(dir $@) && \
 	sed -e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' < $< > $@
 
+perl/build/lib/Git/FromCPAN/%.pm: perl/FromCPAN/%.pm
+	$(QUIET_GEN)mkdir -p $(dir $@) && cp $< $@
+
 perl/build/man/man3/Git.3pm: perl/Git.pm
 	$(QUIET_GEN)mkdir -p $(dir $@) && \
 	pod2man $< $@
diff --git a/perl/Git/FromCPAN/.gitattributes b/perl/FromCPAN/.gitattributes
similarity index 100%
rename from perl/Git/FromCPAN/.gitattributes
rename to perl/FromCPAN/.gitattributes
diff --git a/perl/Git/FromCPAN/Error.pm b/perl/FromCPAN/Error.pm
similarity index 100%
rename from perl/Git/FromCPAN/Error.pm
rename to perl/FromCPAN/Error.pm
diff --git a/perl/Git/FromCPAN/Mail/.gitattributes b/perl/FromCPAN/Mail/.gitattributes
similarity index 100%
rename from perl/Git/FromCPAN/Mail/.gitattributes
rename to perl/FromCPAN/Mail/.gitattributes
diff --git a/perl/Git/FromCPAN/Mail/Address.pm b/perl/FromCPAN/Mail/Address.pm
similarity index 100%
rename from perl/Git/FromCPAN/Mail/Address.pm
rename to perl/FromCPAN/Mail/Address.pm
-- 
2.16.2

I thought about using '$(INSTALL) -m 644' instead of 'cp' to
allow users to set 'INSTALL = install -p' to preserve the
timestamp of the FromCPAN files, but that would only be
useful to users installing from the same tarball version
multiple times.  The intersection of users who care that
much about consistent timestamps and don't care about using
system perl modules seems small.

-- 
Todd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A person who smiles in the face of adversity ... probably has a
scapegoat.


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* Re: [PATCH 3/8] perl: generalize the Git::LoadCPAN facility
  2018-02-14 22:57   ` Jonathan Nieder
  2018-02-15  5:09     ` Todd Zullinger
@ 2018-02-25 18:56     ` Ævar Arnfjörð Bjarmason
  2018-02-25 19:05       ` Randall S. Becker
  1 sibling, 1 reply; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-25 18:56 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep


On Wed, Feb 14 2018, Jonathan Nieder jotted:

> Ævar Arnfjörð Bjarmason wrote:
>
>> Change the two wrappers to load from CPAN (local OS) or our own copy
>> to do so via the same codepath.
>
> nit: I think with s/to load/that load/ this will be easier to read.
>
>> I added the Error.pm wrapper in 20d2a30f8f ("Makefile: replace
>> perl/Makefile.PL with simple make rules", 2017-12-10), and shortly
>> afterwards Matthieu Moy added a wrapper for Mail::Address in
>> bd869f67b9 ("send-email: add and use a local copy of Mail::Address",
>> 2018-01-05).
>>
>> His was simpler since Mail::Address doesn't have an "import" method,
>> but didn't do the same sanity checking, e.g. a missing FromCPAN
>> directory (which OS packages are likely not to have) wouldn't be
>> explicitly warned about.
>
> I'm having trouble parsing this.  Mail::Address didn't do the same
> sanity checking or his didn't?
>
> The comma before e.g. should be a period or semicolon, since it's
> starting a new independent clause.
>
>> Now both use a modification of the previously Error.pm-specific
>> codepath, which has been amended to take the module to load as
>> parameter, as well as whether or not that module has an import method.
>
> Does "now" mean before this patch or after this patch?  Usually
> commit messages describe the status quo without the patch in the
> present tense and the change the patch will make in the imperative.
> So this could say:
>
> 	Update both to use a common implementation based on the previous
> 	Error.pm loader.

All good feeedback, thanks. Incorporated into v2 which I'm about to
submit.

> [...]
>> +++ b/perl/Git/LoadCPAN.pm
>> @@ -0,0 +1,74 @@
> [...]
>> +The Perl code in Git depends on some modules from the CPAN, but we
>> +don't want to make those a hard requirement for anyone building from
>> +source.
>
> not about this patch: have we considered making it a hard requirement?
> Both Mail::Address and Error.pm are pretty widely available, and I
> wonder if we could make the instructions in the INSTALL file say that
> they are required dependencies to simplify things.

I can't remember when, but at some point this was discussed on list, and
the consensus was that us using perl should be kept as a non-invasive
implementation detail that would be as small of a pain as possible for
users.

It's easy for distros to package these modules, but for users building
from source who know nothing about perl it can be a pain.

I also think it's very useful to avoid the side-discussion about not
using some useful CPAN module in the future just because it's not widely
used, but would be perfect for some use-case of ours.

> I admit part of my bias here is coming from the distro world, where we
> have to do extra work to get rid of the FromCPAN embedded copies and
> would be happier not to have to.

I think there's a very good argument to be made for inverting the
NO_PERL_CPAN_FALLBACKS logic, but my soon to be submitted v2 keeps it
off by default.

> [...]
>> +Usually OS's will not ship with Git's Git::FromCPAN tree at all,
>> +preferring to use their own packaging of CPAN modules instead.
>
> nit: I think the plural of OS is OSes, or something like
> "distributors" or "operating systems".

Thanks.

> [...]
>> +    eval {
>> +	require $package_pm;
>> +	1;
>> +    } or do {
>
> also not about this patch: this mixed tabs/spacing formatting feels a
> bit unusual.  I don't know if it's idiomatic for perl, and if it is
> then no complaints; it just stood out a little.  Can
> Documentation/CodingGuidelines say something about the preferred
> indentation in Perl to avoid having to think about such questions?

Thanks, that sucked. Changed to \t. I still haven't gotten around to
hacking my $EDITOR settings for git.git (like for C & SH).

>> --- a/perl/Git/LoadCPAN/Error.pm
>> +++ b/perl/Git/LoadCPAN/Error.pm
>> @@ -2,45 +2,9 @@ package Git::LoadCPAN::Error;
>>  use 5.008;
>>  use strict;
>>  use warnings;
>> +use Git::LoadCPAN (
>> +    module => 'Error',
>> +    import => 1,
>> +);
>
> Nice!
>
> Thanks and hope that helps,
> Jonathan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 1/8] perl: *.pm files should not have the executable bit
  2018-02-14 22:41   ` Jonathan Nieder
@ 2018-02-25 19:01     ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-25 19:01 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: git, Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Marcus Griep


On Wed, Feb 14 2018, Jonathan Nieder jotted:

> Hi,
>
> Ævar Arnfjörð Bjarmason wrote:
>
>> The Git::Mail::Address file added in bd869f67b9 ("send-email: add and
>> use a local copy of Mail::Address", 2018-01-05) had the executable bit
>> set, this should not be the case with *.pm files, it breaks nothing,
>> but is redundant and confusing as none of the other files have it, and
>> it's never executed as a stand-alone program.
>
> Needs a period somewhere to break up the long sentence with comma
> splices.  How about:
>
> 	The Git::Mail::Address file added in bd869f67b9 ("send-email: add and
> 	use a local copy of Mail::Address", 2018-01-05) had the executable bit
> 	set. That bit should not be set for *.pm files. It breaks nothing but
> 	but it is redundant and confusing as none of the other files have it
> 	and these files are never executed as stand-alone programs.

Thanks, used this with s/but but/but/

>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>
> With or without such a tweak,
> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
>
> Thanks.


^ permalink raw reply	[flat|nested] 66+ messages in thread

* RE: [PATCH 3/8] perl: generalize the Git::LoadCPAN facility
  2018-02-25 18:56     ` Ævar Arnfjörð Bjarmason
@ 2018-02-25 19:05       ` Randall S. Becker
  0 siblings, 0 replies; 66+ messages in thread
From: Randall S. Becker @ 2018-02-25 19:05 UTC (permalink / raw)
  To: 'Ævar Arnfjörð Bjarmason',
	'Jonathan Nieder'
  Cc: git, 'Junio C Hamano', 'Matthieu Moy',
	'Petr Baudis', 'Benoit Bourbie',
	'Jeff King', 'Johannes Schindelin',
	'Jari Aalto', 'Giuseppe Bilotta',
	'Marcus Griep'

On February 25, 2018 1:57 PM, Ævar Arnfjörð Bjarmason wrote:
> On Wed, Feb 14 2018, Jonathan Nieder jotted:
> 
> > Ævar Arnfjörð Bjarmason wrote:
> >
> >> Change the two wrappers to load from CPAN (local OS) or our own copy
> >> to do so via the same codepath.
> >
> > nit: I think with s/to load/that load/ this will be easier to read.
> >
> >> I added the Error.pm wrapper in 20d2a30f8f ("Makefile: replace
> >> perl/Makefile.PL with simple make rules", 2017-12-10), and shortly
> >> afterwards Matthieu Moy added a wrapper for Mail::Address in
> >> bd869f67b9 ("send-email: add and use a local copy of Mail::Address",
> >> 2018-01-05).
> >>
> >> His was simpler since Mail::Address doesn't have an "import" method,
> >> but didn't do the same sanity checking, e.g. a missing FromCPAN
> >> directory (which OS packages are likely not to have) wouldn't be
> >> explicitly warned about.
> >
> > I'm having trouble parsing this.  Mail::Address didn't do the same
> > sanity checking or his didn't?
> >
> > The comma before e.g. should be a period or semicolon, since it's
> > starting a new independent clause.
> >
> >> Now both use a modification of the previously Error.pm-specific
> >> codepath, which has been amended to take the module to load as
> >> parameter, as well as whether or not that module has an import method.
> >
> > Does "now" mean before this patch or after this patch?  Usually commit
> > messages describe the status quo without the patch in the present
> > tense and the change the patch will make in the imperative.
> > So this could say:
> >
> > 	Update both to use a common implementation based on the
> previous
> > 	Error.pm loader.
> 
> All good feeedback, thanks. Incorporated into v2 which I'm about to submit.
> 
> > [...]
> >> +++ b/perl/Git/LoadCPAN.pm
> >> @@ -0,0 +1,74 @@
> > [...]
> >> +The Perl code in Git depends on some modules from the CPAN, but we
> >> +don't want to make those a hard requirement for anyone building from
> >> +source.
> >
> > not about this patch: have we considered making it a hard requirement?
> > Both Mail::Address and Error.pm are pretty widely available, and I
> > wonder if we could make the instructions in the INSTALL file say that
> > they are required dependencies to simplify things.
> 
> I can't remember when, but at some point this was discussed on list, and the
> consensus was that us using perl should be kept as a non-invasive
> implementation detail that would be as small of a pain as possible for users.

That would include the platform I'm maintaining, where perl is currently pretty handcuffed and blindfolded (including completion code misinterprets). CPAN isn't currently an option, but might be soon.

> It's easy for distros to package these modules, but for users building from
> source who know nothing about perl it can be a pain.

Know perl I do. Use it not, can I. ;-)

> I also think it's very useful to avoid the side-discussion about not using some
> useful CPAN module in the future just because it's not widely used, but
> would be perfect for some use-case of ours.
> 
> > I admit part of my bias here is coming from the distro world, where we
> > have to do extra work to get rid of the FromCPAN embedded copies and
> > would be happier not to have to.
> 
> I think there's a very good argument to be made for inverting the
> NO_PERL_CPAN_FALLBACKS logic, but my soon to be submitted v2 keeps it
> off by default.

Cool, thanks.

Cheers,
Randall

-- Brief whoami:
  NonStop developer since approximately NonStop(211288444200000000)
  UNIX developer since approximately 421664400
-- In my real life, I talk too much.




^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v2 00/13] various perl fixes
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (7 preceding siblings ...)
  2018-02-14 22:21 ` [PATCH 8/8] perl: hard-depend on the File::{Temp,Spec} modules Ævar Arnfjörð Bjarmason
@ 2018-02-25 19:46 ` Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 " Ævar Arnfjörð Bjarmason
                     ` (13 more replies)
  2018-02-25 19:46 ` [PATCH v2 01/13] perl: *.pm files should not have the executable bit Ævar Arnfjörð Bjarmason
                   ` (12 subsequent siblings)
  21 siblings, 14 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-25 19:46 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Todd Zullinger, Jonathan Nieder, Randall S . Becker,
	Ævar Arnfjörð Bjarmason

Addresses comments against v1, and ships with a new
NO_PERL_CPAN_FALLBACKS knob (thanks Todd!) which distributions can
turn on to not get our FromCPAN copies. Details below.

Todd Zullinger (1):
  Makefile: add NO_PERL_CPAN_FALLBACKS knob

Some of this was split off into into my "perl: move the
perl/Git/FromCPAN tree to perl/FromCPAN", and I added "This option is
intended[...]" to the Makefile documentation.

Ævar Arnfjörð Bjarmason (12):
  perl: *.pm files should not have the executable bit

JN: Rephrased commit message.

  Git.pm: remove redundant "use strict" from sub-package
  Git.pm: add the "use warnings" pragma

These are both new, something I noticed and seems sensible to fix
while we're at it.

  gitweb: hard-depend on the Digest::MD5 5.8 module
  Git.pm: hard-depend on the File::{Temp,Spec} modules
  git-send-email: unconditionally use Net::{SMTP,Domain}

These all "use" the modules now, instead of using "require".

JN: Removed a comment from the gitweb code that isn't needed anymore.

Clarifications / fixes to the commit messages. 

  perl: update our ancient copy of Error.pm

Rephrased commit message.

  perl: update our copy of Mail::Address

Actually ships with the working version of Mail::Address now (oops!),
which makes the patch much smaller, and requires less explanation.

  perl: move CPAN loader wrappers to another namespace

JN: Commit message phrasing.

  perl: generalize the Git::LoadCPAN facility

JN: Commit message phrasing, and s/    /\t/g.

  perl: move the perl/Git/FromCPAN tree to perl/FromCPAN
  perl Git::LoadCPAN: emit better errors under NO_PERL_CPAN_FALLBACKS

These are both new. There's now a NO_PERL_CPAN_FALLBACKS option for
distributors to turn on to stop us from installing these CPAN
fallbacks.

13/13 updates the docs, and emits a better error than what we emit now
in master if the CPAN module we expect from the OS isn't installed.

 INSTALL                                 |  11 +-
 Makefile                                |  16 +-
 contrib/examples/git-difftool.perl      |   2 +-
 git-send-email.perl                     |  28 ++-
 gitweb/INSTALL                          |   3 +-
 gitweb/gitweb.perl                      |  17 +-
 perl/FromCPAN/.gitattributes            |   1 +
 perl/{Git => }/FromCPAN/Error.pm        | 296 +++++++++++++++++++++++++++-----
 perl/{Git => }/FromCPAN/Mail/Address.pm |   8 +-
 perl/Git.pm                             |  14 +-
 perl/Git/Error.pm                       |  46 -----
 perl/Git/LoadCPAN.pm                    | 104 +++++++++++
 perl/Git/LoadCPAN/Error.pm              |  10 ++
 perl/Git/LoadCPAN/Mail/Address.pm       |  10 ++
 perl/Git/Mail/Address.pm                |  24 ---
 15 files changed, 432 insertions(+), 158 deletions(-)
 create mode 100644 perl/FromCPAN/.gitattributes
 rename perl/{Git => }/FromCPAN/Error.pm (72%)
 rename perl/{Git => }/FromCPAN/Mail/Address.pm (96%)
 delete mode 100644 perl/Git/Error.pm
 create mode 100644 perl/Git/LoadCPAN.pm
 create mode 100644 perl/Git/LoadCPAN/Error.pm
 create mode 100644 perl/Git/LoadCPAN/Mail/Address.pm
 delete mode 100755 perl/Git/Mail/Address.pm

-- 
2.15.1.424.g9478a66081


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v2 01/13] perl: *.pm files should not have the executable bit
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (8 preceding siblings ...)
  2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
@ 2018-02-25 19:46 ` Ævar Arnfjörð Bjarmason
  2018-02-25 19:46 ` [PATCH v2 02/13] Git.pm: remove redundant "use strict" from sub-package Ævar Arnfjörð Bjarmason
                   ` (11 subsequent siblings)
  21 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-25 19:46 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Todd Zullinger, Jonathan Nieder, Randall S . Becker,
	Ævar Arnfjörð Bjarmason

The Git::Mail::Address file added in bd869f67b9 ("send-email: add and
use a local copy of Mail::Address", 2018-01-05) had the executable bit
set. That bit should not be set for *.pm files. It breaks nothing but
it is redundant and confusing as none of the other files have it and
these files are never executed as stand-alone programs.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git/Mail/Address.pm | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 mode change 100755 => 100644 perl/Git/Mail/Address.pm

diff --git a/perl/Git/Mail/Address.pm b/perl/Git/Mail/Address.pm
old mode 100755
new mode 100644
-- 
2.15.1.424.g9478a66081


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v2 02/13] Git.pm: remove redundant "use strict" from sub-package
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (9 preceding siblings ...)
  2018-02-25 19:46 ` [PATCH v2 01/13] perl: *.pm files should not have the executable bit Ævar Arnfjörð Bjarmason
@ 2018-02-25 19:46 ` Ævar Arnfjörð Bjarmason
  2018-02-25 19:46 ` [PATCH v2 03/13] Git.pm: add the "use warnings" pragma Ævar Arnfjörð Bjarmason
                   ` (10 subsequent siblings)
  21 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-25 19:46 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Todd Zullinger, Jonathan Nieder, Randall S . Becker,
	Ævar Arnfjörð Bjarmason

In Perl the "use strict/warnings" pragmas are lexical, thus there's no
reason to do:

    package Foo;
    use strict;
    package Bar;
    use strict;
    $x = 5;

To satisfy the desire that the undeclared $x variable will be spotted
at compile-time. It's enough to include the first "use strict".

This functionally changes nothing, but makes a subsequent change where
"use warnings" will be added to Git.pm less confusing and less
verbose, since as with "strict" we'll only need to do that at the top
of the file.

Changes code initially added in a6065b548f ("Git.pm: Try to support
ActiveState output pipe", 2006-06-25).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git.pm | 1 -
 1 file changed, 1 deletion(-)

diff --git a/perl/Git.pm b/perl/Git.pm
index 9d60d7948b..99e5d943af 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -1692,7 +1692,6 @@ sub DESTROY {
 # Pipe implementation for ActiveState Perl.
 
 package Git::activestate_pipe;
-use strict;
 
 sub TIEHANDLE {
 	my ($class, @params) = @_;
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v2 03/13] Git.pm: add the "use warnings" pragma
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (10 preceding siblings ...)
  2018-02-25 19:46 ` [PATCH v2 02/13] Git.pm: remove redundant "use strict" from sub-package Ævar Arnfjörð Bjarmason
@ 2018-02-25 19:46 ` Ævar Arnfjörð Bjarmason
  2018-02-25 19:46 ` [PATCH v2 04/13] gitweb: hard-depend on the Digest::MD5 5.8 module Ævar Arnfjörð Bjarmason
                   ` (9 subsequent siblings)
  21 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-25 19:46 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Todd Zullinger, Jonathan Nieder, Randall S . Becker,
	Ævar Arnfjörð Bjarmason

Amend Git.pm to load the "warnings" pragma like the rest of the code
in perl/ in addition to the existing "strict" pragma. This is
considered the bare minimum best practice in Perl.

Ever since this code was introduced in b1edc53d06 ("Introduce
Git.pm (v4)", 2006-06-24) it's only been using "strict", not
"warnings".

This leaves contrib/buildsystems/Generators/{QMake,VCproj}.pm and
contrib/mw-to-git/Git/Mediawiki.pm without "use warnings". Amending
those would be a sensible follow-up change, but I don't have an easy
way to test those so I'm not changing them.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git.pm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/perl/Git.pm b/perl/Git.pm
index 99e5d943af..7ec16e6dde 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -9,6 +9,7 @@ package Git;
 
 use 5.008;
 use strict;
+use warnings;
 
 
 BEGIN {
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v2 04/13] gitweb: hard-depend on the Digest::MD5 5.8 module
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (11 preceding siblings ...)
  2018-02-25 19:46 ` [PATCH v2 03/13] Git.pm: add the "use warnings" pragma Ævar Arnfjörð Bjarmason
@ 2018-02-25 19:46 ` Ævar Arnfjörð Bjarmason
  2018-02-25 20:00   ` Eric Sunshine
  2018-02-25 19:46 ` [PATCH v2 05/13] Git.pm: hard-depend on the File::{Temp,Spec} modules Ævar Arnfjörð Bjarmason
                   ` (8 subsequent siblings)
  21 siblings, 1 reply; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-25 19:46 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Todd Zullinger, Jonathan Nieder, Randall S . Becker,
	Ævar Arnfjörð Bjarmason

Since my d48b284183 ("perl: bump the required Perl version to 5.8 from
5.6.[21]", 2010-09-24), we've depended on 5.8, so there's no reason to
conditionally require Digest::MD5 anymore. It was released with perl
v5.7.3[1]

The initial introduction of the dependency in
e9fdd74e53 ("gitweb: (gr)avatar support", 2009-06-30) says as much,
this also undoes part of the later 2e9c8789b7 ("gitweb: Mention
optional Perl modules in INSTALL", 2011-02-04) since gitweb will
always be run on at least 5.8, so there's no need to mention
Digest::MD5 as a required module in the documentation, let's instead
say that we require perl 5.8.

As with the preceding Net::{SMTP,Domain} change we now unconditionally
"use" the module instead.

1. $ corelist Digest::MD5
   Data for 2015-02-14
   Digest::MD5 was first released with perl v5.7.3

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 gitweb/INSTALL     |  3 +--
 gitweb/gitweb.perl | 17 ++++-------------
 2 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/gitweb/INSTALL b/gitweb/INSTALL
index 408f2859d3..a58e6b3c44 100644
--- a/gitweb/INSTALL
+++ b/gitweb/INSTALL
@@ -29,12 +29,11 @@ Requirements
 ------------
 
  - Core git tools
- - Perl
+ - Perl 5.8
  - Perl modules: CGI, Encode, Fcntl, File::Find, File::Basename.
  - web server
 
 The following optional Perl modules are required for extra features
- - Digest::MD5 - for gravatar support
  - CGI::Fast and FCGI - for running gitweb as FastCGI script
  - HTML::TagCloud - for fancy tag cloud in project list view
  - HTTP::Date or Time::ParseDate - to support If-Modified-Since for feeds
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 2417057f2b..2594a4badb 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -20,6 +20,8 @@ use Fcntl ':mode';
 use File::Find qw();
 use File::Basename qw(basename);
 use Time::HiRes qw(gettimeofday tv_interval);
+use Digest::MD5 qw(md5_hex);
+
 binmode STDOUT, ':utf8';
 
 if (!defined($CGI::VERSION) || $CGI::VERSION < 4.08) {
@@ -490,7 +492,6 @@ our %feature = (
 	# Currently available providers are gravatar and picon.
 	# If an unknown provider is specified, the feature is disabled.
 
-	# Gravatar depends on Digest::MD5.
 	# Picon currently relies on the indiana.edu database.
 
 	# To enable system wide have in $GITWEB_CONFIG
@@ -1166,18 +1167,8 @@ sub configure_gitweb_features {
 	our @snapshot_fmts = gitweb_get_feature('snapshot');
 	@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
 
-	# check that the avatar feature is set to a known provider name,
-	# and for each provider check if the dependencies are satisfied.
-	# if the provider name is invalid or the dependencies are not met,
-	# reset $git_avatar to the empty string.
 	our ($git_avatar) = gitweb_get_feature('avatar');
-	if ($git_avatar eq 'gravatar') {
-		$git_avatar = '' unless (eval { require Digest::MD5; 1; });
-	} elsif ($git_avatar eq 'picon') {
-		# no dependencies
-	} else {
-		$git_avatar = '';
-	}
+	$git_avatar = '' unless $git_avatar =~ /^(?:gravatar|picon)$/s;
 
 	our @extra_branch_refs = gitweb_get_feature('extra-branch-refs');
 	@extra_branch_refs = filter_and_validate_refs (@extra_branch_refs);
@@ -2167,7 +2158,7 @@ sub gravatar_url {
 	my $size = shift;
 	$avatar_cache{$email} ||=
 		"//www.gravatar.com/avatar/" .
-			Digest::MD5::md5_hex($email) . "?s=";
+			md5_hex($email) . "?s=";
 	return $avatar_cache{$email} . $size;
 }
 
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v2 05/13] Git.pm: hard-depend on the File::{Temp,Spec} modules
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (12 preceding siblings ...)
  2018-02-25 19:46 ` [PATCH v2 04/13] gitweb: hard-depend on the Digest::MD5 5.8 module Ævar Arnfjörð Bjarmason
@ 2018-02-25 19:46 ` Ævar Arnfjörð Bjarmason
  2018-02-25 19:46 ` [PATCH v2 06/13] git-send-email: unconditionally use Net::{SMTP,Domain} Ævar Arnfjörð Bjarmason
                   ` (7 subsequent siblings)
  21 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-25 19:46 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Todd Zullinger, Jonathan Nieder, Randall S . Becker,
	Ævar Arnfjörð Bjarmason

Since my d48b284183 ("perl: bump the required Perl version to 5.8 from
5.6.[21]", 2010-09-24), we've depended on 5.8, so there's no reason to
conditionally require File::Temp and File::Spec anymore. They were
first released with perl versions v5.6.1 and 5.00405, respectively.

This code was originally added in c14c8ceb13 ("Git.pm: Make File::Spec
and File::Temp requirement lazy", 2008-08-15), presumably to make
Git.pm work on 5.6.0.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git.pm | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/perl/Git.pm b/perl/Git.pm
index 7ec16e6dde..151b0e7144 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -11,6 +11,8 @@ use 5.008;
 use strict;
 use warnings;
 
+use File::Temp ();
+use File::Spec ();
 
 BEGIN {
 
@@ -190,7 +192,6 @@ sub repository {
 		};
 
 		if ($dir) {
-			_verify_require();
 			File::Spec->file_name_is_absolute($dir) or $dir = $opts{Directory} . '/' . $dir;
 			$opts{Repository} = abs_path($dir);
 
@@ -1289,8 +1290,6 @@ sub temp_release {
 sub _temp_cache {
 	my ($self, $name) = _maybe_self(@_);
 
-	_verify_require();
-
 	my $temp_fd = \$TEMP_FILEMAP{$name};
 	if (defined $$temp_fd and $$temp_fd->opened) {
 		if ($TEMP_FILES{$$temp_fd}{locked}) {
@@ -1324,11 +1323,6 @@ sub _temp_cache {
 	$$temp_fd;
 }
 
-sub _verify_require {
-	eval { require File::Temp; require File::Spec; };
-	$@ and throw Error::Simple($@);
-}
-
 =item temp_reset ( FILEHANDLE )
 
 Truncates and resets the position of the C<FILEHANDLE>.
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v2 06/13] git-send-email: unconditionally use Net::{SMTP,Domain}
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (13 preceding siblings ...)
  2018-02-25 19:46 ` [PATCH v2 05/13] Git.pm: hard-depend on the File::{Temp,Spec} modules Ævar Arnfjörð Bjarmason
@ 2018-02-25 19:46 ` Ævar Arnfjörð Bjarmason
  2018-02-25 20:03   ` Eric Sunshine
  2018-02-25 19:46 ` [PATCH v2 07/13] perl: update our ancient copy of Error.pm Ævar Arnfjörð Bjarmason
                   ` (6 subsequent siblings)
  21 siblings, 1 reply; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-25 19:46 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Todd Zullinger, Jonathan Nieder, Randall S . Becker,
	Ævar Arnfjörð Bjarmason

The Net::SMTP and Net::Domain were both first released with perl
v5.7.3[1], since my d48b284183 ("perl: bump the required Perl version
to 5.8 from 5.6.[21]", 2010-09-24) we've depended on 5.8, so there's
no reason to conditionally require this anymore.

This conditional loading was initially added in
87840620fd ("send-email: only 'require' instead of 'use' Net::SMTP",
2006-06-01) for Net::SMTP and 134550fe21 ("git-send-email.perl - try
to give real name of the calling host to HELO/EHLO", 2010-03-14) for
Net::Domain, both of which predate the hard dependency on 5.8.

Since they're guaranteed to be installed now let's "use" them
instead. The cost of loading them both is trivial given what
git-send-email does (~15ms on my system), and it's better to not defer
any potential loading errors until runtime.

This patch is better viewed with -w, which shows that the only change
in the last two hunks is removing the "if eval" wrapper block.

1. $ parallel 'corelist {}' ::: Net::{SMTP,Domain}
   Data for 2015-02-14
   Net::SMTP was first released with perl v5.7.3

   Data for 2015-02-14
   Net::Domain was first released with perl v5.7.3

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 git-send-email.perl | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index bbf4deaa0d..d5a4826a1c 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -31,6 +31,8 @@ use Cwd qw(abs_path cwd);
 use Git;
 use Git::I18N;
 use Git::Mail::Address;
+use Net::Domain ();
+use Net::SMTP ();
 
 Getopt::Long::Configure qw/ pass_through /;
 
@@ -1143,10 +1145,8 @@ sub valid_fqdn {
 sub maildomain_net {
 	my $maildomain;
 
-	if (eval { require Net::Domain; 1 }) {
-		my $domain = Net::Domain::domainname();
-		$maildomain = $domain if valid_fqdn($domain);
-	}
+	my $domain = Net::Domain::domainname();
+	$maildomain = $domain if valid_fqdn($domain);
 
 	return $maildomain;
 }
@@ -1154,17 +1154,15 @@ sub maildomain_net {
 sub maildomain_mta {
 	my $maildomain;
 
-	if (eval { require Net::SMTP; 1 }) {
-		for my $host (qw(mailhost localhost)) {
-			my $smtp = Net::SMTP->new($host);
-			if (defined $smtp) {
-				my $domain = $smtp->domain;
-				$smtp->quit;
+	for my $host (qw(mailhost localhost)) {
+		my $smtp = Net::SMTP->new($host);
+		if (defined $smtp) {
+			my $domain = $smtp->domain;
+			$smtp->quit;
 
-				$maildomain = $domain if valid_fqdn($domain);
+			$maildomain = $domain if valid_fqdn($domain);
 
-				last if $maildomain;
-			}
+			last if $maildomain;
 		}
 	}
 
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v2 07/13] perl: update our ancient copy of Error.pm
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (14 preceding siblings ...)
  2018-02-25 19:46 ` [PATCH v2 06/13] git-send-email: unconditionally use Net::{SMTP,Domain} Ævar Arnfjörð Bjarmason
@ 2018-02-25 19:46 ` Ævar Arnfjörð Bjarmason
  2018-02-25 19:46 ` [PATCH v2 08/13] perl: update our copy of Mail::Address Ævar Arnfjörð Bjarmason
                   ` (5 subsequent siblings)
  21 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-25 19:46 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Todd Zullinger, Jonathan Nieder, Randall S . Becker,
	Ævar Arnfjörð Bjarmason

The Error.pm shipped with Git as a fallback if there was no Error.pm
on the system was released in April 2006. There's been dozens of
releases since then, the latest at August 7, 2017. Let's update to
that.

I don't know of anything we need from this new release or which this
fixes. This change is simply a matter of keeping up with
upstream. Before this users who'd install git via their package system
would get an up-to-date Error.pm, but if it's installed from source
they'd get one more than a decade old.

This undoes a local hack we'd accumulated in 96bc4de85c ("Eliminate
Scalar::Util usage from private-Error.pm", 2006-07-26), it's been
redundant since my d48b284183 ("perl: bump the required Perl version
to 5.8 from 5.6.[21]", 2010-09-24).

This also undoes 3a51467b94 ("Typo fix: replacing it's -> its",
2013-04-13). This is the Nth time I find that some upstream code of
ours (in contrib/, in sha1dc/ and now in perl/ ...) has diverged from
upstream because of some tree-wide typo fixing. Let's not do those
fixes against upstream projects, it's more valuable that we have a 1=1
mapping to upstream than to fix typos in docs we never even generate
from this code. If someone wants to fix typos in them fine, but they
should do it with a patch to upstream which git.git can then
incorporate.

The upstream code doesn't cleanly pass a --check, so I'm adding a
.gitattributes file for similar reasons as done for sha1dc in
5d184f468e ("sha1dc: ignore indent-with-non-tab whitespace
violations", 2017-06-06).

The updated source was retrieved from
https://fastapi.metacpan.org/source/SHLOMIF/Error-0.17025/lib/Error.pm

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git/FromCPAN/.gitattributes |   1 +
 perl/Git/FromCPAN/Error.pm       | 296 +++++++++++++++++++++++++++++++++------
 2 files changed, 256 insertions(+), 41 deletions(-)
 create mode 100644 perl/Git/FromCPAN/.gitattributes

diff --git a/perl/Git/FromCPAN/.gitattributes b/perl/Git/FromCPAN/.gitattributes
new file mode 100644
index 0000000000..8b64fc5e22
--- /dev/null
+++ b/perl/Git/FromCPAN/.gitattributes
@@ -0,0 +1 @@
+/Error.pm whitespace=-blank-at-eof
diff --git a/perl/Git/FromCPAN/Error.pm b/perl/Git/FromCPAN/Error.pm
index 6098135ae2..f9c36e9e98 100644
--- a/perl/Git/FromCPAN/Error.pm
+++ b/perl/Git/FromCPAN/Error.pm
@@ -12,10 +12,12 @@
 package Error;
 
 use strict;
+use warnings;
+
 use vars qw($VERSION);
 use 5.004;
 
-$VERSION = "0.15009";
+$VERSION = "0.17025";
 
 use overload (
 	'""'	   =>	'stringify',
@@ -32,21 +34,35 @@ $Error::THROWN = undef;	# last error thrown, a workaround until die $ref works
 my $LAST;		# Last error created
 my %ERROR;		# Last error associated with package
 
-sub throw_Error_Simple
+sub _throw_Error_Simple
 {
     my $args = shift;
     return Error::Simple->new($args->{'text'});
 }
 
-$Error::ObjectifyCallback = \&throw_Error_Simple;
+$Error::ObjectifyCallback = \&_throw_Error_Simple;
 
 
 # Exported subs are defined in Error::subs
 
+use Scalar::Util ();
+
 sub import {
     shift;
+    my @tags = @_;
     local $Exporter::ExportLevel = $Exporter::ExportLevel + 1;
-    Error::subs->import(@_);
+
+    @tags = grep {
+       if( $_ eq ':warndie' ) {
+          Error::WarnDie->import();
+          0;
+       }
+       else {
+          1;
+       }
+    } @tags;
+
+    Error::subs->import(@tags);
 }
 
 # I really want to use last for the name of this method, but it is a keyword
@@ -107,10 +123,6 @@ sub stacktrace {
     $text;
 }
 
-# Allow error propagation, ie
-#
-# $ber->encode(...) or
-#    return Error->prior($ber)->associate($ldap);
 
 sub associate {
     my $err = shift;
@@ -130,6 +142,7 @@ sub associate {
     return;
 }
 
+
 sub new {
     my $self = shift;
     my($pkg,$file,$line) = caller($Error::Depth);
@@ -246,6 +259,10 @@ sub value {
 
 package Error::Simple;
 
+use vars qw($VERSION);
+
+$VERSION = "0.17025";
+
 @Error::Simple::ISA = qw(Error);
 
 sub new {
@@ -288,14 +305,6 @@ use vars qw(@EXPORT_OK @ISA %EXPORT_TAGS);
 
 @ISA = qw(Exporter);
 
-
-sub blessed {
-	my $item = shift;
-	local $@; # don't kill an outer $@
-	ref $item and eval { $item->can('can') };
-}
-
-
 sub run_clauses ($$$\@) {
     my($clauses,$err,$wantarray,$result) = @_;
     my $code = undef;
@@ -314,16 +323,17 @@ sub run_clauses ($$$\@) {
 		my $pkg = $catch->[$i];
 		unless(defined $pkg) {
 		    #except
-		    splice(@$catch,$i,2,$catch->[$i+1]->());
+		    splice(@$catch,$i,2,$catch->[$i+1]->($err));
 		    $i -= 2;
 		    next CATCHLOOP;
 		}
-		elsif(blessed($err) && $err->isa($pkg)) {
+		elsif(Scalar::Util::blessed($err) && $err->isa($pkg)) {
 		    $code = $catch->[$i+1];
 		    while(1) {
 			my $more = 0;
-			local($Error::THROWN);
+			local($Error::THROWN, $@);
 			my $ok = eval {
+			    $@ = $err;
 			    if($wantarray) {
 				@{$result} = $code->($err,\$more);
 			    }
@@ -341,10 +351,9 @@ sub run_clauses ($$$\@) {
 			    undef $err;
 			}
 			else {
-			    $err = defined($Error::THROWN)
-				    ? $Error::THROWN : $@;
-                $err = $Error::ObjectifyCallback->({'text' =>$err})
-                    unless ref($err);
+			    $err = $@ || $Error::THROWN;
+				$err = $Error::ObjectifyCallback->({'text' =>$err})
+					unless ref($err);
 			}
 			last CATCH;
 		    };
@@ -357,7 +366,9 @@ sub run_clauses ($$$\@) {
 	if(defined($owise = $clauses->{'otherwise'})) {
 	    my $code = $clauses->{'otherwise'};
 	    my $more = 0;
+        local($Error::THROWN, $@);
 	    my $ok = eval {
+		$@ = $err;
 		if($wantarray) {
 		    @{$result} = $code->($err,\$more);
 		}
@@ -374,11 +385,10 @@ sub run_clauses ($$$\@) {
 		undef $err;
 	    }
 	    else {
-		$err = defined($Error::THROWN)
-			? $Error::THROWN : $@;
+		$err = $@ || $Error::THROWN;
 
-        $err = $Error::ObjectifyCallback->({'text' =>$err})
-            unless ref($err);
+		$err = $Error::ObjectifyCallback->({'text' =>$err})
+			unless ref($err);
 	    }
 	}
     }
@@ -398,7 +408,7 @@ sub try (&;$) {
 
     do {
 	local $Error::THROWN = undef;
-    local $@ = undef;
+	local $@ = undef;
 
 	$ok = eval {
 	    if($wantarray) {
@@ -413,21 +423,21 @@ sub try (&;$) {
 	    1;
 	};
 
-	$err = defined($Error::THROWN) ? $Error::THROWN : $@
+	$err = $@ || $Error::THROWN
 	    unless $ok;
     };
 
     shift @Error::STACK;
 
     $err = run_clauses($clauses,$err,wantarray,@result)
-	unless($ok);
+    unless($ok);
 
     $clauses->{'finally'}->()
 	if(defined($clauses->{'finally'}));
 
     if (defined($err))
     {
-        if (blessed($err) && $err->can('throw'))
+        if (Scalar::Util::blessed($err) && $err->can('throw'))
         {
             throw $err;
         }
@@ -506,12 +516,116 @@ sub otherwise (&;$) {
 }
 
 1;
+
+package Error::WarnDie;
+
+sub gen_callstack($)
+{
+    my ( $start ) = @_;
+
+    require Carp;
+    local $Carp::CarpLevel = $start;
+    my $trace = Carp::longmess("");
+    # Remove try calls from the trace
+    $trace =~ s/(\n\s+\S+__ANON__[^\n]+)?\n\s+eval[^\n]+\n\s+Error::subs::try[^\n]+(?=\n)//sog;
+    $trace =~ s/(\n\s+\S+__ANON__[^\n]+)?\n\s+eval[^\n]+\n\s+Error::subs::run_clauses[^\n]+\n\s+Error::subs::try[^\n]+(?=\n)//sog;
+    my @callstack = split( m/\n/, $trace );
+    return @callstack;
+}
+
+my $old_DIE;
+my $old_WARN;
+
+sub DEATH
+{
+    my ( $e ) = @_;
+
+    local $SIG{__DIE__} = $old_DIE if( defined $old_DIE );
+
+    die @_ if $^S;
+
+    my ( $etype, $message, $location, @callstack );
+    if ( ref($e) && $e->isa( "Error" ) ) {
+        $etype = "exception of type " . ref( $e );
+        $message = $e->text;
+        $location = $e->file . ":" . $e->line;
+        @callstack = split( m/\n/, $e->stacktrace );
+    }
+    else {
+        # Don't apply subsequent layer of message formatting
+        die $e if( $e =~ m/^\nUnhandled perl error caught at toplevel:\n\n/ );
+        $etype = "perl error";
+        my $stackdepth = 0;
+        while( caller( $stackdepth ) =~ m/^Error(?:$|::)/ ) {
+            $stackdepth++
+        }
+
+        @callstack = gen_callstack( $stackdepth + 1 );
+
+        $message = "$e";
+        chomp $message;
+
+        if ( $message =~ s/ at (.*?) line (\d+)\.$// ) {
+            $location = $1 . ":" . $2;
+        }
+        else {
+            my @caller = caller( $stackdepth );
+            $location = $caller[1] . ":" . $caller[2];
+        }
+    }
+
+    shift @callstack;
+    # Do it this way in case there are no elements; we don't print a spurious \n
+    my $callstack = join( "", map { "$_\n"} @callstack );
+
+    die "\nUnhandled $etype caught at toplevel:\n\n  $message\n\nThrown from: $location\n\nFull stack trace:\n\n$callstack\n";
+}
+
+sub TAXES
+{
+    my ( $message ) = @_;
+
+    local $SIG{__WARN__} = $old_WARN if( defined $old_WARN );
+
+    $message =~ s/ at .*? line \d+\.$//;
+    chomp $message;
+
+    my @callstack = gen_callstack( 1 );
+    my $location = shift @callstack;
+
+    # $location already starts in a leading space
+    $message .= $location;
+
+    # Do it this way in case there are no elements; we don't print a spurious \n
+    my $callstack = join( "", map { "$_\n"} @callstack );
+
+    warn "$message:\n$callstack";
+}
+
+sub import
+{
+    $old_DIE  = $SIG{__DIE__};
+    $old_WARN = $SIG{__WARN__};
+
+    $SIG{__DIE__}  = \&DEATH;
+    $SIG{__WARN__} = \&TAXES;
+}
+
+1;
+
 __END__
 
 =head1 NAME
 
 Error - Error/exception handling in an OO-ish way
 
+=head1 WARNING
+
+Using the "Error" module is B<no longer recommended> due to the black-magical
+nature of its syntactic sugar, which often tends to break. Its maintainers
+have stopped actively writing code that uses it, and discourage people
+from doing so. See the "SEE ALSO" section below for better recommendations.
+
 =head1 SYNOPSIS
 
     use Error qw(:try);
@@ -529,7 +643,7 @@ Error - Error/exception handling in an OO-ish way
     try {
 	do_some_stuff();
 	die "error!" if $condition;
-	throw Error::Simple -text => "Oops!" if $other_condition;
+	throw Error::Simple "Oops!" if $other_condition;
     }
     catch Error::IO with {
 	my $E = shift;
@@ -587,7 +701,7 @@ C<BLOCK> will be passed two arguments. The first will be the error
 being thrown. The second is a reference to a scalar variable. If this
 variable is set by the catch block then, on return from the catch
 block, try will continue processing as if the catch block was never
-found.
+found. The error will also be available in C<$@>.
 
 To propagate the error the catch block may call C<$err-E<gt>throw>
 
@@ -608,7 +722,7 @@ type.
 Catch any error by executing the code in C<BLOCK>
 
 When evaluated C<BLOCK> will be passed one argument, which will be the
-error being processed.
+error being processed. The error will also be available in C<$@>.
 
 Only one otherwise block may be specified per try block
 
@@ -625,12 +739,25 @@ Only one finally block may be specified per try block
 
 =back
 
+=head1 COMPATIBILITY
+
+L<Moose> exports a keyword called C<with> which clashes with Error's. This
+example returns a prototype mismatch error:
+
+    package MyTest;
+
+    use warnings;
+    use Moose;
+    use Error qw(:try);
+
+(Thanks to C<maik.hentsche@amd.com> for the report.).
+
 =head1 CLASS INTERFACE
 
 =head2 CONSTRUCTORS
 
 The C<Error> object is implemented as a HASH. This HASH is initialized
-with the arguments that are passed to its constructor. The elements
+with the arguments that are passed to it's constructor. The elements
 that are used by, or are retrievable by the C<Error> class are listed
 below, other classes may add to these.
 
@@ -655,6 +782,10 @@ an object blessed into that package as the C<-object> argument.
 
 =over 4
 
+=item Error->new()
+
+See the Error::Simple documentation.
+
 =item throw ( [ ARGS ] )
 
 Create a new C<Error> object and throw an error, which will be caught
@@ -730,6 +861,13 @@ The line where the constructor of this error was called from
 
 The text of the error
 
+=item $err->associate($obj)
+
+Associates an error with an object to allow error propagation. I.e:
+
+    $ber->encode(...) or
+        return Error->prior($ber)->associate($ldap);
+
 =back
 
 =head2 OVERLOAD METHODS
@@ -759,11 +897,9 @@ to the constructor.
 
 =head1 PRE-DEFINED ERROR CLASSES
 
-=over 4
-
-=item Error::Simple
+=head2 Error::Simple
 
-This class can be used to hold simple error strings and values. Its
+This class can be used to hold simple error strings and values. It's
 constructor takes two arguments. The first is a text value, the second
 is a numeric value. These values are what will be returned by the
 overload methods.
@@ -775,7 +911,6 @@ of the error object.
 This class is used internally if an eval'd block die's with an error
 that is a plain string. (Unless C<$Error::ObjectifyCallback> is modified)
 
-=back
 
 =head1 $Error::ObjectifyCallback
 
@@ -804,6 +939,76 @@ class MyError::Bar by default:
         # Error handling here.
     }
 
+=cut
+
+=head1 MESSAGE HANDLERS
+
+C<Error> also provides handlers to extend the output of the C<warn()> perl
+function, and to handle the printing of a thrown C<Error> that is not caught
+or otherwise handled. These are not installed by default, but are requested
+using the C<:warndie> tag in the C<use> line.
+
+ use Error qw( :warndie );
+
+These new error handlers are installed in C<$SIG{__WARN__}> and
+C<$SIG{__DIE__}>. If these handlers are already defined when the tag is
+imported, the old values are stored, and used during the new code. Thus, to
+arrange for custom handling of warnings and errors, you will need to perform
+something like the following:
+
+ BEGIN {
+   $SIG{__WARN__} = sub {
+     print STDERR "My special warning handler: $_[0]"
+   };
+ }
+
+ use Error qw( :warndie );
+
+Note that setting C<$SIG{__WARN__}> after the C<:warndie> tag has been
+imported will overwrite the handler that C<Error> provides. If this cannot be
+avoided, then the tag can be explicitly C<import>ed later
+
+ use Error;
+
+ $SIG{__WARN__} = ...;
+
+ import Error qw( :warndie );
+
+=head2 EXAMPLE
+
+The C<__DIE__> handler turns messages such as
+
+ Can't call method "foo" on an undefined value at examples/warndie.pl line 16.
+
+into
+
+ Unhandled perl error caught at toplevel:
+
+   Can't call method "foo" on an undefined value
+
+ Thrown from: examples/warndie.pl:16
+
+ Full stack trace:
+
+         main::inner('undef') called at examples/warndie.pl line 20
+         main::outer('undef') called at examples/warndie.pl line 23
+
+=cut
+
+=head1 SEE ALSO
+
+See L<Exception::Class> for a different module providing Object-Oriented
+exception handling, along with a convenient syntax for declaring hierarchies
+for them. It doesn't provide Error's syntactic sugar of C<try { ... }>,
+C<catch { ... }>, etc. which may be a good thing or a bad thing based
+on what you want. (Because Error's syntactic sugar tends to break.)
+
+L<Error::Exception> aims to combine L<Error> and L<Exception::Class>
+"with correct stringification".
+
+L<TryCatch> and L<Try::Tiny> are similar in concept to Error.pm only providing
+a syntax that hopefully breaks less.
+
 =head1 KNOWN BUGS
 
 None, but that does not mean there are not any.
@@ -816,12 +1021,21 @@ The code that inspired me to write this was originally written by
 Peter Seibel <peter@weblogic.com> and adapted by Jesse Glick
 <jglick@sig.bsh.com>.
 
+C<:warndie> handlers added by Paul Evans <leonerd@leonerd.org.uk>
+
 =head1 MAINTAINER
 
-Shlomi Fish <shlomif@iglu.org.il>
+Shlomi Fish, L<http://www.shlomifish.org/> .
 
 =head1 PAST MAINTAINERS
 
 Arun Kumar U <u_arunkumar@yahoo.com>
 
+=head1 COPYRIGHT
+
+Copyright (c) 1997-8  Graham Barr. All rights reserved.
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
 =cut
+
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v2 08/13] perl: update our copy of Mail::Address
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (15 preceding siblings ...)
  2018-02-25 19:46 ` [PATCH v2 07/13] perl: update our ancient copy of Error.pm Ævar Arnfjörð Bjarmason
@ 2018-02-25 19:46 ` Ævar Arnfjörð Bjarmason
  2018-02-25 19:46 ` [PATCH v2 09/13] perl: move CPAN loader wrappers to another namespace Ævar Arnfjörð Bjarmason
                   ` (4 subsequent siblings)
  21 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-25 19:46 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Todd Zullinger, Jonathan Nieder, Randall S . Becker,
	Ævar Arnfjörð Bjarmason

Update our copy of Mail::Address from 2.19 (Aug 22, 2017) to 2.20 (Jan
23, 2018). Like the preceding Error.pm update this is done simply to
keep up-to-date with upstream, and as can be shown from the diff
there's no functional changes.

The updated source was retrieved from
https://fastapi.metacpan.org/source/MARKOV/MailTools-2.20/lib/Mail/Address.pm

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git/FromCPAN/Mail/Address.pm | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/perl/Git/FromCPAN/Mail/Address.pm b/perl/Git/FromCPAN/Mail/Address.pm
index 13b2ff7d05..683d490b2b 100644
--- a/perl/Git/FromCPAN/Mail/Address.pm
+++ b/perl/Git/FromCPAN/Mail/Address.pm
@@ -1,10 +1,14 @@
-# Copyrights 1995-2017 by [Mark Overmeer <perl@overmeer.net>].
+# Copyrights 1995-2018 by [Mark Overmeer].
 #  For other contributors see ChangeLog.
 # See the manual pages for details on the licensing terms.
 # Pod stripped from pm file by OODoc 2.02.
+# This code is part of the bundle MailTools.  Meta-POD processed with
+# OODoc into POD and HTML manual-pages.  See README.md for Copyright.
+# Licensed under the same terms as Perl itself.
+
 package Mail::Address;
 use vars '$VERSION';
-$VERSION = '2.19';
+$VERSION = '2.20';
 
 use strict;
 
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v2 09/13] perl: move CPAN loader wrappers to another namespace
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (16 preceding siblings ...)
  2018-02-25 19:46 ` [PATCH v2 08/13] perl: update our copy of Mail::Address Ævar Arnfjörð Bjarmason
@ 2018-02-25 19:46 ` Ævar Arnfjörð Bjarmason
  2018-02-25 19:46 ` [PATCH v2 10/13] perl: generalize the Git::LoadCPAN facility Ævar Arnfjörð Bjarmason
                   ` (3 subsequent siblings)
  21 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-25 19:46 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Todd Zullinger, Jonathan Nieder, Randall S . Becker,
	Ævar Arnfjörð Bjarmason

Move the Git::Error and Git::Mail::Address wrappers to the
Git::LoadCPAN::Loader::* namespace, e.g. Git::LoadCPAN::Error. That
module will then either load Error from CPAN (if installed on the OS),
or use Git::FromCPAN::Error.

When I added the Error wrapper in 20d2a30f8f ("Makefile: replace
perl/Makefile.PL with simple make rules", 2017-12-10) I didn't think
about how confusing it would be to have these modules sitting in the
same tree as our normal modules. Let's put these all into
Git::{Load,From}CPAN::* to clearly distinguish them from the rest.

This also makes things a bit less confusing since there was already a
Git::Error namespace ever since 8b9150e3e3 ("Git.pm: Handle failed
commands' output", 2006-06-24).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 contrib/examples/git-difftool.perl      | 2 +-
 git-send-email.perl                     | 4 ++--
 perl/Git.pm                             | 2 +-
 perl/Git/{ => LoadCPAN}/Error.pm        | 8 ++++----
 perl/Git/{ => LoadCPAN}/Mail/Address.pm | 4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)
 rename perl/Git/{ => LoadCPAN}/Error.pm (78%)
 rename perl/Git/{ => LoadCPAN}/Mail/Address.pm (69%)

diff --git a/contrib/examples/git-difftool.perl b/contrib/examples/git-difftool.perl
index fb0fd0b84b..b2ea80f9ed 100755
--- a/contrib/examples/git-difftool.perl
+++ b/contrib/examples/git-difftool.perl
@@ -13,7 +13,7 @@
 use 5.008;
 use strict;
 use warnings;
-use Git::Error qw(:try);
+use Git::LoadCPAN::Error qw(:try);
 use File::Basename qw(dirname);
 use File::Copy;
 use File::Find;
diff --git a/git-send-email.perl b/git-send-email.perl
index d5a4826a1c..1ec22c5ef3 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -26,13 +26,13 @@ use Text::ParseWords;
 use Term::ANSIColor;
 use File::Temp qw/ tempdir tempfile /;
 use File::Spec::Functions qw(catdir catfile);
-use Git::Error qw(:try);
+use Git::LoadCPAN::Error qw(:try);
 use Cwd qw(abs_path cwd);
 use Git;
 use Git::I18N;
-use Git::Mail::Address;
 use Net::Domain ();
 use Net::SMTP ();
+use Git::LoadCPAN::Mail::Address;
 
 Getopt::Long::Configure qw/ pass_through /;
 
diff --git a/perl/Git.pm b/perl/Git.pm
index 151b0e7144..9f246c7988 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -104,7 +104,7 @@ increase notwithstanding).
 
 
 use Carp qw(carp croak); # but croak is bad - throw instead
-use Git::Error qw(:try);
+use Git::LoadCPAN::Error qw(:try);
 use Cwd qw(abs_path cwd);
 use IPC::Open2 qw(open2);
 use Fcntl qw(SEEK_SET SEEK_CUR);
diff --git a/perl/Git/Error.pm b/perl/Git/LoadCPAN/Error.pm
similarity index 78%
rename from perl/Git/Error.pm
rename to perl/Git/LoadCPAN/Error.pm
index 09bbc97390..3513fe745b 100644
--- a/perl/Git/Error.pm
+++ b/perl/Git/LoadCPAN/Error.pm
@@ -1,11 +1,11 @@
-package Git::Error;
+package Git::LoadCPAN::Error;
 use 5.008;
 use strict;
 use warnings;
 
 =head1 NAME
 
-Git::Error - Wrapper for the L<Error> module, in case it's not installed
+Git::LoadCPAN::Error - Wrapper for the L<Error> module, in case it's not installed
 
 =head1 DESCRIPTION
 
@@ -26,13 +26,13 @@ sub import {
     } or do {
 	my $error = $@ || "Zombie Error";
 
-	my $Git_Error_pm_path = $INC{"Git/Error.pm"} || die "BUG: Should have our own path from %INC!";
+	my $Git_Error_pm_path = $INC{"Git/LoadCPAN/Error.pm"} || die "BUG: Should have our own path from %INC!";
 
 	require File::Basename;
 	my $Git_Error_pm_root = File::Basename::dirname($Git_Error_pm_path) || die "BUG: Can't figure out lib/Git dirname from '$Git_Error_pm_path'!";
 
 	require File::Spec;
-	my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_Error_pm_root, 'FromCPAN');
+	my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_Error_pm_root, '..', 'FromCPAN');
 	die "BUG: '$Git_pm_FromCPAN_root' should be a directory!" unless -d $Git_pm_FromCPAN_root;
 
 	local @INC = ($Git_pm_FromCPAN_root, @INC);
diff --git a/perl/Git/Mail/Address.pm b/perl/Git/LoadCPAN/Mail/Address.pm
similarity index 69%
rename from perl/Git/Mail/Address.pm
rename to perl/Git/LoadCPAN/Mail/Address.pm
index 2ce3e84670..879c2f5cd1 100644
--- a/perl/Git/Mail/Address.pm
+++ b/perl/Git/LoadCPAN/Mail/Address.pm
@@ -1,11 +1,11 @@
-package Git::Mail::Address;
+package Git::LoadCPAN::Mail::Address;
 use 5.008;
 use strict;
 use warnings;
 
 =head1 NAME
 
-Git::Mail::Address - Wrapper for the L<Mail::Address> module, in case it's not installed
+Git::LoadCPAN::Mail::Address - Wrapper for the L<Mail::Address> module, in case it's not installed
 
 =head1 DESCRIPTION
 
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v2 10/13] perl: generalize the Git::LoadCPAN facility
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (17 preceding siblings ...)
  2018-02-25 19:46 ` [PATCH v2 09/13] perl: move CPAN loader wrappers to another namespace Ævar Arnfjörð Bjarmason
@ 2018-02-25 19:46 ` Ævar Arnfjörð Bjarmason
  2018-02-25 19:46 ` [PATCH v2 11/13] perl: move the perl/Git/FromCPAN tree to perl/FromCPAN Ævar Arnfjörð Bjarmason
                   ` (2 subsequent siblings)
  21 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-25 19:46 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Todd Zullinger, Jonathan Nieder, Randall S . Becker,
	Ævar Arnfjörð Bjarmason

Change the two wrappers that load from CPAN (local OS) or our own copy
to do so via the same codepath.

I added the Error.pm wrapper in 20d2a30f8f ("Makefile: replace
perl/Makefile.PL with simple make rules", 2017-12-10), and shortly
afterwards Matthieu Moy added a wrapper for Mail::Address in
bd869f67b9 ("send-email: add and use a local copy of Mail::Address",
2018-01-05).

His loader was simpler since Mail::Address doesn't have an "import"
method, but didn't do the same sanity checking; For example, a missing
FromCPAN directory (which OS packages are likely not to have) wouldn't
be explicitly warned about as a "BUG: ...".

Update both to use a common implementation based on the previous
Error.pm loader. Which has been amended to take the module to load as
parameter, as well as whether or not that module has an import
method.

This loader should be generic enough to handle almost all CPAN modules
out there, some use some crazy loading magic and wouldn't like being
wrapped like this, but that would be immediately obvious, and we'd
find out right away since the module wouldn't work at all.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git/LoadCPAN.pm              | 74 +++++++++++++++++++++++++++++++++++++++
 perl/Git/LoadCPAN/Error.pm        | 44 +++--------------------
 perl/Git/LoadCPAN/Mail/Address.pm | 22 +++---------
 3 files changed, 82 insertions(+), 58 deletions(-)
 create mode 100644 perl/Git/LoadCPAN.pm

diff --git a/perl/Git/LoadCPAN.pm b/perl/Git/LoadCPAN.pm
new file mode 100644
index 0000000000..1568c177fe
--- /dev/null
+++ b/perl/Git/LoadCPAN.pm
@@ -0,0 +1,74 @@
+package Git::LoadCPAN;
+use 5.008;
+use strict;
+use warnings;
+
+=head1 NAME
+
+Git::LoadCPAN - Wrapper for loading modules from the CPAN (OS) or Git's own copy
+
+=head1 DESCRIPTION
+
+The Perl code in Git depends on some modules from the CPAN, but we
+don't want to make those a hard requirement for anyone building from
+source.
+
+Therefore the L<Git::LoadCPAN> namespace shipped with Git contains
+wrapper modules like C<Git::LoadCPAN::Module::Name> that will first
+attempt to load C<Module::Name> from the OS, and if that doesn't work
+will fall back on C<Git::FromCPAN::Module::Name> shipped with Git
+itself.
+
+Usually distributors will not ship with Git's Git::FromCPAN tree at
+all, preferring to use their own packaging of CPAN modules instead.
+
+This module is only intended to be used for code shipping in the
+C<git.git> repository. Use it for anything else at your peril!
+
+=cut
+
+sub import {
+	shift;
+	my $caller = caller;
+	my %args = @_;
+	my $module = exists $args{module} ? delete $args{module} : die "BUG: Expected 'module' parameter!";
+	my $import = exists $args{import} ? delete $args{import} : die "BUG: Expected 'import' parameter!";
+	die "BUG: Too many arguments!" if keys %args;
+
+	# Foo::Bar to Foo/Bar.pm
+	my $package_pm = $module;
+	$package_pm =~ s[::][/]g;
+	$package_pm .= '.pm';
+
+	eval {
+		require $package_pm;
+		1;
+	} or do {
+		my $error = $@ || "Zombie Error";
+
+		my $Git_LoadCPAN_pm_path = $INC{"Git/LoadCPAN.pm"} || die "BUG: Should have our own path from %INC!";
+
+		require File::Basename;
+		my $Git_LoadCPAN_pm_root = File::Basename::dirname($Git_LoadCPAN_pm_path) || die "BUG: Can't figure out lib/Git dirname from '$Git_LoadCPAN_pm_path'!";
+
+		require File::Spec;
+		my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_LoadCPAN_pm_root, 'FromCPAN');
+		die "BUG: '$Git_pm_FromCPAN_root' should be a directory!" unless -d $Git_pm_FromCPAN_root;
+
+		local @INC = ($Git_pm_FromCPAN_root, @INC);
+		require $package_pm;
+	};
+
+	if ($import) {
+		no strict 'refs';
+		*{"${caller}::import"} = sub {
+			shift;
+			use strict 'refs';
+			unshift @_, $module;
+			goto &{"${module}::import"};
+		};
+		use strict 'refs';
+	}
+}
+
+1;
diff --git a/perl/Git/LoadCPAN/Error.pm b/perl/Git/LoadCPAN/Error.pm
index 3513fe745b..c6d2c45d80 100644
--- a/perl/Git/LoadCPAN/Error.pm
+++ b/perl/Git/LoadCPAN/Error.pm
@@ -2,45 +2,9 @@ package Git::LoadCPAN::Error;
 use 5.008;
 use strict;
 use warnings;
-
-=head1 NAME
-
-Git::LoadCPAN::Error - Wrapper for the L<Error> module, in case it's not installed
-
-=head1 DESCRIPTION
-
-Wraps the import function for the L<Error> module.
-
-This module is only intended to be used for code shipping in the
-C<git.git> repository. Use it for anything else at your peril!
-
-=cut
-
-sub import {
-    shift;
-    my $caller = caller;
-
-    eval {
-	require Error;
-	1;
-    } or do {
-	my $error = $@ || "Zombie Error";
-
-	my $Git_Error_pm_path = $INC{"Git/LoadCPAN/Error.pm"} || die "BUG: Should have our own path from %INC!";
-
-	require File::Basename;
-	my $Git_Error_pm_root = File::Basename::dirname($Git_Error_pm_path) || die "BUG: Can't figure out lib/Git dirname from '$Git_Error_pm_path'!";
-
-	require File::Spec;
-	my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_Error_pm_root, '..', 'FromCPAN');
-	die "BUG: '$Git_pm_FromCPAN_root' should be a directory!" unless -d $Git_pm_FromCPAN_root;
-
-	local @INC = ($Git_pm_FromCPAN_root, @INC);
-	require Error;
-    };
-
-    unshift @_, $caller;
-    goto &Error::import;
-}
+use Git::LoadCPAN (
+	module => 'Error',
+	import => 1,
+);
 
 1;
diff --git a/perl/Git/LoadCPAN/Mail/Address.pm b/perl/Git/LoadCPAN/Mail/Address.pm
index 879c2f5cd1..f70a4f064c 100644
--- a/perl/Git/LoadCPAN/Mail/Address.pm
+++ b/perl/Git/LoadCPAN/Mail/Address.pm
@@ -2,23 +2,9 @@ package Git::LoadCPAN::Mail::Address;
 use 5.008;
 use strict;
 use warnings;
-
-=head1 NAME
-
-Git::LoadCPAN::Mail::Address - Wrapper for the L<Mail::Address> module, in case it's not installed
-
-=head1 DESCRIPTION
-
-This module is only intended to be used for code shipping in the
-C<git.git> repository. Use it for anything else at your peril!
-
-=cut
-
-eval {
-    require Mail::Address;
-    1;
-} or do {
-    require Git::FromCPAN::Mail::Address;
-};
+use Git::LoadCPAN (
+	module => 'Mail::Address',
+	import => 0,
+);
 
 1;
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v2 11/13] perl: move the perl/Git/FromCPAN tree to perl/FromCPAN
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (18 preceding siblings ...)
  2018-02-25 19:46 ` [PATCH v2 10/13] perl: generalize the Git::LoadCPAN facility Ævar Arnfjörð Bjarmason
@ 2018-02-25 19:46 ` Ævar Arnfjörð Bjarmason
  2018-02-25 19:46 ` [PATCH v2 12/13] Makefile: add NO_PERL_CPAN_FALLBACKS knob Ævar Arnfjörð Bjarmason
  2018-02-25 19:46 ` [PATCH v2 13/13] perl Git::LoadCPAN: emit better errors under NO_PERL_CPAN_FALLBACKS Ævar Arnfjörð Bjarmason
  21 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-25 19:46 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Todd Zullinger, Jonathan Nieder, Randall S . Becker,
	Ævar Arnfjörð Bjarmason

Move the CPAN modules that have lived under perl/Git/FromCPAN since my
20d2a30f8f ("Makefile: replace perl/Makefile.PL with simple make
rules", 2017-12-10) to perl/FromCPAN.

A subsequent change will teach the Makefile to only install these
copies of CPAN modules if a flag that distro packagers would like to
set isn't set. Due to how the wildcard globbing is being done it's
much easier to accomplish that if they're moved to their own
directory.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 Makefile                                | 3 +++
 perl/{Git => }/FromCPAN/.gitattributes  | 0
 perl/{Git => }/FromCPAN/Error.pm        | 0
 perl/{Git => }/FromCPAN/Mail/Address.pm | 0
 perl/Git/LoadCPAN.pm                    | 5 ++---
 5 files changed, 5 insertions(+), 3 deletions(-)
 rename perl/{Git => }/FromCPAN/.gitattributes (100%)
 rename perl/{Git => }/FromCPAN/Error.pm (100%)
 rename perl/{Git => }/FromCPAN/Mail/Address.pm (100%)

diff --git a/Makefile b/Makefile
index c56fdc14ca..7b97699864 100644
--- a/Makefile
+++ b/Makefile
@@ -2300,9 +2300,12 @@ po/build/locale/%/LC_MESSAGES/git.mo: po/%.po
 
 LIB_PERL := $(wildcard perl/Git.pm perl/Git/*.pm perl/Git/*/*.pm perl/Git/*/*/*.pm)
 LIB_PERL_GEN := $(patsubst perl/%.pm,perl/build/lib/%.pm,$(LIB_PERL))
+LIB_CPAN := $(wildcard perl/FromCPAN/*.pm perl/FromCPAN/*/*.pm)
+LIB_CPAN_GEN := $(patsubst perl/%.pm,perl/build/lib/%.pm,$(LIB_CPAN))
 
 ifndef NO_PERL
 all:: $(LIB_PERL_GEN)
+all:: $(LIB_CPAN_GEN)
 endif
 
 perl/build/lib/%.pm: perl/%.pm
diff --git a/perl/Git/FromCPAN/.gitattributes b/perl/FromCPAN/.gitattributes
similarity index 100%
rename from perl/Git/FromCPAN/.gitattributes
rename to perl/FromCPAN/.gitattributes
diff --git a/perl/Git/FromCPAN/Error.pm b/perl/FromCPAN/Error.pm
similarity index 100%
rename from perl/Git/FromCPAN/Error.pm
rename to perl/FromCPAN/Error.pm
diff --git a/perl/Git/FromCPAN/Mail/Address.pm b/perl/FromCPAN/Mail/Address.pm
similarity index 100%
rename from perl/Git/FromCPAN/Mail/Address.pm
rename to perl/FromCPAN/Mail/Address.pm
diff --git a/perl/Git/LoadCPAN.pm b/perl/Git/LoadCPAN.pm
index 1568c177fe..229c1ee87d 100644
--- a/perl/Git/LoadCPAN.pm
+++ b/perl/Git/LoadCPAN.pm
@@ -16,8 +16,7 @@ source.
 Therefore the L<Git::LoadCPAN> namespace shipped with Git contains
 wrapper modules like C<Git::LoadCPAN::Module::Name> that will first
 attempt to load C<Module::Name> from the OS, and if that doesn't work
-will fall back on C<Git::FromCPAN::Module::Name> shipped with Git
-itself.
+will fall back on C<FromCPAN::Module::Name> shipped with Git itself.
 
 Usually distributors will not ship with Git's Git::FromCPAN tree at
 all, preferring to use their own packaging of CPAN modules instead.
@@ -52,7 +51,7 @@ sub import {
 		my $Git_LoadCPAN_pm_root = File::Basename::dirname($Git_LoadCPAN_pm_path) || die "BUG: Can't figure out lib/Git dirname from '$Git_LoadCPAN_pm_path'!";
 
 		require File::Spec;
-		my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_LoadCPAN_pm_root, 'FromCPAN');
+		my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_LoadCPAN_pm_root, '..', 'FromCPAN');
 		die "BUG: '$Git_pm_FromCPAN_root' should be a directory!" unless -d $Git_pm_FromCPAN_root;
 
 		local @INC = ($Git_pm_FromCPAN_root, @INC);
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v2 12/13] Makefile: add NO_PERL_CPAN_FALLBACKS knob
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (19 preceding siblings ...)
  2018-02-25 19:46 ` [PATCH v2 11/13] perl: move the perl/Git/FromCPAN tree to perl/FromCPAN Ævar Arnfjörð Bjarmason
@ 2018-02-25 19:46 ` Ævar Arnfjörð Bjarmason
  2018-02-25 19:46 ` [PATCH v2 13/13] perl Git::LoadCPAN: emit better errors under NO_PERL_CPAN_FALLBACKS Ævar Arnfjörð Bjarmason
  21 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-25 19:46 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Todd Zullinger, Jonathan Nieder, Randall S . Becker,
	Ævar Arnfjörð Bjarmason

From: Todd Zullinger <tmz@pobox.com>

We include some perl modules which are not part of the core perl
install, as a convenience.  This allows us to rely on those modules in
our perl-based tools and scripts without requiring users to install the
modules from CPAN or their operating system packages.

Users whose operating system provides these modules and packagers of Git
often don't want to ship or use these bundled modules.  Allow these
users to set NO_PERL_CPAN_FALLBACKS to avoid installing the bundled
modules.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 Makefile | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/Makefile b/Makefile
index 7b97699864..518c5f6be0 100644
--- a/Makefile
+++ b/Makefile
@@ -296,6 +296,12 @@ all::
 #
 # Define NO_PERL if you do not want Perl scripts or libraries at all.
 #
+# Define NO_PERL_CPAN_FALLBACKS if you do not want to install bundled
+# copies of CPAN modules that serve as a fallback in case the modules
+# are not available on the system. This option is intended for
+# distributions that want to use their packaged versions of Perl
+# modules, instead of the fallbacks shipped with Git.
+#
 # Define PYTHON_PATH to the path of your Python binary (often /usr/bin/python
 # but /usr/bin/python2.7 on some platforms).
 #
@@ -2305,8 +2311,10 @@ LIB_CPAN_GEN := $(patsubst perl/%.pm,perl/build/lib/%.pm,$(LIB_CPAN))
 
 ifndef NO_PERL
 all:: $(LIB_PERL_GEN)
+ifndef NO_PERL_CPAN_FALLBACKS
 all:: $(LIB_CPAN_GEN)
 endif
+endif
 
 perl/build/lib/%.pm: perl/%.pm
 	$(QUIET_GEN)mkdir -p $(dir $@) && \
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v2 13/13] perl Git::LoadCPAN: emit better errors under NO_PERL_CPAN_FALLBACKS
  2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
                   ` (20 preceding siblings ...)
  2018-02-25 19:46 ` [PATCH v2 12/13] Makefile: add NO_PERL_CPAN_FALLBACKS knob Ævar Arnfjörð Bjarmason
@ 2018-02-25 19:46 ` Ævar Arnfjörð Bjarmason
  21 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-25 19:46 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Benoit Bourbie,
	Jeff King, Johannes Schindelin, Jari Aalto, Giuseppe Bilotta,
	Todd Zullinger, Jonathan Nieder, Randall S . Becker,
	Ævar Arnfjörð Bjarmason

Before my 20d2a30f8f ("Makefile: replace perl/Makefile.PL with simple
make rules", 2017-12-10) on an OS package that removed the
private-Error.pm copy we carried around manually removing the OS's
Error.pm would yield:

    $ git add -p
    Can't locate Error.pm in @INC (you may need to install the Error module) [...]

Now, before this change we'll instead emit this more cryptic error:

    $ git add -p
    BUG: '/usr/share/perl5/Git/FromCPAN' should be a directory! at /usr/share/perl5/Git/Error.pm line 36.

This is a confusing error. Now if the new NO_PERL_CPAN_FALLBACKS
option is specified and we can't find the module we'll instead emit:

    $ /tmp/git/bin/git add -p
    BUG: The 'Error' module is not here, but NO_PERL_CPAN_FALLBACKS was set!

    [...]

Where [...] is the lengthy explanation seen in the change below, which
explains what the potential breakage is, and how to fix it.

The reason for checking @@NO_PERL_CPAN_FALLBACKS@@] against the empty
string in Perl is as opposed to checking for a boolean value is that
that's (as far as I can tell) make's idea of a string that's set, and
e.g. NO_PERL_CPAN_FALLBACKS=0 is enough to set NO_PERL_CPAN_FALLBACKS.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 INSTALL              | 11 ++++++++---
 Makefile             |  5 ++++-
 perl/Git/LoadCPAN.pm | 33 ++++++++++++++++++++++++++++++++-
 3 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/INSTALL b/INSTALL
index 808e07b659..60e515eaf7 100644
--- a/INSTALL
+++ b/INSTALL
@@ -88,9 +88,9 @@ Issues of note:
 	export GIT_EXEC_PATH PATH GITPERLLIB
 
  - By default (unless NO_PERL is provided) Git will ship various perl
-   scripts & libraries it needs. However, for simplicity it doesn't
-   use the ExtUtils::MakeMaker toolchain to decide where to place the
-   perl libraries. Depending on the system this can result in the perl
+   scripts. However, for simplicity it doesn't use the
+   ExtUtils::MakeMaker toolchain to decide where to place the perl
+   libraries. Depending on the system this can result in the perl
    libraries not being where you'd like them if they're expected to be
    used by things other than Git itself.
 
@@ -102,6 +102,11 @@ Issues of note:
    Will result in e.g. perllibdir=/usr/share/perl/5.26.1 on Debian,
    perllibdir=/usr/share/perl5 (which we'd use by default) on CentOS.
 
+ - Unless NO_PERL is provided Git will ship various perl libraries it
+   needs. Distributors of Git will usually want to set
+   NO_PERL_CPAN_FALLBACKS if NO_PERL is not provided to use their own
+   copies of the CPAN modules Git needs.
+
  - Git is reasonably self-sufficient, but does depend on a few external
    programs and libraries.  Git can be used without most of them by adding
    the approriate "NO_<LIBRARY>=YesPlease" to the make command line or
diff --git a/Makefile b/Makefile
index 518c5f6be0..4e0cdb3ca4 100644
--- a/Makefile
+++ b/Makefile
@@ -2314,11 +2314,14 @@ all:: $(LIB_PERL_GEN)
 ifndef NO_PERL_CPAN_FALLBACKS
 all:: $(LIB_CPAN_GEN)
 endif
+NO_PERL_CPAN_FALLBACKS_SQ = $(subst ','\'',$(NO_PERL_CPAN_FALLBACKS))
 endif
 
 perl/build/lib/%.pm: perl/%.pm
 	$(QUIET_GEN)mkdir -p $(dir $@) && \
-	sed -e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' < $< > $@
+	sed -e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' \
+	    -e 's|@@NO_PERL_CPAN_FALLBACKS@@|$(NO_PERL_CPAN_FALLBACKS_SQ)|g' \
+	< $< > $@
 
 perl/build/man/man3/Git.3pm: perl/Git.pm
 	$(QUIET_GEN)mkdir -p $(dir $@) && \
diff --git a/perl/Git/LoadCPAN.pm b/perl/Git/LoadCPAN.pm
index 229c1ee87d..e5585e75e8 100644
--- a/perl/Git/LoadCPAN.pm
+++ b/perl/Git/LoadCPAN.pm
@@ -19,13 +19,25 @@ attempt to load C<Module::Name> from the OS, and if that doesn't work
 will fall back on C<FromCPAN::Module::Name> shipped with Git itself.
 
 Usually distributors will not ship with Git's Git::FromCPAN tree at
-all, preferring to use their own packaging of CPAN modules instead.
+all via the C<NO_PERL_CPAN_FALLBACKS> option, preferring to use their
+own packaging of CPAN modules instead.
 
 This module is only intended to be used for code shipping in the
 C<git.git> repository. Use it for anything else at your peril!
 
 =cut
 
+# NO_PERL_CPAN_FALLBACKS_STR evades the sed search-replace from the
+# Makefile, and allows for detecting whether the module is loaded from
+# perl/Git as opposed to perl/build/Git, which is useful for one-off
+# testing without having Error.pm et al installed.
+use constant NO_PERL_CPAN_FALLBACKS_STR => '@@' . 'NO_PERL_CPAN_FALLBACKS' . '@@';
+use constant NO_PERL_CPAN_FALLBACKS => (
+	q[@@NO_PERL_CPAN_FALLBACKS@@] ne ''
+	and
+	q[@@NO_PERL_CPAN_FALLBACKS@@] ne NO_PERL_CPAN_FALLBACKS_STR
+);
+
 sub import {
 	shift;
 	my $caller = caller;
@@ -45,6 +57,25 @@ sub import {
 	} or do {
 		my $error = $@ || "Zombie Error";
 
+		if (NO_PERL_CPAN_FALLBACKS) {
+			chomp(my $error = sprintf <<'THEY_PROMISED', $module);
+BUG: The '%s' module is not here, but NO_PERL_CPAN_FALLBACKS was set!
+
+Git needs this Perl module from the CPAN, and will by default ship
+with a copy of it. This Git was built with NO_PERL_CPAN_FALLBACKS,
+meaning that whoever built it promised to provide this module.
+
+You're seeing this error because they broke that promise, and we can't
+load our fallback version, since we were asked not to install it.
+
+If you're seeing this error and didn't package Git yourself the
+package you're using is broken, or your system is broken. This error
+won't appear if Git is built without NO_PERL_CPAN_FALLBACKS (instead
+we'll use our fallback version of the module).
+THEY_PROMISED
+			die $error;
+		}
+
 		my $Git_LoadCPAN_pm_path = $INC{"Git/LoadCPAN.pm"} || die "BUG: Should have our own path from %INC!";
 
 		require File::Basename;
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* Re: [PATCH v2 04/13] gitweb: hard-depend on the Digest::MD5 5.8 module
  2018-02-25 19:46 ` [PATCH v2 04/13] gitweb: hard-depend on the Digest::MD5 5.8 module Ævar Arnfjörð Bjarmason
@ 2018-02-25 20:00   ` Eric Sunshine
  0 siblings, 0 replies; 66+ messages in thread
From: Eric Sunshine @ 2018-02-25 20:00 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Git List, Junio C Hamano, Matthieu Moy, Petr Baudis,
	Benoit Bourbie, Jeff King, Johannes Schindelin, Jari Aalto,
	Giuseppe Bilotta, Todd Zullinger, Jonathan Nieder,
	Randall S . Becker

On Sun, Feb 25, 2018 at 2:46 PM, Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> Since my d48b284183 ("perl: bump the required Perl version to 5.8 from
> 5.6.[21]", 2010-09-24), we've depended on 5.8, so there's no reason to
> conditionally require Digest::MD5 anymore. It was released with perl
> v5.7.3[1]
>
> The initial introduction of the dependency in
> e9fdd74e53 ("gitweb: (gr)avatar support", 2009-06-30) says as much,
> this also undoes part of the later 2e9c8789b7 ("gitweb: Mention
> optional Perl modules in INSTALL", 2011-02-04) since gitweb will
> always be run on at least 5.8, so there's no need to mention
> Digest::MD5 as a required module in the documentation, let's instead
> say that we require perl 5.8.
>
> As with the preceding Net::{SMTP,Domain} change we now unconditionally
> "use" the module instead.

This is patch 4/13 but the Net::{SMTP,Domain} change doesn't come
until 6/13, so saying "preceding" is confusing.

> 1. $ corelist Digest::MD5
>    Data for 2015-02-14
>    Digest::MD5 was first released with perl v5.7.3
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v2 06/13] git-send-email: unconditionally use Net::{SMTP,Domain}
  2018-02-25 19:46 ` [PATCH v2 06/13] git-send-email: unconditionally use Net::{SMTP,Domain} Ævar Arnfjörð Bjarmason
@ 2018-02-25 20:03   ` Eric Sunshine
  0 siblings, 0 replies; 66+ messages in thread
From: Eric Sunshine @ 2018-02-25 20:03 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Git List, Junio C Hamano, Matthieu Moy, Petr Baudis,
	Benoit Bourbie, Jeff King, Johannes Schindelin, Jari Aalto,
	Giuseppe Bilotta, Todd Zullinger, Jonathan Nieder,
	Randall S . Becker

On Sun, Feb 25, 2018 at 2:46 PM, Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> The Net::SMTP and Net::Domain were both first released with perl
> v5.7.3[1], since my d48b284183 ("perl: bump the required Perl version
> to 5.8 from 5.6.[21]", 2010-09-24) we've depended on 5.8, so there's
> no reason to conditionally require this anymore.

s/this/them/ or s/this/these/

> This conditional loading was initially added in
> 87840620fd ("send-email: only 'require' instead of 'use' Net::SMTP",
> 2006-06-01) for Net::SMTP and 134550fe21 ("git-send-email.perl - try
> to give real name of the calling host to HELO/EHLO", 2010-03-14) for
> Net::Domain, both of which predate the hard dependency on 5.8.
>
> Since they're guaranteed to be installed now let's "use" them
> instead. The cost of loading them both is trivial given what
> git-send-email does (~15ms on my system), and it's better to not defer
> any potential loading errors until runtime.
>
> This patch is better viewed with -w, which shows that the only change
> in the last two hunks is removing the "if eval" wrapper block.
>
> 1. $ parallel 'corelist {}' ::: Net::{SMTP,Domain}
>    Data for 2015-02-14
>    Net::SMTP was first released with perl v5.7.3
>
>    Data for 2015-02-14
>    Net::Domain was first released with perl v5.7.3
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>

^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v3 00/13] various perl fixes
  2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
@ 2018-03-03 15:38   ` Ævar Arnfjörð Bjarmason
  2018-03-05 19:01     ` Junio C Hamano
  2018-03-03 15:38   ` [PATCH v3 01/13] perl: *.pm files should not have the executable bit Ævar Arnfjörð Bjarmason
                     ` (12 subsequent siblings)
  13 siblings, 1 reply; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-03-03 15:38 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Todd Zullinger,
	Jonathan Nieder, Randall S . Becker, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

Same as v2 except rebased on master & a couple of commit message
fixes, thanks to Eric Sunshine (thanks!). tbdiff with v2:

 4: 0d67af28fb !  4: 8ad874c944 gitweb: hard-depend on the Digest::MD5 5.8 module
    @@ -14,9 +14,6 @@
         always be run on at least 5.8, so there's no need to mention
         Digest::MD5 as a required module in the documentation, let's instead
         say that we require perl 5.8.
    -    
    -    As with the preceding Net::{SMTP,Domain} change we now unconditionally
    -    "use" the module instead.
         
         1. $ corelist Digest::MD5
            Data for 2015-02-14
 [...]
 6: 92429af3a3 !  6: 3f44312821 git-send-email: unconditionally use Net::{SMTP,Domain}
    @@ -5,7 +5,7 @@
         The Net::SMTP and Net::Domain were both first released with perl
         v5.7.3[1], since my d48b284183 ("perl: bump the required Perl version
         to 5.8 from 5.6.[21]", 2010-09-24) we've depended on 5.8, so there's
    -    no reason to conditionally require this anymore.
    +    no reason to conditionally require them anymore.
         
         This conditional loading was initially added in
         87840620fd ("send-email: only 'require' instead of 'use' Net::SMTP",

Todd Zullinger (1):
  Makefile: add NO_PERL_CPAN_FALLBACKS knob

Ævar Arnfjörð Bjarmason (12):
  perl: *.pm files should not have the executable bit
  Git.pm: remove redundant "use strict" from sub-package
  Git.pm: add the "use warnings" pragma
  gitweb: hard-depend on the Digest::MD5 5.8 module
  Git.pm: hard-depend on the File::{Temp,Spec} modules
  git-send-email: unconditionally use Net::{SMTP,Domain}
  perl: update our ancient copy of Error.pm
  perl: update our copy of Mail::Address
  perl: move CPAN loader wrappers to another namespace
  perl: generalize the Git::LoadCPAN facility
  perl: move the perl/Git/FromCPAN tree to perl/FromCPAN
  perl Git::LoadCPAN: emit better errors under NO_PERL_CPAN_FALLBACKS

 INSTALL                                 |  11 +-
 Makefile                                |  16 +-
 contrib/examples/git-difftool.perl      |   2 +-
 git-send-email.perl                     |  28 ++-
 gitweb/INSTALL                          |   3 +-
 gitweb/gitweb.perl                      |  17 +-
 perl/FromCPAN/.gitattributes            |   1 +
 perl/{Git => }/FromCPAN/Error.pm        | 296 +++++++++++++++++++++++++++-----
 perl/{Git => }/FromCPAN/Mail/Address.pm |   8 +-
 perl/Git.pm                             |  14 +-
 perl/Git/Error.pm                       |  46 -----
 perl/Git/LoadCPAN.pm                    | 104 +++++++++++
 perl/Git/LoadCPAN/Error.pm              |  10 ++
 perl/Git/LoadCPAN/Mail/Address.pm       |  10 ++
 perl/Git/Mail/Address.pm                |  24 ---
 15 files changed, 432 insertions(+), 158 deletions(-)
 create mode 100644 perl/FromCPAN/.gitattributes
 rename perl/{Git => }/FromCPAN/Error.pm (72%)
 rename perl/{Git => }/FromCPAN/Mail/Address.pm (96%)
 delete mode 100644 perl/Git/Error.pm
 create mode 100644 perl/Git/LoadCPAN.pm
 create mode 100644 perl/Git/LoadCPAN/Error.pm
 create mode 100644 perl/Git/LoadCPAN/Mail/Address.pm
 delete mode 100755 perl/Git/Mail/Address.pm

-- 
2.15.1.424.g9478a66081


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v3 01/13] perl: *.pm files should not have the executable bit
  2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 " Ævar Arnfjörð Bjarmason
@ 2018-03-03 15:38   ` Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 02/13] Git.pm: remove redundant "use strict" from sub-package Ævar Arnfjörð Bjarmason
                     ` (11 subsequent siblings)
  13 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-03-03 15:38 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Todd Zullinger,
	Jonathan Nieder, Randall S . Becker, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

The Git::Mail::Address file added in bd869f67b9 ("send-email: add and
use a local copy of Mail::Address", 2018-01-05) had the executable bit
set. That bit should not be set for *.pm files. It breaks nothing but
it is redundant and confusing as none of the other files have it and
these files are never executed as stand-alone programs.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git/Mail/Address.pm | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 mode change 100755 => 100644 perl/Git/Mail/Address.pm

diff --git a/perl/Git/Mail/Address.pm b/perl/Git/Mail/Address.pm
old mode 100755
new mode 100644
-- 
2.15.1.424.g9478a66081


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v3 02/13] Git.pm: remove redundant "use strict" from sub-package
  2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 " Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 01/13] perl: *.pm files should not have the executable bit Ævar Arnfjörð Bjarmason
@ 2018-03-03 15:38   ` Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 03/13] Git.pm: add the "use warnings" pragma Ævar Arnfjörð Bjarmason
                     ` (10 subsequent siblings)
  13 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-03-03 15:38 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Todd Zullinger,
	Jonathan Nieder, Randall S . Becker, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

In Perl the "use strict/warnings" pragmas are lexical, thus there's no
reason to do:

    package Foo;
    use strict;
    package Bar;
    use strict;
    $x = 5;

To satisfy the desire that the undeclared $x variable will be spotted
at compile-time. It's enough to include the first "use strict".

This functionally changes nothing, but makes a subsequent change where
"use warnings" will be added to Git.pm less confusing and less
verbose, since as with "strict" we'll only need to do that at the top
of the file.

Changes code initially added in a6065b548f ("Git.pm: Try to support
ActiveState output pipe", 2006-06-25).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git.pm | 1 -
 1 file changed, 1 deletion(-)

diff --git a/perl/Git.pm b/perl/Git.pm
index 9d60d7948b..99e5d943af 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -1692,7 +1692,6 @@ sub DESTROY {
 # Pipe implementation for ActiveState Perl.
 
 package Git::activestate_pipe;
-use strict;
 
 sub TIEHANDLE {
 	my ($class, @params) = @_;
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v3 03/13] Git.pm: add the "use warnings" pragma
  2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
                     ` (2 preceding siblings ...)
  2018-03-03 15:38   ` [PATCH v3 02/13] Git.pm: remove redundant "use strict" from sub-package Ævar Arnfjörð Bjarmason
@ 2018-03-03 15:38   ` Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 04/13] gitweb: hard-depend on the Digest::MD5 5.8 module Ævar Arnfjörð Bjarmason
                     ` (9 subsequent siblings)
  13 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-03-03 15:38 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Todd Zullinger,
	Jonathan Nieder, Randall S . Becker, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

Amend Git.pm to load the "warnings" pragma like the rest of the code
in perl/ in addition to the existing "strict" pragma. This is
considered the bare minimum best practice in Perl.

Ever since this code was introduced in b1edc53d06 ("Introduce
Git.pm (v4)", 2006-06-24) it's only been using "strict", not
"warnings".

This leaves contrib/buildsystems/Generators/{QMake,VCproj}.pm and
contrib/mw-to-git/Git/Mediawiki.pm without "use warnings". Amending
those would be a sensible follow-up change, but I don't have an easy
way to test those so I'm not changing them.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git.pm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/perl/Git.pm b/perl/Git.pm
index 99e5d943af..7ec16e6dde 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -9,6 +9,7 @@ package Git;
 
 use 5.008;
 use strict;
+use warnings;
 
 
 BEGIN {
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v3 04/13] gitweb: hard-depend on the Digest::MD5 5.8 module
  2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
                     ` (3 preceding siblings ...)
  2018-03-03 15:38   ` [PATCH v3 03/13] Git.pm: add the "use warnings" pragma Ævar Arnfjörð Bjarmason
@ 2018-03-03 15:38   ` Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 05/13] Git.pm: hard-depend on the File::{Temp,Spec} modules Ævar Arnfjörð Bjarmason
                     ` (8 subsequent siblings)
  13 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-03-03 15:38 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Todd Zullinger,
	Jonathan Nieder, Randall S . Becker, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

Since my d48b284183 ("perl: bump the required Perl version to 5.8 from
5.6.[21]", 2010-09-24), we've depended on 5.8, so there's no reason to
conditionally require Digest::MD5 anymore. It was released with perl
v5.7.3[1]

The initial introduction of the dependency in
e9fdd74e53 ("gitweb: (gr)avatar support", 2009-06-30) says as much,
this also undoes part of the later 2e9c8789b7 ("gitweb: Mention
optional Perl modules in INSTALL", 2011-02-04) since gitweb will
always be run on at least 5.8, so there's no need to mention
Digest::MD5 as a required module in the documentation, let's instead
say that we require perl 5.8.

1. $ corelist Digest::MD5
   Data for 2015-02-14
   Digest::MD5 was first released with perl v5.7.3

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 gitweb/INSTALL     |  3 +--
 gitweb/gitweb.perl | 17 ++++-------------
 2 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/gitweb/INSTALL b/gitweb/INSTALL
index 408f2859d3..a58e6b3c44 100644
--- a/gitweb/INSTALL
+++ b/gitweb/INSTALL
@@ -29,12 +29,11 @@ Requirements
 ------------
 
  - Core git tools
- - Perl
+ - Perl 5.8
  - Perl modules: CGI, Encode, Fcntl, File::Find, File::Basename.
  - web server
 
 The following optional Perl modules are required for extra features
- - Digest::MD5 - for gravatar support
  - CGI::Fast and FCGI - for running gitweb as FastCGI script
  - HTML::TagCloud - for fancy tag cloud in project list view
  - HTTP::Date or Time::ParseDate - to support If-Modified-Since for feeds
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 2417057f2b..2594a4badb 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -20,6 +20,8 @@ use Fcntl ':mode';
 use File::Find qw();
 use File::Basename qw(basename);
 use Time::HiRes qw(gettimeofday tv_interval);
+use Digest::MD5 qw(md5_hex);
+
 binmode STDOUT, ':utf8';
 
 if (!defined($CGI::VERSION) || $CGI::VERSION < 4.08) {
@@ -490,7 +492,6 @@ our %feature = (
 	# Currently available providers are gravatar and picon.
 	# If an unknown provider is specified, the feature is disabled.
 
-	# Gravatar depends on Digest::MD5.
 	# Picon currently relies on the indiana.edu database.
 
 	# To enable system wide have in $GITWEB_CONFIG
@@ -1166,18 +1167,8 @@ sub configure_gitweb_features {
 	our @snapshot_fmts = gitweb_get_feature('snapshot');
 	@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
 
-	# check that the avatar feature is set to a known provider name,
-	# and for each provider check if the dependencies are satisfied.
-	# if the provider name is invalid or the dependencies are not met,
-	# reset $git_avatar to the empty string.
 	our ($git_avatar) = gitweb_get_feature('avatar');
-	if ($git_avatar eq 'gravatar') {
-		$git_avatar = '' unless (eval { require Digest::MD5; 1; });
-	} elsif ($git_avatar eq 'picon') {
-		# no dependencies
-	} else {
-		$git_avatar = '';
-	}
+	$git_avatar = '' unless $git_avatar =~ /^(?:gravatar|picon)$/s;
 
 	our @extra_branch_refs = gitweb_get_feature('extra-branch-refs');
 	@extra_branch_refs = filter_and_validate_refs (@extra_branch_refs);
@@ -2167,7 +2158,7 @@ sub gravatar_url {
 	my $size = shift;
 	$avatar_cache{$email} ||=
 		"//www.gravatar.com/avatar/" .
-			Digest::MD5::md5_hex($email) . "?s=";
+			md5_hex($email) . "?s=";
 	return $avatar_cache{$email} . $size;
 }
 
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v3 05/13] Git.pm: hard-depend on the File::{Temp,Spec} modules
  2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
                     ` (4 preceding siblings ...)
  2018-03-03 15:38   ` [PATCH v3 04/13] gitweb: hard-depend on the Digest::MD5 5.8 module Ævar Arnfjörð Bjarmason
@ 2018-03-03 15:38   ` Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 06/13] git-send-email: unconditionally use Net::{SMTP,Domain} Ævar Arnfjörð Bjarmason
                     ` (7 subsequent siblings)
  13 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-03-03 15:38 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Todd Zullinger,
	Jonathan Nieder, Randall S . Becker, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

Since my d48b284183 ("perl: bump the required Perl version to 5.8 from
5.6.[21]", 2010-09-24), we've depended on 5.8, so there's no reason to
conditionally require File::Temp and File::Spec anymore. They were
first released with perl versions v5.6.1 and 5.00405, respectively.

This code was originally added in c14c8ceb13 ("Git.pm: Make File::Spec
and File::Temp requirement lazy", 2008-08-15), presumably to make
Git.pm work on 5.6.0.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git.pm | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/perl/Git.pm b/perl/Git.pm
index 7ec16e6dde..151b0e7144 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -11,6 +11,8 @@ use 5.008;
 use strict;
 use warnings;
 
+use File::Temp ();
+use File::Spec ();
 
 BEGIN {
 
@@ -190,7 +192,6 @@ sub repository {
 		};
 
 		if ($dir) {
-			_verify_require();
 			File::Spec->file_name_is_absolute($dir) or $dir = $opts{Directory} . '/' . $dir;
 			$opts{Repository} = abs_path($dir);
 
@@ -1289,8 +1290,6 @@ sub temp_release {
 sub _temp_cache {
 	my ($self, $name) = _maybe_self(@_);
 
-	_verify_require();
-
 	my $temp_fd = \$TEMP_FILEMAP{$name};
 	if (defined $$temp_fd and $$temp_fd->opened) {
 		if ($TEMP_FILES{$$temp_fd}{locked}) {
@@ -1324,11 +1323,6 @@ sub _temp_cache {
 	$$temp_fd;
 }
 
-sub _verify_require {
-	eval { require File::Temp; require File::Spec; };
-	$@ and throw Error::Simple($@);
-}
-
 =item temp_reset ( FILEHANDLE )
 
 Truncates and resets the position of the C<FILEHANDLE>.
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v3 06/13] git-send-email: unconditionally use Net::{SMTP,Domain}
  2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
                     ` (5 preceding siblings ...)
  2018-03-03 15:38   ` [PATCH v3 05/13] Git.pm: hard-depend on the File::{Temp,Spec} modules Ævar Arnfjörð Bjarmason
@ 2018-03-03 15:38   ` Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 07/13] perl: update our ancient copy of Error.pm Ævar Arnfjörð Bjarmason
                     ` (6 subsequent siblings)
  13 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-03-03 15:38 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Todd Zullinger,
	Jonathan Nieder, Randall S . Becker, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

The Net::SMTP and Net::Domain were both first released with perl
v5.7.3[1], since my d48b284183 ("perl: bump the required Perl version
to 5.8 from 5.6.[21]", 2010-09-24) we've depended on 5.8, so there's
no reason to conditionally require them anymore.

This conditional loading was initially added in
87840620fd ("send-email: only 'require' instead of 'use' Net::SMTP",
2006-06-01) for Net::SMTP and 134550fe21 ("git-send-email.perl - try
to give real name of the calling host to HELO/EHLO", 2010-03-14) for
Net::Domain, both of which predate the hard dependency on 5.8.

Since they're guaranteed to be installed now let's "use" them
instead. The cost of loading them both is trivial given what
git-send-email does (~15ms on my system), and it's better to not defer
any potential loading errors until runtime.

This patch is better viewed with -w, which shows that the only change
in the last two hunks is removing the "if eval" wrapper block.

1. $ parallel 'corelist {}' ::: Net::{SMTP,Domain}
   Data for 2015-02-14
   Net::SMTP was first released with perl v5.7.3

   Data for 2015-02-14
   Net::Domain was first released with perl v5.7.3

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 git-send-email.perl | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index bbf4deaa0d..d5a4826a1c 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -31,6 +31,8 @@ use Cwd qw(abs_path cwd);
 use Git;
 use Git::I18N;
 use Git::Mail::Address;
+use Net::Domain ();
+use Net::SMTP ();
 
 Getopt::Long::Configure qw/ pass_through /;
 
@@ -1143,10 +1145,8 @@ sub valid_fqdn {
 sub maildomain_net {
 	my $maildomain;
 
-	if (eval { require Net::Domain; 1 }) {
-		my $domain = Net::Domain::domainname();
-		$maildomain = $domain if valid_fqdn($domain);
-	}
+	my $domain = Net::Domain::domainname();
+	$maildomain = $domain if valid_fqdn($domain);
 
 	return $maildomain;
 }
@@ -1154,17 +1154,15 @@ sub maildomain_net {
 sub maildomain_mta {
 	my $maildomain;
 
-	if (eval { require Net::SMTP; 1 }) {
-		for my $host (qw(mailhost localhost)) {
-			my $smtp = Net::SMTP->new($host);
-			if (defined $smtp) {
-				my $domain = $smtp->domain;
-				$smtp->quit;
+	for my $host (qw(mailhost localhost)) {
+		my $smtp = Net::SMTP->new($host);
+		if (defined $smtp) {
+			my $domain = $smtp->domain;
+			$smtp->quit;
 
-				$maildomain = $domain if valid_fqdn($domain);
+			$maildomain = $domain if valid_fqdn($domain);
 
-				last if $maildomain;
-			}
+			last if $maildomain;
 		}
 	}
 
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v3 07/13] perl: update our ancient copy of Error.pm
  2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
                     ` (6 preceding siblings ...)
  2018-03-03 15:38   ` [PATCH v3 06/13] git-send-email: unconditionally use Net::{SMTP,Domain} Ævar Arnfjörð Bjarmason
@ 2018-03-03 15:38   ` Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 08/13] perl: update our copy of Mail::Address Ævar Arnfjörð Bjarmason
                     ` (5 subsequent siblings)
  13 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-03-03 15:38 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Todd Zullinger,
	Jonathan Nieder, Randall S . Becker, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

The Error.pm shipped with Git as a fallback if there was no Error.pm
on the system was released in April 2006. There's been dozens of
releases since then, the latest at August 7, 2017. Let's update to
that.

I don't know of anything we need from this new release or which this
fixes. This change is simply a matter of keeping up with
upstream. Before this users who'd install git via their package system
would get an up-to-date Error.pm, but if it's installed from source
they'd get one more than a decade old.

This undoes a local hack we'd accumulated in 96bc4de85c ("Eliminate
Scalar::Util usage from private-Error.pm", 2006-07-26), it's been
redundant since my d48b284183 ("perl: bump the required Perl version
to 5.8 from 5.6.[21]", 2010-09-24).

This also undoes 3a51467b94 ("Typo fix: replacing it's -> its",
2013-04-13). This is the Nth time I find that some upstream code of
ours (in contrib/, in sha1dc/ and now in perl/ ...) has diverged from
upstream because of some tree-wide typo fixing. Let's not do those
fixes against upstream projects, it's more valuable that we have a 1=1
mapping to upstream than to fix typos in docs we never even generate
from this code. If someone wants to fix typos in them fine, but they
should do it with a patch to upstream which git.git can then
incorporate.

The upstream code doesn't cleanly pass a --check, so I'm adding a
.gitattributes file for similar reasons as done for sha1dc in
5d184f468e ("sha1dc: ignore indent-with-non-tab whitespace
violations", 2017-06-06).

The updated source was retrieved from
https://fastapi.metacpan.org/source/SHLOMIF/Error-0.17025/lib/Error.pm

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git/FromCPAN/.gitattributes |   1 +
 perl/Git/FromCPAN/Error.pm       | 296 +++++++++++++++++++++++++++++++++------
 2 files changed, 256 insertions(+), 41 deletions(-)
 create mode 100644 perl/Git/FromCPAN/.gitattributes

diff --git a/perl/Git/FromCPAN/.gitattributes b/perl/Git/FromCPAN/.gitattributes
new file mode 100644
index 0000000000..8b64fc5e22
--- /dev/null
+++ b/perl/Git/FromCPAN/.gitattributes
@@ -0,0 +1 @@
+/Error.pm whitespace=-blank-at-eof
diff --git a/perl/Git/FromCPAN/Error.pm b/perl/Git/FromCPAN/Error.pm
index 6098135ae2..f9c36e9e98 100644
--- a/perl/Git/FromCPAN/Error.pm
+++ b/perl/Git/FromCPAN/Error.pm
@@ -12,10 +12,12 @@
 package Error;
 
 use strict;
+use warnings;
+
 use vars qw($VERSION);
 use 5.004;
 
-$VERSION = "0.15009";
+$VERSION = "0.17025";
 
 use overload (
 	'""'	   =>	'stringify',
@@ -32,21 +34,35 @@ $Error::THROWN = undef;	# last error thrown, a workaround until die $ref works
 my $LAST;		# Last error created
 my %ERROR;		# Last error associated with package
 
-sub throw_Error_Simple
+sub _throw_Error_Simple
 {
     my $args = shift;
     return Error::Simple->new($args->{'text'});
 }
 
-$Error::ObjectifyCallback = \&throw_Error_Simple;
+$Error::ObjectifyCallback = \&_throw_Error_Simple;
 
 
 # Exported subs are defined in Error::subs
 
+use Scalar::Util ();
+
 sub import {
     shift;
+    my @tags = @_;
     local $Exporter::ExportLevel = $Exporter::ExportLevel + 1;
-    Error::subs->import(@_);
+
+    @tags = grep {
+       if( $_ eq ':warndie' ) {
+          Error::WarnDie->import();
+          0;
+       }
+       else {
+          1;
+       }
+    } @tags;
+
+    Error::subs->import(@tags);
 }
 
 # I really want to use last for the name of this method, but it is a keyword
@@ -107,10 +123,6 @@ sub stacktrace {
     $text;
 }
 
-# Allow error propagation, ie
-#
-# $ber->encode(...) or
-#    return Error->prior($ber)->associate($ldap);
 
 sub associate {
     my $err = shift;
@@ -130,6 +142,7 @@ sub associate {
     return;
 }
 
+
 sub new {
     my $self = shift;
     my($pkg,$file,$line) = caller($Error::Depth);
@@ -246,6 +259,10 @@ sub value {
 
 package Error::Simple;
 
+use vars qw($VERSION);
+
+$VERSION = "0.17025";
+
 @Error::Simple::ISA = qw(Error);
 
 sub new {
@@ -288,14 +305,6 @@ use vars qw(@EXPORT_OK @ISA %EXPORT_TAGS);
 
 @ISA = qw(Exporter);
 
-
-sub blessed {
-	my $item = shift;
-	local $@; # don't kill an outer $@
-	ref $item and eval { $item->can('can') };
-}
-
-
 sub run_clauses ($$$\@) {
     my($clauses,$err,$wantarray,$result) = @_;
     my $code = undef;
@@ -314,16 +323,17 @@ sub run_clauses ($$$\@) {
 		my $pkg = $catch->[$i];
 		unless(defined $pkg) {
 		    #except
-		    splice(@$catch,$i,2,$catch->[$i+1]->());
+		    splice(@$catch,$i,2,$catch->[$i+1]->($err));
 		    $i -= 2;
 		    next CATCHLOOP;
 		}
-		elsif(blessed($err) && $err->isa($pkg)) {
+		elsif(Scalar::Util::blessed($err) && $err->isa($pkg)) {
 		    $code = $catch->[$i+1];
 		    while(1) {
 			my $more = 0;
-			local($Error::THROWN);
+			local($Error::THROWN, $@);
 			my $ok = eval {
+			    $@ = $err;
 			    if($wantarray) {
 				@{$result} = $code->($err,\$more);
 			    }
@@ -341,10 +351,9 @@ sub run_clauses ($$$\@) {
 			    undef $err;
 			}
 			else {
-			    $err = defined($Error::THROWN)
-				    ? $Error::THROWN : $@;
-                $err = $Error::ObjectifyCallback->({'text' =>$err})
-                    unless ref($err);
+			    $err = $@ || $Error::THROWN;
+				$err = $Error::ObjectifyCallback->({'text' =>$err})
+					unless ref($err);
 			}
 			last CATCH;
 		    };
@@ -357,7 +366,9 @@ sub run_clauses ($$$\@) {
 	if(defined($owise = $clauses->{'otherwise'})) {
 	    my $code = $clauses->{'otherwise'};
 	    my $more = 0;
+        local($Error::THROWN, $@);
 	    my $ok = eval {
+		$@ = $err;
 		if($wantarray) {
 		    @{$result} = $code->($err,\$more);
 		}
@@ -374,11 +385,10 @@ sub run_clauses ($$$\@) {
 		undef $err;
 	    }
 	    else {
-		$err = defined($Error::THROWN)
-			? $Error::THROWN : $@;
+		$err = $@ || $Error::THROWN;
 
-        $err = $Error::ObjectifyCallback->({'text' =>$err})
-            unless ref($err);
+		$err = $Error::ObjectifyCallback->({'text' =>$err})
+			unless ref($err);
 	    }
 	}
     }
@@ -398,7 +408,7 @@ sub try (&;$) {
 
     do {
 	local $Error::THROWN = undef;
-    local $@ = undef;
+	local $@ = undef;
 
 	$ok = eval {
 	    if($wantarray) {
@@ -413,21 +423,21 @@ sub try (&;$) {
 	    1;
 	};
 
-	$err = defined($Error::THROWN) ? $Error::THROWN : $@
+	$err = $@ || $Error::THROWN
 	    unless $ok;
     };
 
     shift @Error::STACK;
 
     $err = run_clauses($clauses,$err,wantarray,@result)
-	unless($ok);
+    unless($ok);
 
     $clauses->{'finally'}->()
 	if(defined($clauses->{'finally'}));
 
     if (defined($err))
     {
-        if (blessed($err) && $err->can('throw'))
+        if (Scalar::Util::blessed($err) && $err->can('throw'))
         {
             throw $err;
         }
@@ -506,12 +516,116 @@ sub otherwise (&;$) {
 }
 
 1;
+
+package Error::WarnDie;
+
+sub gen_callstack($)
+{
+    my ( $start ) = @_;
+
+    require Carp;
+    local $Carp::CarpLevel = $start;
+    my $trace = Carp::longmess("");
+    # Remove try calls from the trace
+    $trace =~ s/(\n\s+\S+__ANON__[^\n]+)?\n\s+eval[^\n]+\n\s+Error::subs::try[^\n]+(?=\n)//sog;
+    $trace =~ s/(\n\s+\S+__ANON__[^\n]+)?\n\s+eval[^\n]+\n\s+Error::subs::run_clauses[^\n]+\n\s+Error::subs::try[^\n]+(?=\n)//sog;
+    my @callstack = split( m/\n/, $trace );
+    return @callstack;
+}
+
+my $old_DIE;
+my $old_WARN;
+
+sub DEATH
+{
+    my ( $e ) = @_;
+
+    local $SIG{__DIE__} = $old_DIE if( defined $old_DIE );
+
+    die @_ if $^S;
+
+    my ( $etype, $message, $location, @callstack );
+    if ( ref($e) && $e->isa( "Error" ) ) {
+        $etype = "exception of type " . ref( $e );
+        $message = $e->text;
+        $location = $e->file . ":" . $e->line;
+        @callstack = split( m/\n/, $e->stacktrace );
+    }
+    else {
+        # Don't apply subsequent layer of message formatting
+        die $e if( $e =~ m/^\nUnhandled perl error caught at toplevel:\n\n/ );
+        $etype = "perl error";
+        my $stackdepth = 0;
+        while( caller( $stackdepth ) =~ m/^Error(?:$|::)/ ) {
+            $stackdepth++
+        }
+
+        @callstack = gen_callstack( $stackdepth + 1 );
+
+        $message = "$e";
+        chomp $message;
+
+        if ( $message =~ s/ at (.*?) line (\d+)\.$// ) {
+            $location = $1 . ":" . $2;
+        }
+        else {
+            my @caller = caller( $stackdepth );
+            $location = $caller[1] . ":" . $caller[2];
+        }
+    }
+
+    shift @callstack;
+    # Do it this way in case there are no elements; we don't print a spurious \n
+    my $callstack = join( "", map { "$_\n"} @callstack );
+
+    die "\nUnhandled $etype caught at toplevel:\n\n  $message\n\nThrown from: $location\n\nFull stack trace:\n\n$callstack\n";
+}
+
+sub TAXES
+{
+    my ( $message ) = @_;
+
+    local $SIG{__WARN__} = $old_WARN if( defined $old_WARN );
+
+    $message =~ s/ at .*? line \d+\.$//;
+    chomp $message;
+
+    my @callstack = gen_callstack( 1 );
+    my $location = shift @callstack;
+
+    # $location already starts in a leading space
+    $message .= $location;
+
+    # Do it this way in case there are no elements; we don't print a spurious \n
+    my $callstack = join( "", map { "$_\n"} @callstack );
+
+    warn "$message:\n$callstack";
+}
+
+sub import
+{
+    $old_DIE  = $SIG{__DIE__};
+    $old_WARN = $SIG{__WARN__};
+
+    $SIG{__DIE__}  = \&DEATH;
+    $SIG{__WARN__} = \&TAXES;
+}
+
+1;
+
 __END__
 
 =head1 NAME
 
 Error - Error/exception handling in an OO-ish way
 
+=head1 WARNING
+
+Using the "Error" module is B<no longer recommended> due to the black-magical
+nature of its syntactic sugar, which often tends to break. Its maintainers
+have stopped actively writing code that uses it, and discourage people
+from doing so. See the "SEE ALSO" section below for better recommendations.
+
 =head1 SYNOPSIS
 
     use Error qw(:try);
@@ -529,7 +643,7 @@ Error - Error/exception handling in an OO-ish way
     try {
 	do_some_stuff();
 	die "error!" if $condition;
-	throw Error::Simple -text => "Oops!" if $other_condition;
+	throw Error::Simple "Oops!" if $other_condition;
     }
     catch Error::IO with {
 	my $E = shift;
@@ -587,7 +701,7 @@ C<BLOCK> will be passed two arguments. The first will be the error
 being thrown. The second is a reference to a scalar variable. If this
 variable is set by the catch block then, on return from the catch
 block, try will continue processing as if the catch block was never
-found.
+found. The error will also be available in C<$@>.
 
 To propagate the error the catch block may call C<$err-E<gt>throw>
 
@@ -608,7 +722,7 @@ type.
 Catch any error by executing the code in C<BLOCK>
 
 When evaluated C<BLOCK> will be passed one argument, which will be the
-error being processed.
+error being processed. The error will also be available in C<$@>.
 
 Only one otherwise block may be specified per try block
 
@@ -625,12 +739,25 @@ Only one finally block may be specified per try block
 
 =back
 
+=head1 COMPATIBILITY
+
+L<Moose> exports a keyword called C<with> which clashes with Error's. This
+example returns a prototype mismatch error:
+
+    package MyTest;
+
+    use warnings;
+    use Moose;
+    use Error qw(:try);
+
+(Thanks to C<maik.hentsche@amd.com> for the report.).
+
 =head1 CLASS INTERFACE
 
 =head2 CONSTRUCTORS
 
 The C<Error> object is implemented as a HASH. This HASH is initialized
-with the arguments that are passed to its constructor. The elements
+with the arguments that are passed to it's constructor. The elements
 that are used by, or are retrievable by the C<Error> class are listed
 below, other classes may add to these.
 
@@ -655,6 +782,10 @@ an object blessed into that package as the C<-object> argument.
 
 =over 4
 
+=item Error->new()
+
+See the Error::Simple documentation.
+
 =item throw ( [ ARGS ] )
 
 Create a new C<Error> object and throw an error, which will be caught
@@ -730,6 +861,13 @@ The line where the constructor of this error was called from
 
 The text of the error
 
+=item $err->associate($obj)
+
+Associates an error with an object to allow error propagation. I.e:
+
+    $ber->encode(...) or
+        return Error->prior($ber)->associate($ldap);
+
 =back
 
 =head2 OVERLOAD METHODS
@@ -759,11 +897,9 @@ to the constructor.
 
 =head1 PRE-DEFINED ERROR CLASSES
 
-=over 4
-
-=item Error::Simple
+=head2 Error::Simple
 
-This class can be used to hold simple error strings and values. Its
+This class can be used to hold simple error strings and values. It's
 constructor takes two arguments. The first is a text value, the second
 is a numeric value. These values are what will be returned by the
 overload methods.
@@ -775,7 +911,6 @@ of the error object.
 This class is used internally if an eval'd block die's with an error
 that is a plain string. (Unless C<$Error::ObjectifyCallback> is modified)
 
-=back
 
 =head1 $Error::ObjectifyCallback
 
@@ -804,6 +939,76 @@ class MyError::Bar by default:
         # Error handling here.
     }
 
+=cut
+
+=head1 MESSAGE HANDLERS
+
+C<Error> also provides handlers to extend the output of the C<warn()> perl
+function, and to handle the printing of a thrown C<Error> that is not caught
+or otherwise handled. These are not installed by default, but are requested
+using the C<:warndie> tag in the C<use> line.
+
+ use Error qw( :warndie );
+
+These new error handlers are installed in C<$SIG{__WARN__}> and
+C<$SIG{__DIE__}>. If these handlers are already defined when the tag is
+imported, the old values are stored, and used during the new code. Thus, to
+arrange for custom handling of warnings and errors, you will need to perform
+something like the following:
+
+ BEGIN {
+   $SIG{__WARN__} = sub {
+     print STDERR "My special warning handler: $_[0]"
+   };
+ }
+
+ use Error qw( :warndie );
+
+Note that setting C<$SIG{__WARN__}> after the C<:warndie> tag has been
+imported will overwrite the handler that C<Error> provides. If this cannot be
+avoided, then the tag can be explicitly C<import>ed later
+
+ use Error;
+
+ $SIG{__WARN__} = ...;
+
+ import Error qw( :warndie );
+
+=head2 EXAMPLE
+
+The C<__DIE__> handler turns messages such as
+
+ Can't call method "foo" on an undefined value at examples/warndie.pl line 16.
+
+into
+
+ Unhandled perl error caught at toplevel:
+
+   Can't call method "foo" on an undefined value
+
+ Thrown from: examples/warndie.pl:16
+
+ Full stack trace:
+
+         main::inner('undef') called at examples/warndie.pl line 20
+         main::outer('undef') called at examples/warndie.pl line 23
+
+=cut
+
+=head1 SEE ALSO
+
+See L<Exception::Class> for a different module providing Object-Oriented
+exception handling, along with a convenient syntax for declaring hierarchies
+for them. It doesn't provide Error's syntactic sugar of C<try { ... }>,
+C<catch { ... }>, etc. which may be a good thing or a bad thing based
+on what you want. (Because Error's syntactic sugar tends to break.)
+
+L<Error::Exception> aims to combine L<Error> and L<Exception::Class>
+"with correct stringification".
+
+L<TryCatch> and L<Try::Tiny> are similar in concept to Error.pm only providing
+a syntax that hopefully breaks less.
+
 =head1 KNOWN BUGS
 
 None, but that does not mean there are not any.
@@ -816,12 +1021,21 @@ The code that inspired me to write this was originally written by
 Peter Seibel <peter@weblogic.com> and adapted by Jesse Glick
 <jglick@sig.bsh.com>.
 
+C<:warndie> handlers added by Paul Evans <leonerd@leonerd.org.uk>
+
 =head1 MAINTAINER
 
-Shlomi Fish <shlomif@iglu.org.il>
+Shlomi Fish, L<http://www.shlomifish.org/> .
 
 =head1 PAST MAINTAINERS
 
 Arun Kumar U <u_arunkumar@yahoo.com>
 
+=head1 COPYRIGHT
+
+Copyright (c) 1997-8  Graham Barr. All rights reserved.
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
 =cut
+
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v3 08/13] perl: update our copy of Mail::Address
  2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
                     ` (7 preceding siblings ...)
  2018-03-03 15:38   ` [PATCH v3 07/13] perl: update our ancient copy of Error.pm Ævar Arnfjörð Bjarmason
@ 2018-03-03 15:38   ` Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 09/13] perl: move CPAN loader wrappers to another namespace Ævar Arnfjörð Bjarmason
                     ` (4 subsequent siblings)
  13 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-03-03 15:38 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Todd Zullinger,
	Jonathan Nieder, Randall S . Becker, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

Update our copy of Mail::Address from 2.19 (Aug 22, 2017) to 2.20 (Jan
23, 2018). Like the preceding Error.pm update this is done simply to
keep up-to-date with upstream, and as can be shown from the diff
there's no functional changes.

The updated source was retrieved from
https://fastapi.metacpan.org/source/MARKOV/MailTools-2.20/lib/Mail/Address.pm

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git/FromCPAN/Mail/Address.pm | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/perl/Git/FromCPAN/Mail/Address.pm b/perl/Git/FromCPAN/Mail/Address.pm
index 13b2ff7d05..683d490b2b 100644
--- a/perl/Git/FromCPAN/Mail/Address.pm
+++ b/perl/Git/FromCPAN/Mail/Address.pm
@@ -1,10 +1,14 @@
-# Copyrights 1995-2017 by [Mark Overmeer <perl@overmeer.net>].
+# Copyrights 1995-2018 by [Mark Overmeer].
 #  For other contributors see ChangeLog.
 # See the manual pages for details on the licensing terms.
 # Pod stripped from pm file by OODoc 2.02.
+# This code is part of the bundle MailTools.  Meta-POD processed with
+# OODoc into POD and HTML manual-pages.  See README.md for Copyright.
+# Licensed under the same terms as Perl itself.
+
 package Mail::Address;
 use vars '$VERSION';
-$VERSION = '2.19';
+$VERSION = '2.20';
 
 use strict;
 
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v3 09/13] perl: move CPAN loader wrappers to another namespace
  2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
                     ` (8 preceding siblings ...)
  2018-03-03 15:38   ` [PATCH v3 08/13] perl: update our copy of Mail::Address Ævar Arnfjörð Bjarmason
@ 2018-03-03 15:38   ` Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 10/13] perl: generalize the Git::LoadCPAN facility Ævar Arnfjörð Bjarmason
                     ` (3 subsequent siblings)
  13 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-03-03 15:38 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Todd Zullinger,
	Jonathan Nieder, Randall S . Becker, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

Move the Git::Error and Git::Mail::Address wrappers to the
Git::LoadCPAN::Loader::* namespace, e.g. Git::LoadCPAN::Error. That
module will then either load Error from CPAN (if installed on the OS),
or use Git::FromCPAN::Error.

When I added the Error wrapper in 20d2a30f8f ("Makefile: replace
perl/Makefile.PL with simple make rules", 2017-12-10) I didn't think
about how confusing it would be to have these modules sitting in the
same tree as our normal modules. Let's put these all into
Git::{Load,From}CPAN::* to clearly distinguish them from the rest.

This also makes things a bit less confusing since there was already a
Git::Error namespace ever since 8b9150e3e3 ("Git.pm: Handle failed
commands' output", 2006-06-24).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 contrib/examples/git-difftool.perl      | 2 +-
 git-send-email.perl                     | 4 ++--
 perl/Git.pm                             | 2 +-
 perl/Git/{ => LoadCPAN}/Error.pm        | 8 ++++----
 perl/Git/{ => LoadCPAN}/Mail/Address.pm | 4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)
 rename perl/Git/{ => LoadCPAN}/Error.pm (78%)
 rename perl/Git/{ => LoadCPAN}/Mail/Address.pm (69%)

diff --git a/contrib/examples/git-difftool.perl b/contrib/examples/git-difftool.perl
index fb0fd0b84b..b2ea80f9ed 100755
--- a/contrib/examples/git-difftool.perl
+++ b/contrib/examples/git-difftool.perl
@@ -13,7 +13,7 @@
 use 5.008;
 use strict;
 use warnings;
-use Git::Error qw(:try);
+use Git::LoadCPAN::Error qw(:try);
 use File::Basename qw(dirname);
 use File::Copy;
 use File::Find;
diff --git a/git-send-email.perl b/git-send-email.perl
index d5a4826a1c..1ec22c5ef3 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -26,13 +26,13 @@ use Text::ParseWords;
 use Term::ANSIColor;
 use File::Temp qw/ tempdir tempfile /;
 use File::Spec::Functions qw(catdir catfile);
-use Git::Error qw(:try);
+use Git::LoadCPAN::Error qw(:try);
 use Cwd qw(abs_path cwd);
 use Git;
 use Git::I18N;
-use Git::Mail::Address;
 use Net::Domain ();
 use Net::SMTP ();
+use Git::LoadCPAN::Mail::Address;
 
 Getopt::Long::Configure qw/ pass_through /;
 
diff --git a/perl/Git.pm b/perl/Git.pm
index 151b0e7144..9f246c7988 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -104,7 +104,7 @@ increase notwithstanding).
 
 
 use Carp qw(carp croak); # but croak is bad - throw instead
-use Git::Error qw(:try);
+use Git::LoadCPAN::Error qw(:try);
 use Cwd qw(abs_path cwd);
 use IPC::Open2 qw(open2);
 use Fcntl qw(SEEK_SET SEEK_CUR);
diff --git a/perl/Git/Error.pm b/perl/Git/LoadCPAN/Error.pm
similarity index 78%
rename from perl/Git/Error.pm
rename to perl/Git/LoadCPAN/Error.pm
index 09bbc97390..3513fe745b 100644
--- a/perl/Git/Error.pm
+++ b/perl/Git/LoadCPAN/Error.pm
@@ -1,11 +1,11 @@
-package Git::Error;
+package Git::LoadCPAN::Error;
 use 5.008;
 use strict;
 use warnings;
 
 =head1 NAME
 
-Git::Error - Wrapper for the L<Error> module, in case it's not installed
+Git::LoadCPAN::Error - Wrapper for the L<Error> module, in case it's not installed
 
 =head1 DESCRIPTION
 
@@ -26,13 +26,13 @@ sub import {
     } or do {
 	my $error = $@ || "Zombie Error";
 
-	my $Git_Error_pm_path = $INC{"Git/Error.pm"} || die "BUG: Should have our own path from %INC!";
+	my $Git_Error_pm_path = $INC{"Git/LoadCPAN/Error.pm"} || die "BUG: Should have our own path from %INC!";
 
 	require File::Basename;
 	my $Git_Error_pm_root = File::Basename::dirname($Git_Error_pm_path) || die "BUG: Can't figure out lib/Git dirname from '$Git_Error_pm_path'!";
 
 	require File::Spec;
-	my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_Error_pm_root, 'FromCPAN');
+	my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_Error_pm_root, '..', 'FromCPAN');
 	die "BUG: '$Git_pm_FromCPAN_root' should be a directory!" unless -d $Git_pm_FromCPAN_root;
 
 	local @INC = ($Git_pm_FromCPAN_root, @INC);
diff --git a/perl/Git/Mail/Address.pm b/perl/Git/LoadCPAN/Mail/Address.pm
similarity index 69%
rename from perl/Git/Mail/Address.pm
rename to perl/Git/LoadCPAN/Mail/Address.pm
index 2ce3e84670..879c2f5cd1 100644
--- a/perl/Git/Mail/Address.pm
+++ b/perl/Git/LoadCPAN/Mail/Address.pm
@@ -1,11 +1,11 @@
-package Git::Mail::Address;
+package Git::LoadCPAN::Mail::Address;
 use 5.008;
 use strict;
 use warnings;
 
 =head1 NAME
 
-Git::Mail::Address - Wrapper for the L<Mail::Address> module, in case it's not installed
+Git::LoadCPAN::Mail::Address - Wrapper for the L<Mail::Address> module, in case it's not installed
 
 =head1 DESCRIPTION
 
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v3 10/13] perl: generalize the Git::LoadCPAN facility
  2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
                     ` (9 preceding siblings ...)
  2018-03-03 15:38   ` [PATCH v3 09/13] perl: move CPAN loader wrappers to another namespace Ævar Arnfjörð Bjarmason
@ 2018-03-03 15:38   ` Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 11/13] perl: move the perl/Git/FromCPAN tree to perl/FromCPAN Ævar Arnfjörð Bjarmason
                     ` (2 subsequent siblings)
  13 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-03-03 15:38 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Todd Zullinger,
	Jonathan Nieder, Randall S . Becker, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

Change the two wrappers that load from CPAN (local OS) or our own copy
to do so via the same codepath.

I added the Error.pm wrapper in 20d2a30f8f ("Makefile: replace
perl/Makefile.PL with simple make rules", 2017-12-10), and shortly
afterwards Matthieu Moy added a wrapper for Mail::Address in
bd869f67b9 ("send-email: add and use a local copy of Mail::Address",
2018-01-05).

His loader was simpler since Mail::Address doesn't have an "import"
method, but didn't do the same sanity checking; For example, a missing
FromCPAN directory (which OS packages are likely not to have) wouldn't
be explicitly warned about as a "BUG: ...".

Update both to use a common implementation based on the previous
Error.pm loader. Which has been amended to take the module to load as
parameter, as well as whether or not that module has an import
method.

This loader should be generic enough to handle almost all CPAN modules
out there, some use some crazy loading magic and wouldn't like being
wrapped like this, but that would be immediately obvious, and we'd
find out right away since the module wouldn't work at all.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 perl/Git/LoadCPAN.pm              | 74 +++++++++++++++++++++++++++++++++++++++
 perl/Git/LoadCPAN/Error.pm        | 44 +++--------------------
 perl/Git/LoadCPAN/Mail/Address.pm | 22 +++---------
 3 files changed, 82 insertions(+), 58 deletions(-)
 create mode 100644 perl/Git/LoadCPAN.pm

diff --git a/perl/Git/LoadCPAN.pm b/perl/Git/LoadCPAN.pm
new file mode 100644
index 0000000000..1568c177fe
--- /dev/null
+++ b/perl/Git/LoadCPAN.pm
@@ -0,0 +1,74 @@
+package Git::LoadCPAN;
+use 5.008;
+use strict;
+use warnings;
+
+=head1 NAME
+
+Git::LoadCPAN - Wrapper for loading modules from the CPAN (OS) or Git's own copy
+
+=head1 DESCRIPTION
+
+The Perl code in Git depends on some modules from the CPAN, but we
+don't want to make those a hard requirement for anyone building from
+source.
+
+Therefore the L<Git::LoadCPAN> namespace shipped with Git contains
+wrapper modules like C<Git::LoadCPAN::Module::Name> that will first
+attempt to load C<Module::Name> from the OS, and if that doesn't work
+will fall back on C<Git::FromCPAN::Module::Name> shipped with Git
+itself.
+
+Usually distributors will not ship with Git's Git::FromCPAN tree at
+all, preferring to use their own packaging of CPAN modules instead.
+
+This module is only intended to be used for code shipping in the
+C<git.git> repository. Use it for anything else at your peril!
+
+=cut
+
+sub import {
+	shift;
+	my $caller = caller;
+	my %args = @_;
+	my $module = exists $args{module} ? delete $args{module} : die "BUG: Expected 'module' parameter!";
+	my $import = exists $args{import} ? delete $args{import} : die "BUG: Expected 'import' parameter!";
+	die "BUG: Too many arguments!" if keys %args;
+
+	# Foo::Bar to Foo/Bar.pm
+	my $package_pm = $module;
+	$package_pm =~ s[::][/]g;
+	$package_pm .= '.pm';
+
+	eval {
+		require $package_pm;
+		1;
+	} or do {
+		my $error = $@ || "Zombie Error";
+
+		my $Git_LoadCPAN_pm_path = $INC{"Git/LoadCPAN.pm"} || die "BUG: Should have our own path from %INC!";
+
+		require File::Basename;
+		my $Git_LoadCPAN_pm_root = File::Basename::dirname($Git_LoadCPAN_pm_path) || die "BUG: Can't figure out lib/Git dirname from '$Git_LoadCPAN_pm_path'!";
+
+		require File::Spec;
+		my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_LoadCPAN_pm_root, 'FromCPAN');
+		die "BUG: '$Git_pm_FromCPAN_root' should be a directory!" unless -d $Git_pm_FromCPAN_root;
+
+		local @INC = ($Git_pm_FromCPAN_root, @INC);
+		require $package_pm;
+	};
+
+	if ($import) {
+		no strict 'refs';
+		*{"${caller}::import"} = sub {
+			shift;
+			use strict 'refs';
+			unshift @_, $module;
+			goto &{"${module}::import"};
+		};
+		use strict 'refs';
+	}
+}
+
+1;
diff --git a/perl/Git/LoadCPAN/Error.pm b/perl/Git/LoadCPAN/Error.pm
index 3513fe745b..c6d2c45d80 100644
--- a/perl/Git/LoadCPAN/Error.pm
+++ b/perl/Git/LoadCPAN/Error.pm
@@ -2,45 +2,9 @@ package Git::LoadCPAN::Error;
 use 5.008;
 use strict;
 use warnings;
-
-=head1 NAME
-
-Git::LoadCPAN::Error - Wrapper for the L<Error> module, in case it's not installed
-
-=head1 DESCRIPTION
-
-Wraps the import function for the L<Error> module.
-
-This module is only intended to be used for code shipping in the
-C<git.git> repository. Use it for anything else at your peril!
-
-=cut
-
-sub import {
-    shift;
-    my $caller = caller;
-
-    eval {
-	require Error;
-	1;
-    } or do {
-	my $error = $@ || "Zombie Error";
-
-	my $Git_Error_pm_path = $INC{"Git/LoadCPAN/Error.pm"} || die "BUG: Should have our own path from %INC!";
-
-	require File::Basename;
-	my $Git_Error_pm_root = File::Basename::dirname($Git_Error_pm_path) || die "BUG: Can't figure out lib/Git dirname from '$Git_Error_pm_path'!";
-
-	require File::Spec;
-	my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_Error_pm_root, '..', 'FromCPAN');
-	die "BUG: '$Git_pm_FromCPAN_root' should be a directory!" unless -d $Git_pm_FromCPAN_root;
-
-	local @INC = ($Git_pm_FromCPAN_root, @INC);
-	require Error;
-    };
-
-    unshift @_, $caller;
-    goto &Error::import;
-}
+use Git::LoadCPAN (
+	module => 'Error',
+	import => 1,
+);
 
 1;
diff --git a/perl/Git/LoadCPAN/Mail/Address.pm b/perl/Git/LoadCPAN/Mail/Address.pm
index 879c2f5cd1..f70a4f064c 100644
--- a/perl/Git/LoadCPAN/Mail/Address.pm
+++ b/perl/Git/LoadCPAN/Mail/Address.pm
@@ -2,23 +2,9 @@ package Git::LoadCPAN::Mail::Address;
 use 5.008;
 use strict;
 use warnings;
-
-=head1 NAME
-
-Git::LoadCPAN::Mail::Address - Wrapper for the L<Mail::Address> module, in case it's not installed
-
-=head1 DESCRIPTION
-
-This module is only intended to be used for code shipping in the
-C<git.git> repository. Use it for anything else at your peril!
-
-=cut
-
-eval {
-    require Mail::Address;
-    1;
-} or do {
-    require Git::FromCPAN::Mail::Address;
-};
+use Git::LoadCPAN (
+	module => 'Mail::Address',
+	import => 0,
+);
 
 1;
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v3 11/13] perl: move the perl/Git/FromCPAN tree to perl/FromCPAN
  2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
                     ` (10 preceding siblings ...)
  2018-03-03 15:38   ` [PATCH v3 10/13] perl: generalize the Git::LoadCPAN facility Ævar Arnfjörð Bjarmason
@ 2018-03-03 15:38   ` Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 12/13] Makefile: add NO_PERL_CPAN_FALLBACKS knob Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 13/13] perl Git::LoadCPAN: emit better errors under NO_PERL_CPAN_FALLBACKS Ævar Arnfjörð Bjarmason
  13 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-03-03 15:38 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Todd Zullinger,
	Jonathan Nieder, Randall S . Becker, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

Move the CPAN modules that have lived under perl/Git/FromCPAN since my
20d2a30f8f ("Makefile: replace perl/Makefile.PL with simple make
rules", 2017-12-10) to perl/FromCPAN.

A subsequent change will teach the Makefile to only install these
copies of CPAN modules if a flag that distro packagers would like to
set isn't set. Due to how the wildcard globbing is being done it's
much easier to accomplish that if they're moved to their own
directory.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 Makefile                                | 3 +++
 perl/{Git => }/FromCPAN/.gitattributes  | 0
 perl/{Git => }/FromCPAN/Error.pm        | 0
 perl/{Git => }/FromCPAN/Mail/Address.pm | 0
 perl/Git/LoadCPAN.pm                    | 5 ++---
 5 files changed, 5 insertions(+), 3 deletions(-)
 rename perl/{Git => }/FromCPAN/.gitattributes (100%)
 rename perl/{Git => }/FromCPAN/Error.pm (100%)
 rename perl/{Git => }/FromCPAN/Mail/Address.pm (100%)

diff --git a/Makefile b/Makefile
index 5ae9616e0a..026b9fb6d6 100644
--- a/Makefile
+++ b/Makefile
@@ -2302,9 +2302,12 @@ po/build/locale/%/LC_MESSAGES/git.mo: po/%.po
 
 LIB_PERL := $(wildcard perl/Git.pm perl/Git/*.pm perl/Git/*/*.pm perl/Git/*/*/*.pm)
 LIB_PERL_GEN := $(patsubst perl/%.pm,perl/build/lib/%.pm,$(LIB_PERL))
+LIB_CPAN := $(wildcard perl/FromCPAN/*.pm perl/FromCPAN/*/*.pm)
+LIB_CPAN_GEN := $(patsubst perl/%.pm,perl/build/lib/%.pm,$(LIB_CPAN))
 
 ifndef NO_PERL
 all:: $(LIB_PERL_GEN)
+all:: $(LIB_CPAN_GEN)
 endif
 
 perl/build/lib/%.pm: perl/%.pm
diff --git a/perl/Git/FromCPAN/.gitattributes b/perl/FromCPAN/.gitattributes
similarity index 100%
rename from perl/Git/FromCPAN/.gitattributes
rename to perl/FromCPAN/.gitattributes
diff --git a/perl/Git/FromCPAN/Error.pm b/perl/FromCPAN/Error.pm
similarity index 100%
rename from perl/Git/FromCPAN/Error.pm
rename to perl/FromCPAN/Error.pm
diff --git a/perl/Git/FromCPAN/Mail/Address.pm b/perl/FromCPAN/Mail/Address.pm
similarity index 100%
rename from perl/Git/FromCPAN/Mail/Address.pm
rename to perl/FromCPAN/Mail/Address.pm
diff --git a/perl/Git/LoadCPAN.pm b/perl/Git/LoadCPAN.pm
index 1568c177fe..229c1ee87d 100644
--- a/perl/Git/LoadCPAN.pm
+++ b/perl/Git/LoadCPAN.pm
@@ -16,8 +16,7 @@ source.
 Therefore the L<Git::LoadCPAN> namespace shipped with Git contains
 wrapper modules like C<Git::LoadCPAN::Module::Name> that will first
 attempt to load C<Module::Name> from the OS, and if that doesn't work
-will fall back on C<Git::FromCPAN::Module::Name> shipped with Git
-itself.
+will fall back on C<FromCPAN::Module::Name> shipped with Git itself.
 
 Usually distributors will not ship with Git's Git::FromCPAN tree at
 all, preferring to use their own packaging of CPAN modules instead.
@@ -52,7 +51,7 @@ sub import {
 		my $Git_LoadCPAN_pm_root = File::Basename::dirname($Git_LoadCPAN_pm_path) || die "BUG: Can't figure out lib/Git dirname from '$Git_LoadCPAN_pm_path'!";
 
 		require File::Spec;
-		my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_LoadCPAN_pm_root, 'FromCPAN');
+		my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_LoadCPAN_pm_root, '..', 'FromCPAN');
 		die "BUG: '$Git_pm_FromCPAN_root' should be a directory!" unless -d $Git_pm_FromCPAN_root;
 
 		local @INC = ($Git_pm_FromCPAN_root, @INC);
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v3 12/13] Makefile: add NO_PERL_CPAN_FALLBACKS knob
  2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
                     ` (11 preceding siblings ...)
  2018-03-03 15:38   ` [PATCH v3 11/13] perl: move the perl/Git/FromCPAN tree to perl/FromCPAN Ævar Arnfjörð Bjarmason
@ 2018-03-03 15:38   ` Ævar Arnfjörð Bjarmason
  2018-03-03 15:38   ` [PATCH v3 13/13] perl Git::LoadCPAN: emit better errors under NO_PERL_CPAN_FALLBACKS Ævar Arnfjörð Bjarmason
  13 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-03-03 15:38 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Todd Zullinger,
	Jonathan Nieder, Randall S . Becker, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

From: Todd Zullinger <tmz@pobox.com>

We include some perl modules which are not part of the core perl
install, as a convenience.  This allows us to rely on those modules in
our perl-based tools and scripts without requiring users to install the
modules from CPAN or their operating system packages.

Users whose operating system provides these modules and packagers of Git
often don't want to ship or use these bundled modules.  Allow these
users to set NO_PERL_CPAN_FALLBACKS to avoid installing the bundled
modules.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 Makefile | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/Makefile b/Makefile
index 026b9fb6d6..cbf0bc2344 100644
--- a/Makefile
+++ b/Makefile
@@ -296,6 +296,12 @@ all::
 #
 # Define NO_PERL if you do not want Perl scripts or libraries at all.
 #
+# Define NO_PERL_CPAN_FALLBACKS if you do not want to install bundled
+# copies of CPAN modules that serve as a fallback in case the modules
+# are not available on the system. This option is intended for
+# distributions that want to use their packaged versions of Perl
+# modules, instead of the fallbacks shipped with Git.
+#
 # Define PYTHON_PATH to the path of your Python binary (often /usr/bin/python
 # but /usr/bin/python2.7 on some platforms).
 #
@@ -2307,8 +2313,10 @@ LIB_CPAN_GEN := $(patsubst perl/%.pm,perl/build/lib/%.pm,$(LIB_CPAN))
 
 ifndef NO_PERL
 all:: $(LIB_PERL_GEN)
+ifndef NO_PERL_CPAN_FALLBACKS
 all:: $(LIB_CPAN_GEN)
 endif
+endif
 
 perl/build/lib/%.pm: perl/%.pm
 	$(QUIET_GEN)mkdir -p $(dir $@) && \
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH v3 13/13] perl Git::LoadCPAN: emit better errors under NO_PERL_CPAN_FALLBACKS
  2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
                     ` (12 preceding siblings ...)
  2018-03-03 15:38   ` [PATCH v3 12/13] Makefile: add NO_PERL_CPAN_FALLBACKS knob Ævar Arnfjörð Bjarmason
@ 2018-03-03 15:38   ` Ævar Arnfjörð Bjarmason
  13 siblings, 0 replies; 66+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-03-03 15:38 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Matthieu Moy, Petr Baudis, Jeff King,
	Johannes Schindelin, Jari Aalto, Giuseppe Bilotta, Todd Zullinger,
	Jonathan Nieder, Randall S . Becker, Eric Sunshine,
	Ævar Arnfjörð Bjarmason

Before my 20d2a30f8f ("Makefile: replace perl/Makefile.PL with simple
make rules", 2017-12-10) on an OS package that removed the
private-Error.pm copy we carried around manually removing the OS's
Error.pm would yield:

    $ git add -p
    Can't locate Error.pm in @INC (you may need to install the Error module) [...]

Now, before this change we'll instead emit this more cryptic error:

    $ git add -p
    BUG: '/usr/share/perl5/Git/FromCPAN' should be a directory! at /usr/share/perl5/Git/Error.pm line 36.

This is a confusing error. Now if the new NO_PERL_CPAN_FALLBACKS
option is specified and we can't find the module we'll instead emit:

    $ /tmp/git/bin/git add -p
    BUG: The 'Error' module is not here, but NO_PERL_CPAN_FALLBACKS was set!

    [...]

Where [...] is the lengthy explanation seen in the change below, which
explains what the potential breakage is, and how to fix it.

The reason for checking @@NO_PERL_CPAN_FALLBACKS@@] against the empty
string in Perl is as opposed to checking for a boolean value is that
that's (as far as I can tell) make's idea of a string that's set, and
e.g. NO_PERL_CPAN_FALLBACKS=0 is enough to set NO_PERL_CPAN_FALLBACKS.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 INSTALL              | 11 ++++++++---
 Makefile             |  5 ++++-
 perl/Git/LoadCPAN.pm | 33 ++++++++++++++++++++++++++++++++-
 3 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/INSTALL b/INSTALL
index 808e07b659..60e515eaf7 100644
--- a/INSTALL
+++ b/INSTALL
@@ -88,9 +88,9 @@ Issues of note:
 	export GIT_EXEC_PATH PATH GITPERLLIB
 
  - By default (unless NO_PERL is provided) Git will ship various perl
-   scripts & libraries it needs. However, for simplicity it doesn't
-   use the ExtUtils::MakeMaker toolchain to decide where to place the
-   perl libraries. Depending on the system this can result in the perl
+   scripts. However, for simplicity it doesn't use the
+   ExtUtils::MakeMaker toolchain to decide where to place the perl
+   libraries. Depending on the system this can result in the perl
    libraries not being where you'd like them if they're expected to be
    used by things other than Git itself.
 
@@ -102,6 +102,11 @@ Issues of note:
    Will result in e.g. perllibdir=/usr/share/perl/5.26.1 on Debian,
    perllibdir=/usr/share/perl5 (which we'd use by default) on CentOS.
 
+ - Unless NO_PERL is provided Git will ship various perl libraries it
+   needs. Distributors of Git will usually want to set
+   NO_PERL_CPAN_FALLBACKS if NO_PERL is not provided to use their own
+   copies of the CPAN modules Git needs.
+
  - Git is reasonably self-sufficient, but does depend on a few external
    programs and libraries.  Git can be used without most of them by adding
    the approriate "NO_<LIBRARY>=YesPlease" to the make command line or
diff --git a/Makefile b/Makefile
index cbf0bc2344..56fc2d6f08 100644
--- a/Makefile
+++ b/Makefile
@@ -2316,11 +2316,14 @@ all:: $(LIB_PERL_GEN)
 ifndef NO_PERL_CPAN_FALLBACKS
 all:: $(LIB_CPAN_GEN)
 endif
+NO_PERL_CPAN_FALLBACKS_SQ = $(subst ','\'',$(NO_PERL_CPAN_FALLBACKS))
 endif
 
 perl/build/lib/%.pm: perl/%.pm
 	$(QUIET_GEN)mkdir -p $(dir $@) && \
-	sed -e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' < $< > $@
+	sed -e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' \
+	    -e 's|@@NO_PERL_CPAN_FALLBACKS@@|$(NO_PERL_CPAN_FALLBACKS_SQ)|g' \
+	< $< > $@
 
 perl/build/man/man3/Git.3pm: perl/Git.pm
 	$(QUIET_GEN)mkdir -p $(dir $@) && \
diff --git a/perl/Git/LoadCPAN.pm b/perl/Git/LoadCPAN.pm
index 229c1ee87d..e5585e75e8 100644
--- a/perl/Git/LoadCPAN.pm
+++ b/perl/Git/LoadCPAN.pm
@@ -19,13 +19,25 @@ attempt to load C<Module::Name> from the OS, and if that doesn't work
 will fall back on C<FromCPAN::Module::Name> shipped with Git itself.
 
 Usually distributors will not ship with Git's Git::FromCPAN tree at
-all, preferring to use their own packaging of CPAN modules instead.
+all via the C<NO_PERL_CPAN_FALLBACKS> option, preferring to use their
+own packaging of CPAN modules instead.
 
 This module is only intended to be used for code shipping in the
 C<git.git> repository. Use it for anything else at your peril!
 
 =cut
 
+# NO_PERL_CPAN_FALLBACKS_STR evades the sed search-replace from the
+# Makefile, and allows for detecting whether the module is loaded from
+# perl/Git as opposed to perl/build/Git, which is useful for one-off
+# testing without having Error.pm et al installed.
+use constant NO_PERL_CPAN_FALLBACKS_STR => '@@' . 'NO_PERL_CPAN_FALLBACKS' . '@@';
+use constant NO_PERL_CPAN_FALLBACKS => (
+	q[@@NO_PERL_CPAN_FALLBACKS@@] ne ''
+	and
+	q[@@NO_PERL_CPAN_FALLBACKS@@] ne NO_PERL_CPAN_FALLBACKS_STR
+);
+
 sub import {
 	shift;
 	my $caller = caller;
@@ -45,6 +57,25 @@ sub import {
 	} or do {
 		my $error = $@ || "Zombie Error";
 
+		if (NO_PERL_CPAN_FALLBACKS) {
+			chomp(my $error = sprintf <<'THEY_PROMISED', $module);
+BUG: The '%s' module is not here, but NO_PERL_CPAN_FALLBACKS was set!
+
+Git needs this Perl module from the CPAN, and will by default ship
+with a copy of it. This Git was built with NO_PERL_CPAN_FALLBACKS,
+meaning that whoever built it promised to provide this module.
+
+You're seeing this error because they broke that promise, and we can't
+load our fallback version, since we were asked not to install it.
+
+If you're seeing this error and didn't package Git yourself the
+package you're using is broken, or your system is broken. This error
+won't appear if Git is built without NO_PERL_CPAN_FALLBACKS (instead
+we'll use our fallback version of the module).
+THEY_PROMISED
+			die $error;
+		}
+
 		my $Git_LoadCPAN_pm_path = $INC{"Git/LoadCPAN.pm"} || die "BUG: Should have our own path from %INC!";
 
 		require File::Basename;
-- 
2.15.1.424.g9478a66081


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* Re: [PATCH v3 00/13] various perl fixes
  2018-03-03 15:38   ` [PATCH v3 " Ævar Arnfjörð Bjarmason
@ 2018-03-05 19:01     ` Junio C Hamano
  0 siblings, 0 replies; 66+ messages in thread
From: Junio C Hamano @ 2018-03-05 19:01 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Matthieu Moy, Petr Baudis, Jeff King, Johannes Schindelin,
	Jari Aalto, Giuseppe Bilotta, Todd Zullinger, Jonathan Nieder,
	Randall S . Becker, Eric Sunshine

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> Same as v2 except rebased on master & a couple of commit message
> fixes, thanks to Eric Sunshine (thanks!). tbdiff with v2:

Noting that the series was rebased is a good thing to do, but a
statement of the fact alone without justification makes readers
wonder if there was a valid reason why it was rebased, or it was
just because the 'master' saw more commits that do not have any
impact on what the series does.  For the former, saying something
like "A recently graduated $name topic added another instance of the
same kind of glitch this series addresses, so the series has been
rebased to cover that codepath as well." would make it very helpful.

Thanks.  Will queue.  After scanning it again, I think this is ready
for "next".


^ permalink raw reply	[flat|nested] 66+ messages in thread

end of thread, other threads:[~2018-03-05 19:01 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-14 22:21 [PATCH 0/8] various perl fixes Ævar Arnfjörð Bjarmason
2018-02-14 22:21 ` [PATCH 1/8] perl: *.pm files should not have the executable bit Ævar Arnfjörð Bjarmason
2018-02-14 22:41   ` Jonathan Nieder
2018-02-25 19:01     ` Ævar Arnfjörð Bjarmason
2018-02-14 22:21 ` [PATCH 2/8] perl: move CPAN loader wrappers to another namespace Ævar Arnfjörð Bjarmason
2018-02-14 22:43   ` Jonathan Nieder
2018-02-14 22:21 ` [PATCH 3/8] perl: generalize the Git::LoadCPAN facility Ævar Arnfjörð Bjarmason
2018-02-14 22:57   ` Jonathan Nieder
2018-02-15  5:09     ` Todd Zullinger
2018-02-25 18:56     ` Ævar Arnfjörð Bjarmason
2018-02-25 19:05       ` Randall S. Becker
2018-02-15  4:53   ` Todd Zullinger
2018-02-15 20:41     ` Ævar Arnfjörð Bjarmason
2018-02-15 21:23       ` Todd Zullinger
2018-02-16 14:39         ` Ævar Arnfjörð Bjarmason
2018-02-16 17:55           ` Todd Zullinger
2018-02-16 22:03             ` Jonathan Nieder
2018-02-17  0:47               ` Todd Zullinger
2018-02-17  5:40                 ` Todd Zullinger
2018-02-14 22:21 ` [PATCH 4/8] perl: update our ancient copy of Error.pm Ævar Arnfjörð Bjarmason
2018-02-14 23:03   ` Jonathan Nieder
2018-02-15 20:46     ` Ævar Arnfjörð Bjarmason
2018-02-14 22:21 ` [PATCH 5/8] perl: update our copy of Mail::Address Ævar Arnfjörð Bjarmason
2018-02-14 23:46   ` Jonathan Nieder
2018-02-15  9:32     ` Matthieu Moy
2018-02-15 20:31       ` Ævar Arnfjörð Bjarmason
2018-02-14 22:21 ` [PATCH 6/8] git-send-email: unconditionally use Net::{SMTP,Domain} Ævar Arnfjörð Bjarmason
2018-02-14 23:49   ` Jonathan Nieder
2018-02-15 20:43     ` Ævar Arnfjörð Bjarmason
2018-02-14 22:21 ` [PATCH 7/8] gitweb: hard-depend on the Digest::MD5 5.8 module Ævar Arnfjörð Bjarmason
2018-02-14 23:52   ` Jonathan Nieder
2018-02-14 22:21 ` [PATCH 8/8] perl: hard-depend on the File::{Temp,Spec} modules Ævar Arnfjörð Bjarmason
2018-02-14 23:54   ` Jonathan Nieder
2018-02-15 20:42     ` Ævar Arnfjörð Bjarmason
2018-02-15 21:33       ` Junio C Hamano
2018-02-25 19:46 ` [PATCH v2 00/13] various perl fixes Ævar Arnfjörð Bjarmason
2018-03-03 15:38   ` [PATCH v3 " Ævar Arnfjörð Bjarmason
2018-03-05 19:01     ` Junio C Hamano
2018-03-03 15:38   ` [PATCH v3 01/13] perl: *.pm files should not have the executable bit Ævar Arnfjörð Bjarmason
2018-03-03 15:38   ` [PATCH v3 02/13] Git.pm: remove redundant "use strict" from sub-package Ævar Arnfjörð Bjarmason
2018-03-03 15:38   ` [PATCH v3 03/13] Git.pm: add the "use warnings" pragma Ævar Arnfjörð Bjarmason
2018-03-03 15:38   ` [PATCH v3 04/13] gitweb: hard-depend on the Digest::MD5 5.8 module Ævar Arnfjörð Bjarmason
2018-03-03 15:38   ` [PATCH v3 05/13] Git.pm: hard-depend on the File::{Temp,Spec} modules Ævar Arnfjörð Bjarmason
2018-03-03 15:38   ` [PATCH v3 06/13] git-send-email: unconditionally use Net::{SMTP,Domain} Ævar Arnfjörð Bjarmason
2018-03-03 15:38   ` [PATCH v3 07/13] perl: update our ancient copy of Error.pm Ævar Arnfjörð Bjarmason
2018-03-03 15:38   ` [PATCH v3 08/13] perl: update our copy of Mail::Address Ævar Arnfjörð Bjarmason
2018-03-03 15:38   ` [PATCH v3 09/13] perl: move CPAN loader wrappers to another namespace Ævar Arnfjörð Bjarmason
2018-03-03 15:38   ` [PATCH v3 10/13] perl: generalize the Git::LoadCPAN facility Ævar Arnfjörð Bjarmason
2018-03-03 15:38   ` [PATCH v3 11/13] perl: move the perl/Git/FromCPAN tree to perl/FromCPAN Ævar Arnfjörð Bjarmason
2018-03-03 15:38   ` [PATCH v3 12/13] Makefile: add NO_PERL_CPAN_FALLBACKS knob Ævar Arnfjörð Bjarmason
2018-03-03 15:38   ` [PATCH v3 13/13] perl Git::LoadCPAN: emit better errors under NO_PERL_CPAN_FALLBACKS Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 01/13] perl: *.pm files should not have the executable bit Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 02/13] Git.pm: remove redundant "use strict" from sub-package Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 03/13] Git.pm: add the "use warnings" pragma Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 04/13] gitweb: hard-depend on the Digest::MD5 5.8 module Ævar Arnfjörð Bjarmason
2018-02-25 20:00   ` Eric Sunshine
2018-02-25 19:46 ` [PATCH v2 05/13] Git.pm: hard-depend on the File::{Temp,Spec} modules Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 06/13] git-send-email: unconditionally use Net::{SMTP,Domain} Ævar Arnfjörð Bjarmason
2018-02-25 20:03   ` Eric Sunshine
2018-02-25 19:46 ` [PATCH v2 07/13] perl: update our ancient copy of Error.pm Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 08/13] perl: update our copy of Mail::Address Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 09/13] perl: move CPAN loader wrappers to another namespace Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 10/13] perl: generalize the Git::LoadCPAN facility Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 11/13] perl: move the perl/Git/FromCPAN tree to perl/FromCPAN Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 12/13] Makefile: add NO_PERL_CPAN_FALLBACKS knob Ævar Arnfjörð Bjarmason
2018-02-25 19:46 ` [PATCH v2 13/13] perl Git::LoadCPAN: emit better errors under NO_PERL_CPAN_FALLBACKS Ævar Arnfjörð Bjarmason

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).