[PATCH 1 of 3] paths: make getpath() accept multiple defaults

Gregory Szorc gregory.szorc at gmail.com
Sat Dec 26 11:39:31 CST 2015



> On Dec 26, 2015, at 05:06, Yuya Nishihara <yuya at tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya at tcha.org>
> # Date 1451113839 -32400
> #      Sat Dec 26 16:10:39 2015 +0900
> # Node ID 38c6d17c94e16ed63f532730cb2992eb86dd9e6a
> # Parent  e2aa9c4030c4109e5efa50462ffc6048ca30106f
> paths: make getpath() accept multiple defaults

This series looks sensible to me and is much simpler than what I was brainstorming.

Thank you for cleaning up my mess.

> 
> This is necessary to handle "default-push" and "default" as fallback items.
> We can't apply the same rule as "default:pushurl" because "default-push" is
> a valid named path.
> 
> This series is for default branch. I have a simpler patch for stable.
> 
> diff --git a/mercurial/ui.py b/mercurial/ui.py
> --- a/mercurial/ui.py
> +++ b/mercurial/ui.py
> @@ -1115,7 +1115,7 @@ class paths(dict):
>             self['default'].pushloc = defaultpush
> 
>     def getpath(self, name, default=None):
> -        """Return a ``path`` from a string, falling back to a default.
> +        """Return a ``path`` from a string, falling back to default.
> 
>         ``name`` can be a named path or locations. Locations are filesystem
>         paths or URIs.
> @@ -1125,13 +1125,16 @@ class paths(dict):
>         """
>         # Only fall back to default if no path was requested.
>         if name is None:
> -            if default:
> +            if not default:
> +                default = ()
> +            elif not isinstance(default, (tuple, list)):
> +                default = (default,)
> +            for k in default:
>                 try:
> -                    return self[default]
> +                    return self[k]
>                 except KeyError:
> -                    return None
> -            else:
> -                return None
> +                    continue
> +            return None
> 
>         # Most likely empty string.
>         # This may need to raise in the future.
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list