[PATCH hglib] client: add pathto helper (issue4510)

Yuya Nishihara yuya at tcha.org
Fri Apr 8 10:15:40 EDT 2016


On Wed, 06 Apr 2016 15:51:14 +0200, Axel Hecht wrote:
> # HG changeset patch
> # User Axel Hecht <axel at pike.org>
> # Date 1432910925 -7200
> #      Fri May 29 16:48:45 2015 +0200
> # Node ID 0850d9353245231ad335d89b9753b42cca933e33
> # Parent  98efa416f763d5f408244baeaf6ab5e2fc4fd756
> client: add pathto helper (issue4510)
> 
> Reimplement what localrepo.pathto does via util.pathto for hglib.
> 
> diff --git a/hglib/client.py b/hglib/client.py
> --- a/hglib/client.py
> +++ b/hglib/client.py
> @@ -1164,6 +1164,18 @@
>  
>          return self._parserevs(out)
>  
> +    def pathto(self, f, cwd=b('.')):
> +        """
> +        Return relative path to f. If cwd is given, use it as current
> +        working directory.
> +        The returned path uses os.sep as separator.
> +
> +        f - file path with / as separator
> +        cwd - working directory with os.sep as separator
> +        """
> +        return os.path.relpath(os.path.join(self.root(), *(f.split(b('/')))),
> +                               start=cwd)

If this is intended to be a 100% copy of localrepo.pathto(), "cwd" should be
relative to root, not relative to cwd.

Other than that, this patch seems fine.


More information about the Mercurial-devel mailing list