path: drop `git_pathdup()` in favor of `repo_git_path()`
Remove `git_pathdup()` in favor of `repo_git_path()`. The latter does essentially the same, with the only exception that it does not rely on `the_repository` but takes the repo as separate parameter. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Feb 7, 2025 at 12:03 UTC
bba59f58a4eeda6fafaa3d41e14f3d00a179923f
16 files changed
+22
-36
bisect.c
+1
-1
@@ -930,7 +930,7 @@ static enum bisect_error check_good_are_ancestors_of_bad(struct repository *r,
930
if (!current_bad_oid)
931
return error(_("a %s revision is needed"), term_bad);
932
933
- filename = git_pathdup("BISECT_ANCESTORS_OK");
933
+ filename = repo_git_path(the_repository, "BISECT_ANCESTORS_OK");
934
935
/* Check if file BISECT_ANCESTORS_OK exists. */
936
if (!stat(filename, &st) && S_ISREG(st.st_mode))
builtin/am.c
+1
-1
@@ -158,7 +158,7 @@ static void am_state_init(struct am_state *state)
158
159
memset(state, 0, sizeof(*state));
160
161
- state->dir = git_pathdup("rebase-apply");
161
+ state->dir = repo_git_path(the_repository, "rebase-apply");
162
163
state->prec = 4;
164
builtin/clone.c
+1
-1
@@ -938,7 +938,7 @@ static void write_refspec_config(const char *src_ref_prefix,
938
939
static void dissociate_from_references(void)
940
{
941
- char *alternates = git_pathdup("objects/info/alternates");
941
+ char *alternates = repo_git_path(the_repository, "objects/info/alternates");
942
943
if (!access(alternates, F_OK)) {
944
struct child_process cmd = CHILD_PROCESS_INIT;
builtin/config.c
+4
-4
@@ -775,13 +775,13 @@ static void location_options_init(struct config_location_options *opts,
775
opts->source.file = opts->file_to_free = git_system_config();
776
opts->source.scope = CONFIG_SCOPE_SYSTEM;
777
} else if (opts->use_local_config) {
778
- opts->source.file = opts->file_to_free = git_pathdup("config");
778
+ opts->source.file = opts->file_to_free = repo_git_path(the_repository, "config");
779
opts->source.scope = CONFIG_SCOPE_LOCAL;
780
} else if (opts->use_worktree_config) {
781
struct worktree **worktrees = get_worktrees();
782
if (the_repository->repository_format_worktree_config)
783
opts->source.file = opts->file_to_free =
784
- git_pathdup("config.worktree");
784
+ repo_git_path(the_repository, "config.worktree");
785
else if (worktrees[0] && worktrees[1])
786
die(_("--worktree cannot be used with multiple "
787
"working trees unless the config\n"
@@ -790,7 +790,7 @@ static void location_options_init(struct config_location_options *opts,
790
"section in \"git help worktree\" for details"));
791
else
792
opts->source.file = opts->file_to_free =
793
- git_pathdup("config");
793
+ repo_git_path(the_repository, "config");
794
opts->source.scope = CONFIG_SCOPE_LOCAL;
795
free_worktrees(worktrees);
796
} else if (opts->source.file) {
@@ -1087,7 +1087,7 @@ static int show_editor(struct config_location_options *opts)
1087
git_config(git_default_config, NULL);
1088
config_file = opts->source.file ?
1089
xstrdup(opts->source.file) :
1090
- git_pathdup("config");
1090
+ repo_git_path(the_repository, "config");
1091
if (opts->use_global_config) {
1092
int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666);
1093
if (fd >= 0) {
builtin/fast-import.c
+2
-2
@@ -328,7 +328,7 @@ static void write_branch_report(FILE *rpt, struct branch *b)
328
329
static void write_crash_report(const char *err)
330
{
331
- char *loc = git_pathdup("fast_import_crash_%"PRIuMAX, (uintmax_t) getpid());
331
+ char *loc = repo_git_path(the_repository, "fast_import_crash_%"PRIuMAX, (uintmax_t) getpid());
332
FILE *rpt = fopen(loc, "w");
333
struct branch *b;
334
unsigned long lu;
@@ -3280,7 +3280,7 @@ static char* make_fast_import_path(const char *path)
3280
{
3281
if (!relative_marks_paths || is_absolute_path(path))
3282
return prefix_filename(global_prefix, path);
3283
- return git_pathdup("info/fast-import/%s", path);
3283
+ return repo_git_path(the_repository, "info/fast-import/%s", path);
3284
}
3285
3286
static void option_import_marks(const char *marks,
builtin/fsck.c
+1
-1
@@ -326,7 +326,7 @@ static void check_unreachable_object(struct object *obj)
326
printable_type(&obj->oid, obj->type),
327
describe_object(&obj->oid));
328
if (write_lost_and_found) {
329
- char *filename = git_pathdup("lost-found/%s/%s",
329
+ char *filename = repo_git_path(the_repository, "lost-found/%s/%s",
330
obj->type == OBJ_COMMIT ? "commit" : "other",
331
describe_object(&obj->oid));
332
FILE *f;
builtin/gc.c
+2
-2
@@ -546,7 +546,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
546
if (xgethostname(my_host, sizeof(my_host)))
547
xsnprintf(my_host, sizeof(my_host), "unknown");
548
549
- pidfile_path = git_pathdup("gc.pid");
549
+ pidfile_path = repo_git_path(the_repository, "gc.pid");
550
fd = hold_lock_file_for_update(&lock, pidfile_path,
551
LOCK_DIE_ON_ERROR);
552
if (!force) {
@@ -607,7 +607,7 @@ static int report_last_gc_error(void)
607
int ret = 0;
608
ssize_t len;
609
struct stat st;
610
- char *gc_log_path = git_pathdup("gc.log");
610
+ char *gc_log_path = repo_git_path(the_repository, "gc.log");
611
612
if (stat(gc_log_path, &st)) {
613
if (errno == ENOENT)
builtin/notes.c
+1
-1
@@ -197,7 +197,7 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
197
struct strbuf buf = STRBUF_INIT;
198
199
/* write the template message before editing: */
200
- d->edit_path = git_pathdup("NOTES_EDITMSG");
200
+ d->edit_path = repo_git_path(the_repository, "NOTES_EDITMSG");
201
fd = xopen(d->edit_path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
202
203
if (d->msg_nr)
builtin/replace.c
+1
-1
@@ -345,7 +345,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
345
}
346
strbuf_release(&ref);
347
348
- tmpfile = git_pathdup("REPLACE_EDITOBJ");
348
+ tmpfile = repo_git_path(the_repository, "REPLACE_EDITOBJ");
349
if (export_object(&old_oid, type, raw, tmpfile)) {
350
free(tmpfile);
351
return -1;
builtin/tag.c
+1
-1
@@ -667,7 +667,7 @@ int cmd_tag(int argc,
667
if (create_tag_object) {
668
if (force_sign_annotate && !annotate)
669
opt.sign = 1;
670
- path = git_pathdup("TAG_EDITMSG");
670
+ path = repo_git_path(the_repository, "TAG_EDITMSG");
671
create_tag(&object, object_ref, tag, &buf, &opt, &prev, &object,
672
&trailer_args, path);
673
}
builtin/worktree.c
+2
-2
@@ -337,7 +337,7 @@ static void check_candidate_path(const char *path,
337
338
static void copy_sparse_checkout(const char *worktree_git_dir)
339
{
340
- char *from_file = git_pathdup("info/sparse-checkout");
340
+ char *from_file = repo_git_path(the_repository, "info/sparse-checkout");
341
char *to_file = xstrfmt("%s/info/sparse-checkout", worktree_git_dir);
342
343
if (file_exists(from_file)) {
@@ -353,7 +353,7 @@ static void copy_sparse_checkout(const char *worktree_git_dir)
353
354
static void copy_filtered_worktree_config(const char *worktree_git_dir)
355
{
356
- char *from_file = git_pathdup("config.worktree");
356
+ char *from_file = repo_git_path(the_repository, "config.worktree");
357
char *to_file = xstrfmt("%s/config.worktree", worktree_git_dir);
358
359
if (file_exists(from_file)) {
dir.c
+1
-1
@@ -3455,7 +3455,7 @@ void setup_standard_excludes(struct dir_struct *dir)
3455
3456
char *get_sparse_checkout_filename(void)
3457
{
3458
- return git_pathdup("info/sparse-checkout");
3458
+ return repo_git_path(the_repository, "info/sparse-checkout");
3459
}
3460
3461
int get_sparse_checkout_patterns(struct pattern_list *pl)
http-backend.c
+1
-1
@@ -183,7 +183,7 @@ static void send_strbuf(struct strbuf *hdr,
183
static void send_local_file(struct strbuf *hdr, const char *the_type,
184
const char *name)
185
{
186
- char *p = git_pathdup("%s", name);
186
+ char *p = repo_git_path(the_repository, "%s", name);
187
size_t buf_alloc = 8192;
188
char *buf = xmalloc(buf_alloc);
189
int fd;
notes-merge.c
+1
-1
@@ -309,7 +309,7 @@ static void write_buf_to_worktree(const struct object_id *obj,
309
const char *buf, unsigned long size)
310
{
311
int fd;
312
- char *path = git_pathdup(NOTES_MERGE_WORKTREE "/%s", oid_to_hex(obj));
312
+ char *path = repo_git_path(the_repository, NOTES_MERGE_WORKTREE "/%s", oid_to_hex(obj));
313
if (safe_create_leading_directories_const(path))
314
die_errno("unable to create directory for '%s'", path);
315
object-file.c
+1
-1
@@ -717,7 +717,7 @@ static void read_info_alternates(struct repository *r,
717
void add_to_alternates_file(const char *reference)
718
{
719
struct lock_file lock = LOCK_INIT;
720
- char *alts = git_pathdup("objects/info/alternates");
720
+ char *alts = repo_git_path(the_repository, "objects/info/alternates");
721
FILE *in, *out;
722
int found = 0;
723
path.h
+1
-15
@@ -292,24 +292,10 @@ static inline const char *git_path(const char *fmt, ...)
292
{ \
293
static char *ret; \
294
if (!ret) \
295
- ret = git_pathdup(filename); \
295
+ ret = repo_git_path(the_repository, 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
-
299
# endif /* USE_THE_REPOSITORY_VARIABLE */
300
301
#endif /* PATH_H */