Skip to content

Commit 14c90ac

Browse files
pks-tgitster
authored andcommitted
environment: make get_graft_file() accept a repository
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1dc4ec2 commit 14c90ac

File tree

6 files changed

+11
-13
lines changed

6 files changed

+11
-13
lines changed

builtin/replace.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "builtin.h"
1212
#include "config.h"
1313
#include "editor.h"
14-
#include "environment.h"
1514
#include "gettext.h"
1615
#include "hex.h"
1716
#include "refs.h"
@@ -514,7 +513,7 @@ static int create_graft(int argc, const char **argv, int force, int gentle)
514513

515514
static int convert_graft_file(int force)
516515
{
517-
const char *graft_file = get_graft_file(the_repository);
516+
const char *graft_file = repo_get_graft_file(the_repository);
518517
FILE *fp = fopen_or_warn(graft_file, "r");
519518
struct strbuf buf = STRBUF_INIT, err = STRBUF_INIT;
520519
struct strvec args = STRVEC_INIT;

commit.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,14 @@ static int read_graft_file(struct repository *r, const char *graft_file)
292292

293293
void prepare_commit_graft(struct repository *r)
294294
{
295-
char *graft_file;
295+
const char *graft_file;
296296

297297
if (r->parsed_objects->commit_graft_prepared)
298298
return;
299299
if (!startup_info->have_repository)
300300
return;
301301

302-
graft_file = get_graft_file(r);
302+
graft_file = repo_get_graft_file(r);
303303
read_graft_file(r, graft_file);
304304
/* make sure shallows are read */
305305
is_repository_shallow(r);

environment.c

-7
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,6 @@ int odb_pack_keep(const char *name)
306306
return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
307307
}
308308

309-
char *get_graft_file(struct repository *r)
310-
{
311-
if (!r->graft_file)
312-
BUG("git environment hasn't been setup");
313-
return r->graft_file;
314-
}
315-
316309
static void set_git_dir_1(const char *path)
317310
{
318311
xsetenv(GIT_DIR_ENVIRONMENT, path, 1);

environment.h

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef ENVIRONMENT_H
22
#define ENVIRONMENT_H
33

4-
struct repository;
54
struct strvec;
65

76
/*
@@ -106,7 +105,6 @@ int have_git_dir(void);
106105
extern int is_bare_repository_cfg;
107106
int is_bare_repository(void);
108107
extern char *git_work_tree_cfg;
109-
char *get_graft_file(struct repository *r);
110108
void set_git_dir(const char *path, int make_realpath);
111109
const char *get_git_namespace(void);
112110
const char *strip_namespace(const char *namespaced_ref);

repository.c

+7
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ const char *repo_get_index_file(struct repository *repo)
119119
return repo->index_file;
120120
}
121121

122+
const char *repo_get_graft_file(struct repository *repo)
123+
{
124+
if (!repo->graft_file)
125+
BUG("repository hasn't been set up");
126+
return repo->graft_file;
127+
}
128+
122129
static void repo_set_commondir(struct repository *repo,
123130
const char *commondir)
124131
{

repository.h

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ const char *repo_get_git_dir(struct repository *repo);
210210
const char *repo_get_common_dir(struct repository *repo);
211211
const char *repo_get_object_directory(struct repository *repo);
212212
const char *repo_get_index_file(struct repository *repo);
213+
const char *repo_get_graft_file(struct repository *repo);
213214

214215
/*
215216
* Define a custom repository layout. Any field can be NULL, which

0 commit comments

Comments
 (0)