[PATCH] Allow using UNC path for git repository

78 views
Skip to first unread message

Erik Faye-Lund

unread,
Jul 13, 2010, 10:17:43 AM7/13/10
to msy...@googlegroups.com, Cezary Zawadka, Erik Faye-Lund
From: Cezary Zawadka <czaw...@gmail.com>

Signed-off-by: Cezary Zawadka <czaw...@gmail.com>
Signed-off-by: Erik Faye-Lund <kusm...@gmail.com>
---

Since Cezary's work on this seems to have stalled, I'm resending a touched
up version. I've done essentially what Dscho suggested.

I added Cezary's Sign-Off, because he promised it for the next round in
this thread, but I don't know how kosher that is:
http://groups.google.com/group/msysgit/browse_thread/thread/d974fbb5bbf8a25

compat/mingw.c | 23 +++++++++++++++++++++++
compat/mingw.h | 2 ++
git-compat-util.h | 4 ++++
path.c | 7 -------
4 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index 4a83c61..861d3da 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1744,3 +1744,26 @@ const char *get_windows_home_directory()

return home_directory;
}
+
+int mingw_offset_1st_component(const char *path)
+{
+ if (has_dos_drive_prefix(path))
+ return 2 + is_dir_sep(path[2]);
+
+ /* unc paths */
+ if (is_dir_sep(path[0]) && is_dir_sep(path[1])) {
+
+ /* skip server name */
+ char *pos = strpbrk(path + 2, "\\/");
+ if (!pos)
+ return 0;
+
+ do {
+ pos++;
+ } while (*pos && !is_dir_sep(*pos));
+
+ return pos - path;
+ }
+
+ return is_dir_sep(path[0]);
+}
diff --git a/compat/mingw.h b/compat/mingw.h
index 8104039..dbb179c 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -270,6 +270,8 @@ int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format

#define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':')
#define is_dir_sep(c) ((c) == '/' || (c) == '\\')
+int mingw_offset_1st_component(const char *path);
+#define offset_1st_component mingw_offset_1st_component
#define PATH_SEP ';'
#define PRIuMAX "I64u"

diff --git a/git-compat-util.h b/git-compat-util.h
index 1df461f..8239679 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -179,6 +179,10 @@ extern char *gitbasename(char *);
#define has_dos_drive_prefix(path) 0
#endif

+#ifndef offset_1st_component
+#define offset_1st_component(path) (is_dir_sep((path)[0]))
+#endif
+
#ifndef is_dir_sep
#define is_dir_sep(c) ((c) == '/')
#endif
diff --git a/path.c b/path.c
index 21f20ae..a121fbd 100644
--- a/path.c
+++ b/path.c
@@ -728,10 +728,3 @@ int daemon_avoid_alias(const char *p)
}
}
}
-
-int offset_1st_component(const char *path)
-{
- if (has_dos_drive_prefix(path))
- return 2 + is_dir_sep(path[2]);
- return is_dir_sep(path[0]);
-}
--
1.7.1.msysgit.0.385.g3ed98.dirty

Erik Faye-Lund

unread,
Jul 13, 2010, 10:36:15 AM7/13/10
to msy...@googlegroups.com, Cezary Zawadka, Erik Faye-Lund
On Tue, Jul 13, 2010 at 4:17 PM, Erik Faye-Lund
<kusm...@googlemail.com> wrote:
> From: Cezary Zawadka <czaw...@gmail.com>
>
> Signed-off-by: Cezary Zawadka <czaw...@gmail.com>
> Signed-off-by: Erik Faye-Lund <kusm...@gmail.com>
> ---
>
> Since Cezary's work on this seems to have stalled, I'm resending a touched
> up version. I've done essentially what Dscho suggested.
>
> I added Cezary's Sign-Off, because he promised it for the next round in
> this thread, but I don't know how kosher that is:
> http://groups.google.com/group/msysgit/browse_thread/thread/d974fbb5bbf8a25
>

I forgot to mention that I also updated the patch to handle both \ and
/ as path separators, as Windows (and Git for Windows in general)
supports both.

--
Erik "kusma" Faye-Lund

Eric Sunshine

unread,
Jul 13, 2010, 10:57:18 AM7/13/10
to msy...@googlegroups.com
On 7/13/2010 10:17 AM, Erik Faye-Lund wrote:
> +#ifndef offset_1st_component
> +#define offset_1st_component(path) (is_dir_sep((path)[0]))
> +#endif

For "/foo", computed offset points at "foo".

> + if (has_dos_drive_prefix(path))
> + return 2 + is_dir_sep(path[2]);

For "c:/foo", computed offset points at "foo".

> + /* unc paths */

> + do {
> + pos++;
> + } while (*pos&& !is_dir_sep(*pos));

> + return pos - path;

For "//host/share/foo", computed offset points at "/foo", which is
inconsistent. The return statement probably should be restated as:

return pos - path + is_dir_sep(*pos);

(Cezary's original patch also had this shortcoming.)

-- ES

Johannes Schindelin

unread,
Jul 13, 2010, 11:14:09 AM7/13/10
to Eric Sunshine, msy...@googlegroups.com
Hi,

[re-adding kusmabite to the Cc: list; don't know who else should have been
there, please don't cull the Cc: list again!]

Unfortunately, I already committed and pushed, after verifying that it
does not break the test suite.

Care to make a patch and verify that it still works in the intended
use-case?

Ciao,
Johannes

Eric Sunshine

unread,
Jul 13, 2010, 11:59:31 AM7/13/10
to Johannes Schindelin, msy...@googlegroups.com, Erik Faye-Lund
On 7/13/2010 11:14 AM, Johannes Schindelin wrote:
> [re-adding kusmabite to the Cc: list; don't know who else should have been
> there, please don't cull the Cc: list again!]

Bitten by Thunderbird 3.0's "smart" Reply List button.

> On Tue, 13 Jul 2010, Eric Sunshine wrote:
>> For "//host/share/foo", computed offset points at "/foo", which is
>> inconsistent. The return statement probably should be restated as:
>> return pos - path + is_dir_sep(*pos);
>> (Cezary's original patch also had this shortcoming.)
> Unfortunately, I already committed and pushed, after verifying that it
> does not break the test suite.
> Care to make a patch and verify that it still works in the intended
> use-case?

Will do.

-- ES

Erik Faye-Lund

unread,
Jul 13, 2010, 12:02:37 PM7/13/10
to Eric Sunshine, Johannes Schindelin, msy...@googlegroups.com
On Tue, Jul 13, 2010 at 5:59 PM, Eric Sunshine <ericsu...@gmail.com> wrote:
> On 7/13/2010 11:14 AM, Johannes Schindelin wrote:
>>
>> [re-adding kusmabite to the Cc: list; don't know who else should have been
>> there, please don't cull the Cc: list again!]
>
> Bitten by Thunderbird 3.0's "smart" Reply List button.
>
>> On Tue, 13 Jul 2010, Eric Sunshine wrote:
>>>
>>> For "//host/share/foo", computed offset points at "/foo", which is
>>> inconsistent. The return statement probably should be restated as:
>>>     return pos - path + is_dir_sep(*pos);
>>> (Cezary's original patch also had this shortcoming.)
>>
>> Unfortunately, I already committed and pushed, after verifying that it
>> does not break the test suite.

Did you really? I can't find it; it's not where I'd expect it
(http://repo.or.cz/w/git/mingw/4msysgit.git/shortlog/refs/heads/devel).
Is there somewhere else you're pushing stuff out?

If you forgot to push, perhaps you could squash in a small fix?

--
Erik "kusma" Faye-Lund

Johannes Schindelin

unread,
Jul 13, 2010, 12:13:01 PM7/13/10
to kusm...@gmail.com, Eric Sunshine, msy...@googlegroups.com
Hi,

Oops... I just realized that I pushed to my personal repo, and pushed to
4msysgit now.

Anyway, we can squash in any fixes with the next rebasing-merge.

Ciao,
Dscho

Eric Sunshine

unread,
Jul 13, 2010, 12:39:47 PM7/13/10
to Johannes Schindelin, msy...@googlegroups.com, Erik Faye-Lund

Cezary Zawadka

unread,
Jul 13, 2010, 5:16:55 PM7/13/10
to kusm...@gmail.com, msy...@googlegroups.com
thanks guys, I forgot about these things :)

czarek

Reply all
Reply to author
Forward
0 new messages