From: Jeff King Date: Sat, 25 Apr 2026 23:47:00 GMT Subject: Re: [PATCH] alias: restore support for simple dotted aliases Message-ID: <20260425234700.GB29816@coredump.intra.peff.net> In-Reply-To: <20260425232916.GA29816@coredump.intra.peff.net> On Sat, Apr 25, 2026 at 07:29:16PM -0400, Jeff King wrote: > On Sat, Apr 25, 2026 at 11:57:24AM +0200, Jonatan Holmgren wrote: > > > That is a challenge we are going to have to consider. I think reserving > > `command` is a worthwhile compromise, but obviously we cannot do that for > > arbitrary future keys such as `help`, `hidden`, etc. > > We don't necessarily have to reserve them. When we see alias.foo.bar, we > could consider it as both alias "foo.bar" and the "bar" key of alias > "foo", without regard to what is in "bar" (i.e., whether it is "command" > or "help", etc). I.e., don't "fall back" but allow two overlapping > namespace.s > > That is the most backwards-compatible thing we could do, but does create > some interesting situations. For reference, I mean something like this: diff --git a/alias.c b/alias.c index ec9833dd30..07c6bd3645 100644 --- a/alias.c +++ b/alias.c @@ -34,16 +34,20 @@ static int config_alias_cb(const char *var, const char *value, if (subsection && !subsection_len) subsection = NULL; - if (subsection && strcmp(key, "command")) - return 0; - if (data->alias) { int match; if (subsection) - match = (strlen(data->alias) == subsection_len && - !strncmp(data->alias, subsection, - subsection_len)); + /* + * alias.foo.command always matches "foo", but for + * historical compatibility also match alias.foo.bar as + * "foo.bar", even when "bar" is "command" or any other + * key we happen to know about. + */ + match = (!strcmp(key, "command") && + strlen(data->alias) == subsection_len && + !strncmp(data->alias, subsection, subsection_len)) + || !strcmp(data->alias, subsection); else match = !strcasecmp(data->alias, key); @@ -59,8 +63,23 @@ static int config_alias_cb(const char *var, const char *value, return config_error_nonbool(var); if (subsection) + /* + * If it's not alias.foo.command, then either it's a + * historical alias (git "foo.bar"), or it's some + * metadata not support yet by this version + * ("alias.foo.help" or similar). + * + * We'll guess it's the former and include the whole + * "foo.bar" in the list. + * + * We might want to suppress duplicates when we see both + * alias.foo.command and alias.foo.help, since that's + * what a hypothetical future version might understand. + */ item = string_list_append_nodup(data->list, - xmemdupz(subsection, subsection_len)); + !strcmp(key, "command") + ? xmemdupz(subsection, subsection_len) + : xstrdup(subsection)); else item = string_list_append(data->list, key); item->util = xstrdup(value); -Peff