[PATCH 2 of 3] context: add "descendant()" to changectx for efficient descendant examination

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Tue Sep 18 07:44:06 CDT 2012


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1347971952 -32400
# Node ID 0e7f7a718a160bfa71adf573b8e20c5fbad22d9e
# Parent  da712d99933e8b524eef25c0fe014ed5c1215764
context: add "descendant()" to changectx for efficient descendant examination

This patch adds "descendant()", which uses "revlog.descendant()" for
descendant examination, to changectx.

This implementation is more efficient than "new in old.descendants()"
expression, because:

  - "changectx.descendants()" creates temporary "changectx" objects,
    but "revlog.descendant()" doesn't

    "revlog.descendant()" checks only revision numbers of descendants.

  - "revlog.descendant()" stops scanning, when scanning of all
    revisions less than one of examination target is finished

    this can avoid useless scanning in "not descendant" case.

diff -r da712d99933e -r 0e7f7a718a16 mercurial/context.py
--- a/mercurial/context.py	Tue Sep 18 21:39:12 2012 +0900
+++ b/mercurial/context.py	Tue Sep 18 21:39:12 2012 +0900
@@ -288,6 +288,10 @@
         n = self._repo.changelog.ancestor(self._node, n2)
         return changectx(self._repo, n)
 
+    def descendant(self, other):
+        """True if other is descendant of this changeset"""
+        return self._repo.changelog.descendant(self._rev, other._rev)
+
     def walk(self, match):
         fset = set(match.files())
         # for dirstate.walk, files=['.'] means "walk the whole tree".


More information about the Mercurial-devel mailing list