Submitter | Boris Feld |
---|---|
Date | Jan. 17, 2018, 6:33 p.m. |
Message ID | <e3bb410037a49980a831.1516214029@FB> |
Download | mbox | patch |
Permalink | /patch/26819/ |
State | Accepted |
Headers | show |
Comments
On Wed, 2018-01-17 at 19:33 +0100, Boris Feld wrote: > # HG changeset patch > # User Boris Feld <boris.feld@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). Funny, I had this very need yesterday, and I needed it cached, so I did this instead: http://mercurial.markmail.org/search/list:com.selenic.mercurial-devel#q uery:list%3Acom.selenic.mercurial- devel+page:1+mid:6mqe6sjrsmuixcbe+state:results
Patch
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):