Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/context.py @ 19149:921b64e1f7b9
filecontext: use 'is not None' to check for filelog existence
Previously we used 'if filelog:' to check if the filelog existed. If the
instance did exist, this pattern then calls len() on the filelog to see
if it is empty. I'm developing a filelog replacement that doesn't have
len() implemented, so it's better to do an explicit 'is not None' check
here instead.
Also change _changeid() to return the _changeid attribute if it has it.
Previously it would try to obtain it from the _changectx(), and if that
did not exist it would construct the _changectx() using the linkrev. In
the extension I'm working on, filectx's don't have easy access to linkrevs
so avoiding this when possible is better.
author | Durham Goode <durham@fb.com> |
---|---|
date | Wed, 01 May 2013 10:42:03 -0700 |
parents | 36067f5baf24 |
children | ec367f203cb5 |
comparison
equal
deleted
inserted
replaced
19148:3bda242bf244 | 19149:921b64e1f7b9 |
---|---|
396 or fileid is not None | 396 or fileid is not None |
397 or changectx is not None), \ | 397 or changectx is not None), \ |
398 ("bad args: changeid=%r, fileid=%r, changectx=%r" | 398 ("bad args: changeid=%r, fileid=%r, changectx=%r" |
399 % (changeid, fileid, changectx)) | 399 % (changeid, fileid, changectx)) |
400 | 400 |
401 if filelog: | 401 if filelog is not None: |
402 self._filelog = filelog | 402 self._filelog = filelog |
403 | 403 |
404 if changeid is not None: | 404 if changeid is not None: |
405 self._changeid = changeid | 405 self._changeid = changeid |
406 if changectx is not None: | 406 if changectx is not None: |
435 def _filelog(self): | 435 def _filelog(self): |
436 return self._repo.file(self._path) | 436 return self._repo.file(self._path) |
437 | 437 |
438 @propertycache | 438 @propertycache |
439 def _changeid(self): | 439 def _changeid(self): |
440 if '_changectx' in self.__dict__: | 440 if '_changeid' in self.__dict__: |
441 return self._changeid | |
442 elif '_changectx' in self.__dict__: | |
441 return self._changectx.rev() | 443 return self._changectx.rev() |
442 else: | 444 else: |
443 return self._filelog.linkrev(self._filerev) | 445 return self._filelog.linkrev(self._filerev) |
444 | 446 |
445 @propertycache | 447 @propertycache |
1165 self._repo = repo | 1167 self._repo = repo |
1166 self._path = path | 1168 self._path = path |
1167 self._changeid = None | 1169 self._changeid = None |
1168 self._filerev = self._filenode = None | 1170 self._filerev = self._filenode = None |
1169 | 1171 |
1170 if filelog: | 1172 if filelog is not None: |
1171 self._filelog = filelog | 1173 self._filelog = filelog |
1172 if workingctx: | 1174 if workingctx: |
1173 self._changectx = workingctx | 1175 self._changectx = workingctx |
1174 | 1176 |
1175 @propertycache | 1177 @propertycache |