From patchwork Wed Oct 9 22:43:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D7037: context: make copies related function return None or a valid value From: phabricator X-Patchwork-Id: 42163 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Wed, 9 Oct 2019 22:43:42 +0000 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 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):