Proposed Namespace Changes

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Dec 18 19:07:21 CST 2014



On 12/18/2014 04:58 PM, Sean Farley wrote:
>
> Sean Farley writes:
>
>> Following discussion on IRC with marmoute, it seems that having an
>> individual namespace as an object would look better. Here is a
>> hypothetical example:
>>
>> repo.names = {}
>>
>> repo.names["bookmarks"] = namespace.create(repo, "bookmarks", "bookmark", ...)
>>
>> repo.names["bookmarks"].listnames() (should we rename 'allnames'?)
>>
>> repo.names["bookmarks"].templatename
>>
>> repo.names["bookmarks"].namesof(nodeid)
>>
>> Let's look at all the method names we have so far,
>>
>> - singlenode(name) -> returns first node found, errors out otherwise
>>
>> - names(namespace, node) -> returns list of names
>>
>> - namesof(node) -> return dictionary of {namespace: name}
>>
>> - allnames(namespace) -> returns list of names in a namespace
>>
>> - namespaces() -> return list of namespaces
>>
>> Here's how it would look as an object:
>>
>> - singlenode(name) -> returns first node found, errors out otherwise
>>
>> - names(node) -> returns list of names
>>
>> - repo.names.namesof(node) -> return dictionary of {namespace: name}
>>
>> - allnames() -> returns list of names in a namespace
>>
>> - repo.names.keys() -> return list of namespaces
>>
>> So, the only kink here is the 'namesof' method since we'd be operating
>> on each namespace independently. Thoughts?
>
> To answer my own question, I think the solution here would be two
> objects:
>
> - namespaces (inherits or wraps a sortdict)
> - namespace (the proposed changes)
>
> This would mean we could call methods on all namespaces via its object:
>
> repo.names.listnames() -> return all namespaces (same as the keys of its
> dictionary)

What about repo.names being iterable `for namespace in repo.names`

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list