Skip to content

Commit bba59f5

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7f17900 commit bba59f5

16 files changed

+22
-36
lines changed

bisect.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ static enum bisect_error check_good_are_ancestors_of_bad(struct repository *r,
930930
if (!current_bad_oid)
931931
return error(_("a %s revision is needed"), term_bad);
932932

933-
filename = git_pathdup("BISECT_ANCESTORS_OK");
933+
filename = repo_git_path(the_repository, "BISECT_ANCESTORS_OK");
934934

935935
/* Check if file BISECT_ANCESTORS_OK exists. */
936936
if (!stat(filename, &st) && S_ISREG(st.st_mode))

builtin/am.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static void am_state_init(struct am_state *state)
158158

159159
memset(state, 0, sizeof(*state));
160160

161-
state->dir = git_pathdup("rebase-apply");
161+
state->dir = repo_git_path(the_repository, "rebase-apply");
162162

163163
state->prec = 4;
164164

builtin/clone.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ static void write_refspec_config(const char *src_ref_prefix,
938938

939939
static void dissociate_from_references(void)
940940
{
941-
char *alternates = git_pathdup("objects/info/alternates");
941+
char *alternates = repo_git_path(the_repository, "objects/info/alternates");
942942

943943
if (!access(alternates, F_OK)) {
944944
struct child_process cmd = CHILD_PROCESS_INIT;

builtin/config.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -775,13 +775,13 @@ static void location_options_init(struct config_location_options *opts,
775775
opts->source.file = opts->file_to_free = git_system_config();
776776
opts->source.scope = CONFIG_SCOPE_SYSTEM;
777777
} 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");
779779
opts->source.scope = CONFIG_SCOPE_LOCAL;
780780
} else if (opts->use_worktree_config) {
781781
struct worktree **worktrees = get_worktrees();
782782
if (the_repository->repository_format_worktree_config)
783783
opts->source.file = opts->file_to_free =
784-
git_pathdup("config.worktree");
784+
repo_git_path(the_repository, "config.worktree");
785785
else if (worktrees[0] && worktrees[1])
786786
die(_("--worktree cannot be used with multiple "
787787
"working trees unless the config\n"
@@ -790,7 +790,7 @@ static void location_options_init(struct config_location_options *opts,
790790
"section in \"git help worktree\" for details"));
791791
else
792792
opts->source.file = opts->file_to_free =
793-
git_pathdup("config");
793+
repo_git_path(the_repository, "config");
794794
opts->source.scope = CONFIG_SCOPE_LOCAL;
795795
free_worktrees(worktrees);
796796
} else if (opts->source.file) {
@@ -1087,7 +1087,7 @@ static int show_editor(struct config_location_options *opts)
10871087
git_config(git_default_config, NULL);
10881088
config_file = opts->source.file ?
10891089
xstrdup(opts->source.file) :
1090-
git_pathdup("config");
1090+
repo_git_path(the_repository, "config");
10911091
if (opts->use_global_config) {
10921092
int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666);
10931093
if (fd >= 0) {

builtin/fast-import.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ static void write_branch_report(FILE *rpt, struct branch *b)
328328

329329
static void write_crash_report(const char *err)
330330
{
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());
332332
FILE *rpt = fopen(loc, "w");
333333
struct branch *b;
334334
unsigned long lu;
@@ -3280,7 +3280,7 @@ static char* make_fast_import_path(const char *path)
32803280
{
32813281
if (!relative_marks_paths || is_absolute_path(path))
32823282
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);
32843284
}
32853285

32863286
static void option_import_marks(const char *marks,

builtin/fsck.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ static void check_unreachable_object(struct object *obj)
326326
printable_type(&obj->oid, obj->type),
327327
describe_object(&obj->oid));
328328
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",
330330
obj->type == OBJ_COMMIT ? "commit" : "other",
331331
describe_object(&obj->oid));
332332
FILE *f;

builtin/gc.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
546546
if (xgethostname(my_host, sizeof(my_host)))
547547
xsnprintf(my_host, sizeof(my_host), "unknown");
548548

549-
pidfile_path = git_pathdup("gc.pid");
549+
pidfile_path = repo_git_path(the_repository, "gc.pid");
550550
fd = hold_lock_file_for_update(&lock, pidfile_path,
551551
LOCK_DIE_ON_ERROR);
552552
if (!force) {
@@ -607,7 +607,7 @@ static int report_last_gc_error(void)
607607
int ret = 0;
608608
ssize_t len;
609609
struct stat st;
610-
char *gc_log_path = git_pathdup("gc.log");
610+
char *gc_log_path = repo_git_path(the_repository, "gc.log");
611611

612612
if (stat(gc_log_path, &st)) {
613613
if (errno == ENOENT)

builtin/notes.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
197197
struct strbuf buf = STRBUF_INIT;
198198

199199
/* 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");
201201
fd = xopen(d->edit_path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
202202

203203
if (d->msg_nr)

builtin/replace.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
345345
}
346346
strbuf_release(&ref);
347347

348-
tmpfile = git_pathdup("REPLACE_EDITOBJ");
348+
tmpfile = repo_git_path(the_repository, "REPLACE_EDITOBJ");
349349
if (export_object(&old_oid, type, raw, tmpfile)) {
350350
free(tmpfile);
351351
return -1;

builtin/tag.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ int cmd_tag(int argc,
667667
if (create_tag_object) {
668668
if (force_sign_annotate && !annotate)
669669
opt.sign = 1;
670-
path = git_pathdup("TAG_EDITMSG");
670+
path = repo_git_path(the_repository, "TAG_EDITMSG");
671671
create_tag(&object, object_ref, tag, &buf, &opt, &prev, &object,
672672
&trailer_args, path);
673673
}

builtin/worktree.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ static void check_candidate_path(const char *path,
337337

338338
static void copy_sparse_checkout(const char *worktree_git_dir)
339339
{
340-
char *from_file = git_pathdup("info/sparse-checkout");
340+
char *from_file = repo_git_path(the_repository, "info/sparse-checkout");
341341
char *to_file = xstrfmt("%s/info/sparse-checkout", worktree_git_dir);
342342

343343
if (file_exists(from_file)) {
@@ -353,7 +353,7 @@ static void copy_sparse_checkout(const char *worktree_git_dir)
353353

354354
static void copy_filtered_worktree_config(const char *worktree_git_dir)
355355
{
356-
char *from_file = git_pathdup("config.worktree");
356+
char *from_file = repo_git_path(the_repository, "config.worktree");
357357
char *to_file = xstrfmt("%s/config.worktree", worktree_git_dir);
358358

359359
if (file_exists(from_file)) {

dir.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3455,7 +3455,7 @@ void setup_standard_excludes(struct dir_struct *dir)
34553455

34563456
char *get_sparse_checkout_filename(void)
34573457
{
3458-
return git_pathdup("info/sparse-checkout");
3458+
return repo_git_path(the_repository, "info/sparse-checkout");
34593459
}
34603460

34613461
int get_sparse_checkout_patterns(struct pattern_list *pl)

http-backend.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static void send_strbuf(struct strbuf *hdr,
183183
static void send_local_file(struct strbuf *hdr, const char *the_type,
184184
const char *name)
185185
{
186-
char *p = git_pathdup("%s", name);
186+
char *p = repo_git_path(the_repository, "%s", name);
187187
size_t buf_alloc = 8192;
188188
char *buf = xmalloc(buf_alloc);
189189
int fd;

notes-merge.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static void write_buf_to_worktree(const struct object_id *obj,
309309
const char *buf, unsigned long size)
310310
{
311311
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));
313313
if (safe_create_leading_directories_const(path))
314314
die_errno("unable to create directory for '%s'", path);
315315

object-file.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ static void read_info_alternates(struct repository *r,
717717
void add_to_alternates_file(const char *reference)
718718
{
719719
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");
721721
FILE *in, *out;
722722
int found = 0;
723723

path.h

+1-15
Original file line numberDiff line numberDiff line change
@@ -292,24 +292,10 @@ static inline const char *git_path(const char *fmt, ...)
292292
{ \
293293
static char *ret; \
294294
if (!ret) \
295-
ret = git_pathdup(filename); \
295+
ret = repo_git_path(the_repository, filename); \
296296
return ret; \
297297
}
298298

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-
313299
# endif /* USE_THE_REPOSITORY_VARIABLE */
314300

315301
#endif /* PATH_H */

0 commit comments

Comments
 (0)