Patchwork D7037: context: make copies related function return None or a valid value

login
register
mail settings
Submitter phabricator
Date Oct. 9, 2019, 10:43 p.m.
Message ID <differential-rev-PHID-DREV-6pm5ymz5wwf4s7atfdxr-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/42163/
State Superseded
Headers show

Comments

phabricator - Oct. 9, 2019, 10:43 p.m.
marmoute created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  With the previous code, existing but empty value where 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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D7037

AFFECTED FILES
  mercurial/changelog.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -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):