25
__attribute__((format (printf, 1, 2)));
26
27
/*
28
- * The `git_common_path` family of functions will construct a path into a
28
+ * The `strbuf_git_common_path` family of functions will construct a path into a
29
* repository's common git directory, which is shared by all worktrees.
30
*/
31
43
va_list args);
44
45
/*
46
- * Return a statically allocated path into the main repository's
47
- * (the_repository) common git directory.
48
- */
49
-const char *git_common_path(const char *fmt, ...)
50
- __attribute__((format (printf, 1, 2)));
51
-
52
-/*
53
- * The `git_path` family of functions will construct a path into a repository's
46
+ * The `repo_git_path` family of functions will construct a path into a repository's
47
* git directory.
48
*
49
* These functions will perform adjustments to the resultant path to account
80
__attribute__((format (printf, 3, 4)));
81
82
/*
90
- * Return a statically allocated path into the main repository's
91
- * (the_repository) git directory.
92
- */
93
-const char *git_path(const char *fmt, ...)
94
- __attribute__((format (printf, 1, 2)));
95
-
96
-/*
97
- * Similar to git_path() but can produce paths for a specified
83
+ * Similar to repo_git_path() but can produce paths for a specified
84
* worktree instead of current one. When no worktree is given, then the path is
85
* computed relative to main worktree of the given repository.
86
*/
89
const char *fmt, ...)
90
__attribute__((format (printf, 3, 4)));
91
106
-/*
107
- * Return a path into the main repository's (the_repository) git directory.
108
- */
109
-char *git_pathdup(const char *fmt, ...)
110
- __attribute__((format (printf, 1, 2)));
111
-
112
-/*
113
- * Construct a path into the main repository's (the_repository) git directory
114
- * and place it in the provided buffer `buf`, the contents of the buffer will
115
- * be overridden.
116
- */
117
-char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
118
- __attribute__((format (printf, 2, 3)));
119
-
120
-/*
121
- * Construct a path into the main repository's (the_repository) git directory
122
- * and append it to the provided buffer `sb`.
123
- */
124
-void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
125
- __attribute__((format (printf, 2, 3)));
126
-
92
/*
93
* Return a path into the worktree of repository `repo`.
94
*
130
/*
131
* You can define a static memoized git path like:
132
*
168
- * static GIT_PATH_FUNC(git_path_foo, "FOO")
133
+ * static REPO_GIT_PATH_FUNC(git_path_foo, "FOO")
134
*
135
* or use one of the global ones below.
136
*/
172
-#define GIT_PATH_FUNC(func, filename) \
173
- const char *func(void) \
174
- { \
175
- static char *ret; \
176
- if (!ret) \
177
- ret = git_pathdup(filename); \
178
- return ret; \
179
- }
180
-
137
#define REPO_GIT_PATH_FUNC(var, filename) \
138
const char *git_path_##var(struct repository *r) \
139
{ \
217
*/
218
void safe_create_dir(const char *dir, int share);
219
220
+/*
221
+ * Do not use this function. It is only exported to other subsystems until we
222
+ * can get rid of the below block of functions that implicitly rely on
223
+ * `the_repository`.
224
+ */
225
+struct strbuf *get_pathname(void);
226
+
227
+# ifdef USE_THE_REPOSITORY_VARIABLE
228
+# include "strbuf.h"
229
+# include "repository.h"
230
+
231
+/*
232
+ * Return a statically allocated path into the main repository's
233
+ * (the_repository) common git directory.
234
+ */
235
+__attribute__((format (printf, 1, 2)))
236
+static inline const char *git_common_path(const char *fmt, ...)
237
+{
238
+ struct strbuf *pathname = get_pathname();
239
+ va_list args;
240
+ va_start(args, fmt);
241
+ repo_common_pathv(the_repository, pathname, fmt, args);
242
+ va_end(args);
243
+ return pathname->buf;
244
+}
245
+
246
+/*
247
+ * Construct a path into the main repository's (the_repository) git directory
248
+ * and place it in the provided buffer `buf`, the contents of the buffer will
249
+ * be overridden.
250
+ */
251
+__attribute__((format (printf, 2, 3)))
252
+static inline char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
253
+{
254
+ va_list args;
255
+ strbuf_reset(buf);
256
+ va_start(args, fmt);
257
+ repo_git_pathv(the_repository, NULL, buf, fmt, args);
258
+ va_end(args);
259
+ return buf->buf;
260
+}
261
+
262
+/*
263
+ * Construct a path into the main repository's (the_repository) git directory
264
+ * and append it to the provided buffer `sb`.
265
+ */
266
+__attribute__((format (printf, 2, 3)))
267
+static inline void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
268
+{
269
+ va_list args;
270
+ va_start(args, fmt);
271
+ repo_git_pathv(the_repository, NULL, sb, fmt, args);
272
+ va_end(args);
273
+}
274
+
275
+/*
276
+ * Return a statically allocated path into the main repository's
277
+ * (the_repository) git directory.
278
+ */
279
+__attribute__((format (printf, 1, 2)))
280
+static inline const char *git_path(const char *fmt, ...)
281
+{
282
+ struct strbuf *pathname = get_pathname();
283
+ va_list args;
284
+ va_start(args, fmt);
285
+ repo_git_pathv(the_repository, NULL, pathname, fmt, args);
286
+ va_end(args);
287
+ return pathname->buf;
288
+}
289
+
290
+#define GIT_PATH_FUNC(func, filename) \
291
+ const char *func(void) \
292
+ { \
293
+ static char *ret; \
294
+ if (!ret) \
295
+ ret = git_pathdup(filename); \
296
+ return ret; \
297
+ }
298
+
299
+/*
300
+ * Return a path into the main repository's (the_repository) git directory.
301
+ */
302
+__attribute__((format (printf, 1, 2)))
303
+static inline char *git_pathdup(const char *fmt, ...)
304
+{
305
+ struct strbuf path = STRBUF_INIT;
306
+ va_list args;
307
+ va_start(args, fmt);
308
+ repo_git_pathv(the_repository, NULL, &path, fmt, args);
309
+ va_end(args);
310
+ return strbuf_detach(&path, NULL);
311
+}
312
+
313
+# endif /* USE_THE_REPOSITORY_VARIABLE */
314
+
315
#endif /* PATH_H */