Mercurial > public > mercurial-scm > hg-stable
diff hgext/split.py @ 46843:728d89f6f9b1
refactor: prefer checks against nullrev over nullid
A common pattern is using a changeset context and obtaining the node to
compare against nullid. Change this to obtain the nullrev instead. In
the future, the nullid becomes a property of the repository and is no
longer a global constant, so using nullrev is much easier to reason
about. Python function call overhead makes the difference moot, but
future changes will result in more dictionary lookups otherwise, so
prefer the simpler pattern.
Differential Revision: https://phab.mercurial-scm.org/D10290
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Tue, 30 Mar 2021 02:32:30 +0200 |
parents | 7f6c002d7c0a |
children | 8ee1ac083ee7 |
line wrap: on
line diff
--- a/hgext/split.py Tue Mar 30 02:33:12 2021 +0200 +++ b/hgext/split.py Tue Mar 30 02:32:30 2021 +0200 @@ -12,7 +12,7 @@ from mercurial.i18n import _ from mercurial.node import ( - nullid, + nullrev, short, ) @@ -80,12 +80,12 @@ raise error.InputError(_(b'cannot split multiple revisions')) rev = revs.first() - ctx = repo[rev] - # Handle nullid specially here (instead of leaving for precheck() + # Handle nullrev specially here (instead of leaving for precheck() # below) so we get a nicer message and error code. - if rev is None or ctx.node() == nullid: + if rev is None or rev == nullrev: ui.status(_(b'nothing to split\n')) return 1 + ctx = repo[rev] if ctx.node() is None: raise error.InputError(_(b'cannot split working directory'))