summaryrefslogtreecommitdiff
path: root/src/path.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-03-18 17:33:46 -0400
committerEdward Thomson <ethomson@github.com>2016-03-24 15:59:48 -0400
commitba6f86eb2e100ad6f39e70bd52d7144df1b43a1a (patch)
tree1c27cf8a021ac4771be8d8d39d6904a5ebe572d8 /src/path.c
parent82a1aab647c9a587e0b8959719a6ea507a68ea31 (diff)
downloadlibgit2-ba6f86eb2e100ad6f39e70bd52d7144df1b43a1a.tar.gz
Introduce `git_path_common_dirlen`
Diffstat (limited to 'src/path.c')
-rw-r--r--src/path.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/path.c b/src/path.c
index 1fd14fcb9..4133985a4 100644
--- a/src/path.c
+++ b/src/path.c
@@ -810,6 +810,20 @@ int git_path_cmp(
return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
}
+size_t git_path_common_dirlen(const char *one, const char *two)
+{
+ const char *p, *q, *dirsep = NULL;
+
+ for (p = one, q = two; *p && *q; p++, q++) {
+ if (*p == '/' && *q == '/')
+ dirsep = p;
+ else if (*p != *q)
+ break;
+ }
+
+ return dirsep ? (dirsep - one) + 1 : 0;
+}
+
int git_path_make_relative(git_buf *path, const char *parent)
{
const char *p, *q, *p_dirsep, *q_dirsep;