[PATCH 7 of 9 V2] obsolete: compute extinct changesets
pierre-yves.david at logilab.fr
pierre-yves.david at logilab.fr
Fri Jul 6 12:54:08 CDT 2012
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1341596049 -7200
# Node ID 6c0a3b9bcb4c319714a0edd07ee99dea4487f3c4
# Parent 4c9a282e873277ae9d225505bc28a8822da4253f
obsolete: compute extinct changesets
`extinct` changesets are obsolete changesets with obsolete descendants only. They
are of no interest anymore and can be:
- exclude from exchange
- hidden to the user in most situation
- safely garbage collected
This changeset just allows mercurial to detect them.
The implementation is a bit naive, as for unstable changesets. We better use a
simple revset query and a cache, but simple version comes first.
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -233,10 +233,25 @@ class changectx(object):
def obsolete(self):
"""True if the changeset is obsolete"""
return (self.node() in self._repo.obsstore.precursors
and self.phase() > phases.public)
+ def extinct(self):
+ """True if the changeset is extinct"""
+ # We should just compute a cache a check againts it.
+ # see revset implementation for details
+ #
+ # But this naive implementation does not require cache
+ if self.phase() <= phases.public:
+ return False
+ if not self.obsolete():
+ return False
+ for desc in self.descendants():
+ if not desc.obsolete():
+ return False
+ return True
+
def unstable(self):
"""True if the changeset is not obsolete but it's ancestor are"""
# We should just compute /(obsolete()::) - obsolete()/
# and keep it in a cache.
#
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -566,10 +566,17 @@ def draft(repo, subset, x):
Changeset in draft phase."""
getargs(x, 0, 0, _("draft takes no arguments"))
pc = repo._phasecache
return [r for r in subset if pc.phase(repo, r) == phases.draft]
+def extinct(repo, subset, x):
+ """``extinct()``
+ obsolete changeset with obsolete descendant only."""
+ getargs(x, 0, 0, _("obsolete takes no arguments"))
+ extinctset = set(repo.revs('(obsolete()::) - (::(not obsolete()))'))
+ return [r for r in subset if r in extinctset]
+
def extra(repo, subset, x):
"""``extra(label, [value])``
Changesets with the given label in the extra metadata, with the given
optional value.
@@ -1363,10 +1370,11 @@ symbols = {
"date": date,
"desc": desc,
"descendants": descendants,
"_firstdescendants": _firstdescendants,
"draft": draft,
+ "extinct": extinct,
"extra": extra,
"file": hasfile,
"filelog": filelog,
"first": first,
"follow": follow,
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -298,5 +298,15 @@ detect outgoing obsolete and unstable
$ hg push ../tmpc/
pushing to ../tmpc/
searching for changes
abort: push includes an unstable changeset: 7878242aeece!
[255]
+
+Test that extinct changeset are properly detected
+
+ $ hg log -r 'extinct()'
+ changeset: 3:cdbce2fbb163
+ parent: 1:7c3bad9141dc
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: add new_c
+
More information about the Mercurial-devel
mailing list