diff options
author | Russell Belfer <rb@github.com> | 2012-08-01 04:02:54 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-08-23 03:07:19 +0400 |
commit | ca1b6e54095a7e28d468a832f143025feae6cd4f (patch) | |
tree | 0ff9b9fbf71cd4f0489985b64f57590687361cd2 /src/path.c | |
parent | 662880ca60e4d1662bb10648522242ac54797720 (diff) |
Add template dir and set gid to repo init
This extends git_repository_init_ext further with support for
initializing the repository from an external template directory
and with support for the "create shared" type flags that make a
set GID repository directory.
This also adds tests for much of the new functionality to the
existing `repo/init.c` test suite.
Also, this adds a bunch of new utility functions including a
very general purpose `git_futils_mkdir` (with the ability to
make paths and to chmod the paths post-creation) and a file
tree copying function `git_futils_cp_r`. Also, this includes
some new path functions that were useful to keep the code
simple.
Diffstat (limited to 'src/path.c')
-rw-r--r-- | src/path.c | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/src/path.c b/src/path.c index 22391c52b..15188850d 100644 --- a/src/path.c +++ b/src/path.c @@ -147,6 +147,20 @@ char *git_path_basename(const char *path) return basename; } +size_t git_path_basename_offset(git_buf *buffer) +{ + ssize_t slash; + + if (!buffer || buffer->size <= 0) + return 0; + + slash = git_buf_rfind_next(buffer, '/'); + + if (slash >= 0 && buffer->ptr[slash] == '/') + return (size_t)(slash + 1); + + return 0; +} const char *git_path_topdir(const char *path) { @@ -193,6 +207,31 @@ int git_path_root(const char *path) return -1; /* Not a real error - signals that path is not rooted */ } +int git_path_join_unrooted( + git_buf *path_out, const char *path, const char *base, ssize_t *root_at) +{ + int error, root; + + assert(path && path_out); + + root = git_path_root(path); + + if (base != NULL && root < 0) { + error = git_buf_joinpath(path_out, base, path); + + if (root_at) + *root_at = (ssize_t)strlen(base); + } + else { + error = git_buf_sets(path_out, path); + + if (root_at) + *root_at = (root < 0) ? 0 : (ssize_t)root; + } + + return error; +} + int git_path_prettify(git_buf *path_out, const char *path, const char *base) { char buf[GIT_PATH_MAX]; @@ -502,12 +541,7 @@ bool git_path_contains_file(git_buf *base, const char *file) int git_path_find_dir(git_buf *dir, const char *path, const char *base) { - int error; - - if (base != NULL && git_path_root(path) < 0) - error = git_buf_joinpath(dir, base, path); - else - error = git_buf_sets(dir, path); + int error = git_path_join_unrooted(dir, path, base, NULL); if (!error) { char buf[GIT_PATH_MAX]; |