help: use list_aliases() for alias listing
help.c has its own get_alias() config callback that duplicates the parsing logic in alias.c. Consolidate by teaching list_aliases() to also store the alias values (via the string_list util field), then use it in list_all_cmds_help_aliases() instead of the private callback. This preserves the existing error checking for value-less alias definitions by checking in alias.c rather than help.c. No functional change intended. Signed-off-by: Jonatan Holmgren <jonatan@jontes.page> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonatan Holmgren committed
Feb 18, 2026 at 22:57 UTC
3f0cdfa87907096ed7c6caa33fbf360e0e19844c
3 files changed
+19
-16
alias.c
+7
-1
@@ -29,7 +29,13 @@ static int config_alias_cb(const char *key, const char *value,
29
key, value);
30
}
31
} else if (data->list) {
32
- string_list_append(data->list, p);
32
+ struct string_list_item *item;
33
+
34
+ if (!value)
35
+ return config_error_nonbool(key);
36
+
37
+ item = string_list_append(data->list, p);
38
+ item->util = xstrdup(value);
39
}
40
41
return 0;
help.c
+2
-15
@@ -20,6 +20,7 @@
20
#include "prompt.h"
21
#include "fsmonitor-ipc.h"
22
#include "repository.h"
23
+#include "alias.h"
24
25
#ifndef NO_CURL
26
#include "git-curl-compat.h" /* For LIBCURL_VERSION only */
@@ -469,20 +470,6 @@ void list_developer_interfaces_help(void)
470
putchar('\n');
471
}
472
472
-static int get_alias(const char *var, const char *value,
473
- const struct config_context *ctx UNUSED, void *data)
474
-{
475
- struct string_list *list = data;
476
-
477
- if (skip_prefix(var, "alias.", &var)) {
478
- if (!value)
479
- return config_error_nonbool(var);
480
- string_list_append(list, var)->util = xstrdup(value);
481
- }
482
-
483
- return 0;
484
-}
485
-
473
static void list_all_cmds_help_external_commands(void)
474
{
475
struct string_list others = STRING_LIST_INIT_DUP;
@@ -502,7 +489,7 @@ static void list_all_cmds_help_aliases(int longest)
489
struct cmdname_help *aliases;
490
int i;
491
505
- repo_config(the_repository, get_alias, &alias_list);
492
+ list_aliases(&alias_list);
493
string_list_sort(&alias_list);
494
495
for (i = 0; i < alias_list.nr; i++) {
t/t0014-alias.sh
+10
@@ -112,4 +112,14 @@ test_expect_success 'cannot alias-shadow a sample of regular builtins' '
112
done
113
'
114
115
+test_expect_success 'alias without value reports error' '
116
+ test_when_finished "git config --unset alias.noval" &&
117
+ cat >>.git/config <<-\EOF &&
118
+ [alias]
119
+ noval
120
+ EOF
121
+ test_must_fail git noval 2>error &&
122
+ test_grep "alias.noval" error
123
+'
124
+
125
test_done