From: Christian Couder <chriscool@tuxfamily.org>
To: git@vger.kernel.org
Cc: Junio Hamano <junkio@cox.net>,
Pierre Habouzit <madcoder@debian.org>,
Martin Koegler <mkoegler@auto.tuwien.ac.at>,
Johannes Sixt <j.sixt@viscovery.net>
Subject: [PATCH 2/6] config: add 'git_config_string' to refactor string config variables.
Date: Sat, 16 Feb 2008 06:00:24 +0100 [thread overview]
Message-ID: <20080216060024.385fa360.chriscool@tuxfamily.org> (raw)
In many places we just check if a value from the config file is not
NULL, then we duplicate it and return 0. This patch introduces the new
'git_config_string' function to do that.
This function is also used to refactor some code in 'config.c'.
Refactoring other files is left for other patches.
Also not all the code in "config.c" is refactored, because the function
takes a "const char **" as its first parameter, but in many places a
"char *" is used instead of a "const char *". (And C does not allow
using a "char **" instead of a "const char **" without a warning.)
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
cache.h | 1 +
config.c | 25 ++++++++++++-------------
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/cache.h b/cache.h
index 3867ba7..cef058d 100644
--- a/cache.h
+++ b/cache.h
@@ -625,6 +625,7 @@ extern int git_parse_ulong(const char *, unsigned long *);
extern int git_config_int(const char *, const char *);
extern unsigned long git_config_ulong(const char *, const char *);
extern int git_config_bool(const char *, const char *);
+extern int git_config_string(const char **, const char *, const char *);
extern int git_config_set(const char *, const char *);
extern int git_config_set_multivar(const char *, const char *, const char *, int);
extern int git_config_rename_section(const char *, const char *);
diff --git a/config.c b/config.c
index 3e72778..ca6af2d 100644
--- a/config.c
+++ b/config.c
@@ -309,6 +309,14 @@ int git_config_bool(const char *name, const char *value)
return git_config_int(name, value) != 0;
}
+int git_config_string(const char **dest, const char *var, const char *value)
+{
+ if (!value)
+ return config_error_nonbool(var);
+ *dest = xstrdup(value);
+ return 0;
+}
+
int git_default_config(const char *var, const char *value)
{
/* This needs a better name */
@@ -421,20 +429,11 @@ int git_default_config(const char *var, const char *value)
return 0;
}
- if (!strcmp(var, "i18n.commitencoding")) {
- if (!value)
- return config_error_nonbool(var);
- git_commit_encoding = xstrdup(value);
- return 0;
- }
-
- if (!strcmp(var, "i18n.logoutputencoding")) {
- if (!value)
- return config_error_nonbool(var);
- git_log_output_encoding = xstrdup(value);
- return 0;
- }
+ if (!strcmp(var, "i18n.commitencoding"))
+ return git_config_string(&git_commit_encoding, var, value);
+ if (!strcmp(var, "i18n.logoutputencoding"))
+ return git_config_string(&git_log_output_encoding, var, value);
if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
pager_use_color = git_config_bool(var,value);
--
1.5.4.1.129.gf12af-dirty
next reply other threads:[~2008-02-16 4:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-16 5:00 Christian Couder [this message]
2008-02-16 11:53 ` [PATCH 2/6] config: add 'git_config_string' to refactor string config variables Jeff King
2008-02-16 18:21 ` Christian Couder
2008-02-16 18:33 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080216060024.385fa360.chriscool@tuxfamily.org \
--to=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=j.sixt@viscovery.net \
--cc=junkio@cox.net \
--cc=madcoder@debian.org \
--cc=mkoegler@auto.tuwien.ac.at \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).