git: revered merge detection logic in post-receive-email script
[sbcl.git] / git / post-receive-email
index cc90b7f..af8377c 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/sh
 #
+# (Modified for SBCL.)
+#
 # Copyright (c) 2007 Andy Parkins
 #
 # An example hook script to mail out commit update information.  This hook
@@ -172,6 +174,11 @@ generate_email()
        if [ -z "$describe" ]; then
                describe=$rev
        fi
+       # SBCL: Also grab the commit title.
+       title=$(git log -n1 --pretty=format:%s $rev)
+       if [ -z "$title" ]; then
+               title=$rev
+       fi
 
        generate_email_header
 
@@ -194,19 +201,24 @@ generate_email_header()
 {
        # --- Email (all stdout will be the email)
        # Generate header
+
+        # SBCL: branch updates get the commit title in the subject
+        if [ "branch" = "$refname_type" ] && [ "update" = "$change_type" ]
+       then
+           subject="${emailprefix} $short_refname: $title"
+        else
+           subject="${emailprefix} $refname_type $short_refname: ${change_type}d. $describe"
+       fi
+
        cat <<-EOF
        To: $recipients
-       Subject: ${emailprefix}$projectdesc $refname_type, $short_refname, ${change_type}d. $describe
+       Subject: $subject
        X-Git-Refname: $refname
        X-Git-Reftype: $refname_type
        X-Git-Oldrev: $oldrev
        X-Git-Newrev: $newrev
 
-       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 "$projectdesc".
-
-       The $refname_type, $short_refname has been ${change_type}d
+The $refname_type "$short_refname" has been ${change_type}d in $projectdesc:
        EOF
 }
 
@@ -336,8 +348,8 @@ generate_update_branch_email()
        # the base revision and then forward to the new revision
        for rev in $(git rev-list $oldrev..$newrev)
        do
-               revtype=$(git cat-file -t "$rev")
-               echo "       via  $rev ($revtype)"
+           revtype=$(git cat-file -t "$rev")
+           echo "       via  $rev ($revtype)"
        done
 
        if [ "$fast_forward" ]; then
@@ -388,11 +400,13 @@ generate_update_branch_email()
 
        echo ""
        if [ -z "$rewind_only" ]; then
-               echo "Those revisions listed above that are new to this repository have"
-               echo "not appeared on any other notification email; so we list those"
-               echo "revisions in full, below."
+               # Silenced for SBCL.
+               #
+               # echo "Those revisions listed above that are new to this repository have"
+               # echo "not appeared on any other notification email; so we list those"
+               # echo "revisions in full, below."
+               # echo ""
 
-               echo ""
                echo $LOGBEGIN
                show_new_revisions
 
@@ -412,9 +426,14 @@ generate_update_branch_email()
        # point - the user will be interested in what this revision changed
        # - including the undoing of previous revisions in the case of
        # non-fast-forward updates.
-       echo ""
-       echo "Summary of changes:"
-       git diff-tree --stat --summary --find-copies-harder $oldrev..$newrev
+        #
+        # Silenced for SBCL: we use "git show -p --stat -C %s" to generate
+        # revision information, getting the diffstat between the commit message
+        # and the diff. This would just duplicate that.
+        #
+       # echo ""
+       # echo "Summary of changes:"
+       # git diff-tree --stat --summary --find-copies-harder $oldrev..$newrev
 }
 
 #
@@ -621,12 +640,13 @@ show_new_revisions()
 
        other_branches=$(git for-each-ref --format='%(refname)' refs/heads/ |
            grep -F -v $refname)
+       # SBCL: show oldest first via --reverse
        git rev-parse --not $other_branches |
        if [ -z "$custom_showrev" ]
        then
-               git rev-list --pretty --stdin $revspec
+               git rev-list --reverse --pretty --stdin $revspec
        else
-               git rev-list --stdin $revspec |
+               git rev-list --reverse --stdin $revspec |
                while read onerev
                do
                        eval $(printf "$custom_showrev" $onerev)
@@ -684,6 +704,42 @@ if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
 else
        while read oldrev newrev refname
        do
-               generate_email $oldrev $newrev $refname | send_mail
+         echo "Sending email for $refname: $oldrev -> $newrev"
+         # SBCL KLUDGE: the default script sends one email per
+         # push. We want one per commit. As long as we're
+         # in fast-forward-only world, this should do the
+         # right thing.
+         if (expr "$oldrev" : '0*$' >/dev/null ||                  # create
+             expr "$newrev" : '0*$' >/dev/null ||                  # delete
+              ! expr "$refname" : "refs/heads/" > /dev/null)        # not a branch
+         then
+             # Just one email.
+             generate_email $oldrev $newrev $refname | send_mail
+         else
+              # Get all revisions from old to new.
+              revlist=$(git rev-list --reverse $oldrev..$newrev)
+              no_merges=true
+              # Check for merges.
+              for rev in $revlist
+              do
+                  if ($no_merges && git rev-parse --verify --quiet "$rev"^2 > /dev/null)
+                  then
+                      no_merges=false
+                  fi
+              done
+              if $no_merges
+              then
+                  # Simple branch update, one mail per commit.
+                 lastrev=$oldrev
+                 for step in $revlist
+                 do
+                     generate_email $lastrev $step $refname | send_mail
+                     lastrev=$step
+                 done
+              else
+                  # There's a merge -- just one email.
+                 generate_email $oldrev $newrev $refname | send_mail
+              fi
+         fi
        done
 fi