make got path APIs available to library consumers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
diff --git a/include/got_path.h b/include/got_path.h
new file mode 100644
index 0000000..d796646
--- /dev/null
+++ b/include/got_path.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
+ *
+ * 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 *);
diff --git a/lib/commit_graph.c b/lib/commit_graph.c
index 02c170d..ebce7f7 100644
--- a/lib/commit_graph.c
+++ b/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;
diff --git a/lib/deflate.c b/lib/deflate.c
index bb2a535..dc7337a 100644
--- a/lib/deflate.c
+++ b/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
diff --git a/lib/delta.c b/lib/delta.c
index 730bb4f..c4bed18 100644
--- a/lib/delta.c
+++ b/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"
diff --git a/lib/diff.c b/lib/diff.c
index 8f10487..8563f78 100644
--- a/lib/diff.c
+++ b/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"
diff --git a/lib/fileindex.c b/lib/fileindex.c
index 155c46e..a30b4cf 100644
--- a/lib/fileindex.c
+++ b/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"
diff --git a/lib/got_lib_path.h b/lib/got_lib_path.h
deleted file mode 100644
index d796646..0000000
--- a/lib/got_lib_path.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
- *
- * 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 *);
diff --git a/lib/inflate.c b/lib/inflate.c
index d5a41ac..bd40396 100644
--- a/lib/inflate.c
+++ b/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
diff --git a/lib/lockfile.c b/lib/lockfile.c
index dc493f7..0426e42 100644
--- a/lib/lockfile.c
+++ b/lib/lockfile.c
@@ -26,9 +26,9 @@
#include <time.h>
#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)
diff --git a/lib/object.c b/lib/object.c
index a2abc10..8356628 100644
--- a/lib/object.c
+++ b/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"
diff --git a/lib/object_create.c b/lib/object_create.c
index 6e0d389..a3dbc82 100644
--- a/lib/object_create.c
+++ b/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]))
diff --git a/lib/object_parse.c b/lib/object_parse.c
index 2f081c6..8840c62 100644
--- a/lib/object_parse.c
+++ b/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]))
diff --git a/lib/pack.c b/lib/pack.c
index 5de6375..11d1e50 100644
--- a/lib/pack.c
+++ b/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"
diff --git a/lib/path.c b/lib/path.c
index d122320..253851f 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -27,8 +27,7 @@
#include <string.h>
#include "got_error.h"
-
-#include "got_lib_path.h"
+#include "got_path.h"
#ifndef MIN
#define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
diff --git a/lib/reference.c b/lib/reference.c
index 168ef0c..a33e604 100644
--- a/lib/reference.c
+++ b/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"
diff --git a/lib/repository.c b/lib/repository.c
index ad65519..97763cc 100644
--- a/lib/repository.c
+++ b/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"
diff --git a/lib/worktree.c b/lib/worktree.c
index 343a0f8..14285e5 100644
--- a/lib/worktree.c
+++ b/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"
diff --git a/regress/delta/delta_test.c b/regress/delta/delta_test.c
index 490fa9c..4a49027 100644
--- a/regress/delta/delta_test.c
+++ b/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]))
diff --git a/regress/path/path_test.c b/regress/path/path_test.c
index 4514dde..951b0e5 100644
--- a/regress/path/path_test.c
+++ b/regress/path/path_test.c
@@ -24,8 +24,7 @@
#include <err.h>
#include "got_error.h"
-
-#include "got_lib_path.h"
+#include "got_path.h"
#ifndef nitems
#define nitems(_a) (sizeof(_a) / sizeof((_a)[0]))
diff --git a/regress/repository/repository_test.c b/regress/repository/repository_test.c
index db57150..8eb2dae 100644
--- a/regress/repository/repository_test.c
+++ b/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]))
diff --git a/regress/worktree/worktree_test.c b/regress/worktree/worktree_test.c
index 1755d39..473f50c 100644
--- a/regress/worktree/worktree_test.c
+++ b/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 "../../../"