[PATCH 1 of 5] changelog: introduce a 'tiprev' method

Boris Feld boris.feld at octobus.net
Wed Jan 17 18:33:49 UTC 2018


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1493857401 -7200
#      Thu May 04 02:23:21 2017 +0200
# Node ID e3bb410037a49980a8316e4e5a49ab23ea978047
# Parent  0e369eca888fc80ee980fe8200c59dc7b0024dae
# EXP-Topic tiprev
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r e3bb410037a4
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):


More information about the Mercurial-devel mailing list