--- trac-post-commit-hook.orig	2008-06-03 15:26:10.000000000 -0700
+++ trac-post-commit-hook	2008-06-03 15:25:59.000000000 -0700
@@ -2,7 +2,8 @@
 
 # trac-post-commit-hook
 # ----------------------------------------------------------------------------
-# Copyright (c) 2004 Stephen Hansen 
+# Copyright (c) 2004 Stephen Hansen
+# Portions copyright (c) 2008 Digg, LLC.
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to
@@ -39,10 +40,10 @@
 # (all the other arguments are now deprecated and not needed anymore)
 #
 # It searches commit messages for text in the form of:
-#   command #1
-#   command #1, #2
-#   command #1 & #2 
-#   command #1 and #2
+#   command #1 [to user]
+#   command #1, #2 [to user]
+#   command #1 & #2 [to user]
+#   command #1 and #2 [to user]
 #
 # Instead of the short-hand syntax "#1", "ticket:1" can be used as well, e.g.:
 #   command ticket:1
@@ -62,7 +63,11 @@
 #     commit message being added to it. 
 #   references, refs, addresses, re, see 
 #     The specified issue numbers are left in their current status, but 
-#     the contents of this commit message are added to their notes. 
+#     the contents of this commit message are added to their notes.
+#   reassign, reassigns, assign, assigns
+#     Behaves the same as references, above, and reassigns the ticket to the
+#     specified user. Example: reassign #1 to otheruser
+#     The "to" is optional; this also works: reassign #1 otheruser
 #
 # A fairly complicated example of what you can do is with a commit message
 # of:
@@ -111,10 +116,11 @@
 
 
 ticket_prefix = '(?:#|(?:ticket|issue|bug)[: ]?)'
+ticket_suffix = '(?:(?: +to +)?(?P<owner>[a-z]+))?'
 ticket_reference = ticket_prefix + '[0-9]+'
 ticket_command =  (r'(?P<action>[A-Za-z]*).?'
-                   '(?P<ticket>%s(?:(?:[, &]*|[ ]?and[ ]?)%s)*)' %
-                   (ticket_reference, ticket_reference))
+                   '(?P<ticket>%s(?:(?:[, &]*|[ ]?and[ ]?)%s)*)%s' %
+                   (ticket_reference, ticket_reference, ticket_suffix))
 
 if options.envelope:
     ticket_command = r'\%s%s\%s' % (options.envelope[0], ticket_command,
@@ -134,7 +140,11 @@
                        're':         '_cmdRefs',
                        'references': '_cmdRefs',
                        'refs':       '_cmdRefs',
-                       'see':        '_cmdRefs'}
+                       'see':        '_cmdRefs',
+                       'reassign':   '_cmdAssign',
+                       'reassigns':  '_cmdAssign',
+                       'assign':     '_cmdAssign',
+                       'assigns':    '_cmdAssign'}
 
     def __init__(self, project=options.project, author=options.user,
                  rev=options.rev, url=options.url):
@@ -156,12 +166,14 @@
         cmd_groups = command_re.findall(self.msg)
 
         tickets = {}
-        for cmd, tkts in cmd_groups:
+        owners = {}
+        for cmd, tkts, owner in cmd_groups:
             funcname = CommitHook._supported_cmds.get(cmd.lower(), '')
             if funcname:
                 for tkt_id in ticket_re.findall(tkts):
                     func = getattr(self, funcname)
                     tickets.setdefault(tkt_id, []).append(func)
+                    owners[tkt_id] = owner or self.author
 
         for tkt_id, cmds in tickets.iteritems():
             try:
@@ -169,7 +181,7 @@
                 
                 ticket = Ticket(self.env, int(tkt_id), db)
                 for cmd in cmds:
-                    cmd(ticket)
+                    cmd(ticket, owners[tkt_id])
 
                 # determine sequence number... 
                 cnum = 0
@@ -190,13 +202,18 @@
                                    'ID %s: %s' % (tkt_id, e)
             
 
-    def _cmdClose(self, ticket):
+    def _cmdClose(self, ticket, owner = ''):
         ticket['status'] = 'closed'
         ticket['resolution'] = 'fixed'
 
-    def _cmdRefs(self, ticket):
+    def _cmdRefs(self, ticket, owner = ''):
         pass
 
+    def _cmdAssign(self, ticket, owner):
+        if ticket['cc'].find(ticket['owner']) == -1:
+            ticket['cc'] += ", " + ticket['owner']
+        ticket['owner'] = owner
+
 
 if __name__ == "__main__":
     if len(sys.argv) < 5:

