git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Martin Ågren" <martin.agren@gmail.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, hkleynhans@bloomberg.net,
	Thomas Gummerer <t.gummerer@gmail.com>
Subject: [PATCH 2/4] pager: refactor `pager_command_config()`
Date: Sun,  5 Nov 2017 12:58:20 +0100	[thread overview]
Message-ID: <2b0f8f5c1f42f7a85d8017ca378de8acde2688a3.1509879269.git.martin.agren@gmail.com> (raw)
In-Reply-To: <cover.1509879269.git.martin.agren@gmail.com>

`pager_command_config()` checks for the config `pager.<cmd>`. In the
next commit, we will want to also look for some strings on the form
`pager.<cmd>.foo`.

Refactor the code to verify upfront that the string starts with
"pager.<cmd>" and then check that the remainder is the empty string.
This makes it easy to look for other remainders in the next patch.

While at it, before assigning to `value`, free any old value we might
already have picked up.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
---
 pager.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/pager.c b/pager.c
index 92b23e6cd..8968f26f1 100644
--- a/pager.c
+++ b/pager.c
@@ -191,14 +191,19 @@ struct pager_command_config_data {
 static int pager_command_config(const char *var, const char *value, void *vdata)
 {
 	struct pager_command_config_data *data = vdata;
-	const char *cmd;
+	const char *cmd, *remainder;
+
+	if (!skip_prefix(var, "pager.", &cmd) ||
+	    !skip_prefix(cmd, data->cmd, &remainder))
+		return 0;
 
-	if (skip_prefix(var, "pager.", &cmd) && !strcmp(cmd, data->cmd)) {
+	if (!*remainder) {
 		int b = git_parse_maybe_bool(value);
 		if (b >= 0)
 			data->want = b;
 		else {
 			data->want = 1;
+			free(data->value);
 			data->value = xstrdup(value);
 		}
 	}
-- 
2.15.0.415.gac1375d7e


  parent reply	other threads:[~2017-11-05 11:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-01 16:36 Git Open Source Weekend London 11th/12th November Thomas Gummerer
2017-11-04  9:28 ` Jeff King
2017-11-04 17:15   ` Philip Oakley
2017-11-05 11:58   ` [PATCH/DONOTAPPLY 0/4] first steps towards pager.foo.{command,enable} Martin Ågren
2017-11-05 11:58     ` [PATCH 1/4] t7006: document that `pager.foo` can be partially preserved Martin Ågren
2017-11-05 11:58     ` Martin Ågren [this message]
2017-11-05 11:58     ` [PATCH 3/4] pager: introduce `pager.*.command` and `.enable` Martin Ågren
2017-11-05 11:58     ` [PATCH 4/4] pager: make `pager.foo.command` imply `.enable=true` Martin Ågren
2017-11-06 10:48     ` [PATCH/DONOTAPPLY 0/4] first steps towards pager.foo.{command,enable} Jeff King
2017-11-07 20:46       ` Martin Ågren
2017-11-05 12:42 ` Git Open Source Weekend London 11th/12th November Patrick Steinhardt

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=2b0f8f5c1f42f7a85d8017ca378de8acde2688a3.1509879269.git.martin.agren@gmail.com \
    --to=martin.agren@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=hkleynhans@bloomberg.net \
    --cc=peff@peff.net \
    --cc=t.gummerer@gmail.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.
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).