[ic] New git commit e-mail hook

Daniel Browning db at endpoint.com
Mon Nov 30 06:59:57 UTC 2009


I finished preparing a replacement for our existing interchange-cvs 
e-mail hook. Before I complete the installation, here is some 
additional information about it.

The hook is based on one from the gitadmin-bin GNOME repo. 
I modified it to make allow customization of many parameters 
so that it may be used for other projects. I've been using it
successfully on several client repositories for several months.

The installation and configuration is pretty straightforward:

cd hooks/

wget http://icdevgroup.org/~danb/git-email-hook/post-receive-email
wget http://icdevgroup.org/~danb/git-email-hook/git.py
wget http://icdevgroup.org/~danb/git-email-hook/util.py
chmod a+x post-receive-email
ln -s post-receive-email post-receive
cd ..

git config --add hooks.mailinglist commits at yourproject.org
git config --add hooks.fromaddress interchange-cvs at icdevgroup.org
git config --add hooks.replyto interchange-core at icdevgroup.org

Here is one of the test scripts I am using to test it:

http://icdevgroup.org/~danb/git-email-hook/test-email-hook

Here is what it does when executed with "sh test-email-hook":

 * Download the new e-mail hook from icdevgroup.org
 * Customize the configuration (To:, From:, and Reply-To:)
 * Clone a git repo from an existing Interchange repo.
 * Perform a few test commits and pushes. 

At that point there should be a handeful of e-mails ready for
evaluation.

One of the differences is that it detects commits that were 
already applied to another branch and doesn't repeat them 
verbatim, for example:

==================================================================
Subjec: [interchange/STABLE_5_6-branch] Correct detection of broken getppid() for Perl 5.10.0 (RT #286)
Summary of changes:

  3bf8e5c... Correct detection of broken getppid() for Perl 5.10.0 (RT # (*)

(*) This commit already existed in another branch; no separate mail sent
==================================================================

Another difference is in how it handles a push of multiple commits. The 
old hook sent all the commits out in one e-mail, which was suboptimal
for several reasons:

 * Groups commits that are often unrelated.
 * Cannot use one-line summary in e-mail Subject header.
 * Prevents the use of "git am" on the e-mails.

The new hook creates a separate e-mail for each commit.

Attached below is an example of the default e-mail hook that is 
distributed with git (that we are using now for interchange-cvs)
compared with the new hook.

Sincerely,
-- 
Daniel Browning
End Point Corporation
http://www.endpoint.com/


==================================================================
Subject: [interchange-cvs] [SCM] Interchange branch, master, updated. REL_5_7_3-27-9f9d7c57

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Interchange".

The branch, master has been updated
       via  9f9d7c578da699776722641ec3c1edd4b51f3a99 (commit)
      from  bcf1ee92ace67afe84ee7ce96abad9809d98aeaa (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 9f9d7c578da699776722641ec3c1edd4b51f3a99
Author: Jon Jensen <jon at endpoint.com>
Date:   Sat Jun 27 17:38:50 2009 +0200

    Abort daemon startup when required module is missing and clean up error output
    
    Fix problem with eval $@ error result's scope in global Perl module
    require routine. This was caused because logGlobal contains an eval
    itself that overrides $@. Now when a "Require module Something::Special"
    directive is issued and not satisfied, it is fatal as was originally
    intended.
    
    Remove logGlobal call that results in duplicate error output.
    
    Correctly say "Aborting Interchange daemon" instead of "Aborting
    catalog" when dying on global config errors.

-----------------------------------------------------------------------

Summary of changes and diff:
 lib/Vend/Config.pm |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/Vend/Config.pm b/lib/Vend/Config.pm
index 88f2915..5158365 100644
--- a/lib/Vend/Config.pm
+++ b/lib/Vend/Config.pm
@@ -349,7 +349,6 @@ sub config_error {
                warn "$msg\n" unless $Vend::Quiet;
        }
        else {
-               logGlobal({level => 'warn'}, $msg);
                die "$msg\n";
        }
 }
@@ -2697,8 +2696,8 @@ sub parse_require {
        }
        else {
                $carptype = \&config_error;
-               $error_message = 'Required %s %s not present. Aborting catalog.'
-                       unless $error_message;
+               $error_message ||= 'Required %s %s not present. Aborting '
+                       . ($C ? 'catalog' : 'Interchange daemon') . '.';
        }
 
        my $nostrict;
@@ -2768,11 +2767,12 @@ sub parse_require {
                                        unshift(@INC, $pathinfo);
                                }
                                eval "require $module$oldtype;";
+                               my $error = $@;
                                if ($pathinfo) {
                                        shift(@INC);
                                }
-                               ::logGlobal("while eval'ing module %s got [%s]", $module, $@) if ($@);
-                               return ! $@;
+                               ::logGlobal("while eval'ing module %s got [%s]\n", $module, $error) if $error;
+                               return ! $error;
                        }
                        else {
                                # Since we aren't safe to actually require, we will 


hooks/post-receive
-- 
Interchange
==================================================================

And here is an example of the new hook:
==================================================================
[interchange] Abort daemon startup when required module is missing and clean up error output
commit ae5e8619a06dea16a386dcbfe7ea9fd574068db7
Author: Jon Jensen <jon at endpoint.com>
Date:   Sat Jun 27 17:38:50 2009 +0200

    Abort daemon startup when required module is missing and clean up error output
    
    Fix problem with eval $@ error result's scope in global Perl module
    require routine. This was caused because logGlobal contains an eval
    itself that overrides $@. Now when a "Require module Something::Special"
    directive is issued and not satisfied, it is fatal as was originally
    intended.
    
    Remove logGlobal call that results in duplicate error output.
    
    Correctly say "Aborting Interchange daemon" instead of "Aborting
    catalog" when dying on global config errors.

 lib/Vend/Config.pm |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/lib/Vend/Config.pm b/lib/Vend/Config.pm
index 88f2915..5158365 100644
--- a/lib/Vend/Config.pm
+++ b/lib/Vend/Config.pm
@@ -349,7 +349,6 @@ sub config_error {
                warn "$msg\n" unless $Vend::Quiet;
        }
        else {
-               logGlobal({level => 'warn'}, $msg);
                die "$msg\n";
        }
 }
@@ -2697,8 +2696,8 @@ sub parse_require {
        }
        else {
                $carptype = \&config_error;
-               $error_message = 'Required %s %s not present. Aborting catalog.'
-                       unless $error_message;
+               $error_message ||= 'Required %s %s not present. Aborting '
+                       . ($C ? 'catalog' : 'Interchange daemon') . '.';
        }
 
        my $nostrict;
@@ -2768,11 +2767,12 @@ sub parse_require {
                                        unshift(@INC, $pathinfo);
                                }
                                eval "require $module$oldtype;";
+                               my $error = $@;
                                if ($pathinfo) {
                                        shift(@INC);
                                }
-                               ::logGlobal("while eval'ing module %s got [%s]", $module, $@) if ($@);
-                               return ! $@;
+                               ::logGlobal("while eval'ing module %s got [%s]\n", $module, $error) if $error;
+                               return ! $error;
                        }
                        else {
                                # Since we aren't safe to actually require, we will 
==================================================================



More information about the interchange-users mailing list