From: larsxschneider@gmail.com
To: git@vger.kernel.org
Cc: peff@peff.net, sschuberth@gmail.com, ramsay@ramsayjones.plus.com,
sunshine@sunshineco.com, hvoigt@hvoigt.net, sbeller@google.com,
Lars Schneider <larsxschneider@gmail.com>
Subject: [PATCH v3 2/3] config: add 'type' to config_source struct that identifies config type
Date: Sat, 13 Feb 2016 15:24:15 +0100 [thread overview]
Message-ID: <1455373456-64691-3-git-send-email-larsxschneider@gmail.com> (raw)
In-Reply-To: <1455373456-64691-1-git-send-email-larsxschneider@gmail.com>
From: Lars Schneider <larsxschneider@gmail.com>
Use the config type to print more detailed error messages that inform
the user about the origin of a config error (file, stdin, blob).
Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
---
config.c | 17 ++++++++++-------
t/t1300-repo-config.sh | 8 +++++++-
t/t1308-config-set.sh | 4 ++--
3 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/config.c b/config.c
index 86a5eb2..6a5942f 100644
--- a/config.c
+++ b/config.c
@@ -24,6 +24,7 @@ struct config_source {
size_t pos;
} buf;
} u;
+ const char *type;
const char *name;
const char *path;
int die_on_error;
@@ -471,9 +472,9 @@ static int git_parse_source(config_fn_t fn, void *data)
break;
}
if (cf->die_on_error)
- die(_("bad config file line %d in %s"), cf->linenr, cf->name);
+ die(_("bad config line %d in %s %s"), cf->linenr, cf->type, cf->name);
else
- return error(_("bad config file line %d in %s"), cf->linenr, cf->name);
+ return error(_("bad config line %d in %s %s"), cf->linenr, cf->type, cf->name);
}
static int parse_unit_factor(const char *end, uintmax_t *val)
@@ -588,9 +589,9 @@ static void die_bad_number(const char *name, const char *value)
if (!value)
value = "";
- if (cf && cf->name)
- die(_("bad numeric config value '%s' for '%s' in %s: %s"),
- value, name, cf->name, reason);
+ if (cf && cf->type && cf->name)
+ die(_("bad numeric config value '%s' for '%s' in %s %s: %s"),
+ value, name, cf->type, cf->name, reason);
die(_("bad numeric config value '%s' for '%s': %s"), value, name, reason);
}
@@ -1066,7 +1067,8 @@ static int do_config_from_file(config_fn_t fn,
struct config_source top;
top.u.file = f;
- top.name = name;
+ top.type = path ? "file" : "stdin";
+ top.name = name ? name : "";
top.path = path;
top.die_on_error = 1;
top.do_fgetc = config_file_fgetc;
@@ -1078,7 +1080,7 @@ static int do_config_from_file(config_fn_t fn,
static int git_config_from_stdin(config_fn_t fn, void *data)
{
- return do_config_from_file(fn, "<stdin>", NULL, stdin, data);
+ return do_config_from_file(fn, NULL, NULL, stdin, data);
}
int git_config_from_file(config_fn_t fn, const char *filename, void *data)
@@ -1104,6 +1106,7 @@ int git_config_from_buf(config_fn_t fn, const char *name, const char *buf,
top.u.buf.buf = buf;
top.u.buf.len = len;
top.u.buf.pos = 0;
+ top.type = "blob";
top.name = name;
top.path = NULL;
top.die_on_error = 0;
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 52678e7..7abdfcb 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -700,12 +700,18 @@ test_expect_success 'invalid unit' '
git config aninvalid.unit >actual &&
test_cmp expect actual &&
cat >expect <<-\EOF &&
- fatal: bad numeric config value '\''1auto'\'' for '\''aninvalid.unit'\'' in .git/config: invalid unit
+ fatal: bad numeric config value '\''1auto'\'' for '\''aninvalid.unit'\'' in file .git/config: invalid unit
EOF
test_must_fail git config --int --get aninvalid.unit 2>actual &&
test_i18ncmp expect actual
'
+test_expect_success 'invalid stdin config' '
+ echo "fatal: bad config line 1 in stdin " >expect &&
+ echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
+ test_cmp expect output
+'
+
cat > expect << EOF
true
false
diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh
index 91235b7..82f82a1 100755
--- a/t/t1308-config-set.sh
+++ b/t/t1308-config-set.sh
@@ -195,14 +195,14 @@ test_expect_success 'proper error on error in default config files' '
cp .git/config .git/config.old &&
test_when_finished "mv .git/config.old .git/config" &&
echo "[" >>.git/config &&
- echo "fatal: bad config file line 34 in .git/config" >expect &&
+ echo "fatal: bad config line 34 in file .git/config" >expect &&
test_expect_code 128 test-config get_value foo.bar 2>actual &&
test_cmp expect actual
'
test_expect_success 'proper error on error in custom config files' '
echo "[" >>syntax-error &&
- echo "fatal: bad config file line 1 in syntax-error" >expect &&
+ echo "fatal: bad config line 1 in file syntax-error" >expect &&
test_expect_code 128 test-config configset_get_value foo.bar syntax-error 2>actual &&
test_cmp expect actual
'
--
2.5.1
next prev parent reply other threads:[~2016-02-13 14:25 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-13 14:24 [PATCH v3 0/3] config: add '--sources' option to print the source of a config value larsxschneider
2016-02-13 14:24 ` [PATCH v3 1/3] git-config.txt: describe '--includes' default behavior larsxschneider
2016-02-13 17:17 ` Jeff King
2016-02-13 21:00 ` Junio C Hamano
2016-02-14 0:34 ` Jeff King
2016-02-14 12:17 ` Lars Schneider
2016-02-14 16:05 ` Jeff King
2016-02-13 14:24 ` larsxschneider [this message]
2016-02-13 17:24 ` [PATCH v3 2/3] config: add 'type' to config_source struct that identifies config type Jeff King
2016-02-13 21:04 ` Junio C Hamano
2016-02-14 12:26 ` Lars Schneider
2016-02-14 12:24 ` Lars Schneider
2016-02-14 16:07 ` Jeff King
2016-02-13 14:24 ` [PATCH v3 3/3] config: add '--show-origin' option to print the origin of a config value larsxschneider
2016-02-13 17:44 ` Jeff King
2016-02-13 18:04 ` Jeff King
2016-02-13 18:15 ` Jeff King
2016-02-15 9:41 ` Lars Schneider
2016-02-14 12:48 ` Lars Schneider
2016-02-14 16:18 ` Jeff King
2016-02-15 7:53 ` Johannes Schindelin
2016-02-13 14:43 ` [PATCH v3 0/3] config: add '--sources' option to print the source " Mike Rappazzo
2016-02-13 17:26 ` Sebastian Schuberth
2016-02-13 18:19 ` Jeff King
2016-02-13 21:05 ` Junio C Hamano
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=1455373456-64691-3-git-send-email-larsxschneider@gmail.com \
--to=larsxschneider@gmail.com \
--cc=git@vger.kernel.org \
--cc=hvoigt@hvoigt.net \
--cc=peff@peff.net \
--cc=ramsay@ramsayjones.plus.com \
--cc=sbeller@google.com \
--cc=sschuberth@gmail.com \
--cc=sunshine@sunshineco.com \
/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).