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

Re: Fwd: git clone does not respect command line options

From
Jeff King <peff@peff.net>
Date
Feb 26, 2016, 08:45 UTC
Message-ID
<20160226084514.GA28898@sigill.intra.peff.net>
In-Reply-To
<CACsJy8BK=2aKg68msH9vawHrXr=PsQYgs6sGXy0koy459MYfSA@mail.gmail.com>
On Fri, Feb 26, 2016 at 03:34:53PM +0700, Duy Nguyen wrote:
Show 14 quoted lines
> On Fri, Feb 26, 2016 at 3:24 PM, Jeff King <peff@peff.net> wrote:
> > As an alternative, it would be nice to have some config syntax for
> > "clear the list". Maybe something like an empty string, which I think
> > has no meaning for the current multi-valued variables (at least not for
> > credential helpers or refspecs). That would allow something like:
> >
> >   git -c credential.helper= clone ...
> >
> > to do what you'd expect.
> 
> I've been thinking of -= instead. It's unambiguous. And you can use
> wildcards on both sides. "credential.helper -= *" means delete that
> key, "credential.* -= *" deletes all credential.* keys.
> credential.helper -= abc only deletes it if the previous value is abc.

But there you're inventing new syntax, so you'd need to invent new syntax inside the config file, too. And you'd need to somehow communicate to the consumers of the config values that the value is "unset". So for config callbacks inside of git, they need to take more than just the key/value pair (or we'd have to read all of the config and pre-process it). Ditto for git-config. How do we show in the output of --get-all that the list was reset? Or again, we could pre-process completely in git-config (which would probably mean using a new option, --get-list or something, instead of --get-all).

By contrast, I think my suggestion can be implemented as:
diff --git a/credential.c b/credential.c
index 7d6501d..aa99666 100644
--- a/credential.c
+++ b/credential.c
@@ -63,9 +63,12 @@ static int credential_config_callback(const char *var, const char *value,
 		key = dot + 1;
 	}
 
-	if (!strcmp(key, "helper"))
-		string_list_append(&c->helpers, value);
-	else if (!strcmp(key, "username")) {
+	if (!strcmp(key, "helper")) {
+		if (*value)
+			string_list_append(&c->helpers, value);
+		else
+			string_list_clear(&c->helpers, 0);
+	} else if (!strcmp(key, "username")) {
 		if (!c->username)
 			c->username = xstrdup(value);
 	}

The big downside is that each consumer of the value needs to learn this
trick. But as I said, I think there aren't very many.

Don't get me wrong; I think your suggestion is a little cleaner. If we
were designing the config system from scratch, I'd probably favor a
single query-able tree rather than the callback system, and do things
like list-processing centrally. But given the history, I'm not sure if
it's worth it now.

-Peff
Previous: Duy NguyenNext: Junio C Hamano
Message 8 of 12 in “Fwd: git clone does not respect command line options”
  1. GuilhermeFeb 26, 2016
  2. Jeff KingFeb 26, 2016
  3. GuilhermeFeb 26, 2016
  4. Jeff KingFeb 26, 2016
  5. Jacob KellerFeb 26, 2016
  6. Jeff KingFeb 26, 2016
  7. Duy NguyenFeb 26, 2016
  8. Jeff KingFeb 26, 2016
  9. Junio C HamanoFeb 26, 2016
  10. GuilhermeFeb 28, 2016
  11. Jeff KingFeb 26, 2016
  12. Jeff KingFeb 28, 2016

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.