emerge --changelog: fix split ChangeLog bugs
authorZac Medico <zmedico@gentoo.org>
Thu, 22 Mar 2012 17:15:10 +0000 (10:15 -0700)
committerZac Medico <zmedico@gentoo.org>
Thu, 22 Mar 2012 18:10:02 +0000 (11:10 -0700)
This should fix possible missing content when displaying split
ChangeLogs (bug #389611), and also normalizes blank lines.

pym/_emerge/resolver/output.py
pym/_emerge/resolver/output_helpers.py

index bec6619a16eb84036911e08d85916ab92fc6a893..a97658afbe5069983c15253c61fdbd866ef6df0c 100644 (file)
@@ -16,7 +16,7 @@ from portage.dbapi.dep_expand import dep_expand
 from portage.dep import cpvequal, _repo_separator
 from portage.exception import InvalidDependString, SignatureException
 from portage.package.ebuild._spawn_nofetch import spawn_nofetch
-from portage.output import ( blue, bold, colorize, create_color_func,
+from portage.output import ( blue, colorize, create_color_func,
        darkblue, darkgreen, green, nc_len, red, teal, turquoise, yellow )
 bad = create_color_func("BAD")
 from portage.util import writemsg_stdout
@@ -598,13 +598,9 @@ class Display(object):
        def print_changelog(self):
                """Prints the changelog text to std_out
                """
-               if not self.changelogs:
-                       return
-               writemsg_stdout('\n', noiselevel=-1)
-               for revision, text in self.changelogs:
-                       writemsg_stdout(bold('*'+revision) + '\n' + text,
+               for chunk in self.changelogs:
+                       writemsg_stdout(chunk,
                                noiselevel=-1)
-               return
 
 
        def get_display_list(self, mylist):
index cda0b089616d10f757b5431c2e473d878a00ae48..ae84158cfaea2dd4d8872f6d818c43638158c44c 100644 (file)
@@ -14,8 +14,8 @@ import sys
 from portage import os
 from portage import _encodings, _unicode_encode
 from portage._sets.base import InternalPackageSet
-from portage.output import blue, colorize, create_color_func, green, red, \
-       teal, yellow
+from portage.output import (blue, bold, colorize, create_color_func,
+       green, red, teal, yellow)
 bad = create_color_func("BAD")
 from portage.util import shlex_split, writemsg
 from portage.versions import catpkgsplit
@@ -539,26 +539,57 @@ def _calc_changelog(ebuildpath,current,next):
                        divisions = divisions[i:]
                        break
 
-       return divisions
+       output = []
+       prev_blank = False
+       prev_rev = False
+       for rev, lines in divisions:
+               if rev is not None:
+                       if not (prev_blank or prev_rev):
+                               output.append("\n")
+                       output.append(bold('*' + rev) + '\n')
+                       prev_rev = True
+                       prev_blank = False
+               if lines:
+                       prev_rev = False
+                       if not prev_blank:
+                               output.append("\n")
+                       for l in lines:
+                               output.append(l + "\n")
+                       output.append("\n")
+                       prev_blank = True
+       return output
+
+def _strip_header_comments(lines):
+       # strip leading and trailing blank or header/comment lines
+       i = 0
+       while i < len(lines) and (not lines[i] or lines[i][:1] == "#"):
+               i += 1
+       if i:
+               lines = lines[i:]
+       while lines and (not lines[-1] or lines[-1][:1] == "#"):
+               lines.pop()
+       return lines
 
 def _find_changelog_tags(changelog):
        divs = []
+       if not changelog:
+               return divs
        release = None
-       while 1:
-               match = re.search(r'^\*\ ?([-a-zA-Z0-9_.+]*)(?:\ .*)?\n',changelog,re.M)
-               if match is None:
-                       if release is not None:
-                               divs.append((release,changelog))
-                       return divs
-               if release is not None:
-                       divs.append((release,changelog[:match.start()]))
-               changelog = changelog[match.end():]
+       release_end = 0
+       for match in re.finditer(r'^\*\ ?([-a-zA-Z0-9_.+]*)(?:\ .*)?$',
+               changelog, re.M):
+               divs.append((release, _strip_header_comments(
+                       changelog[release_end:match.start()].splitlines())))
+               release_end = match.end()
                release = match.group(1)
                if release.endswith('.ebuild'):
                        release = release[:-7]
                if release.endswith('-r0'):
                        release = release[:-3]
 
+       divs.append((release,
+               _strip_header_comments(changelog[release_end:].splitlines())))
+       return divs
 
 class PkgInfo(object):
        """Simple class to hold instance attributes for current