Bug#852332: dh-make-perl: DEBFULLNAME and DEBEMAIL should be used with git

Carnë Draug carandraug+dev at gmail.com
Tue Jan 24 14:19:24 UTC 2017


Package: dh-make-perl
Version: 0.92
Followup-For: Bug #852332

On 24 January 2017 at 13:15, gregor herrmann <gregoa at debian.org> wrote:
> On Tue, 24 Jan 2017 12:55:10 +0000, Dominic Hargreaves wrote:
>
>> > @@ -777,7 +777,7 @@ sub git_add_debian {
>> >
>> >      my $git = Git->repository( $self->main_dir );
>> >      $git->command( 'add', 'debian' );
>> > -    $git->command( 'commit', '-m',
>> > +    $git->command( 'commit', '--author', $self->get_developer, '-m',
>> >          "Initial packaging by dh-make-perl $VERSION" );
>> >      $git->command(
>> >          qw( remote add origin ),
>>
>> This will indeed create commits with the email and name specified, but
>> the committer address will not be overridden which is probably confusing.
>
> Ack.
> Maybe setting GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL via
> environment variables would work?

There are options to git, not to git commit.  One can use:

    git commit -c "user.name=Foo" -c "user.email=Bar" ...

Which would mean changing DhMakePerl::Command::Packaging to have
get_email and get_name (which would then also be used by
get_developer).  I have attached a new patch that does that.

Carnë
-------------- next part --------------
From 941e701f86cb754594789aa5231416f4eb8a3a61 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carn=C3=AB=20Draug?= <carandraug+dev at gmail.com>
Date: Tue, 24 Jan 2017 14:15:15 +0000
Subject: [PATCH] DhMakePerl::Command::make: use author and email information
 for git commits.

DhMakePerl::Command::Packaging (get_name, get_email): two new methods
to retrieve only email and name because git handles them separate.

Closes: #852332
---
 Changes                             |  5 +++++
 lib/DhMakePerl/Command/Packaging.pm | 36 +++++++++++++++++++++++-------------
 lib/DhMakePerl/Command/make.pm      | 10 +++++++---
 3 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/Changes b/Changes
index 9c47553..4c952ec 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,9 @@
 0.93 (201x-xx-xx)
+  [ Carnë Draug ]
+  * Use dh-make-perl email and name information for git commits.
+    (Closes: #852332)
+  * DhMakePerl::Command::Packaging: add two new methods: get_email
+    and get_name.
 
 0.92 (2016-09-20)
 
diff --git a/lib/DhMakePerl/Command/Packaging.pm b/lib/DhMakePerl/Command/Packaging.pm
index d759b66..e560abd 100644
--- a/lib/DhMakePerl/Command/Packaging.pm
+++ b/lib/DhMakePerl/Command/Packaging.pm
@@ -119,14 +119,27 @@ sub makefile_pl {
     return $self->main_file('Makefile.PL');
 }
 
-sub get_developer {
+sub get_email {
     my $self = shift;
-
     my $email = $self->cfg->email;
 
-    my ( $user, $pwnam, $name, $mailh );
-    $user = $ENV{LOGNAME} || $ENV{USER};
-    $pwnam = getpwuid($<);
+    $email ||= ( $ENV{DEBEMAIL} || $ENV{EMAIL} );
+    unless ($email) {
+	my $mailh;
+        chomp( $mailh = `cat /etc/mailname` );
+        $email = $self->get_user . '@' . $mailh;
+    }
+
+    $email =~ s/^(.*)\s+<(.*)>$/$2/;
+    return $email;
+}
+
+sub get_name {
+    my $self = shift;
+
+    my $name;
+    my $user = $ENV{LOGNAME} || $ENV{USER};
+    my $pwnam = getpwuid($<);
     die "Cannot determine current user\n" unless $pwnam;
     if ( defined $ENV{DEBFULLNAME} ) {
         $name = $ENV{DEBFULLNAME};
@@ -137,15 +150,12 @@ sub get_developer {
     }
     $user ||= $pwnam->name;
     $name ||= $user;
-    $email ||= ( $ENV{DEBEMAIL} || $ENV{EMAIL} );
-    unless ($email) {
-        chomp( $mailh = `cat /etc/mailname` );
-        $email = $user . '@' . $mailh;
-    }
-
-    $email =~ s/^(.*)\s+<(.*)>$/$2/;
+    return $name;
+}
 
-    return "$name <$email>";
+sub get_developer {
+    my $self = shift;
+    return $self->get_name . " <" . $self->get_email . ">";
 }
 
 sub fill_maintainer {
diff --git a/lib/DhMakePerl/Command/make.pm b/lib/DhMakePerl/Command/make.pm
index 31db889..dae325b 100644
--- a/lib/DhMakePerl/Command/make.pm
+++ b/lib/DhMakePerl/Command/make.pm
@@ -744,11 +744,13 @@ sub git_import_upstream__init_debian {
     $self->reset_git_environment();
 
     Git::command( 'init', $self->main_dir );
+    my @git_config = ( '-c', 'user.name="' . $self->get_name . '"',
+                       '-c', 'user.email="' . $self->get_email . '"');
 
     my $git = Git->repository( $self->main_dir );
     $git->command( qw(symbolic-ref HEAD refs/heads/upstream) );
     $git->command( 'add', '.' );
-    $git->command( 'commit', '-m',
+    $git->command( 'commit', @git_config, '-m',
               "Import original source of "
             . $self->perlname . ' '
             . $self->version );
@@ -762,7 +764,7 @@ sub git_import_upstream__init_debian {
       # debian/ directory from the working tree; git has the history, so I don't
       # need the debian.bak
       $git->command( 'rm', '-r', $self->debian_dir );
-      $git->command( 'commit', '-m',
+      $git->command( 'commit', @git_config, '-m',
                      'Removed debian directory embedded in upstream source' );
     }
 }
@@ -776,8 +778,10 @@ sub git_add_debian {
     $self->reset_git_environment;
 
     my $git = Git->repository( $self->main_dir );
+    my @git_config = ( '-c', 'user.name="' . $self->get_name . '"',
+                       '-c', 'user.email="' . $self->get_email . '"');
     $git->command( 'add', 'debian' );
-    $git->command( 'commit', '-m',
+    $git->command( 'commit', @git_config, '-m',
         "Initial packaging by dh-make-perl $VERSION" );
     $git->command(
         qw( remote add origin ),
-- 
2.11.0



More information about the pkg-perl-maintainers mailing list