]> git.ipfire.org Git - thirdparty/git.git/commitdiff
path: drop `git_path()` in favor of `repo_git_path()`
authorPatrick Steinhardt <ps@pks.im>
Fri, 7 Feb 2025 11:03:37 +0000 (12:03 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 28 Feb 2025 21:54:11 +0000 (13:54 -0800)
Remove `git_path()` in favor of the `repo_git_path()` family of
functions, which makes the implicit dependency on `the_repository` go
away.

Note that `git_path()` returned a string allocated via `get_pathname()`,
which uses a rotating set of statically allocated buffers. Consequently,
callers didn't have to free the returned string. The same isn't true for
`repo_common_path()`, so we also have to add logic to free the returned
strings.

This refactoring also allows us to remove `repo_common_pathv()` as well
as `get_pathname()` from the public interface.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
15 files changed:
builtin/commit.c
builtin/gc.c
builtin/notes.c
builtin/rebase.c
builtin/remote.c
builtin/rev-parse.c
builtin/worktree.c
notes-merge.c
path.c
path.h
read-cache.c
remote.c
rerere.c
shallow.c
wt-status.c

index 9fb405dd4a628de711ed429ca43e6105494dded4..2f459682221d6a12003918453a1f5bc17ea09a96 100644 (file)
@@ -352,6 +352,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
        struct pathspec pathspec;
        int refresh_flags = REFRESH_QUIET;
        const char *ret;
+       char *path = NULL;
 
        if (is_status)
                refresh_flags |= REFRESH_UNMERGED;
@@ -524,9 +525,9 @@ static const char *prepare_index(const char **argv, const char *prefix,
        if (write_locked_index(the_repository->index, &index_lock, 0))
                die(_("unable to write new index file"));
 
-       hold_lock_file_for_update(&false_lock,
-                                 git_path("next-index-%"PRIuMAX,
-                                          (uintmax_t) getpid()),
+       path = repo_git_path(the_repository, "next-index-%"PRIuMAX,
+                            (uintmax_t) getpid());
+       hold_lock_file_for_update(&false_lock, path,
                                  LOCK_DIE_ON_ERROR);
 
        create_base_index(current_head);
@@ -542,6 +543,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
 out:
        string_list_clear(&partial, 0);
        clear_pathspec(&pathspec);
+       free(path);
        return ret;
 }
 
index 57f6aee174fdb220dfbc9a151e5088a6fbef42c3..5923d9a05ba97dfbc98bc81a9ef2a077f602f9bf 100644 (file)
@@ -99,9 +99,11 @@ static void process_log_file(void)
                /* There was some error recorded in the lock file */
                commit_lock_file(&log_lock);
        } else {
+               char *path = repo_git_path(the_repository, "gc.log");
                /* No error, clean up any old gc.log */
-               unlink(git_path("gc.log"));
+               unlink(path);
                rollback_lock_file(&log_lock);
+               free(path);
        }
 }
 
@@ -299,8 +301,11 @@ static int too_many_loose_objects(struct gc_config *cfg)
        int num_loose = 0;
        int needed = 0;
        const unsigned hexsz_loose = the_hash_algo->hexsz - 2;
+       char *path;
 
-       dir = opendir(git_path("objects/17"));
+       path = repo_git_path(the_repository, "objects/17");
+       dir = opendir(path);
+       free(path);
        if (!dir)
                return 0;
 
@@ -821,11 +826,12 @@ struct repository *repo UNUSED)
        }
 
        if (daemonized) {
-               hold_lock_file_for_update(&log_lock,
-                                         git_path("gc.log"),
+               char *path = repo_git_path(the_repository, "gc.log");
+               hold_lock_file_for_update(&log_lock, path,
                                          LOCK_DIE_ON_ERROR);
                dup2(get_lock_file_fd(&log_lock), 2);
                atexit(process_log_file_at_exit);
+               free(path);
        }
 
        gc_before_repack(&opts, &cfg);
@@ -887,8 +893,11 @@ struct repository *repo UNUSED)
                warning(_("There are too many unreachable loose objects; "
                        "run 'git prune' to remove them."));
 
-       if (!daemonized)
-               unlink(git_path("gc.log"));
+       if (!daemonized) {
+               char *path = repo_git_path(the_repository, "gc.log");
+               unlink(path);
+               free(path);
+       }
 
 out:
        gc_config_release(&cfg);
index 18bcbb2f9134305792fea7139ef88c422d615cf8..ff61ec5f2da95377bd03d553db2d9dacfcd3f05f 100644 (file)
@@ -979,6 +979,8 @@ static int merge(int argc, const char **argv, const char *prefix,
        else { /* Merge has unresolved conflicts */
                struct worktree **worktrees;
                const struct worktree *wt;
+               char *path;
+
                /* Update .git/NOTES_MERGE_PARTIAL with partial merge result */
                refs_update_ref(get_main_ref_store(the_repository), msg.buf,
                                "NOTES_MERGE_PARTIAL", &result_oid, NULL,
@@ -994,10 +996,13 @@ static int merge(int argc, const char **argv, const char *prefix,
                if (refs_update_symref(get_main_ref_store(the_repository), "NOTES_MERGE_REF", notes_ref, NULL))
                        die(_("failed to store link to current notes ref (%s)"),
                            notes_ref);
+
+               path = repo_git_path(the_repository, NOTES_MERGE_WORKTREE);
                fprintf(stderr, _("Automatic notes merge failed. Fix conflicts in %s "
                                  "and commit the result with 'git notes merge --commit', "
                                  "or abort the merge with 'git notes merge --abort'.\n"),
-                       git_path(NOTES_MERGE_WORKTREE));
+                       path);
+               free(path);
        }
 
        free_notes(t);
index 6c9eaf3788c900fb52cb15255ae02b65abb711e3..d4715ed35d77edf9065dec9a46ed433a30d7fd68 100644 (file)
@@ -644,7 +644,7 @@ static int run_am(struct rebase_options *opts)
                return run_command(&am);
        }
 
-       rebased_patches = xstrdup(git_path("rebased-patches"));
+       rebased_patches = repo_git_path(the_repository, "rebased-patches");
        format_patch.out = open(rebased_patches,
                                O_WRONLY | O_CREAT | O_TRUNC, 0666);
        if (format_patch.out < 0) {
index 71d84fb3cfbef21986a5ae64496eb6c1a7c604cf..0489fcc8f3331edd9bcda84db024343f2d646792 100644 (file)
@@ -644,9 +644,11 @@ static int migrate_file(struct remote *remote)
                git_config_set_multivar(buf.buf, remote->fetch.items[i].raw, "^$", 0);
 #ifndef WITH_BREAKING_CHANGES
        if (remote->origin == REMOTE_REMOTES)
-               unlink_or_warn(git_path("remotes/%s", remote->name));
+               unlink_or_warn(repo_git_path_replace(the_repository, &buf,
+                                                    "remotes/%s", remote->name));
        else if (remote->origin == REMOTE_BRANCHES)
-               unlink_or_warn(git_path("branches/%s", remote->name));
+               unlink_or_warn(repo_git_path_replace(the_repository, &buf,
+                                                    "branches/%s", remote->name));
 #endif /* WITH_BREAKING_CHANGES */
        strbuf_release(&buf);
 
index 428c866c05f4a47cef88ebcb1296facc46cbb143..490da33beccf72690ef61a092c957646ee639e9e 100644 (file)
@@ -789,8 +789,8 @@ int cmd_rev_parse(int argc,
                        if (!strcmp(arg, "--git-path")) {
                                if (!argv[i + 1])
                                        die(_("--git-path requires an argument"));
-                               strbuf_reset(&buf);
-                               print_path(git_path("%s", argv[i + 1]), prefix,
+                               print_path(repo_git_path_replace(the_repository, &buf,
+                                                                "%s", argv[i + 1]), prefix,
                                                format,
                                                DEFAULT_RELATIVE_IF_SHARED);
                                i++;
@@ -1083,7 +1083,7 @@ int cmd_rev_parse(int argc,
                                        die(_("Could not read the index"));
                                if (the_repository->index->split_index) {
                                        const struct object_id *oid = &the_repository->index->split_index->base_oid;
-                                       const char *path = git_path("sharedindex.%s", oid_to_hex(oid));
+                                       const char *path = repo_git_path_replace(the_repository, &buf, "sharedindex.%s", oid_to_hex(oid));
                                        print_path(path, prefix, format, DEFAULT_RELATIVE);
                                }
                                continue;
index 761e302a369e39ebb2d4fb744fe979b353eee6dd..48448a835509445acc104124eada94dab4b9cd43 100644 (file)
@@ -163,7 +163,9 @@ static int delete_git_dir(const char *id)
 
 static void delete_worktrees_dir_if_empty(void)
 {
-       rmdir(git_path("worktrees")); /* ignore failed removal */
+       char *path = repo_git_path(the_repository, "worktrees");
+       rmdir(path); /* ignore failed removal */
+       free(path);
 }
 
 static void prune_worktree(const char *id, const char *reason)
@@ -212,8 +214,13 @@ static void prune_worktrees(void)
        struct strbuf reason = STRBUF_INIT;
        struct strbuf main_path = STRBUF_INIT;
        struct string_list kept = STRING_LIST_INIT_DUP;
-       DIR *dir = opendir(git_path("worktrees"));
+       char *path;
+       DIR *dir;
        struct dirent *d;
+
+       path = repo_git_path(the_repository, "worktrees");
+       dir = opendir(path);
+       free(path);
        if (!dir)
                return;
        while ((d = readdir_skip_dot_and_dotdot(dir)) != NULL) {
index 8c22a171c147ba8489e20b103543bed577d4355c..67a472020dedd9ac6097d4f45606cd7651a0edcc 100644 (file)
@@ -275,34 +275,38 @@ static void diff_tree_local(struct notes_merge_options *o,
 
 static void check_notes_merge_worktree(struct notes_merge_options *o)
 {
+       struct strbuf buf = STRBUF_INIT;
+
        if (!o->has_worktree) {
                /*
                 * Must establish NOTES_MERGE_WORKTREE.
                 * Abort if NOTES_MERGE_WORKTREE already exists
                 */
-               if (file_exists(git_path(NOTES_MERGE_WORKTREE)) &&
-                   !is_empty_dir(git_path(NOTES_MERGE_WORKTREE))) {
+               if (file_exists(repo_git_path_replace(the_repository, &buf, NOTES_MERGE_WORKTREE)) &&
+                   !is_empty_dir(repo_git_path_replace(the_repository, &buf, NOTES_MERGE_WORKTREE))) {
                        if (advice_enabled(ADVICE_RESOLVE_CONFLICT))
                                die(_("You have not concluded your previous "
                                    "notes merge (%s exists).\nPlease, use "
                                    "'git notes merge --commit' or 'git notes "
                                    "merge --abort' to commit/abort the "
                                    "previous merge before you start a new "
-                                   "notes merge."), git_path("NOTES_MERGE_*"));
+                                   "notes merge."), repo_git_path_replace(the_repository, &buf, "NOTES_MERGE_*"));
                        else
                                die(_("You have not concluded your notes merge "
-                                   "(%s exists)."), git_path("NOTES_MERGE_*"));
+                                   "(%s exists)."), repo_git_path_replace(the_repository, &buf, "NOTES_MERGE_*"));
                }
 
-               if (safe_create_leading_directories_const(git_path(
+               if (safe_create_leading_directories_const(repo_git_path_replace(the_repository, &buf,
                                NOTES_MERGE_WORKTREE "/.test")))
                        die_errno("unable to create directory %s",
-                                 git_path(NOTES_MERGE_WORKTREE));
+                                 repo_git_path_replace(the_repository, &buf, NOTES_MERGE_WORKTREE));
                o->has_worktree = 1;
-       } else if (!file_exists(git_path(NOTES_MERGE_WORKTREE)))
+       } else if (!file_exists(repo_git_path_replace(the_repository, &buf, NOTES_MERGE_WORKTREE)))
                /* NOTES_MERGE_WORKTREE should already be established */
                die("missing '%s'. This should not happen",
-                   git_path(NOTES_MERGE_WORKTREE));
+                   repo_git_path_replace(the_repository, &buf, NOTES_MERGE_WORKTREE));
+
+       strbuf_release(&buf);
 }
 
 static void write_buf_to_worktree(const struct object_id *obj,
diff --git a/path.c b/path.c
index 2d07ba723dfd250504568fe8573470f4548254a1..a42f72800db6737cfa7356482d0c9f1b0ba23603 100644 (file)
--- a/path.c
+++ b/path.c
@@ -30,7 +30,7 @@ static int get_st_mode_bits(const char *path, int *mode)
        return 0;
 }
 
-struct strbuf *get_pathname(void)
+static struct strbuf *get_pathname(void)
 {
        static struct strbuf pathname_array[4] = {
                STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT
@@ -417,9 +417,9 @@ static void strbuf_worktree_gitdir(struct strbuf *buf,
                repo_common_path_append(repo, buf, "worktrees/%s", wt->id);
 }
 
-void repo_git_pathv(const struct repository *repo,
-                   const struct worktree *wt, struct strbuf *buf,
-                   const char *fmt, va_list args)
+static void repo_git_pathv(const struct repository *repo,
+                          const struct worktree *wt, struct strbuf *buf,
+                          const char *fmt, va_list args)
 {
        int gitdir_len;
        strbuf_worktree_gitdir(buf, repo, wt);
diff --git a/path.h b/path.h
index bed0a4c6f9eca38c450920a6dc8c8f0bdd64742c..f28d5a7ca9525c5325ab438e386e974733c19c8c 100644 (file)
--- a/path.h
+++ b/path.h
@@ -221,37 +221,10 @@ char *xdg_cache_home(const char *filename);
  */
 void safe_create_dir(const char *dir, int share);
 
-/*
- * Do not use this function. It is only exported to other subsystems until we
- * can get rid of the below block of functions that implicitly rely on
- * `the_repository`.
- */
-struct strbuf *get_pathname(void);
-
 # ifdef USE_THE_REPOSITORY_VARIABLE
 #  include "strbuf.h"
 #  include "repository.h"
 
-/* Internal implementation details that should not be used. */
-void repo_git_pathv(const struct repository *repo,
-                   const struct worktree *wt, struct strbuf *buf,
-                   const char *fmt, va_list args);
-
-/*
- * Return a statically allocated path into the main repository's
- * (the_repository) git directory.
- */
-__attribute__((format (printf, 1, 2)))
-static inline const char *git_path(const char *fmt, ...)
-{
-       struct strbuf *pathname = get_pathname();
-       va_list args;
-       va_start(args, fmt);
-       repo_git_pathv(the_repository, NULL, pathname, fmt, args);
-       va_end(args);
-       return pathname->buf;
-}
-
 #define GIT_PATH_FUNC(func, filename) \
        const char *func(void) \
        { \
index d54be2c17268728caf3e1e3ef94a5832d2cbfa60..66ad0015a7f75a44d444fe9411810a59e46ea941 100644 (file)
@@ -3251,15 +3251,18 @@ static int clean_shared_index_files(const char *current_hex)
 
        while ((de = readdir(dir)) != NULL) {
                const char *sha1_hex;
-               const char *shared_index_path;
+               char *shared_index_path;
                if (!skip_prefix(de->d_name, "sharedindex.", &sha1_hex))
                        continue;
                if (!strcmp(sha1_hex, current_hex))
                        continue;
-               shared_index_path = git_path("%s", de->d_name);
+
+               shared_index_path = repo_git_path(the_repository, "%s", de->d_name);
                if (should_delete_shared_index(shared_index_path) > 0 &&
                    unlink(shared_index_path))
                        warning_errno(_("unable to unlink: %s"), shared_index_path);
+
+               free(shared_index_path);
        }
        closedir(dir);
 
@@ -3271,6 +3274,7 @@ static int write_shared_index(struct index_state *istate,
 {
        struct split_index *si = istate->split_index;
        int ret, was_full = !istate->sparse_index;
+       char *path;
 
        move_cache_to_base_index(istate);
        convert_to_sparse(istate, 0);
@@ -3291,13 +3295,15 @@ static int write_shared_index(struct index_state *istate,
                error(_("cannot fix permission bits on '%s'"), get_tempfile_path(*temp));
                return ret;
        }
-       ret = rename_tempfile(temp,
-                             git_path("sharedindex.%s", oid_to_hex(&si->base->oid)));
+
+       path = repo_git_path(the_repository, "sharedindex.%s", oid_to_hex(&si->base->oid));
+       ret = rename_tempfile(temp, path);
        if (!ret) {
                oidcpy(&si->base_oid, &si->base->oid);
                clean_shared_index_files(oid_to_hex(&si->base->oid));
        }
 
+       free(path);
        return ret;
 }
 
@@ -3378,9 +3384,12 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
        if (new_shared_index) {
                struct tempfile *temp;
                int saved_errno;
+               char *path;
 
                /* Same initial permissions as the main .git/index file */
-               temp = mks_tempfile_sm(git_path("sharedindex_XXXXXX"), 0, 0666);
+               path = repo_git_path(the_repository, "sharedindex_XXXXXX");
+               temp = mks_tempfile_sm(path, 0, 0666);
+               free(path);
                if (!temp) {
                        ret = do_write_locked_index(istate, lock, flags,
                                                    ~WRITE_SPLIT_INDEX_EXTENSION);
@@ -3401,9 +3410,10 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
 
        /* Freshen the shared index only if the split-index was written */
        if (!ret && !new_shared_index && !is_null_oid(&si->base_oid)) {
-               const char *shared_index = git_path("sharedindex.%s",
-                                                   oid_to_hex(&si->base_oid));
+               char *shared_index = repo_git_path(the_repository, "sharedindex.%s",
+                                                  oid_to_hex(&si->base_oid));
                freshen_shared_index(shared_index, 1);
+               free(shared_index);
        }
 
 out:
index 1779f0e7bbb8b88965f2fedf407e50ed20ea7a13..81d151a507b1b7b87ff53d158462d843ba3fee0d 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -321,10 +321,11 @@ static void read_remotes_file(struct remote_state *remote_state,
                              struct remote *remote)
 {
        struct strbuf buf = STRBUF_INIT;
-       FILE *f = fopen_or_warn(git_path("remotes/%s", remote->name), "r");
+       FILE *f = fopen_or_warn(repo_git_path_append(the_repository, &buf,
+                                                    "remotes/%s", remote->name), "r");
 
        if (!f)
-               return;
+               goto out;
 
        warn_about_deprecated_remote_type("remotes", remote);
 
@@ -343,8 +344,10 @@ static void read_remotes_file(struct remote_state *remote_state,
                else if (skip_prefix(buf.buf, "Pull:", &v))
                        refspec_append(&remote->fetch, skip_spaces(v));
        }
-       strbuf_release(&buf);
        fclose(f);
+
+out:
+       strbuf_release(&buf);
 }
 
 static void read_branches_file(struct remote_state *remote_state,
@@ -352,20 +355,19 @@ static void read_branches_file(struct remote_state *remote_state,
 {
        char *frag, *to_free = NULL;
        struct strbuf buf = STRBUF_INIT;
-       FILE *f = fopen_or_warn(git_path("branches/%s", remote->name), "r");
+       FILE *f = fopen_or_warn(repo_git_path_append(the_repository, &buf,
+                                                    "branches/%s", remote->name), "r");
 
        if (!f)
-               return;
+               goto out;
 
        warn_about_deprecated_remote_type("branches", remote);
 
        strbuf_getline_lf(&buf, f);
        fclose(f);
        strbuf_trim(&buf);
-       if (!buf.len) {
-               strbuf_release(&buf);
-               return;
-       }
+       if (!buf.len)
+               goto out;
 
        remote->configured_in_repo = 1;
        remote->origin = REMOTE_BRANCHES;
@@ -393,6 +395,7 @@ static void read_branches_file(struct remote_state *remote_state,
        refspec_appendf(&remote->push, "HEAD:refs/heads/%s", frag);
        remote->fetch_tags = 1; /* always auto-follow */
 
+out:
        strbuf_release(&buf);
        free(to_free);
 }
index 6dd6b959b52d828889367719bd404a2562b078fb..6bd395bebee5e7cd81163d19c587b146ed4fb39a 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -127,8 +127,12 @@ static int is_rr_file(const char *name, const char *filename, int *variant)
 static void scan_rerere_dir(struct rerere_dir *rr_dir)
 {
        struct dirent *de;
-       DIR *dir = opendir(git_path("rr-cache/%s", rr_dir->name));
+       char *path;
+       DIR *dir;
 
+       path = repo_git_path(the_repository, "rr-cache/%s", rr_dir->name);
+       dir = opendir(path);
+       free(path);
        if (!dir)
                return;
        while ((de = readdir(dir)) != NULL) {
@@ -1234,6 +1238,7 @@ void rerere_gc(struct repository *r, struct string_list *rr)
        timestamp_t now = time(NULL);
        timestamp_t cutoff_noresolve = now - 15 * 86400;
        timestamp_t cutoff_resolve = now - 60 * 86400;
+       struct strbuf buf = STRBUF_INIT;
 
        if (setup_rerere(r, rr, 0) < 0)
                return;
@@ -1243,7 +1248,7 @@ void rerere_gc(struct repository *r, struct string_list *rr)
        repo_config_get_expiry_in_days(the_repository, "gc.rerereunresolved",
                                       &cutoff_noresolve, now);
        git_config(git_default_config, NULL);
-       dir = opendir(git_path("rr-cache"));
+       dir = opendir(repo_git_path_replace(the_repository, &buf, "rr-cache"));
        if (!dir)
                die_errno(_("unable to open rr-cache directory"));
        /* Collect stale conflict IDs ... */
@@ -1272,9 +1277,12 @@ void rerere_gc(struct repository *r, struct string_list *rr)
 
        /* ... and then remove the empty directories */
        for (i = 0; i < to_remove.nr; i++)
-               rmdir(git_path("rr-cache/%s", to_remove.items[i].string));
+               rmdir(repo_git_path_replace(the_repository, &buf,
+                                           "rr-cache/%s", to_remove.items[i].string));
+
        string_list_clear(&to_remove, 0);
        rollback_lock_file(&write_lock);
+       strbuf_release(&buf);
 }
 
 /*
index b54244ffa90d66a35fef51f2ac8d5ab8144fa9b8..4bd9342c9a745a5f4c2723986cf25662354e4752 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -364,7 +364,9 @@ const char *setup_temporary_shallow(const struct oid_array *extra)
        struct strbuf sb = STRBUF_INIT;
 
        if (write_shallow_commits(&sb, 0, extra)) {
-               temp = xmks_tempfile(git_path("shallow_XXXXXX"));
+               char *path = repo_git_path(the_repository, "shallow_XXXXXX");
+               temp = xmks_tempfile(path);
+               free(path);
 
                if (write_in_full(temp->fd, sb.buf, sb.len) < 0 ||
                    close_tempfile_gently(temp) < 0)
index 3ee918176422c7c8c045fadae67c39a7d57e987e..1da5732f57b1154be731025728be752ccf2946c7 100644 (file)
@@ -1289,7 +1289,8 @@ static void show_am_in_progress(struct wt_status *s,
 static char *read_line_from_git_path(const char *filename)
 {
        struct strbuf buf = STRBUF_INIT;
-       FILE *fp = fopen_or_warn(git_path("%s", filename), "r");
+       FILE *fp = fopen_or_warn(repo_git_path_append(the_repository, &buf,
+                                                     "%s", filename), "r");
 
        if (!fp) {
                strbuf_release(&buf);
@@ -1383,27 +1384,33 @@ static void abbrev_oid_in_line(struct strbuf *line)
 
 static int read_rebase_todolist(const char *fname, struct string_list *lines)
 {
-       struct strbuf line = STRBUF_INIT;
-       FILE *f = fopen(git_path("%s", fname), "r");
+       struct strbuf buf = STRBUF_INIT;
+       FILE *f = fopen(repo_git_path_append(the_repository, &buf, "%s", fname), "r");
+       int ret;
 
        if (!f) {
-               if (errno == ENOENT)
-                       return -1;
+               if (errno == ENOENT) {
+                       ret = -1;
+                       goto out;
+               }
                die_errno("Could not open file %s for reading",
-                         git_path("%s", fname));
+                         repo_git_path_replace(the_repository, &buf, "%s", fname));
        }
-       while (!strbuf_getline_lf(&line, f)) {
-               if (starts_with(line.buf, comment_line_str))
+       while (!strbuf_getline_lf(&buf, f)) {
+               if (starts_with(buf.buf, comment_line_str))
                        continue;
-               strbuf_trim(&line);
-               if (!line.len)
+               strbuf_trim(&buf);
+               if (!buf.len)
                        continue;
-               abbrev_oid_in_line(&line);
-               string_list_append(lines, line.buf);
+               abbrev_oid_in_line(&buf);
+               string_list_append(lines, buf.buf);
        }
        fclose(f);
-       strbuf_release(&line);
-       return 0;
+
+       ret = 0;
+out:
+       strbuf_release(&buf);
+       return ret;
 }
 
 static void show_rebase_information(struct wt_status *s,
@@ -1434,9 +1441,12 @@ static void show_rebase_information(struct wt_status *s,
                                i < have_done.nr;
                                i++)
                                status_printf_ln(s, color, "   %s", have_done.items[i].string);
-                       if (have_done.nr > nr_lines_to_show && s->hints)
+                       if (have_done.nr > nr_lines_to_show && s->hints) {
+                               char *path = repo_git_path(the_repository, "rebase-merge/done");
                                status_printf_ln(s, color,
-                                       _("  (see more in file %s)"), git_path("rebase-merge/done"));
+                                       _("  (see more in file %s)"), path);
+                               free(path);
+                       }
                }
 
                if (yet_to_do.nr == 0)