Author: gstein
Date: Fri Dec 15 10:17:15 2023
New Revision: 1914681

URL: http://svn.apache.org/viewvc?rev=1914681&view=rev
Log:
Switch from a generator class/object to a simple generation function.

* tools/hook-scripts/mailer/mailer.py:
  (generate_content): use new function, rather than the old
    DiffGenerator class.
  (class DiffGenerator): remove, but keep its contents as close as
    possible for new function ...
  (generate_changelist_diffs): ... here. This creates a "self" object
    to hold "instance vars" as if it was still the old class. This
    minimizes the changes necessary: switch from raising IndexError to
    just returning; switch from returning values to yield

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=1914681&r1=1914680&r2=1914681&view=diff
==============================================================================
--- subversion/trunk/tools/hook-scripts/mailer/mailer.py (original)
+++ subversion/trunk/tools/hook-scripts/mailer/mailer.py Fri Dec 15 10:17:15 
2023
@@ -800,8 +800,9 @@ def generate_content(writer, cfg, repos,
     other_summary = None
 
   if len(paths) != len(changelist) and show_nonmatching_paths == 'yes':
-    other_diffs = DiffGenerator(changelist, paths, False, cfg, repos, date,
-                                group, params, pool)
+    other_diffs = generate_changelist_diffs(changelist, paths, False, cfg,
+                                            repos, date, group, params,
+                                            pool)
   else:
     other_diffs = None
 
@@ -816,8 +817,8 @@ def generate_content(writer, cfg, repos,
     summary=summary,
     show_nonmatching_paths=show_nonmatching_paths,
     other_summary=other_summary,
-    diffs=DiffGenerator(changelist, paths, True, cfg, repos, date, group,
-                        params, pool),
+    diffs=generate_changelist_diffs(changelist, paths, True, cfg, repos,
+                                    date, group, params, pool),
     other_diffs=other_diffs,
     )
   ### clean this up in future rev. Just use wb
@@ -857,11 +858,13 @@ def _gather_paths(action, changelist, pa
   return items
 
 
-class DiffGenerator:
-  "This is a generator-like object returning DiffContent objects."
-
-  def __init__(self, changelist, paths, in_paths, cfg, repos, date, group,
-               params, pool):
+def generate_changelist_diffs(changelist, paths, in_paths, cfg, repos,
+                              date, group, params, pool):
+    "This is a generator returning diffs for each change."
+
+    ### for now, pretend we're still an object, like the former
+    ### incarnation, in order to minimize textual changes.
+    self = _data()
     self.changelist = changelist
     self.paths = paths
     self.in_paths = in_paths
@@ -877,14 +880,9 @@ class DiffGenerator:
     self.diffsels = DiffSelections(cfg, group, params)
     self.diffurls = DiffURLSelections(cfg, group, params)
 
-  def __nonzero__(self):
-    # we always have some items
-    return True
-
-  def __getitem__(self, idx):
     while True:
       if self.idx == len(self.changelist):
-        raise IndexError
+          return  # will raise StopIteration
 
       path, change = self.changelist[self.idx]
       self.idx = self.idx + 1
@@ -1025,7 +1023,7 @@ class DiffGenerator:
               }))
 
       # return a data item for this diff
-      return _data(
+      yield _data(
         path=change.path,
         base_path=base_path_bytes,
         base_rev=change.base_rev,


Reply via email to