THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
5.8KB

  1. #ifndef PATH_H
  2. #define PATH_H
  3. struct repository;
  4. struct strbuf;
  5. /*
  6. * The result to all functions which return statically allocated memory may be
  7. * overwritten by another call to _any_ one of these functions. Consider using
  8. * the safer variants which operate on strbufs or return allocated memory.
  9. */
  10. /*
  11. * Return a statically allocated path.
  12. */
  13. const char *mkpath(const char *fmt, ...)
  14. __attribute__((format (printf, 1, 2)));
  15. /*
  16. * Return a path.
  17. */
  18. char *mkpathdup(const char *fmt, ...)
  19. __attribute__((format (printf, 1, 2)));
  20. /*
  21. * Construct a path and place the result in the provided buffer `buf`.
  22. */
  23. char *mksnpath(char *buf, size_t n, const char *fmt, ...)
  24. __attribute__((format (printf, 3, 4)));
  25. /*
  26. * The `git_common_path` family of functions will construct a path into a
  27. * repository's common git directory, which is shared by all worktrees.
  28. */
  29. /*
  30. * Constructs a path into the common git directory of repository `repo` and
  31. * append it in the provided buffer `sb`.
  32. */
  33. void strbuf_git_common_path(struct strbuf *sb,
  34. const struct repository *repo,
  35. const char *fmt, ...)
  36. __attribute__((format (printf, 3, 4)));
  37. /*
  38. * Return a statically allocated path into the main repository's
  39. * (the_repository) common git directory.
  40. */
  41. const char *git_common_path(const char *fmt, ...)
  42. __attribute__((format (printf, 1, 2)));
  43. /*
  44. * The `git_path` family of functions will construct a path into a repository's
  45. * git directory.
  46. *
  47. * These functions will perform adjustments to the resultant path to account
  48. * for special paths which are either considered common among worktrees (e.g.
  49. * paths into the object directory) or have been explicitly set via an
  50. * environment variable or config (e.g. path to the index file).
  51. *
  52. * For an exhaustive list of the adjustments made look at `common_list` and
  53. * `adjust_git_path` in path.c.
  54. */
  55. /*
  56. * Return a path into the git directory of repository `repo`.
  57. */
  58. char *repo_git_path(const struct repository *repo,
  59. const char *fmt, ...)
  60. __attribute__((format (printf, 2, 3)));
  61. /*
  62. * Construct a path into the git directory of repository `repo` and append it
  63. * to the provided buffer `sb`.
  64. */
  65. void strbuf_repo_git_path(struct strbuf *sb,
  66. const struct repository *repo,
  67. const char *fmt, ...)
  68. __attribute__((format (printf, 3, 4)));
  69. /*
  70. * Return a statically allocated path into the main repository's
  71. * (the_repository) git directory.
  72. */
  73. const char *git_path(const char *fmt, ...)
  74. __attribute__((format (printf, 1, 2)));
  75. /*
  76. * Return a path into the main repository's (the_repository) git directory.
  77. */
  78. char *git_pathdup(const char *fmt, ...)
  79. __attribute__((format (printf, 1, 2)));
  80. /*
  81. * Construct a path into the main repository's (the_repository) git directory
  82. * and place it in the provided buffer `buf`, the contents of the buffer will
  83. * be overridden.
  84. */
  85. char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
  86. __attribute__((format (printf, 2, 3)));
  87. /*
  88. * Construct a path into the main repository's (the_repository) git directory
  89. * and append it to the provided buffer `sb`.
  90. */
  91. void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
  92. __attribute__((format (printf, 2, 3)));
  93. /*
  94. * Return a path into the worktree of repository `repo`.
  95. *
  96. * If the repository doesn't have a worktree NULL is returned.
  97. */
  98. char *repo_worktree_path(const struct repository *repo,
  99. const char *fmt, ...)
  100. __attribute__((format (printf, 2, 3)));
  101. /*
  102. * Construct a path into the worktree of repository `repo` and append it
  103. * to the provided buffer `sb`.
  104. *
  105. * If the repository doesn't have a worktree nothing will be appended to `sb`.
  106. */
  107. void strbuf_repo_worktree_path(struct strbuf *sb,
  108. const struct repository *repo,
  109. const char *fmt, ...)
  110. __attribute__((format (printf, 3, 4)));
  111. /*
  112. * Return a path into a submodule's git directory located at `path`. `path`
  113. * must only reference a submodule of the main repository (the_repository).
  114. */
  115. char *git_pathdup_submodule(const char *path, const char *fmt, ...)
  116. __attribute__((format (printf, 2, 3)));
  117. /*
  118. * Construct a path into a submodule's git directory located at `path` and
  119. * append it to the provided buffer `sb`. `path` must only reference a
  120. * submodule of the main repository (the_repository).
  121. */
  122. int strbuf_git_path_submodule(struct strbuf *sb, const char *path,
  123. const char *fmt, ...)
  124. __attribute__((format (printf, 3, 4)));
  125. void report_linked_checkout_garbage(void);
  126. /*
  127. * You can define a static memoized git path like:
  128. *
  129. * static GIT_PATH_FUNC(git_path_foo, "FOO")
  130. *
  131. * or use one of the global ones below.
  132. */
  133. #define GIT_PATH_FUNC(func, filename) \
  134. const char *func(void) \
  135. { \
  136. static char *ret; \
  137. if (!ret) \
  138. ret = git_pathdup(filename); \
  139. return ret; \
  140. }
  141. #define REPO_GIT_PATH_FUNC(var, filename) \
  142. const char *git_path_##var(struct repository *r) \
  143. { \
  144. if (!r->cached_paths.var) \
  145. r->cached_paths.var = repo_git_path(r, filename); \
  146. return r->cached_paths.var; \
  147. }
  148. struct path_cache {
  149. const char *cherry_pick_head;
  150. const char *revert_head;
  151. const char *squash_msg;
  152. const char *merge_msg;
  153. const char *merge_rr;
  154. const char *merge_mode;
  155. const char *merge_head;
  156. const char *fetch_head;
  157. const char *shallow;
  158. };
  159. #define PATH_CACHE_INIT { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
  160. const char *git_path_cherry_pick_head(struct repository *r);
  161. const char *git_path_revert_head(struct repository *r);
  162. const char *git_path_squash_msg(struct repository *r);
  163. const char *git_path_merge_msg(struct repository *r);
  164. const char *git_path_merge_rr(struct repository *r);
  165. const char *git_path_merge_mode(struct repository *r);
  166. const char *git_path_merge_head(struct repository *r);
  167. const char *git_path_fetch_head(struct repository *r);
  168. const char *git_path_shallow(struct repository *r);
  169. int ends_with_path_components(const char *path, const char *components);
  170. #endif /* PATH_H */