This patch makes the subject lines reflect the log entry and not the file name
and version number.
See the difference between these two mail archives:
http://www.geocrawler.com/archives/3/7495/2001/10/0/
http://www.geocrawler.com/archives/3/7495/2001/11/0/
Regards,
Zooko
---
zooko.com
Security and Distributed Systems Engineering
---
Index: syncmail
===================================================================
RCS file: /cvsroot/mnet/CVSROOT/syncmail,v
retrieving revision 1.9
retrieving revision 1.14
diff -u -r1.9 -r1.14
--- syncmail 16 Mar 2002 14:25:15 -0000 1.9
+++ syncmail 17 Mar 2002 14:26:25 -0000 1.14
@@ -68,7 +68,7 @@
import getopt
# Notification command
-MAILCMD = '/bin/mail -s "CVS: %(SUBJECT)s" %(PEOPLE)s 2>&1 > /dev/null'
+MAILCMD = "/bin/mail -s 'CVS: %(SUBJECT)s' %(PEOPLE)s 2>&1 > /dev/null"
# Diff trimming stuff
DIFF_HEAD_LINES = 20
@@ -142,7 +142,7 @@
-def blast_mail(mailcmd, filestodiff, contextlines):
+def blast_mail(mailcmd, filestodiff, contextlines, logentry):
# cannot wait for child process or that will cause parent to retain cvs
# lock for too long. Urg!
if not os.fork():
@@ -150,7 +150,7 @@
# give up the lock you cvs thang!
time.sleep(2)
fp = os.popen(mailcmd, 'w')
- fp.write(sys.stdin.read())
+ fp.write(logentry)
fp.write('\n')
# append the diffs if available
for file in filestodiff:
@@ -160,6 +160,33 @@
# doesn't matter what code we return, it isn't waited on
os._exit(0)
+
+def abbreviate_logentry_for_subject(logentry):
+ WIDTHLIMIT = 80
+ SUBJECTSIZE = len('Subject: ')
+ LMstr='Log Message:'
+ i = string.find(logentry, LMstr)
+ if i == -1:
+ # Whoops. Whatever.
+ # the caller will fallback to old-style when it sees `None'
+ return None
+ subject = logentry[i+len(LMstr):]
+ while (len(subject) > 0) and (subject[0] not in string.letters+string.digits):
+ subject = subject[1:] # I have the feeling that there's a nicer way to do this...
+ subject = string.replace(subject, "'", '"')
+ # Now break at the first line break
+ i = string.find(subject, '\n')
+ if i == -1:
+ i = len(subject)
+ j = string.find(subject, '\r')
+ if j == -1:
+ j = len(subject)
+ subject = subject[:min(i,j)]
+
+ if len(subject) < (WIDTHLIMIT - SUBJECTSIZE):
+ return subject
+ else:
+ return subject[:(WIDTHLIMIT - SUBJECTSIZE - 3)] + "..."
# scan args for options
@@ -185,13 +212,18 @@
elif opt == '-u':
contextlines = 0
+ # The log entry is on stdin. --Zooko 2001-11-21
+ logentry = sys.stdin.read()
+ SUBJECT = abbreviate_logentry_for_subject(logentry)
+ if SUBJECT is None:
+ SUBJECT = args[0]
+
# What follows is the specification containing the files that were
# modified. The argument actually must be split, with the first component
# containing the directory the checkin is being made in, relative to
# $CVSROOT, followed by the list of files that are changing.
if not args:
usage(1, 'No CVS module specified')
- SUBJECT = args[0]
specs = string.split(args[0])
del args[0]
@@ -218,7 +250,8 @@
L.append(s)
specs = L
print 'Generating notification message...'
- blast_mail(mailcmd, specs[1:], contextlines)
+
+ blast_mail(mailcmd, specs[1:], contextlines, logentry)
print 'Generating notification message... done.'
|