diff options
author | Russell Belfer <rb@github.com> | 2013-03-16 03:39:00 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-03-16 03:39:00 +0400 |
commit | 5540d9477ed143707435324e785336d254b12e47 (patch) | |
tree | 4ffaba1990a82cc51ee5169d7d2913ecceef4df2 /src/fileops.h | |
parent | a5f6138407efb6d8866fe8de5aac13454aefcd82 (diff) |
Implement global/system file search paths
The goal of this work is to expose the search logic for "global",
"system", and "xdg" files through the git_libgit2_opts() interface.
Behind the scenes, I changed the logic for finding files to have a
notion of a git_strarray that represents a search path and to store
a separate search path for each of the three tiers of config file.
For each tier, I implemented a function to initialize it to default
values (generally based on environment variables), and then general
interfaces to get it, set it, reset it, and prepend new directories
to it.
Next, I exposed these interfaces through the git_libgit2_opts
interface, reusing the GIT_CONFIG_LEVEL_SYSTEM, etc., constants
for the user to control which search path they were modifying.
There are alternative designs for the opts interface / argument
ordering, so I'm putting this phase out for discussion.
Additionally, I ended up doing a little bit of clean up regarding
attr.h and attr_file.h, adding a new attrcache.h so the other two
files wouldn't have to be included in so many places.
Diffstat (limited to 'src/fileops.h')
-rw-r--r-- | src/fileops.h | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/src/fileops.h b/src/fileops.h index 7ba99d3d9..57ab91837 100644 --- a/src/fileops.h +++ b/src/fileops.h @@ -276,25 +276,55 @@ extern void git_futils_mmap_free(git_map *map); * * @param pathbuf buffer to write the full path into * @param filename name of file to find in the home directory - * @return - * - 0 if found; - * - GIT_ENOTFOUND if not found; - * - -1 on an unspecified OS related error. + * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error */ extern int git_futils_find_global_file(git_buf *path, const char *filename); /** + * Find an "XDG" file (i.e. one in user's XDG config path). + * + * @param pathbuf buffer to write the full path into + * @param filename name of file to find in the home directory + * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error + */ +extern int git_futils_find_xdg_file(git_buf *path, const char *filename); + +/** * Find a "system" file (i.e. one shared for all users of the system). * * @param pathbuf buffer to write the full path into * @param filename name of file to find in the home directory - * @return - * - 0 if found; - * - GIT_ENOTFOUND if not found; - * - -1 on an unspecified OS related error. + * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error */ extern int git_futils_find_system_file(git_buf *path, const char *filename); +typedef enum { + GIT_FUTILS_DIR_SYSTEM = 0, + GIT_FUTILS_DIR_GLOBAL = 1, + GIT_FUTILS_DIR_XDG = 2, + GIT_FUTILS_DIR__MAX = 3, +} git_futils_dir_t; + +/** + * Get the strarray of search paths for global/system files + * + * @param out git_strarray of search paths + * @param which which list of paths to return + * @return 0 on success, <0 on failure (allocation error) + */ +extern int git_futils_dirs_get( + const git_strarray **out, git_futils_dir_t which); + +/** + * Set or prepend strarray of search paths for global/system files + * + * @param which which list of paths to modify + * @param dirs new list of search paths + * @param replace true to replace old, false to prepend to old + * @return 0 on success, <0 on failure (allocation error) + */ +extern int git_futils_dirs_set( + git_futils_dir_t which, const git_strarray *dirs, bool replace); /** * Create a "fake" symlink (text file containing the target path). |