]> git.ipfire.org Git - thirdparty/git.git/commitdiff
environment: make `get_graft_file()` accept a repository
authorPatrick Steinhardt <ps@pks.im>
Thu, 12 Sep 2024 11:29:35 +0000 (13:29 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 12 Sep 2024 17:15:40 +0000 (10:15 -0700)
The `get_graft_file()` function retrieves the path to the graft file of
`the_repository`. Make it accept a `struct repository` such that it can
work on arbitrary repositories and make it part of the repository
subsystem. This reduces our reliance on `the_repository` and clarifies
scope.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/replace.c
commit.c
environment.c
environment.h
repository.c
repository.h

index 34cc4672bc11a2aa94d0d387d175b044e7ab5fb0..01161350b1f80873addaadbbf043173db2c5aeb0 100644 (file)
@@ -11,7 +11,6 @@
 #include "builtin.h"
 #include "config.h"
 #include "editor.h"
-#include "environment.h"
 #include "gettext.h"
 #include "hex.h"
 #include "refs.h"
@@ -514,7 +513,7 @@ static int create_graft(int argc, const char **argv, int force, int gentle)
 
 static int convert_graft_file(int force)
 {
-       const char *graft_file = get_graft_file(the_repository);
+       const char *graft_file = repo_get_graft_file(the_repository);
        FILE *fp = fopen_or_warn(graft_file, "r");
        struct strbuf buf = STRBUF_INIT, err = STRBUF_INIT;
        struct strvec args = STRVEC_INIT;
index 3238772f521cbe82e6ae3a26f967bac5efc77a6f..1f710a92a1747dc9e309c639920c473e5ecf85c2 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -292,14 +292,14 @@ static int read_graft_file(struct repository *r, const char *graft_file)
 
 void prepare_commit_graft(struct repository *r)
 {
-       char *graft_file;
+       const char *graft_file;
 
        if (r->parsed_objects->commit_graft_prepared)
                return;
        if (!startup_info->have_repository)
                return;
 
-       graft_file = get_graft_file(r);
+       graft_file = repo_get_graft_file(r);
        read_graft_file(r, graft_file);
        /* make sure shallows are read */
        is_repository_shallow(r);
index 10ef77576c392ad0af3f4c3703d28aaba05a74f9..371f01a705dca69301e52500e94a6a71cd40a2b2 100644 (file)
@@ -306,13 +306,6 @@ int odb_pack_keep(const char *name)
        return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
 }
 
-char *get_graft_file(struct repository *r)
-{
-       if (!r->graft_file)
-               BUG("git environment hasn't been setup");
-       return r->graft_file;
-}
-
 static void set_git_dir_1(const char *path)
 {
        xsetenv(GIT_DIR_ENVIRONMENT, path, 1);
index ff590cfff73315191707ebf61e6e6e168ee4f206..d12c48481b62f7b887693d2b90901c48f28ff7ca 100644 (file)
@@ -1,7 +1,6 @@
 #ifndef ENVIRONMENT_H
 #define ENVIRONMENT_H
 
-struct repository;
 struct strvec;
 
 /*
@@ -106,7 +105,6 @@ int have_git_dir(void);
 extern int is_bare_repository_cfg;
 int is_bare_repository(void);
 extern char *git_work_tree_cfg;
-char *get_graft_file(struct repository *r);
 void set_git_dir(const char *path, int make_realpath);
 const char *get_git_namespace(void);
 const char *strip_namespace(const char *namespaced_ref);
index 849a912b03199f81527ac35cb99bcec2f6c2aeda..c2c231a7fd89f24cbd4e30e35c8401a4372b02ae 100644 (file)
@@ -119,6 +119,13 @@ const char *repo_get_index_file(struct repository *repo)
        return repo->index_file;
 }
 
+const char *repo_get_graft_file(struct repository *repo)
+{
+       if (!repo->graft_file)
+               BUG("repository hasn't been set up");
+       return repo->graft_file;
+}
+
 static void repo_set_commondir(struct repository *repo,
                               const char *commondir)
 {
index 15660ac2f19e7fea5930128f088544cf11536d2c..ad0f984b44493d5ba6cd7d673130eeb8160848e2 100644 (file)
@@ -210,6 +210,7 @@ const char *repo_get_git_dir(struct repository *repo);
 const char *repo_get_common_dir(struct repository *repo);
 const char *repo_get_object_directory(struct repository *repo);
 const char *repo_get_index_file(struct repository *repo);
+const char *repo_get_graft_file(struct repository *repo);
 
 /*
  * Define a custom repository layout. Any field can be NULL, which