]> git.ipfire.org Git - thirdparty/git.git/commitdiff
path: drop `git_pathdup()` in favor of `repo_git_path()`
authorPatrick Steinhardt <ps@pks.im>
Fri, 7 Feb 2025 11:03:32 +0000 (12:03 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Feb 2025 17:59:22 +0000 (09:59 -0800)
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>
16 files changed:
bisect.c
builtin/am.c
builtin/clone.c
builtin/config.c
builtin/fast-import.c
builtin/fsck.c
builtin/gc.c
builtin/notes.c
builtin/replace.c
builtin/tag.c
builtin/worktree.c
dir.c
http-backend.c
notes-merge.c
object-file.c
path.h

index 7a3c77c6d84da0cb6e135b6e0b1ca3596903af5c..269a98bf978de679469f9af950cc491f31430c52 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -930,7 +930,7 @@ static enum bisect_error check_good_are_ancestors_of_bad(struct repository *r,
        if (!current_bad_oid)
                return error(_("a %s revision is needed"), term_bad);
 
-       filename = git_pathdup("BISECT_ANCESTORS_OK");
+       filename = repo_git_path(the_repository, "BISECT_ANCESTORS_OK");
 
        /* Check if file BISECT_ANCESTORS_OK exists. */
        if (!stat(filename, &st) && S_ISREG(st.st_mode))
index 390b463144202d605da6d9d52ca06e60068e372e..2921bb89ef16e6d050b07c325f0da488d805d9c6 100644 (file)
@@ -158,7 +158,7 @@ static void am_state_init(struct am_state *state)
 
        memset(state, 0, sizeof(*state));
 
-       state->dir = git_pathdup("rebase-apply");
+       state->dir = repo_git_path(the_repository, "rebase-apply");
 
        state->prec = 4;
 
index fd001d800c635e46bbc7027a8fdda2a8c9fbf069..5ae6ee9db9b4fbcd1b2ad79d6929b870999d2c6c 100644 (file)
@@ -938,7 +938,7 @@ static void write_refspec_config(const char *src_ref_prefix,
 
 static void dissociate_from_references(void)
 {
-       char *alternates = git_pathdup("objects/info/alternates");
+       char *alternates = repo_git_path(the_repository, "objects/info/alternates");
 
        if (!access(alternates, F_OK)) {
                struct child_process cmd = CHILD_PROCESS_INIT;
index 16e6e3055598f1355714dc6de458b662870214c0..53a90094e31454372d27b2175af6ee5aa382f0f1 100644 (file)
@@ -775,13 +775,13 @@ static void location_options_init(struct config_location_options *opts,
                opts->source.file = opts->file_to_free = git_system_config();
                opts->source.scope = CONFIG_SCOPE_SYSTEM;
        } else if (opts->use_local_config) {
-               opts->source.file = opts->file_to_free = git_pathdup("config");
+               opts->source.file = opts->file_to_free = repo_git_path(the_repository, "config");
                opts->source.scope = CONFIG_SCOPE_LOCAL;
        } else if (opts->use_worktree_config) {
                struct worktree **worktrees = get_worktrees();
                if (the_repository->repository_format_worktree_config)
                        opts->source.file = opts->file_to_free =
-                               git_pathdup("config.worktree");
+                               repo_git_path(the_repository, "config.worktree");
                else if (worktrees[0] && worktrees[1])
                        die(_("--worktree cannot be used with multiple "
                              "working trees unless the config\n"
@@ -790,7 +790,7 @@ static void location_options_init(struct config_location_options *opts,
                              "section in \"git help worktree\" for details"));
                else
                        opts->source.file = opts->file_to_free =
-                               git_pathdup("config");
+                               repo_git_path(the_repository, "config");
                opts->source.scope = CONFIG_SCOPE_LOCAL;
                free_worktrees(worktrees);
        } else if (opts->source.file) {
@@ -1087,7 +1087,7 @@ static int show_editor(struct config_location_options *opts)
        git_config(git_default_config, NULL);
        config_file = opts->source.file ?
                        xstrdup(opts->source.file) :
-                       git_pathdup("config");
+                       repo_git_path(the_repository, "config");
        if (opts->use_global_config) {
                int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666);
                if (fd >= 0) {
index a6a84058cde7b5139bea4c8e55d3b75555833906..c6f5147e8b0736dee33b009a80e5acd419c14339 100644 (file)
@@ -328,7 +328,7 @@ static void write_branch_report(FILE *rpt, struct branch *b)
 
 static void write_crash_report(const char *err)
 {
-       char *loc = git_pathdup("fast_import_crash_%"PRIuMAX, (uintmax_t) getpid());
+       char *loc = repo_git_path(the_repository, "fast_import_crash_%"PRIuMAX, (uintmax_t) getpid());
        FILE *rpt = fopen(loc, "w");
        struct branch *b;
        unsigned long lu;
@@ -3280,7 +3280,7 @@ static char* make_fast_import_path(const char *path)
 {
        if (!relative_marks_paths || is_absolute_path(path))
                return prefix_filename(global_prefix, path);
-       return git_pathdup("info/fast-import/%s", path);
+       return repo_git_path(the_repository, "info/fast-import/%s", path);
 }
 
 static void option_import_marks(const char *marks,
index 7a4dcb0716052ff1b9236ea66b8901960fe1c55d..c12203e0121058447cb5ad6158e5598503809db4 100644 (file)
@@ -326,7 +326,7 @@ static void check_unreachable_object(struct object *obj)
                                  printable_type(&obj->oid, obj->type),
                                  describe_object(&obj->oid));
                if (write_lost_and_found) {
-                       char *filename = git_pathdup("lost-found/%s/%s",
+                       char *filename = repo_git_path(the_repository, "lost-found/%s/%s",
                                obj->type == OBJ_COMMIT ? "commit" : "other",
                                describe_object(&obj->oid));
                        FILE *f;
index 0bf35334942ca0e5ad7bb0821b89d56fed1af07d..57f6aee174fdb220dfbc9a151e5088a6fbef42c3 100644 (file)
@@ -546,7 +546,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
        if (xgethostname(my_host, sizeof(my_host)))
                xsnprintf(my_host, sizeof(my_host), "unknown");
 
-       pidfile_path = git_pathdup("gc.pid");
+       pidfile_path = repo_git_path(the_repository, "gc.pid");
        fd = hold_lock_file_for_update(&lock, pidfile_path,
                                       LOCK_DIE_ON_ERROR);
        if (!force) {
@@ -607,7 +607,7 @@ static int report_last_gc_error(void)
        int ret = 0;
        ssize_t len;
        struct stat st;
-       char *gc_log_path = git_pathdup("gc.log");
+       char *gc_log_path = repo_git_path(the_repository, "gc.log");
 
        if (stat(gc_log_path, &st)) {
                if (errno == ENOENT)
index d051abf6dff8f2bce193fd52b4beda5060af3972..18bcbb2f9134305792fea7139ef88c422d615cf8 100644 (file)
@@ -197,7 +197,7 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
                struct strbuf buf = STRBUF_INIT;
 
                /* write the template message before editing: */
-               d->edit_path = git_pathdup("NOTES_EDITMSG");
+               d->edit_path = repo_git_path(the_repository, "NOTES_EDITMSG");
                fd = xopen(d->edit_path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
 
                if (d->msg_nr)
index a4eaadff91f1be107a8e0e25a701d2006ff8cac2..15ec0922ce14d87296f4aa557fa75d9abbf12a85 100644 (file)
@@ -345,7 +345,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
        }
        strbuf_release(&ref);
 
-       tmpfile = git_pathdup("REPLACE_EDITOBJ");
+       tmpfile = repo_git_path(the_repository, "REPLACE_EDITOBJ");
        if (export_object(&old_oid, type, raw, tmpfile)) {
                free(tmpfile);
                return -1;
index e8a344b9264b9c79099b4e7990c5b9595e2abae5..d3e0943b734759ae559a21889a7ff6bb40f65c92 100644 (file)
@@ -667,7 +667,7 @@ int cmd_tag(int argc,
        if (create_tag_object) {
                if (force_sign_annotate && !annotate)
                        opt.sign = 1;
-               path = git_pathdup("TAG_EDITMSG");
+               path = repo_git_path(the_repository, "TAG_EDITMSG");
                create_tag(&object, object_ref, tag, &buf, &opt, &prev, &object,
                           &trailer_args, path);
        }
index c043d4d523f578814852a752f763e75d0ca8ac3c..c84e6aa2cb5b9015eaa49f140a5826b9b3e3e44c 100644 (file)
@@ -337,7 +337,7 @@ static void check_candidate_path(const char *path,
 
 static void copy_sparse_checkout(const char *worktree_git_dir)
 {
-       char *from_file = git_pathdup("info/sparse-checkout");
+       char *from_file = repo_git_path(the_repository, "info/sparse-checkout");
        char *to_file = xstrfmt("%s/info/sparse-checkout", worktree_git_dir);
 
        if (file_exists(from_file)) {
@@ -353,7 +353,7 @@ static void copy_sparse_checkout(const char *worktree_git_dir)
 
 static void copy_filtered_worktree_config(const char *worktree_git_dir)
 {
-       char *from_file = git_pathdup("config.worktree");
+       char *from_file = repo_git_path(the_repository, "config.worktree");
        char *to_file = xstrfmt("%s/config.worktree", worktree_git_dir);
 
        if (file_exists(from_file)) {
diff --git a/dir.c b/dir.c
index 5b2181e5899ce951791aa5e46ccdbb2d71ce6144..4122f6513d82b2cecf60f550a43f19dacf2d54fd 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -3455,7 +3455,7 @@ void setup_standard_excludes(struct dir_struct *dir)
 
 char *get_sparse_checkout_filename(void)
 {
-       return git_pathdup("info/sparse-checkout");
+       return repo_git_path(the_repository, "info/sparse-checkout");
 }
 
 int get_sparse_checkout_patterns(struct pattern_list *pl)
index 33cf3782826f6cca696ecb8c85cea7f4a0829b46..50b2858fad634a36382176c313763dba22326b25 100644 (file)
@@ -183,7 +183,7 @@ static void send_strbuf(struct strbuf *hdr,
 static void send_local_file(struct strbuf *hdr, const char *the_type,
                                const char *name)
 {
-       char *p = git_pathdup("%s", name);
+       char *p = repo_git_path(the_repository, "%s", name);
        size_t buf_alloc = 8192;
        char *buf = xmalloc(buf_alloc);
        int fd;
index 8d701ed428aa621cc21871c49a0776bccf4be916..c997c0c1e3925f76d79addc7fc7490f86112abe0 100644 (file)
@@ -309,7 +309,7 @@ static void write_buf_to_worktree(const struct object_id *obj,
                                  const char *buf, unsigned long size)
 {
        int fd;
-       char *path = git_pathdup(NOTES_MERGE_WORKTREE "/%s", oid_to_hex(obj));
+       char *path = repo_git_path(the_repository, NOTES_MERGE_WORKTREE "/%s", oid_to_hex(obj));
        if (safe_create_leading_directories_const(path))
                die_errno("unable to create directory for '%s'", path);
 
index 6ce1caacae7f0b03f11159f0e742a5f07ddd7b08..335cc2a5da24f1b3684d1061ec267556301d9a04 100644 (file)
@@ -717,7 +717,7 @@ static void read_info_alternates(struct repository *r,
 void add_to_alternates_file(const char *reference)
 {
        struct lock_file lock = LOCK_INIT;
-       char *alts = git_pathdup("objects/info/alternates");
+       char *alts = repo_git_path(the_repository, "objects/info/alternates");
        FILE *in, *out;
        int found = 0;
 
diff --git a/path.h b/path.h
index 8798db74694b23e3500e1d5a2038727587946b55..65a8f21c4cee6024435b412129f43b3f83862d7d 100644 (file)
--- a/path.h
+++ b/path.h
@@ -292,24 +292,10 @@ static inline const char *git_path(const char *fmt, ...)
        { \
                static char *ret; \
                if (!ret) \
-                       ret = git_pathdup(filename); \
+                       ret = repo_git_path(the_repository, filename); \
                return ret; \
        }
 
-/*
- * Return a path into the main repository's (the_repository) git directory.
- */
-__attribute__((format (printf, 1, 2)))
-static inline char *git_pathdup(const char *fmt, ...)
-{
-       struct strbuf path = STRBUF_INIT;
-       va_list args;
-       va_start(args, fmt);
-       repo_git_pathv(the_repository, NULL, &path, fmt, args);
-       va_end(args);
-       return strbuf_detach(&path, NULL);
-}
-
 # endif /* USE_THE_REPOSITORY_VARIABLE */
 
 #endif /* PATH_H */