[PATCH 4 of 6] phases: add a function to compute heads from root

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Dec 14 03:50:19 CST 2011


On 13 déc. 2011, at 23:57, Matt Mackall wrote:

> On Tue, 2011-12-13 at 00:52 +0100, Pierre-Yves David wrote:
>> 
>> +def analyseremotephases(repo, subset, roots):
> 
> Localization error. In en_us, we use 'analyze', 'serialize', etc.

Noted. I'll rename this function

>> +    """Compute phases heads and root in a subset of node from root dict
>> +
>> +    * subset is heads of the subset
>> +    * roots is {<nodeid> => phase} mapping. key and value are string.
>> +    Accept unknown element input
>> +    """
>> +    # build list from dictionary
>> +    phaseroots = [[] for p in allphases]
> 
> [] * len(allphases)

Won't work

>>> [] * 3
[]

[[]] * len(allphases) won't either

>>> a = [[]] * 3
>>> a[0].append('babar')
>>> a
[['babar'], ['babar'], ['babar']]

We need a new object for each element. List comprehension seemed the
simplest way to do it.

> 
>> +    for nhex, phase in roots.iteritems():
>> +        node = bin(nhex)
>> +        phase = int(phase)
>> +        if node in repo:
>> +            phaseroots[phase].append(node)
>> +    # remove potential nullid root added by pushkey
>> +    phaseroots[0] = []
>> +    # compute heads
>> +    phaseheads = [[] for p in allphases]
>> +    for phase in allphases[:-1]:
>> +        toproof = phaseroots[phase + 1]
>> +        #rvset = repo.set('(::%ln) - (%ln::)', subset, toproof)
> 
> Dead comment?

Not sure, I might have left it here for experimenting other formula while
looking to solve a bug which was finally elsewhere. thanks for catching this,
I'll check it and leave only one.

>> +        revset = repo.set('heads((%ln + parents(%ln)) - (%ln::%ln))',
>> +                          subset, toproof, toproof, subset)
>> +        phaseheads[phase].extend(c.node() for c in revset)
>> +    return phaseheads, phaseroots


More information about the Mercurial-devel mailing list