comparison mercurial/context.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 ad878e3f282b
children d55b71393907
comparison
equal deleted inserted replaced
46842:ad878e3f282b 46843:728d89f6f9b1
2883 man1 = self.p1().manifest() 2883 man1 = self.p1().manifest()
2884 p2 = self._parents[1] 2884 p2 = self._parents[1]
2885 # "1 < len(self._parents)" can't be used for checking 2885 # "1 < len(self._parents)" can't be used for checking
2886 # existence of the 2nd parent, because "memctx._parents" is 2886 # existence of the 2nd parent, because "memctx._parents" is
2887 # explicitly initialized by the list, of which length is 2. 2887 # explicitly initialized by the list, of which length is 2.
2888 if p2.node() != nullid: 2888 if p2.rev() != nullrev:
2889 man2 = p2.manifest() 2889 man2 = p2.manifest()
2890 managing = lambda f: f in man1 or f in man2 2890 managing = lambda f: f in man1 or f in man2
2891 else: 2891 else:
2892 managing = lambda f: f in man1 2892 managing = lambda f: f in man1
2893 2893
2901 removed.append(f) 2901 removed.append(f)
2902 2902
2903 return scmutil.status(modified, added, removed, [], [], [], []) 2903 return scmutil.status(modified, added, removed, [], [], [], [])
2904 2904
2905 def parents(self): 2905 def parents(self):
2906 if self._parents[1].node() == nullid: 2906 if self._parents[1].rev() == nullrev:
2907 return [self._parents[0]] 2907 return [self._parents[0]]
2908 return self._parents 2908 return self._parents
2909 2909
2910 2910
2911 class memfilectx(committablefilectx): 2911 class memfilectx(committablefilectx):
3050 man1 = self.p1().manifest() 3050 man1 = self.p1().manifest()
3051 p2 = self._parents[1] 3051 p2 = self._parents[1]
3052 # "1 < len(self._parents)" can't be used for checking 3052 # "1 < len(self._parents)" can't be used for checking
3053 # existence of the 2nd parent, because "metadataonlyctx._parents" is 3053 # existence of the 2nd parent, because "metadataonlyctx._parents" is
3054 # explicitly initialized by the list, of which length is 2. 3054 # explicitly initialized by the list, of which length is 2.
3055 if p2.node() != nullid: 3055 if p2.rev() != nullrev:
3056 man2 = p2.manifest() 3056 man2 = p2.manifest()
3057 managing = lambda f: f in man1 or f in man2 3057 managing = lambda f: f in man1 or f in man2
3058 else: 3058 else:
3059 managing = lambda f: f in man1 3059 managing = lambda f: f in man1
3060 3060