Re: [PATCH 7/7] t0000: verify that real_path() removes extra slashes

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH 7/7] t0000: verify that real_path() removes extra slashes

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:54:38

Nguyen Thai Ngoc Duy [off-list ref] writes:
quoted hunk
Just an idea. We could unify "[a-z]:" and "//host" into "dos root"
concept. That would teach other code paths about UNC paths too.
...
diff --git a/path.c b/path.c
index 66acd24..0e4e2d7 100644
--- a/path.c
+++ b/path.c
@@ -498,11 +498,12 @@ const char *relative_path(const char *abs, const char *base)
 int normalize_path_copy(char *dst, const char *src)
 {
 	char *dst0;
+	int i, len;
 
-	if (has_dos_drive_prefix(src)) {
+	len = offset_1st_component(src, 1);
+	for (i = 0; i < len; i++)
 		*dst++ = *src++;
-		*dst++ = *src++;
-	}
+
 	dst0 = dst;
Modulo that I suspect you could get rid of offset_1st_component()
altogether and has_dos_drive_prefix() return the length of the "d:"
or "//d" part (which needs to be copied literally regardless of the
"normalization"), what you suggest feels like the right approach.
Why do you need the "keep_root" parameter and do things differently
depending on the setting by the way?  Wouldn't "skip the root level
when computing the offset of the first path component" something the
caller can easily decide to do or not to do, and wouldn't it make
the semantics of the function cleaner and simpler by making it do
only one thing and one thing well?

Re: Re: [PATCH 7/7] t0000: verify that real_path() removes extra slashes

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:54:39

On Fri, Sep 7, 2012 at 12:34 AM, Junio C Hamano [off-list ref] wrote:
Modulo that I suspect you could get rid of offset_1st_component()
altogether and has_dos_drive_prefix() return the length of the "d:"
or "//d" part (which needs to be copied literally regardless of the
"normalization"), what you suggest feels like the right approach.
Why do you need the "keep_root" parameter and do things differently
depending on the setting by the way?
That's how offset_1st_component() originally works, root slash if
present is counted.
Wouldn't "skip the root level
when computing the offset of the first path component" something the
caller can easily decide to do or not to do, and wouldn't it make
the semantics of the function cleaner and simpler by making it do
only one thing and one thing well?
Yeah. I'll have a closer look later and see if we can simplify the function.
-- 
Duy

-- 
*** 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help