changelog: make copies related function return None or a valid value
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 10 Oct 2019 00:06:41 +0200
changeset 43145 4296cc3c4ae1
parent 43144 ea230325dc8c
child 43146 0171483b082f
changelog: make copies related function return None or a valid value With the previous code, existing but empty value were not "decoded", leading to the method returning one of `None`, some valid value (`list` or `dict`) or `b''`. On a general basis, not explicitly checking for None is a source of bugs. Having a clean return types will help the side-data copies code in future changesets. Differential Revision: https://phab.mercurial-scm.org/D7037
mercurial/changelog.py
--- a/mercurial/changelog.py	Thu Oct 10 00:01:40 2019 +0200
+++ b/mercurial/changelog.py	Thu Oct 10 00:06:41 2019 +0200
@@ -363,22 +363,30 @@
     @property
     def filesadded(self):
         rawindices = self.extra.get(b'filesadded')
-        return rawindices and decodefileindices(self.files, rawindices)
+        if rawindices is None:
+            return None
+        return decodefileindices(self.files, rawindices)
 
     @property
     def filesremoved(self):
         rawindices = self.extra.get(b'filesremoved')
-        return rawindices and decodefileindices(self.files, rawindices)
+        if rawindices is None:
+            return None
+        return decodefileindices(self.files, rawindices)
 
     @property
     def p1copies(self):
         rawcopies = self.extra.get(b'p1copies')
-        return rawcopies and decodecopies(self.files, rawcopies)
+        if rawcopies is None:
+            return None
+        return decodecopies(self.files, rawcopies)
 
     @property
     def p2copies(self):
         rawcopies = self.extra.get(b'p2copies')
-        return rawcopies and decodecopies(self.files, rawcopies)
+        if rawcopies is None:
+            return None
+        return decodecopies(self.files, rawcopies)
 
     @property
     def description(self):