diff options
author | Edward Thomson <ethomson@microsoft.com> | 2013-10-10 02:26:42 +0400 |
---|---|---|
committer | Edward Thomson <ethomson@microsoft.com> | 2013-10-17 00:20:24 +0400 |
commit | c929d6b727cb35a681152ae2c7d6dfbaf971f829 (patch) | |
tree | e45734363923b2dbb240a93a027fe2abf6fa8db3 /src/path.h | |
parent | 7fa73de16378ecfa484747d1b61656282923a88a (diff) |
Move path prefixed help to path.h
Diffstat (limited to 'src/path.h')
-rw-r--r-- | src/path.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/path.h b/src/path.h index eaf94d486..17f4f7726 100644 --- a/src/path.h +++ b/src/path.h @@ -358,6 +358,34 @@ extern int git_path_dirload_with_stat( const char *end_stat, git_vector *contents); +enum { GIT_PATH_NOTEQUAL = 0, GIT_PATH_EQUAL = 1, GIT_PATH_PREFIX = 2 }; + +/* + * Determines if a path is equal to or potentially a child of another. + * @param parent The possible parent + * @param child The possible child + */ +GIT_INLINE(int) git_path_equal_or_prefixed( + const char *parent, + const char *child) +{ + const char *p = parent, *c = child; + + while (*p && *c) { + if (*p++ != *c++) + return GIT_PATH_NOTEQUAL; + } + + if (*p != '\0') + return GIT_PATH_NOTEQUAL; + if (*c == '\0') + return GIT_PATH_EQUAL; + if (*c == '/') + return GIT_PATH_PREFIX; + + return GIT_PATH_NOTEQUAL; +} + /* translate errno to libgit2 error code and set error message */ extern int git_path_set_error( int errno_value, const char *path, const char *action); |