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 );
@@ -468,20 +470,6 @@ void list_developer_interfaces_help(void)
468470 putchar ('\n' );
469471}
470472
471- static int get_alias (const char * var , const char * value ,
472- const struct config_context * ctx UNUSED , void * data )
473- {
474- struct string_list * list = data ;
475-
476- if (skip_prefix (var , "alias." , & var )) {
477- if (!value )
478- return config_error_nonbool (var );
479- string_list_append (list , var )-> util = xstrdup (value );
480- }
481-
482- return 0 ;
483- }
484-
485473static void list_all_cmds_help_external_commands (void )
486474{
487475 struct string_list others = STRING_LIST_INIT_DUP ;
@@ -501,11 +489,11 @@ static void list_all_cmds_help_aliases(int longest)
501489 struct cmdname_help * aliases ;
502490 int i ;
503491
504- repo_config ( the_repository , get_alias , & alias_list );
492+ list_aliases ( & alias_list );
505493 string_list_sort (& alias_list );
506494
507495 for (i = 0 ; i < alias_list .nr ; i ++ ) {
508- size_t len = strlen (alias_list .items [i ].string );
496+ size_t len = utf8_strwidth (alias_list .items [i ].string );
509497 if (longest < len )
510498 longest = len ;
511499 }
@@ -586,7 +574,8 @@ static int git_unknown_cmd_config(const char *var, const char *value,
586574 void * cb )
587575{
588576 struct help_unknown_cmd_config * cfg = cb ;
589- const char * p ;
577+ const char * subsection , * key ;
578+ size_t subsection_len ;
590579
591580 if (!strcmp (var , "help.autocorrect" )) {
592581 int v = parse_autocorrect (value );
@@ -601,8 +590,18 @@ static int git_unknown_cmd_config(const char *var, const char *value,
601590 }
602591
603592 /* Also use aliases for command lookup */
604- if (skip_prefix (var , "alias." , & p ))
605- add_cmdname (& cfg -> aliases , p , strlen (p ));
593+ if (!parse_config_key (var , "alias" , & subsection , & subsection_len ,
594+ & key )) {
595+ if (subsection ) {
596+ /* [alias "name"] command = value */
597+ if (!strcmp (key , "command" ))
598+ add_cmdname (& cfg -> aliases , subsection ,
599+ subsection_len );
600+ } else {
601+ /* alias.name = value */
602+ add_cmdname (& cfg -> aliases , key , strlen (key ));
603+ }
604+ }
606605
607606 return 0 ;
608607}
0 commit comments