diff options
author | Vicent Marti <vicent@github.com> | 2014-09-17 15:39:57 +0200 |
---|---|---|
committer | Vicent Marti <vicent@github.com> | 2014-09-17 15:39:57 +0200 |
commit | 276d9ea3a664b1c1a75a72a05744fd7fc078538e (patch) | |
tree | ae900f0dbde48f21a95482af14e2f2af851730e5 /src/path.c | |
parent | 5c22c4a20519b066e00a25b57c2266e829d905a5 (diff) | |
parent | 74240afb9c3394d35dfb3fe59dc38dbff70c0368 (diff) | |
download | libgit2-276d9ea3a664b1c1a75a72a05744fd7fc078538e.tar.gz |
Merge pull request #2571 from libgit2/vmg/walk-up-path
Fix `git_path_walk_up` to work with non-rooted paths
Diffstat (limited to 'src/path.c')
-rw-r--r-- | src/path.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/path.c b/src/path.c index 11c022812..67133f97e 100644 --- a/src/path.c +++ b/src/path.c @@ -417,7 +417,7 @@ int git_path_fromurl(git_buf *local_path_out, const char *file_url) int git_path_walk_up( git_buf *path, const char *ceiling, - int (*cb)(void *data, git_buf *), + int (*cb)(void *data, const char *), void *data) { int error = 0; @@ -435,12 +435,20 @@ int git_path_walk_up( } scan = git_buf_len(path); + /* empty path: yield only once */ + if (!scan) { + error = cb(data, ""); + if (error) + giterr_set_after_callback(error); + return error; + } + iter.ptr = path->ptr; iter.size = git_buf_len(path); iter.asize = path->asize; while (scan >= stop) { - error = cb(data, &iter); + error = cb(data, iter.ptr); iter.ptr[scan] = oldc; if (error) { @@ -460,6 +468,13 @@ int git_path_walk_up( if (scan >= 0) iter.ptr[scan] = oldc; + /* relative path: yield for the last component */ + if (!error && stop == 0 && iter.ptr[0] != '/') { + error = cb(data, ""); + if (error) + giterr_set_after_callback(error); + } + return error; } |