vendor/libgit2/src/path.h in rugged-0.21.4 vs vendor/libgit2/src/path.h in rugged-0.22.0b1

- old
+ new

@@ -126,10 +126,18 @@ GIT_INLINE(int) git_path_is_relative(const char *p) { return (p[0] == '.' && (p[1] == '/' || (p[1] == '.' && p[2] == '/'))); } +/** + * Check if string is at end of path segment (i.e. looking at '/' or '\0') + */ +GIT_INLINE(int) git_path_at_end_of_segment(const char *p) +{ + return !*p || *p == '/'; +} + extern int git__percent_decode(git_buf *decoded_out, const char *input); /** * Extract path from file:// URL. */ @@ -187,10 +195,21 @@ * @return true if subdirectory exists, false otherwise. */ extern bool git_path_contains_dir(git_buf *parent, const char *subdir); /** + * Make the path relative to the given parent path. + * + * @param path The path to make relative + * @param parent The parent path to make path relative to + * @return 0 if path was made relative, GIT_ENOTFOUND + * if there was not common root between the paths, + * or <0. + */ +extern int git_path_make_relative(git_buf *path, const char *parent); + +/** * Check if the given path contains the given file. * * @param dir Directory path that might contain file * @param file File name to look for in parent * @return true if file exists, false otherwise. @@ -302,11 +321,11 @@ * @param state Passed to fn as the first ath. */ extern int git_path_walk_up( git_buf *pathbuf, const char *ceiling, - int (*callback)(void *payload, git_buf *path), + int (*callback)(void *payload, const char *path), void *payload); /** * Load all directory entries (except '.' and '..') into a vector. * @@ -438,51 +457,9 @@ #endif /* GIT_USE_ICONV */ extern bool git_path_does_fs_decompose_unicode(const char *root); /* Used for paths to repositories on the filesystem */ +extern bool git_path_is_local_file_url(const char *file_url); extern int git_path_from_url_or_path(git_buf *local_path_out, const char *url_or_path); - -/* Flags to determine path validity in `git_path_isvalid` */ -#define GIT_PATH_REJECT_TRAVERSAL (1 << 0) -#define GIT_PATH_REJECT_DOT_GIT (1 << 1) -#define GIT_PATH_REJECT_SLASH (1 << 2) -#define GIT_PATH_REJECT_BACKSLASH (1 << 3) -#define GIT_PATH_REJECT_TRAILING_DOT (1 << 4) -#define GIT_PATH_REJECT_TRAILING_SPACE (1 << 5) -#define GIT_PATH_REJECT_TRAILING_COLON (1 << 6) -#define GIT_PATH_REJECT_DOS_PATHS (1 << 7) -#define GIT_PATH_REJECT_NT_CHARS (1 << 8) -#define GIT_PATH_REJECT_DOT_GIT_HFS (1 << 9) -#define GIT_PATH_REJECT_DOT_GIT_NTFS (1 << 10) - -/* Default path safety for writing files to disk: since we use the - * Win32 "File Namespace" APIs ("\\?\") we need to protect from - * paths that the normal Win32 APIs would not write. - */ -#ifdef GIT_WIN32 -# define GIT_PATH_REJECT_DEFAULTS \ - GIT_PATH_REJECT_TRAVERSAL | \ - GIT_PATH_REJECT_BACKSLASH | \ - GIT_PATH_REJECT_TRAILING_DOT | \ - GIT_PATH_REJECT_TRAILING_SPACE | \ - GIT_PATH_REJECT_TRAILING_COLON | \ - GIT_PATH_REJECT_DOS_PATHS | \ - GIT_PATH_REJECT_NT_CHARS -#else -# define GIT_PATH_REJECT_DEFAULTS GIT_PATH_REJECT_TRAVERSAL -#endif - -/* - * Determine whether a path is a valid git path or not - this must not contain - * a '.' or '..' component, or a component that is ".git" (in any case). - * - * `repo` is optional. If specified, it will be used to determine the short - * path name to reject (if `GIT_PATH_REJECT_DOS_SHORTNAME` is specified), - * in addition to the default of "git~1". - */ -extern bool git_path_isvalid( - git_repository *repo, - const char *path, - unsigned int flags); #endif