<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -6,11 +6,13 @@
 
 		From: 	tyler@slide.com
 		To:		commits@slide.com
-		Subject: 	GITCOMMIT [$MACHINE/$BRANCH] Minor change (ce0520c)
+		Subject: 	GITCOMMIT [$MACHINE/$BRANCH/ce0520c] Minor change 
 
-			commit ce0520ceebb756aee7fce58f4fd643a6bca349d8
 			Author: R. Tyler Ballance &lt;tyler@slide.com&gt;
-			Date:   Thu Dec 4 10:37:55 2008 -0800
+			Commit: asdb123b123bfd123
+
+			Changes committed:
+				M	file
 
 				Minor change
 
@@ -21,6 +23,27 @@
 			@@ -992,28 +992,5 @@ 
 
 				$DIFF
+	
+	The post-commit hook also supports sending &quot;attention&quot; mails with the
+	syntax of &quot;attn tyler,jason&quot;. This will send a &quot;[Review Request] mail
+	formatted similar to the following:
+
+		From: tyler@slide.com
+		CC: tyler@slide.com, jason@slide.com
+		Subject: [Review Request] Minor change
+
+			(commit body here)
+			--
+			file |    6 ++++--
+			1 files changed, 4 insertions(+), 2 deletions(-)
+
+			diff --git a/file b/file
+			index bc1f44a..4468922 100644
+			--- a/file
+			+++ b/file
+			@@ -992,28 +992,5 @@ 
+
+				$DIFF
 '''
 
 import getpass
@@ -34,21 +57,35 @@ from optparse import OptionParser
 SMTP_SERVER = 'smtp.your.com'
 MAIL_SUFFIX = '@your.com'
 
+def find_attn(commit):
+	rc = re.findall(r'(?:^|\s)attn[:\s]+([\w \t,-]+[\w,])', commit)
+	if not rc:
+		return []
+	if len(rc) &gt; 1:
+		return rc
+	return rc[0].split(',')
+
 def mail_commit(address):
 	user = os.getenv('PG_USER') or getpass.getuser()
 	machine = socket.gethostname()
-	base_git_cmd = 'git log --max-count=1 --no-color --no-merges --author=%s' % (user)
-	branch = os.popen('git branch --no-color | grep &quot;* &quot; | sed \'s/* //g\'').read().rstrip()
-	commit_diff = os.popen('%s --unified=4 --pretty=medium' % base_git_cmd).read().rstrip()
-	mail_subject = os.popen('%s --pretty=format:&quot;%%s (%%h)&quot;'  % (base_git_cmd)).read().rstrip()
-	mail_subject = 'GITCOMMIT [%s/%s] %s' % (machine, branch, mail_subject)
-
+	branch = os.popen('git symbolic-ref HEAD').read().rstrip()
+	branch = branch.replace('refs/heads/', '')
+	changes = os.popen('git diff HEAD^...HEAD --name-status --no-color').read().rstrip()
+	message = os.popen('git show HEAD --pretty=format:&quot;From: %(user)s@slide.com\r\nTo: %(to)s\r\nSubject: GITCOMMIT [%(hostname)s/%(branch)s/%%h] %%s\r\n\r\nAuthor: %%aN &lt;%%ae&gt;\r\nCommit: %%H\r\n\r\nChanges committed:\r\n\t%(changes)s\r\n\r\n%%s\r\n\r\n%%b\r\n\r\n&quot; --no-color' % {
+					'user' : user, 'to' : address, 'branch' : branch, 'hostname' : machine, 'changes' : '\n\t'.join(changes.split('\n'))}).read().rstrip()
 	print 'Sending a commit mail to %s' % (address)
 
 	s = smtplib.SMTP(SMTP_SERVER)
-	sender = os.getenv('GIT_FROM') or ('%s%s' % (user, MAIL_SUFFIX))
-	message = 'From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s' % (sender, address, mail_subject, commit_diff)
-	s.sendmail('%s%s' % (user, MAIL_SUFFIX), [address], message)
+	addresses = [address]
+	s.sendmail('%s@%s' % (user, MAIL_SUFFIX), addresses, message)
+
+	addresses = find_attn(message)
+	if addresses:
+		addresses.append(user)
+		addresses = ['%s@%s' % (a.strip(), MAIL_SUFFIX) for a in addresses]
+		print 'Sending a review mail to: %s' % ','.join(addresses)
+		message = os.popen('git format-patch --stdout HEAD^ --subject-prefix=&quot;Review Request&quot; --cc=%s' % ','.join(addresses)).read().rstrip()
+		s.sendmail('%s@%s' % (user, MAIL_SUFFIX) , addresses, message)
 	s.quit()
 
 if __name__ == '__main__':</diff>
      <filename>post-commit.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>d571147ef869f99016e892ab2b17bc8121db3421</id>
    </parent>
  </parents>
  <author>
    <name>R. Tyler Ballance</name>
    <email>tyler@slide.com</email>
  </author>
  <url>http://github.com/rtyler/slide-git-scripts/commit/875189f3d13a05fc2f922e37640ceebd6753422d</url>
  <id>875189f3d13a05fc2f922e37640ceebd6753422d</id>
  <committed-date>2009-01-06T22:58:15-08:00</committed-date>
  <authored-date>2009-01-06T22:58:15-08:00</authored-date>
  <message>Bring changes over from the Slide post-commit hook, add support for &quot;attn user&quot; mails to be sent when a commit is committed. Also cleaned up the fscked usage of git-log(1)

Signed-off-by: R. Tyler Ballance &lt;tyler@slide.com&gt;</message>
  <tree>8a0cfdf4dd0a68fe5d89d87b2bf402c66e7ec27a</tree>
  <committer>
    <name>R. Tyler Ballance</name>
    <email>tyler@slide.com</email>
  </committer>
</commit>
