[PATCH 4 of 9 RFC] localrepo: add a method to return markers in a namespace
David Soria Parra
davidsp at fb.com
Mon Mar 31 12:41:09 CDT 2014
Sean Farley <sean.michael.farley at gmail.com> writes:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley at gmail.com>
> # Date 1396218396 18000
> # Sun Mar 30 17:26:36 2014 -0500
> # Node ID 0c5c36fe392d9dfbc56ac466e312a62bdeb2bf93
> # Parent 1bb668ecda482ee83f31d505c2094e6402668931
> localrepo: add a method to return markers in a namespace
>
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -671,10 +671,37 @@ class localrepository(object):
> RFC: should we allow tags and bookmarks to be set this way?
> '''
> self._createmarkernamespace(namespace)
> self._markers[namespace][name] = node
>
> + def markers(self, namespace=None, name=None):
> + '''Return markers in the namespace, otherwise return all markers.
> +
> + If namespace is None, this will return a dictionary of dictionaries.
> +
> + If namespace is passed but name is None, this function will return a
> + dictionary.
> +
> + If both namespace and name are passed, this will return a value.
> +
> + RFC: should this allow namespace=None and name='foo' to find all 'foo'
> + no matter the namespace?
> + '''
> + if namespace is None:
> + # create a read-only copy that adds tags and bookmarks
> + allmarks = self._markers.copy()
> + allmarks["tag"] = self.tags()
> + allmarks["bookmark"] = self._bookmarks
> + return allmarks
> +
> + self._createmarkernamespace(namespace)
> +
> + if name is not None:
> + return self._markers[namespace][name]
> +
> + return self._markers[namespace]
> +
I personally think this is a bit error prone as you can accidentally
have a name = None when passing to markers and then you suddenly get a
dictionary instead of an expected value. I would recommend to only
return self._markers[namespace] so people can use it as
self.markers(namespace).get(name, default).
More information about the Mercurial-devel
mailing list