Author: gstein Date: Sun Dec 24 00:24:03 2023 New Revision: 1914899 URL: http://svn.apache.org/viewvc?rev=1914899&view=rev Log: Create a new send() method on OutputBase to wrap up the construction of messages, with a long-format and a short-format fallback.
* tools/hook-scripts/mailer/mailer.py: (OutputBase.send): new method to pull together the start/finish on SELF, and use of the WRITER. This incorporates the new MessageTooLarge exception to fall back to a shorter message generation function. (Commit.generate): move message generation into a new long_commit() local function, and use .send() to build/send a message. Switch to using FAILED rather than RET. (PropChange.generate): similar to above, with long_propchange() (Lock.generate): similar to above, with long_lock() (class MessageTooLarge): new exception for when a generated message becomes too large, and a fallback to a short message is needed. This is caught in OutputBase.send(), but not (yet) raised. Modified: subversion/trunk/tools/hook-scripts/mailer/mailer.py Modified: subversion/trunk/tools/hook-scripts/mailer/mailer.py URL: http://svn.apache.org/viewvc/subversion/trunk/tools/hook-scripts/mailer/mailer.py?rev=1914899&r1=1914898&r2=1914899&view=diff ============================================================================== --- subversion/trunk/tools/hook-scripts/mailer/mailer.py (original) +++ subversion/trunk/tools/hook-scripts/mailer/mailer.py Sun Dec 24 00:24:03 2023 @@ -190,6 +190,21 @@ class OutputBase: self.repos = repos self._CHUNKSIZE = 128 * 1024 + def send(self, basic_subject, group, params, long_func, short_func): + writer = self.start(basic_subject, group, params) + + try: + try: + long_func(writer) + except MessageTooLarge: + short_func(writer) + + self.finish() + except MessageSendFailure: + return True # failed + + return False # succeeded + def start(self, basic_subject, group, params): """Override this method. @@ -517,24 +532,20 @@ class Commit(Messenger): ### rather than rebuilding it each time. iterpool = svn.core.svn_pool_create(scratch_pool) - ret = 0 + failed = False for (group, param_tuple), (params, paths) in sorted(self.groups.items()): subject_line = self.make_subject(self.basic_subject, group, params) - try: - writer = output.start(subject_line, group, params) + def long_commit(writer): # generate the content for this group and set of params generate_content(writer, self.cfg, self.repos, self.changelist, group, params, paths, iterpool) - - output.finish() - except MessageSendFailure: - ret = 1 + failed |= output.send(subject_line, group, params, long_commit, None) svn.core.svn_pool_clear(iterpool) svn.core.svn_pool_destroy(iterpool) - return ret + return int(failed) class PropChange(Messenger): @@ -555,13 +566,13 @@ class PropChange(Messenger): def generate(self, output, scratch_pool): actions = { 'A': 'added', 'M': 'modified', 'D': 'deleted' } - ret = 0 + failed = False ### maybe create an iterpool? for (group, param_tuple), params in self.groups.items(): subject_line = self.make_subject(self.basic_subject, group, params) - try: - writer = output.start(subject_line, group, params) + + def long_propchange(writer): writer.write('Author: %s\n' 'Revision: %s\n' 'Property Name: %s\n' @@ -589,10 +600,9 @@ class PropChange(Messenger): 'to' : tempfile2.name, })): writer.write(to_str(diffs.raw)) - output.finish() - except MessageSendFailure: - ret = 1 - return ret + failed |= output.send(subject_line, group, params, long_propchange, None) + + return int(failed) def get_commondir(dirlist): @@ -672,12 +682,12 @@ class Lock(Messenger): pool) def generate(self, output, scratch_pool): - ret = 0 + failed = False + for (group, param_tuple), (params, paths) in sorted(self.groups.items()): subject_line = self.make_subject(self.basic_subject, group, params) - try: - writer = output.start(subject_line, group, params) + def long_lock(writer): writer.write('Author: %s\n' '%s paths:\n' % (self.author, self.do_lock and 'Locked' or 'Unlocked')) @@ -689,10 +699,9 @@ class Lock(Messenger): if self.do_lock: writer.write('Comment:\n%s\n' % (self.lock.comment or '')) - output.finish() - except MessageSendFailure: - ret = 1 - return ret + failed |= output.send(subject_line, group, params, long_lock, None) + + return int(failed) class DiffSelections: @@ -1444,6 +1453,8 @@ class UnknownSubcommand(Exception): pass class MessageSendFailure(Exception): pass +class MessageTooLarge(Exception): + pass if __name__ == '__main__':