#72 Handle malformed versions in changelogs
Merged 5 years ago by lsedlar. Opened 5 years ago by lsedlar.
lsedlar/compose-utils bad-changelogs  into  master

file modified
+21 -12
@@ -104,18 +104,27 @@ 

  

      if new_changelog and old_changelog:

          result = []

-         old_time = old_changelog[0].time

-         old_nvr = LooseVersion(to_utf8(old_changelog[0].name).rsplit(None, 1)[-1])

-         while new_changelog:

-             entry = new_changelog.pop(0)

-             new_nvr = LooseVersion(to_utf8(entry.name).rsplit(None, 1)[-1])

-             if entry.time < old_time or (entry.time == old_time and new_nvr <= old_nvr):

-                 # We want to take all entries from new changelog that are newer

-                 # than old changelog, or from the same day as latest old entry

-                 # but with newer version.

-                 break

-             result.insert(0, entry)

-         return result

+         try:

+             old_time = old_changelog[0].time

+             old_nvr = LooseVersion(to_utf8(old_changelog[0].name).rsplit(None, 1)[-1])

+             while new_changelog:

+                 entry = new_changelog.pop(0)

+                 new_nvr = LooseVersion(to_utf8(entry.name).rsplit(None, 1)[-1])

+                 if entry.time < old_time or (

+                     entry.time == old_time and new_nvr <= old_nvr

+                 ):

+                     # We want to take all entries from new changelog that are newer

+                     # than old changelog, or from the same day as latest old entry

+                     # but with newer version.

+                     break

+                 result.insert(0, entry)

+             return result

+         except Exception:

+             # There was a problem getting all new changelog entries. If we

+             # managed to get at least some, return that, otherwise fall back to

+             # returning whole changelog.

+             if result:

+                 return result

      return new_changelog

  

  

There can be anything really, so when we fail to compare the versions for any reason the changelog should not crash. Instead we will take whatever entries we collected so far (which could potentially be missing something), or if we have nothing so far return the whole changelog.

Fixes: https://pagure.io/compose-utils/issue/71

rebased onto ecaa942

5 years ago

Pretty please pagure-ci rebuild

Pull-Request has been merged by lsedlar

5 years ago