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

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Tue Jan 17 11:35:40 CST 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1326821506 -3600
# Node ID b4680e030682a7fad6cc7226f03b9ead203f84b6
# Parent  1b22ef5905a472f8264839b3eb70091666e61205
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
@@ -35,10 +35,14 @@ class localrepository(repo.repository):
         self.opener = scmutil.opener(self.path)
         self.wopener = scmutil.opener(self.root)
         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)
             extensions.loadall(self.ui)
         except IOError:
diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -107,11 +107,10 @@ trackedphases = allphases[1:]
 phasenames = ['public', 'draft', 'secret']
 
 def readroots(repo):
     """Read phase roots from disk"""
     roots = [set() for i in allphases]
-    roots[0].add(nullid)
     try:
         f = repo.sopener('phaseroots')
         try:
             for line in f:
                 phase, nh = line.strip().split()
@@ -119,10 +118,13 @@ def readroots(repo):
         finally:
             f.close()
     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):
     """Write phase roots from disk"""
     f = repo.sopener('phaseroots', 'w', atomictemp=True)
diff --git a/mercurial/statichttprepo.py b/mercurial/statichttprepo.py
--- a/mercurial/statichttprepo.py
+++ b/mercurial/statichttprepo.py
@@ -84,10 +84,11 @@ class statichttprepository(localrepo.loc
         u = util.url(path.rstrip('/') + "/.hg")
         self.path, authinfo = u.authinfo()
 
         opener = build_opener(ui, authinfo)
         self.opener = opener(self.path)
+        self._whennophasedata = []
 
         try:
             requirements = scmutil.readrequires(self.opener, self.supported)
         except IOError, inst:
             if inst.errno != errno.ENOENT:


More information about the Mercurial-devel mailing list