commit 324d37e7c791a6e6ff08598c3e6206ba956d0965 from: Stefan Sperling date: Sat May 11 13:14:30 2019 UTC make got path APIs available to library consumers commit - 384417cbfe7fa5168e4ed18dcfd233ddddf94ac4 commit + 324d37e7c791a6e6ff08598c3e6206ba956d0965 blob - /dev/null blob + d79664694d4c2376976a212524c0b51cd08c16a2 (mode 644) --- /dev/null +++ include/got_path.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2018, 2019 Stefan Sperling + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* Utilities for dealing with filesystem paths. */ + +#define GOT_DEFAULT_FILE_MODE (S_IRUSR|S_IWUSR | S_IRGRP | S_IROTH) +#define GOT_DEFAULT_DIR_MODE (S_IRWXU | S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH) + +/* Determine whether a path is an absolute path. */ +int got_path_is_absolute(const char *); + +/* + * Return an absolute version of a relative path. + * The result is allocated with malloc(3). + */ +char *got_path_get_absolute(const char *); + +/* + * Normalize a path for internal processing. + * The result is allocated with malloc(3). + */ +char *got_path_normalize(const char *); + +/* + * Canonicalize absolute paths by removing redundant path separators + * and resolving references to parent directories ("/../"). + * Relative paths are copied from input to buf as-is. + */ +const struct got_error *got_canonpath(const char *, char *, size_t); + +/* + * Get child part of two absolute paths. The second path must equal the first + * path up to some path component, and must be longer than the first path. + * The result is allocated with malloc(3). + */ +const struct got_error *got_path_skip_common_ancestor(char **, const char *, + const char *); + +/* Determine whether a path points to the root directory "/" . */ +int got_path_is_root_dir(const char *); + +/* Determine whether a path is a path-wise child of another path. */ +int got_path_is_child(const char *, const char *, size_t); + +/* + * Like strcmp() but orders children in subdirectories directly after + * their parents. + */ +int got_path_cmp(const char *, const char *); + +/* + * Path lists allow for predictable concurrent iteration over multiple lists + * of paths obtained from disparate sources which don't all provide the same + * ordering guarantees (e.g. git trees, file index, and on-disk directories). + */ +struct got_pathlist_entry { + TAILQ_ENTRY(got_pathlist_entry) entry; + const char *path; + void *data; /* data pointer provided to got_pathlist_insert() */ +}; +TAILQ_HEAD(got_pathlist_head, got_pathlist_entry); + +/* + * Insert a path into the list of paths in a predictable order. + * The caller should already have initialized the list head. This list stores + * the pointer to the path as-is, i.e. the path is not copied internally and + * must remain available until the list is freed with got_pathlist_free(). + * If the first argument is not NULL, set it to a pointer to the newly inserted + * element, or to a NULL pointer in case the path was already on the list. + */ +const struct got_error *got_pathlist_insert(struct got_pathlist_entry **, + struct got_pathlist_head *, const char *, void *); + +/* Free resources allocated for a path list. */ +void got_pathlist_free(struct got_pathlist_head *); + +/* Attempt to create a directory at a given path. */ +const struct got_error *got_path_mkdir(const char *); + +/* dirname(3) with error handling and dynamically allocated result. */ +const struct got_error *got_path_dirname(char **, const char *); blob - 02c170d983d89a460edddc640f4bbe73be8844a3 blob + ebce7f7027aeb718420ab89f7d105782e677c30d --- lib/commit_graph.c +++ lib/commit_graph.c @@ -29,12 +29,12 @@ #include "got_error.h" #include "got_object.h" #include "got_commit_graph.h" +#include "got_path.h" #include "got_lib_delta.h" #include "got_lib_inflate.h" #include "got_lib_object.h" #include "got_lib_object_idset.h" -#include "got_lib_path.h" struct got_commit_graph_node { struct got_object_id id; blob - bb2a5351cc68df9c42b395ae9f5fc993097213b8 blob + dc7337a52c9983c9eef7461efc7e58772347d66f --- lib/deflate.c +++ lib/deflate.c @@ -26,8 +26,8 @@ #include "got_error.h" #include "got_object.h" +#include "got_path.h" -#include "got_lib_path.h" #include "got_lib_deflate.h" #ifndef MIN blob - 730bb4f921b6fb457b977f7f128336551b10e0c1 blob + c4bed1896f0d4b8f8e0c3d1f5b4629b46371abfe --- lib/delta.c +++ lib/delta.c @@ -28,9 +28,9 @@ #include "got_error.h" #include "got_repository.h" #include "got_object.h" +#include "got_path.h" #include "got_lib_delta.h" -#include "got_lib_path.h" #include "got_lib_inflate.h" #include "got_lib_object.h" blob - 8f10487f075939999a42f3ca045ab7ea935aabcc blob + 8563f7894b512bf056774c692ac717124855bc9a --- lib/diff.c +++ lib/diff.c @@ -29,9 +29,9 @@ #include "got_error.h" #include "got_diff.h" #include "got_opentemp.h" +#include "got_path.h" #include "got_lib_diff.h" -#include "got_lib_path.h" #include "got_lib_delta.h" #include "got_lib_inflate.h" #include "got_lib_object.h" blob - 155c46e802fabfc2001a37c6c61e4e9cd9145b8e blob + a30b4cfe7f85f2d82af4af74ce41f45aa9f9c9e2 --- lib/fileindex.c +++ lib/fileindex.c @@ -29,8 +29,8 @@ #include "got_error.h" #include "got_object.h" +#include "got_path.h" -#include "got_lib_path.h" #include "got_lib_fileindex.h" #include "got_lib_worktree.h" blob - d79664694d4c2376976a212524c0b51cd08c16a2 (mode 644) blob + /dev/null --- lib/got_lib_path.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2018, 2019 Stefan Sperling - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* Utilities for dealing with filesystem paths. */ - -#define GOT_DEFAULT_FILE_MODE (S_IRUSR|S_IWUSR | S_IRGRP | S_IROTH) -#define GOT_DEFAULT_DIR_MODE (S_IRWXU | S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH) - -/* Determine whether a path is an absolute path. */ -int got_path_is_absolute(const char *); - -/* - * Return an absolute version of a relative path. - * The result is allocated with malloc(3). - */ -char *got_path_get_absolute(const char *); - -/* - * Normalize a path for internal processing. - * The result is allocated with malloc(3). - */ -char *got_path_normalize(const char *); - -/* - * Canonicalize absolute paths by removing redundant path separators - * and resolving references to parent directories ("/../"). - * Relative paths are copied from input to buf as-is. - */ -const struct got_error *got_canonpath(const char *, char *, size_t); - -/* - * Get child part of two absolute paths. The second path must equal the first - * path up to some path component, and must be longer than the first path. - * The result is allocated with malloc(3). - */ -const struct got_error *got_path_skip_common_ancestor(char **, const char *, - const char *); - -/* Determine whether a path points to the root directory "/" . */ -int got_path_is_root_dir(const char *); - -/* Determine whether a path is a path-wise child of another path. */ -int got_path_is_child(const char *, const char *, size_t); - -/* - * Like strcmp() but orders children in subdirectories directly after - * their parents. - */ -int got_path_cmp(const char *, const char *); - -/* - * Path lists allow for predictable concurrent iteration over multiple lists - * of paths obtained from disparate sources which don't all provide the same - * ordering guarantees (e.g. git trees, file index, and on-disk directories). - */ -struct got_pathlist_entry { - TAILQ_ENTRY(got_pathlist_entry) entry; - const char *path; - void *data; /* data pointer provided to got_pathlist_insert() */ -}; -TAILQ_HEAD(got_pathlist_head, got_pathlist_entry); - -/* - * Insert a path into the list of paths in a predictable order. - * The caller should already have initialized the list head. This list stores - * the pointer to the path as-is, i.e. the path is not copied internally and - * must remain available until the list is freed with got_pathlist_free(). - * If the first argument is not NULL, set it to a pointer to the newly inserted - * element, or to a NULL pointer in case the path was already on the list. - */ -const struct got_error *got_pathlist_insert(struct got_pathlist_entry **, - struct got_pathlist_head *, const char *, void *); - -/* Free resources allocated for a path list. */ -void got_pathlist_free(struct got_pathlist_head *); - -/* Attempt to create a directory at a given path. */ -const struct got_error *got_path_mkdir(const char *); - -/* dirname(3) with error handling and dynamically allocated result. */ -const struct got_error *got_path_dirname(char **, const char *); blob - d5a41ac80b86adcdf3016cddcccfd30b3f49a3ce blob + bd403961e91efebbe3b1c417dae2da911d752c55 --- lib/inflate.c +++ lib/inflate.c @@ -26,8 +26,8 @@ #include "got_error.h" #include "got_object.h" +#include "got_path.h" -#include "got_lib_path.h" #include "got_lib_inflate.h" #ifndef MIN blob - dc493f7e516c34646e567efa01b16692c2a21501 blob + 0426e42d52de29293430223cc643f1687b0f5372 --- lib/lockfile.c +++ lib/lockfile.c @@ -26,9 +26,9 @@ #include #include "got_error.h" +#include "got_path.h" #include "got_lib_lockfile.h" -#include "got_lib_path.h" const struct got_error * got_lockfile_lock(struct got_lockfile **lf, const char *path) blob - a2abc10f3ccc865a84eac6dbce1887f5fdf60a6b blob + 8356628a161963e4861146e9b08423ccb7f8cecb --- lib/object.c +++ lib/object.c @@ -39,10 +39,10 @@ #include "got_object.h" #include "got_repository.h" #include "got_opentemp.h" +#include "got_path.h" #include "got_lib_sha1.h" #include "got_lib_delta.h" -#include "got_lib_path.h" #include "got_lib_inflate.h" #include "got_lib_object.h" #include "got_lib_privsep.h" blob - 6e0d38934875115a92f1d9ea9e6ce822976910f7 blob + a3dbc82a22f6ebf95eaf48fb75437c549011c14d --- lib/object_create.c +++ lib/object_create.c @@ -32,13 +32,13 @@ #include "got_object.h" #include "got_repository.h" #include "got_opentemp.h" +#include "got_path.h" #include "got_lib_sha1.h" #include "got_lib_deflate.h" #include "got_lib_delta.h" #include "got_lib_object.h" #include "got_lib_lockfile.h" -#include "got_lib_path.h" #ifndef nitems #define nitems(_a) (sizeof(_a) / sizeof((_a)[0])) blob - 2f081c6a67da579464a6d640538662e44fa480d9 blob + 8840c627c2b32e58972343d498577b2c050be4f2 --- lib/object_parse.c +++ lib/object_parse.c @@ -39,6 +39,7 @@ #include "got_object.h" #include "got_repository.h" #include "got_opentemp.h" +#include "got_path.h" #include "got_lib_sha1.h" #include "got_lib_delta.h" @@ -48,7 +49,6 @@ #include "got_lib_pack.h" #include "got_lib_privsep.h" #include "got_lib_repository.h" -#include "got_lib_path.h" #ifndef nitems #define nitems(_a) (sizeof(_a) / sizeof((_a)[0])) blob - 5de6375a4acead9c2ad76d03bd677d14c756be17 blob + 11d1e5017d0a95ea7ae5ecf9df6bb025770e1f9d --- lib/pack.c +++ lib/pack.c @@ -35,9 +35,9 @@ #include "got_error.h" #include "got_object.h" #include "got_opentemp.h" +#include "got_path.h" #include "got_lib_sha1.h" -#include "got_lib_path.h" #include "got_lib_delta.h" #include "got_lib_inflate.h" #include "got_lib_object.h" blob - d1223209f4d236906d280ad91c80f5e0992e0c72 blob + 253851ff74356045bae103ab830cc17e3c96fbb8 --- lib/path.c +++ lib/path.c @@ -27,8 +27,7 @@ #include #include "got_error.h" - -#include "got_lib_path.h" +#include "got_path.h" #ifndef MIN #define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b)) blob - 168ef0c6453dfb820f829ead7011fc90b64c5c47 blob + a33e604ced7ec4e337f571bc9f44ca9de3bbd8fb --- lib/reference.c +++ lib/reference.c @@ -35,9 +35,9 @@ #include "got_repository.h" #include "got_reference.h" #include "got_opentemp.h" +#include "got_path.h" #include "got_lib_sha1.h" -#include "got_lib_path.h" #include "got_lib_delta.h" #include "got_lib_inflate.h" #include "got_lib_object.h" blob - ad65519dfb217bedfcc6bfb83c59cc4be503a896 blob + 97763ccc4a03b11ad76e0aa9dd7083d2b46c387f --- lib/repository.c +++ lib/repository.c @@ -40,8 +40,8 @@ #include "got_repository.h" #include "got_worktree.h" #include "got_object.h" +#include "got_path.h" -#include "got_lib_path.h" #include "got_lib_delta.h" #include "got_lib_inflate.h" #include "got_lib_object.h" blob - 343a0f8599eef56421c1734b466437bf0377aa31 blob + 14285e597290f7d3ef572c716a5a998b24c7a4ff --- lib/worktree.c +++ lib/worktree.c @@ -40,9 +40,9 @@ #include "got_object.h" #include "got_worktree.h" #include "got_opentemp.h" +#include "got_path.h" #include "got_lib_worktree.h" -#include "got_lib_path.h" #include "got_lib_sha1.h" #include "got_lib_fileindex.h" #include "got_lib_inflate.h" blob - 490fa9cc29d86b5e10874cade681cf9d2e515326 blob + 4a49027df9609976dca32ab3d55e9d07182a7870 --- regress/delta/delta_test.c +++ regress/delta/delta_test.c @@ -24,9 +24,9 @@ #include "got_error.h" #include "got_opentemp.h" +#include "got_path.h" #include "got_lib_delta.h" -#include "got_lib_path.h" #ifndef nitems #define nitems(_a) (sizeof(_a) / sizeof((_a)[0])) blob - 4514dde0727519afee770ae44ddcc350f37da197 blob + 951b0e5d9dcc4b66f8910ab132b9b27642090cff --- regress/path/path_test.c +++ regress/path/path_test.c @@ -24,9 +24,8 @@ #include #include "got_error.h" +#include "got_path.h" -#include "got_lib_path.h" - #ifndef nitems #define nitems(_a) (sizeof(_a) / sizeof((_a)[0])) #endif blob - db57150665e1556a687d6d952c8c2549b53fec0e blob + 8eb2dae3d768894303eff1d87c647c9d538b8096 --- regress/repository/repository_test.c +++ regress/repository/repository_test.c @@ -33,8 +33,8 @@ #include "got_diff.h" #include "got_opentemp.h" #include "got_privsep.h" +#include "got_path.h" -#include "got_lib_path.h" #ifndef nitems #define nitems(_a) (sizeof(_a) / sizeof((_a)[0])) blob - 1755d39ad8b6509251ed8431b7b1064a563e2203 blob + 473f50c361965f19299b520819cf1a0b17cc8e31 --- regress/worktree/worktree_test.c +++ regress/worktree/worktree_test.c @@ -37,9 +37,9 @@ #include "got_worktree.h" #include "got_opentemp.h" #include "got_privsep.h" +#include "got_path.h" #include "got_lib_worktree.h" -#include "got_lib_path.h" #define GOT_REPO_PATH "../../../"