* [PATCH v2 01/11] daemon.c: replace `git_config()` with `git_config_get_bool()` family
2014-08-07 16:21 [PATCH v2 00/11] git_config callers rewritten with the new config-set API Tanay Abhra
@ 2014-08-07 16:21 ` Tanay Abhra
2014-08-07 16:21 ` [PATCH v2 02/11] http-backend.c: " Tanay Abhra
` (11 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Tanay Abhra @ 2014-08-07 16:21 UTC (permalink / raw)
To: git; +Cc: Tanay Abhra, Matthieu Moy, Ramkumar Ramachandra
Use `git_config_get_bool()` family instead of `git_config()` to take advantage of
the config-set API which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
daemon.c | 26 ++++----------------------
1 file changed, 4 insertions(+), 22 deletions(-)
diff --git a/daemon.c b/daemon.c
index e6b51ed..6f78b61 100644
--- a/daemon.c
+++ b/daemon.c
@@ -230,23 +230,6 @@ struct daemon_service {
int overridable;
};
-static struct daemon_service *service_looking_at;
-static int service_enabled;
-
-static int git_daemon_config(const char *var, const char *value, void *cb)
-{
- const char *service;
-
- if (skip_prefix(var, "daemon.", &service) &&
- !strcmp(service, service_looking_at->config_name)) {
- service_enabled = git_config_bool(var, value);
- return 0;
- }
-
- /* we are not interested in parsing any other configuration here */
- return 0;
-}
-
static int daemon_error(const char *dir, const char *msg)
{
if (!informative_errors)
@@ -324,6 +307,7 @@ static int run_service(const char *dir, struct daemon_service *service)
{
const char *path;
int enabled = service->enabled;
+ struct strbuf var = STRBUF_INIT;
loginfo("Request %s for '%s'", service->name, dir);
@@ -354,11 +338,9 @@ static int run_service(const char *dir, struct daemon_service *service)
}
if (service->overridable) {
- service_looking_at = service;
- service_enabled = -1;
- git_config(git_daemon_config, NULL);
- if (0 <= service_enabled)
- enabled = service_enabled;
+ strbuf_addf(&var, "daemon.%s", service->config_name);
+ git_config_get_bool(var.buf, &enabled);
+ strbuf_release(&var);
}
if (!enabled) {
logerror("'%s': service not enabled for '%s'",
--
1.9.0.GIT
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 02/11] http-backend.c: replace `git_config()` with `git_config_get_bool()` family
2014-08-07 16:21 [PATCH v2 00/11] git_config callers rewritten with the new config-set API Tanay Abhra
2014-08-07 16:21 ` [PATCH v2 01/11] daemon.c: replace `git_config()` with `git_config_get_bool()` family Tanay Abhra
@ 2014-08-07 16:21 ` Tanay Abhra
2014-08-07 16:21 ` [PATCH v2 03/11] read-cache.c: replace `git_config()` with `git_config_get_*()` family Tanay Abhra
` (10 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Tanay Abhra @ 2014-08-07 16:21 UTC (permalink / raw)
To: git; +Cc: Tanay Abhra, Matthieu Moy, Ramkumar Ramachandra
Use `git_config_get_bool()` family instead of `git_config()` to take advantage of
the config-set API which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
http-backend.c | 31 ++++++++++++-------------------
1 file changed, 12 insertions(+), 19 deletions(-)
diff --git a/http-backend.c b/http-backend.c
index 80790bb..106ca6b 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -219,29 +219,22 @@ static void get_idx_file(char *name)
send_local_file("application/x-git-packed-objects-toc", name);
}
-static int http_config(const char *var, const char *value, void *cb)
+static void http_config(void)
{
- const char *p;
+ int i, value = 0;
+ struct strbuf var = STRBUF_INIT;
- if (!strcmp(var, "http.getanyfile")) {
- getanyfile = git_config_bool(var, value);
- return 0;
- }
+ git_config_get_bool("http.getanyfile", &getanyfile);
- if (skip_prefix(var, "http.", &p)) {
- int i;
-
- for (i = 0; i < ARRAY_SIZE(rpc_service); i++) {
- struct rpc_service *svc = &rpc_service[i];
- if (!strcmp(p, svc->config_name)) {
- svc->enabled = git_config_bool(var, value);
- return 0;
- }
- }
+ for (i = 0; i < ARRAY_SIZE(rpc_service); i++) {
+ struct rpc_service *svc = &rpc_service[i];
+ strbuf_addf(&var, "http.%s", svc->config_name);
+ if (!git_config_get_bool(var.buf, &value))
+ svc->enabled = value;
+ strbuf_reset(&var);
}
- /* we are not interested in parsing any other configuration here */
- return 0;
+ strbuf_release(&var);
}
static struct rpc_service *select_service(const char *name)
@@ -627,7 +620,7 @@ int main(int argc, char **argv)
access("git-daemon-export-ok", F_OK) )
not_found("Repository not exported: '%s'", dir);
- git_config(http_config, NULL);
+ http_config();
cmd->imp(cmd_arg);
return 0;
}
--
1.9.0.GIT
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 03/11] read-cache.c: replace `git_config()` with `git_config_get_*()` family
2014-08-07 16:21 [PATCH v2 00/11] git_config callers rewritten with the new config-set API Tanay Abhra
2014-08-07 16:21 ` [PATCH v2 01/11] daemon.c: replace `git_config()` with `git_config_get_bool()` family Tanay Abhra
2014-08-07 16:21 ` [PATCH v2 02/11] http-backend.c: " Tanay Abhra
@ 2014-08-07 16:21 ` Tanay Abhra
2014-08-07 16:21 ` [PATCH v2 04/11] archive.c: replace `git_config()` with `git_config_get_bool()` family Tanay Abhra
` (9 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Tanay Abhra @ 2014-08-07 16:21 UTC (permalink / raw)
To: git; +Cc: Tanay Abhra, Matthieu Moy, Ramkumar Ramachandra
Use `git_config_get_*()` family instead of `git_config()` to take
advantage of the config-set API which provides a cleaner control flow.
Use an intermediate value, as `version` can not be used directly in
git_config_get_int() due to incompatible type.
Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
read-cache.c | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index 5d3c8bd..acb132d 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1238,24 +1238,16 @@ static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
#define INDEX_FORMAT_DEFAULT 3
-static int index_format_config(const char *var, const char *value, void *cb)
-{
- unsigned int *version = cb;
- if (!strcmp(var, "index.version")) {
- *version = git_config_int(var, value);
- return 0;
- }
- return 1;
-}
-
static unsigned int get_index_format_default(void)
{
char *envversion = getenv("GIT_INDEX_VERSION");
char *endp;
+ int value;
unsigned int version = INDEX_FORMAT_DEFAULT;
if (!envversion) {
- git_config(index_format_config, &version);
+ if (!git_config_get_int("index.version", &value))
+ version = value;
if (version < INDEX_FORMAT_LB || INDEX_FORMAT_UB < version) {
warning(_("index.version set, but the value is invalid.\n"
"Using version %i"), INDEX_FORMAT_DEFAULT);
--
1.9.0.GIT
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 04/11] archive.c: replace `git_config()` with `git_config_get_bool()` family
2014-08-07 16:21 [PATCH v2 00/11] git_config callers rewritten with the new config-set API Tanay Abhra
` (2 preceding siblings ...)
2014-08-07 16:21 ` [PATCH v2 03/11] read-cache.c: replace `git_config()` with `git_config_get_*()` family Tanay Abhra
@ 2014-08-07 16:21 ` Tanay Abhra
2014-08-07 16:21 ` [PATCH v2 05/11] fetchpack.c: replace `git_config()` with `git_config_get_*()` family Tanay Abhra
` (8 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Tanay Abhra @ 2014-08-07 16:21 UTC (permalink / raw)
To: git; +Cc: Tanay Abhra, Matthieu Moy, Ramkumar Ramachandra
Use `git_config_get_bool()` family instead of `git_config()` to take advantage of
the config-set API which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
archive.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/archive.c b/archive.c
index 3fc0fb2..952a659 100644
--- a/archive.c
+++ b/archive.c
@@ -402,14 +402,6 @@ static int parse_archive_args(int argc, const char **argv,
return argc;
}
-static int git_default_archive_config(const char *var, const char *value,
- void *cb)
-{
- if (!strcmp(var, "uploadarchive.allowunreachable"))
- remote_allow_unreachable = git_config_bool(var, value);
- return git_default_config(var, value, cb);
-}
-
int write_archive(int argc, const char **argv, const char *prefix,
int setup_prefix, const char *name_hint, int remote)
{
@@ -420,7 +412,9 @@ int write_archive(int argc, const char **argv, const char *prefix,
if (setup_prefix && prefix == NULL)
prefix = setup_git_directory_gently(&nongit);
- git_config(git_default_archive_config, NULL);
+ git_config_get_bool("uploadarchive.allowunreachable", &remote_allow_unreachable);
+ git_config(git_default_config, NULL);
+
init_tar_archiver();
init_zip_archiver();
--
1.9.0.GIT
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 05/11] fetchpack.c: replace `git_config()` with `git_config_get_*()` family
2014-08-07 16:21 [PATCH v2 00/11] git_config callers rewritten with the new config-set API Tanay Abhra
` (3 preceding siblings ...)
2014-08-07 16:21 ` [PATCH v2 04/11] archive.c: replace `git_config()` with `git_config_get_bool()` family Tanay Abhra
@ 2014-08-07 16:21 ` Tanay Abhra
2014-08-07 16:21 ` [PATCH v2 06/11] rerere.c: " Tanay Abhra
` (7 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Tanay Abhra @ 2014-08-07 16:21 UTC (permalink / raw)
To: git; +Cc: Tanay Abhra, Matthieu Moy, Ramkumar Ramachandra
Use `git_config_get_*()` family instead of `git_config()` to take advantage of
the config-set API which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
fetch-pack.c | 35 ++++++++---------------------------
1 file changed, 8 insertions(+), 27 deletions(-)
diff --git a/fetch-pack.c b/fetch-pack.c
index b8a58fa..a13e9db 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -869,34 +869,15 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
return ref;
}
-static int fetch_pack_config(const char *var, const char *value, void *cb)
+static void fetch_pack_config(void)
{
- if (strcmp(var, "fetch.unpacklimit") == 0) {
- fetch_unpack_limit = git_config_int(var, value);
- return 0;
- }
-
- if (strcmp(var, "transfer.unpacklimit") == 0) {
- transfer_unpack_limit = git_config_int(var, value);
- return 0;
- }
-
- if (strcmp(var, "repack.usedeltabaseoffset") == 0) {
- prefer_ofs_delta = git_config_bool(var, value);
- return 0;
- }
-
- if (!strcmp(var, "fetch.fsckobjects")) {
- fetch_fsck_objects = git_config_bool(var, value);
- return 0;
- }
-
- if (!strcmp(var, "transfer.fsckobjects")) {
- transfer_fsck_objects = git_config_bool(var, value);
- return 0;
- }
+ git_config_get_int("fetch.unpacklimit", &fetch_unpack_limit);
+ git_config_get_int("transfer.unpacklimit", &transfer_unpack_limit);
+ git_config_get_bool("repack.usedeltabaseoffset", &prefer_ofs_delta);
+ git_config_get_bool("fetch.fsckobjects", &fetch_fsck_objects);
+ git_config_get_bool("transfer.fsckobjects", &transfer_fsck_objects);
- return git_default_config(var, value, cb);
+ git_config(git_default_config, NULL);
}
static void fetch_pack_setup(void)
@@ -904,7 +885,7 @@ static void fetch_pack_setup(void)
static int did_setup;
if (did_setup)
return;
- git_config(fetch_pack_config, NULL);
+ fetch_pack_config();
if (0 <= transfer_unpack_limit)
unpack_limit = transfer_unpack_limit;
else if (0 <= fetch_unpack_limit)
--
1.9.0.GIT
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 06/11] rerere.c: replace `git_config()` with `git_config_get_*()` family
2014-08-07 16:21 [PATCH v2 00/11] git_config callers rewritten with the new config-set API Tanay Abhra
` (4 preceding siblings ...)
2014-08-07 16:21 ` [PATCH v2 05/11] fetchpack.c: replace `git_config()` with `git_config_get_*()` family Tanay Abhra
@ 2014-08-07 16:21 ` Tanay Abhra
2014-08-07 16:21 ` [PATCH v2 07/11] builtin/gc.c: " Tanay Abhra
` (6 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Tanay Abhra @ 2014-08-07 16:21 UTC (permalink / raw)
To: git; +Cc: Tanay Abhra, Matthieu Moy, Ramkumar Ramachandra
Use `git_config_get_*()` family instead of `git_config()` to take advantage of
the config-set API which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
rerere.c | 43 ++++++++++++-------------------------------
1 file changed, 12 insertions(+), 31 deletions(-)
diff --git a/rerere.c b/rerere.c
index d84b495..20b18ad 100644
--- a/rerere.c
+++ b/rerere.c
@@ -573,15 +573,11 @@ static int do_plain_rerere(struct string_list *rr, int fd)
return write_rr(rr, fd);
}
-static int git_rerere_config(const char *var, const char *value, void *cb)
+static void git_rerere_config(void)
{
- if (!strcmp(var, "rerere.enabled"))
- rerere_enabled = git_config_bool(var, value);
- else if (!strcmp(var, "rerere.autoupdate"))
- rerere_autoupdate = git_config_bool(var, value);
- else
- return git_default_config(var, value, cb);
- return 0;
+ git_config_get_bool("rerere.enabled", &rerere_enabled);
+ git_config_get_bool("rerere.autoupdate", &rerere_autoupdate);
+ git_config(git_default_config, NULL);
}
static int is_rerere_enabled(void)
@@ -606,7 +602,7 @@ int setup_rerere(struct string_list *merge_rr, int flags)
{
int fd;
- git_config(git_rerere_config, NULL);
+ git_rerere_config();
if (!is_rerere_enabled())
return -1;
@@ -699,24 +695,6 @@ static void unlink_rr_item(const char *name)
rmdir(git_path("rr-cache/%s", name));
}
-struct rerere_gc_config_cb {
- int cutoff_noresolve;
- int cutoff_resolve;
-};
-
-static int git_rerere_gc_config(const char *var, const char *value, void *cb)
-{
- struct rerere_gc_config_cb *cf = cb;
-
- if (!strcmp(var, "gc.rerereresolved"))
- cf->cutoff_resolve = git_config_int(var, value);
- else if (!strcmp(var, "gc.rerereunresolved"))
- cf->cutoff_noresolve = git_config_int(var, value);
- else
- return git_default_config(var, value, cb);
- return 0;
-}
-
void rerere_gc(struct string_list *rr)
{
struct string_list to_remove = STRING_LIST_INIT_DUP;
@@ -724,9 +702,12 @@ void rerere_gc(struct string_list *rr)
struct dirent *e;
int i, cutoff;
time_t now = time(NULL), then;
- struct rerere_gc_config_cb cf = { 15, 60 };
+ int cutoff_noresolve = 15;
+ int cutoff_resolve = 60;
- git_config(git_rerere_gc_config, &cf);
+ git_config_get_int("gc.rerereresolved", &cutoff_resolve);
+ git_config_get_int("gc.rerereunresolved", &cutoff_noresolve);
+ git_config(git_default_config, NULL);
dir = opendir(git_path("rr-cache"));
if (!dir)
die_errno("unable to open rr-cache directory");
@@ -736,12 +717,12 @@ void rerere_gc(struct string_list *rr)
then = rerere_last_used_at(e->d_name);
if (then) {
- cutoff = cf.cutoff_resolve;
+ cutoff = cutoff_resolve;
} else {
then = rerere_created_at(e->d_name);
if (!then)
continue;
- cutoff = cf.cutoff_noresolve;
+ cutoff = cutoff_noresolve;
}
if (then < now - cutoff * 86400)
string_list_append(&to_remove, e->d_name);
--
1.9.0.GIT
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 07/11] builtin/gc.c: replace `git_config()` with `git_config_get_*()` family
2014-08-07 16:21 [PATCH v2 00/11] git_config callers rewritten with the new config-set API Tanay Abhra
` (5 preceding siblings ...)
2014-08-07 16:21 ` [PATCH v2 06/11] rerere.c: " Tanay Abhra
@ 2014-08-07 16:21 ` Tanay Abhra
2014-08-07 16:21 ` [PATCH v2 08/11] pager.c: replace `git_config()` with `git_config_get_value()` Tanay Abhra
` (5 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Tanay Abhra @ 2014-08-07 16:21 UTC (permalink / raw)
To: git; +Cc: Tanay Abhra, Matthieu Moy, Ramkumar Ramachandra
Use `git_config_get_*()` family instead of `git_config()` to take advantage of
the config-set API which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
builtin/gc.c | 51 ++++++++++++++++++++-------------------------------
1 file changed, 20 insertions(+), 31 deletions(-)
diff --git a/builtin/gc.c b/builtin/gc.c
index 8d219d8..ced1456 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -55,44 +55,33 @@ static void remove_pidfile_on_signal(int signo)
raise(signo);
}
-static int gc_config(const char *var, const char *value, void *cb)
+static void gc_config(void)
{
- if (!strcmp(var, "gc.packrefs")) {
+ const char *value;
+
+ if (!git_config_get_value("gc.packrefs", &value)) {
if (value && !strcmp(value, "notbare"))
pack_refs = -1;
else
- pack_refs = git_config_bool(var, value);
- return 0;
- }
- if (!strcmp(var, "gc.aggressivewindow")) {
- aggressive_window = git_config_int(var, value);
- return 0;
- }
- if (!strcmp(var, "gc.aggressivedepth")) {
- aggressive_depth = git_config_int(var, value);
- return 0;
- }
- if (!strcmp(var, "gc.auto")) {
- gc_auto_threshold = git_config_int(var, value);
- return 0;
- }
- if (!strcmp(var, "gc.autopacklimit")) {
- gc_auto_pack_limit = git_config_int(var, value);
- return 0;
+ pack_refs = git_config_bool("gc.packrefs", value);
}
- if (!strcmp(var, "gc.autodetach")) {
- detach_auto = git_config_bool(var, value);
- return 0;
- }
- if (!strcmp(var, "gc.pruneexpire")) {
- if (value && strcmp(value, "now")) {
+
+ git_config_get_int("gc.aggressivewindow", &aggressive_window);
+ git_config_get_int("gc.aggressivedepth", &aggressive_depth);
+ git_config_get_int("gc.auto", &gc_auto_threshold);
+ git_config_get_int("gc.autopacklimit", &gc_auto_pack_limit);
+ git_config_get_bool("gc.autodetach", &detach_auto);
+
+ if (!git_config_get_string_const("gc.pruneexpire", &prune_expire)) {
+ if (strcmp(prune_expire, "now")) {
unsigned long now = approxidate("now");
- if (approxidate(value) >= now)
- return error(_("Invalid %s: '%s'"), var, value);
+ if (approxidate(prune_expire) >= now) {
+ git_die_config("gc.pruneexpire", _("Invalid gc.pruneexpire: '%s'"),
+ prune_expire);
+ }
}
- return git_config_string(&prune_expire, var, value);
}
- return git_default_config(var, value, cb);
+ git_config(git_default_config, NULL);
}
static int too_many_loose_objects(void)
@@ -301,7 +290,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
argv_array_pushl(&prune, "prune", "--expire", NULL );
argv_array_pushl(&rerere, "rerere", "gc", NULL);
- git_config(gc_config, NULL);
+ gc_config();
if (pack_refs < 0)
pack_refs = !is_bare_repository();
--
1.9.0.GIT
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 08/11] pager.c: replace `git_config()` with `git_config_get_value()`
2014-08-07 16:21 [PATCH v2 00/11] git_config callers rewritten with the new config-set API Tanay Abhra
` (6 preceding siblings ...)
2014-08-07 16:21 ` [PATCH v2 07/11] builtin/gc.c: " Tanay Abhra
@ 2014-08-07 16:21 ` Tanay Abhra
2014-08-07 16:21 ` [PATCH v2 09/11] imap-send.c: replace `git_config()` with `git_config_get_*()` family Tanay Abhra
` (4 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Tanay Abhra @ 2014-08-07 16:21 UTC (permalink / raw)
To: git; +Cc: Tanay Abhra, Matthieu Moy, Ramkumar Ramachandra
Use `git_config_get_value()` instead of `git_config()` to take advantage of
the config-set API which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
| 40 +++++++++++++---------------------------
1 file changed, 13 insertions(+), 27 deletions(-)
--git a/pager.c b/pager.c
index 8b5cbc5..b7eb7e7 100644
--- a/pager.c
+++ b/pager.c
@@ -6,12 +6,6 @@
#define DEFAULT_PAGER "less"
#endif
-struct pager_config {
- const char *cmd;
- int want;
- char *value;
-};
-
/*
* This is split up from the rest of git so that we can do
* something different on Windows.
@@ -155,30 +149,22 @@ int decimal_width(int number)
return width;
}
-static int pager_command_config(const char *var, const char *value, void *data)
+/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
+int check_pager_config(const char *cmd)
{
- struct pager_config *c = data;
- if (starts_with(var, "pager.") && !strcmp(var + 6, c->cmd)) {
- int b = git_config_maybe_bool(var, value);
+ int want = -1;
+ struct strbuf key = STRBUF_INIT;
+ const char *value = NULL;
+ strbuf_addf(&key, "pager.%s", cmd);
+ if (!git_config_get_value(key.buf, &value)) {
+ int b = git_config_maybe_bool(key.buf, value);
if (b >= 0)
- c->want = b;
+ want = b;
else {
- c->want = 1;
- c->value = xstrdup(value);
+ want = 1;
+ pager_program = xstrdup(value);
}
}
- return 0;
-}
-
-/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
-int check_pager_config(const char *cmd)
-{
- struct pager_config c;
- c.cmd = cmd;
- c.want = -1;
- c.value = NULL;
- git_config(pager_command_config, &c);
- if (c.value)
- pager_program = c.value;
- return c.want;
+ strbuf_release(&key);
+ return want;
}
--
1.9.0.GIT
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 09/11] imap-send.c: replace `git_config()` with `git_config_get_*()` family
2014-08-07 16:21 [PATCH v2 00/11] git_config callers rewritten with the new config-set API Tanay Abhra
` (7 preceding siblings ...)
2014-08-07 16:21 ` [PATCH v2 08/11] pager.c: replace `git_config()` with `git_config_get_value()` Tanay Abhra
@ 2014-08-07 16:21 ` Tanay Abhra
2014-08-07 16:21 ` [PATCH v2 10/11] alias.c: replace `git_config()` with `git_config_get_string()` Tanay Abhra
` (3 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Tanay Abhra @ 2014-08-07 16:21 UTC (permalink / raw)
To: git; +Cc: Tanay Abhra, Matthieu Moy, Ramkumar Ramachandra
Use `git_config_get_*()` family instead of `git_config()` to take advantage of
the config-set API which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
imap-send.c | 60 ++++++++++++++++++++++++++----------------------------------
1 file changed, 26 insertions(+), 34 deletions(-)
diff --git a/imap-send.c b/imap-send.c
index 524fbab..618d75b 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1326,43 +1326,35 @@ static int split_msg(struct strbuf *all_msgs, struct strbuf *msg, int *ofs)
static char *imap_folder;
-static int git_imap_config(const char *key, const char *val, void *cb)
+static void git_imap_config(void)
{
- if (!skip_prefix(key, "imap.", &key))
- return 0;
+ const char *val = NULL;
+
+ git_config_get_bool("imap.sslverify", &server.ssl_verify);
+ git_config_get_bool("imap.preformattedhtml", &server.use_html);
+ git_config_get_string("imap.folder", &imap_folder);
- /* check booleans first, and barf on others */
- if (!strcmp("sslverify", key))
- server.ssl_verify = git_config_bool(key, val);
- else if (!strcmp("preformattedhtml", key))
- server.use_html = git_config_bool(key, val);
- else if (!val)
- return config_error_nonbool(key);
-
- if (!strcmp("folder", key)) {
- imap_folder = xstrdup(val);
- } else if (!strcmp("host", key)) {
- if (starts_with(val, "imap:"))
- val += 5;
- else if (starts_with(val, "imaps:")) {
- val += 6;
- server.use_ssl = 1;
+ if (!git_config_get_value("imap.host", &val)) {
+ if (!val) {
+ git_die_config("imap.host", "Missing value for 'imap.host'");
+ } else {
+ if (starts_with(val, "imap:"))
+ val += 5;
+ else if (starts_with(val, "imaps:")) {
+ val += 6;
+ server.use_ssl = 1;
+ }
+ if (starts_with(val, "//"))
+ val += 2;
+ server.host = xstrdup(val);
}
- if (starts_with(val, "//"))
- val += 2;
- server.host = xstrdup(val);
- } else if (!strcmp("user", key))
- server.user = xstrdup(val);
- else if (!strcmp("pass", key))
- server.pass = xstrdup(val);
- else if (!strcmp("port", key))
- server.port = git_config_int(key, val);
- else if (!strcmp("tunnel", key))
- server.tunnel = xstrdup(val);
- else if (!strcmp("authmethod", key))
- server.auth_method = xstrdup(val);
+ }
- return 0;
+ git_config_get_string("imap.user", &server.user);
+ git_config_get_string("imap.pass", &server.pass);
+ git_config_get_int("imap.port", &server.port);
+ git_config_get_string("imap.tunnel", &server.tunnel);
+ git_config_get_string("imap.authmethod", &server.auth_method);
}
int main(int argc, char **argv)
@@ -1383,7 +1375,7 @@ int main(int argc, char **argv)
usage(imap_send_usage);
setup_git_directory_gently(&nongit_ok);
- git_config(git_imap_config, NULL);
+ git_imap_config();
if (!server.port)
server.port = server.use_ssl ? 993 : 143;
--
1.9.0.GIT
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 10/11] alias.c: replace `git_config()` with `git_config_get_string()`
2014-08-07 16:21 [PATCH v2 00/11] git_config callers rewritten with the new config-set API Tanay Abhra
` (8 preceding siblings ...)
2014-08-07 16:21 ` [PATCH v2 09/11] imap-send.c: replace `git_config()` with `git_config_get_*()` family Tanay Abhra
@ 2014-08-07 16:21 ` Tanay Abhra
2014-08-07 16:21 ` [PATCH v2 11/11] branch.c: replace `git_config()` with `git_config_get_string() Tanay Abhra
` (2 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Tanay Abhra @ 2014-08-07 16:21 UTC (permalink / raw)
To: git; +Cc: Tanay Abhra, Matthieu Moy, Ramkumar Ramachandra
Use `git_config_get_string()` instead of `git_config()` to take advantage of
the config-set API which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
alias.c | 25 ++++++-------------------
1 file changed, 6 insertions(+), 19 deletions(-)
diff --git a/alias.c b/alias.c
index 758c867..6aa164a 100644
--- a/alias.c
+++ b/alias.c
@@ -1,26 +1,13 @@
#include "cache.h"
-static const char *alias_key;
-static char *alias_val;
-
-static int alias_lookup_cb(const char *k, const char *v, void *cb)
-{
- const char *name;
- if (skip_prefix(k, "alias.", &name) && !strcmp(name, alias_key)) {
- if (!v)
- return config_error_nonbool(k);
- alias_val = xstrdup(v);
- return 0;
- }
- return 0;
-}
-
char *alias_lookup(const char *alias)
{
- alias_key = alias;
- alias_val = NULL;
- git_config(alias_lookup_cb, NULL);
- return alias_val;
+ char *v = NULL;
+ struct strbuf key = STRBUF_INIT;
+ strbuf_addf(&key, "alias.%s", alias);
+ git_config_get_string(key.buf, &v);
+ strbuf_release(&key);
+ return v;
}
#define SPLIT_CMDLINE_BAD_ENDING 1
--
1.9.0.GIT
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 11/11] branch.c: replace `git_config()` with `git_config_get_string()
2014-08-07 16:21 [PATCH v2 00/11] git_config callers rewritten with the new config-set API Tanay Abhra
` (9 preceding siblings ...)
2014-08-07 16:21 ` [PATCH v2 10/11] alias.c: replace `git_config()` with `git_config_get_string()` Tanay Abhra
@ 2014-08-07 16:21 ` Tanay Abhra
2014-08-07 17:04 ` Matthieu Moy
2014-08-07 17:56 ` [PATCH v3 " Tanay Abhra
2014-08-07 18:36 ` [PATCH v2 00/11] git_config callers rewritten with the new config-set API Matthieu Moy
2014-08-07 20:10 ` Junio C Hamano
12 siblings, 2 replies; 16+ messages in thread
From: Tanay Abhra @ 2014-08-07 16:21 UTC (permalink / raw)
To: git; +Cc: Tanay Abhra, Matthieu Moy, Ramkumar Ramachandra
Use `git_config_get_string()` instead of `git_config()` to take advantage of
the config-set API which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
branch.c | 27 +++++++--------------------
1 file changed, 7 insertions(+), 20 deletions(-)
diff --git a/branch.c b/branch.c
index 735767d..df6b120 100644
--- a/branch.c
+++ b/branch.c
@@ -140,30 +140,17 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,
return 0;
}
-struct branch_desc_cb {
- const char *config_name;
- const char *value;
-};
-
-static int read_branch_desc_cb(const char *var, const char *value, void *cb)
-{
- struct branch_desc_cb *desc = cb;
- if (strcmp(desc->config_name, var))
- return 0;
- free((char *)desc->value);
- return git_config_string(&desc->value, var, value);
-}
-
int read_branch_desc(struct strbuf *buf, const char *branch_name)
{
- struct branch_desc_cb cb;
+ char *v = NULL;
struct strbuf name = STRBUF_INIT;
strbuf_addf(&name, "branch.%s.description", branch_name);
- cb.config_name = name.buf;
- cb.value = NULL;
- git_config(read_branch_desc_cb, &cb);
- if (cb.value)
- strbuf_addstr(buf, cb.value);
+ if (git_config_get_string(name.buf, &v)) {
+ strbuf_release(&name);
+ return -1;
+ }
+ strbuf_addstr(buf, v);
+ free(v);
strbuf_release(&name);
return 0;
}
--
1.9.0.GIT
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH v2 11/11] branch.c: replace `git_config()` with `git_config_get_string()
2014-08-07 16:21 ` [PATCH v2 11/11] branch.c: replace `git_config()` with `git_config_get_string() Tanay Abhra
@ 2014-08-07 17:04 ` Matthieu Moy
2014-08-07 17:56 ` [PATCH v3 " Tanay Abhra
1 sibling, 0 replies; 16+ messages in thread
From: Matthieu Moy @ 2014-08-07 17:04 UTC (permalink / raw)
To: Tanay Abhra; +Cc: git, Ramkumar Ramachandra
Tanay Abhra <tanayabh@gmail.com> writes:
> Use `git_config_get_string()` instead of `git_config()` to take advantage of
> the config-set API which provides a cleaner control flow.
>
> Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
> ---
> branch.c | 27 +++++++--------------------
> 1 file changed, 7 insertions(+), 20 deletions(-)
>
> diff --git a/branch.c b/branch.c
> index 735767d..df6b120 100644
> --- a/branch.c
> +++ b/branch.c
> @@ -140,30 +140,17 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,
> return 0;
> }
>
> -struct branch_desc_cb {
> - const char *config_name;
> - const char *value;
> -};
> -
> -static int read_branch_desc_cb(const char *var, const char *value, void *cb)
> -{
> - struct branch_desc_cb *desc = cb;
> - if (strcmp(desc->config_name, var))
> - return 0;
> - free((char *)desc->value);
> - return git_config_string(&desc->value, var, value);
> -}
> -
> int read_branch_desc(struct strbuf *buf, const char *branch_name)
> {
> - struct branch_desc_cb cb;
> + char *v = NULL;
> struct strbuf name = STRBUF_INIT;
> strbuf_addf(&name, "branch.%s.description", branch_name);
> - cb.config_name = name.buf;
> - cb.value = NULL;
> - git_config(read_branch_desc_cb, &cb);
> - if (cb.value)
> - strbuf_addstr(buf, cb.value);
> + if (git_config_get_string(name.buf, &v)) {
> + strbuf_release(&name);
> + return -1;
> + }
> + strbuf_addstr(buf, v);
> + free(v);
There's a behavior change here, but I think it is the right thing to do.
It lacks a proper commit message though:
As a reminder, your patch "change `git_config()` return value to void"
in the other series did:
--- a/branch.c
+++ b/branch.c
@@ -161,10 +161,7 @@ int read_branch_desc(struct strbuf *buf, const char *branch_name)
strbuf_addf(&name, "branch.%s.description", branch_name);
cb.config_name = name.buf;
cb.value = NULL;
- if (git_config(read_branch_desc_cb, &cb) < 0) {
- strbuf_release(&name);
- return -1;
- }
+ git_config(read_branch_desc_cb, &cb);
if (cb.value)
strbuf_addstr(buf, cb.value);
strbuf_release(&name);
So, before it, read_branch_desc() was returning -1 iff git_config()
failed, which essentially never happened.
Now, you're retoring a similar "if", but you strbuf_release and return
-1 if no value is found for the variable.
There are 3 callers of read_branch_desc:
builtin/branch.c: read_branch_desc(&buf, branch_name);
builtin/fmt-merge-msg.c: if (!read_branch_desc(&desc, name)) {
builtin/log.c: read_branch_desc(&desc, branch_name);
Only the one in fmt-merge-msg.c uses the return value:
static void add_branch_desc(struct strbuf *out, const char *name)
{
struct strbuf desc = STRBUF_INIT;
if (!read_branch_desc(&desc, name)) {
const char *bp = desc.buf;
while (*bp) { /* (1) */
const char *ep = strchrnul(bp, '\n');
if (*ep)
ep++;
strbuf_addf(out, " : %.*s", (int)(ep - bp), bp);
bp = ep;
}
if (out->buf[out->len - 1] != '\n') /* (2) */
strbuf_addch(out, '\n');
}
strbuf_release(&desc);
}
the (1) part is a no-op if no value is found, but the old code was still
adding a \n in the (2) part, even when no value was found.
So, the new code is better than the old one, but your patch does a bit
more than the commit message claims.
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v3 11/11] branch.c: replace `git_config()` with `git_config_get_string()
2014-08-07 16:21 ` [PATCH v2 11/11] branch.c: replace `git_config()` with `git_config_get_string() Tanay Abhra
2014-08-07 17:04 ` Matthieu Moy
@ 2014-08-07 17:56 ` Tanay Abhra
1 sibling, 0 replies; 16+ messages in thread
From: Tanay Abhra @ 2014-08-07 17:56 UTC (permalink / raw)
To: git; +Cc: Matthieu Moy, Ramkumar Ramachandra
Use `git_config_get_string()` instead of `git_config()` to take advantage of
the config-set API which provides a cleaner control flow. While we are at
it, return -1 if we find no value for the queried variable. Original code
returned 0 for all cases, which was checked by `add_branch_desc()` in
fmt-merge-msg.c resulting in addition of a spurious newline to the `out`
strbuf. Now, the newline addition is skipped as -1 is returned to the caller
if no value is found.
Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
v3: Changed the commit message to a more appropriate one.
branch.c | 27 +++++++--------------------
1 file changed, 7 insertions(+), 20 deletions(-)
diff --git a/branch.c b/branch.c
index 735767d..df6b120 100644
--- a/branch.c
+++ b/branch.c
@@ -140,30 +140,17 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,
return 0;
}
-struct branch_desc_cb {
- const char *config_name;
- const char *value;
-};
-
-static int read_branch_desc_cb(const char *var, const char *value, void *cb)
-{
- struct branch_desc_cb *desc = cb;
- if (strcmp(desc->config_name, var))
- return 0;
- free((char *)desc->value);
- return git_config_string(&desc->value, var, value);
-}
-
int read_branch_desc(struct strbuf *buf, const char *branch_name)
{
- struct branch_desc_cb cb;
+ char *v = NULL;
struct strbuf name = STRBUF_INIT;
strbuf_addf(&name, "branch.%s.description", branch_name);
- cb.config_name = name.buf;
- cb.value = NULL;
- git_config(read_branch_desc_cb, &cb);
- if (cb.value)
- strbuf_addstr(buf, cb.value);
+ if (git_config_get_string(name.buf, &v)) {
+ strbuf_release(&name);
+ return -1;
+ }
+ strbuf_addstr(buf, v);
+ free(v);
strbuf_release(&name);
return 0;
}
-- 1.9.0.GIT
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH v2 00/11] git_config callers rewritten with the new config-set API
2014-08-07 16:21 [PATCH v2 00/11] git_config callers rewritten with the new config-set API Tanay Abhra
` (10 preceding siblings ...)
2014-08-07 16:21 ` [PATCH v2 11/11] branch.c: replace `git_config()` with `git_config_get_string() Tanay Abhra
@ 2014-08-07 18:36 ` Matthieu Moy
2014-08-07 20:10 ` Junio C Hamano
12 siblings, 0 replies; 16+ messages in thread
From: Matthieu Moy @ 2014-08-07 18:36 UTC (permalink / raw)
To: Tanay Abhra; +Cc: git, Ramkumar Ramachandra
Tanay Abhra <tanayabh@gmail.com> writes:
> [v2]: git_die_config() messages changed. Diff between v1 and v2 is at the bottom.
I went through the series once more, and all the changes look good.
v3 for PATCH 11/11 addresses my comment about the commit message in v2.
Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr>
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 00/11] git_config callers rewritten with the new config-set API
2014-08-07 16:21 [PATCH v2 00/11] git_config callers rewritten with the new config-set API Tanay Abhra
` (11 preceding siblings ...)
2014-08-07 18:36 ` [PATCH v2 00/11] git_config callers rewritten with the new config-set API Matthieu Moy
@ 2014-08-07 20:10 ` Junio C Hamano
12 siblings, 0 replies; 16+ messages in thread
From: Junio C Hamano @ 2014-08-07 20:10 UTC (permalink / raw)
To: Tanay Abhra; +Cc: git, Matthieu Moy, Ramkumar Ramachandra
Tanay Abhra <tanayabh@gmail.com> writes:
> 11 files changed, 114 insertions(+), 250 deletions(-)
Nice reduction.
^ permalink raw reply [flat|nested] 16+ messages in thread