2020#include "prompt.h"
2121#include "fsmonitor-ipc.h"
2222#include "repository.h"
23+ #include "alias.h"
24+ #include "utf8.h"
2325
2426#ifndef NO_CURL
2527#include "git-curl-compat.h" /* For LIBCURL_VERSION only */
@@ -107,7 +109,7 @@ static void print_command_list(const struct cmdname_help *cmds,
107109
108110 for (i = 0 ; cmds [i ].name ; i ++ ) {
109111 if (cmds [i ].category & mask ) {
110- size_t len = strlen (cmds [i ].name );
112+ size_t len = utf8_strwidth (cmds [i ].name );
111113 printf (" %s " , cmds [i ].name );
112114 if (longest > len )
113115 mput_char (' ' , longest - len );
@@ -469,20 +471,6 @@ void list_developer_interfaces_help(void)
469471 putchar ('\n' );
470472}
471473
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-
486474static void list_all_cmds_help_external_commands (void )
487475{
488476 struct string_list others = STRING_LIST_INIT_DUP ;
@@ -502,11 +490,11 @@ static void list_all_cmds_help_aliases(int longest)
502490 struct cmdname_help * aliases ;
503491 int i ;
504492
505- repo_config ( the_repository , get_alias , & alias_list );
493+ list_aliases ( & alias_list );
506494 string_list_sort (& alias_list );
507495
508496 for (i = 0 ; i < alias_list .nr ; i ++ ) {
509- size_t len = strlen (alias_list .items [i ].string );
497+ size_t len = utf8_strwidth (alias_list .items [i ].string );
510498 if (longest < len )
511499 longest = len ;
512500 }
@@ -587,7 +575,8 @@ static int git_unknown_cmd_config(const char *var, const char *value,
587575 void * cb )
588576{
589577 struct help_unknown_cmd_config * cfg = cb ;
590- const char * p ;
578+ const char * subsection , * key ;
579+ size_t subsection_len ;
591580
592581 if (!strcmp (var , "help.autocorrect" )) {
593582 int v = parse_autocorrect (value );
@@ -602,8 +591,18 @@ static int git_unknown_cmd_config(const char *var, const char *value,
602591 }
603592
604593 /* Also use aliases for command lookup */
605- if (skip_prefix (var , "alias." , & p ))
606- add_cmdname (& cfg -> aliases , p , strlen (p ));
594+ if (!parse_config_key (var , "alias" , & subsection , & subsection_len ,
595+ & key )) {
596+ if (subsection ) {
597+ /* [alias "name"] command = value */
598+ if (!strcmp (key , "command" ))
599+ add_cmdname (& cfg -> aliases , subsection ,
600+ subsection_len );
601+ } else {
602+ /* alias.name = value */
603+ add_cmdname (& cfg -> aliases , key , strlen (key ));
604+ }
605+ }
607606
608607 return 0 ;
609608}
0 commit comments