Mercurial > hg
comparison mercurial/changelog.py @ 43145:4296cc3c4ae1
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
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 10 Oct 2019 00:06:41 +0200 |
parents | 037a8759eda1 |
children | 0171483b082f |
comparison
equal
deleted
inserted
replaced
43144:ea230325dc8c | 43145:4296cc3c4ae1 |
---|---|
361 return self._text[off[2] + 1 : off[3]].split(b'\n') | 361 return self._text[off[2] + 1 : off[3]].split(b'\n') |
362 | 362 |
363 @property | 363 @property |
364 def filesadded(self): | 364 def filesadded(self): |
365 rawindices = self.extra.get(b'filesadded') | 365 rawindices = self.extra.get(b'filesadded') |
366 return rawindices and decodefileindices(self.files, rawindices) | 366 if rawindices is None: |
367 return None | |
368 return decodefileindices(self.files, rawindices) | |
367 | 369 |
368 @property | 370 @property |
369 def filesremoved(self): | 371 def filesremoved(self): |
370 rawindices = self.extra.get(b'filesremoved') | 372 rawindices = self.extra.get(b'filesremoved') |
371 return rawindices and decodefileindices(self.files, rawindices) | 373 if rawindices is None: |
374 return None | |
375 return decodefileindices(self.files, rawindices) | |
372 | 376 |
373 @property | 377 @property |
374 def p1copies(self): | 378 def p1copies(self): |
375 rawcopies = self.extra.get(b'p1copies') | 379 rawcopies = self.extra.get(b'p1copies') |
376 return rawcopies and decodecopies(self.files, rawcopies) | 380 if rawcopies is None: |
381 return None | |
382 return decodecopies(self.files, rawcopies) | |
377 | 383 |
378 @property | 384 @property |
379 def p2copies(self): | 385 def p2copies(self): |
380 rawcopies = self.extra.get(b'p2copies') | 386 rawcopies = self.extra.get(b'p2copies') |
381 return rawcopies and decodecopies(self.files, rawcopies) | 387 if rawcopies is None: |
388 return None | |
389 return decodecopies(self.files, rawcopies) | |
382 | 390 |
383 @property | 391 @property |
384 def description(self): | 392 def description(self): |
385 return encoding.tolocal(self._text[self._offsets[3] + 2 :]) | 393 return encoding.tolocal(self._text[self._offsets[3] + 2 :]) |
386 | 394 |