Skip to content

Commit 909a2bf

Browse files
pks-tgitster
authored andcommitted
config: introduce missing setters that take repo as parameter
While we already provide some of the config-setting interfaces with a `struct repository` as parameter, others only have a variant that implicitly depends on `the_repository`. Fill in those gaps such that we can start to deprecate the repo-less variants. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7ac1664 commit 909a2bf

File tree

2 files changed

+87
-21
lines changed

2 files changed

+87
-21
lines changed

config.c

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3178,21 +3178,39 @@ static void maybe_remove_section(struct config_store_data *store,
31783178
*end_offset = store->parsed[store->parsed_nr - 1].end;
31793179
}
31803180

3181+
int repo_config_set_in_file_gently(struct repository *r, const char *config_filename,
3182+
const char *key, const char *comment, const char *value)
3183+
{
3184+
return repo_config_set_multivar_in_file_gently(r, config_filename, key, value, NULL, comment, 0);
3185+
}
3186+
31813187
int git_config_set_in_file_gently(const char *config_filename,
31823188
const char *key, const char *comment, const char *value)
31833189
{
3184-
return git_config_set_multivar_in_file_gently(config_filename, key, value, NULL, comment, 0);
3190+
return repo_config_set_in_file_gently(the_repository, config_filename,
3191+
key, comment, value);
3192+
}
3193+
3194+
void repo_config_set_in_file(struct repository *r, const char *config_filename,
3195+
const char *key, const char *value)
3196+
{
3197+
repo_config_set_multivar_in_file(r, config_filename, key, value, NULL, 0);
31853198
}
31863199

31873200
void git_config_set_in_file(const char *config_filename,
31883201
const char *key, const char *value)
31893202
{
3190-
git_config_set_multivar_in_file(config_filename, key, value, NULL, 0);
3203+
repo_config_set_in_file(the_repository, config_filename, key, value);
3204+
}
3205+
3206+
int repo_config_set_gently(struct repository *r, const char *key, const char *value)
3207+
{
3208+
return repo_config_set_multivar_gently(r, key, value, NULL, 0);
31913209
}
31923210

31933211
int git_config_set_gently(const char *key, const char *value)
31943212
{
3195-
return git_config_set_multivar_gently(key, value, NULL, 0);
3213+
return repo_config_set_gently(the_repository, key, value);
31963214
}
31973215

31983216
int repo_config_set_worktree_gently(struct repository *r,
@@ -3209,13 +3227,18 @@ int repo_config_set_worktree_gently(struct repository *r,
32093227
return repo_config_set_multivar_gently(r, key, value, NULL, 0);
32103228
}
32113229

3212-
void git_config_set(const char *key, const char *value)
3230+
void repo_config_set(struct repository *r, const char *key, const char *value)
32133231
{
3214-
git_config_set_multivar(key, value, NULL, 0);
3232+
repo_config_set_multivar(r, key, value, NULL, 0);
32153233

32163234
trace2_cmd_set_config(key, value);
32173235
}
32183236

3237+
void git_config_set(const char *key, const char *value)
3238+
{
3239+
repo_config_set(the_repository, key, value);
3240+
}
3241+
32193242
char *git_config_prepare_comment_string(const char *comment)
32203243
{
32213244
size_t leading_blanks;
@@ -3293,11 +3316,12 @@ static void validate_comment_string(const char *comment)
32933316
* - the config file is removed and the lock file rename()d to it.
32943317
*
32953318
*/
3296-
int git_config_set_multivar_in_file_gently(const char *config_filename,
3297-
const char *key, const char *value,
3298-
const char *value_pattern,
3299-
const char *comment,
3300-
unsigned flags)
3319+
int repo_config_set_multivar_in_file_gently(struct repository *r,
3320+
const char *config_filename,
3321+
const char *key, const char *value,
3322+
const char *value_pattern,
3323+
const char *comment,
3324+
unsigned flags)
33013325
{
33023326
int fd = -1, in_fd = -1;
33033327
int ret;
@@ -3317,7 +3341,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
33173341
store.multi_replace = (flags & CONFIG_FLAGS_MULTI_REPLACE) != 0;
33183342

33193343
if (!config_filename)
3320-
config_filename = filename_buf = git_pathdup("config");
3344+
config_filename = filename_buf = repo_git_path(r, "config");
33213345

33223346
/*
33233347
* The lock serves a purpose in addition to locking: the new
@@ -3526,7 +3550,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
35263550
ret = 0;
35273551

35283552
/* Invalidate the config cache */
3529-
git_config_clear();
3553+
repo_config_clear(r);
35303554

35313555
out_free:
35323556
rollback_lock_file(&lock);
@@ -3543,19 +3567,39 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
35433567
goto out_free;
35443568
}
35453569

3546-
void git_config_set_multivar_in_file(const char *config_filename,
3547-
const char *key, const char *value,
3548-
const char *value_pattern, unsigned flags)
3570+
int git_config_set_multivar_in_file_gently(const char *config_filename,
3571+
const char *key, const char *value,
3572+
const char *value_pattern,
3573+
const char *comment,
3574+
unsigned flags)
35493575
{
3550-
if (!git_config_set_multivar_in_file_gently(config_filename, key, value,
3551-
value_pattern, NULL, flags))
3576+
return repo_config_set_multivar_in_file_gently(the_repository, config_filename,
3577+
key, value, value_pattern,
3578+
comment, flags);
3579+
}
3580+
3581+
void repo_config_set_multivar_in_file(struct repository *r,
3582+
const char *config_filename,
3583+
const char *key, const char *value,
3584+
const char *value_pattern, unsigned flags)
3585+
{
3586+
if (!repo_config_set_multivar_in_file_gently(r, config_filename, key, value,
3587+
value_pattern, NULL, flags))
35523588
return;
35533589
if (value)
35543590
die(_("could not set '%s' to '%s'"), key, value);
35553591
else
35563592
die(_("could not unset '%s'"), key);
35573593
}
35583594

3595+
void git_config_set_multivar_in_file(const char *config_filename,
3596+
const char *key, const char *value,
3597+
const char *value_pattern, unsigned flags)
3598+
{
3599+
repo_config_set_multivar_in_file(the_repository, config_filename,
3600+
key, value, value_pattern, flags);
3601+
}
3602+
35593603
int git_config_set_multivar_gently(const char *key, const char *value,
35603604
const char *value_pattern, unsigned flags)
35613605
{
@@ -3576,12 +3620,21 @@ int repo_config_set_multivar_gently(struct repository *r, const char *key,
35763620
return res;
35773621
}
35783622

3623+
void repo_config_set_multivar(struct repository *r,
3624+
const char *key, const char *value,
3625+
const char *value_pattern, unsigned flags)
3626+
{
3627+
char *file = repo_git_path(r, "config");
3628+
git_config_set_multivar_in_file(file, key, value,
3629+
value_pattern, flags);
3630+
free(file);
3631+
}
3632+
35793633
void git_config_set_multivar(const char *key, const char *value,
35803634
const char *value_pattern, unsigned flags)
35813635
{
3582-
git_config_set_multivar_in_file(git_path("config"),
3583-
key, value, value_pattern,
3584-
flags);
3636+
repo_config_set_multivar(the_repository, key, value,
3637+
value_pattern, flags);
35853638
}
35863639

35873640
static size_t section_name_match (const char *buf, const char *name)

config.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,18 @@ int git_config_pathname(char **, const char *, const char *);
298298
int git_config_expiry_date(timestamp_t *, const char *, const char *);
299299
int git_config_color(char *, const char *, const char *);
300300
int git_config_set_in_file_gently(const char *, const char *, const char *, const char *);
301+
int repo_config_set_in_file_gently(struct repository *r, const char *config_filename,
302+
const char *key, const char *comment, const char *value);
301303

302304
/**
303305
* write config values to a specific config file, takes a key/value pair as
304306
* parameter.
305307
*/
306308
void git_config_set_in_file(const char *, const char *, const char *);
309+
void repo_config_set_in_file(struct repository *, const char *, const char *, const char *);
307310

308311
int git_config_set_gently(const char *, const char *);
312+
int repo_config_set_gently(struct repository *r, const char *, const char *);
309313

310314
/**
311315
* Write a config value that should apply to the current worktree. If
@@ -318,6 +322,7 @@ int repo_config_set_worktree_gently(struct repository *, const char *, const cha
318322
* write config values to `.git/config`, takes a key/value pair as parameter.
319323
*/
320324
void git_config_set(const char *, const char *);
325+
void repo_config_set(struct repository *, const char *, const char *);
321326

322327
int git_config_parse_key(const char *, char **, size_t *);
323328

@@ -341,9 +346,11 @@ int git_config_parse_key(const char *, char **, size_t *);
341346
#define CONFIG_FLAGS_FIXED_VALUE (1 << 1)
342347

343348
int git_config_set_multivar_gently(const char *, const char *, const char *, unsigned);
344-
void git_config_set_multivar(const char *, const char *, const char *, unsigned);
345349
int repo_config_set_multivar_gently(struct repository *, const char *, const char *, const char *, unsigned);
350+
void git_config_set_multivar(const char *, const char *, const char *, unsigned);
351+
void repo_config_set_multivar(struct repository *r, const char *, const char *, const char *, unsigned);
346352
int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, const char *, unsigned);
353+
int repo_config_set_multivar_in_file_gently(struct repository *, const char *, const char *, const char *, const char *, const char *, unsigned);
347354

348355
char *git_config_prepare_comment_string(const char *);
349356

@@ -372,6 +379,12 @@ void git_config_set_multivar_in_file(const char *config_filename,
372379
const char *value,
373380
const char *value_pattern,
374381
unsigned flags);
382+
void repo_config_set_multivar_in_file(struct repository *r,
383+
const char *config_filename,
384+
const char *key,
385+
const char *value,
386+
const char *value_pattern,
387+
unsigned flags);
375388

376389
/**
377390
* rename or remove sections in the config file

0 commit comments

Comments
 (0)