o ]Lb @s\ddlmZddlmZddlmZmZmZmZddZ Gddde Z Gd d d e Z d S) )absolute_import)_)pycompat registrar templatekwutilcCs|durgS|gS)zF a convenience method to return an empty list instead of None N)valr r 6/usr/lib/python3/dist-packages/mercurial/namespaces.pytolist sr c@sTeZdZdZdZddZddZddZdd d Zd d Z e Z dddZ ddZ d S) namespaceszprovides an interface to register and operate on multiple namespaces. See the namespace class below for details on the namespace object. rc Cst|_t}dd}dd}dd}tdd|d|||dd}||d d}d d}d d}td d |d |||dhdd}||dd} dd} dd} tdd|d| | | dd}||dS)NcS |jSN) _bookmarkskeysrepor r r $ z%namespaces.__init__..cSst|j|Sr)r rgetrnamer r r r%cS ||Sr) nodebookmarksrnoder r r r&rs bookmarkssbookmarkT) templatenamelogfmt listnamesnamemapnodemapbuiltincSsdd|DS)NcSsg|]\}}|qSr r ).0tnr r r 2sz9namespaces.__init__....)tagslistrr r r r2cSst|jj|Sr)r _tagscachetagsrrr r r r3r)cSrr)nodetagsrr r r r4rstagsstagstip)rrr r!r" deprecatedr#cSs |Sr) branchmaprrr r r rAs cSst||dS)NT)r branchtiprr r r rBrcSs||gSr)branchrr r r rCssbranchessbranch)rsortdict_namesr getlogcolumns namespace addnamespace) selfcolumnsbmknames bmknamemap bmknodemapr&tagnames tagnamemap tagnodemapbnamesbnamemapbnodemapr r r __init__sT    znamespaces.__init__cCs |j|S)zreturns the namespace object)r2)r6r4r r r __getitem__Os znamespaces.__getitem__cCrr)r2__iter__r6r r r rCSs znamespaces.__iter__NcCs|j||Sr)r2r)r6r4defaultr r r rVsznamespaces.getcCs t|jSr)r iteritemsr2rDr r r itemsYs znamespaces.itemscsf|dur|j|jn|jj<jtjvr1ttj}|jddhdfdd}dSdS)zregister a namespace namespace: the name to be registered (in plural form) order: optional argument to specify the order of namespaces (e.g. 'branches' should be listed before 'bookmarks') Nsreposctx)requirescst||jSr)r shownamesr)contextmappingr4r r generatekwosz+namespaces.addnamespace..generatekw)r2insertrrkeywordsrtemplatekeyword)r6r4orderrPrMr rLr r5^s   znamespaces.addnamespacecCs>t|jD]\}}|||}|r|Sqttd|)a Return the 'best' node for the given name. What's best is defined by the namespace's singlenode() function. The first match returned by a namespace in the defined precedence order is used. Raises a KeyError if there is no such node. sno such name: %s)rrFr2 singlenodeKeyErrorr)r6rrnsvr&r r r rRss  znamespaces.singlenoder) __name__ __module__ __qualname____doc___names_versionrArBrCrrGrFr5rRr r r r r s1   r c@sFeZdZdZ          d ddZddZdd Zd d ZdS) r4aprovides an interface to a namespace Namespaces are basically generic many-to-many mapping between some (namespaced) names and nodes. The goal here is to control the pollution of jamming things into tags or bookmarks (in extension-land) and to simplify internal bits of mercurial: log output, tab completion, etc. More precisely, we define a mapping of names to nodes, and a mapping from nodes to names. Each mapping returns a list. Furthermore, each name mapping will be passed a name to lookup which might not be in its domain. In this case, each method should return an empty list and not raise an error. This namespace object will define the properties we need: 'name': the namespace (plural form) 'templatename': name to use for templating (usually the singular form of the plural namespace name) 'listnames': list of all names in the namespace (usually the keys of a dictionary) 'namemap': function that takes a name and returns a list of nodes 'nodemap': function that takes a node and returns a list of names 'deprecated': set of names to be masked for ordinary use 'builtin': bool indicating if this namespace is supported by core Mercurial. NFc Cs||_||_||_||_||_||_||_||_| r| |_|jdur&|j|_|jdur/|j|_|jdur?d|j dd|_| durHt |_ n| |_ | |_ dS)aVcreate a namespace name: the namespace to be registered (in plural form) templatename: the name to use for templating logname: the name to use for log output; if not specified templatename is used colorname: the name to use for colored log output; if not specified logname is used logfmt: the format to use for (i18n-ed) log output; if not specified it is composed from logname listnames: function to list all names namemap: function that inputs a name, output node(s) nodemap: function that inputs a node, output name(s) deprecated: set of names to be masked for ordinary use builtin: whether namespace is implemented by core Mercurial singlenode: function that inputs a name, output best node (or None) Ns%s: s%s ) rrlogname colornamerr r!r"rRljustsetr-r#) r6rrr\r]rr r!r"r-r#rRr r r rAs(     znamespace.__init__cCt|||S)z[method that returns a (sorted) list of names in a namespace that match a given node)sortedr")r6rrr r r namessznamespace.namescCr`)z]method that returns a list of nodes in a namespace that match a given name. )rar!)r6rrr r r nodessznamespace.nodescsN|||}|r%t|dkr!|jtfdd|D}|S|dSdS)zreturns the best node for the given name By default, the best node is the node from nodes() with the highest revision number. It can be overriden by the namespace.rc3s|]}|VqdSr)rev)r$rclr r sz'namespace.singlenode..rN)r!len changelogmaxr)r6rrr&maxrevr rer rRs   znamespace.singlenode) NNNNNNNNFN)rVrWrXrYrArbrcrRr r r r r4s  > r4N) __future__ri18nrrrrrr objectr r4r r r r s  l