From: Bert Wesarg <bert.wesarg@googlemail.com>
To: git@vger.kernel.org
Cc: Bert Wesarg <bert.wesarg@googlemail.com>
Subject: [PATCH 6/7] config: provide access to the current line number
Date: Tue, 21 Jan 2020 10:24:54 +0100 [thread overview]
Message-ID: <92356342164523c7753eda52c8985cb4774d1434.1579598053.git.bert.wesarg@googlemail.com> (raw)
In-Reply-To: <cover.1579598053.git.bert.wesarg@googlemail.com>
Users are nowadays trained to see message from CLI tools in the form
<file>:<lno>: …
To be able to give such messages when notifying the user about
configurations in any config file, it is currently only possible to get
the file name (if the value originates from a file to begin with) via
`current_config_name()`. Now it is also possible to query the current line
number for the configuration.
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
config.c | 8 ++++++++
config.h | 1 +
t/helper/test-config.c | 1 +
t/t1308-config-set.sh | 14 ++++++++++++--
4 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/config.c b/config.c
index 4c461bb7a3..5d1d6b5871 100644
--- a/config.c
+++ b/config.c
@@ -3333,6 +3333,14 @@ const char *config_scope_name(enum config_scope scope)
}
}
+int current_config_line(void)
+{
+ if (current_config_kvi)
+ return current_config_kvi->linenr;
+ else
+ return cf->linenr;
+}
+
int lookup_config(const char **mapping, int nr_mapping, const char *var)
{
int i;
diff --git a/config.h b/config.h
index c063f33ff6..371f7f2dd0 100644
--- a/config.h
+++ b/config.h
@@ -306,6 +306,7 @@ const char *config_scope_name(enum config_scope scope);
enum config_scope current_config_scope(void);
const char *current_config_origin_type(void);
const char *current_config_name(void);
+int current_config_line(void);
/**
* Include Directives
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index 1e3bc7c8f4..234c722b48 100644
--- a/t/helper/test-config.c
+++ b/t/helper/test-config.c
@@ -48,6 +48,7 @@ static int iterate_cb(const char *var, const char *value, void *data)
printf("value=%s\n", value ? value : "(null)");
printf("origin=%s\n", current_config_origin_type());
printf("name=%s\n", current_config_name());
+ printf("lno=%d\n", current_config_line());
printf("scope=%s\n", config_scope_name(current_config_scope()));
return 0;
diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh
index 7b4e1a63eb..9e36e7a590 100755
--- a/t/t1308-config-set.sh
+++ b/t/t1308-config-set.sh
@@ -238,8 +238,8 @@ test_expect_success 'error on modifying repo config without repo' '
cmdline_config="'foo.bar=from-cmdline'"
test_expect_success 'iteration shows correct origins' '
- echo "[foo]bar = from-repo" >.git/config &&
- echo "[foo]bar = from-home" >.gitconfig &&
+ printf "[ignore]\n\tthis = please\n[foo]bar = from-repo\n" >.git/config &&
+ printf "[foo]\n\tbar = from-home\n" >.gitconfig &&
if test_have_prereq MINGW
then
# Use Windows path (i.e. *not* $HOME)
@@ -253,18 +253,28 @@ test_expect_success 'iteration shows correct origins' '
value=from-home
origin=file
name=$HOME_GITCONFIG
+ lno=2
scope=global
+ key=ignore.this
+ value=please
+ origin=file
+ name=.git/config
+ lno=2
+ scope=repo
+
key=foo.bar
value=from-repo
origin=file
name=.git/config
+ lno=3
scope=repo
key=foo.bar
value=from-cmdline
origin=command line
name=
+ lno=-1
scope=cmdline
EOF
GIT_CONFIG_PARAMETERS=$cmdline_config test-tool config iterate >actual &&
--
2.24.1.497.g9abd7b20b4.dirty
next prev parent reply other threads:[~2020-01-21 9:25 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-16 21:25 [PATCH] remote: rename also remotes in the branch.<name>.pushRemote config Bert Wesarg
2020-01-16 23:14 ` Junio C Hamano
2020-01-17 9:33 ` [PATCH v2] remote rename: rename branch.<name>.pushRemote config values too Bert Wesarg
2020-01-17 11:50 ` Johannes Schindelin
2020-01-17 12:37 ` Bert Wesarg
2020-01-17 13:30 ` Johannes Schindelin
2020-01-17 14:40 ` Bert Wesarg
2020-01-20 11:25 ` Johannes Schindelin
2020-01-20 13:14 ` Bert Wesarg
2020-01-20 13:51 ` Johannes Schindelin
2020-01-17 18:48 ` Junio C Hamano
2020-01-17 20:20 ` Bert Wesarg
2020-01-17 21:24 ` Junio C Hamano
2020-01-21 9:24 ` [PATCH 0/7] remote rename: improve handling of configuration values Bert Wesarg
2020-01-21 9:24 ` [PATCH 1/7] pull --rebase/remote rename: document and honor single-letter abbreviations rebase types Bert Wesarg
2020-01-21 23:26 ` Junio C Hamano
2020-01-22 7:34 ` Bert Wesarg
2020-01-22 19:43 ` Junio C Hamano
2020-01-21 9:24 ` [PATCH 2/7] remote: clean-up by returning early to avoid one indentation Bert Wesarg
2020-01-23 23:02 ` Junio C Hamano
2020-01-21 9:24 ` [PATCH 3/7] remote: clean-up config callback Bert Wesarg
2020-01-21 9:24 ` [PATCH v3 4/7] remote rename: rename branch.<name>.pushRemote config values too Bert Wesarg
2020-01-21 9:24 ` [PATCH 5/7] [RFC] config: make `scope_name` global as `config_scope_name` Bert Wesarg
2020-01-22 0:12 ` Matt Rogers
2020-01-22 7:37 ` Bert Wesarg
2020-01-23 1:30 ` Matt Rogers
2020-01-21 9:24 ` Bert Wesarg [this message]
2020-01-21 9:24 ` [PATCH 7/7] remote rename: gently handle remote.pushDefault config Bert Wesarg
2020-01-23 23:03 ` Junio C Hamano
2020-01-24 8:49 ` Bert Wesarg
2020-01-22 15:26 ` [PATCH 0/7] remote rename: improve handling of configuration values Bert Wesarg
2020-01-17 9:49 ` [PATCH] remote: rename also remotes in the branch.<name>.pushRemote config Johannes Schindelin
2020-01-17 9:45 ` Johannes Schindelin
-- strict thread matches above, loose matches on Subject: below --
2020-01-24 9:25 [PATCH v2 0/7] remote rename/remove: improve handling of configuration values Bert Wesarg
2020-01-24 9:25 ` [PATCH 6/7] config: provide access to the current line number Bert Wesarg
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=92356342164523c7753eda52c8985cb4774d1434.1579598053.git.bert.wesarg@googlemail.com \
--to=bert.wesarg@googlemail.com \
--cc=git@vger.kernel.org \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).