comparison mercurial/revset.py @ 17469:fb72eec7efd8

obsolete: introduce caches for all meaningful sets This changeset introduces caches on the `obsstore` that keeps track of sets of revisions meaningful for obsolescence related logics. For now they are: - obsolete: changesets used as precursors (and not public), - extinct: obsolete changesets with osbolete descendants only, - unstable: non obsolete changesets with obsolete ancestors. The cache is accessed using the `getobscache(repo, '<set-name>')` function which builds the cache on demand. The `clearobscaches(repo)` function takes care of clearing the caches if any. Caches are cleared when one of these events happens: - a new marker is added, - a new changeset is added, - some changesets are made public, - some public changesets are demoted to draft or secret. Declaration of more sets is made easy because we will have to handle at least two other "troubles" (latecomer and conflicting). Caches are now used by revset and changectx. It is usually not much more expensive to compute the whole set than to check the property of a few elements. The performance boost is welcome in case we apply obsolescence logic on a lot of revisions. This makes the feature usable!
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Tue, 28 Aug 2012 20:52:04 +0200
parents e7cfe3587ea4
children 31f32a96e1e3
comparison
equal deleted inserted replaced
17460:a306837f8c87 17469:fb72eec7efd8
10 import node 10 import node
11 import bookmarks as bookmarksmod 11 import bookmarks as bookmarksmod
12 import match as matchmod 12 import match as matchmod
13 from i18n import _ 13 from i18n import _
14 import encoding 14 import encoding
15 import obsolete as obsmod
15 16
16 def _revancestors(repo, revs, followfirst): 17 def _revancestors(repo, revs, followfirst):
17 """Like revlog.ancestors(), but supports followfirst.""" 18 """Like revlog.ancestors(), but supports followfirst."""
18 cut = followfirst and 1 or None 19 cut = followfirst and 1 or None
19 cl = repo.changelog 20 cl = repo.changelog
619 """``extinct()`` 620 """``extinct()``
620 Obsolete changesets with obsolete descendants only. 621 Obsolete changesets with obsolete descendants only.
621 """ 622 """
622 # i18n: "extinct" is a keyword 623 # i18n: "extinct" is a keyword
623 getargs(x, 0, 0, _("extinct takes no arguments")) 624 getargs(x, 0, 0, _("extinct takes no arguments"))
624 extinctset = set(repo.revs('(obsolete()::) - (::(not obsolete()))')) 625 extincts = obsmod.getobscache(repo, 'extinct')
625 return [r for r in subset if r in extinctset] 626 return [r for r in subset if r in extincts]
626 627
627 def extra(repo, subset, x): 628 def extra(repo, subset, x):
628 """``extra(label, [value])`` 629 """``extra(label, [value])``
629 Changesets with the given label in the extra metadata, with the given 630 Changesets with the given label in the extra metadata, with the given
630 optional value. 631 optional value.
957 def obsolete(repo, subset, x): 958 def obsolete(repo, subset, x):
958 """``obsolete()`` 959 """``obsolete()``
959 Mutable changeset with a newer version.""" 960 Mutable changeset with a newer version."""
960 # i18n: "obsolete" is a keyword 961 # i18n: "obsolete" is a keyword
961 getargs(x, 0, 0, _("obsolete takes no arguments")) 962 getargs(x, 0, 0, _("obsolete takes no arguments"))
962 return [r for r in subset if repo[r].obsolete()] 963 obsoletes = obsmod.getobscache(repo, 'obsolete')
964 return [r for r in subset if r in obsoletes]
963 965
964 def origin(repo, subset, x): 966 def origin(repo, subset, x):
965 """``origin([set])`` 967 """``origin([set])``
966 Changesets that were specified as a source for the grafts, transplants or 968 Changesets that were specified as a source for the grafts, transplants or
967 rebases that created the given revisions. Omitting the optional set is the 969 rebases that created the given revisions. Omitting the optional set is the
1435 """``unstable()`` 1437 """``unstable()``
1436 Non-obsolete changesets with obsolete ancestors. 1438 Non-obsolete changesets with obsolete ancestors.
1437 """ 1439 """
1438 # i18n: "unstable" is a keyword 1440 # i18n: "unstable" is a keyword
1439 getargs(x, 0, 0, _("unstable takes no arguments")) 1441 getargs(x, 0, 0, _("unstable takes no arguments"))
1440 unstableset = set(repo.revs('(obsolete()::) - obsolete()')) 1442 unstables = obsmod.getobscache(repo, 'unstable')
1441 return [r for r in subset if r in unstableset] 1443 return [r for r in subset if r in unstables]
1442 1444
1443 1445
1444 def user(repo, subset, x): 1446 def user(repo, subset, x):
1445 """``user(string)`` 1447 """``user(string)``
1446 User name contains string. The match is case-insensitive. 1448 User name contains string. The match is case-insensitive.