[PATCH 7 of 8 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 18:04:52 CST 2012


On 18 janv. 2012, at 00:01, Matt Mackall wrote:

>> +        # 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 = []
> 
> Not excited about this name. How about _phasedefaults?

sounds good

>>         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
> 
> asserts are discouraged. With or without, we get a traceback in the
> field, so why bother?

We get a traceback sooner with a better message

>> 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 = []
> 
> Why is this needed? Doesn't inheritance take care of this?

No, statichttprepository inherit from localrepo but never call it's parent __init__



More information about the Mercurial-devel mailing list