[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 4/6] realpath: let --relative-to default to --relative-base
From: |
Pádraig Brady |
Subject: |
Re: [PATCH 4/6] realpath: let --relative-to default to --relative-base |
Date: |
Wed, 14 Mar 2012 21:38:25 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20110816 Thunderbird/6.0 |
On 03/14/2012 08:38 PM, Eric Blake wrote:
> Most of the time, if someone wants to filter which paths are
> relative while leaving all others absolute, they also want to
> to the filtering based on the same --relative-to directory.
> Make this easier to specify.
> --- a/src/realpath.c
> +++ b/src/realpath.c
> @@ -331,10 +331,7 @@ main (int argc, char **argv)
> }
>
> if (relative_base && !relative_to)
> - {
> - error (0, 0, _("--relative-base requires --relative-to"));
> - usage (EXIT_FAILURE);
> - }
> + relative_to = relative_base;
I wonder is it worth short circuiting some later code
when relative_to == relative_base, like:
diff --git a/src/realpath.c b/src/realpath.c
index 7834c62..c3f5809 100644
--- a/src/realpath.c
+++ b/src/realpath.c
@@ -183,7 +183,8 @@ relpath (const char *can_fname)
if (can_relative_base)
{
if (!path_prefix (can_relative_base, can_fname)
- || !path_prefix (can_relative_base, can_relative_to))
+ || ((can_relative_base != can_relative_to)
+ && !path_prefix (can_relative_base, can_relative_to)))
return false;
}
@@ -345,7 +346,9 @@ main (int argc, char **argv)
if (need_dir && !isdir (can_relative_to))
error (EXIT_FAILURE, ENOTDIR, "%s", quote (relative_to));
}
- if (relative_base)
+ if (relative_base == relative_to)
+ can_relative_base = can_relative_to;
+ else if (relative_base)
{
can_relative_base = realpath_canon (relative_base, can_mode);
if (!can_relative_base)
cheers,
Pádraig.
- [PATCH 0/6] realpath cleanups, Eric Blake, 2012/03/14
- [PATCH 5/6] doc: clarify current realpath --relative-base behavior, Eric Blake, 2012/03/14
- [PATCH 2/6] realpath: fix problems with root handling, Eric Blake, 2012/03/14
- [PATCH 6/6] realpath: let --relative-base work even as child of --relative-to, Eric Blake, 2012/03/14
- [PATCH 1/6] test: expose recent gnulib canonicalize bug, Eric Blake, 2012/03/14
- [PATCH 4/6] realpath: let --relative-to default to --relative-base, Eric Blake, 2012/03/14
- Re: [PATCH 4/6] realpath: let --relative-to default to --relative-base,
Pádraig Brady <=
- [PATCH 3/6] tests: cover more realpath scenarios, Eric Blake, 2012/03/14
- Re: [PATCH 0/6] realpath cleanups, Pádraig Brady, 2012/03/14