[PATCH 7 of 9 phases] phases: mechanism to allow extension to alter initial computation of phase

Pierre-Yves David pierre-yves.david at ens-lyon.org
Tue Jan 17 17:37:48 CST 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1326821506 -3600
# Node ID 0bc43e3f1b0ba4b7694b5f15be80bba1da4cf084
# Parent  6307522246542311b755afc7a354fd68ed153ede
phases: mechanism to allow extension to alter initial computation of phase

This commit add a whennodata list where extension can register a callback to be
called if no phase related data are found in the repository.

The goal is to ensure the existing extension that move phase data in 2.1 can
compute consistent phase boundary for existing repo.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -37,6 +37,10 @@
         self.baseui = baseui
         self.ui = baseui.copy()
         self._dirtyphases = False
+        # A list of callback to shape the phase if no data were found.
+        # Callback are in the form: func(repo, roots) --> processed root.
+        # This list it to be filled by extension during repo setup
+        self._whennophasedata = []
 
         try:
             self.ui.readconfig(self.join("hgrc"), self.root)
diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -109,7 +109,6 @@
 def readroots(repo):
     """Read phase roots from disk"""
     roots = [set() for i in allphases]
-    roots[0].add(nullid)
     try:
         f = repo.sopener('phaseroots')
         try:
@@ -121,6 +120,9 @@
     except IOError, inst:
         if inst.errno != errno.ENOENT:
             raise
+        for wnd in repo._whennophasedata:
+            roots = wnd(repo, roots)
+            assert roots is not None, '%r forgot to return a value' % wnd
     return roots
 
 def writeroots(repo):
diff --git a/mercurial/statichttprepo.py b/mercurial/statichttprepo.py
--- a/mercurial/statichttprepo.py
+++ b/mercurial/statichttprepo.py
@@ -86,6 +86,7 @@
 
         opener = build_opener(ui, authinfo)
         self.opener = opener(self.path)
+        self._whennophasedata = []
 
         try:
             requirements = scmutil.readrequires(self.opener, self.supported)


More information about the Mercurial-devel mailing list