git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/4] pager: refactor `pager_command_config()`

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Nov 5, 2017, 11:58 UTC
Message-ID
<2b0f8f5c1f42f7a85d8017ca378de8acde2688a3.1509879269.git.martin.agren@gmail.com>
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
Previous: Martin ÅgrenNext: Martin Ågren
Message 6 of 11 in “Git Open Source Weekend London 11th/12th November”
  1. Thomas GummererNov 1, 2017
  2. Jeff KingNov 4, 2017
  3. Philip OakleyNov 4, 2017
  4. 0/4 first steps towards pager.foo.{command,enable}Martin Ågren, Nov 5, 2017
  5. 1/4 t7006: document that `pager.foo` can be partially preservedMartin Ågren, Nov 5, 2017
  6. 2/4 pager: refactor `pager_command_config()`Martin Ågren, Nov 5, 2017
  7. 3/4 pager: introduce `pager.*.command` and `.enable`Martin Ågren, Nov 5, 2017
  8. 4/4 pager: make `pager.foo.command` imply `.enable=true`Martin Ågren, Nov 5, 2017
  9. Jeff KingNov 6, 2017
  10. Martin ÅgrenNov 7, 2017
  11. Patrick SteinhardtNov 5, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.