Thread (17 messages) flat view 17 messages, 6 authors, 2016-06-15

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

From: Johannes Sixt <hidden>
Date: 2016-06-15 22:58:43

Possibly related (same subject, not in this thread)

Am 11.09.2013 05:19, schrieb Jiang Xin:
quoted hunk ↗ jump to hunk
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

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help