mirror of
https://git.proxmox.com/git/libgit2
synced 2025-07-27 07:30:34 +00:00
path: Teach UNC paths to git_path_dirname_r()
Fix libgit2/libgit2sharp#256
This commit is contained in:
parent
34b6f05f39
commit
50a762a563
25
src/path.c
25
src/path.c
@ -19,6 +19,22 @@
|
|||||||
|
|
||||||
#define LOOKS_LIKE_DRIVE_PREFIX(S) (git__isalpha((S)[0]) && (S)[1] == ':')
|
#define LOOKS_LIKE_DRIVE_PREFIX(S) (git__isalpha((S)[0]) && (S)[1] == ':')
|
||||||
|
|
||||||
|
static bool looks_like_network_computer_name(const char *path, int pos)
|
||||||
|
{
|
||||||
|
if (pos < 3)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (path[0] != '/' || path[1] != '/')
|
||||||
|
return false;
|
||||||
|
|
||||||
|
while (pos-- > 2) {
|
||||||
|
if (path[pos] == '/')
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Based on the Android implementation, BSD licensed.
|
* Based on the Android implementation, BSD licensed.
|
||||||
* Check http://android.git.kernel.org/
|
* Check http://android.git.kernel.org/
|
||||||
@ -111,6 +127,15 @@ int git_path_dirname_r(git_buf *buffer, const char *path)
|
|||||||
len = 3;
|
len = 3;
|
||||||
goto Exit;
|
goto Exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Similarly checks if we're dealing with a network computer name
|
||||||
|
'//computername/.git' will return '//computername/' */
|
||||||
|
|
||||||
|
if (looks_like_network_computer_name(path, len)) {
|
||||||
|
len++;
|
||||||
|
goto Exit;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Exit:
|
Exit:
|
||||||
|
@ -91,6 +91,10 @@ void test_core_path__00_dirname(void)
|
|||||||
#ifdef GIT_WIN32
|
#ifdef GIT_WIN32
|
||||||
check_dirname("C:/path/", "C:/");
|
check_dirname("C:/path/", "C:/");
|
||||||
check_dirname("C:/path", "C:/");
|
check_dirname("C:/path", "C:/");
|
||||||
|
check_dirname("//computername/path/", "//computername/");
|
||||||
|
check_dirname("//computername/path", "//computername/");
|
||||||
|
check_dirname("//computername/sub/path/", "//computername/sub");
|
||||||
|
check_dirname("//computername/sub/path", "//computername/sub");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user