[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Add dirs to subject of mailer.py

From: Chris Foote <Chris.Foote_at_xtra.co.nz>
Date: 2003-01-12 22:43:36 CET

This patch adds the directories to the subject line of the mail.

Log:
* mailer.py:
  (mail_subject): Add call to collapse_dirs.
  (collapse_dirs): New function to the directories changed.
  (_svn_dirname): New function to get the dirname of an SVN path.

Index: tools/hook-scripts/mailer.py
===================================================================
--- tools/hook-scripts/mailer.py (revision 4359)
+++ tools/hook-scripts/mailer.py (working copy)
@@ -14,6 +14,7 @@
 import ConfigParser
 import time
 import popen2
+import re
 
 import svn.fs
 import svn.util
@@ -59,12 +60,64 @@
 
 
 def mail_subject(cfg, repos, changes):
- subject = 'rev %d - DIRS-GO-HERE' % repos.rev
+ commondir, dirlist = collapse_dirs(changes)
+ if commondir != '':
+ subject = 'rev %d - in %s: %s' % (repos.rev, commondir, dirlist)
+ else:
+ subject = 'rev %d - %s' % (repos.rev, dirlist)
+
   if cfg.general.subject_prefix:
     return cfg.general.subject_prefix + ' ' + subject
   return subject
 
 
+def collapse_dirs(changes):
+ # Collapse the list of changed directories only if the root directory
+ # was not modified, because otherwise everything is under root and
+ # there's no point in collapsing the directories, and only if more
+ # than one directory was modified.
+
+ dirschanged = []
+ for fname, change in changes.items():
+ if change.item_type == ChangeCollector.FILE:
+ fname = _svn_dirname(fname)
+ if fname != '/':
+ fname = re.sub(r'^(.+)[/\\]$', r'\1', fname)
+ if fname not in dirschanged:
+ dirschanged.append(fname)
+ dirschanged.sort()
+
+ commondir = ''
+ if '/' not in dirschanged and len(dirschanged) > 1:
+ firstline = dirschanged.pop(0)
+ commonpieces = firstline.split('/')
+ for line in dirschanged:
+ pieces = line.split('/')
+ i = 0
+ while i < len(pieces) and i < len(commonpieces):
+ if pieces[i] != commonpieces[i]:
+ commonpieces = commonpieces[:i]
+ break
+ i+=1
+
+ dirschanged = [firstline] + dirschanged
+
+ if len(commonpieces):
+ commondir = string.join(commonpieces, '/')
+ new_dirschanged = []
+ for dir in dirschanged:
+ if dir == commondir:
+ dir = '.'
+ else:
+ dir = string.replace(dir, commondir + '/', "")
+ new_dirschanged.append(dir)
+
+ dirschanged = new_dirschanged
+
+ dirlist = string.join(dirschanged, ' ')
+ return commondir, dirlist
+
+
 class MailedOutput:
   def __init__(self, cfg, subject):
     self.cfg = cfg
@@ -564,6 +617,13 @@
   pass
 
 
+def _svn_dirname(path):
+ "Compute the dirname of an SVN path ('/' separators)."
+ idx = string.rfind(path, '/')
+ if idx == -1:
+ return path
+ return path[:idx]
+
 def _svn_basename(path):
   "Compute the basename of an SVN path ('/' separators)."
   idx = string.rfind(path, '/')

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sun Jan 12 22:45:43 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.