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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Aug 13, 2024 at 11:13 UTC
909a2bfb1ff29df388be58b777c4c71186a3e90f
2 files changed
+87
-21
config.c
+73
-20
@@ -3178,21 +3178,39 @@ static void maybe_remove_section(struct config_store_data *store,
3178
*end_offset = store->parsed[store->parsed_nr - 1].end;
3179
}
3180
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
+
3187
int git_config_set_in_file_gently(const char *config_filename,
3188
const char *key, const char *comment, const char *value)
3189
{
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);
3198
}
3199
3200
void git_config_set_in_file(const char *config_filename,
3201
const char *key, const char *value)
3202
{
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);
3209
}
3210
3211
int git_config_set_gently(const char *key, const char *value)
3212
{
3195
- return git_config_set_multivar_gently(key, value, NULL, 0);
3213
+ return repo_config_set_gently(the_repository, key, value);
3214
}
3215
3216
int repo_config_set_worktree_gently(struct repository *r,
@@ -3209,13 +3227,18 @@ int repo_config_set_worktree_gently(struct repository *r,
3227
return repo_config_set_multivar_gently(r, key, value, NULL, 0);
3228
}
3229
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)
3231
{
3214
- git_config_set_multivar(key, value, NULL, 0);
3232
+ repo_config_set_multivar(r, key, value, NULL, 0);
3233
3234
trace2_cmd_set_config(key, value);
3235
}
3236
3237
+void git_config_set(const char *key, const char *value)
3238
+{
3239
+ repo_config_set(the_repository, key, value);
3240
+}
3241
+
3242
char *git_config_prepare_comment_string(const char *comment)
3243
{
3244
size_t leading_blanks;
@@ -3293,11 +3316,12 @@ static void validate_comment_string(const char *comment)
3316
* - the config file is removed and the lock file rename()d to it.
3317
*
3318
*/
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)
3325
{
3326
int fd = -1, in_fd = -1;
3327
int ret;
@@ -3317,7 +3341,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
3341
store.multi_replace = (flags & CONFIG_FLAGS_MULTI_REPLACE) != 0;
3342
3343
if (!config_filename)
3320
- config_filename = filename_buf = git_pathdup("config");
3344
+ config_filename = filename_buf = repo_git_path(r, "config");
3345
3346
/*
3347
* 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,
3550
ret = 0;
3551
3552
/* Invalidate the config cache */
3529
- git_config_clear();
3553
+ repo_config_clear(r);
3554
3555
out_free:
3556
rollback_lock_file(&lock);
@@ -3543,12 +3567,24 @@ write_err_out:
3567
goto out_free;
3568
}
3569
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)
3575
{
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))
3588
return;
3589
if (value)
3590
die(_("could not set '%s' to '%s'"), key, value);
@@ -3556,6 +3592,14 @@ void git_config_set_multivar_in_file(const char *config_filename,
3592
die(_("could not unset '%s'"), key);
3593
}
3594
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
+
3603
int git_config_set_multivar_gently(const char *key, const char *value,
3604
const char *value_pattern, unsigned flags)
3605
{
@@ -3576,12 +3620,21 @@ int repo_config_set_multivar_gently(struct repository *r, const char *key,
3620
return res;
3621
}
3622
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
+
3633
void git_config_set_multivar(const char *key, const char *value,
3634
const char *value_pattern, unsigned flags)
3635
{
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);
3638
}
3639
3640
static size_t section_name_match (const char *buf, const char *name)
config.h
+14
-1
@@ -298,14 +298,18 @@ int git_config_pathname(char **, const char *, const char *);
298
int git_config_expiry_date(timestamp_t *, const char *, const char *);
299
int git_config_color(char *, const char *, const char *);
300
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);
303
304
/**
305
* write config values to a specific config file, takes a key/value pair as
306
* parameter.
307
*/
308
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 *);
310
311
int git_config_set_gently(const char *, const char *);
312
+int repo_config_set_gently(struct repository *r, const char *, const char *);
313
314
/**
315
* 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
322
* write config values to `.git/config`, takes a key/value pair as parameter.
323
*/
324
void git_config_set(const char *, const char *);
325
+void repo_config_set(struct repository *, const char *, const char *);
326
327
int git_config_parse_key(const char *, char **, size_t *);
328
@@ -341,9 +346,11 @@ int git_config_parse_key(const char *, char **, size_t *);
346
#define CONFIG_FLAGS_FIXED_VALUE (1 << 1)
347
348
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);
349
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);
352
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);
354
355
char *git_config_prepare_comment_string(const char *);
356
@@ -372,6 +379,12 @@ void git_config_set_multivar_in_file(const char *config_filename,
379
const char *value,
380
const char *value_pattern,
381
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);
388
389
/**
390
* rename or remove sections in the config file