D7037: context: make copies related function return None or a valid value
marmoute (Pierre-Yves David)
phabricator at mercurial-scm.org
Wed Oct 9 22:43:42 UTC 2019
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
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):
To: marmoute, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list