summaryrefslogtreecommitdiff
path: root/src/path.h
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-07-10 15:13:30 -0700
committerRussell Belfer <rb@github.com>2012-07-10 23:19:47 -0700
commitb0fe11292219f5d63f2159e0b0eb24ff21d66b10 (patch)
tree62a8d4e86fbd701152d65c42eda86bd14fdfdada /src/path.h
parent039fc4067989a14a09784ed16ce7126ac75461cb (diff)
downloadlibgit2-b0fe11292219f5d63f2159e0b0eb24ff21d66b10.tar.gz
Add path utilities to resolve relative paths
This makes it easy to take a buffer containing a path with relative references (i.e. .. or . path segments) and resolve all of those into a clean path. This can be applied to URLs as well as file paths which can be useful. As part of this, I made the drive-letter detection apply on all platforms, not just windows. If you give a path that looks like "c:/..." on any platform, it seems like we might as well detect that as a rooted path. I suppose if you create a directory named "x:" on another platform and want to use that as the beginning of a relative path under the root directory of your repo, this could cause a problem, but then it seems like you're asking for trouble.
Diffstat (limited to 'src/path.h')
-rw-r--r--src/path.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/path.h b/src/path.h
index fd76805e5..d68393b3d 100644
--- a/src/path.h
+++ b/src/path.h
@@ -186,6 +186,29 @@ extern int git_path_prettify_dir(git_buf *path_out, const char *path, const char
extern int git_path_find_dir(git_buf *dir, const char *path, const char *base);
/**
+ * Resolve relative references within a path.
+ *
+ * This eliminates "./" and "../" relative references inside a path,
+ * as well as condensing multiple slashes into single ones. It will
+ * not touch the path before the "ceiling" length.
+ *
+ * Additionally, this will recognize an "c:/" drive prefix or a "xyz://" URL
+ * prefix and not touch that part of the path.
+ */
+extern int git_path_resolve_relative(git_buf *path, size_t ceiling);
+
+/**
+ * Apply a relative path to base path.
+ *
+ * Note that the base path could be a filename or a URL and this
+ * should still work. The relative path is walked segment by segment
+ * with three rules: series of slashes will be condensed to a single
+ * slash, "." will be eaten with no change, and ".." will remove a
+ * segment from the base path.
+ */
+extern int git_path_apply_relative(git_buf *target, const char *relpath);
+
+/**
* Walk each directory entry, except '.' and '..', calling fn(state).
*
* @param pathbuf buffer the function reads the initial directory