From: Zooko <zo...@zo...> - 2002-04-11 12:39:00
|
Here's a new version of my patch which generates subject lines from the contents of the log entry instead of from the file name and version number. This is diffed against current CVS head. I use this patch for several of my sourceforge projects [1]. Most of the syncmail messages go to mne...@li... [2]. [1] http://sourceforge.net/users/zooko [2] http://sourceforge.net/mailarchive/forum.php?forum_id=7725 Index: syncmail =================================================================== RCS file: /cvsroot/cvs-syncmail/syncmail/syncmail,v retrieving revision 1.11 diff -u -d -r1.11 syncmail --- syncmail 10 Apr 2002 21:36:35 -0000 1.11 +++ syncmail 11 Apr 2002 12:35:40 -0000 @@ -75,6 +75,9 @@ from cStringIO import StringIO +# How many characters of the subject line will be used up by a tag pre-pended by the mailing list software? (If this value is off by a few it doesn't hurt much.) +TAGLEN=len("[mnet-cvs] ") + # Which SMTP server to do we connect to? Empty string means localhost. MAILHOST = '' MAILPORT = 25 @@ -228,6 +231,31 @@ conn.close() os._exit(0) + +def abbreviate_logentry_for_subject(logentry): + WIDTHLIMIT = 80 - TAGLEN + 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... + # 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 @@ -256,13 +284,18 @@ elif opt in ('-q', '--quiet'): verbose = 0 + # The log entry is on stdin. --Zooko 2002-04-10 + logentry = sys.stdin.read() + subject = abbreviate_logentry_for_subject(logentry) + # 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] + if subject is None: + subject = args[0] specs = string.split(args[0]) del args[0] |