Re: Regression in e02ca72: git svn rebase is broken on Windows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 11.09.2013 05:19, schrieb Jiang Xin:
> I tested 'relative_path' function using 'test-path-utils', and got the
> following result:
> 
>     $ ./test-path-utils relative_path 'C:/a/b' 'D:/x/y'
>     ../../../C:/a/b
> 
>     $ ./test-path-utils relative_path '/a/b' 'x/y'
>     ../..//a/b
> 
>     $ ./test-path-utils relative_path 'a/b' '/x/y'
>     ../../../a/b
> 
> For the first case, in and prefix are on different ROOT, and for the other
> two cases, one path is a relative path, and another is an absolute path.
> 
> I write a patch to test whether two paths (in and prefix) have the same
> root. The result after applied the patch:
> 
>     $ ./test-path-utils relative_path 'C:/a/b' 'C:/x/y'
>     ../../a/b
> 
>     $ ./test-path-utils relative_path 'C:/a/b' 'D:/x/y'
>     C:/a/b
> 
>     $ ./test-path-utils relative_path '/a/b' 'x/y'
>     /a/b
> 
>     $ ./test-path-utils relative_path 'a/b' '/x/y'
>     a/b
> 
> 
> diff --git a/path.c b/path.c
> index 7f3324a..51f5d28 100644
> --- a/path.c
> +++ b/path.c
> @@ -441,6 +441,25 @@ int adjust_shared_perm(const char *path)
>         return 0;
>  }
> 
> +static int have_same_root(const char *path1, const char *path2)
> +{
> +       /* for POSIX:
> +
> +          return ((path1 && is_dir_sep(*path1)) ^
> +                  (path2 && is_dir_sep(*path2))) == 0;
> +       */
> +       return path1 && path2 && *path1 && *path2 && (
> +               (is_dir_sep(*path1) &&
> +                is_dir_sep(*path2)) ||
> +               (*(path1+1) == ':' &&
> +                *(path2+1) == ':' &&
> +                !strncasecmp(path1, path2, 1)) ||
> +               (!is_dir_sep(*path1) &&
> +                !is_dir_sep(*path2) &&
> +                *(path1+1) != ':' &&
> +                *(path2+1) != ':'));

I think this can be simplified to

	return path1 && path2 &&
		is_absolute_path(path1) &&
		is_absolute_path(path2) &&
		!strncasecmp(path1, path2, 1);

which would not mistake a path D:/foo on Unix as an absolute path.

> +}

-- Hannes

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]