# HG changeset patch # User Boris Feld # Date 2017-05-04 00:23:21 # Node ID 8810f0643fa1cd363f5a1c4e84ed80e3a7a5ae7f # Parent 2b9e2415f5b5d440734ccdf2fc79561c7c104635 changelog: introduce a 'tiprev' method Accessing tiprev is a common need through the code base. It is usually done using "len(changelog) -1". That form is tedious and error-prone. For example, it will give wrong results on filtered changelog (if the unfiltered tip is filtered). As a result, we introduce a simple 'tiprev()' method to provide this exact information in a nice way. diff --git a/mercurial/changelog.py b/mercurial/changelog.py --- a/mercurial/changelog.py +++ b/mercurial/changelog.py @@ -295,6 +295,11 @@ class changelog(revlog.revlog): self._divert = False self.filteredrevs = frozenset() + def tiprev(self): + for i in xrange(len(self) -1, -2, -1): + if i not in self.filteredrevs: + return i + def tip(self): """filtered version of revlog.tip""" for i in xrange(len(self) -1, -2, -1):