changeset 35671:8810f0643fa1

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.
author Boris Feld <boris.feld@octobus.net>
date Thu, 04 May 2017 02:23:21 +0200
parents 2b9e2415f5b5
children 5a6e0eee7781
files mercurial/changelog.py
diffstat 1 files changed, 5 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changelog.py	Wed Jan 17 15:47:38 2018 -0500
+++ b/mercurial/changelog.py	Thu May 04 02:23:21 2017 +0200
@@ -295,6 +295,11 @@
         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):