coreutils
[Top][All Lists]
Advanced

[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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]