Skip to content

Commit

Permalink
Merge branch 'ab/perl-fixes'
Browse files Browse the repository at this point in the history
Clean-up to various pieces of Perl code we have.

* ab/perl-fixes:
  perl Git::LoadCPAN: emit better errors under NO_PERL_CPAN_FALLBACKS
  Makefile: add NO_PERL_CPAN_FALLBACKS knob
  perl: move the perl/Git/FromCPAN tree to perl/FromCPAN
  perl: generalize the Git::LoadCPAN facility
  perl: move CPAN loader wrappers to another namespace
  perl: update our copy of Mail::Address
  perl: update our ancient copy of Error.pm
  git-send-email: unconditionally use Net::{SMTP,Domain}
  Git.pm: hard-depend on the File::{Temp,Spec} modules
  gitweb: hard-depend on the Digest::MD5 5.8 module
  Git.pm: add the "use warnings" pragma
  Git.pm: remove redundant "use strict" from sub-package
  perl: *.pm files should not have the executable bit
  • Loading branch information
gitster committed Mar 15, 2018
2 parents e74737b + 1aca69c commit ae1644b
Show file tree
Hide file tree
Showing 15 changed files with 431 additions and 158 deletions.
11 changes: 8 additions & 3 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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).
#
Expand Down Expand Up @@ -2304,14 +2310,22 @@ 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)
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 $@) && \
Expand Down
2 changes: 1 addition & 1 deletion contrib/examples/git-difftool.perl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 13 additions & 15 deletions git-send-email.perl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
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 /;

Expand Down Expand Up @@ -1199,28 +1201,24 @@ 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;
}

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;
}
}

Expand Down
3 changes: 1 addition & 2 deletions gitweb/INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 4 additions & 13 deletions gitweb/gitweb.perl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
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) {
Expand Down Expand Up @@ -490,7 +492,6 @@ sub evaluate_uri {
# 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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions perl/FromCPAN/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Error.pm whitespace=-blank-at-eof
Loading

0 comments on commit ae1644b

Please sign in to comment.