Patchwork [05,of,10] revlog: add a method to retrieve snapshot depth

login
register
mail settings
Submitter Boris Feld
Date Aug. 16, 2018, 1:43 p.m.
Message ID <0543f2d7c86af60df21a.1534426992@FB-lair>
Download mbox | patch
Permalink /patch/33785/
State Accepted
Headers show

Comments

Boris Feld - Aug. 16, 2018, 1:43 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1534327754 -7200
#      Wed Aug 15 12:09:14 2018 +0200
# Node ID 0543f2d7c86af60df21a51b0dc826780400d3a62
# Parent  23af56696ff32b0172570e4430775a7793d9d8f9
# EXP-Topic sparse-snapshot
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 0543f2d7c86a
revlog: add a method to retrieve snapshot depth

Some snapshot property (eg: maximum size) will depend on their depth.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -2094,6 +2094,12 @@  class revlog(object):
             return False
         return self.issnapshot(deltap)
 
+    def snapshotdepth(self, rev):
+        """number of snapshot in the chain before this one"""
+        if not self.issnapshot(rev):
+            raise ProgrammingError('revision %d not a snapshot')
+        return len(self._deltachain(rev)[0]) - 1
+
     def revdiff(self, rev1, rev2):
         """return or calculate a delta between two revisions