Author: gstein
Date: Fri Apr 19 23:20:54 2024
New Revision: 1917169

URL: http://svn.apache.org/viewvc?rev=1917169&view=rev
Log:
Omit the content of the diffs, when the message becomes too long. Just
rely on leaving a diff URL.

* tools/hook-scripts/mailer/mailer.py:
  (Commit.long_commit): pass False for (new) NO_DIFF_CONTENT parameter
    to generate_commit()
  (Commit.short_commit): pass True for (new) NO_DIFF_CONTENT parameter
    to generate_commit(), removing the generate_urls() call.
  (generate_commit): accept a new NO_DIFF_CONTENT parameter, and pass
    that into the generate_changelist_diffs() calls, along with
    re-ordering the paramters. Also place NO_DIFF_CONTENT into the
    DATA passed into render_commit().
  (generate_urls): removed.
  (generate_changelist_diffs): reorder the parameters to align with
    those of generate_commit() (aesthetic; no functional change). Add
    the NO_DIFF_CONTENT and skip construction of the diff generator.
  (render_commit): place a large NOTE in the message when the diff
    content is removed (due to length).
  (_render_diffs): skip trying to output diff content when absent.

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=1917169&r1=1917168&r2=1917169&view=diff
==============================================================================
--- subversion/trunk/tools/hook-scripts/mailer/mailer.py (original)
+++ subversion/trunk/tools/hook-scripts/mailer/mailer.py Fri Apr 19 23:20:54 
2024
@@ -547,13 +547,13 @@ class Commit(Messenger):
 
       def long_commit(writer):
         # generate commit message (with diffs) for this group and params
-        generate_commit(writer, self.cfg, self.repos, self.changelist,
+        generate_commit(writer, self.cfg, self.repos, self.changelist, False,
                         group, params, paths, iterpool)
 
       def short_commit(writer):
         # generate a shorter message, using URLs instead of diffs
-        generate_urls(writer, self.cfg, self.repos, self.changelist,
-                      group, params, paths, iterpool)
+        generate_commit(writer, self.cfg, self.repos, self.changelist, True,
+                        group, params, paths, iterpool)
 
       failed |= output.send(subject_line, group, params,
                             long_commit, short_commit)
@@ -788,8 +788,8 @@ class DiffURLSelections:
     return self._get_url('modify', repos_rev, change)
 
 
-def generate_commit(writer, cfg, repos, changelist, group, params, paths,
-                    pool):
+def generate_commit(writer, cfg, repos, changelist, no_diff_content,
+                    group, params, paths, pool):
 
   svndate = repos.get_rev_prop(svn.core.SVN_PROP_REVISION_DATE, pool)
   ### pick a different date format?
@@ -809,9 +809,10 @@ def generate_commit(writer, cfg, repos,
     other_summary = None
 
   if len(paths) != len(changelist) and show_nonmatching_paths == 'yes':
-    other_diffs = generate_changelist_diffs(changelist, paths, False, cfg,
-                                            repos, date, group, params,
-                                            pool)
+    other_diffs = generate_changelist_diffs(cfg, repos, changelist,
+                                            no_diff_content, False,
+                                            group, params, paths,
+                                            date, pool)
   else:
     other_diffs = None
 
@@ -824,10 +825,12 @@ def generate_commit(writer, cfg, repos,
     log=to_str(repos.get_rev_prop(svn.core.SVN_PROP_REVISION_LOG, pool) or 
b''),
     commit_url=commit_url,
     summary=summary,
+    no_diff_content=no_diff_content,
     show_nonmatching_paths=show_nonmatching_paths,
     other_summary=other_summary,
-    diffs=generate_changelist_diffs(changelist, paths, True, cfg, repos,
-                                    date, group, params, pool),
+    diffs=generate_changelist_diffs(cfg, repos, changelist,
+                                    no_diff_content, True,
+                                    group, params, paths, date, pool),
     other_diffs=other_diffs,
     )
   ### clean this up in future rev. Just use wb
@@ -836,11 +839,6 @@ def generate_commit(writer, cfg, repos,
   render_commit(w, wb, data)
 
 
-def generate_urls(writer, cfg, repos, changelist, group, params, paths,
-                  pool):
-    writer.write('COMMIT MESSAGE USING URLS\n')
-
-
 def generate_summary(changelist, paths, in_paths):
   def gather_info(action):
     return _gather_paths(action, changelist, paths, in_paths)
@@ -872,8 +870,9 @@ def _gather_paths(action, changelist, pa
   return items
 
 
-def generate_changelist_diffs(changelist, paths, in_paths, cfg, repos,
-                              date, group, params, pool):
+def generate_changelist_diffs(cfg, repos, changelist,
+                              no_diff_content, in_paths,
+                              group, params, paths, date, pool):
     "This is a generator returning diffs for each change."
 
     diffsels = DiffSelections(cfg, group, params)
@@ -1005,7 +1004,7 @@ def generate_changelist_diffs(changelist
 
       if diff:
         binary = diff.either_binary()
-        if binary:
+        if binary or no_diff_content:
           content = src_fname = dst_fname = None
         else:
             src_fname, dst_fname = diff.get_files()
@@ -1110,6 +1109,12 @@ def render_commit(w, wb, data):
       else:
         w('and changes in other areas\n')
 
+    if data.no_diff_content:
+        w('\nNOTE: this message was too long when including "diff" contents.'
+          '\n      The contents have been replaced with URLs to display the'
+          '\n      diff contents on a web page.'
+          '\n\n')
+
     _render_diffs(w, wb, data.diffs, '')
     if data.other_diffs:
         _render_diffs(w, wb, data.other_diffs,
@@ -1189,15 +1194,18 @@ def _render_diffs(w, wb, diffs, section_
       if not diff.diff:
         continue
 
-      w(SEPARATOR + '\n')
-
       if diff.binary:
+        w(SEPARATOR + '\n')
         if diff.singular:
           w('Binary file. No diff available.\n')
         else:
           w('Binary file (source and/or target). No diff available.\n')
         continue
 
+      if diff.content is None:
+          continue
+
+      w(SEPARATOR + '\n')
       for line in diff.content:
         wb(line.raw)
 


Reply via email to